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