Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[pandora-kernel.git] / drivers / staging / rt2860 / rtmp.h
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27     Module Name:
28     rtmp.h
29
30     Abstract:
31     Miniport generic portion header file
32
33     Revision History:
34     Who         When          What
35     --------    ----------    ----------------------------------------------
36     Paul Lin    2002-08-01    created
37     James Tan   2002-09-06    modified (Revise NTCRegTable)
38     John Chang  2004-09-06    modified for RT2600
39 */
40 #ifndef __RTMP_H__
41 #define __RTMP_H__
42
43 #include "spectrum_def.h"
44 #include "rtmp_dot11.h"
45 #include "rtmp_chip.h"
46
47 struct rt_rtmp_adapter;
48
49 /*#define DBG           1 */
50
51 /*#define DBG_DIAGNOSE          1 */
52
53 /*+++Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
54 #define MAX_DATAMM_RETRY        3
55 #define MGMT_USE_QUEUE_FLAG     0x80
56 /*---Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
57
58 #define MAXSEQ          (0xFFF)
59
60 extern unsigned char SNAP_AIRONET[];
61 extern unsigned char CISCO_OUI[];
62 extern u8 BaSizeArray[4];
63
64 extern u8 BROADCAST_ADDR[MAC_ADDR_LEN];
65 extern u8 ZERO_MAC_ADDR[MAC_ADDR_LEN];
66 extern unsigned long BIT32[32];
67 extern u8 BIT8[8];
68 extern char *CipherName[];
69 extern char *MCSToMbps[];
70 extern u8 RxwiMCSToOfdmRate[12];
71 extern u8 SNAP_802_1H[6];
72 extern u8 SNAP_BRIDGE_TUNNEL[6];
73 extern u8 SNAP_AIRONET[8];
74 extern u8 CKIP_LLC_SNAP[8];
75 extern u8 EAPOL_LLC_SNAP[8];
76 extern u8 EAPOL[2];
77 extern u8 IPX[2];
78 extern u8 APPLE_TALK[2];
79 extern u8 RateIdToPlcpSignal[12];       /* see IEEE802.11a-1999 p.14 */
80 extern u8 OfdmRateToRxwiMCS[];
81 extern u8 OfdmSignalToRateId[16];
82 extern u8 default_cwmin[4];
83 extern u8 default_cwmax[4];
84 extern u8 default_sta_aifsn[4];
85 extern u8 MapUserPriorityToAccessCategory[8];
86
87 extern u16 RateUpPER[];
88 extern u16 RateDownPER[];
89 extern u8 Phy11BNextRateDownward[];
90 extern u8 Phy11BNextRateUpward[];
91 extern u8 Phy11BGNextRateDownward[];
92 extern u8 Phy11BGNextRateUpward[];
93 extern u8 Phy11ANextRateDownward[];
94 extern u8 Phy11ANextRateUpward[];
95 extern char RssiSafeLevelForTxRate[];
96 extern u8 RateIdToMbps[];
97 extern u16 RateIdTo500Kbps[];
98
99 extern u8 CipherSuiteWpaNoneTkip[];
100 extern u8 CipherSuiteWpaNoneTkipLen;
101
102 extern u8 CipherSuiteWpaNoneAes[];
103 extern u8 CipherSuiteWpaNoneAesLen;
104
105 extern u8 SsidIe;
106 extern u8 SupRateIe;
107 extern u8 ExtRateIe;
108
109 extern u8 HtCapIe;
110 extern u8 AddHtInfoIe;
111 extern u8 NewExtChanIe;
112
113 extern u8 ErpIe;
114 extern u8 DsIe;
115 extern u8 TimIe;
116 extern u8 WpaIe;
117 extern u8 Wpa2Ie;
118 extern u8 IbssIe;
119 extern u8 Ccx2Ie;
120 extern u8 WapiIe;
121
122 extern u8 WPA_OUI[];
123 extern u8 RSN_OUI[];
124 extern u8 WAPI_OUI[];
125 extern u8 WME_INFO_ELEM[];
126 extern u8 WME_PARM_ELEM[];
127 extern u8 Ccx2QosInfo[];
128 extern u8 Ccx2IeInfo[];
129 extern u8 RALINK_OUI[];
130 extern u8 PowerConstraintIE[];
131
132 extern u8 RateSwitchTable[];
133 extern u8 RateSwitchTable11B[];
134 extern u8 RateSwitchTable11G[];
135 extern u8 RateSwitchTable11BG[];
136
137 extern u8 RateSwitchTable11BGN1S[];
138 extern u8 RateSwitchTable11BGN2S[];
139 extern u8 RateSwitchTable11BGN2SForABand[];
140 extern u8 RateSwitchTable11N1S[];
141 extern u8 RateSwitchTable11N2S[];
142 extern u8 RateSwitchTable11N2SForABand[];
143
144 extern u8 PRE_N_HT_OUI[];
145
146 struct rt_rssi_sample {
147         char LastRssi0;         /* last received RSSI */
148         char LastRssi1;         /* last received RSSI */
149         char LastRssi2;         /* last received RSSI */
150         char AvgRssi0;
151         char AvgRssi1;
152         char AvgRssi2;
153         short AvgRssi0X8;
154         short AvgRssi1X8;
155         short AvgRssi2X8;
156 };
157
158 /* */
159 /*  Queue structure and macros */
160 /* */
161 struct rt_queue_entry;
162
163 struct rt_queue_entry {
164         struct rt_queue_entry *Next;
165 };
166
167 /* Queue structure */
168 struct rt_queue_header {
169         struct rt_queue_entry *Head;
170         struct rt_queue_entry *Tail;
171         unsigned long Number;
172 };
173
174 #define InitializeQueueHeader(QueueHeader)              \
175 {                                                       \
176         (QueueHeader)->Head = (QueueHeader)->Tail = NULL;   \
177         (QueueHeader)->Number = 0;                          \
178 }
179
180 #define RemoveHeadQueue(QueueHeader)                \
181 (QueueHeader)->Head;                                \
182 {                                                   \
183         struct rt_queue_entry *pNext;                             \
184         if ((QueueHeader)->Head != NULL) {                              \
185                 pNext = (QueueHeader)->Head->Next;          \
186                 (QueueHeader)->Head->Next = NULL;               \
187                 (QueueHeader)->Head = pNext;                \
188                 if (pNext == NULL)                          \
189                         (QueueHeader)->Tail = NULL;             \
190                 (QueueHeader)->Number--;                    \
191         }                                                                                               \
192 }
193
194 #define InsertHeadQueue(QueueHeader, QueueEntry)            \
195 {                                                           \
196                 ((struct rt_queue_entry *)QueueEntry)->Next = (QueueHeader)->Head; \
197                 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);       \
198                 if ((QueueHeader)->Tail == NULL)                        \
199                         (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);   \
200                 (QueueHeader)->Number++;                                \
201 }
202
203 #define InsertTailQueue(QueueHeader, QueueEntry)                \
204 {                                                               \
205         ((struct rt_queue_entry *)QueueEntry)->Next = NULL;                    \
206         if ((QueueHeader)->Tail)                                    \
207                 (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \
208         else                                                        \
209                 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);       \
210         (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);           \
211         (QueueHeader)->Number++;                                    \
212 }
213
214 #define InsertTailQueueAc(pAd, pEntry, QueueHeader, QueueEntry)                 \
215 {                                                                                                                                               \
216         ((struct rt_queue_entry *)QueueEntry)->Next = NULL;                                                     \
217         if ((QueueHeader)->Tail)                                                                                        \
218                 (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry);                      \
219         else                                                                                                                            \
220                 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);                            \
221         (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);                                    \
222         (QueueHeader)->Number++;                                                                                        \
223 }
224
225 /* */
226 /*  Macros for flag and ref count operations */
227 /* */
228 #define RTMP_SET_FLAG(_M, _F)       ((_M)->Flags |= (_F))
229 #define RTMP_CLEAR_FLAG(_M, _F)     ((_M)->Flags &= ~(_F))
230 #define RTMP_CLEAR_FLAGS(_M)        ((_M)->Flags = 0)
231 #define RTMP_TEST_FLAG(_M, _F)      (((_M)->Flags & (_F)) != 0)
232 #define RTMP_TEST_FLAGS(_M, _F)     (((_M)->Flags & (_F)) == (_F))
233 /* Macro for power save flag. */
234 #define RTMP_SET_PSFLAG(_M, _F)       ((_M)->PSFlags |= (_F))
235 #define RTMP_CLEAR_PSFLAG(_M, _F)     ((_M)->PSFlags &= ~(_F))
236 #define RTMP_CLEAR_PSFLAGS(_M)        ((_M)->PSFlags = 0)
237 #define RTMP_TEST_PSFLAG(_M, _F)      (((_M)->PSFlags & (_F)) != 0)
238 #define RTMP_TEST_PSFLAGS(_M, _F)     (((_M)->PSFlags & (_F)) == (_F))
239
240 #define OPSTATUS_SET_FLAG(_pAd, _F)     ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
241 #define OPSTATUS_CLEAR_FLAG(_pAd, _F)   ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
242 #define OPSTATUS_TEST_FLAG(_pAd, _F)    (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
243
244 #define CLIENT_STATUS_SET_FLAG(_pEntry, _F)      ((_pEntry)->ClientStatusFlags |= (_F))
245 #define CLIENT_STATUS_CLEAR_FLAG(_pEntry, _F)    ((_pEntry)->ClientStatusFlags &= ~(_F))
246 #define CLIENT_STATUS_TEST_FLAG(_pEntry, _F)     (((_pEntry)->ClientStatusFlags & (_F)) != 0)
247
248 #define RX_FILTER_SET_FLAG(_pAd, _F)    ((_pAd)->CommonCfg.PacketFilter |= (_F))
249 #define RX_FILTER_CLEAR_FLAG(_pAd, _F)  ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
250 #define RX_FILTER_TEST_FLAG(_pAd, _F)   (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
251
252 #define STA_NO_SECURITY_ON(_p)          (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
253 #define STA_WEP_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
254 #define STA_TKIP_ON(_p)                 (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
255 #define STA_AES_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
256
257 #define STA_TGN_WIFI_ON(_p)             (_p->StaCfg.bTGnWifiTest == TRUE)
258
259 #define CKIP_KP_ON(_p)                          ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
260 #define CKIP_CMIC_ON(_p)                        ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
261
262 #define INC_RING_INDEX(_idx, _RingSize)    \
263 {                                          \
264     (_idx) = (_idx+1) % (_RingSize);       \
265 }
266
267 /* StaActive.SupportedHtPhy.MCSSet is copied from AP beacon.  Don't need to update here. */
268 #define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd)                                 \
269 {                                                                                       \
270         _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth;      \
271         _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs;      \
272         _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF;      \
273         _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20;      \
274         _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40;      \
275         _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC;      \
276         _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC;      \
277         _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset;      \
278         _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth;      \
279         _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode;      \
280         _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent;      \
281         NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(u8) * 16);\
282 }
283
284 #define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability)                                 \
285 {                                                                                       \
286         _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (u8)(_pHtCapability->HtCapInfo.AMsduSize); \
287         _pAd->MacTab.Content[BSSID_WCID].MmpsMode = (u8)(_pHtCapability->HtCapInfo.MimoPs);     \
288         _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (u8)(_pHtCapability->HtCapParm.MaxRAmpduFactor);     \
289 }
290
291 /* */
292 /* MACRO for 32-bit PCI register read / write */
293 /* */
294 /* Usage : RTMP_IO_READ32( */
295 /*              struct rt_rtmp_adapter *pAd, */
296 /*              unsigned long Register_Offset, */
297 /*              unsigned long * pValue) */
298 /* */
299 /*         RTMP_IO_WRITE32( */
300 /*              struct rt_rtmp_adapter *pAd, */
301 /*              unsigned long Register_Offset, */
302 /*              unsigned long Value) */
303 /* */
304
305 /* */
306 /* Common fragment list structure -  Identical to the scatter gather frag list structure */
307 /* */
308 /*#define struct rt_rtmp_sg_element         SCATTER_GATHER_ELEMENT */
309 /*#define struct rt_rtmp_sg_element *PSCATTER_GATHER_ELEMENT */
310 #define NIC_MAX_PHYS_BUF_COUNT              8
311
312 struct rt_rtmp_sg_element {
313         void *Address;
314         unsigned long Length;
315         unsigned long *Reserved;
316 };
317
318 struct rt_rtmp_sg_list {
319         unsigned long NumberOfElements;
320         unsigned long *Reserved;
321         struct rt_rtmp_sg_element Elements[NIC_MAX_PHYS_BUF_COUNT];
322 };
323
324 /* */
325 /*  Some utility macros */
326 /* */
327 #define GET_LNA_GAIN(_pAd)      ((_pAd->LatchRfRegs.Channel <= 14) ? (_pAd->BLNAGain) : ((_pAd->LatchRfRegs.Channel <= 64) ? (_pAd->ALNAGain0) : ((_pAd->LatchRfRegs.Channel <= 128) ? (_pAd->ALNAGain1) : (_pAd->ALNAGain2))))
328
329 #define INC_COUNTER64(Val)          (Val.QuadPart++)
330
331 #define INFRA_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
332 #define ADHOC_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
333 #define MONITOR_ON(_p)              (((_p)->StaCfg.BssType) == BSS_MONITOR)
334 #define IDLE_ON(_p)                 (!INFRA_ON(_p) && !ADHOC_ON(_p))
335
336 /* Check LEAP & CCKM flags */
337 #define LEAP_ON(_p)                 (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
338 #define LEAP_CCKM_ON(_p)            ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
339
340 /* if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */
341 #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap)                \
342 {                                                                                                                               \
343         if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) {        \
344                 _pExtraLlcSnapEncap = SNAP_802_1H;                                              \
345                 if (NdisEqualMemory(IPX, _pBufVA + 12, 2) ||                    \
346                         NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) { \
347                         _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;                       \
348                 }                                                                                                               \
349         }                                                                                                                       \
350         else {                          \
351                 _pExtraLlcSnapEncap = NULL;                                                             \
352         }                                                                                                                       \
353 }
354
355 /* New Define for new Tx Path. */
356 #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap)       \
357 {                                                                                                                               \
358         if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) {              \
359                 _pExtraLlcSnapEncap = SNAP_802_1H;                                              \
360                 if (NdisEqualMemory(IPX, _pBufVA, 2) ||                                 \
361                         NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) {              \
362                         _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;                       \
363                 }                                                                                                               \
364         }                                                                                                                       \
365         else {          \
366                 _pExtraLlcSnapEncap = NULL;                                                             \
367         }                                                                                                                       \
368 }
369
370 #define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType)                   \
371 {                                                                       \
372     NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN);                           \
373     NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN);          \
374     NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
375 }
376
377 /* if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way. */
378 /* else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field */
379 /* else remove the LLC/SNAP field from the result Ethernet frame */
380 /* Patch for WHQL only, which did not turn on Netbios but use IPX within its payload */
381 /* Note: */
382 /*     _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO */
383 /*     _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed */
384 #define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP)      \
385 {                                                                       \
386     char LLC_Len[2];                                                    \
387                                                                         \
388     _pRemovedLLCSNAP = NULL;                                            \
389     if (NdisEqualMemory(SNAP_802_1H, _pData, 6)  ||                     \
390         NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) {               \
391         u8 *pProto = _pData + 6;                                        \
392                                                                         \
393         if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) &&  \
394                 NdisEqualMemory(SNAP_802_1H, _pData, 6))        {       \
395                 LLC_Len[0] = (u8)(_DataSize / 256);                     \
396                 LLC_Len[1] = (u8)(_DataSize % 256);                     \
397                 MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);      \
398         }                                                               \
399         else    {                                                       \
400                 MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto);       \
401                 _pRemovedLLCSNAP = _pData;                              \
402                 _DataSize -= LENGTH_802_1_H;                            \
403                 _pData += LENGTH_802_1_H;                               \
404         }                                                               \
405     }                                                                   \
406         else    {                                                       \
407         LLC_Len[0] = (u8)(_DataSize / 256);                             \
408         LLC_Len[1] = (u8)(_DataSize % 256);                             \
409         MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);              \
410     }                                                                   \
411 }
412
413 /* Enqueue this frame to MLME engine */
414 /* We need to enqueue the whole frame because MLME need to pass data type */
415 /* information from 802.11 header */
416 #ifdef RTMP_MAC_PCI
417 #define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal)        \
418 {                                                                                       \
419     u32 High32TSF, Low32TSF;                                                          \
420     RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF);                                       \
421     RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF);                                        \
422     MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal);   \
423 }
424 #endif /* RTMP_MAC_PCI // */
425 #ifdef RTMP_MAC_USB
426 #define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal)        \
427 {                                                                                       \
428     u32 High32TSF = 0, Low32TSF = 0;                                                          \
429     MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal);   \
430 }
431 #endif /* RTMP_MAC_USB // */
432
433 #define MAC_ADDR_EQUAL(pAddr1, pAddr2)           RTMPEqualMemory((void *)(pAddr1), (void *)(pAddr2), MAC_ADDR_LEN)
434 #define SSID_EQUAL(ssid1, len1, ssid2, len2)    ((len1 == len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
435
436 /* */
437 /* Check if it is Japan W53(ch52,56,60,64) channel. */
438 /* */
439 #define JapanChannelCheck(channel)  ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
440
441 #define STA_EXTRA_SETTING(_pAd)
442
443 #define STA_PORT_SECURED(_pAd) \
444 { \
445         BOOLEAN Cancelled; \
446         (_pAd)->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
447         NdisAcquireSpinLock(&((_pAd)->MacTabLock)); \
448         (_pAd)->MacTab.Content[BSSID_WCID].PortSecured = (_pAd)->StaCfg.PortSecured; \
449         (_pAd)->MacTab.Content[BSSID_WCID].PrivacyFilter = Ndis802_11PrivFilterAcceptAll;\
450         NdisReleaseSpinLock(&(_pAd)->MacTabLock); \
451         RTMPCancelTimer(&((_pAd)->Mlme.LinkDownTimer), &Cancelled);\
452         STA_EXTRA_SETTING(_pAd); \
453 }
454
455 /* */
456 /*  Data buffer for DMA operation, the buffer must be contiguous physical memory */
457 /*  Both DMA to / from CPU use the same structure. */
458 /* */
459 struct rt_rtmp_dmabuf {
460         unsigned long AllocSize;
461         void *AllocVa;          /* TxBuf virtual address */
462         dma_addr_t AllocPa;     /* TxBuf physical address */
463 };
464
465 /* */
466 /* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */
467 /* contiguous physical memory. char stored the binding Rx packet descriptor */
468 /* which won't be released, driver has to wait until upper layer return the packet */
469 /* before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair */
470 /* to describe the packet buffer. For Tx, char stored the tx packet descriptor */
471 /* which driver should ACK upper layer when the tx is physically done or failed. */
472 /* */
473 struct rt_rtmp_dmacb {
474         unsigned long AllocSize;        /* Control block size */
475         void *AllocVa;          /* Control block virtual address */
476         dma_addr_t AllocPa;     /* Control block physical address */
477         void *pNdisPacket;
478         void *pNextNdisPacket;
479
480         struct rt_rtmp_dmabuf DmaBuf;   /* Associated DMA buffer structure */
481 };
482
483 struct rt_rtmp_tx_ring {
484         struct rt_rtmp_dmacb Cell[TX_RING_SIZE];
485         u32 TxCpuIdx;
486         u32 TxDmaIdx;
487         u32 TxSwFreeIdx;        /* software next free tx index */
488 };
489
490 struct rt_rtmp_rx_ring {
491         struct rt_rtmp_dmacb Cell[RX_RING_SIZE];
492         u32 RxCpuIdx;
493         u32 RxDmaIdx;
494         int RxSwReadIdx;        /* software next read index */
495 };
496
497 struct rt_rtmp_mgmt_ring {
498         struct rt_rtmp_dmacb Cell[MGMT_RING_SIZE];
499         u32 TxCpuIdx;
500         u32 TxDmaIdx;
501         u32 TxSwFreeIdx;        /* software next free tx index */
502 };
503
504 /* */
505 /*  Statistic counter structure */
506 /* */
507 struct rt_counter_802_3 {
508         /* General Stats */
509         unsigned long GoodTransmits;
510         unsigned long GoodReceives;
511         unsigned long TxErrors;
512         unsigned long RxErrors;
513         unsigned long RxNoBuffer;
514
515         /* Ethernet Stats */
516         unsigned long RcvAlignmentErrors;
517         unsigned long OneCollision;
518         unsigned long MoreCollisions;
519
520 };
521
522 struct rt_counter_802_11 {
523         unsigned long Length;
524         LARGE_INTEGER LastTransmittedFragmentCount;
525         LARGE_INTEGER TransmittedFragmentCount;
526         LARGE_INTEGER MulticastTransmittedFrameCount;
527         LARGE_INTEGER FailedCount;
528         LARGE_INTEGER RetryCount;
529         LARGE_INTEGER MultipleRetryCount;
530         LARGE_INTEGER RTSSuccessCount;
531         LARGE_INTEGER RTSFailureCount;
532         LARGE_INTEGER ACKFailureCount;
533         LARGE_INTEGER FrameDuplicateCount;
534         LARGE_INTEGER ReceivedFragmentCount;
535         LARGE_INTEGER MulticastReceivedFrameCount;
536         LARGE_INTEGER FCSErrorCount;
537 };
538
539 struct rt_counter_ralink {
540         unsigned long TransmittedByteCount;     /* both successful and failure, used to calculate TX throughput */
541         unsigned long ReceivedByteCount;        /* both CRC okay and CRC error, used to calculate RX throughput */
542         unsigned long BeenDisassociatedCount;
543         unsigned long BadCQIAutoRecoveryCount;
544         unsigned long PoorCQIRoamingCount;
545         unsigned long MgmtRingFullCount;
546         unsigned long RxCountSinceLastNULL;
547         unsigned long RxCount;
548         unsigned long RxRingErrCount;
549         unsigned long KickTxCount;
550         unsigned long TxRingErrCount;
551         LARGE_INTEGER RealFcsErrCount;
552         unsigned long PendingNdisPacketCount;
553
554         unsigned long OneSecOsTxCount[NUM_OF_TX_RING];
555         unsigned long OneSecDmaDoneCount[NUM_OF_TX_RING];
556         u32 OneSecTxDoneCount;
557         unsigned long OneSecRxCount;
558         u32 OneSecTxAggregationCount;
559         u32 OneSecRxAggregationCount;
560         u32 OneSecReceivedByteCount;
561         u32 OneSecFrameDuplicateCount;
562
563         u32 OneSecTransmittedByteCount; /* both successful and failure, used to calculate TX throughput */
564         u32 OneSecTxNoRetryOkCount;
565         u32 OneSecTxRetryOkCount;
566         u32 OneSecTxFailCount;
567         u32 OneSecFalseCCACnt;  /* CCA error count, for debug purpose, might move to global counter */
568         u32 OneSecRxOkCnt;      /* RX without error */
569         u32 OneSecRxOkDataCnt;  /* unicast-to-me DATA frame count */
570         u32 OneSecRxFcsErrCnt;  /* CRC error */
571         u32 OneSecBeaconSentCnt;
572         u32 LastOneSecTotalTxCount;     /* OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount */
573         u32 LastOneSecRxOkDataCnt;      /* OneSecRxOkDataCnt */
574         unsigned long DuplicateRcv;
575         unsigned long TxAggCount;
576         unsigned long TxNonAggCount;
577         unsigned long TxAgg1MPDUCount;
578         unsigned long TxAgg2MPDUCount;
579         unsigned long TxAgg3MPDUCount;
580         unsigned long TxAgg4MPDUCount;
581         unsigned long TxAgg5MPDUCount;
582         unsigned long TxAgg6MPDUCount;
583         unsigned long TxAgg7MPDUCount;
584         unsigned long TxAgg8MPDUCount;
585         unsigned long TxAgg9MPDUCount;
586         unsigned long TxAgg10MPDUCount;
587         unsigned long TxAgg11MPDUCount;
588         unsigned long TxAgg12MPDUCount;
589         unsigned long TxAgg13MPDUCount;
590         unsigned long TxAgg14MPDUCount;
591         unsigned long TxAgg15MPDUCount;
592         unsigned long TxAgg16MPDUCount;
593
594         LARGE_INTEGER TransmittedOctetsInAMSDU;
595         LARGE_INTEGER TransmittedAMSDUCount;
596         LARGE_INTEGER ReceivedOctesInAMSDUCount;
597         LARGE_INTEGER ReceivedAMSDUCount;
598         LARGE_INTEGER TransmittedAMPDUCount;
599         LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
600         LARGE_INTEGER TransmittedOctetsInAMPDUCount;
601         LARGE_INTEGER MPDUInReceivedAMPDUCount;
602 };
603
604 struct rt_counter_drs {
605         /* to record the each TX rate's quality. 0 is best, the bigger the worse. */
606         u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
607         u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
608         u8 TxRateUpPenalty;     /* extra # of second penalty due to last unstable condition */
609         unsigned long CurrTxRateStableTime;     /* # of second in current TX rate */
610         BOOLEAN fNoisyEnvironment;
611         BOOLEAN fLastSecAccordingRSSI;
612         u8 LastSecTxRateChangeAction;   /* 0: no change, 1:rate UP, 2:rate down */
613         u8 LastTimeTxRateChangeAction;  /*Keep last time value of LastSecTxRateChangeAction */
614         unsigned long LastTxOkCount;
615 };
616
617 /***************************************************************************
618   *     security key related data structure
619   **************************************************************************/
620 struct rt_cipher_key {
621         u8 Key[16];             /* right now we implement 4 keys, 128 bits max */
622         u8 RxMic[8];            /* make alignment */
623         u8 TxMic[8];
624         u8 TxTsc[6];            /* 48bit TSC value */
625         u8 RxTsc[6];            /* 48bit TSC value */
626         u8 CipherAlg;   /* 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128 */
627         u8 KeyLen;
628         u8 BssId[6];
629         /* Key length for each key, 0: entry is invalid */
630         u8 Type;                /* Indicate Pairwise/Group when reporting MIC error */
631 };
632
633 /* structure to define WPA Group Key Rekey Interval */
634 struct PACKED rt_802_11_wpa_rekey {
635         unsigned long ReKeyMethod;      /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
636         unsigned long ReKeyInterval;    /* time-based: seconds, packet-based: kilo-packets */
637 };
638
639 #ifdef RTMP_MAC_USB
640 /***************************************************************************
641   *     RTUSB I/O related data structure
642   **************************************************************************/
643 struct rt_set_asic_wcid {
644         unsigned long WCID;             /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
645         unsigned long SetTid;           /* time-based: seconds, packet-based: kilo-packets */
646         unsigned long DeleteTid;        /* time-based: seconds, packet-based: kilo-packets */
647         u8 Addr[MAC_ADDR_LEN];  /* avoid in interrupt when write key */
648 };
649
650 struct rt_set_asic_wcid_attri {
651         unsigned long WCID;             /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
652         unsigned long Cipher;           /* ASIC Cipher definition */
653         u8 Addr[ETH_LENGTH_OF_ADDRESS];
654 };
655
656 /* for USB interface, avoid in interrupt when write key */
657 struct rt_add_pairwise_key_entry {
658         u8 MacAddr[6];
659         u16 MacTabMatchWCID;    /* ASIC */
660         struct rt_cipher_key CipherKey;
661 };
662
663 /* Cipher suite type for mixed mode group cipher, P802.11i-2004 */
664 typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
665         Cipher_Type_NONE,
666         Cipher_Type_WEP40,
667         Cipher_Type_TKIP,
668         Cipher_Type_RSVD,
669         Cipher_Type_CCMP,
670         Cipher_Type_WEP104
671 } RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
672 #endif /* RTMP_MAC_USB // */
673
674 struct rt_rogueap_entry {
675         u8 Addr[MAC_ADDR_LEN];
676         u8 ErrorCode[2];        /*00 01-Invalid authentication type */
677         /*00 02-Authentication timeout */
678         /*00 03-Challenge from AP failed */
679         /*00 04-Challenge to AP failed */
680         BOOLEAN Reported;
681 };
682
683 struct rt_rogueap_table {
684         u8 RogueApNr;
685         struct rt_rogueap_entry RogueApEntry[MAX_LEN_OF_BSS_TABLE];
686 };
687
688 /* */
689 /* Cisco IAPP format */
690 /* */
691 struct rt_cisco_iapp_content {
692         u16 Length;             /*IAPP Length */
693         u8 MessageType; /*IAPP type */
694         u8 FunctionCode;        /*IAPP function type */
695         u8 DestinaionMAC[MAC_ADDR_LEN];
696         u8 SourceMAC[MAC_ADDR_LEN];
697         u16 Tag;                /*Tag(element IE) - Adjacent AP report */
698         u16 TagLength;  /*Length of element not including 4 byte header */
699         u8 OUI[4];              /*0x00, 0x40, 0x96, 0x00 */
700         u8 PreviousAP[MAC_ADDR_LEN];    /*MAC Address of access point */
701         u16 Channel;
702         u16 SsidLen;
703         u8 Ssid[MAX_LEN_OF_SSID];
704         u16 Seconds;            /*Seconds that the client has been disassociated. */
705 };
706
707 /*
708   *     Fragment Frame structure
709   */
710 struct rt_fragment_frame {
711         void *pFragPacket;
712         unsigned long RxSize;
713         u16 Sequence;
714         u16 LastFrag;
715         unsigned long Flags;            /* Some extra frame information. bit 0: LLC presented */
716 };
717
718 /* */
719 /* Packet information for NdisQueryPacket */
720 /* */
721 struct rt_packet_info {
722         u32 PhysicalBufferCount;        /* Physical breaks of buffer descripor chained */
723         u32 BufferCount;        /* Number of Buffer descriptor chained */
724         u32 TotalPacketLength;  /* Self explained */
725         char *pFirstBuffer;     /* Pointer to first buffer descriptor */
726 };
727
728 /* */
729 /*  Arcfour Structure Added by PaulWu */
730 /* */
731 struct rt_arcfourcontext {
732         u32 X;
733         u32 Y;
734         u8 STATE[256];
735 };
736
737 /* */
738 /* Tkip Key structure which RC4 key & MIC calculation */
739 /* */
740 struct rt_tkip_key_info {
741         u32 nBytesInM;          /* # bytes in M for MICKEY */
742         unsigned long IV16;
743         unsigned long IV32;
744         unsigned long K0;               /* for MICKEY Low */
745         unsigned long K1;               /* for MICKEY Hig */
746         unsigned long L;                /* Current state for MICKEY */
747         unsigned long R;                /* Current state for MICKEY */
748         unsigned long M;                /* Message accumulator for MICKEY */
749         u8 RC4KEY[16];
750         u8 MIC[8];
751 };
752
753 /* */
754 /* Private / Misc data, counters for driver internal use */
755 /* */
756 struct rt_private {
757         u32 SystemResetCnt;     /* System reset counter */
758         u32 TxRingFullCnt;      /* Tx ring full occurrance number */
759         u32 PhyRxErrCnt;        /* PHY Rx error count, for debug purpose, might move to global counter */
760         /* Variables for WEP encryption / decryption in rtmp_wep.c */
761         u32 FCSCRC32;
762         struct rt_arcfourcontext WEPCONTEXT;
763         /* Tkip stuff */
764         struct rt_tkip_key_info Tx;
765         struct rt_tkip_key_info Rx;
766 };
767
768 /***************************************************************************
769   *     Channel and BBP related data structures
770   **************************************************************************/
771 /* structure to tune BBP R66 (BBP TUNING) */
772 struct rt_bbp_r66_tuning {
773         BOOLEAN bEnable;
774         u16 FalseCcaLowerThreshold;     /* default 100 */
775         u16 FalseCcaUpperThreshold;     /* default 512 */
776         u8 R66Delta;
777         u8 R66CurrentValue;
778         BOOLEAN R66LowerUpperSelect;    /*Before LinkUp, Used LowerBound or UpperBound as R66 value. */
779 };
780
781 /* structure to store channel TX power */
782 struct rt_channel_tx_power {
783         u16 RemainingTimeForUse;        /*unit: sec */
784         u8 Channel;
785         char Power;
786         char Power2;
787         u8 MaxTxPwr;
788         u8 DfsReq;
789 };
790
791 /* structure to store 802.11j channel TX power */
792 struct rt_channel_11j_tx_power {
793         u8 Channel;
794         u8 BW;          /* BW_10 or BW_20 */
795         char Power;
796         char Power2;
797         u16 RemainingTimeForUse;        /*unit: sec */
798 };
799
800 struct rt_soft_rx_ant_diversity {
801         u8 EvaluatePeriod;      /* 0:not evalute status, 1: evaluate status, 2: switching status */
802         u8 EvaluateStableCnt;
803         u8 Pair1PrimaryRxAnt;   /* 0:Ant-E1, 1:Ant-E2 */
804         u8 Pair1SecondaryRxAnt; /* 0:Ant-E1, 1:Ant-E2 */
805         u8 Pair2PrimaryRxAnt;   /* 0:Ant-E3, 1:Ant-E4 */
806         u8 Pair2SecondaryRxAnt; /* 0:Ant-E3, 1:Ant-E4 */
807         short Pair1AvgRssi[2];  /* AvgRssi[0]:E1, AvgRssi[1]:E2 */
808         short Pair2AvgRssi[2];  /* AvgRssi[0]:E3, AvgRssi[1]:E4 */
809         short Pair1LastAvgRssi; /* */
810         short Pair2LastAvgRssi; /* */
811         unsigned long RcvPktNumWhenEvaluate;
812         BOOLEAN FirstPktArrivedWhenEvaluate;
813         struct rt_ralink_timer RxAntDiversityTimer;
814 };
815
816 /***************************************************************************
817   *     structure for radar detection and channel switch
818   **************************************************************************/
819 struct rt_radar_detect {
820         /*BOOLEAN           IEEE80211H;                     // 0: disable, 1: enable IEEE802.11h */
821         u8 CSCount;             /*Channel switch counter */
822         u8 CSPeriod;            /*Channel switch period (beacon count) */
823         u8 RDCount;             /*Radar detection counter */
824         u8 RDMode;              /*Radar Detection mode */
825         u8 RDDurRegion; /*Radar detection duration region */
826         u8 BBPR16;
827         u8 BBPR17;
828         u8 BBPR18;
829         u8 BBPR21;
830         u8 BBPR22;
831         u8 BBPR64;
832         unsigned long InServiceMonitorCount;    /* unit: sec */
833         u8 DfsSessionTime;
834         BOOLEAN bFastDfs;
835         u8 ChMovingTime;
836         u8 LongPulseRadarTh;
837 };
838
839 typedef enum _ABGBAND_STATE_ {
840         UNKNOWN_BAND,
841         BG_BAND,
842         A_BAND,
843 } ABGBAND_STATE;
844
845 #ifdef RTMP_MAC_PCI
846 /* Power save method control */
847 typedef union _PS_CONTROL {
848         struct {
849                 unsigned long EnablePSinIdle:1; /* Enable radio off when not connect to AP. radio on only when sitesurvey, */
850                 unsigned long EnableNewPS:1;    /* Enable new  Chip power save fucntion . New method can only be applied in chip version after 2872. and PCIe. */
851                 unsigned long rt30xxPowerMode:2;        /* Power Level Mode for rt30xx chip */
852                 unsigned long rt30xxFollowHostASPM:1;   /* Card Follows Host's setting for rt30xx chip. */
853                 unsigned long rt30xxForceASPMTest:1;    /* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */
854                 unsigned long rsv:26;   /* Radio Measurement Enable */
855         } field;
856         unsigned long word;
857 } PS_CONTROL, *PPS_CONTROL;
858 #endif /* RTMP_MAC_PCI // */
859
860 /***************************************************************************
861   *     structure for MLME state machine
862   **************************************************************************/
863 struct rt_mlme {
864         /* STA state machines */
865         struct rt_state_machine CntlMachine;
866         struct rt_state_machine AssocMachine;
867         struct rt_state_machine AuthMachine;
868         struct rt_state_machine AuthRspMachine;
869         struct rt_state_machine SyncMachine;
870         struct rt_state_machine WpaPskMachine;
871         struct rt_state_machine LeapMachine;
872         STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
873         STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
874         STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
875         STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
876         STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
877         /* Action */
878         struct rt_state_machine ActMachine;
879
880         /* common WPA state machine */
881         struct rt_state_machine WpaMachine;
882         STATE_MACHINE_FUNC WpaFunc[WPA_FUNC_SIZE];
883
884         unsigned long ChannelQuality;   /* 0..100, Channel Quality Indication for Roaming */
885         unsigned long Now32;            /* latch the value of NdisGetSystemUpTime() */
886         unsigned long LastSendNULLpsmTime;
887
888         BOOLEAN bRunning;
889         spinlock_t TaskLock;
890         struct rt_mlme_queue Queue;
891
892         u32 ShiftReg;
893
894         struct rt_ralink_timer PeriodicTimer;
895         struct rt_ralink_timer APSDPeriodicTimer;
896         struct rt_ralink_timer LinkDownTimer;
897         struct rt_ralink_timer LinkUpTimer;
898 #ifdef RTMP_MAC_PCI
899         u8 bPsPollTimerRunning;
900         struct rt_ralink_timer PsPollTimer;
901         struct rt_ralink_timer RadioOnOffTimer;
902 #endif                          /* RTMP_MAC_PCI // */
903         unsigned long PeriodicRound;
904         unsigned long OneSecPeriodicRound;
905
906         u8 RealRxPath;
907         BOOLEAN bLowThroughput;
908         BOOLEAN bEnableAutoAntennaCheck;
909         struct rt_ralink_timer RxAntEvalTimer;
910
911 #ifdef RT30xx
912         u8 CaliBW40RfR24;
913         u8 CaliBW20RfR24;
914 #endif                          /* RT30xx // */
915
916 #ifdef RTMP_MAC_USB
917         struct rt_ralink_timer AutoWakeupTimer;
918         BOOLEAN AutoWakeupTimerRunning;
919 #endif                          /* RTMP_MAC_USB // */
920 };
921
922 /***************************************************************************
923   *     802.11 N related data structures
924   **************************************************************************/
925 struct reordering_mpdu {
926         struct reordering_mpdu *next;
927         void *pPacket;  /* coverted to 802.3 frame */
928         int Sequence;           /* sequence number of MPDU */
929         BOOLEAN bAMSDU;
930 };
931
932 struct reordering_list {
933         struct reordering_mpdu *next;
934         int qlen;
935 };
936
937 struct reordering_mpdu_pool {
938         void *mem;
939         spinlock_t lock;
940         struct reordering_list freelist;
941 };
942
943 typedef enum _REC_BLOCKACK_STATUS {
944         Recipient_NONE = 0,
945         Recipient_USED,
946         Recipient_HandleRes,
947         Recipient_Accept
948 } REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
949
950 typedef enum _ORI_BLOCKACK_STATUS {
951         Originator_NONE = 0,
952         Originator_USED,
953         Originator_WaitRes,
954         Originator_Done
955 } ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
956
957 struct rt_ba_ori_entry {
958         u8 Wcid;
959         u8 TID;
960         u8 BAWinSize;
961         u8 Token;
962 /* Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header. */
963         u16 Sequence;
964         u16 TimeOutValue;
965         ORI_BLOCKACK_STATUS ORI_BA_Status;
966         struct rt_ralink_timer ORIBATimer;
967         void *pAdapter;
968 };
969
970 struct rt_ba_rec_entry {
971         u8 Wcid;
972         u8 TID;
973         u8 BAWinSize;   /* 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU. */
974         /*u8 NumOfRxPkt; */
975         /*u8    Curindidx; // the head in the RX reordering buffer */
976         u16 LastIndSeq;
977 /*      u16          LastIndSeqAtTimer; */
978         u16 TimeOutValue;
979         struct rt_ralink_timer RECBATimer;
980         unsigned long LastIndSeqAtTimer;
981         unsigned long nDropPacket;
982         unsigned long rcvSeq;
983         REC_BLOCKACK_STATUS REC_BA_Status;
984 /*      u8   RxBufIdxUsed; */
985         /* corresponding virtual address for RX reordering packet storage. */
986         /*RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF]; */
987         spinlock_t RxReRingLock;        /* Rx Ring spinlock */
988 /*      struct _BA_REC_ENTRY *pNext; */
989         void *pAdapter;
990         struct reordering_list list;
991 };
992
993 struct rt_ba_table {
994         unsigned long numAsRecipient;   /* I am recipient of numAsRecipient clients. These client are in the BARecEntry[] */
995         unsigned long numAsOriginator;  /* I am originator of   numAsOriginator clients. These clients are in the BAOriEntry[] */
996         unsigned long numDoneOriginator;        /* count Done Originator sessions */
997         struct rt_ba_ori_entry BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
998         struct rt_ba_rec_entry BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
999 };
1000
1001 /*For QureyBATableOID use; */
1002 struct PACKED rt_oid_ba_rec_entry {
1003         u8 MACAddr[MAC_ADDR_LEN];
1004         u8 BaBitmap;            /* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize */
1005         u8 rsv;
1006         u8 BufSize[8];
1007         REC_BLOCKACK_STATUS REC_BA_Status[8];
1008 };
1009
1010 /*For QureyBATableOID use; */
1011 struct PACKED rt_oid_ba_ori_entry {
1012         u8 MACAddr[MAC_ADDR_LEN];
1013         u8 BaBitmap;            /* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status */
1014         u8 rsv;
1015         u8 BufSize[8];
1016         ORI_BLOCKACK_STATUS ORI_BA_Status[8];
1017 };
1018
1019 struct rt_queryba_table {
1020         struct rt_oid_ba_ori_entry BAOriEntry[32];
1021         struct rt_oid_ba_rec_entry BARecEntry[32];
1022         u8 OriNum;              /* Number of below BAOriEntry */
1023         u8 RecNum;              /* Number of below BARecEntry */
1024 };
1025
1026 typedef union _BACAP_STRUC {
1027         struct {
1028                 u32 RxBAWinLimit:8;
1029                 u32 TxBAWinLimit:8;
1030                 u32 AutoBA:1;   /* automatically BA */
1031                 u32 Policy:2;   /* 0: DELAY_BA 1:IMMED_BA  (//BA Policy subfiled value in ADDBA frame)   2:BA-not use */
1032                 u32 MpduDensity:3;
1033                 u32 AmsduEnable:1;      /*Enable AMSDU transmisstion */
1034                 u32 AmsduSize:1;        /* 0:3839, 1:7935 bytes. u32  MSDUSizeToBytes[]        = { 3839, 7935}; */
1035                 u32 MMPSmode:2; /* MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable */
1036                 u32 bHtAdhoc:1; /* adhoc can use ht rate. */
1037                 u32 b2040CoexistScanSup:1;      /*As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz. */
1038                 u32: 4;
1039         } field;
1040         u32 word;
1041 } BACAP_STRUC, *PBACAP_STRUC;
1042
1043 struct rt_oid_add_ba_entry {
1044         BOOLEAN IsRecipient;
1045         u8 MACAddr[MAC_ADDR_LEN];
1046         u8 TID;
1047         u8 nMSDU;
1048         u16 TimeOut;
1049         BOOLEAN bAllTid;        /* If True, delete all TID for BA sessions with this MACaddr. */
1050 };
1051
1052 #define IS_HT_STA(_pMacEntry)   \
1053         (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
1054
1055 #define IS_HT_RATE(_pMacEntry)  \
1056         (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1057
1058 #define PEER_IS_HT_RATE(_pMacEntry)     \
1059         (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1060
1061 /*This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second.  (Details see MLMEPeriodic) */
1062 struct rt_iot {
1063         u8 Threshold[2];
1064         u8 ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE];  /* compare with threshold[0] */
1065         u8 RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; /* compare with threshold[1] */
1066         unsigned long OneSecInWindowCount;
1067         unsigned long OneSecFrameDuplicateCount;
1068         unsigned long OneSecOutWindowCount;
1069         u8 DelOriAct;
1070         u8 DelRecAct;
1071         u8 RTSShortProt;
1072         u8 RTSLongProt;
1073         BOOLEAN bRTSLongProtOn;
1074         BOOLEAN bLastAtheros;
1075         BOOLEAN bCurrentAtheros;
1076         BOOLEAN bNowAtherosBurstOn;
1077         BOOLEAN bNextDisableRxBA;
1078         BOOLEAN bToggle;
1079 };
1080
1081 /* This is the registry setting for 802.11n transmit setting.  Used in advanced page. */
1082 typedef union _REG_TRANSMIT_SETTING {
1083         struct {
1084                 /*u32  PhyMode:4; */
1085                 /*u32  MCS:7;                 // MCS */
1086                 u32 rsv0:10;
1087                 u32 TxBF:1;
1088                 u32 BW:1;       /*channel bandwidth 20MHz or 40 MHz */
1089                 u32 ShortGI:1;
1090                 u32 STBC:1;     /*SPACE */
1091                 u32 TRANSNO:2;
1092                 u32 HTMODE:1;
1093                 u32 EXTCHA:2;
1094                 u32 rsv:13;
1095         } field;
1096         u32 word;
1097 } REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
1098
1099 typedef union _DESIRED_TRANSMIT_SETTING {
1100         struct {
1101                 u16 MCS:7;      /* MCS */
1102                 u16 PhyMode:4;
1103                 u16 FixedTxMode:2;      /* If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode. */
1104                 u16 rsv:3;
1105         } field;
1106         u16 word;
1107 } DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
1108
1109 #ifdef RTMP_MAC_USB
1110 /***************************************************************************
1111   *     USB-based chip Beacon related data structures
1112   **************************************************************************/
1113 #define BEACON_BITMAP_MASK              0xff
1114 struct rt_beacon_sync {
1115         u8 BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET];
1116         u8 BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE];
1117         unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
1118         unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
1119         BOOLEAN EnableBeacon;   /* trigger to enable beacon transmission. */
1120         u8 BeaconBitMap;        /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */
1121         u8 DtimBitOn;   /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */
1122 };
1123 #endif /* RTMP_MAC_USB // */
1124
1125 /***************************************************************************
1126   *     Multiple SSID related data structures
1127   **************************************************************************/
1128 #define WLAN_MAX_NUM_OF_TIM                     ((MAX_LEN_OF_MAC_TABLE >> 3) + 1)       /* /8 + 1 */
1129 #define WLAN_CT_TIM_BCMC_OFFSET         0       /* unit: 32B */
1130
1131 /* clear bcmc TIM bit */
1132 #define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
1133         pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
1134
1135 /* set bcmc TIM bit */
1136 #define WLAN_MR_TIM_BCMC_SET(apidx) \
1137         pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
1138
1139 /* clear a station PS TIM bit */
1140 #define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
1141         {       u8 tim_offset = wcid >> 3; \
1142                 u8 bit_offset = wcid & 0x7; \
1143                 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
1144
1145 /* set a station PS TIM bit */
1146 #define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
1147         {       u8 tim_offset = wcid >> 3; \
1148                 u8 bit_offset = wcid & 0x7; \
1149                 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
1150
1151 /* configuration common to OPMODE_AP as well as OPMODE_STA */
1152 struct rt_common_config {
1153
1154         BOOLEAN bCountryFlag;
1155         u8 CountryCode[3];
1156         u8 Geography;
1157         u8 CountryRegion;       /* Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel */
1158         u8 CountryRegionForABand;       /* Enum of country region for A band */
1159         u8 PhyMode;             /* PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED */
1160         u16 Dsifs;              /* in units of usec */
1161         unsigned long PacketFilter;     /* Packet filter for receiving */
1162         u8 RegulatoryClass;
1163
1164         char Ssid[MAX_LEN_OF_SSID];     /* NOT NULL-terminated */
1165         u8 SsidLen;             /* the actual ssid length in used */
1166         u8 LastSsidLen; /* the actual ssid length in used */
1167         char LastSsid[MAX_LEN_OF_SSID]; /* NOT NULL-terminated */
1168         u8 LastBssid[MAC_ADDR_LEN];
1169
1170         u8 Bssid[MAC_ADDR_LEN];
1171         u16 BeaconPeriod;
1172         u8 Channel;
1173         u8 CentralChannel;      /* Central Channel when using 40MHz is indicating. not real channel. */
1174
1175         u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1176         u8 SupRateLen;
1177         u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1178         u8 ExtRateLen;
1179         u8 DesireRate[MAX_LEN_OF_SUPPORTED_RATES];      /* OID_802_11_DESIRED_RATES */
1180         u8 MaxDesiredRate;
1181         u8 ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
1182
1183         unsigned long BasicRateBitmap;  /* backup basic ratebitmap */
1184
1185         BOOLEAN bAPSDCapable;
1186         BOOLEAN bInServicePeriod;
1187         BOOLEAN bAPSDAC_BE;
1188         BOOLEAN bAPSDAC_BK;
1189         BOOLEAN bAPSDAC_VI;
1190         BOOLEAN bAPSDAC_VO;
1191
1192         /* because TSPEC can modify the APSD flag, we need to keep the APSD flag
1193            requested in association stage from the station;
1194            we need to recover the APSD flag after the TSPEC is deleted. */
1195         BOOLEAN bACMAPSDBackup[4];      /* for delivery-enabled & trigger-enabled both */
1196         BOOLEAN bACMAPSDTr[4];  /* no use */
1197
1198         BOOLEAN bNeedSendTriggerFrame;
1199         BOOLEAN bAPSDForcePowerSave;    /* Force power save mode, should only use in APSD-STAUT */
1200         unsigned long TriggerTimerCount;
1201         u8 MaxSPLength;
1202         u8 BBPCurrentBW;        /* BW_10,       BW_20, BW_40 */
1203         /* move to MULTISSID_STRUCT for MBSS */
1204         /*HTTRANSMIT_SETTING    HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI. */
1205         REG_TRANSMIT_SETTING RegTransmitSetting;        /*registry transmit setting. this is for reading registry setting only. not useful. */
1206         /*u8       FixedTxMode;              // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode */
1207         u8 TxRate;              /* Same value to fill in TXD. TxRate is 6-bit */
1208         u8 MaxTxRate;   /* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1209         u8 TxRateIndex; /* Tx rate index in RateSwitchTable */
1210         u8 TxRateTableSize;     /* Valid Tx rate table size in RateSwitchTable */
1211         /*BOOLEAN               bAutoTxRateSwitch; */
1212         u8 MinTxRate;   /* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1213         u8 RtsRate;             /* RATE_xxx */
1214         HTTRANSMIT_SETTING MlmeTransmit;        /* MGMT frame PHY rate setting when operatin at Ht rate. */
1215         u8 MlmeRate;            /* RATE_xxx, used to send MLME frames */
1216         u8 BasicMlmeRate;       /* Default Rate for sending MLME frames */
1217
1218         u16 RtsThreshold;       /* in unit of BYTE */
1219         u16 FragmentThreshold;  /* in unit of BYTE */
1220
1221         u8 TxPower;             /* in unit of mW */
1222         unsigned long TxPowerPercentage;        /* 0~100 % */
1223         unsigned long TxPowerDefault;   /* keep for TxPowerPercentage */
1224         u8 PwrConstraint;
1225
1226         BACAP_STRUC BACapability;       /*   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0 */
1227         BACAP_STRUC REGBACapability;    /*   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0 */
1228
1229         struct rt_iot IOTestParm;       /* 802.11n InterOpbility Test Parameter; */
1230         unsigned long TxPreamble;       /* Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto */
1231         BOOLEAN bUseZeroToDisableFragment;      /* Microsoft use 0 as disable */
1232         unsigned long UseBGProtection;  /* 0: auto, 1: always use, 2: always not use */
1233         BOOLEAN bUseShortSlotTime;      /* 0: disable, 1 - use short slot (9us) */
1234         BOOLEAN bEnableTxBurst; /* 1: enble TX PACKET BURST (when BA is established or AP is not a legacy WMM AP), 0: disable TX PACKET BURST */
1235         BOOLEAN bAggregationCapable;    /* 1: enable TX aggregation when the peer supports it */
1236         BOOLEAN bPiggyBackCapable;      /* 1: enable TX piggy-back according MAC's version */
1237         BOOLEAN bIEEE80211H;    /* 1: enable IEEE802.11h spec. */
1238         unsigned long DisableOLBCDetect;        /* 0: enable OLBC detect; 1 disable OLBC detect */
1239
1240         BOOLEAN bRdg;
1241
1242         BOOLEAN bWmmCapable;    /* 0:disable WMM, 1:enable WMM */
1243         struct rt_qos_capability_parm APQosCapability;  /* QOS capability of the current associated AP */
1244         struct rt_edca_parm APEdcaParm; /* EDCA parameters of the current associated AP */
1245         struct rt_qbss_load_parm APQbssLoad;    /* QBSS load of the current associated AP */
1246         u8 AckPolicy[4];        /* ACK policy of the specified AC. see ACK_xxx */
1247         BOOLEAN bDLSCapable;    /* 0:disable DLS, 1:enable DLS */
1248         /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1249         /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1250         /* OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros. */
1251         /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition */
1252         unsigned long OpStatusFlags;
1253
1254         BOOLEAN NdisRadioStateOff;      /*For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff. */
1255         ABGBAND_STATE BandState;        /* For setting BBP used on B/G or A mode. */
1256
1257         /* IEEE802.11H--DFS. */
1258         struct rt_radar_detect RadarDetect;
1259
1260         /* HT */
1261         u8 BASize;              /* USer desired BAWindowSize. Should not exceed our max capability */
1262         /*struct rt_ht_capability      SupportedHtPhy; */
1263         struct rt_ht_capability DesiredHtPhy;
1264         struct rt_ht_capability_ie HtCapability;
1265         struct rt_add_ht_info_ie AddHTInfo;     /* Useful as AP. */
1266         /*This IE is used with channel switch announcement element when changing to a new 40MHz. */
1267         /*This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp. */
1268         struct rt_new_ext_chan_ie NewExtChanOffset;     /*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */
1269
1270         BOOLEAN bHTProtect;
1271         BOOLEAN bMIMOPSEnable;
1272         BOOLEAN bBADecline;
1273 /*2008/11/05: KH add to support Antenna power-saving of AP<-- */
1274         BOOLEAN bGreenAPEnable;
1275 /*2008/11/05: KH add to support Antenna power-saving of AP--> */
1276         BOOLEAN bDisableReordering;
1277         BOOLEAN bForty_Mhz_Intolerant;
1278         BOOLEAN bExtChannelSwitchAnnouncement;
1279         BOOLEAN bRcvBSSWidthTriggerEvents;
1280         unsigned long LastRcvBSSWidthTriggerEventsTime;
1281
1282         u8 TxBASize;
1283
1284         /* Enable wireless event */
1285         BOOLEAN bWirelessEvent;
1286         BOOLEAN bWiFiTest;      /* Enable this parameter for WiFi test */
1287
1288         /* Tx & Rx Stream number selection */
1289         u8 TxStream;
1290         u8 RxStream;
1291
1292         BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */
1293
1294 #ifdef RTMP_MAC_USB
1295         BOOLEAN bMultipleIRP;   /* Multiple Bulk IN flag */
1296         u8 NumOfBulkInIRP;      /* if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1 */
1297         struct rt_ht_capability SupportedHtPhy;
1298         unsigned long MaxPktOneTxBulk;
1299         u8 TxBulkFactor;
1300         u8 RxBulkFactor;
1301
1302         BOOLEAN IsUpdateBeacon;
1303         struct rt_beacon_sync *pBeaconSync;
1304         struct rt_ralink_timer BeaconUpdateTimer;
1305         u32 BeaconAdjust;
1306         u32 BeaconFactor;
1307         u32 BeaconRemain;
1308 #endif                          /* RTMP_MAC_USB // */
1309
1310         spinlock_t MeasureReqTabLock;
1311         struct rt_measure_req_tab *pMeasureReqTab;
1312
1313         spinlock_t TpcReqTabLock;
1314         struct rt_tpc_req_tab *pTpcReqTab;
1315
1316         BOOLEAN PSPXlink;       /* 0: Disable. 1: Enable */
1317
1318 #if defined(RT305x) || defined(RT30xx)
1319         /* request by Gary, for High Power issue */
1320         u8 HighPowerPatchDisabled;
1321 #endif
1322
1323         BOOLEAN HT_DisallowTKIP;        /* Restrict the encryption type in 11n HT mode */
1324 };
1325
1326 /* Modified by Wu Xi-Kun 4/21/2006 */
1327 /* STA configuration and status */
1328 struct rt_sta_admin_config {
1329         /* GROUP 1 - */
1330         /*   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1331         /*   the user intended configuration, but not necessary fully equal to the final */
1332         /*   settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either */
1333         /*   AP or IBSS holder). */
1334         /*   Once initialized, user configuration can only be changed via OID_xxx */
1335         u8 BssType;             /* BSS_INFRA or BSS_ADHOC */
1336         u16 AtimWin;            /* used when starting a new IBSS */
1337
1338         /* GROUP 2 - */
1339         /*   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1340         /*   the user intended configuration, and should be always applied to the final */
1341         /*   settings in ACTIVE BSS without compromising with the BSS holder. */
1342         /*   Once initialized, user configuration can only be changed via OID_xxx */
1343         u8 RssiTrigger;
1344         u8 RssiTriggerMode;     /* RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD */
1345         u16 DefaultListenCount; /* default listen count; */
1346         unsigned long WindowsPowerMode; /* Power mode for AC power */
1347         unsigned long WindowsBatteryPowerMode;  /* Power mode for battery if exists */
1348         BOOLEAN bWindowsACCAMEnable;    /* Enable CAM power mode when AC on */
1349         BOOLEAN bAutoReconnect; /* Set to TRUE when setting OID_802_11_SSID with no matching BSSID */
1350         unsigned long WindowsPowerProfile;      /* Windows power profile, for NDIS5.1 PnP */
1351
1352         /* MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1) */
1353         u16 Psm;                /* power management mode   (PWR_ACTIVE|PWR_SAVE) */
1354         u16 DisassocReason;
1355         u8 DisassocSta[MAC_ADDR_LEN];
1356         u16 DeauthReason;
1357         u8 DeauthSta[MAC_ADDR_LEN];
1358         u16 AuthFailReason;
1359         u8 AuthFailSta[MAC_ADDR_LEN];
1360
1361         NDIS_802_11_PRIVACY_FILTER PrivacyFilter;       /* PrivacyFilter enum for 802.1X */
1362         NDIS_802_11_AUTHENTICATION_MODE AuthMode;       /* This should match to whatever microsoft defined */
1363         NDIS_802_11_WEP_STATUS WepStatus;
1364         NDIS_802_11_WEP_STATUS OrigWepStatus;   /* Original wep status set from OID */
1365
1366         /* Add to support different cipher suite for WPA2/WPA mode */
1367         NDIS_802_11_ENCRYPTION_STATUS GroupCipher;      /* Multicast cipher suite */
1368         NDIS_802_11_ENCRYPTION_STATUS PairCipher;       /* Unicast cipher suite */
1369         BOOLEAN bMixCipher;     /* Indicate current Pair & Group use different cipher suites */
1370         u16 RsnCapability;
1371
1372         NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1373
1374         u8 WpaPassPhrase[64];   /* WPA PSK pass phrase */
1375         u32 WpaPassPhraseLen;   /* the length of WPA PSK pass phrase */
1376         u8 PMK[32];             /* WPA PSK mode PMK */
1377         u8 PTK[64];             /* WPA PSK mode PTK */
1378         u8 GTK[32];             /* GTK from authenticator */
1379         struct rt_bssid_info SavedPMK[PMKID_NO];
1380         u32 SavedPMKNum;        /* Saved PMKID number */
1381
1382         u8 DefaultKeyId;
1383
1384         /* WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED */
1385         u8 PortSecured;
1386
1387         /* For WPA countermeasures */
1388         unsigned long LastMicErrorTime; /* record last MIC error time */
1389         unsigned long MicErrCnt;        /* Should be 0, 1, 2, then reset to zero (after disassoiciation). */
1390         BOOLEAN bBlockAssoc;    /* Block associate attempt for 60 seconds after counter measure occurred. */
1391         /* For WPA-PSK supplicant state */
1392         WPA_STATE WpaState;     /* Default is SS_NOTUSE and handled by microsoft 802.1x */
1393         u8 ReplayCounter[8];
1394         u8 ANonce[32];  /* ANonce for WPA-PSK from aurhenticator */
1395         u8 SNonce[32];  /* SNonce for WPA-PSK */
1396
1397         u8 LastSNR0;            /* last received BEACON's SNR */
1398         u8 LastSNR1;            /* last received BEACON's SNR for 2nd  antenna */
1399         struct rt_rssi_sample RssiSample;
1400         unsigned long NumOfAvgRssiSample;
1401
1402         unsigned long LastBeaconRxTime; /* OS's timestamp of the last BEACON RX time */
1403         unsigned long Last11bBeaconRxTime;      /* OS's timestamp of the last 11B BEACON RX time */
1404         unsigned long Last11gBeaconRxTime;      /* OS's timestamp of the last 11G BEACON RX time */
1405         unsigned long Last20NBeaconRxTime;      /* OS's timestamp of the last 20MHz N BEACON RX time */
1406
1407         unsigned long LastScanTime;     /* Record last scan time for issue BSSID_SCAN_LIST */
1408         unsigned long ScanCnt;          /* Scan counts since most recent SSID, BSSID, SCAN OID request */
1409         BOOLEAN bSwRadio;       /* Software controlled Radio On/Off, TRUE: On */
1410         BOOLEAN bHwRadio;       /* Hardware controlled Radio On/Off, TRUE: On */
1411         BOOLEAN bRadio;         /* Radio state, And of Sw & Hw radio state */
1412         BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */
1413         BOOLEAN bShowHiddenSSID;        /* Show all known SSID in SSID list get operation */
1414
1415         /* New for WPA, windows want us to keep association information and */
1416         /* Fixed IEs from last association response */
1417         struct rt_ndis_802_11_association_information AssocInfo;
1418         u16 ReqVarIELen;        /* Length of next VIE include EID & Length */
1419         u8 ReqVarIEs[MAX_VIE_LEN];      /* The content saved here should be little-endian format. */
1420         u16 ResVarIELen;        /* Length of next VIE include EID & Length */
1421         u8 ResVarIEs[MAX_VIE_LEN];
1422
1423         u8 RSNIE_Len;
1424         u8 RSN_IE[MAX_LEN_OF_RSNIE];    /* The content saved here should be little-endian format. */
1425
1426         unsigned long CLBusyBytes;      /* Save the total bytes received durning channel load scan time */
1427         u16 RPIDensity[8];      /* Array for RPI density collection */
1428
1429         u8 RMReqCnt;            /* Number of measurement request saved. */
1430         u8 CurrentRMReqIdx;     /* Number of measurement request saved. */
1431         BOOLEAN ParallelReq;    /* Parallel measurement, only one request performed, */
1432         /* It must be the same channel with maximum duration */
1433         u16 ParallelDuration;   /* Maximum duration for parallel measurement */
1434         u8 ParallelChannel;     /* Only one channel with parallel measurement */
1435         u16 IAPPToken;  /* IAPP dialog token */
1436         /* Hack for channel load and noise histogram parameters */
1437         u8 NHFactor;            /* Parameter for Noise histogram */
1438         u8 CLFactor;            /* Parameter for channel load */
1439
1440         struct rt_ralink_timer StaQuickResponeForRateUpTimer;
1441         BOOLEAN StaQuickResponeForRateUpTimerRunning;
1442
1443         u8 DtimCount;   /* 0.. DtimPeriod-1 */
1444         u8 DtimPeriod;  /* default = 3 */
1445
1446         /*////////////////////////////////////////////////////////////////////////////////////// */
1447         /* This is only for WHQL test. */
1448         BOOLEAN WhqlTest;
1449         /*////////////////////////////////////////////////////////////////////////////////////// */
1450
1451         struct rt_ralink_timer WpaDisassocAndBlockAssocTimer;
1452         /* Fast Roaming */
1453         BOOLEAN bAutoRoaming;   /* 0:disable auto roaming by RSSI, 1:enable auto roaming by RSSI */
1454         char dBmToRoam;         /* the condition to roam when receiving Rssi less than this value. It's negative value. */
1455
1456         BOOLEAN IEEE8021X;
1457         BOOLEAN IEEE8021x_required_keys;
1458         struct rt_cipher_key DesireSharedKey[4];        /* Record user desired WEP keys */
1459         u8 DesireSharedKeyId;
1460
1461         /* 0: driver ignores wpa_supplicant */
1462         /* 1: wpa_supplicant initiates scanning and AP selection */
1463         /* 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters */
1464         u8 WpaSupplicantUP;
1465         u8 WpaSupplicantScanCount;
1466         BOOLEAN bRSN_IE_FromWpaSupplicant;
1467
1468         char dev_name[16];
1469         u16 OriDevType;
1470
1471         BOOLEAN bTGnWifiTest;
1472         BOOLEAN bScanReqIsFromWebUI;
1473
1474         HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;       /* For transmit phy setting in TXWI. */
1475         DESIRED_TRANSMIT_SETTING DesiredTransmitSetting;
1476         struct rt_ht_phy_info DesiredHtPhyInfo;
1477         BOOLEAN bAutoTxRateSwitch;
1478
1479 #ifdef RTMP_MAC_PCI
1480         u8 BBPR3;
1481         /* PS Control has 2 meanings for advanced power save function. */
1482         /* 1. EnablePSinIdle : When no connection, always radio off except need to do site survey. */
1483         /* 2. EnableNewPS  : will save more current in sleep or radio off mode. */
1484         PS_CONTROL PSControl;
1485 #endif                          /* RTMP_MAC_PCI // */
1486
1487         BOOLEAN bAutoConnectByBssid;
1488         unsigned long BeaconLostTime;   /* seconds */
1489         BOOLEAN bForceTxBurst;  /* 1: force enble TX PACKET BURST, 0: disable */
1490 };
1491
1492 /* This data structure keep the current active BSS/IBSS's configuration that this STA */
1493 /* had agreed upon joining the network. Which means these parameters are usually decided */
1494 /* by the BSS/IBSS creator instead of user configuration. Data in this data structurre */
1495 /* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */
1496 /* Normally, after SCAN or failed roaming attempts, we need to recover back to */
1497 /* the current active settings. */
1498 struct rt_sta_active_config {
1499         u16 Aid;
1500         u16 AtimWin;            /* in kusec; IBSS parameter set element */
1501         u16 CapabilityInfo;
1502         u16 CfpMaxDuration;
1503         u16 CfpPeriod;
1504
1505         /* Copy supported rate from desired AP's beacon. We are trying to match */
1506         /* AP's supported and extended rate settings. */
1507         u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1508         u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1509         u8 SupRateLen;
1510         u8 ExtRateLen;
1511         /* Copy supported ht from desired AP's beacon. We are trying to match */
1512         struct rt_ht_phy_info SupportedPhyInfo;
1513         struct rt_ht_capability SupportedHtPhy;
1514 };
1515
1516 struct rt_mac_table_entry;
1517
1518 struct rt_mac_table_entry {
1519         /*Choose 1 from ValidAsWDS and ValidAsCLI  to validize. */
1520         BOOLEAN ValidAsCLI;     /* Sta mode, set this TRUE after Linkup,too. */
1521         BOOLEAN ValidAsWDS;     /* This is WDS Entry. only for AP mode. */
1522         BOOLEAN ValidAsApCli;   /*This is a AP-Client entry, only for AP mode which enable AP-Client functions. */
1523         BOOLEAN ValidAsMesh;
1524         BOOLEAN ValidAsDls;     /* This is DLS Entry. only for STA mode. */
1525         BOOLEAN isCached;
1526         BOOLEAN bIAmBadAtheros; /* Flag if this is Atheros chip that has IOT problem.  We need to turn on RTS/CTS protection. */
1527
1528         u8 EnqueueEapolStartTimerRunning;       /* Enqueue EAPoL-Start for triggering EAP SM */
1529         /*jan for wpa */
1530         /* record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB */
1531         u8 CMTimerRunning;
1532         u8 apidx;               /* MBSS number */
1533         u8 RSNIE_Len;
1534         u8 RSN_IE[MAX_LEN_OF_RSNIE];
1535         u8 ANonce[LEN_KEY_DESC_NONCE];
1536         u8 SNonce[LEN_KEY_DESC_NONCE];
1537         u8 R_Counter[LEN_KEY_DESC_REPLAY];
1538         u8 PTK[64];
1539         u8 ReTryCounter;
1540         struct rt_ralink_timer RetryTimer;
1541         struct rt_ralink_timer EnqueueStartForPSKTimer; /* A timer which enqueue EAPoL-Start for triggering PSK SM */
1542         NDIS_802_11_AUTHENTICATION_MODE AuthMode;       /* This should match to whatever microsoft defined */
1543         NDIS_802_11_WEP_STATUS WepStatus;
1544         NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1545         AP_WPA_STATE WpaState;
1546         GTK_STATE GTKState;
1547         u16 PortSecured;
1548         NDIS_802_11_PRIVACY_FILTER PrivacyFilter;       /* PrivacyFilter enum for 802.1X */
1549         struct rt_cipher_key PairwiseKey;
1550         void *pAd;
1551         int PMKID_CacheIdx;
1552         u8 PMKID[LEN_PMKID];
1553
1554         u8 Addr[MAC_ADDR_LEN];
1555         u8 PsMode;
1556         SST Sst;
1557         AUTH_STATE AuthState;   /* for SHARED KEY authentication state machine used only */
1558         BOOLEAN IsReassocSta;   /* Indicate whether this is a reassociation procedure */
1559         u16 Aid;
1560         u16 CapabilityInfo;
1561         u8 LastRssi;
1562         unsigned long NoDataIdleCount;
1563         u16 StationKeepAliveCount;      /* unit: second */
1564         unsigned long PsQIdleCount;
1565         struct rt_queue_header PsQueue;
1566
1567         u32 StaConnectTime;     /* the live time of this station since associated with AP */
1568
1569         BOOLEAN bSendBAR;
1570         u16 NoBADataCountDown;
1571
1572         u32 CachedBuf[16];      /* u32 (4 bytes) for alignment */
1573         u32 TxBFCount;          /* 3*3 */
1574         u32 FIFOCount;
1575         u32 DebugFIFOCount;
1576         u32 DebugTxCount;
1577         BOOLEAN bDlsInit;
1578
1579 /*==================================================== */
1580 /*WDS entry needs these */
1581 /* if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab */
1582         u32 MatchWDSTabIdx;
1583         u8 MaxSupportedRate;
1584         u8 CurrTxRate;
1585         u8 CurrTxRateIndex;
1586         /* to record the each TX rate's quality. 0 is best, the bigger the worse. */
1587         u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
1588 /*      u16          OneSecTxOkCount; */
1589         u32 OneSecTxNoRetryOkCount;
1590         u32 OneSecTxRetryOkCount;
1591         u32 OneSecTxFailCount;
1592         u32 ContinueTxFailCnt;
1593         u32 CurrTxRateStableTime;       /* # of second in current TX rate */
1594         u8 TxRateUpPenalty;     /* extra # of second penalty due to last unstable condition */
1595 /*==================================================== */
1596
1597         BOOLEAN fNoisyEnvironment;
1598         BOOLEAN fLastSecAccordingRSSI;
1599         u8 LastSecTxRateChangeAction;   /* 0: no change, 1:rate UP, 2:rate down */
1600         char LastTimeTxRateChangeAction;        /*Keep last time value of LastSecTxRateChangeAction */
1601         unsigned long LastTxOkCount;
1602         u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
1603
1604         /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1605         /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1606         /* CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros. */
1607         /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED */
1608         unsigned long ClientStatusFlags;
1609
1610         HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;       /* For transmit phy setting in TXWI. */
1611
1612         /* HT EWC MIMO-N used parameters */
1613         u16 RXBAbitmap; /* fill to on-chip  RXWI_BA_BITMASK in 8.1.3RX attribute entry format */
1614         u16 TXBAbitmap; /* This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI */
1615         u16 TXAutoBAbitmap;
1616         u16 BADeclineBitmap;
1617         u16 BARecWcidArray[NUM_OF_TID]; /* The mapping wcid of recipient session. if RXBAbitmap bit is masked */
1618         u16 BAOriWcidArray[NUM_OF_TID]; /* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1619         u16 BAOriSequence[NUM_OF_TID];  /* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1620
1621         /* 802.11n features. */
1622         u8 MpduDensity;
1623         u8 MaxRAmpduFactor;
1624         u8 AMsduSize;
1625         u8 MmpsMode;            /* MIMO power save more. */
1626
1627         struct rt_ht_capability_ie HTCapability;
1628
1629         BOOLEAN bAutoTxRateSwitch;
1630
1631         u8 RateLen;
1632         struct rt_mac_table_entry *pNext;
1633         u16 TxSeq[NUM_OF_TID];
1634         u16 NonQosDataSeq;
1635
1636         struct rt_rssi_sample RssiSample;
1637
1638         u32 TXMCSExpected[16];
1639         u32 TXMCSSuccessful[16];
1640         u32 TXMCSFailed[16];
1641         u32 TXMCSAutoFallBack[16][16];
1642
1643         unsigned long LastBeaconRxTime;
1644
1645         unsigned long AssocDeadLine;
1646 };
1647
1648 struct rt_mac_table {
1649         u16 Size;
1650         struct rt_mac_table_entry *Hash[HASH_TABLE_SIZE];
1651         struct rt_mac_table_entry Content[MAX_LEN_OF_MAC_TABLE];
1652         struct rt_queue_header McastPsQueue;
1653         unsigned long PsQIdleCount;
1654         BOOLEAN fAnyStationInPsm;
1655         BOOLEAN fAnyStationBadAtheros;  /* Check if any Station is atheros 802.11n Chip.  We need to use RTS/CTS with Atheros 802,.11n chip. */
1656         BOOLEAN fAnyTxOPForceDisable;   /* Check if it is necessary to disable BE TxOP */
1657         BOOLEAN fAllStationAsRalink;    /* Check if all stations are ralink-chipset */
1658         BOOLEAN fAnyStationIsLegacy;    /* Check if I use legacy rate to transmit to my BSS Station/ */
1659         BOOLEAN fAnyStationNonGF;       /* Check if any Station can't support GF. */
1660         BOOLEAN fAnyStation20Only;      /* Check if any Station can't support GF. */
1661         BOOLEAN fAnyStationMIMOPSDynamic;       /* Check if any Station is MIMO Dynamic */
1662         BOOLEAN fAnyBASession;  /* Check if there is BA session.  Force turn on RTS/CTS */
1663 /*2008/10/28: KH add to support Antenna power-saving of AP<-- */
1664 /*2008/10/28: KH add to support Antenna power-saving of AP--> */
1665 };
1666
1667 struct wificonf {
1668         BOOLEAN bShortGI;
1669         BOOLEAN bGreenField;
1670 };
1671
1672 struct rt_rtmp_dev_info {
1673         u8 chipName[16];
1674         RTMP_INF_TYPE infType;
1675 };
1676
1677 struct rt_rtmp_chip_op {
1678         /*  Calibration access related callback functions */
1679         int (*eeinit) (struct rt_rtmp_adapter *pAd);    /* int (*eeinit)(struct rt_rtmp_adapter *pAd); */
1680         int (*eeread) (struct rt_rtmp_adapter *pAd, u16 offset, u16 *pValue);   /* int (*eeread)(struct rt_rtmp_adapter *pAd, int offset, u16 *pValue); */
1681
1682         /* MCU related callback functions */
1683         int (*loadFirmware) (struct rt_rtmp_adapter *pAd);      /* int (*loadFirmware)(struct rt_rtmp_adapter *pAd); */
1684         int (*eraseFirmware) (struct rt_rtmp_adapter *pAd);     /* int (*eraseFirmware)(struct rt_rtmp_adapter *pAd); */
1685         int (*sendCommandToMcu) (struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1);;     /* int (*sendCommandToMcu)(struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1); */
1686
1687         /* RF access related callback functions */
1688         struct rt_reg_pair *pRFRegTable;
1689         void (*AsicRfInit) (struct rt_rtmp_adapter *pAd);
1690         void (*AsicRfTurnOn) (struct rt_rtmp_adapter *pAd);
1691         void (*AsicRfTurnOff) (struct rt_rtmp_adapter *pAd);
1692         void (*AsicReverseRfFromSleepMode) (struct rt_rtmp_adapter *pAd);
1693         void (*AsicHaltAction) (struct rt_rtmp_adapter *pAd);
1694 };
1695
1696 /* */
1697 /*  The miniport adapter structure */
1698 /* */
1699 struct rt_rtmp_adapter {
1700         void *OS_Cookie;        /* save specific structure relative to OS */
1701         struct net_device *net_dev;
1702         unsigned long VirtualIfCnt;
1703         const struct firmware *firmware;
1704
1705         struct rt_rtmp_chip_op chipOps;
1706         u16 ThisTbttNumToNextWakeUp;
1707
1708 #ifdef RTMP_MAC_PCI
1709 /*****************************************************************************************/
1710 /*      PCI related parameters                                                                                                                            */
1711 /*****************************************************************************************/
1712         u8 *CSRBaseAddress;     /* PCI MMIO Base Address, all access will use */
1713         unsigned int irq_num;
1714
1715         u16 LnkCtrlBitMask;
1716         u16 RLnkCtrlConfiguration;
1717         u16 RLnkCtrlOffset;
1718         u16 HostLnkCtrlConfiguration;
1719         u16 HostLnkCtrlOffset;
1720         u16 PCIePowerSaveLevel;
1721         unsigned long Rt3xxHostLinkCtrl;        /* USed for 3090F chip */
1722         unsigned long Rt3xxRalinkLinkCtrl;      /* USed for 3090F chip */
1723         u16 DeviceID;   /* Read from PCI config */
1724         unsigned long AccessBBPFailCount;
1725         BOOLEAN bPCIclkOff;     /* flag that indicate if the PICE power status in Configuration SPace.. */
1726         BOOLEAN bPCIclkOffDisableTx;    /* */
1727
1728         BOOLEAN brt30xxBanMcuCmd;       /*when = 0xff means all commands are ok to set . */
1729         BOOLEAN b3090ESpecialChip;      /*3090E special chip that write EEPROM 0x24=0x9280. */
1730         unsigned long CheckDmaBusyCount;        /* Check Interrupt Status Register Count. */
1731
1732         u32 int_enable_reg;
1733         u32 int_disable_mask;
1734         u32 int_pending;
1735
1736         struct rt_rtmp_dmabuf TxBufSpace[NUM_OF_TX_RING];       /* Shared memory of all 1st pre-allocated TxBuf associated with each TXD */
1737         struct rt_rtmp_dmabuf RxDescRing;       /* Shared memory for RX descriptors */
1738         struct rt_rtmp_dmabuf TxDescRing[NUM_OF_TX_RING];       /* Shared memory for Tx descriptors */
1739         struct rt_rtmp_tx_ring TxRing[NUM_OF_TX_RING];  /* AC0~4 + HCCA */
1740 #endif                          /* RTMP_MAC_PCI // */
1741
1742         spinlock_t irq_lock;
1743         u8 irq_disabled;
1744
1745 #ifdef RTMP_MAC_USB
1746 /*****************************************************************************************/
1747 /*      USB related parameters                                                           */
1748 /*****************************************************************************************/
1749         struct usb_config_descriptor *config;
1750         u32 BulkInEpAddr;       /* bulk-in endpoint address */
1751         u32 BulkOutEpAddr[6];   /* bulk-out endpoint address */
1752
1753         u32 NumberOfPipes;
1754         u16 BulkOutMaxPacketSize;
1755         u16 BulkInMaxPacketSize;
1756
1757         /*======Control Flags */
1758         long PendingIoCount;
1759         unsigned long BulkFlags;
1760         BOOLEAN bUsbTxBulkAggre;        /* Flags for bulk out data priority */
1761
1762         /*======Cmd Thread */
1763         struct rt_cmdq CmdQ;
1764         spinlock_t CmdQLock;    /* CmdQLock spinlock */
1765         struct rt_rtmp_os_task cmdQTask;
1766
1767         /*======Semaphores (event) */
1768         struct semaphore UsbVendorReq_semaphore;
1769         void *UsbVendorReqBuf;
1770         wait_queue_head_t *wait;
1771 #endif                          /* RTMP_MAC_USB // */
1772
1773 /*****************************************************************************************/
1774 /*      RBUS related parameters                                                                                                                           */
1775 /*****************************************************************************************/
1776
1777 /*****************************************************************************************/
1778 /*      Both PCI/USB related parameters                                                                                                           */
1779 /*****************************************************************************************/
1780         /*struct rt_rtmp_dev_info                 chipInfo; */
1781         RTMP_INF_TYPE infType;
1782
1783 /*****************************************************************************************/
1784 /*      Driver Mgmt related parameters                                                                                                            */
1785 /*****************************************************************************************/
1786         struct rt_rtmp_os_task mlmeTask;
1787 #ifdef RTMP_TIMER_TASK_SUPPORT
1788         /* If you want use timer task to handle the timer related jobs, enable this. */
1789         struct rt_rtmp_timer_task_queue TimerQ;
1790         spinlock_t TimerQLock;
1791         struct rt_rtmp_os_task timerTask;
1792 #endif                          /* RTMP_TIMER_TASK_SUPPORT // */
1793
1794 /*****************************************************************************************/
1795 /*      Tx related parameters                                                           */
1796 /*****************************************************************************************/
1797         BOOLEAN DeQueueRunning[NUM_OF_TX_RING]; /* for ensuring RTUSBDeQueuePacket get call once */
1798         spinlock_t DeQueueLock[NUM_OF_TX_RING];
1799
1800 #ifdef RTMP_MAC_USB
1801         /* Data related context and AC specified, 4 AC supported */
1802         spinlock_t BulkOutLock[6];      /* BulkOut spinlock for 4 ACs */
1803         spinlock_t MLMEBulkOutLock;     /* MLME BulkOut lock */
1804
1805         struct rt_ht_tx_context TxContext[NUM_OF_TX_RING];
1806         spinlock_t TxContextQueueLock[NUM_OF_TX_RING];  /* TxContextQueue spinlock */
1807
1808         /* 4 sets of Bulk Out index and pending flag */
1809         u8 NextBulkOutIndex[4]; /* only used for 4 EDCA bulkout pipe */
1810
1811         BOOLEAN BulkOutPending[6];      /* used for total 6 bulkout pipe */
1812         u8 bulkResetPipeid;
1813         BOOLEAN MgmtBulkPending;
1814         unsigned long bulkResetReq[6];
1815 #endif                          /* RTMP_MAC_USB // */
1816
1817         /* resource for software backlog queues */
1818         struct rt_queue_header TxSwQueue[NUM_OF_TX_RING];       /* 4 AC + 1 HCCA */
1819         spinlock_t TxSwQueueLock[NUM_OF_TX_RING];       /* TxSwQueue spinlock */
1820
1821         struct rt_rtmp_dmabuf MgmtDescRing;     /* Shared memory for MGMT descriptors */
1822         struct rt_rtmp_mgmt_ring MgmtRing;
1823         spinlock_t MgmtRingLock;        /* Prio Ring spinlock */
1824
1825 /*****************************************************************************************/
1826 /*      Rx related parameters                                                           */
1827 /*****************************************************************************************/
1828
1829 #ifdef RTMP_MAC_PCI
1830         struct rt_rtmp_rx_ring RxRing;
1831         spinlock_t RxRingLock;  /* Rx Ring spinlock */
1832 #ifdef RT3090
1833         spinlock_t McuCmdLock;  /*MCU Command Queue spinlock */
1834 #endif                          /* RT3090 // */
1835 #endif                          /* RTMP_MAC_PCI // */
1836 #ifdef RTMP_MAC_USB
1837         struct rt_rx_context RxContext[RX_RING_SIZE];   /* 1 for redundant multiple IRP bulk in. */
1838         spinlock_t BulkInLock;  /* BulkIn spinlock for 4 ACs */
1839         u8 PendingRx;   /* The Maximum pending Rx value should be       RX_RING_SIZE. */
1840         u8 NextRxBulkInIndex;   /* Indicate the current RxContext Index which hold by Host controller. */
1841         u8 NextRxBulkInReadIndex;       /* Indicate the current RxContext Index which driver can read & process it. */
1842         unsigned long NextRxBulkInPosition;     /* Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength. */
1843         unsigned long TransferBufferLength;     /* current length of the packet buffer */
1844         unsigned long ReadPosition;     /* current read position in a packet buffer */
1845 #endif                          /* RTMP_MAC_USB // */
1846
1847 /*****************************************************************************************/
1848 /*      ASIC related parameters                                                          */
1849 /*****************************************************************************************/
1850         u32 MACVersion; /* MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101).. */
1851
1852         /* --------------------------- */
1853         /* E2PROM */
1854         /* --------------------------- */
1855         unsigned long EepromVersion;    /* byte 0: version, byte 1: revision, byte 2~3: unused */
1856         unsigned long FirmwareVersion;  /* byte 0: Minor version, byte 1: Major version, otherwise unused. */
1857         u16 EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
1858         u8 EEPROMAddressNum;    /* 93c46=6  93c66=8 */
1859         BOOLEAN EepromAccess;
1860         u8 EFuseTag;
1861
1862         /* --------------------------- */
1863         /* BBP Control */
1864         /* --------------------------- */
1865         u8 BbpWriteLatch[140];  /* record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID */
1866         char BbpRssiToDbmDelta; /* change from u8 to char for high power */
1867         struct rt_bbp_r66_tuning BbpTuning;
1868
1869         /* ---------------------------- */
1870         /* RFIC control */
1871         /* ---------------------------- */
1872         u8 RfIcType;            /* RFIC_xxx */
1873         unsigned long RfFreqOffset;     /* Frequency offset for channel switching */
1874         struct rt_rtmp_rf_regs LatchRfRegs;     /* latch th latest RF programming value since RF IC doesn't support READ */
1875
1876         EEPROM_ANTENNA_STRUC Antenna;   /* Since ANtenna definition is different for a & g. We need to save it for future reference. */
1877         EEPROM_NIC_CONFIG2_STRUC NicConfig2;
1878
1879         /* This soft Rx Antenna Diversity mechanism is used only when user set */
1880         /* RX Antenna = DIVERSITY ON */
1881         struct rt_soft_rx_ant_diversity RxAnt;
1882
1883         u8 RFProgSeq;
1884         struct rt_channel_tx_power TxPower[MAX_NUM_OF_CHANNELS];        /* Store Tx power value for all channels. */
1885         struct rt_channel_tx_power ChannelList[MAX_NUM_OF_CHANNELS];    /* list all supported channels for site survey */
1886         struct rt_channel_11j_tx_power TxPower11J[MAX_NUM_OF_11JCHANNELS];      /* 802.11j channel and bw */
1887         struct rt_channel_11j_tx_power ChannelList11J[MAX_NUM_OF_11JCHANNELS];  /* list all supported channels for site survey */
1888
1889         u8 ChannelListNum;      /* number of channel in ChannelList[] */
1890         u8 Bbp94;
1891         BOOLEAN BbpForCCK;
1892         unsigned long Tx20MPwrCfgABand[5];
1893         unsigned long Tx20MPwrCfgGBand[5];
1894         unsigned long Tx40MPwrCfgABand[5];
1895         unsigned long Tx40MPwrCfgGBand[5];
1896
1897         BOOLEAN bAutoTxAgcA;    /* Enable driver auto Tx Agc control */
1898         u8 TssiRefA;            /* Store Tssi reference value as 25 temperature. */
1899         u8 TssiPlusBoundaryA[5];        /* Tssi boundary for increase Tx power to compensate. */
1900         u8 TssiMinusBoundaryA[5];       /* Tssi boundary for decrease Tx power to compensate. */
1901         u8 TxAgcStepA;  /* Store Tx TSSI delta increment / decrement value */
1902         char TxAgcCompensateA;  /* Store the compensation (TxAgcStep * (idx-1)) */
1903
1904         BOOLEAN bAutoTxAgcG;    /* Enable driver auto Tx Agc control */
1905         u8 TssiRefG;            /* Store Tssi reference value as 25 temperature. */
1906         u8 TssiPlusBoundaryG[5];        /* Tssi boundary for increase Tx power to compensate. */
1907         u8 TssiMinusBoundaryG[5];       /* Tssi boundary for decrease Tx power to compensate. */
1908         u8 TxAgcStepG;  /* Store Tx TSSI delta increment / decrement value */
1909         char TxAgcCompensateG;  /* Store the compensation (TxAgcStep * (idx-1)) */
1910
1911         char BGRssiOffset0;     /* Store B/G RSSI#0 Offset value on EEPROM 0x46h */
1912         char BGRssiOffset1;     /* Store B/G RSSI#1 Offset value */
1913         char BGRssiOffset2;     /* Store B/G RSSI#2 Offset value */
1914
1915         char ARssiOffset0;      /* Store A RSSI#0 Offset value on EEPROM 0x4Ah */
1916         char ARssiOffset1;      /* Store A RSSI#1 Offset value */
1917         char ARssiOffset2;      /* Store A RSSI#2 Offset value */
1918
1919         char BLNAGain;          /* Store B/G external LNA#0 value on EEPROM 0x44h */
1920         char ALNAGain0;         /* Store A external LNA#0 value for ch36~64 */
1921         char ALNAGain1;         /* Store A external LNA#1 value for ch100~128 */
1922         char ALNAGain2;         /* Store A external LNA#2 value for ch132~165 */
1923 #ifdef RT30xx
1924         /* for 3572 */
1925         u8 Bbp25;
1926         u8 Bbp26;
1927
1928         u8 TxMixerGain24G;      /* Tx mixer gain value from EEPROM to improve Tx EVM / Tx DAC, 2.4G */
1929         u8 TxMixerGain5G;
1930 #endif                          /* RT30xx // */
1931         /* ---------------------------- */
1932         /* LED control */
1933         /* ---------------------------- */
1934         MCU_LEDCS_STRUC LedCntl;
1935         u16 Led1;               /* read from EEPROM 0x3c */
1936         u16 Led2;               /* EEPROM 0x3e */
1937         u16 Led3;               /* EEPROM 0x40 */
1938         u8 LedIndicatorStrength;
1939         u8 RssiSingalstrengthOffet;
1940         BOOLEAN bLedOnScanning;
1941         u8 LedStatus;
1942
1943 /*****************************************************************************************/
1944 /*      802.11 related parameters                                                        */
1945 /*****************************************************************************************/
1946         /* outgoing BEACON frame buffer and corresponding TXD */
1947         struct rt_txwi BeaconTxWI;
1948         u8 *BeaconBuf;
1949         u16 BeaconOffset[HW_BEACON_MAX_COUNT];
1950
1951         /* pre-build PS-POLL and NULL frame upon link up. for efficiency purpose. */
1952         struct rt_pspoll_frame PsPollFrame;
1953         struct rt_header_802_11 NullFrame;
1954
1955 #ifdef RTMP_MAC_USB
1956         struct rt_tx_context BeaconContext[BEACON_RING_SIZE];
1957         struct rt_tx_context NullContext;
1958         struct rt_tx_context PsPollContext;
1959         struct rt_tx_context RTSContext;
1960 #endif                          /* RTMP_MAC_USB // */
1961
1962 /*=========AP=========== */
1963
1964 /*=======STA=========== */
1965         /* ----------------------------------------------- */
1966         /* STA specific configuration & operation status */
1967         /* used only when pAd->OpMode == OPMODE_STA */
1968         /* ----------------------------------------------- */
1969         struct rt_sta_admin_config StaCfg;      /* user desired settings */
1970         struct rt_sta_active_config StaActive;  /* valid only when ADHOC_ON(pAd) || INFRA_ON(pAd) */
1971         char nickname[IW_ESSID_MAX_SIZE + 1];   /* nickname, only used in the iwconfig i/f */
1972         int PreMediaState;
1973
1974 /*=======Common=========== */
1975         /* OP mode: either AP or STA */
1976         u8 OpMode;              /* OPMODE_STA, OPMODE_AP */
1977
1978         int IndicateMediaState; /* Base on Indication state, default is NdisMediaStateDisConnected */
1979
1980         /* MAT related parameters */
1981
1982         /* configuration: read from Registry & E2PROM */
1983         BOOLEAN bLocalAdminMAC; /* Use user changed MAC */
1984         u8 PermanentAddress[MAC_ADDR_LEN];      /* Factory default MAC address */
1985         u8 CurrentAddress[MAC_ADDR_LEN];        /* User changed MAC address */
1986
1987         /* ------------------------------------------------------ */
1988         /* common configuration to both OPMODE_STA and OPMODE_AP */
1989         /* ------------------------------------------------------ */
1990         struct rt_common_config CommonCfg;
1991         struct rt_mlme Mlme;
1992
1993         /* AP needs those vaiables for site survey feature. */
1994         struct rt_mlme_aux MlmeAux;     /* temporary settings used during MLME state machine */
1995         struct rt_bss_table ScanTab;    /* store the latest SCAN result */
1996
1997         /*About MacTab, the sta driver will use #0 and #1 for multicast and AP. */
1998         struct rt_mac_table MacTab;     /* ASIC on-chip WCID entry table.  At TX, ASIC always use key according to this on-chip table. */
1999         spinlock_t MacTabLock;
2000
2001         struct rt_ba_table BATable;
2002
2003         spinlock_t BATabLock;
2004         struct rt_ralink_timer RECBATimer;
2005
2006         /* encryption/decryption KEY tables */
2007         struct rt_cipher_key SharedKey[MAX_MBSSID_NUM][4];      /* STA always use SharedKey[BSS0][0..3] */
2008
2009         /* RX re-assembly buffer for fragmentation */
2010         struct rt_fragment_frame FragFrame;     /* Frame storage for fragment frame */
2011
2012         /* various Counters */
2013         struct rt_counter_802_3 Counters8023;   /* 802.3 counters */
2014         struct rt_counter_802_11 WlanCounters;  /* 802.11 MIB counters */
2015         struct rt_counter_ralink RalinkCounters;        /* Ralink propriety counters */
2016         struct rt_counter_drs DrsCounters;      /* counters for Dynamic TX Rate Switching */
2017         struct rt_private PrivateInfo;  /* Private information & counters */
2018
2019         /* flags, see fRTMP_ADAPTER_xxx flags */
2020         unsigned long Flags;            /* Represent current device status */
2021         unsigned long PSFlags;          /* Power Save operation flag. */
2022
2023         /* current TX sequence # */
2024         u16 Sequence;
2025
2026         /* Control disconnect / connect event generation */
2027         /*+++Didn't used anymore */
2028         unsigned long LinkDownTime;
2029         /*--- */
2030         unsigned long LastRxRate;
2031         unsigned long LastTxRate;
2032         /*+++Used only for Station */
2033         BOOLEAN bConfigChanged; /* Config Change flag for the same SSID setting */
2034         /*--- */
2035
2036         unsigned long ExtraInfo;        /* Extra information for displaying status */
2037         unsigned long SystemErrorBitmap;        /* b0: E2PROM version error */
2038
2039         /*+++Didn't used anymore */
2040         unsigned long MacIcVersion;     /* MAC/BBP serial interface issue solved after ver.D */
2041         /*--- */
2042
2043         /* --------------------------- */
2044         /* System event log */
2045         /* --------------------------- */
2046         struct rt_802_11_event_table EventTab;
2047
2048         BOOLEAN HTCEnable;
2049
2050         /*****************************************************************************************/
2051         /*      Statistic related parameters                                                     */
2052         /*****************************************************************************************/
2053 #ifdef RTMP_MAC_USB
2054         unsigned long BulkOutDataOneSecCount;
2055         unsigned long BulkInDataOneSecCount;
2056         unsigned long BulkLastOneSecCount;      /* BulkOutDataOneSecCount + BulkInDataOneSecCount */
2057         unsigned long watchDogRxCnt;
2058         unsigned long watchDogRxOverFlowCnt;
2059         unsigned long watchDogTxPendingCnt[NUM_OF_TX_RING];
2060         int TransferedLength[NUM_OF_TX_RING];
2061 #endif                          /* RTMP_MAC_USB // */
2062
2063         BOOLEAN bUpdateBcnCntDone;
2064         unsigned long watchDogMacDeadlock;      /* prevent MAC/BBP into deadlock condition */
2065         /* ---------------------------- */
2066         /* DEBUG paramerts */
2067         /* ---------------------------- */
2068         /*unsigned long         DebugSetting[4]; */
2069         BOOLEAN bBanAllBaSetup;
2070         BOOLEAN bPromiscuous;
2071
2072         /* ---------------------------- */
2073         /* rt2860c emulation-use Parameters */
2074         /* ---------------------------- */
2075         /*unsigned long         rtsaccu[30]; */
2076         /*unsigned long         ctsaccu[30]; */
2077         /*unsigned long         cfendaccu[30]; */
2078         /*unsigned long         bacontent[16]; */
2079         /*unsigned long         rxint[RX_RING_SIZE+1]; */
2080         /*u8         rcvba[60]; */
2081         BOOLEAN bLinkAdapt;
2082         BOOLEAN bForcePrintTX;
2083         BOOLEAN bForcePrintRX;
2084         /*BOOLEAN               bDisablescanning;               //defined in RT2870 USB */
2085         BOOLEAN bStaFifoTest;
2086         BOOLEAN bProtectionTest;
2087         BOOLEAN bBroadComHT;
2088         /*+++Following add from RT2870 USB. */
2089         unsigned long BulkOutReq;
2090         unsigned long BulkOutComplete;
2091         unsigned long BulkOutCompleteOther;
2092         unsigned long BulkOutCompleteCancel;    /* seems not use now? */
2093         unsigned long BulkInReq;
2094         unsigned long BulkInComplete;
2095         unsigned long BulkInCompleteFail;
2096         /*--- */
2097
2098         struct wificonf WIFItestbed;
2099
2100         struct reordering_mpdu_pool mpdu_blk_pool;
2101
2102         unsigned long OneSecondnonBEpackets;    /* record non BE packets per second */
2103
2104 #ifdef LINUX
2105         struct iw_statistics iw_stats;
2106
2107         struct net_device_stats stats;
2108 #endif                          /* LINUX // */
2109
2110         unsigned long TbttTickCount;
2111 #ifdef PCI_MSI_SUPPORT
2112         BOOLEAN HaveMsi;
2113 #endif                          /* PCI_MSI_SUPPORT // */
2114
2115         u8 is_on;
2116
2117 #define TIME_BASE                       (1000000/OS_HZ)
2118 #define TIME_ONE_SECOND         (1000000/TIME_BASE)
2119         u8 flg_be_adjust;
2120         unsigned long be_adjust_last_time;
2121
2122         u8 FlgCtsEnabled;
2123         u8 PM_FlgSuspend;
2124
2125 #ifdef RT30xx
2126 #ifdef RTMP_EFUSE_SUPPORT
2127         BOOLEAN bUseEfuse;
2128         u8 EEPROMImage[1024];
2129 #endif                          /* RTMP_EFUSE_SUPPORT // */
2130 #endif                          /* RT30xx // */
2131 };
2132
2133 #define DELAYINTMASK            0x0003fffb
2134 #define INTMASK                         0x0003fffb
2135 #define IndMask                         0x0003fffc
2136 #define RxINT                           0x00000005      /* Delayed Rx or indivi rx */
2137 #define TxDataInt                       0x000000fa      /* Delayed Tx or indivi tx */
2138 #define TxMgmtInt                       0x00000102      /* Delayed Tx or indivi tx */
2139 #define TxCoherent                      0x00020000      /* tx coherent */
2140 #define RxCoherent                      0x00010000      /* rx coherent */
2141 #define McuCommand                      0x00000200      /* mcu */
2142 #define PreTBTTInt                      0x00001000      /* Pre-TBTT interrupt */
2143 #define TBTTInt                         0x00000800      /* TBTT interrupt */
2144 #define GPTimeOutInt                    0x00008000      /* GPtimeout interrupt */
2145 #define AutoWakeupInt           0x00004000      /* AutoWakeupInt interrupt */
2146 #define FifoStaFullInt                  0x00002000      /*  fifo statistics full interrupt */
2147
2148 /***************************************************************************
2149   *     Rx Path software control block related data structures
2150   **************************************************************************/
2151 struct rt_rx_blk {
2152         RT28XX_RXD_STRUC RxD;
2153         struct rt_rxwi *pRxWI;
2154         struct rt_header_802_11 *pHeader;
2155         void *pRxPacket;
2156         u8 *pData;
2157         u16 DataSize;
2158         u16 Flags;
2159         u8 UserPriority;        /* for calculate TKIP MIC using */
2160 };
2161
2162 #define RX_BLK_SET_FLAG(_pRxBlk, _flag)         (_pRxBlk->Flags |= _flag)
2163 #define RX_BLK_TEST_FLAG(_pRxBlk, _flag)        (_pRxBlk->Flags & _flag)
2164 #define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag)       (_pRxBlk->Flags &= ~(_flag))
2165
2166 #define fRX_WDS                 0x0001
2167 #define fRX_AMSDU       0x0002
2168 #define fRX_ARALINK     0x0004
2169 #define fRX_HTC         0x0008
2170 #define fRX_PAD         0x0010
2171 #define fRX_AMPDU       0x0020
2172 #define fRX_QOS                 0x0040
2173 #define fRX_INFRA               0x0080
2174 #define fRX_EAP                 0x0100
2175 #define fRX_MESH                0x0200
2176 #define fRX_APCLI               0x0400
2177 #define fRX_DLS                 0x0800
2178 #define fRX_WPI                 0x1000
2179
2180 #define LENGTH_AMSDU_SUBFRAMEHEAD       14
2181 #define LENGTH_ARALINK_SUBFRAMEHEAD     14
2182 #define LENGTH_ARALINK_HEADER_FIELD      2
2183
2184 /***************************************************************************
2185   *     Tx Path software control block related data structures
2186   **************************************************************************/
2187 #define TX_UNKOWN_FRAME                 0x00
2188 #define TX_MCAST_FRAME                  0x01
2189 #define TX_LEGACY_FRAME                 0x02
2190 #define TX_AMPDU_FRAME                  0x04
2191 #define TX_AMSDU_FRAME                  0x08
2192 #define TX_RALINK_FRAME                 0x10
2193 #define TX_FRAG_FRAME                   0x20
2194
2195 /*      Currently the sizeof(struct rt_tx_blk) is 148 bytes. */
2196 struct rt_tx_blk {
2197         u8 QueIdx;
2198         u8 TxFrameType; /* Indicate the Transmission type of the all frames in one batch */
2199         u8 TotalFrameNum;       /* Total frame number want to send-out in one batch */
2200         u16 TotalFragNum;       /* Total frame fragments required in one batch */
2201         u16 TotalFrameLen;      /* Total length of all frames want to send-out in one batch */
2202
2203         struct rt_queue_header TxPacketList;
2204         struct rt_mac_table_entry *pMacEntry;   /* NULL: packet with 802.11 RA field is multicast/broadcast address */
2205         HTTRANSMIT_SETTING *pTransmit;
2206
2207         /* Following structure used for the characteristics of a specific packet. */
2208         void *pPacket;
2209         u8 *pSrcBufHeader;      /* Reference to the head of sk_buff->data */
2210         u8 *pSrcBufData;        /* Reference to the sk_buff->data, will changed depends on hanlding progresss */
2211         u32 SrcBufLen;          /* Length of packet payload which not including Layer 2 header */
2212         u8 *pExtraLlcSnapEncap; /* NULL means no extra LLC/SNAP is required */
2213         u8 HeaderBuf[128];      /* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */
2214         /*RT2870 2.1.0.0 uses only 80 bytes */
2215         /*RT3070 2.1.1.0 uses only 96 bytes */
2216         /*RT3090 2.1.0.0 uses only 96 bytes */
2217         u8 MpduHeaderLen;       /* 802.11 header length NOT including the padding */
2218         u8 HdrPadLen;   /* recording Header Padding Length; */
2219         u8 apidx;               /* The interface associated to this packet */
2220         u8 Wcid;                /* The MAC entry associated to this packet */
2221         u8 UserPriority;        /* priority class of packet */
2222         u8 FrameGap;            /* what kind of IFS this packet use */
2223         u8 MpduReqNum;  /* number of fragments of this frame */
2224         u8 TxRate;              /* TODO: Obsoleted? Should change to MCS? */
2225         u8 CipherAlg;   /* cipher alogrithm */
2226         struct rt_cipher_key *pKey;
2227
2228         u16 Flags;              /*See following definitions for detail. */
2229
2230         /*YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer. */
2231         unsigned long Priv;             /* Hardware specific value saved in here. */
2232 };
2233
2234 #define fTX_bRtsRequired        0x0001  /* Indicate if need send RTS frame for protection. Not used in RT2860/RT2870. */
2235 #define fTX_bAckRequired        0x0002  /* the packet need ack response */
2236 #define fTX_bPiggyBack          0x0004  /* Legacy device use Piggback or not */
2237 #define fTX_bHTRate             0x0008  /* allow to use HT rate */
2238 #define fTX_bForceNonQoS        0x0010  /* force to transmit frame without WMM-QoS in HT mode */
2239 #define fTX_bAllowFrag          0x0020  /* allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment */
2240 #define fTX_bMoreData           0x0040  /* there are more data packets in PowerSave Queue */
2241 #define fTX_bWMM                0x0080  /* QOS Data */
2242 #define fTX_bClearEAPFrame      0x0100
2243
2244 #define TX_BLK_SET_FLAG(_pTxBlk, _flag)         (_pTxBlk->Flags |= _flag)
2245 #define TX_BLK_TEST_FLAG(_pTxBlk, _flag)        (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
2246 #define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag)       (_pTxBlk->Flags &= ~(_flag))
2247
2248 /***************************************************************************
2249   *     Other static inline function definitions
2250   **************************************************************************/
2251 static inline void ConvertMulticastIP2MAC(u8 *pIpAddr,
2252                                           u8 **ppMacAddr,
2253                                           u16 ProtoType)
2254 {
2255         if (pIpAddr == NULL)
2256                 return;
2257
2258         if (ppMacAddr == NULL || *ppMacAddr == NULL)
2259                 return;
2260
2261         switch (ProtoType) {
2262         case ETH_P_IPV6:
2263 /*                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2264                 *(*ppMacAddr) = 0x33;
2265                 *(*ppMacAddr + 1) = 0x33;
2266                 *(*ppMacAddr + 2) = pIpAddr[12];
2267                 *(*ppMacAddr + 3) = pIpAddr[13];
2268                 *(*ppMacAddr + 4) = pIpAddr[14];
2269                 *(*ppMacAddr + 5) = pIpAddr[15];
2270                 break;
2271
2272         case ETH_P_IP:
2273         default:
2274 /*                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2275                 *(*ppMacAddr) = 0x01;
2276                 *(*ppMacAddr + 1) = 0x00;
2277                 *(*ppMacAddr + 2) = 0x5e;
2278                 *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
2279                 *(*ppMacAddr + 4) = pIpAddr[2];
2280                 *(*ppMacAddr + 5) = pIpAddr[3];
2281                 break;
2282         }
2283
2284         return;
2285 }
2286
2287 char *GetPhyMode(int Mode);
2288 char *GetBW(int BW);
2289
2290 /* */
2291 /*  Private routines in rtmp_init.c */
2292 /* */
2293 int RTMPAllocAdapterBlock(void *handle,
2294                                   struct rt_rtmp_adapter **ppAdapter);
2295
2296 int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd);
2297
2298 void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd);
2299
2300 int NICReadRegParameters(struct rt_rtmp_adapter *pAd,
2301                                  void *WrapperConfigurationContext);
2302
2303 #ifdef RTMP_RF_RW_SUPPORT
2304 void NICInitRFRegisters(struct rt_rtmp_adapter *pAd);
2305
2306 void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd);
2307
2308 int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd,
2309                                   u8 regID, u8 value);
2310
2311 int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
2312                                  u8 regID, u8 *pValue);
2313 #endif /* RTMP_RF_RW_SUPPORT // */
2314
2315 void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr);
2316
2317 void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd);
2318
2319 int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2320
2321 int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2322
2323 void NICIssueReset(struct rt_rtmp_adapter *pAd);
2324
2325 void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType);
2326
2327 void UserCfgInit(struct rt_rtmp_adapter *pAd);
2328
2329 void NICResetFromError(struct rt_rtmp_adapter *pAd);
2330
2331 int NICLoadFirmware(struct rt_rtmp_adapter *pAd);
2332
2333 void NICEraseFirmware(struct rt_rtmp_adapter *pAd);
2334
2335 int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd);
2336
2337 BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd);
2338
2339 void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd);
2340
2341 void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd);
2342
2343 void RTMPZeroMemory(void *pSrc, unsigned long Length);
2344
2345 unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length);
2346
2347 void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length);
2348
2349 void AtoH(char *src, u8 *dest, int destlen);
2350
2351 void RTMPPatchMacBbpBug(struct rt_rtmp_adapter *pAd);
2352
2353 void RTMPInitTimer(struct rt_rtmp_adapter *pAd,
2354                    struct rt_ralink_timer *pTimer,
2355                    void *pTimerFunc, void *pData, IN BOOLEAN Repeat);
2356
2357 void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2358
2359 void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2360
2361 void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled);
2362
2363 void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status);
2364
2365 void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm);
2366
2367 void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd);
2368
2369 /* */
2370 /* prototype in action.c */
2371 /* */
2372 void ActionStateMachineInit(struct rt_rtmp_adapter *pAd,
2373                             struct rt_state_machine *S,
2374                             OUT STATE_MACHINE_FUNC Trans[]);
2375
2376 void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2377
2378 void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2379
2380 void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2381
2382 void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2383
2384 void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2385
2386 void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2387
2388 void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2389
2390 void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2391
2392 void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2393
2394 void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp);
2395
2396 void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2397
2398 void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2399
2400 void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2401
2402 void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2403
2404 void RECBATimerTimeout(void *SystemSpecific1,
2405                        void *FunctionContext,
2406                        void *SystemSpecific2, void *SystemSpecific3);
2407
2408 void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd);
2409
2410 void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
2411
2412 void ActHeaderInit(struct rt_rtmp_adapter *pAd,
2413                    struct rt_header_802_11 *pHdr80211,
2414                    u8 *Addr1, u8 *Addr2, u8 *Addr3);
2415
2416 void BarHeaderInit(struct rt_rtmp_adapter *pAd,
2417                    struct rt_frame_bar *pCntlBar, u8 *pDA, u8 *pSA);
2418
2419 void InsertActField(struct rt_rtmp_adapter *pAd,
2420                     u8 *pFrameBuf,
2421                     unsigned long *pFrameLen, u8 Category, u8 ActCode);
2422
2423 BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2424                            unsigned long Wcid,
2425                            unsigned long MsgLen, struct rt_frame_ba_req *pMsg);
2426
2427 /* */
2428 /* Private routines in rtmp_data.c */
2429 /* */
2430 BOOLEAN RTMPHandleRxDoneInterrupt(struct rt_rtmp_adapter *pAd);
2431
2432 BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd,
2433                                          INT_SOURCE_CSR_STRUC TxRingBitmap);
2434
2435 void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd);
2436
2437 void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2438
2439 void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2440
2441 void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd);
2442
2443 void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd);
2444
2445 BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd,
2446                               u8 *pPrevAddr1, u8 *p8023hdr);
2447
2448 BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd,
2449                       unsigned long TxRate, struct rt_mac_table_entry *pMacEntry);
2450
2451 int Sniff2BytesFromNdisBuffer(char *pFirstBuffer,
2452                                       u8 DesiredOffset,
2453                                       u8 *pByte0, u8 *pByte1);
2454
2455 int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2456
2457 void STASendPackets(void *MiniportAdapterContext,
2458                     void **ppPacketArray, u32 NumberOfPackets);
2459
2460 void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd,
2461                        IN BOOLEAN bIntContext,
2462                        u8 QueIdx, u8 Max_Tx_Packets);
2463
2464 int RTMPHardTransmit(struct rt_rtmp_adapter *pAd,
2465                              void *pPacket,
2466                              u8 QueIdx, unsigned long *pFreeTXDLeft);
2467
2468 int STAHardTransmit(struct rt_rtmp_adapter *pAd,
2469                             struct rt_tx_blk *pTxBlk, u8 QueIdx);
2470
2471 void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd,
2472                              struct rt_mac_table_entry *pEntry,
2473                              struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
2474
2475 int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd,
2476                                u8 RingType,
2477                                u8 NumberRequired, u8 *FreeNumberIs);
2478
2479 int MlmeHardTransmit(struct rt_rtmp_adapter *pAd,
2480                              u8 QueIdx, void *pPacket);
2481
2482 int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd,
2483                                      u8 QueIdx, void *pPacket);
2484
2485 #ifdef RTMP_MAC_PCI
2486 int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd,
2487                                    u8 QueIdx, void *pPacket);
2488
2489 int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd,
2490                                  u8 QueIdx, void *pPacket);
2491
2492 void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd,
2493                            struct rt_txd *pTxD, IN BOOLEAN bWIV, u8 QSEL);
2494 #endif /* RTMP_MAC_PCI // */
2495
2496 u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size);
2497
2498 void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq,  /* HW new a sequence. */
2499                    u8 BASize,
2500                    u8 WCID,
2501                    unsigned long Length,
2502                    u8 PID,
2503                    u8 TID,
2504                    u8 TxRate,
2505                    u8 Txopmode,
2506                    IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING *pTransmit);
2507
2508 void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd,
2509                         struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2510
2511 void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd,
2512                          struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2513
2514 void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd);
2515
2516 void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd);
2517
2518 int MiniportMMRequest(struct rt_rtmp_adapter *pAd,
2519                               u8 QueIdx, u8 *pData, u32 Length);
2520
2521 /*+++mark by shiang, now this function merge to MiniportMMRequest() */
2522 /*---mark by shiang, now this function merge to MiniportMMRequest() */
2523
2524 void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd,
2525                        u8 TxRate, IN BOOLEAN bQosNull);
2526
2527 void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd);
2528
2529 void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd,
2530                       u8 *pDA,
2531                       IN unsigned int NextMpduSize,
2532                       u8 TxRate,
2533                       u8 RTSRate,
2534                       u16 AckDuration,
2535                       u8 QueIdx, u8 FrameGap);
2536
2537 struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 * QueIdx);
2538
2539 void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey);
2540
2541 void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2542
2543 void WpaDisassocApAndBlockAssoc(void *SystemSpecific1,
2544                                 void *FunctionContext,
2545                                 void *SystemSpecific2,
2546                                 void *SystemSpecific3);
2547
2548 void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd);
2549
2550 void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd);
2551
2552 int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd,
2553                                 IN BOOLEAN pInsAMSDUHdr,
2554                                 void *pInPacket,
2555                                 void **ppOutPacket);
2556
2557 int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd,
2558                                    void **pPacket,
2559                                    u8 *pHeader,
2560                                    u32 HeaderLen,
2561                                    u8 *pData, u32 DataLen);
2562
2563 void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2564
2565 BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx);
2566
2567 BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket);
2568
2569 BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket);
2570
2571 /* */
2572 /* Private routines in rtmp_wep.c */
2573 /* */
2574 void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd,
2575                        u8 *pKey,
2576                        u8 KeyId, u8 KeyLen, u8 *pDest);
2577
2578 void RTMPEncryptData(struct rt_rtmp_adapter *pAd,
2579                      u8 *pSrc, u8 *pDest, u32 Len);
2580
2581 BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd,
2582                            u8 *pData,
2583                            unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey);
2584
2585 void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest);
2586
2587 void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen);
2588
2589 u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx);
2590
2591 void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx,
2592                      u8 *pDest, u8 *pSrc, u32 Len);
2593
2594 void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2595                      u8 *pDest, u8 *pSrc, u32 Len);
2596
2597 void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2598                         u8 *pDest, u8 *pSrc, u32 Len);
2599
2600 u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len);
2601
2602 /* */
2603 /* MLME routines */
2604 /* */
2605
2606 /* Asic/RF/BBP related functions */
2607
2608 void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd);
2609
2610 void AsicUpdateProtect(struct rt_rtmp_adapter *pAd,
2611                        u16 OperaionMode,
2612                        u8 SetMask,
2613                        IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist);
2614
2615 void AsicSwitchChannel(struct rt_rtmp_adapter *pAd,
2616                        u8 Channel, IN BOOLEAN bScan);
2617
2618 void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel);
2619
2620 void AsicRfTuningExec(void *SystemSpecific1,
2621                       void *FunctionContext,
2622                       void *SystemSpecific2, void *SystemSpecific3);
2623
2624 void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd);
2625
2626 void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
2627                              u16 TbttNumToNextWakeUp);
2628
2629 void AsicForceSleep(struct rt_rtmp_adapter *pAd);
2630
2631 void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
2632
2633 void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid);
2634
2635 void AsicSetMcastWC(struct rt_rtmp_adapter *pAd);
2636
2637 void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid);
2638
2639 void AsicEnableRDG(struct rt_rtmp_adapter *pAd);
2640
2641 void AsicDisableRDG(struct rt_rtmp_adapter *pAd);
2642
2643 void AsicDisableSync(struct rt_rtmp_adapter *pAd);
2644
2645 void AsicEnableBssSync(struct rt_rtmp_adapter *pAd);
2646
2647 void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd);
2648
2649 void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm);
2650
2651 void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime);
2652
2653 void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2654                            u8 BssIndex,
2655                            u8 KeyIdx,
2656                            u8 CipherAlg,
2657                            u8 *pKey, u8 *pTxMic, u8 *pRxMic);
2658
2659 void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2660                               u8 BssIndex, u8 KeyIdx);
2661
2662 void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd,
2663                              u16 WCID,
2664                              u8 BssIndex,
2665                              u8 CipherAlg,
2666                              IN BOOLEAN bUsePairewiseKeyTable);
2667
2668 void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd,
2669                          u16 WCID, unsigned long uIV, unsigned long uEIV);
2670
2671 void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd,
2672                            u16 WCID, u8 *pAddr);
2673
2674 void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd,
2675                      u16 WCID,
2676                      u8 BssIndex,
2677                      u8 KeyIdx,
2678                      struct rt_cipher_key *pCipherKey,
2679                      IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey);
2680
2681 void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2682                              u8 *pAddr,
2683                              u8 WCID, struct rt_cipher_key *pCipherKey);
2684
2685 void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2686                                 u8 BssIdx, u8 Wcid);
2687
2688 BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
2689                              u8 Command,
2690                              u8 Token, u8 Arg0, u8 Arg1);
2691
2692 #ifdef RTMP_MAC_PCI
2693 BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command);
2694 #endif /* RTMP_MAC_PCI // */
2695
2696 void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2697
2698 void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd,
2699                       struct rt_header_802_11 *pHdr80211,
2700                       u8 SubType,
2701                       u8 ToDs, u8 *pDA, u8 *pBssid);
2702
2703 void MlmeRadioOff(struct rt_rtmp_adapter *pAd);
2704
2705 void MlmeRadioOn(struct rt_rtmp_adapter *pAd);
2706
2707 void BssTableInit(struct rt_bss_table *Tab);
2708
2709 void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab);
2710
2711 unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel);
2712
2713 unsigned long BssSsidTableSearch(struct rt_bss_table *Tab,
2714                          u8 *pBssid,
2715                          u8 *pSsid, u8 SsidLen, u8 Channel);
2716
2717 unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab,
2718                              u8 *Bssid,
2719                              u8 *pSsid,
2720                              u8 SsidLen, u8 Channel);
2721
2722 unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab,
2723                                u8 *pSsid, u8 SsidLen);
2724
2725 void BssTableDeleteEntry(struct rt_bss_table *pTab,
2726                          u8 *pBssid, u8 Channel);
2727
2728 void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd,
2729                            struct rt_ba_ori_entry *pBAORIEntry);
2730
2731 void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo,   /* AP might use this additional ht info IE */
2732                  u8 HtCapabilityLen,
2733                  u8 AddHtInfoLen,
2734                  u8 NewExtChanOffset,
2735                  u8 Channel,
2736                  char Rssi,
2737                  IN LARGE_INTEGER TimeStamp,
2738                  u8 CkipFlag,
2739                  struct rt_edca_parm *pEdcaParm,
2740                  struct rt_qos_capability_parm *pQosCapability,
2741                  struct rt_qbss_load_parm *pQbssLoad,
2742                  u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2743
2744 unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *pTab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo,     /* AP might use this additional ht info IE */
2745                        u8 HtCapabilityLen,
2746                        u8 AddHtInfoLen,
2747                        u8 NewExtChanOffset,
2748                        u8 Channel,
2749                        char Rssi,
2750                        IN LARGE_INTEGER TimeStamp,
2751                        u8 CkipFlag,
2752                        struct rt_edca_parm *pEdcaParm,
2753                        struct rt_qos_capability_parm *pQosCapability,
2754                        struct rt_qbss_load_parm *pQbssLoad,
2755                        u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2756
2757 void BATableInsertEntry(struct rt_rtmp_adapter *pAd,
2758                         u16 Aid,
2759                         u16 TimeOutValue,
2760                         u16 StartingSeq,
2761                         u8 TID,
2762                         u8 BAWinSize,
2763                         u8 OriginatorStatus, IN BOOLEAN IsRecipient);
2764
2765 void BssTableSsidSort(struct rt_rtmp_adapter *pAd,
2766                       struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen);
2767
2768 void BssTableSortByRssi(struct rt_bss_table *OutTab);
2769
2770 void BssCipherParse(struct rt_bss_entry *pBss);
2771
2772 int MlmeQueueInit(struct rt_mlme_queue *Queue);
2773
2774 void MlmeQueueDestroy(struct rt_mlme_queue *Queue);
2775
2776 BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd,
2777                     unsigned long Machine,
2778                     unsigned long MsgType, unsigned long MsgLen, void *Msg);
2779
2780 BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2781                            unsigned long Wcid,
2782                            unsigned long TimeStampHigh,
2783                            unsigned long TimeStampLow,
2784                            u8 Rssi0,
2785                            u8 Rssi1,
2786                            u8 Rssi2,
2787                            unsigned long MsgLen, void *Msg, u8 Signal);
2788
2789 BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem **Elem);
2790
2791 void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd);
2792
2793 BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue);
2794
2795 BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue);
2796
2797 BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd,
2798                      struct rt_frame_802_11 *pFrame,
2799                      int *Machine, int *MsgType);
2800
2801 void StateMachineInit(struct rt_state_machine *Sm,
2802                       IN STATE_MACHINE_FUNC Trans[],
2803                       unsigned long StNr,
2804                       unsigned long MsgNr,
2805                       IN STATE_MACHINE_FUNC DefFunc,
2806                       unsigned long InitState, unsigned long Base);
2807
2808 void StateMachineSetAction(struct rt_state_machine *S,
2809                            unsigned long St, unsigned long Msg, IN STATE_MACHINE_FUNC F);
2810
2811 void StateMachinePerformAction(struct rt_rtmp_adapter *pAd,
2812                                struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem);
2813
2814 void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2815
2816 void AssocStateMachineInit(struct rt_rtmp_adapter *pAd,
2817                            struct rt_state_machine *Sm,
2818                            OUT STATE_MACHINE_FUNC Trans[]);
2819
2820 void ReassocTimeout(void *SystemSpecific1,
2821                     void *FunctionContext,
2822                     void *SystemSpecific2, void *SystemSpecific3);
2823
2824 void AssocTimeout(void *SystemSpecific1,
2825                   void *FunctionContext,
2826                   void *SystemSpecific2, void *SystemSpecific3);
2827
2828 void DisassocTimeout(void *SystemSpecific1,
2829                      void *FunctionContext,
2830                      void *SystemSpecific2, void *SystemSpecific3);
2831
2832 /*---------------------------------------------- */
2833 void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2834
2835 void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2836
2837 void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2838
2839 void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2840
2841 void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2842
2843 void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2844
2845 void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2846
2847 void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2848
2849 void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2850
2851 void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2852
2853 void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2854
2855 void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2856
2857 void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd,
2858                                   struct rt_mlme_queue_elem *Elem);
2859
2860 #ifdef RTMP_MAC_USB
2861 void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg);
2862 #endif /* RTMP_MAC_USB // */
2863
2864 void ComposePsPoll(struct rt_rtmp_adapter *pAd);
2865
2866 void ComposeNullFrame(struct rt_rtmp_adapter *pAd);
2867
2868 void AssocPostProc(struct rt_rtmp_adapter *pAd,
2869                    u8 *pAddr2,
2870                    u16 CapabilityInfo,
2871                    u16 Aid,
2872                    u8 SupRate[],
2873                    u8 SupRateLen,
2874                    u8 ExtRate[],
2875                    u8 ExtRateLen,
2876                    struct rt_edca_parm *pEdcaParm,
2877                    struct rt_ht_capability_ie *pHtCapability,
2878                    u8 HtCapabilityLen, struct rt_add_ht_info_ie *pAddHtInfo);
2879
2880 void AuthStateMachineInit(struct rt_rtmp_adapter *pAd,
2881                           struct rt_state_machine *sm, OUT STATE_MACHINE_FUNC Trans[]);
2882
2883 void AuthTimeout(void *SystemSpecific1,
2884                  void *FunctionContext,
2885                  void *SystemSpecific2, void *SystemSpecific3);
2886
2887 void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2888
2889 void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2890
2891 void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2892
2893 void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2894
2895 void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2896
2897 void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2898
2899 void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2900
2901 /*============================================= */
2902
2903 void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd,
2904                              struct rt_state_machine *Sm,
2905                              IN STATE_MACHINE_FUNC Trans[]);
2906
2907 void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2908
2909 void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd,
2910                                  struct rt_header_802_11 *pHdr80211,
2911                                  u16 Alg,
2912                                  u16 Seq,
2913                                  u16 Reason, u16 Status);
2914
2915 /* */
2916 /* Private routines in dls.c */
2917 /* */
2918
2919 /*======================================== */
2920
2921 void SyncStateMachineInit(struct rt_rtmp_adapter *pAd,
2922                           struct rt_state_machine *Sm,
2923                           OUT STATE_MACHINE_FUNC Trans[]);
2924
2925 void BeaconTimeout(void *SystemSpecific1,
2926                    void *FunctionContext,
2927                    void *SystemSpecific2, void *SystemSpecific3);
2928
2929 void ScanTimeout(void *SystemSpecific1,
2930                  void *FunctionContext,
2931                  void *SystemSpecific2, void *SystemSpecific3);
2932
2933 void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2934
2935 void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2936
2937 void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2938
2939 void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd);
2940
2941 BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd);
2942 /*========================================= */
2943
2944 void MlmeCntlInit(struct rt_rtmp_adapter *pAd,
2945                   struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]);
2946
2947 void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
2948                                   struct rt_state_machine *S,
2949                                   struct rt_mlme_queue_elem *Elem);
2950
2951 void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2952
2953 void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2954
2955 void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2956
2957 void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2958
2959 void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2960
2961 void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2962
2963 void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2964
2965 void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2966
2967 void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2968
2969 void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2970
2971 void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2972
2973 void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2974
2975 void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType);
2976
2977 void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP);
2978
2979 void IterateOnBssTab(struct rt_rtmp_adapter *pAd);
2980
2981 void IterateOnBssTab2(struct rt_rtmp_adapter *pAd);;
2982
2983 void JoinParmFill(struct rt_rtmp_adapter *pAd,
2984                   struct rt_mlme_join_req *JoinReq, unsigned long BssIdx);
2985
2986 void AssocParmFill(struct rt_rtmp_adapter *pAd,
2987                    struct rt_mlme_assoc_req *AssocReq,
2988                    u8 *pAddr,
2989                    u16 CapabilityInfo,
2990                    unsigned long Timeout, u16 ListenIntv);
2991
2992 void ScanParmFill(struct rt_rtmp_adapter *pAd,
2993                   struct rt_mlme_scan_req *ScanReq,
2994                   char Ssid[],
2995                   u8 SsidLen, u8 BssType, u8 ScanType);
2996
2997 void DisassocParmFill(struct rt_rtmp_adapter *pAd,
2998                       struct rt_mlme_disassoc_req *DisassocReq,
2999                       u8 *pAddr, u16 Reason);
3000
3001 void StartParmFill(struct rt_rtmp_adapter *pAd,
3002                    struct rt_mlme_start_req *StartReq,
3003                    char Ssid[], u8 SsidLen);
3004
3005 void AuthParmFill(struct rt_rtmp_adapter *pAd,
3006                   struct rt_mlme_auth_req *AuthReq,
3007                   u8 *pAddr, u16 Alg);
3008
3009 void EnqueuePsPoll(struct rt_rtmp_adapter *pAd);
3010
3011 void EnqueueBeaconFrame(struct rt_rtmp_adapter *pAd);
3012
3013 void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3014
3015 void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3016
3017 void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3018
3019 void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3020
3021 void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3022
3023 void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3024
3025 void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3026
3027 void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3028
3029 void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3030
3031 void ScanNextChannel(struct rt_rtmp_adapter *pAd);
3032
3033 unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd);
3034
3035 BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd,
3036                           void *Msg,
3037                           unsigned long MsgLen,
3038                           u8 *BssType,
3039                           char ssid[],
3040                           u8 *SsidLen, u8 *ScanType);
3041
3042 BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd,
3043                                     void *Msg,
3044                                     unsigned long MsgLen,
3045                                     u8 MsgChannel,
3046                                     u8 *pAddr2,
3047                                     u8 *pBssid,
3048                                     char Ssid[],
3049                                     u8 *pSsidLen,
3050                                     u8 *pBssType,
3051                                     u16 *pBeaconPeriod,
3052                                     u8 *pChannel,
3053                                     u8 *pNewChannel,
3054                                     OUT LARGE_INTEGER *pTimestamp,
3055                                     struct rt_cf_parm *pCfParm,
3056                                     u16 *pAtimWin,
3057                                     u16 *pCapabilityInfo,
3058                                     u8 *pErp,
3059                                     u8 *pDtimCount,
3060                                     u8 *pDtimPeriod,
3061                                     u8 *pBcastFlag,
3062                                     u8 *pMessageToMe,
3063                                     u8 SupRate[],
3064                                     u8 *pSupRateLen,
3065                                     u8 ExtRate[],
3066                                     u8 *pExtRateLen,
3067                                     u8 *pCkipFlag,
3068                                     u8 *pAironetCellPowerLimit,
3069                                     struct rt_edca_parm *pEdcaParm,
3070                                     struct rt_qbss_load_parm *pQbssLoad,
3071                                     struct rt_qos_capability_parm *pQosCapability,
3072                                     unsigned long *pRalinkIe,
3073                                     u8 *pHtCapabilityLen,
3074                                     u8 *pPreNHtCapabilityLen,
3075                                     struct rt_ht_capability_ie *pHtCapability,
3076                                     u8 *AddHtInfoLen,
3077                                     struct rt_add_ht_info_ie *AddHtInfo,
3078                                     u8 *NewExtChannel,
3079                                     u16 *LengthVIE,
3080                                     struct rt_ndis_802_11_variable_ies *pVIE);
3081
3082 BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd,
3083                                  void *pMsg,
3084                                  unsigned long MsgLen, u8 *pAddr2);
3085
3086 BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd,
3087                                  void *pMsg, unsigned long MsgLen);
3088
3089 BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd,
3090                               u8 Wcid, void *pMsg, unsigned long MsgLen);
3091
3092 BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd,
3093                            void *Msg,
3094                            unsigned long MsgLen,
3095                            u8 *pApAddr,
3096                            u16 *CapabilityInfo,
3097                            unsigned long *Timeout, u16 *ListenIntv);
3098
3099 BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd,
3100                           void *Msg,
3101                           unsigned long MsgLen,
3102                           u8 *pAddr,
3103                           unsigned long *Timeout, u16 *Alg);
3104
3105 BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd,
3106                            void *Msg,
3107                            unsigned long MsgLen,
3108                            char Ssid[], u8 *Ssidlen);
3109
3110 BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd,
3111                        void *Msg,
3112                        unsigned long MsgLen,
3113                        u8 *pAddr,
3114                        u16 *Alg,
3115                        u16 *Seq,
3116                        u16 *Status, char ChlgText[]);
3117
3118 BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void *pMsg, unsigned long MsgLen, u8 *pAddr2, u16 *pCapabilityInfo, u16 *pStatus, u16 *pAid, u8 SupRate[], u8 *pSupRateLen, u8 ExtRate[], u8 *pExtRateLen, struct rt_ht_capability_ie *pHtCapability, struct rt_add_ht_info_ie *pAddHtInfo,     /* AP might use this additional ht info IE */
3119                            u8 *pHtCapabilityLen,
3120                            u8 *pAddHtInfoLen,
3121                            u8 *pNewExtChannelOffset,
3122                            struct rt_edca_parm *pEdcaParm, u8 *pCkipFlag);
3123
3124 BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd,
3125                            void *Msg,
3126                            unsigned long MsgLen,
3127                            u8 *pAddr2, u16 *Reason);
3128
3129 BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd,
3130                              struct rt_eapol_packet *pMsg,
3131                              unsigned long MsgLen,
3132                              u8 MsgType, struct rt_mac_table_entry *pEntry);
3133
3134 BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd,
3135                          void *Msg,
3136                          unsigned long MsgLen,
3137                          u8 *pAddr2, u16 *Reason);
3138
3139 BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd,
3140                            void *Msg,
3141                            unsigned long MsgLen,
3142                            u8 *pAddr2,
3143                            char Ssid[], u8 *pSsidLen);
3144
3145 BOOLEAN GetTimBit(char *Ptr,
3146                   u16 Aid,
3147                   u8 *TimLen,
3148                   u8 *BcastFlag,
3149                   u8 *DtimCount,
3150                   u8 *DtimPeriod, u8 *MessageToMe);
3151
3152 u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel);
3153
3154 NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss);
3155
3156 BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd,
3157                            void *Msg, unsigned long MsgLen);
3158
3159 BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd,
3160                            void *Msg, unsigned long MsgLen, u8 *pAddr2);
3161
3162 unsigned long MakeOutgoingFrame(u8 *Buffer, unsigned long *Length, ...);
3163
3164 void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed);
3165
3166 u8 RandomByte(struct rt_rtmp_adapter *pAd);
3167
3168 void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pTxRate);
3169
3170 void MlmePeriodicExec(void *SystemSpecific1,
3171                       void *FunctionContext,
3172                       void *SystemSpecific2, void *SystemSpecific3);
3173
3174 void LinkDownExec(void *SystemSpecific1,
3175                   void *FunctionContext,
3176                   void *SystemSpecific2, void *SystemSpecific3);
3177
3178 void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd);
3179
3180 void MlmeAutoScan(struct rt_rtmp_adapter *pAd);
3181
3182 void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd);
3183
3184 BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen);
3185
3186 void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3187
3188 BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd);
3189
3190 void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd);
3191
3192 void MlmeSetTxRate(struct rt_rtmp_adapter *pAd,
3193                    struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate);
3194
3195 void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd,
3196                            struct rt_mac_table_entry *pEntry,
3197                            u8 **ppTable,
3198                            u8 *pTableSize, u8 *pInitTxRateIdx);
3199
3200 void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd,
3201                                  struct rt_mac_table_entry *pMacEntry, unsigned long Now);
3202
3203 void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3204
3205 void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm);
3206
3207 void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble);
3208
3209 void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAd);
3210
3211 void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd,
3212                        IN BOOLEAN bLinkUp, u8 apidx);
3213
3214 void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx);
3215
3216 void RTMPCheckRates(struct rt_rtmp_adapter *pAd,
3217                     IN u8 SupRate[], IN u8 *SupRateLen);
3218
3219 BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd,
3220                          u8 CentralChannel, u8 Channel);
3221
3222 BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd,
3223                     u8 Wcid,
3224                     struct rt_ht_capability_ie *pHtCapability,
3225                     struct rt_add_ht_info_ie *pAddHtInfo);
3226
3227 void StaQuickResponeForRateUpExec(void *SystemSpecific1,
3228                                   void *FunctionContext,
3229                                   void *SystemSpecific2,
3230                                   void *SystemSpecific3);
3231
3232 void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd);
3233
3234 char RTMPMaxRssi(struct rt_rtmp_adapter *pAd,
3235                  char Rssi0, char Rssi1, char Rssi2);
3236
3237 #ifdef RT30xx
3238 void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3239
3240 void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd);
3241
3242 #ifdef RTMP_EFUSE_SUPPORT
3243 /*2008/09/11:KH add to support efuse<-- */
3244 int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3245
3246 int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3247
3248 void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd,
3249                                 u16 Offset,
3250                                 u16 Length, u16 *pData);
3251
3252 int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd);
3253
3254 void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock);
3255
3256 int eFuse_init(struct rt_rtmp_adapter *pAd);
3257 /*2008/09/11:KH add to support efuse--> */
3258 #endif /* RTMP_EFUSE_SUPPORT // */
3259
3260 /* add by johnli, RF power sequence setup */
3261 void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd);
3262
3263 void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3264
3265 void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3266 /* end johnli */
3267
3268 #ifdef RT3070
3269 void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd);
3270 #endif /* RT3070 // */
3271 #ifdef RT3090
3272 void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd);
3273 #endif /* RT3090 // */
3274
3275 void RT30xxHaltAction(struct rt_rtmp_adapter *pAd);
3276
3277 void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3278 #endif /* RT30xx // */
3279
3280 void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd);
3281
3282 void AsicRxAntEvalTimeout(void *SystemSpecific1,
3283                           void *FunctionContext,
3284                           void *SystemSpecific2, void *SystemSpecific3);
3285
3286 void APSDPeriodicExec(void *SystemSpecific1,
3287                       void *FunctionContext,
3288                       void *SystemSpecific2, void *SystemSpecific3);
3289
3290 BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd,
3291                                            struct rt_mac_table_entry *pEntry);
3292
3293 u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3294
3295 void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry);
3296
3297 BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd);
3298
3299 int MlmeInit(struct rt_rtmp_adapter *pAd);
3300
3301 void MlmeHandler(struct rt_rtmp_adapter *pAd);
3302
3303 void MlmeHalt(struct rt_rtmp_adapter *pAd);
3304
3305 void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd);
3306
3307 void BuildChannelList(struct rt_rtmp_adapter *pAd);
3308
3309 u8 FirstChannel(struct rt_rtmp_adapter *pAd);
3310
3311 u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel);
3312
3313 void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd,
3314                             u8 AironetCellPowerLimit);
3315
3316 /* */
3317 /* Prototypes of function definition in rtmp_tkip.c */
3318 /* */
3319 void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd,
3320                         u8 *pTKey,
3321                         u8 KeyId,
3322                         u8 *pTA,
3323                         u8 *pMICKey,
3324                         u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32);
3325
3326 void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd,
3327                        u8 *pKey,
3328                        u8 *pDA,
3329                        u8 *pSA, u8 UserPriority, u8 *pMICKey);
3330
3331 BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd,
3332                                 u8 *pSrc,
3333                                 u8 *pDA,
3334                                 u8 *pSA,
3335                                 u8 *pMICKey,
3336                                 u8 UserPriority, u32 Len);
3337
3338 void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd,
3339                            void *pPacket,
3340                            u8 *pEncap,
3341                            struct rt_cipher_key *pKey, u8 apidx);
3342
3343 void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar);
3344
3345 void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes);
3346
3347 void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip);
3348
3349 BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd,
3350                             u8 *pData,
3351                             unsigned long DataByteCnt,
3352                             u8 UserPriority, struct rt_cipher_key *pWpaKey);
3353
3354 BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd,
3355                            u8 *pData,
3356                            unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey);
3357
3358 /* */
3359 /* Prototypes of function definition in cmm_info.c */
3360 /* */
3361 int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band);
3362
3363 int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg);
3364
3365 int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg);
3366
3367 int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd,
3368                     char *keyString,
3369                     struct rt_cipher_key *pSharedKey, int keyIdx);
3370
3371 int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd,
3372                        char *keyString,
3373                        u8 *pHashStr,
3374                        int hashStrLen, u8 *pPMKBuf);
3375
3376 /* */
3377 /* Prototypes of function definition in cmm_info.c */
3378 /* */
3379 void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd);
3380
3381 void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode);
3382
3383 void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt,
3384                     u8 *pMcsSet,
3385                     struct rt_ht_capability_ie *pHtCapability,
3386                     struct rt_add_ht_info_ie *pAddHtInfo);
3387
3388 void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd,
3389                                u8 BssIdx,
3390                                u8 KeyIdx,
3391                                u8 CipherAlg, struct rt_mac_table_entry *pEntry);
3392
3393 char *GetEncryptType(char enc);
3394
3395 char *GetAuthMode(char auth);
3396
3397 void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode);
3398
3399 void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx);
3400
3401 void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd,
3402                            u16 Event_flag,
3403                            u8 *pAddr, u8 BssIdx, char Rssi);
3404
3405 char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber);
3406
3407 /*===================================
3408         Function prototype in cmm_wpa.c
3409   =================================== */
3410 void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd,
3411                        struct rt_mac_table_entry *pEntry,
3412                        u8 *pHeader802_3,
3413                        u32 HdrLen,
3414                        u8 *pData,
3415                        u32 DataLen, IN BOOLEAN bClearFrame);
3416
3417 void WpaDerivePTK(struct rt_rtmp_adapter *pAd,
3418                   u8 *PMK,
3419                   u8 *ANonce,
3420                   u8 *AA,
3421                   u8 *SNonce,
3422                   u8 *SA, u8 *output, u32 len);
3423
3424 void GenRandom(struct rt_rtmp_adapter *pAd, u8 *macAddr, u8 *random);
3425
3426 BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd,
3427                           struct rt_mac_table_entry *pEntry,
3428                           u8 *pData,
3429                           unsigned long DataByteCount, u8 FromWhichBSSID);
3430
3431 void AES_GTK_KEY_UNWRAP(u8 *key,
3432                         u8 *plaintext,
3433                         u32 c_len, u8 *ciphertext);
3434
3435 BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd,
3436                               u8 *pKeyData,
3437                               u8 KeyDataLen,
3438                               u8 GroupKeyIndex,
3439                               u8 MsgType,
3440                               IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry);
3441
3442 void ConstructEapolMsg(struct rt_mac_table_entry *pEntry,
3443                        u8 GroupKeyWepStatus,
3444                        u8 MsgType,
3445                        u8 DefaultKeyIdx,
3446                        u8 *KeyNonce,
3447                        u8 *TxRSC,
3448                        u8 *GTK,
3449                        u8 *RSNIE,
3450                        u8 RSNIE_Len, struct rt_eapol_packet *pMsg);
3451
3452 int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd,
3453                                          struct rt_rx_blk *pRxBlk,
3454                                          IN NDIS_802_11_ENCRYPTION_STATUS
3455                                          GroupCipher,
3456                                          struct rt_cipher_key *pShard_key);
3457
3458 void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd,
3459                    u32 AuthMode, u32 WepStatus, u8 apidx);
3460
3461 /* */
3462 /* function prototype in ap_wpa.c */
3463 /* */
3464 void RTMPGetTxTscFromAsic(struct rt_rtmp_adapter *pAd,
3465                           u8 apidx, u8 *pTxTsc);
3466
3467 void APInstallPairwiseKey(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3468
3469 u32 APValidateRSNIE(struct rt_rtmp_adapter *pAd,
3470                      struct rt_mac_table_entry *pEntry,
3471                      u8 *pRsnIe, u8 rsnie_len);
3472
3473 void HandleCounterMeasure(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3474
3475 void WPAStart4WayHS(struct rt_rtmp_adapter *pAd,
3476                     struct rt_mac_table_entry *pEntry, unsigned long TimeInterval);
3477
3478 void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3479
3480 void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd,
3481                         struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3482
3483 void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd,
3484                         struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3485
3486 void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd,
3487                         struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3488
3489 void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd,
3490                         struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3491
3492 void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd,
3493                          struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3494
3495 void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd,
3496                          struct rt_mac_table_entry *pEntry,
3497                          void *Msg, u32 MsgLen);
3498
3499 void WpaDeriveGTK(u8 *PMK,
3500                   u8 *GNonce,
3501                   u8 *AA, u8 *output, u32 len);
3502
3503 void AES_GTK_KEY_WRAP(u8 *key,
3504                       u8 *plaintext,
3505                       u32 p_len, u8 *ciphertext);
3506
3507 /*typedef void (*TIMER_FUNCTION)(unsigned long); */
3508
3509 /* timeout -- ms */
3510 void RTMP_SetPeriodicTimer(struct timer_list *pTimer,
3511                            IN unsigned long timeout);
3512
3513 void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd,
3514                         struct timer_list *pTimer,
3515                         IN TIMER_FUNCTION function, void *data);
3516
3517 void RTMP_OS_Add_Timer(struct timer_list *pTimer,
3518                        IN unsigned long timeout);
3519
3520 void RTMP_OS_Mod_Timer(struct timer_list *pTimer,
3521                        IN unsigned long timeout);
3522
3523 void RTMP_OS_Del_Timer(struct timer_list *pTimer,
3524                        OUT BOOLEAN *pCancelled);
3525
3526 void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry);
3527
3528 void RTMPusecDelay(unsigned long usec);
3529
3530 int os_alloc_mem(struct rt_rtmp_adapter *pAd,
3531                          u8 **mem, unsigned long size);
3532
3533 int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem);
3534
3535 void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd,
3536                                unsigned long Length,
3537                                IN BOOLEAN Cached,
3538                                void **VirtualAddress,
3539                                dma_addr_t *PhysicalAddress);
3540
3541 void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd);
3542
3543 int AdapterBlockAllocateMemory(void *handle, void **ppAd);
3544
3545 void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd,
3546                                u32 Index,
3547                                unsigned long Length,
3548                                IN BOOLEAN Cached,
3549                                void **VirtualAddress,
3550                                dma_addr_t *PhysicalAddress);
3551
3552 void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3553                                 u32 Index,
3554                                 unsigned long Length,
3555                                 IN BOOLEAN Cached,
3556                                 void **VirtualAddress,
3557                                 dma_addr_t *PhysicalAddress);
3558
3559 void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3560                             unsigned long Length,
3561                             IN BOOLEAN Cached,
3562                             void *VirtualAddress,
3563                             dma_addr_t PhysicalAddress);
3564
3565 void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd,
3566                                  unsigned long Length,
3567                                  IN BOOLEAN Cached,
3568                                  void **VirtualAddress,
3569                                  dma_addr_t *PhysicalAddress);
3570
3571 void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd,
3572                                unsigned long Length,
3573                                IN BOOLEAN Cached,
3574                                void **VirtualAddress,
3575                                dma_addr_t *PhysicalAddress);
3576
3577 void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd,
3578                          unsigned long Length,
3579                          void *VirtualAddress,
3580                          dma_addr_t PhysicalAddress);
3581
3582 void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size);
3583
3584 void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd,
3585                                          unsigned long Length,
3586                                          IN BOOLEAN Cached,
3587                                          void **VirtualAddress,
3588                                          OUT dma_addr_t *PhysicalAddress);
3589
3590 void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd,
3591                                          unsigned long Length,
3592                                          IN BOOLEAN Cached,
3593                                          void **VirtualAddress);
3594
3595 void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd,
3596                                            unsigned long Length);
3597
3598 void RTMP_QueryPacketInfo(void *pPacket,
3599                           struct rt_packet_info *pPacketInfo,
3600                           u8 **pSrcBufVA, u32 *pSrcBufLen);
3601
3602 void RTMP_QueryNextPacketInfo(void **ppPacket,
3603                               struct rt_packet_info *pPacketInfo,
3604                               u8 **pSrcBufVA, u32 *pSrcBufLen);
3605
3606 BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk);
3607
3608 struct rt_rtmp_sg_list *rt_get_sg_list_from_packet(void *pPacket,
3609                                                 struct rt_rtmp_sg_list *sg);
3610
3611 void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket);
3612
3613 u32 BA_Reorder_AMSDU_Annnounce(struct rt_rtmp_adapter *pAd, void *pPacket);
3614
3615 struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID);
3616
3617 void *duplicate_pkt(struct rt_rtmp_adapter *pAd,
3618                            u8 *pHeader802_3,
3619                            u32 HdrLen,
3620                            u8 *pData,
3621                            unsigned long DataSize, u8 FromWhichBSSID);
3622
3623 void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd,
3624                                          void *pOldPkt);
3625
3626 void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd,
3627                                        struct rt_ba_rec_entry *pBAEntry,
3628                                        unsigned long Now32);
3629
3630 void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd,
3631                        struct rt_mac_table_entry *pEntry,
3632                        u8 TID,
3633                        u16 TimeOut,
3634                        unsigned long DelayTime, IN BOOLEAN isForced);
3635
3636 void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid);
3637
3638 BOOLEAN OS_Need_Clone_Packet(void);
3639
3640 void build_tx_packet(struct rt_rtmp_adapter *pAd,
3641                      void *pPacket,
3642                      u8 *pFrame, unsigned long FrameLen);
3643
3644 void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
3645                           u8 Wcid,
3646                           u8 TID,
3647                           IN BOOLEAN bPassive, IN BOOLEAN bForceSend);
3648
3649 void BARecSessionTearDown(struct rt_rtmp_adapter *pAd,
3650                           u8 Wcid, u8 TID, IN BOOLEAN bPassive);
3651
3652 BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num);
3653 void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd);
3654
3655 char *rstrtok(char *s, IN const char *ct);
3656
3657 /*//////// common ioctl functions ////////// */
3658 int SetCommonHT(struct rt_rtmp_adapter *pAd);
3659
3660 int WpaCheckEapCode(struct rt_rtmp_adapter *pAd,
3661                     u8 *pFrame, u16 FrameLen, u16 OffSet);
3662
3663 void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd,
3664                                       IN BOOLEAN bUnicast);
3665
3666 int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd);
3667
3668 BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc);
3669
3670 /* AMPDU packet indication */
3671 void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd,
3672                            struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3673
3674 /* AMSDU packet indication */
3675 void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd,
3676                            struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3677
3678 /* Normal legacy Rx packet indication */
3679 void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd,
3680                             struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3681
3682 void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd,
3683                            struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3684
3685 void update_os_packet_info(struct rt_rtmp_adapter *pAd,
3686                            struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3687
3688 void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd,
3689                                  struct rt_rx_blk *pRxBlk,
3690                                  u8 *pHeader802_3,
3691                                  u8 FromWhichBSSID);
3692
3693 /* remove LLC and get 802_3 Header */
3694 #define  RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3)    \
3695 {                                                                                                                                                               \
3696         u8 *_pRemovedLLCSNAP = NULL, *_pDA, *_pSA;                                 \
3697                                                                                                                                                                 \
3698         if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH))        {            \
3699                 _pDA = _pRxBlk->pHeader->Addr3;                                         \
3700                 _pSA = (u8 *)_pRxBlk->pHeader + sizeof(struct rt_header_802_11);                \
3701         }                                                                           \
3702         else    {\
3703                 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA))       {\
3704                         _pDA = _pRxBlk->pHeader->Addr1;                                     \
3705                 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS))                                                                 \
3706                         _pSA = _pRxBlk->pHeader->Addr2;                                                                         \
3707                 else                                                                                                                                    \
3708                         _pSA = _pRxBlk->pHeader->Addr3;                                     \
3709                 }                                                                       \
3710                 else    {       \
3711                         _pDA = _pRxBlk->pHeader->Addr1;                                     \
3712                         _pSA = _pRxBlk->pHeader->Addr2;                                     \
3713                 }                                                                       \
3714         }                                                                           \
3715                                                                                                                                                                 \
3716         CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData,                             \
3717                 _pRxBlk->DataSize, _pRemovedLLCSNAP);                                   \
3718 }
3719
3720 void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd,
3721                                           void *pPacket,
3722                                           u8 FromWhichBSSID);
3723
3724 #define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
3725                         Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
3726                         /*announce_802_3_packet(_pAd, _pPacket); */
3727
3728 void *DuplicatePacket(struct rt_rtmp_adapter *pAd,
3729                              void *pPacket, u8 FromWhichBSSID);
3730
3731 void *ClonePacket(struct rt_rtmp_adapter *pAd,
3732                          void *pPacket,
3733                          u8 *pData, unsigned long DataSize);
3734
3735 /* Normal, AMPDU or AMSDU */
3736 void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3737                                  struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3738
3739 void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3740                               struct rt_mac_table_entry *pEntry,
3741                               struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3742
3743 void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd,
3744                         struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI);
3745
3746 void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd,
3747                                  OUT PRT28XX_RXD_STRUC pSaveRxD,
3748                                  OUT BOOLEAN *pbReschedule,
3749                                  IN u32 *pRxPending);
3750
3751 void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3752
3753 enum {
3754         DIDmsg_lnxind_wlansniffrm = 0x00000044,
3755         DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
3756         DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
3757         DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
3758         DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
3759         DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
3760         DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
3761         DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
3762         DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
3763         DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
3764         DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
3765 };
3766 enum {
3767         P80211ENUM_msgitem_status_no_value = 0x00
3768 };
3769 enum {
3770         P80211ENUM_truth_false = 0x00,
3771         P80211ENUM_truth_true = 0x01
3772 };
3773
3774 /* Definition from madwifi */
3775 struct rt_p80211item_uint32 {
3776         u32 did;
3777         u16 status;
3778         u16 len;
3779         u32 data;
3780 };
3781
3782 struct rt_wlan_ng_prism2_header {
3783         u32 msgcode;
3784         u32 msglen;
3785 #define WLAN_DEVNAMELEN_MAX 16
3786         u8 devname[WLAN_DEVNAMELEN_MAX];
3787         struct rt_p80211item_uint32 hosttime;
3788         struct rt_p80211item_uint32 mactime;
3789         struct rt_p80211item_uint32 channel;
3790         struct rt_p80211item_uint32 rssi;
3791         struct rt_p80211item_uint32 sq;
3792         struct rt_p80211item_uint32 signal;
3793         struct rt_p80211item_uint32 noise;
3794         struct rt_p80211item_uint32 rate;
3795         struct rt_p80211item_uint32 istx;
3796         struct rt_p80211item_uint32 frmlen;
3797 };
3798
3799 /* The radio capture header precedes the 802.11 header. */
3800 struct PACKED rt_ieee80211_radiotap_header {
3801         u8 it_version;  /* Version 0. Only increases
3802                                  * for drastic changes,
3803                                  * introduction of compatible
3804                                  * new fields does not count.
3805                                  */
3806         u8 it_pad;
3807         u16 it_len;             /* length of the whole
3808                                  * header in bytes, including
3809                                  * it_version, it_pad,
3810                                  * it_len, and data fields.
3811                                  */
3812         u32 it_present; /* A bitmap telling which
3813                                  * fields are present. Set bit 31
3814                                  * (0x80000000) to extend the
3815                                  * bitmap by another 32 bits.
3816                                  * Additional extensions are made
3817                                  * by setting bit 31.
3818                                  */
3819 };
3820
3821 enum ieee80211_radiotap_type {
3822         IEEE80211_RADIOTAP_TSFT = 0,
3823         IEEE80211_RADIOTAP_FLAGS = 1,
3824         IEEE80211_RADIOTAP_RATE = 2,
3825         IEEE80211_RADIOTAP_CHANNEL = 3,
3826         IEEE80211_RADIOTAP_FHSS = 4,
3827         IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
3828         IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
3829         IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
3830         IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
3831         IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
3832         IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
3833         IEEE80211_RADIOTAP_ANTENNA = 11,
3834         IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
3835         IEEE80211_RADIOTAP_DB_ANTNOISE = 13
3836 };
3837
3838 #define WLAN_RADIOTAP_PRESENT (                 \
3839         (1 << IEEE80211_RADIOTAP_TSFT)  |       \
3840         (1 << IEEE80211_RADIOTAP_FLAGS) |       \
3841         (1 << IEEE80211_RADIOTAP_RATE)  |       \
3842          0)
3843
3844 struct rt_wlan_radiotap_header {
3845         struct rt_ieee80211_radiotap_header wt_ihdr;
3846         long long wt_tsft;
3847         u8 wt_flags;
3848         u8 wt_rate;
3849 };
3850 /* Definition from madwifi */
3851
3852 void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3853
3854 void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates);
3855
3856 int Set_FixedTxMode_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3857
3858 BOOLEAN RT28XXChipsetCheck(IN void *_dev_p);
3859
3860 void RT28XXDMADisable(struct rt_rtmp_adapter *pAd);
3861
3862 void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd);
3863
3864 void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd,
3865                                int apidx,
3866                                unsigned long BeaconLen, unsigned long UpdatePos);
3867
3868 int rt28xx_init(struct rt_rtmp_adapter *pAd,
3869                 char *pDefaultMac, char *pHostName);
3870
3871 int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd);
3872
3873 void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd);
3874
3875 int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd);
3876
3877 void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd);
3878
3879 void tbtt_tasklet(unsigned long data);
3880
3881 struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd,
3882                            struct rt_rtmp_os_netdev_op_hook *pNetHook);
3883
3884 BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev);
3885
3886 int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType);
3887
3888 BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd);
3889
3890 #ifdef RTMP_MAC_PCI
3891 /* */
3892 /* Function Prototype in cmm_data_pci.c */
3893 /* */
3894 u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd,
3895                                struct rt_tx_blk *pTxBlk,
3896                                IN BOOLEAN bIsLast, u16 *FreeNumber);
3897
3898 u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
3899                                      struct rt_tx_blk *pTxBlk,
3900                                      IN BOOLEAN bIsLast,
3901                                      u16 *FreeNumber);
3902
3903 u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
3904                                     struct rt_tx_blk *pTxBlk,
3905                                     u8 frameNum, u16 *FreeNumber);
3906
3907 u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
3908                                    struct rt_tx_blk *pTxBlk,
3909                                    u8 fragNum, u16 *FreeNumber);
3910
3911 u16 RtmpPCI_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
3912                                   struct rt_tx_blk *pTxBlk,
3913                                   IN BOOLEAN bIsLast, u16 *FreeNumber);
3914
3915 void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
3916                                   struct rt_tx_blk *pTxBlk,
3917                                   u16 totalMPDUSize,
3918                                   u16 FirstTxIdx);
3919
3920 void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd,
3921                           u8 QueIdx, u16 LastTxIdx);
3922
3923 void RtmpPCIDataKickOut(struct rt_rtmp_adapter *pAd,
3924                         struct rt_tx_blk *pTxBlk, u8 QueIdx);
3925
3926 int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd,
3927                        u8 QueIdx,
3928                        void *pPacket,
3929                        u8 *pSrcBufVA, u32 SrcBufLen);
3930
3931 int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
3932                              struct rt_header_802_11 *pHeader,
3933                              struct rt_rxwi *pRxWI, IN PRT28XX_RXD_STRUC pRxD);
3934
3935 BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd,
3936                               u8 Level, u16 TbttNumToNextWakeUp);
3937
3938 BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level);
3939
3940 void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd);
3941
3942 void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd);
3943
3944 void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level);
3945
3946 void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max);
3947
3948 void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd);
3949
3950 void PsPollWakeExec(void *SystemSpecific1,
3951                     void *FunctionContext,
3952                     void *SystemSpecific2, void *SystemSpecific3);
3953
3954 void RadioOnExec(void *SystemSpecific1,
3955                  void *FunctionContext,
3956                  void *SystemSpecific2, void *SystemSpecific3);
3957
3958 void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
3959
3960 void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
3961                                          u16 TbttNumToNextWakeUp);
3962
3963 void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd);
3964
3965 void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
3966 #endif /* RTMP_MAC_PCI // */
3967
3968 #ifdef RTMP_MAC_USB
3969 /* */
3970 /* Function Prototype in rtusb_bulk.c */
3971 /* */
3972 void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd,
3973                      struct rt_tx_context *pTxContext,
3974                      u8 BulkOutPipeId, IN usb_complete_t Func);
3975
3976 void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd,
3977                        struct rt_ht_tx_context *pTxContext,
3978                        u8 BulkOutPipeId,
3979                        unsigned long BulkOutSize, IN usb_complete_t Func);
3980
3981 void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
3982
3983 void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd);
3984
3985 void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd);
3986
3987 void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd,
3988                             u8 BulkOutPipeId, u8 Index);
3989
3990 void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd);
3991
3992 void RTUSBBulkOutRTSFrame(struct rt_rtmp_adapter *pAd);
3993
3994 void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd);
3995
3996 void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd);
3997
3998 void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index);
3999
4000 void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd);
4001
4002 void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd);
4003
4004 void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd);
4005
4006 void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd);
4007
4008 void DoBulkIn(struct rt_rtmp_adapter *pAd);
4009
4010 void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
4011
4012 void RTUSBBulkRxHandle(IN unsigned long data);
4013
4014 /* */
4015 /* Function Prototype in rtusb_io.c */
4016 /* */
4017 int RTUSBMultiRead(struct rt_rtmp_adapter *pAd,
4018                         u16 Offset, u8 *pData, u16 length);
4019
4020 int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd,
4021                     u16 Offset, const u8 *pData, u16 length);
4022
4023 int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd,
4024                             u16 Offset, const u8 *pData);
4025
4026 int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd,
4027                               u8 Id, u8 *pValue);
4028
4029 int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd,
4030                                u8 Id, u8 Value);
4031
4032 int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value);
4033
4034 int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd,
4035                              u32 TransferFlags,
4036                              u8 ReservedBits,
4037                              u8 Request,
4038                              u16 Value,
4039                              u16 Index,
4040                              void *TransferBuffer,
4041                              u32 TransferBufferLength);
4042
4043 int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd,
4044                          u16 Offset, u8 *pData, u16 length);
4045
4046 int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd,
4047                           u16 Offset, u8 *pData, u16 length);
4048
4049 void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd);
4050
4051 int RTUSBWakeUp(struct rt_rtmp_adapter *pAd);
4052
4053 void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq);
4054
4055 int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd,
4056                                     IN NDIS_OID Oid,
4057                                     IN BOOLEAN SetInformation,
4058                                     void *pInformationBuffer,
4059                                     u32 InformationBufferLength);
4060
4061 int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd,
4062                                     IN NDIS_OID Oid,
4063                                     void *pInformationBuffer,
4064                                     u32 InformationBufferLength);
4065
4066 void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt);
4067
4068 int RTUSBCmdThread(IN void *Context);
4069
4070 void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd);
4071
4072 void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd);
4073
4074 void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd);
4075
4076 void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd);
4077
4078 void RTUSBWatchDog(struct rt_rtmp_adapter *pAd);
4079
4080 int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd,
4081                                u16 Offset, u32 Value);
4082
4083 int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd,
4084                               u16 Offset, u32 *pValue);
4085
4086 int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd,
4087                           u16 Offset, u16 Value);
4088
4089 int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd,
4090                        const u8 *pFwImage, unsigned long FwLen);
4091
4092 int RTUSBVenderReset(struct rt_rtmp_adapter *pAd);
4093
4094 int RTUSBSetHardWareRegister(struct rt_rtmp_adapter *pAdapter, void *pBuf);
4095
4096 int RTUSBQueryHardWareRegister(struct rt_rtmp_adapter *pAdapter,
4097                                        void *pBuf);
4098
4099 void CMDHandler(struct rt_rtmp_adapter *pAd);
4100
4101 int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAdapter);
4102
4103 void MacTableInitialize(struct rt_rtmp_adapter *pAd);
4104
4105 void MlmeSetPsm(struct rt_rtmp_adapter *pAd, u16 psm);
4106
4107 int RTMPWPAAddKeyProc(struct rt_rtmp_adapter *pAd, void *pBuf);
4108
4109 void AsicRxAntEvalAction(struct rt_rtmp_adapter *pAd);
4110
4111 void append_pkt(struct rt_rtmp_adapter *pAd,
4112                 u8 *pHeader802_3,
4113                 u32 HdrLen,
4114                 u8 *pData,
4115                 unsigned long DataSize, void **ppPacket);
4116
4117 u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd,
4118                                 void *pPacket,
4119                                 u8 *pData, unsigned long DataSize);
4120
4121 int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
4122                              struct rt_header_802_11 *pHeader,
4123                              struct rt_rxwi *pRxWI,
4124                              IN PRT28XX_RXD_STRUC pRxINFO);
4125
4126 void RTUSBMlmeHardTransmit(struct rt_rtmp_adapter *pAd, struct rt_mgmt *pMgmt);
4127
4128 int MlmeThread(void *Context);
4129
4130 /* */
4131 /* Function Prototype in rtusb_data.c */
4132 /* */
4133 int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd,
4134                                        u8 BulkOutPipeId,
4135                                        u32 NumberRequired);
4136
4137 BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId);
4138
4139 void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd,
4140                      struct rt_txinfo *pTxInfo,
4141                      u16 USBDMApktLen,
4142                      IN BOOLEAN bWiv,
4143                      u8 QueueSel, u8 NextValid, u8 TxBurst);
4144
4145 /* */
4146 /* Function Prototype in cmm_data_usb.c */
4147 /* */
4148 u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
4149                                   struct rt_tx_blk *pTxBlk,
4150                                   IN BOOLEAN bIsLast, u16 *FreeNumber);
4151
4152 u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
4153                                      struct rt_tx_blk *pTxBlk,
4154                                      IN BOOLEAN bIsLast,
4155                                      u16 *FreeNumber);
4156
4157 u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
4158                                    struct rt_tx_blk *pTxBlk,
4159                                    u8 fragNum, u16 *FreeNumber);
4160
4161 u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
4162                                     struct rt_tx_blk *pTxBlk,
4163                                     u8 frameNum, u16 *FreeNumber);
4164
4165 void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
4166                                   struct rt_tx_blk *pTxBlk,
4167                                   u16 totalMPDUSize, u16 TxIdx);
4168
4169 void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd,
4170                           u8 QueIdx, u16 TxIdx);
4171
4172 void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd,
4173                         struct rt_tx_blk *pTxBlk, u8 QueIdx);
4174
4175 int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd,
4176                        u8 QueIdx,
4177                        void *pPacket,
4178                        u8 *pSrcBufVA, u32 SrcBufLen);
4179
4180 void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd,
4181                              u8 QueIdx,
4182                              u8 *pNullFrame, u32 frameLen);
4183
4184 void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1,
4185                                       void *FunctionContext,
4186                                       void *SystemSpecific2,
4187                                       void *SystemSpecific3);
4188
4189 void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
4190
4191 void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
4192                                          u16 TbttNumToNextWakeUp);
4193
4194 void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd);
4195
4196 void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
4197 #endif /* RTMP_MAC_USB // */
4198
4199 void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4200
4201 void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4202
4203 #ifdef RTMP_TIMER_TASK_SUPPORT
4204 int RtmpTimerQThread(IN void *Context);
4205
4206 struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd,
4207                                         struct rt_ralink_timer *pTimer);
4208
4209 BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd,
4210                          struct rt_ralink_timer *pTimer);
4211
4212 void RtmpTimerQExit(struct rt_rtmp_adapter *pAd);
4213
4214 void RtmpTimerQInit(struct rt_rtmp_adapter *pAd);
4215 #endif /* RTMP_TIMER_TASK_SUPPORT // */
4216
4217 void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd);
4218
4219 BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd,
4220                             struct rt_mac_table_entry *pEntry,
4221                             u8 MaxSupportedRateIn500Kbps,
4222                             struct rt_ht_capability_ie *pHtCapability,
4223                             u8 HtCapabilityLen,
4224                             struct rt_add_ht_info_ie *pAddHtInfo,
4225                             u8 AddHtInfoLen, u16 CapabilityInfo);
4226
4227 BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
4228                      struct rt_mlme_queue_elem *pElem,
4229                      struct rt_ralink_timer *pAuthTimer,
4230                      char *pSMName,
4231                      u16 SeqNo,
4232                      u8 *pNewElement, unsigned long ElementLen);
4233
4234 void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd);
4235
4236 void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd);
4237
4238 void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth);
4239
4240 int rt28xx_close(struct net_device *dev);
4241 int rt28xx_open(struct net_device *dev);
4242
4243 #define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
4244 #define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
4245 #define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
4246
4247 #ifdef LINUX
4248 __inline int VIRTUAL_IF_UP(struct rt_rtmp_adapter *pAd)
4249 {
4250         if (VIRTUAL_IF_NUM(pAd) == 0) {
4251                 if (rt28xx_open(pAd->net_dev) != 0) {
4252                         DBGPRINT(RT_DEBUG_TRACE,
4253                                  ("rt28xx_open return fail!\n"));
4254                         return -1;
4255                 }
4256         } else {
4257         }
4258         VIRTUAL_IF_INC(pAd);
4259         return 0;
4260 }
4261
4262 __inline void VIRTUAL_IF_DOWN(struct rt_rtmp_adapter *pAd)
4263 {
4264         VIRTUAL_IF_DEC(pAd);
4265         if (VIRTUAL_IF_NUM(pAd) == 0)
4266                 rt28xx_close(pAd->net_dev);
4267         return;
4268 }
4269 #endif /* LINUX // */
4270
4271 /*
4272         OS Related funciton prototype definitions.
4273         TODO: Maybe we need to move these function prototypes to other proper place.
4274 */
4275 int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd,
4276                             u32 eventType,
4277                             int flags,
4278                             u8 *pSrcMac,
4279                             u8 *pData, u32 dataLen);
4280
4281 int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr);
4282
4283 int RtmpOSNetDevAttach(struct net_device *pNetDev,
4284                        struct rt_rtmp_os_netdev_op_hook *pDevOpHook);
4285
4286 void RtmpOSNetDevClose(struct net_device *pNetDev);
4287
4288 void RtmpOSNetDevDetach(struct net_device *pNetDev);
4289
4290 int RtmpOSNetDevAlloc(struct net_device **pNewNetDev, u32 privDataSize);
4291
4292 void RtmpOSNetDevFree(struct net_device *pNetDev);
4293
4294 struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName);
4295
4296 void RtmpOSNetDeviceRefPut(struct net_device *pNetDev);
4297
4298 struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd,
4299                             int devType,
4300                             int devNum,
4301                             int privMemSize, char *pNamePrefix);
4302
4303 /*
4304         Task operation related function prototypes
4305 */
4306 void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask);
4307
4308 int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask);
4309
4310 int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask);
4311
4312 int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask,
4313                            char *pTaskName, void * pPriv);
4314
4315 int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask,
4316                              IN int (*fn) (void *), IN void *arg);
4317
4318 /*
4319         File operation related function prototypes
4320 */
4321 struct file *RtmpOSFileOpen(IN char *pPath, IN int flag, IN int mode);
4322
4323 int RtmpOSFileClose(struct file *osfd);
4324
4325 void RtmpOSFileSeek(struct file *osfd, IN int offset);
4326
4327 int RtmpOSFileRead(struct file *osfd, IN char *pDataPtr, IN int readLen);
4328
4329 int RtmpOSFileWrite(struct file *osfd, IN char *pDataPtr, IN int writeLen);
4330
4331 #endif /* __RTMP_H__ */