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