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