Merge branch 'bugzilla-13041' into release
[linux-2.6] / 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 "link_list.h"
44 #include "spectrum_def.h"
45
46
47 #ifdef CONFIG_STA_SUPPORT
48 #include "aironet.h"
49 #endif // CONFIG_STA_SUPPORT //
50
51 //#define DBG_DIAGNOSE          1
52
53 #if defined(CONFIG_AP_SUPPORT) && defined(CONFIG_STA_SUPPORT)
54 #define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd)        if(_pAd->OpMode == OPMODE_AP)
55 #define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd)       if(_pAd->OpMode == OPMODE_STA)
56 #else
57 #define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd)
58 #define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd)
59 #endif
60
61 #define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
62 #define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
63 #define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
64
65
66
67 //
68 //  NDIS Version definitions
69 //
70 #ifdef  NDIS50_MINIPORT
71 #define RTMP_NDIS_MAJOR_VERSION     5
72 #define RTMP_NDIS_MINOR_VERSION     0
73 #endif
74
75 #ifdef  NDIS51_MINIPORT
76 #define RTMP_NDIS_MAJOR_VERSION     5
77 #define RTMP_NDIS_MINOR_VERSION     1
78 #endif
79
80 extern  char    NIC_VENDOR_DESC[];
81 extern  int     NIC_VENDOR_DESC_LEN;
82
83 extern  unsigned char   SNAP_AIRONET[];
84 extern  unsigned char   CipherSuiteCiscoCCKM[];
85 extern  unsigned char   CipherSuiteCiscoCCKMLen;
86 extern  unsigned char   CipherSuiteCiscoCCKM24[];
87 extern  unsigned char   CipherSuiteCiscoCCKM24Len;
88 extern  unsigned char   CipherSuiteCCXTkip[];
89 extern  unsigned char   CipherSuiteCCXTkipLen;
90 extern  unsigned char   CISCO_OUI[];
91 extern  UCHAR   BaSizeArray[4];
92
93 extern UCHAR BROADCAST_ADDR[MAC_ADDR_LEN];
94 extern UCHAR MULTICAST_ADDR[MAC_ADDR_LEN];
95 extern UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN];
96 extern ULONG BIT32[32];
97 extern UCHAR BIT8[8];
98 extern char* CipherName[];
99 extern char* MCSToMbps[];
100 extern UCHAR     RxwiMCSToOfdmRate[12];
101 extern UCHAR SNAP_802_1H[6];
102 extern UCHAR SNAP_BRIDGE_TUNNEL[6];
103 extern UCHAR SNAP_AIRONET[8];
104 extern UCHAR CKIP_LLC_SNAP[8];
105 extern UCHAR EAPOL_LLC_SNAP[8];
106 extern UCHAR EAPOL[2];
107 extern UCHAR IPX[2];
108 extern UCHAR APPLE_TALK[2];
109 extern UCHAR RateIdToPlcpSignal[12]; // see IEEE802.11a-1999 p.14
110 extern UCHAR     OfdmRateToRxwiMCS[];
111 extern UCHAR OfdmSignalToRateId[16] ;
112 extern UCHAR default_cwmin[4];
113 extern UCHAR default_cwmax[4];
114 extern UCHAR default_sta_aifsn[4];
115 extern UCHAR MapUserPriorityToAccessCategory[8];
116
117 extern USHORT RateUpPER[];
118 extern USHORT RateDownPER[];
119 extern UCHAR  Phy11BNextRateDownward[];
120 extern UCHAR  Phy11BNextRateUpward[];
121 extern UCHAR  Phy11BGNextRateDownward[];
122 extern UCHAR  Phy11BGNextRateUpward[];
123 extern UCHAR  Phy11ANextRateDownward[];
124 extern UCHAR  Phy11ANextRateUpward[];
125 extern CHAR   RssiSafeLevelForTxRate[];
126 extern UCHAR  RateIdToMbps[];
127 extern USHORT RateIdTo500Kbps[];
128
129 extern UCHAR  CipherSuiteWpaNoneTkip[];
130 extern UCHAR  CipherSuiteWpaNoneTkipLen;
131
132 extern UCHAR  CipherSuiteWpaNoneAes[];
133 extern UCHAR  CipherSuiteWpaNoneAesLen;
134
135 extern UCHAR  SsidIe;
136 extern UCHAR  SupRateIe;
137 extern UCHAR  ExtRateIe;
138
139 #ifdef DOT11_N_SUPPORT
140 extern UCHAR  HtCapIe;
141 extern UCHAR  AddHtInfoIe;
142 extern UCHAR  NewExtChanIe;
143 #ifdef DOT11N_DRAFT3
144 extern UCHAR  ExtHtCapIe;
145 #endif // DOT11N_DRAFT3 //
146 #endif // DOT11_N_SUPPORT //
147
148 extern UCHAR  ErpIe;
149 extern UCHAR  DsIe;
150 extern UCHAR  TimIe;
151 extern UCHAR  WpaIe;
152 extern UCHAR  Wpa2Ie;
153 extern UCHAR  IbssIe;
154 extern UCHAR  Ccx2Ie;
155
156 extern UCHAR  WPA_OUI[];
157 extern UCHAR  RSN_OUI[];
158 extern UCHAR  WME_INFO_ELEM[];
159 extern UCHAR  WME_PARM_ELEM[];
160 extern UCHAR  Ccx2QosInfo[];
161 extern UCHAR  Ccx2IeInfo[];
162 extern UCHAR  RALINK_OUI[];
163 extern UCHAR  PowerConstraintIE[];
164
165
166 extern UCHAR  RateSwitchTable[];
167 extern UCHAR  RateSwitchTable11B[];
168 extern UCHAR  RateSwitchTable11G[];
169 extern UCHAR  RateSwitchTable11BG[];
170
171 #ifdef DOT11_N_SUPPORT
172 extern UCHAR  RateSwitchTable11BGN1S[];
173 extern UCHAR  RateSwitchTable11BGN2S[];
174 extern UCHAR  RateSwitchTable11BGN2SForABand[];
175 extern UCHAR  RateSwitchTable11N1S[];
176 extern UCHAR  RateSwitchTable11N2S[];
177 extern UCHAR  RateSwitchTable11N2SForABand[];
178
179 #ifdef CONFIG_STA_SUPPORT
180 extern UCHAR  PRE_N_HT_OUI[];
181 #endif // CONFIG_STA_SUPPORT //
182 #endif // DOT11_N_SUPPORT //
183
184 #define MAXSEQ          (0xFFF)
185
186 #ifdef RALINK_ATE
187 typedef struct _ATE_INFO {
188         UCHAR   Mode;
189         CHAR    TxPower0;
190         CHAR    TxPower1;
191         CHAR    TxAntennaSel;
192         CHAR    RxAntennaSel;
193         TXWI_STRUC  TxWI;         // TXWI
194         USHORT  QID;
195         UCHAR   Addr1[MAC_ADDR_LEN];
196         UCHAR   Addr2[MAC_ADDR_LEN];
197         UCHAR   Addr3[MAC_ADDR_LEN];
198         UCHAR   Channel;
199         UINT32  TxLength;
200         UINT32  TxCount;
201         UINT32  TxDoneCount; // Tx DMA Done
202         UINT32  RFFreqOffset;
203         BOOLEAN bRxFer;
204         BOOLEAN bQATxStart; // Have compiled QA in and use it to ATE tx.
205         BOOLEAN bQARxStart;     // Have compiled QA in and use it to ATE rx.
206         BOOLEAN bFWLoading;     // Reload firmware when ATE is done.
207         UINT32  RxTotalCnt;
208         UINT32  RxCntPerSec;
209
210         CHAR    LastSNR0;             // last received SNR
211         CHAR    LastSNR1;             // last received SNR for 2nd  antenna
212         CHAR    LastRssi0;            // last received RSSI
213         CHAR    LastRssi1;            // last received RSSI for 2nd  antenna
214         CHAR    LastRssi2;            // last received RSSI for 3rd  antenna
215         CHAR    AvgRssi0;             // last 8 frames' average RSSI
216         CHAR    AvgRssi1;             // last 8 frames' average RSSI
217         CHAR    AvgRssi2;             // last 8 frames' average RSSI
218         SHORT   AvgRssi0X8;           // sum of last 8 frames' RSSI
219         SHORT   AvgRssi1X8;           // sum of last 8 frames' RSSI
220         SHORT   AvgRssi2X8;           // sum of last 8 frames' RSSI
221
222         UINT32  NumOfAvgRssiSample;
223
224 #ifdef RALINK_28xx_QA
225         // Tx frame
226         USHORT          HLen; // Header Length
227         USHORT          PLen; // Pattern Length
228         UCHAR           Header[32]; // Header buffer
229         UCHAR           Pattern[32]; // Pattern buffer
230         USHORT          DLen; // Data Length
231         USHORT          seq;
232         UINT32          CID;
233         THREAD_PID              AtePid;
234         // counters
235         UINT32          U2M;
236         UINT32          OtherData;
237         UINT32          Beacon;
238         UINT32          OtherCount;
239         UINT32          TxAc0;
240         UINT32          TxAc1;
241         UINT32          TxAc2;
242         UINT32          TxAc3;
243         UINT32          TxHCCA;
244         UINT32          TxMgmt;
245         UINT32          RSSI0;
246         UINT32          RSSI1;
247         UINT32          RSSI2;
248         UINT32          SNR0;
249         UINT32          SNR1;
250         // control
251         //UINT32                Repeat; // Tx Cpu count
252         UCHAR           TxStatus; // task Tx status // 0 --> task is idle, 1 --> task is running
253 #endif // RALINK_28xx_QA //
254 }       ATE_INFO, *PATE_INFO;
255
256 #ifdef RALINK_28xx_QA
257 struct ate_racfghdr {
258         UINT32          magic_no;
259         USHORT          command_type;
260         USHORT          command_id;
261         USHORT          length;
262         USHORT          sequence;
263         USHORT          status;
264         UCHAR           data[2046];
265 }  __attribute__((packed));
266 #endif // RALINK_28xx_QA //
267 #endif // RALINK_ATE //
268
269 #ifdef DOT11_N_SUPPORT
270 struct reordering_mpdu
271 {
272         struct reordering_mpdu  *next;
273         PNDIS_PACKET                    pPacket;                /* coverted to 802.3 frame */
274         int                                             Sequence;               /* sequence number of MPDU */
275         BOOLEAN                                 bAMSDU;
276 };
277
278 struct reordering_list
279 {
280         struct reordering_mpdu *next;
281         int     qlen;
282 };
283
284 struct reordering_mpdu_pool
285 {
286         PVOID                                   mem;
287         NDIS_SPIN_LOCK                  lock;
288         struct reordering_list  freelist;
289 };
290 #endif // DOT11_N_SUPPORT //
291
292 typedef struct  _RSSI_SAMPLE {
293         CHAR                    LastRssi0;             // last received RSSI
294         CHAR                    LastRssi1;             // last received RSSI
295         CHAR                    LastRssi2;             // last received RSSI
296         CHAR                    AvgRssi0;
297         CHAR                    AvgRssi1;
298         CHAR                    AvgRssi2;
299         SHORT                   AvgRssi0X8;
300         SHORT                   AvgRssi1X8;
301         SHORT                   AvgRssi2X8;
302 } RSSI_SAMPLE;
303
304 //
305 //  Queue structure and macros
306 //
307 typedef struct  _QUEUE_ENTRY    {
308         struct _QUEUE_ENTRY     *Next;
309 }   QUEUE_ENTRY, *PQUEUE_ENTRY;
310
311 // Queue structure
312 typedef struct  _QUEUE_HEADER   {
313         PQUEUE_ENTRY    Head;
314         PQUEUE_ENTRY    Tail;
315         ULONG           Number;
316 }   QUEUE_HEADER, *PQUEUE_HEADER;
317
318 #define InitializeQueueHeader(QueueHeader)              \
319 {                                                       \
320         (QueueHeader)->Head = (QueueHeader)->Tail = NULL;   \
321         (QueueHeader)->Number = 0;                          \
322 }
323
324 #define RemoveHeadQueue(QueueHeader)                \
325 (QueueHeader)->Head;                                \
326 {                                                   \
327         PQUEUE_ENTRY pNext;                             \
328         if ((QueueHeader)->Head != NULL)                                \
329         {                                                                                               \
330                 pNext = (QueueHeader)->Head->Next;          \
331                 (QueueHeader)->Head = pNext;                \
332                 if (pNext == NULL)                          \
333                         (QueueHeader)->Tail = NULL;             \
334                 (QueueHeader)->Number--;                    \
335         }                                                                                               \
336 }
337
338 #define InsertHeadQueue(QueueHeader, QueueEntry)            \
339 {                                                           \
340                 ((PQUEUE_ENTRY)QueueEntry)->Next = (QueueHeader)->Head; \
341                 (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry);       \
342                 if ((QueueHeader)->Tail == NULL)                        \
343                         (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry);   \
344                 (QueueHeader)->Number++;                                \
345 }
346
347 #define InsertTailQueue(QueueHeader, QueueEntry)                \
348 {                                                               \
349         ((PQUEUE_ENTRY)QueueEntry)->Next = NULL;                    \
350         if ((QueueHeader)->Tail)                                    \
351                 (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
352         else                                                        \
353                 (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry);       \
354         (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry);           \
355         (QueueHeader)->Number++;                                    \
356 }
357
358 //
359 //  Macros for flag and ref count operations
360 //
361 #define RTMP_SET_FLAG(_M, _F)       ((_M)->Flags |= (_F))
362 #define RTMP_CLEAR_FLAG(_M, _F)     ((_M)->Flags &= ~(_F))
363 #define RTMP_CLEAR_FLAGS(_M)        ((_M)->Flags = 0)
364 #define RTMP_TEST_FLAG(_M, _F)      (((_M)->Flags & (_F)) != 0)
365 #define RTMP_TEST_FLAGS(_M, _F)     (((_M)->Flags & (_F)) == (_F))
366
367 // Macro for power save flag.
368 #define RTMP_SET_PSFLAG(_M, _F)       ((_M)->PSFlags |= (_F))
369 #define RTMP_CLEAR_PSFLAG(_M, _F)     ((_M)->PSFlags &= ~(_F))
370 #define RTMP_CLEAR_PSFLAGS(_M)        ((_M)->PSFlags = 0)
371 #define RTMP_TEST_PSFLAG(_M, _F)      (((_M)->PSFlags & (_F)) != 0)
372 #define RTMP_TEST_PSFLAGS(_M, _F)     (((_M)->PSFlags & (_F)) == (_F))
373
374 #define OPSTATUS_SET_FLAG(_pAd, _F)     ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
375 #define OPSTATUS_CLEAR_FLAG(_pAd, _F)   ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
376 #define OPSTATUS_TEST_FLAG(_pAd, _F)    (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
377
378 #define CLIENT_STATUS_SET_FLAG(_pEntry,_F)      ((_pEntry)->ClientStatusFlags |= (_F))
379 #define CLIENT_STATUS_CLEAR_FLAG(_pEntry,_F)    ((_pEntry)->ClientStatusFlags &= ~(_F))
380 #define CLIENT_STATUS_TEST_FLAG(_pEntry,_F)     (((_pEntry)->ClientStatusFlags & (_F)) != 0)
381
382 #define RX_FILTER_SET_FLAG(_pAd, _F)    ((_pAd)->CommonCfg.PacketFilter |= (_F))
383 #define RX_FILTER_CLEAR_FLAG(_pAd, _F)  ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
384 #define RX_FILTER_TEST_FLAG(_pAd, _F)   (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
385
386 #ifdef CONFIG_STA_SUPPORT
387 #define STA_NO_SECURITY_ON(_p)          (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
388 #define STA_WEP_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
389 #define STA_TKIP_ON(_p)                 (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
390 #define STA_AES_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
391
392 #define STA_TGN_WIFI_ON(_p)             (_p->StaCfg.bTGnWifiTest == TRUE)
393 #endif // CONFIG_STA_SUPPORT //
394
395 #define CKIP_KP_ON(_p)                          ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
396 #define CKIP_CMIC_ON(_p)                        ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
397
398
399 #define INC_RING_INDEX(_idx, _RingSize)    \
400 {                                          \
401     (_idx) = (_idx+1) % (_RingSize);       \
402 }
403
404 #define IS_RT3070(_pAd)                         (((_pAd)->MACVersion & 0xffff0000) == 0x30700000)
405
406 #define RING_PACKET_INIT(_TxRing, _idx)    \
407 {                                          \
408     _TxRing->Cell[_idx].pNdisPacket = NULL;                              \
409     _TxRing->Cell[_idx].pNextNdisPacket = NULL;                              \
410 }
411
412 #define TXDT_INIT(_TxD)    \
413 {                                          \
414         NdisZeroMemory(_TxD, TXD_SIZE); \
415         _TxD->DMADONE = 1;                              \
416 }
417
418 //Set last data segment
419 #define RING_SET_LASTDS(_TxD, _IsSD0)    \
420 {                                          \
421     if (_IsSD0) {_TxD->LastSec0 = 1;}     \
422     else {_TxD->LastSec1 = 1;}     \
423 }
424
425 // Increase TxTsc value for next transmission
426 // TODO:
427 // When i==6, means TSC has done one full cycle, do re-keying stuff follow specs
428 // Should send a special event microsoft defined to request re-key
429 #define INC_TX_TSC(_tsc)                                \
430 {                                                       \
431     int i=0;                                            \
432     while (++_tsc[i] == 0x0)                            \
433     {                                                   \
434         i++;                                            \
435         if (i == 6)                                     \
436             break;                                      \
437     }                                                   \
438 }
439
440 #ifdef DOT11_N_SUPPORT
441 // StaActive.SupportedHtPhy.MCSSet is copied from AP beacon.  Don't need to update here.
442 #define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd)                                 \
443 {                                                                                       \
444         _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth;      \
445         _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs;      \
446         _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF;      \
447         _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20;      \
448         _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40;      \
449         _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC;      \
450         _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC;      \
451         _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset;      \
452         _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth;      \
453         _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode;      \
454         _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent;      \
455         NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(UCHAR) * 16);\
456 }
457
458 #define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability)                                 \
459 {                                                                                       \
460         _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (UCHAR)(_pHtCapability->HtCapInfo.AMsduSize);      \
461         _pAd->MacTab.Content[BSSID_WCID].MmpsMode= (UCHAR)(_pHtCapability->HtCapInfo.MimoPs);   \
462         _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (UCHAR)(_pHtCapability->HtCapParm.MaxRAmpduFactor);  \
463 }
464 #endif // DOT11_N_SUPPORT //
465
466 //
467 // MACRO for 32-bit PCI register read / write
468 //
469 // Usage : RTMP_IO_READ32(
470 //              PRTMP_ADAPTER pAd,
471 //              ULONG Register_Offset,
472 //              PULONG  pValue)
473 //
474 //         RTMP_IO_WRITE32(
475 //              PRTMP_ADAPTER pAd,
476 //              ULONG Register_Offset,
477 //              ULONG Value)
478 //
479
480 //
481 // BBP & RF are using indirect access. Before write any value into it.
482 // We have to make sure there is no outstanding command pending via checking busy bit.
483 //
484 #define MAX_BUSY_COUNT  100         // Number of retry before failing access BBP & RF indirect register
485 //
486 #define RTMP_RF_IO_WRITE32(_A, _V)                  \
487 {                                                   \
488     PHY_CSR4_STRUC  Value;                          \
489     ULONG           BusyCnt = 0;                    \
490     if ((_A)->bPCIclkOff)                       \
491     {                                                                                           \
492         return;                                                                         \
493     }                                               \
494     do {                                            \
495         RTMP_IO_READ32(_A, RF_CSR_CFG0, &Value.word);  \
496         if (Value.field.Busy == IDLE)               \
497             break;                                  \
498         BusyCnt++;                                  \
499     }   while (BusyCnt < MAX_BUSY_COUNT);           \
500     if (BusyCnt < MAX_BUSY_COUNT)                   \
501     {                                               \
502         RTMP_IO_WRITE32(_A, RF_CSR_CFG0, _V);          \
503     }                                               \
504 }
505
506 #define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)        \
507 {                                                       \
508     BBP_CSR_CFG_STRUC  BbpCsr;                             \
509     int             i, k;                               \
510     for (i=0; i<MAX_BUSY_COUNT; i++)                    \
511     {                                                   \
512         RTMP_IO_READ32(_A, BBP_CSR_CFG, &BbpCsr.word);     \
513         if (BbpCsr.field.Busy == BUSY)                  \
514         {                                               \
515             continue;                                   \
516         }                                               \
517         BbpCsr.word = 0;                                \
518         BbpCsr.field.fRead = 1;                         \
519         BbpCsr.field.BBP_RW_MODE = 1;                         \
520         BbpCsr.field.Busy = 1;                          \
521         BbpCsr.field.RegNum = _I;                       \
522         RTMP_IO_WRITE32(_A, BBP_CSR_CFG, BbpCsr.word);     \
523         for (k=0; k<MAX_BUSY_COUNT; k++)                \
524         {                                               \
525             RTMP_IO_READ32(_A, BBP_CSR_CFG, &BbpCsr.word); \
526             if (BbpCsr.field.Busy == IDLE)              \
527                 break;                                  \
528         }                                               \
529         if ((BbpCsr.field.Busy == IDLE) &&              \
530             (BbpCsr.field.RegNum == _I))                \
531         {                                               \
532             *(_pV) = (UCHAR)BbpCsr.field.Value;         \
533             break;                                      \
534         }                                               \
535     }                                                   \
536     if (BbpCsr.field.Busy == BUSY)                      \
537     {                                                   \
538         DBGPRINT_ERR(("DFS BBP read R%d fail\n", _I));      \
539         *(_pV) = (_A)->BbpWriteLatch[_I];               \
540     }                                                   \
541 }
542
543 //#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)    {}
544 // Read BBP register by register's ID. Generate PER to test BA
545 #define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)        \
546 {                                                       \
547     BBP_CSR_CFG_STRUC  BbpCsr;                             \
548     int             i, k;                               \
549     if ((_A)->bPCIclkOff == FALSE)                     \
550     {                                                   \
551     for (i=0; i<MAX_BUSY_COUNT; i++)                    \
552     {                                                   \
553                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
554         if (BbpCsr.field.Busy == BUSY)                  \
555         {                                               \
556             continue;                                   \
557         }                                               \
558         BbpCsr.word = 0;                                \
559         BbpCsr.field.fRead = 1;                         \
560         BbpCsr.field.BBP_RW_MODE = 1;                         \
561         BbpCsr.field.Busy = 1;                          \
562         BbpCsr.field.RegNum = _I;                       \
563                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
564                 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                 \
565                 RTMPusecDelay(1000);                                                    \
566         for (k=0; k<MAX_BUSY_COUNT; k++)                \
567         {                                               \
568                         RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                        \
569             if (BbpCsr.field.Busy == IDLE)              \
570                 break;                                  \
571         }                                               \
572         if ((BbpCsr.field.Busy == IDLE) &&              \
573             (BbpCsr.field.RegNum == _I))                \
574         {                                               \
575             *(_pV) = (UCHAR)BbpCsr.field.Value;         \
576             break;                                      \
577         }                                               \
578     }                                                   \
579     if (BbpCsr.field.Busy == BUSY)                      \
580     {                                                   \
581                 DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", _I, BbpCsr.word));    \
582         *(_pV) = (_A)->BbpWriteLatch[_I];               \
583                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
584                 BbpCsr.field.Busy = 0;                          \
585                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
586     }                                                   \
587     }                   \
588 }
589
590 #define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)        \
591 {                                                       \
592     BBP_CSR_CFG_STRUC  BbpCsr;                             \
593     int             BusyCnt;                            \
594     for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)  \
595     {                                                   \
596         RTMP_IO_READ32(_A, BBP_CSR_CFG, &BbpCsr.word);     \
597         if (BbpCsr.field.Busy == BUSY)                  \
598             continue;                                   \
599         BbpCsr.word = 0;                                \
600         BbpCsr.field.fRead = 0;                         \
601         BbpCsr.field.BBP_RW_MODE = 1;                         \
602         BbpCsr.field.Busy = 1;                          \
603         BbpCsr.field.Value = _V;                        \
604         BbpCsr.field.RegNum = _I;                       \
605         RTMP_IO_WRITE32(_A, BBP_CSR_CFG, BbpCsr.word);     \
606         (_A)->BbpWriteLatch[_I] = _V;                   \
607         break;                                          \
608     }                                                   \
609     if (BusyCnt == MAX_BUSY_COUNT)                      \
610     {                                                   \
611         DBGPRINT_ERR(("BBP write R%d fail\n", _I));     \
612     }                                                   \
613 }
614
615 // Write BBP register by register's ID & value
616 #define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)        \
617 {                                                       \
618     BBP_CSR_CFG_STRUC  BbpCsr;                             \
619     int             BusyCnt;                            \
620     if ((_A)->bPCIclkOff == FALSE)                     \
621     {                                                   \
622     for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)  \
623     {                                                   \
624                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
625         if (BbpCsr.field.Busy == BUSY)                  \
626             continue;                                   \
627         BbpCsr.word = 0;                                \
628         BbpCsr.field.fRead = 0;                         \
629         BbpCsr.field.BBP_RW_MODE = 1;                         \
630         BbpCsr.field.Busy = 1;                          \
631         BbpCsr.field.Value = _V;                        \
632         BbpCsr.field.RegNum = _I;                       \
633                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
634                 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                 \
635             if (_A->OpMode == OPMODE_AP)                    \
636                 RTMPusecDelay(1000);                                                    \
637         (_A)->BbpWriteLatch[_I] = _V;                   \
638         break;                                          \
639     }                                                   \
640     if (BusyCnt == MAX_BUSY_COUNT)                      \
641     {                                                   \
642                 DBGPRINT_ERR(("BBP write R%d=0x%x fail\n", _I, BbpCsr.word));   \
643                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
644                 BbpCsr.field.Busy = 0;                          \
645                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
646     }                                                   \
647     }                                                   \
648 }
649
650
651 #define     MAP_CHANNEL_ID_TO_KHZ(ch, khz)  {               \
652                 switch (ch)                                 \
653                 {                                           \
654                     case 1:     khz = 2412000;   break;     \
655                     case 2:     khz = 2417000;   break;     \
656                     case 3:     khz = 2422000;   break;     \
657                     case 4:     khz = 2427000;   break;     \
658                     case 5:     khz = 2432000;   break;     \
659                     case 6:     khz = 2437000;   break;     \
660                     case 7:     khz = 2442000;   break;     \
661                     case 8:     khz = 2447000;   break;     \
662                     case 9:     khz = 2452000;   break;     \
663                     case 10:    khz = 2457000;   break;     \
664                     case 11:    khz = 2462000;   break;     \
665                     case 12:    khz = 2467000;   break;     \
666                     case 13:    khz = 2472000;   break;     \
667                     case 14:    khz = 2484000;   break;     \
668                     case 36:  /* UNII */  khz = 5180000;   break;     \
669                     case 40:  /* UNII */  khz = 5200000;   break;     \
670                     case 44:  /* UNII */  khz = 5220000;   break;     \
671                     case 48:  /* UNII */  khz = 5240000;   break;     \
672                     case 52:  /* UNII */  khz = 5260000;   break;     \
673                     case 56:  /* UNII */  khz = 5280000;   break;     \
674                     case 60:  /* UNII */  khz = 5300000;   break;     \
675                     case 64:  /* UNII */  khz = 5320000;   break;     \
676                     case 149: /* UNII */  khz = 5745000;   break;     \
677                     case 153: /* UNII */  khz = 5765000;   break;     \
678                     case 157: /* UNII */  khz = 5785000;   break;     \
679                     case 161: /* UNII */  khz = 5805000;   break;     \
680                     case 165: /* UNII */  khz = 5825000;   break;     \
681                     case 100: /* HiperLAN2 */  khz = 5500000;   break;     \
682                     case 104: /* HiperLAN2 */  khz = 5520000;   break;     \
683                     case 108: /* HiperLAN2 */  khz = 5540000;   break;     \
684                     case 112: /* HiperLAN2 */  khz = 5560000;   break;     \
685                     case 116: /* HiperLAN2 */  khz = 5580000;   break;     \
686                     case 120: /* HiperLAN2 */  khz = 5600000;   break;     \
687                     case 124: /* HiperLAN2 */  khz = 5620000;   break;     \
688                     case 128: /* HiperLAN2 */  khz = 5640000;   break;     \
689                     case 132: /* HiperLAN2 */  khz = 5660000;   break;     \
690                     case 136: /* HiperLAN2 */  khz = 5680000;   break;     \
691                     case 140: /* HiperLAN2 */  khz = 5700000;   break;     \
692                     case 34:  /* Japan MMAC */   khz = 5170000;   break;   \
693                     case 38:  /* Japan MMAC */   khz = 5190000;   break;   \
694                     case 42:  /* Japan MMAC */   khz = 5210000;   break;   \
695                     case 46:  /* Japan MMAC */   khz = 5230000;   break;   \
696                     case 184: /* Japan */   khz = 4920000;   break;   \
697                     case 188: /* Japan */   khz = 4940000;   break;   \
698                     case 192: /* Japan */   khz = 4960000;   break;   \
699                     case 196: /* Japan */   khz = 4980000;   break;   \
700                     case 208: /* Japan, means J08 */   khz = 5040000;   break;   \
701                     case 212: /* Japan, means J12 */   khz = 5060000;   break;   \
702                     case 216: /* Japan, means J16 */   khz = 5080000;   break;   \
703                     default:    khz = 2412000;   break;     \
704                 }                                           \
705             }
706
707 #define     MAP_KHZ_TO_CHANNEL_ID(khz, ch)  {               \
708                 switch (khz)                                \
709                 {                                           \
710                     case 2412000:    ch = 1;     break;     \
711                     case 2417000:    ch = 2;     break;     \
712                     case 2422000:    ch = 3;     break;     \
713                     case 2427000:    ch = 4;     break;     \
714                     case 2432000:    ch = 5;     break;     \
715                     case 2437000:    ch = 6;     break;     \
716                     case 2442000:    ch = 7;     break;     \
717                     case 2447000:    ch = 8;     break;     \
718                     case 2452000:    ch = 9;     break;     \
719                     case 2457000:    ch = 10;    break;     \
720                     case 2462000:    ch = 11;    break;     \
721                     case 2467000:    ch = 12;    break;     \
722                     case 2472000:    ch = 13;    break;     \
723                     case 2484000:    ch = 14;    break;     \
724                     case 5180000:    ch = 36;  /* UNII */  break;     \
725                     case 5200000:    ch = 40;  /* UNII */  break;     \
726                     case 5220000:    ch = 44;  /* UNII */  break;     \
727                     case 5240000:    ch = 48;  /* UNII */  break;     \
728                     case 5260000:    ch = 52;  /* UNII */  break;     \
729                     case 5280000:    ch = 56;  /* UNII */  break;     \
730                     case 5300000:    ch = 60;  /* UNII */  break;     \
731                     case 5320000:    ch = 64;  /* UNII */  break;     \
732                     case 5745000:    ch = 149; /* UNII */  break;     \
733                     case 5765000:    ch = 153; /* UNII */  break;     \
734                     case 5785000:    ch = 157; /* UNII */  break;     \
735                     case 5805000:    ch = 161; /* UNII */  break;     \
736                     case 5825000:    ch = 165; /* UNII */  break;     \
737                     case 5500000:    ch = 100; /* HiperLAN2 */  break;     \
738                     case 5520000:    ch = 104; /* HiperLAN2 */  break;     \
739                     case 5540000:    ch = 108; /* HiperLAN2 */  break;     \
740                     case 5560000:    ch = 112; /* HiperLAN2 */  break;     \
741                     case 5580000:    ch = 116; /* HiperLAN2 */  break;     \
742                     case 5600000:    ch = 120; /* HiperLAN2 */  break;     \
743                     case 5620000:    ch = 124; /* HiperLAN2 */  break;     \
744                     case 5640000:    ch = 128; /* HiperLAN2 */  break;     \
745                     case 5660000:    ch = 132; /* HiperLAN2 */  break;     \
746                     case 5680000:    ch = 136; /* HiperLAN2 */  break;     \
747                     case 5700000:    ch = 140; /* HiperLAN2 */  break;     \
748                     case 5170000:    ch = 34;  /* Japan MMAC */   break;   \
749                     case 5190000:    ch = 38;  /* Japan MMAC */   break;   \
750                     case 5210000:    ch = 42;  /* Japan MMAC */   break;   \
751                     case 5230000:    ch = 46;  /* Japan MMAC */   break;   \
752                     case 4920000:    ch = 184; /* Japan */  break;   \
753                     case 4940000:    ch = 188; /* Japan */  break;   \
754                     case 4960000:    ch = 192; /* Japan */  break;   \
755                     case 4980000:    ch = 196; /* Japan */  break;   \
756                     case 5040000:    ch = 208; /* Japan, means J08 */  break;   \
757                     case 5060000:    ch = 212; /* Japan, means J12 */  break;   \
758                     case 5080000:    ch = 216; /* Japan, means J16 */  break;   \
759                     default:         ch = 1;     break;     \
760                 }                                           \
761             }
762
763 //
764 // Common fragment list structure -  Identical to the scatter gather frag list structure
765 //
766 #define NIC_MAX_PHYS_BUF_COUNT              8
767
768 typedef struct _RTMP_SCATTER_GATHER_ELEMENT {
769     PVOID               Address;
770     ULONG               Length;
771     PULONG              Reserved;
772 } RTMP_SCATTER_GATHER_ELEMENT, *PRTMP_SCATTER_GATHER_ELEMENT;
773
774
775 typedef struct _RTMP_SCATTER_GATHER_LIST {
776     ULONG  NumberOfElements;
777     PULONG Reserved;
778     RTMP_SCATTER_GATHER_ELEMENT Elements[NIC_MAX_PHYS_BUF_COUNT];
779 } RTMP_SCATTER_GATHER_LIST, *PRTMP_SCATTER_GATHER_LIST;
780
781 //
782 //  Some utility macros
783 //
784 #ifndef min
785 #define min(_a, _b)     (((_a) < (_b)) ? (_a) : (_b))
786 #endif
787
788 #ifndef max
789 #define max(_a, _b)     (((_a) > (_b)) ? (_a) : (_b))
790 #endif
791
792 #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))))
793
794 #define INC_COUNTER64(Val)          (Val.QuadPart++)
795
796 #define INFRA_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
797 #define ADHOC_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
798 #define MONITOR_ON(_p)              (((_p)->StaCfg.BssType) == BSS_MONITOR)
799 #define IDLE_ON(_p)                 (!INFRA_ON(_p) && !ADHOC_ON(_p))
800
801 // Check LEAP & CCKM flags
802 #define LEAP_ON(_p)                 (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
803 #define LEAP_CCKM_ON(_p)            ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
804
805 // if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required
806 #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap)                \
807 {                                                                                                                               \
808         if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500)          \
809         {                                                                                                                       \
810                 _pExtraLlcSnapEncap = SNAP_802_1H;                                              \
811                 if (NdisEqualMemory(IPX, _pBufVA + 12, 2) ||                    \
812                         NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2))           \
813                 {                                                                                                               \
814                         _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;                       \
815                 }                                                                                                               \
816         }                                                                                                                       \
817         else                                                                                                            \
818         {                                                                                                                       \
819                 _pExtraLlcSnapEncap = NULL;                                                             \
820         }                                                                                                                       \
821 }
822
823 // New Define for new Tx Path.
824 #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap)       \
825 {                                                                                                                               \
826         if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500)                        \
827         {                                                                                                                       \
828                 _pExtraLlcSnapEncap = SNAP_802_1H;                                              \
829                 if (NdisEqualMemory(IPX, _pBufVA, 2) ||                                 \
830                         NdisEqualMemory(APPLE_TALK, _pBufVA, 2))                        \
831                 {                                                                                                               \
832                         _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;                       \
833                 }                                                                                                               \
834         }                                                                                                                       \
835         else                                                                                                            \
836         {                                                                                                                       \
837                 _pExtraLlcSnapEncap = NULL;                                                             \
838         }                                                                                                                       \
839 }
840
841
842 #define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType)                   \
843 {                                                                       \
844     NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN);                           \
845     NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN);          \
846     NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
847 }
848
849 // if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way.
850 // else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field
851 // else remove the LLC/SNAP field from the result Ethernet frame
852 // Patch for WHQL only, which did not turn on Netbios but use IPX within its payload
853 // Note:
854 //     _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO
855 //     _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed
856 #define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP)      \
857 {                                                                       \
858     char LLC_Len[2];                                                    \
859                                                                         \
860     _pRemovedLLCSNAP = NULL;                                            \
861     if (NdisEqualMemory(SNAP_802_1H, _pData, 6)  ||                     \
862         NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6))                 \
863     {                                                                   \
864         PUCHAR pProto = _pData + 6;                                     \
865                                                                         \
866         if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) &&  \
867             NdisEqualMemory(SNAP_802_1H, _pData, 6))                    \
868         {                                                               \
869             LLC_Len[0] = (UCHAR)(_DataSize / 256);                      \
870             LLC_Len[1] = (UCHAR)(_DataSize % 256);                      \
871             MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);          \
872         }                                                               \
873         else                                                            \
874         {                                                               \
875             MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto);           \
876             _pRemovedLLCSNAP = _pData;                                  \
877             _DataSize -= LENGTH_802_1_H;                                \
878             _pData += LENGTH_802_1_H;                                   \
879         }                                                               \
880     }                                                                   \
881     else                                                                \
882     {                                                                   \
883         LLC_Len[0] = (UCHAR)(_DataSize / 256);                          \
884         LLC_Len[1] = (UCHAR)(_DataSize % 256);                          \
885         MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);              \
886     }                                                                   \
887 }
888
889 #define SWITCH_AB( _pAA, _pBB)    \
890 {                                                                           \
891     PVOID pCC;                                                          \
892     pCC = _pBB;                                                 \
893     _pBB = _pAA;                                                 \
894     _pAA = pCC;                                                 \
895 }
896
897 // Enqueue this frame to MLME engine
898 // We need to enqueue the whole frame because MLME need to pass data type
899 // information from 802.11 header
900 #define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal)        \
901 {                                                                                       \
902     UINT32 High32TSF, Low32TSF;                                                          \
903     RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF);                                       \
904     RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF);                                        \
905     MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (UCHAR)_Rssi0, (UCHAR)_Rssi1,(UCHAR)_Rssi2,_FrameSize, _pFrame, (UCHAR)_PlcpSignal);   \
906 }
907
908 #define NDIS_QUERY_BUFFER(_NdisBuf, _ppVA, _pBufLen)                    \
909     NdisQueryBuffer(_NdisBuf, _ppVA, _pBufLen)
910
911 #define MAC_ADDR_EQUAL(pAddr1,pAddr2)           RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
912 #define SSID_EQUAL(ssid1, len1, ssid2, len2)    ((len1==len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
913
914 //
915 // Check if it is Japan W53(ch52,56,60,64) channel.
916 //
917 #define JapanChannelCheck(channel)  ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
918
919 #ifdef CONFIG_STA_SUPPORT
920 #define STA_PORT_SECURED(_pAd) \
921 { \
922         _pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
923         RTMP_SET_PSFLAG(_pAd, fRTMP_PS_CAN_GO_SLEEP); \
924         NdisAcquireSpinLock(&(_pAd)->MacTabLock); \
925         _pAd->MacTab.Content[BSSID_WCID].PortSecured = _pAd->StaCfg.PortSecured; \
926         NdisReleaseSpinLock(&(_pAd)->MacTabLock); \
927 }
928 #endif // CONFIG_STA_SUPPORT //
929
930
931 //
932 // Register set pair for initialzation register set definition
933 //
934 typedef struct  _RTMP_REG_PAIR
935 {
936         ULONG   Register;
937         ULONG   Value;
938 } RTMP_REG_PAIR, *PRTMP_REG_PAIR;
939
940 typedef struct  _REG_PAIR
941 {
942         UCHAR   Register;
943         UCHAR   Value;
944 } REG_PAIR, *PREG_PAIR;
945
946 //
947 // Register set pair for initialzation register set definition
948 //
949 typedef struct  _RTMP_RF_REGS
950 {
951         UCHAR   Channel;
952         ULONG   R1;
953         ULONG   R2;
954         ULONG   R3;
955         ULONG   R4;
956 } RTMP_RF_REGS, *PRTMP_RF_REGS;
957
958 typedef struct _FREQUENCY_ITEM {
959         UCHAR   Channel;
960         UCHAR   N;
961         UCHAR   R;
962         UCHAR   K;
963 } FREQUENCY_ITEM, *PFREQUENCY_ITEM;
964
965 //
966 //  Data buffer for DMA operation, the buffer must be contiguous physical memory
967 //  Both DMA to / from CPU use the same structure.
968 //
969 typedef struct  _RTMP_DMABUF
970 {
971         ULONG                   AllocSize;
972         PVOID                   AllocVa;            // TxBuf virtual address
973         NDIS_PHYSICAL_ADDRESS   AllocPa;            // TxBuf physical address
974 } RTMP_DMABUF, *PRTMP_DMABUF;
975
976
977 typedef union   _HEADER_802_11_SEQ{
978 #ifdef RT_BIG_ENDIAN
979     struct {
980         USHORT                  Sequence:12;
981         USHORT                  Frag:4;
982     }   field;
983 #else
984     struct {
985         USHORT                  Frag:4;
986         USHORT                  Sequence:12;
987     }   field;
988 #endif
989     USHORT           value;
990 }       HEADER_802_11_SEQ, *PHEADER_802_11_SEQ;
991
992 //
993 //  Data buffer for DMA operation, the buffer must be contiguous physical memory
994 //  Both DMA to / from CPU use the same structure.
995 //
996 typedef struct  _RTMP_REORDERBUF
997 {
998         BOOLEAN                 IsFull;
999         PVOID                   AllocVa;            // TxBuf virtual address
1000         UCHAR                   Header802_3[14];
1001         HEADER_802_11_SEQ                       Sequence;       //support compressed bitmap BA, so no consider fragment in BA
1002         UCHAR           DataOffset;
1003         USHORT          Datasize;
1004         ULONG                   AllocSize;
1005         NDIS_PHYSICAL_ADDRESS   AllocPa;            // TxBuf physical address
1006 }   RTMP_REORDERBUF, *PRTMP_REORDERBUF;
1007
1008 //
1009 // Control block (Descriptor) for all ring descriptor DMA operation, buffer must be
1010 // contiguous physical memory. NDIS_PACKET stored the binding Rx packet descriptor
1011 // which won't be released, driver has to wait until upper layer return the packet
1012 // before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair
1013 // to describe the packet buffer. For Tx, NDIS_PACKET stored the tx packet descriptor
1014 // which driver should ACK upper layer when the tx is physically done or failed.
1015 //
1016 typedef struct _RTMP_DMACB
1017 {
1018         ULONG                   AllocSize;          // Control block size
1019         PVOID                   AllocVa;            // Control block virtual address
1020         NDIS_PHYSICAL_ADDRESS   AllocPa;            // Control block physical address
1021         PNDIS_PACKET pNdisPacket;
1022         PNDIS_PACKET pNextNdisPacket;
1023
1024         RTMP_DMABUF             DmaBuf;             // Associated DMA buffer structure
1025 } RTMP_DMACB, *PRTMP_DMACB;
1026
1027 typedef struct _RTMP_TX_BUF
1028 {
1029         PQUEUE_ENTRY    Next;
1030         UCHAR           Index;
1031         ULONG                   AllocSize;          // Control block size
1032         PVOID                   AllocVa;            // Control block virtual address
1033         NDIS_PHYSICAL_ADDRESS   AllocPa;            // Control block physical address
1034 } RTMP_TXBUF, *PRTMP_TXBUF;
1035
1036 typedef struct _RTMP_RX_BUF
1037 {
1038         BOOLEAN           InUse;
1039         ULONG                   ByBaRecIndex;
1040         RTMP_REORDERBUF MAP_RXBuf[MAX_RX_REORDERBUF];
1041 } RTMP_RXBUF, *PRTMP_RXBUF;
1042 typedef struct _RTMP_TX_RING
1043 {
1044         RTMP_DMACB  Cell[TX_RING_SIZE];
1045         UINT32          TxCpuIdx;
1046         UINT32          TxDmaIdx;
1047         UINT32          TxSwFreeIdx;    // software next free tx index
1048 } RTMP_TX_RING, *PRTMP_TX_RING;
1049
1050 typedef struct _RTMP_RX_RING
1051 {
1052         RTMP_DMACB  Cell[RX_RING_SIZE];
1053         UINT32          RxCpuIdx;
1054         UINT32          RxDmaIdx;
1055         INT32           RxSwReadIdx;    // software next read index
1056 } RTMP_RX_RING, *PRTMP_RX_RING;
1057
1058 typedef struct _RTMP_MGMT_RING
1059 {
1060         RTMP_DMACB  Cell[MGMT_RING_SIZE];
1061         UINT32          TxCpuIdx;
1062         UINT32          TxDmaIdx;
1063         UINT32          TxSwFreeIdx; // software next free tx index
1064 } RTMP_MGMT_RING, *PRTMP_MGMT_RING;
1065
1066 //
1067 //  Statistic counter structure
1068 //
1069 typedef struct _COUNTER_802_3
1070 {
1071         // General Stats
1072         ULONG       GoodTransmits;
1073         ULONG       GoodReceives;
1074         ULONG       TxErrors;
1075         ULONG       RxErrors;
1076         ULONG       RxNoBuffer;
1077
1078         // Ethernet Stats
1079         ULONG       RcvAlignmentErrors;
1080         ULONG       OneCollision;
1081         ULONG       MoreCollisions;
1082
1083 } COUNTER_802_3, *PCOUNTER_802_3;
1084
1085 typedef struct _COUNTER_802_11 {
1086         ULONG           Length;
1087         LARGE_INTEGER   LastTransmittedFragmentCount;
1088         LARGE_INTEGER   TransmittedFragmentCount;
1089         LARGE_INTEGER   MulticastTransmittedFrameCount;
1090         LARGE_INTEGER   FailedCount;
1091         LARGE_INTEGER   RetryCount;
1092         LARGE_INTEGER   MultipleRetryCount;
1093         LARGE_INTEGER   RTSSuccessCount;
1094         LARGE_INTEGER   RTSFailureCount;
1095         LARGE_INTEGER   ACKFailureCount;
1096         LARGE_INTEGER   FrameDuplicateCount;
1097         LARGE_INTEGER   ReceivedFragmentCount;
1098         LARGE_INTEGER   MulticastReceivedFrameCount;
1099         LARGE_INTEGER   FCSErrorCount;
1100 } COUNTER_802_11, *PCOUNTER_802_11;
1101
1102 typedef struct _COUNTER_RALINK {
1103         ULONG           TransmittedByteCount;   // both successful and failure, used to calculate TX throughput
1104         ULONG           LastReceivedByteCount;
1105         ULONG           ReceivedByteCount;      // both CRC okay and CRC error, used to calculate RX throughput
1106         ULONG           BeenDisassociatedCount;
1107         ULONG           BadCQIAutoRecoveryCount;
1108         ULONG           PoorCQIRoamingCount;
1109         ULONG           MgmtRingFullCount;
1110         ULONG           RxCountSinceLastNULL;
1111         ULONG           RxCount;
1112         ULONG           RxRingErrCount;
1113         ULONG           KickTxCount;
1114         ULONG           TxRingErrCount;
1115         LARGE_INTEGER   RealFcsErrCount;
1116         ULONG           PendingNdisPacketCount;
1117
1118         ULONG           OneSecOsTxCount[NUM_OF_TX_RING];
1119         ULONG           OneSecDmaDoneCount[NUM_OF_TX_RING];
1120         UINT32          OneSecTxDoneCount;
1121         ULONG           OneSecRxCount;
1122         UINT32          OneSecTxAggregationCount;
1123         UINT32          OneSecRxAggregationCount;
1124
1125         UINT32                  OneSecFrameDuplicateCount;
1126
1127
1128         UINT32          OneSecTxNoRetryOkCount;
1129         UINT32          OneSecTxRetryOkCount;
1130         UINT32          OneSecTxFailCount;
1131         UINT32          OneSecFalseCCACnt;      // CCA error count, for debug purpose, might move to global counter
1132         UINT32          OneSecRxOkCnt;          // RX without error
1133         UINT32          OneSecRxOkDataCnt;      // unicast-to-me DATA frame count
1134         UINT32          OneSecRxFcsErrCnt;      // CRC error
1135         UINT32          OneSecBeaconSentCnt;
1136         UINT32          LastOneSecTotalTxCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
1137         UINT32          LastOneSecRxOkDataCnt;  // OneSecRxOkDataCnt
1138         ULONG           DuplicateRcv;
1139         ULONG           TxAggCount;
1140         ULONG           TxNonAggCount;
1141         ULONG           TxAgg1MPDUCount;
1142         ULONG           TxAgg2MPDUCount;
1143         ULONG           TxAgg3MPDUCount;
1144         ULONG           TxAgg4MPDUCount;
1145         ULONG           TxAgg5MPDUCount;
1146         ULONG           TxAgg6MPDUCount;
1147         ULONG           TxAgg7MPDUCount;
1148         ULONG           TxAgg8MPDUCount;
1149         ULONG           TxAgg9MPDUCount;
1150         ULONG           TxAgg10MPDUCount;
1151         ULONG           TxAgg11MPDUCount;
1152         ULONG           TxAgg12MPDUCount;
1153         ULONG           TxAgg13MPDUCount;
1154         ULONG           TxAgg14MPDUCount;
1155         ULONG           TxAgg15MPDUCount;
1156         ULONG           TxAgg16MPDUCount;
1157
1158         LARGE_INTEGER       TransmittedOctetsInAMSDU;
1159         LARGE_INTEGER       TransmittedAMSDUCount;
1160         LARGE_INTEGER       ReceivedOctesInAMSDUCount;
1161         LARGE_INTEGER       ReceivedAMSDUCount;
1162         LARGE_INTEGER       TransmittedAMPDUCount;
1163         LARGE_INTEGER       TransmittedMPDUsInAMPDUCount;
1164         LARGE_INTEGER       TransmittedOctetsInAMPDUCount;
1165         LARGE_INTEGER       MPDUInReceivedAMPDUCount;
1166 } COUNTER_RALINK, *PCOUNTER_RALINK;
1167
1168 typedef struct _PID_COUNTER {
1169         ULONG           TxAckRequiredCount;      // CRC error
1170         ULONG           TxAggreCount;
1171         ULONG           TxSuccessCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
1172         ULONG           LastSuccessRate;
1173 } PID_COUNTER, *PPID_COUNTER;
1174
1175 typedef struct _COUNTER_DRS {
1176         // to record the each TX rate's quality. 0 is best, the bigger the worse.
1177         USHORT          TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
1178         UCHAR           PER[MAX_STEP_OF_TX_RATE_SWITCH];
1179         UCHAR           TxRateUpPenalty;      // extra # of second penalty due to last unstable condition
1180         ULONG           CurrTxRateStableTime; // # of second in current TX rate
1181         BOOLEAN         fNoisyEnvironment;
1182         BOOLEAN         fLastSecAccordingRSSI;
1183         UCHAR           LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
1184         UCHAR                   LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
1185         ULONG                   LastTxOkCount;
1186 } COUNTER_DRS, *PCOUNTER_DRS;
1187
1188 //
1189 //  Arcfour Structure Added by PaulWu
1190 //
1191 typedef struct  _ARCFOUR
1192 {
1193         UINT            X;
1194         UINT            Y;
1195         UCHAR           STATE[256];
1196 } ARCFOURCONTEXT, *PARCFOURCONTEXT;
1197
1198 // MIMO Tx parameter, ShortGI, MCS, STBC, etc.  these are fields in TXWI too. just copy to TXWI.
1199 typedef struct  _RECEIVE_SETTING {
1200 #ifdef RT_BIG_ENDIAN
1201         USHORT          MIMO:1;
1202         USHORT          OFDM:1;
1203         USHORT          rsv:3;
1204         USHORT          STBC:2; //SPACE
1205         USHORT          ShortGI:1;
1206         USHORT          Mode:2; //channel bandwidth 20MHz or 40 MHz
1207         USHORT          NumOfRX:2;                 // MIMO. WE HAVE 3R
1208 #else
1209         USHORT          NumOfRX:2;                 // MIMO. WE HAVE 3R
1210         USHORT          Mode:2; //channel bandwidth 20MHz or 40 MHz
1211         USHORT          ShortGI:1;
1212         USHORT          STBC:2; //SPACE
1213         USHORT          rsv:3;
1214         USHORT          OFDM:1;
1215         USHORT          MIMO:1;
1216 #endif
1217  } RECEIVE_SETTING, *PRECEIVE_SETTING;
1218
1219 // Shared key data structure
1220 typedef struct  _WEP_KEY {
1221         UCHAR   KeyLen;                     // Key length for each key, 0: entry is invalid
1222         UCHAR   Key[MAX_LEN_OF_KEY];        // right now we implement 4 keys, 128 bits max
1223 } WEP_KEY, *PWEP_KEY;
1224
1225 typedef struct _CIPHER_KEY {
1226         UCHAR   Key[16];            // right now we implement 4 keys, 128 bits max
1227         UCHAR   RxMic[8];                       // make alignment
1228         UCHAR   TxMic[8];
1229         UCHAR   TxTsc[6];           // 48bit TSC value
1230         UCHAR   RxTsc[6];           // 48bit TSC value
1231         UCHAR   CipherAlg;          // 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128
1232         UCHAR   KeyLen;
1233 #ifdef CONFIG_STA_SUPPORT
1234         UCHAR   BssId[6];
1235 #endif // CONFIG_STA_SUPPORT //
1236             // Key length for each key, 0: entry is invalid
1237         UCHAR   Type;               // Indicate Pairwise/Group when reporting MIC error
1238 } CIPHER_KEY, *PCIPHER_KEY;
1239
1240 typedef struct _BBP_TUNING_STRUCT {
1241         BOOLEAN     Enable;
1242         UCHAR       FalseCcaCountUpperBound;  // 100 per sec
1243         UCHAR       FalseCcaCountLowerBound;  // 10 per sec
1244         UCHAR       R17LowerBound;            // specified in E2PROM
1245         UCHAR       R17UpperBound;            // 0x68 according to David Tung
1246         UCHAR       CurrentR17Value;
1247 } BBP_TUNING, *PBBP_TUNING;
1248
1249 typedef struct _SOFT_RX_ANT_DIVERSITY_STRUCT {
1250         UCHAR     EvaluatePeriod;                // 0:not evalute status, 1: evaluate status, 2: switching status
1251         UCHAR     Pair1PrimaryRxAnt;     // 0:Ant-E1, 1:Ant-E2
1252         UCHAR     Pair1SecondaryRxAnt;   // 0:Ant-E1, 1:Ant-E2
1253         UCHAR     Pair2PrimaryRxAnt;     // 0:Ant-E3, 1:Ant-E4
1254         UCHAR     Pair2SecondaryRxAnt;   // 0:Ant-E3, 1:Ant-E4
1255         SHORT     Pair1AvgRssi[2];       // AvgRssi[0]:E1, AvgRssi[1]:E2
1256         SHORT     Pair2AvgRssi[2];       // AvgRssi[0]:E3, AvgRssi[1]:E4
1257         SHORT     Pair1LastAvgRssi;      //
1258         SHORT     Pair2LastAvgRssi;      //
1259         ULONG     RcvPktNumWhenEvaluate;
1260         BOOLEAN   FirstPktArrivedWhenEvaluate;
1261         RALINK_TIMER_STRUCT    RxAntDiversityTimer;
1262 } SOFT_RX_ANT_DIVERSITY, *PSOFT_RX_ANT_DIVERSITY;
1263
1264 typedef struct _LEAP_AUTH_INFO {
1265         BOOLEAN         Enabled;        //Ture: Enable LEAP Authentication
1266         BOOLEAN         CCKM;           //Ture: Use Fast Reauthentication with CCKM
1267         UCHAR           Reserve[2];
1268         UCHAR           UserName[256];  //LEAP, User name
1269         ULONG           UserNameLen;
1270         UCHAR           Password[256];  //LEAP, User Password
1271         ULONG           PasswordLen;
1272 } LEAP_AUTH_INFO, *PLEAP_AUTH_INFO;
1273
1274 typedef struct {
1275         UCHAR        Addr[MAC_ADDR_LEN];
1276         UCHAR        ErrorCode[2];  //00 01-Invalid authentication type
1277                                                                 //00 02-Authentication timeout
1278                                                                 //00 03-Challenge from AP failed
1279                                                                 //00 04-Challenge to AP failed
1280         BOOLEAN      Reported;
1281 } ROGUEAP_ENTRY, *PROGUEAP_ENTRY;
1282
1283 typedef struct {
1284         UCHAR               RogueApNr;
1285         ROGUEAP_ENTRY       RogueApEntry[MAX_LEN_OF_BSS_TABLE];
1286 } ROGUEAP_TABLE, *PROGUEAP_TABLE;
1287
1288 typedef struct {
1289         BOOLEAN     Enable;
1290         UCHAR       Delta;
1291         BOOLEAN     PlusSign;
1292 } CCK_TX_POWER_CALIBRATE, *PCCK_TX_POWER_CALIBRATE;
1293
1294 //
1295 // Receive Tuple Cache Format
1296 //
1297 typedef struct  _TUPLE_CACHE    {
1298         BOOLEAN         Valid;
1299         UCHAR           MacAddress[MAC_ADDR_LEN];
1300         USHORT          Sequence;
1301         USHORT          Frag;
1302 } TUPLE_CACHE, *PTUPLE_CACHE;
1303
1304 //
1305 // Fragment Frame structure
1306 //
1307 typedef struct  _FRAGMENT_FRAME {
1308         PNDIS_PACKET    pFragPacket;
1309         ULONG       RxSize;
1310         USHORT      Sequence;
1311         USHORT      LastFrag;
1312         ULONG       Flags;          // Some extra frame information. bit 0: LLC presented
1313 } FRAGMENT_FRAME, *PFRAGMENT_FRAME;
1314
1315
1316 //
1317 // Packet information for NdisQueryPacket
1318 //
1319 typedef struct  _PACKET_INFO    {
1320         UINT            PhysicalBufferCount;    // Physical breaks of buffer descripor chained
1321         UINT            BufferCount ;           // Number of Buffer descriptor chained
1322         UINT            TotalPacketLength ;     // Self explained
1323         PNDIS_BUFFER    pFirstBuffer;           // Pointer to first buffer descriptor
1324 } PACKET_INFO, *PPACKET_INFO;
1325
1326 //
1327 // Tkip Key structure which RC4 key & MIC calculation
1328 //
1329 typedef struct  _TKIP_KEY_INFO  {
1330         UINT        nBytesInM;  // # bytes in M for MICKEY
1331         ULONG       IV16;
1332         ULONG       IV32;
1333         ULONG       K0;         // for MICKEY Low
1334         ULONG       K1;         // for MICKEY Hig
1335         ULONG       L;          // Current state for MICKEY
1336         ULONG       R;          // Current state for MICKEY
1337         ULONG       M;          // Message accumulator for MICKEY
1338         UCHAR       RC4KEY[16];
1339         UCHAR       MIC[8];
1340 } TKIP_KEY_INFO, *PTKIP_KEY_INFO;
1341
1342 //
1343 // Private / Misc data, counters for driver internal use
1344 //
1345 typedef struct  __PRIVATE_STRUC {
1346         UINT       SystemResetCnt;         // System reset counter
1347         UINT       TxRingFullCnt;          // Tx ring full occurrance number
1348         UINT       PhyRxErrCnt;            // PHY Rx error count, for debug purpose, might move to global counter
1349         // Variables for WEP encryption / decryption in rtmp_wep.c
1350         UINT       FCSCRC32;
1351         ARCFOURCONTEXT  WEPCONTEXT;
1352         // Tkip stuff
1353         TKIP_KEY_INFO   Tx;
1354         TKIP_KEY_INFO   Rx;
1355 } PRIVATE_STRUC, *PPRIVATE_STRUC;
1356
1357 // structure to tune BBP R66 (BBP TUNING)
1358 typedef struct _BBP_R66_TUNING {
1359         BOOLEAN     bEnable;
1360         USHORT      FalseCcaLowerThreshold;  // default 100
1361         USHORT      FalseCcaUpperThreshold;  // default 512
1362         UCHAR       R66Delta;
1363         UCHAR       R66CurrentValue;
1364         BOOLEAN         R66LowerUpperSelect; //Before LinkUp, Used LowerBound or UpperBound as R66 value.
1365 } BBP_R66_TUNING, *PBBP_R66_TUNING;
1366
1367 // structure to store channel TX power
1368 typedef struct _CHANNEL_TX_POWER {
1369         USHORT     RemainingTimeForUse;         //unit: sec
1370         UCHAR      Channel;
1371 #ifdef DOT11N_DRAFT3
1372         BOOLEAN       bEffectedChannel; // For BW 40 operating in 2.4GHz , the "effected channel" is the channel that is covered in 40Mhz.
1373 #endif // DOT11N_DRAFT3 //
1374         CHAR       Power;
1375         CHAR       Power2;
1376         UCHAR      MaxTxPwr;
1377         UCHAR      DfsReq;
1378 } CHANNEL_TX_POWER, *PCHANNEL_TX_POWER;
1379
1380 // structure to store 802.11j channel TX power
1381 typedef struct _CHANNEL_11J_TX_POWER {
1382         UCHAR      Channel;
1383         UCHAR      BW;  // BW_10 or BW_20
1384         CHAR       Power;
1385         CHAR       Power2;
1386         USHORT     RemainingTimeForUse;         //unit: sec
1387 } CHANNEL_11J_TX_POWER, *PCHANNEL_11J_TX_POWER;
1388
1389 typedef enum _ABGBAND_STATE_ {
1390         UNKNOWN_BAND,
1391         BG_BAND,
1392         A_BAND,
1393 } ABGBAND_STATE;
1394
1395 typedef struct _MLME_STRUCT {
1396 #ifdef CONFIG_STA_SUPPORT
1397         // STA state machines
1398         STATE_MACHINE           CntlMachine;
1399         STATE_MACHINE           AssocMachine;
1400         STATE_MACHINE           AuthMachine;
1401         STATE_MACHINE           AuthRspMachine;
1402         STATE_MACHINE           SyncMachine;
1403         STATE_MACHINE           WpaPskMachine;
1404         STATE_MACHINE           LeapMachine;
1405         STATE_MACHINE           AironetMachine;
1406         STATE_MACHINE_FUNC      AssocFunc[ASSOC_FUNC_SIZE];
1407         STATE_MACHINE_FUNC      AuthFunc[AUTH_FUNC_SIZE];
1408         STATE_MACHINE_FUNC      AuthRspFunc[AUTH_RSP_FUNC_SIZE];
1409         STATE_MACHINE_FUNC      SyncFunc[SYNC_FUNC_SIZE];
1410         STATE_MACHINE_FUNC      WpaPskFunc[WPA_PSK_FUNC_SIZE];
1411         STATE_MACHINE_FUNC      AironetFunc[AIRONET_FUNC_SIZE];
1412 #endif // CONFIG_STA_SUPPORT //
1413         STATE_MACHINE_FUNC      ActFunc[ACT_FUNC_SIZE];
1414         // Action
1415         STATE_MACHINE           ActMachine;
1416
1417
1418 #ifdef QOS_DLS_SUPPORT
1419         STATE_MACHINE                   DlsMachine;
1420         STATE_MACHINE_FUNC      DlsFunc[DLS_FUNC_SIZE];
1421 #endif // QOS_DLS_SUPPORT //
1422
1423
1424
1425
1426         ULONG                   ChannelQuality;  // 0..100, Channel Quality Indication for Roaming
1427         ULONG                   Now32;           // latch the value of NdisGetSystemUpTime()
1428         ULONG                   LastSendNULLpsmTime;
1429
1430         BOOLEAN                 bRunning;
1431         NDIS_SPIN_LOCK          TaskLock;
1432         MLME_QUEUE              Queue;
1433
1434         UINT                    ShiftReg;
1435
1436         RALINK_TIMER_STRUCT     PeriodicTimer;
1437         RALINK_TIMER_STRUCT     APSDPeriodicTimer;
1438         RALINK_TIMER_STRUCT     LinkDownTimer;
1439         RALINK_TIMER_STRUCT     LinkUpTimer;
1440     UCHAR                   bPsPollTimerRunning;
1441     RALINK_TIMER_STRUCT     PsPollTimer;
1442         RALINK_TIMER_STRUCT     RadioOnOffTimer;
1443         ULONG                   PeriodicRound;
1444         ULONG                   OneSecPeriodicRound;
1445
1446         UCHAR                                   RealRxPath;
1447         BOOLEAN                                 bLowThroughput;
1448         BOOLEAN                                 bEnableAutoAntennaCheck;
1449         RALINK_TIMER_STRUCT             RxAntEvalTimer;
1450
1451
1452 } MLME_STRUCT, *PMLME_STRUCT;
1453
1454 // structure for radar detection and channel switch
1455 typedef struct _RADAR_DETECT_STRUCT {
1456         UCHAR           CSCount;                        //Channel switch counter
1457         UCHAR           CSPeriod;                       //Channel switch period (beacon count)
1458         UCHAR           RDCount;                        //Radar detection counter
1459         UCHAR           RDMode;                         //Radar Detection mode
1460         UCHAR           RDDurRegion;            //Radar detection duration region
1461         UCHAR           BBPR16;
1462         UCHAR           BBPR17;
1463         UCHAR           BBPR18;
1464         UCHAR           BBPR21;
1465         UCHAR           BBPR22;
1466         UCHAR           BBPR64;
1467         ULONG           InServiceMonitorCount; // unit: sec
1468         UINT8           DfsSessionTime;
1469         BOOLEAN         bFastDfs;
1470         UINT8           ChMovingTime;
1471         UINT8           LongPulseRadarTh;
1472 } RADAR_DETECT_STRUCT, *PRADAR_DETECT_STRUCT;
1473
1474 #ifdef CARRIER_DETECTION_SUPPORT
1475 typedef enum CD_STATE_n
1476 {
1477         CD_NORMAL,
1478         CD_SILENCE,
1479         CD_MAX_STATE
1480 } CD_STATE;
1481
1482 typedef struct CARRIER_DETECTION_s
1483 {
1484         BOOLEAN                                 Enable;
1485         UINT8                                   CDSessionTime;
1486         UINT8                                   CDPeriod;
1487         CD_STATE                                CD_State;
1488 } CARRIER_DETECTION, *PCARRIER_DETECTION;
1489 #endif // CARRIER_DETECTION_SUPPORT //
1490
1491 typedef enum _REC_BLOCKACK_STATUS
1492 {
1493     Recipient_NONE=0,
1494         Recipient_USED,
1495         Recipient_HandleRes,
1496     Recipient_Accept
1497 } REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
1498
1499 typedef enum _ORI_BLOCKACK_STATUS
1500 {
1501     Originator_NONE=0,
1502         Originator_USED,
1503     Originator_WaitRes,
1504     Originator_Done
1505 } ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
1506
1507 #ifdef DOT11_N_SUPPORT
1508 typedef struct _BA_ORI_ENTRY{
1509         UCHAR   Wcid;
1510         UCHAR   TID;
1511         UCHAR   BAWinSize;
1512         UCHAR   Token;
1513 // Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header.
1514         USHORT  Sequence;
1515         USHORT  TimeOutValue;
1516         ORI_BLOCKACK_STATUS  ORI_BA_Status;
1517         RALINK_TIMER_STRUCT ORIBATimer;
1518         PVOID   pAdapter;
1519 } BA_ORI_ENTRY, *PBA_ORI_ENTRY;
1520
1521 typedef struct _BA_REC_ENTRY {
1522         UCHAR   Wcid;
1523         UCHAR   TID;
1524         UCHAR   BAWinSize;      // 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU.
1525         USHORT          LastIndSeq;
1526         USHORT          TimeOutValue;
1527         RALINK_TIMER_STRUCT RECBATimer;
1528         ULONG           LastIndSeqAtTimer;
1529         ULONG           nDropPacket;
1530         ULONG           rcvSeq;
1531         REC_BLOCKACK_STATUS  REC_BA_Status;
1532         NDIS_SPIN_LOCK          RxReRingLock;                 // Rx Ring spinlock
1533         PVOID   pAdapter;
1534         struct reordering_list  list;
1535 } BA_REC_ENTRY, *PBA_REC_ENTRY;
1536
1537
1538 typedef struct {
1539         ULONG           numAsRecipient;         // I am recipient of numAsRecipient clients. These client are in the BARecEntry[]
1540         ULONG           numAsOriginator;        // I am originator of   numAsOriginator clients. These clients are in the BAOriEntry[]
1541         BA_ORI_ENTRY       BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
1542         BA_REC_ENTRY       BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
1543 } BA_TABLE, *PBA_TABLE;
1544
1545 //For QureyBATableOID use;
1546 typedef struct  PACKED _OID_BA_REC_ENTRY{
1547         UCHAR   MACAddr[MAC_ADDR_LEN];
1548         UCHAR   BaBitmap;   // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize
1549         UCHAR   rsv;
1550         UCHAR   BufSize[8];
1551         REC_BLOCKACK_STATUS     REC_BA_Status[8];
1552 } OID_BA_REC_ENTRY, *POID_BA_REC_ENTRY;
1553
1554 //For QureyBATableOID use;
1555 typedef struct  PACKED _OID_BA_ORI_ENTRY{
1556         UCHAR   MACAddr[MAC_ADDR_LEN];
1557         UCHAR   BaBitmap;  // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status
1558         UCHAR   rsv;
1559         UCHAR   BufSize[8];
1560         ORI_BLOCKACK_STATUS  ORI_BA_Status[8];
1561 } OID_BA_ORI_ENTRY, *POID_BA_ORI_ENTRY;
1562
1563 typedef struct _QUERYBA_TABLE{
1564         OID_BA_ORI_ENTRY       BAOriEntry[32];
1565         OID_BA_REC_ENTRY       BARecEntry[32];
1566         UCHAR   OriNum;// Number of below BAOriEntry
1567         UCHAR   RecNum;// Number of below BARecEntry
1568 } QUERYBA_TABLE, *PQUERYBA_TABLE;
1569
1570 typedef union   _BACAP_STRUC    {
1571 #ifdef RT_BIG_ENDIAN
1572         struct  {
1573                 UINT32     :4;
1574                 UINT32     b2040CoexistScanSup:1;               //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
1575                 UINT32     bHtAdhoc:1;                  // adhoc can use ht rate.
1576                 UINT32     MMPSmode:2;  // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
1577                 UINT32     AmsduSize:1; // 0:3839, 1:7935 bytes. UINT  MSDUSizeToBytes[]        = { 3839, 7935};
1578                 UINT32     AmsduEnable:1;       //Enable AMSDU transmisstion
1579                 UINT32          MpduDensity:3;
1580                 UINT32          Policy:2;       // 0: DELAY_BA 1:IMMED_BA  (//BA Policy subfiled value in ADDBA frame)   2:BA-not use
1581                 UINT32          AutoBA:1;       // automatically BA
1582                 UINT32          TxBAWinLimit:8;
1583                 UINT32          RxBAWinLimit:8;
1584         }       field;
1585 #else
1586         struct  {
1587                 UINT32          RxBAWinLimit:8;
1588                 UINT32          TxBAWinLimit:8;
1589                 UINT32          AutoBA:1;       // automatically BA
1590                 UINT32          Policy:2;       // 0: DELAY_BA 1:IMMED_BA  (//BA Policy subfiled value in ADDBA frame)   2:BA-not use
1591                 UINT32          MpduDensity:3;
1592                 UINT32          AmsduEnable:1;  //Enable AMSDU transmisstion
1593                 UINT32          AmsduSize:1;    // 0:3839, 1:7935 bytes. UINT  MSDUSizeToBytes[]        = { 3839, 7935};
1594                 UINT32          MMPSmode:2;     // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
1595                 UINT32          bHtAdhoc:1;                     // adhoc can use ht rate.
1596                 UINT32          b2040CoexistScanSup:1;          //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
1597                 UINT32          :4;
1598         }       field;
1599 #endif
1600         UINT32                  word;
1601 } BACAP_STRUC, *PBACAP_STRUC;
1602 #endif // DOT11_N_SUPPORT //
1603
1604 //This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second.  (Details see MLMEPeriodic)
1605 typedef struct  _IOT_STRUC      {
1606         UCHAR                   Threshold[2];
1607         UCHAR                   ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE];     // compare with threshold[0]
1608         UCHAR                   RefreshNum[MAX_LEN_OF_BA_REC_TABLE];    // compare with threshold[1]
1609         ULONG                   OneSecInWindowCount;
1610         ULONG                   OneSecFrameDuplicateCount;
1611         ULONG                   OneSecOutWindowCount;
1612         UCHAR                   DelOriAct;
1613         UCHAR                   DelRecAct;
1614         UCHAR                   RTSShortProt;
1615         UCHAR                   RTSLongProt;
1616         BOOLEAN                 bRTSLongProtOn;
1617 #ifdef CONFIG_STA_SUPPORT
1618         BOOLEAN                 bLastAtheros;
1619     BOOLEAN                     bCurrentAtheros;
1620     BOOLEAN         bNowAtherosBurstOn;
1621         BOOLEAN                 bNextDisableRxBA;
1622     BOOLEAN                     bToggle;
1623 #endif // CONFIG_STA_SUPPORT //
1624 } IOT_STRUC, *PIOT_STRUC;
1625
1626 // This is the registry setting for 802.11n transmit setting.  Used in advanced page.
1627 typedef union _REG_TRANSMIT_SETTING {
1628 #ifdef RT_BIG_ENDIAN
1629  struct {
1630          UINT32  rsv:13;
1631                  UINT32  EXTCHA:2;
1632                  UINT32  HTMODE:1;
1633                  UINT32  TRANSNO:2;
1634                  UINT32  STBC:1; //SPACE
1635                  UINT32  ShortGI:1;
1636                  UINT32  BW:1; //channel bandwidth 20MHz or 40 MHz
1637                  UINT32  TxBF:1; // 3*3
1638                  UINT32  rsv0:10;
1639     } field;
1640 #else
1641  struct {
1642                  UINT32  rsv0:10;
1643                  UINT32  TxBF:1;
1644          UINT32  BW:1; //channel bandwidth 20MHz or 40 MHz
1645          UINT32  ShortGI:1;
1646          UINT32  STBC:1; //SPACE
1647          UINT32  TRANSNO:2;
1648          UINT32  HTMODE:1;
1649          UINT32  EXTCHA:2;
1650          UINT32  rsv:13;
1651     } field;
1652 #endif
1653  UINT32   word;
1654 } REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
1655
1656 typedef union  _DESIRED_TRANSMIT_SETTING {
1657 #ifdef RT_BIG_ENDIAN
1658         struct  {
1659                         USHORT          rsv:3;
1660                         USHORT          FixedTxMode:2;                  // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
1661                         USHORT          PhyMode:4;
1662                         USHORT          MCS:7;                 // MCS
1663         }       field;
1664 #else
1665         struct  {
1666                         USHORT          MCS:7;                  // MCS
1667                         USHORT          PhyMode:4;
1668                         USHORT          FixedTxMode:2;                  // If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode.
1669                         USHORT          rsv:3;
1670         }       field;
1671 #endif
1672         USHORT          word;
1673  } DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
1674
1675 typedef struct {
1676         BOOLEAN         IsRecipient;
1677         UCHAR   MACAddr[MAC_ADDR_LEN];
1678         UCHAR   TID;
1679         UCHAR   nMSDU;
1680         USHORT   TimeOut;
1681         BOOLEAN bAllTid;  // If True, delete all TID for BA sessions with this MACaddr.
1682 } OID_ADD_BA_ENTRY, *POID_ADD_BA_ENTRY;
1683
1684 //
1685 // Multiple SSID structure
1686 //
1687 #define WLAN_MAX_NUM_OF_TIM                     ((MAX_LEN_OF_MAC_TABLE >> 3) + 1) /* /8 + 1 */
1688 #define WLAN_CT_TIM_BCMC_OFFSET         0 /* unit: 32B */
1689
1690 /* clear bcmc TIM bit */
1691 #define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
1692         pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
1693
1694 /* set bcmc TIM bit */
1695 #define WLAN_MR_TIM_BCMC_SET(apidx) \
1696         pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
1697
1698 /* clear a station PS TIM bit */
1699 #define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
1700         {       UCHAR tim_offset = wcid >> 3; \
1701                 UCHAR bit_offset = wcid & 0x7; \
1702                 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
1703
1704 /* set a station PS TIM bit */
1705 #define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
1706         {       UCHAR tim_offset = wcid >> 3; \
1707                 UCHAR bit_offset = wcid & 0x7; \
1708                 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
1709
1710
1711 typedef struct _MULTISSID_STRUCT {
1712         UCHAR                                                           Bssid[MAC_ADDR_LEN];
1713     UCHAR                               SsidLen;
1714     CHAR                                Ssid[MAX_LEN_OF_SSID];
1715     USHORT                              CapabilityInfo;
1716
1717     PNET_DEV                                    MSSIDDev;
1718
1719         NDIS_802_11_AUTHENTICATION_MODE     AuthMode;
1720         NDIS_802_11_WEP_STATUS              WepStatus;
1721         NDIS_802_11_WEP_STATUS                          GroupKeyWepStatus;
1722         WPA_MIX_PAIR_CIPHER                                     WpaMixPairCipher;
1723
1724         ULONG                                                           TxCount;
1725         ULONG                                                           RxCount;
1726         ULONG                                                           ReceivedByteCount;
1727         ULONG                                                           TransmittedByteCount;
1728         ULONG                                                           RxErrorCount;
1729         ULONG                                                           RxDropCount;
1730
1731         HTTRANSMIT_SETTING                                      HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
1732         RT_HT_PHY_INFO                                          DesiredHtPhyInfo;
1733         DESIRED_TRANSMIT_SETTING                DesiredTransmitSetting; // Desired transmit setting. this is for reading registry setting only. not useful.
1734         BOOLEAN                                                         bAutoTxRateSwitch;
1735
1736         UCHAR                               DefaultKeyId;
1737
1738         UCHAR                                                           TxRate;       // RATE_1, RATE_2, RATE_5_5, RATE_11, ...
1739         UCHAR                                                           DesiredRates[MAX_LEN_OF_SUPPORTED_RATES];// OID_802_11_DESIRED_RATES
1740         UCHAR                                                           DesiredRatesIndex;
1741         UCHAR                                                           MaxTxRate;            // RATE_1, RATE_2, RATE_5_5, RATE_11
1742
1743         UCHAR                                                           TimBitmaps[WLAN_MAX_NUM_OF_TIM];
1744
1745     // WPA
1746     UCHAR                               GMK[32];
1747     UCHAR                               PMK[32];
1748         UCHAR                                                           GTK[32];
1749     BOOLEAN                             IEEE8021X;
1750     BOOLEAN                             PreAuth;
1751     UCHAR                               GNonce[32];
1752     UCHAR                               PortSecured;
1753     NDIS_802_11_PRIVACY_FILTER          PrivacyFilter;
1754     UCHAR                               BANClass3Data;
1755     ULONG                               IsolateInterStaTraffic;
1756
1757     UCHAR                               RSNIE_Len[2];
1758     UCHAR                               RSN_IE[2][MAX_LEN_OF_RSNIE];
1759
1760
1761     UCHAR                                       TimIELocationInBeacon;
1762     UCHAR                                       CapabilityInfoLocationInBeacon;
1763     // outgoing BEACON frame buffer and corresponding TXWI
1764         // PTXWI_STRUC                           BeaconTxWI; //
1765     CHAR                                BeaconBuf[MAX_BEACON_SIZE]; // NOTE: BeaconBuf should be 4-byte aligned
1766
1767     BOOLEAN                             bHideSsid;
1768         UINT16                                                          StationKeepAliveTime; // unit: second
1769
1770     USHORT                              VLAN_VID;
1771     USHORT                              VLAN_Priority;
1772
1773     RT_802_11_ACL                                               AccessControlList;
1774
1775         // EDCA Qos
1776     BOOLEAN                                                             bWmmCapable;    // 0:disable WMM, 1:enable WMM
1777     BOOLEAN                                                             bDLSCapable;    // 0:disable DLS, 1:enable DLS
1778
1779         UCHAR                                                   DlsPTK[64];             // Due to windows dirver count on meetinghouse to handle 4-way shake
1780
1781         // For 802.1x daemon setting per BSS
1782         UCHAR                                                           radius_srv_num;
1783         RADIUS_SRV_INFO                                         radius_srv_info[MAX_RADIUS_SRV_NUM];
1784
1785 #ifdef RTL865X_SOC
1786         unsigned int                                            mylinkid;
1787 #endif
1788
1789
1790         UINT32                                  RcvdConflictSsidCount;
1791         UINT32                                  RcvdSpoofedAssocRespCount;
1792         UINT32                                  RcvdSpoofedReassocRespCount;
1793         UINT32                                  RcvdSpoofedProbeRespCount;
1794         UINT32                                  RcvdSpoofedBeaconCount;
1795         UINT32                                  RcvdSpoofedDisassocCount;
1796         UINT32                                  RcvdSpoofedAuthCount;
1797         UINT32                                  RcvdSpoofedDeauthCount;
1798         UINT32                                  RcvdSpoofedUnknownMgmtCount;
1799         UINT32                                  RcvdReplayAttackCount;
1800
1801         CHAR                                    RssiOfRcvdConflictSsid;
1802         CHAR                                    RssiOfRcvdSpoofedAssocResp;
1803         CHAR                                    RssiOfRcvdSpoofedReassocResp;
1804         CHAR                                    RssiOfRcvdSpoofedProbeResp;
1805         CHAR                                    RssiOfRcvdSpoofedBeacon;
1806         CHAR                                    RssiOfRcvdSpoofedDisassoc;
1807         CHAR                                    RssiOfRcvdSpoofedAuth;
1808         CHAR                                    RssiOfRcvdSpoofedDeauth;
1809         CHAR                                    RssiOfRcvdSpoofedUnknownMgmt;
1810         CHAR                                    RssiOfRcvdReplayAttack;
1811
1812         BOOLEAN                                 bBcnSntReq;
1813         UCHAR                                   BcnBufIdx;
1814 } MULTISSID_STRUCT, *PMULTISSID_STRUCT;
1815
1816
1817
1818 #ifdef DOT11N_DRAFT3
1819 typedef enum _BSS2040COEXIST_FLAG{
1820         BSS_2040_COEXIST_DISABLE = 0,
1821         BSS_2040_COEXIST_TIMER_FIRED  = 1,
1822         BSS_2040_COEXIST_INFO_SYNC = 2,
1823         BSS_2040_COEXIST_INFO_NOTIFY = 4,
1824 }BSS2040COEXIST_FLAG;
1825 #endif // DOT11N_DRAFT3 //
1826
1827 // configuration common to OPMODE_AP as well as OPMODE_STA
1828 typedef struct _COMMON_CONFIG {
1829
1830         BOOLEAN         bCountryFlag;
1831         UCHAR           CountryCode[3];
1832         UCHAR           Geography;
1833         UCHAR       CountryRegion;      // Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel
1834         UCHAR       CountryRegionForABand;      // Enum of country region for A band
1835         UCHAR       PhyMode;            // PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED
1836         USHORT      Dsifs;              // in units of usec
1837         ULONG       PacketFilter;       // Packet filter for receiving
1838
1839         CHAR        Ssid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
1840         UCHAR       SsidLen;               // the actual ssid length in used
1841         UCHAR       LastSsidLen;               // the actual ssid length in used
1842         CHAR        LastSsid[MAX_LEN_OF_SSID]; // NOT NULL-terminated
1843         UCHAR           LastBssid[MAC_ADDR_LEN];
1844
1845         UCHAR       Bssid[MAC_ADDR_LEN];
1846         USHORT      BeaconPeriod;
1847         UCHAR       Channel;
1848         UCHAR       CentralChannel;     // Central Channel when using 40MHz is indicating. not real channel.
1849
1850         UCHAR       SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1851         UCHAR       SupRateLen;
1852         UCHAR       ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1853         UCHAR       ExtRateLen;
1854         UCHAR       DesireRate[MAX_LEN_OF_SUPPORTED_RATES];      // OID_802_11_DESIRED_RATES
1855         UCHAR       MaxDesiredRate;
1856         UCHAR       ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
1857
1858         ULONG       BasicRateBitmap;        // backup basic ratebitmap
1859
1860         BOOLEAN         bAPSDCapable;
1861         BOOLEAN         bInServicePeriod;
1862         BOOLEAN         bAPSDAC_BE;
1863         BOOLEAN         bAPSDAC_BK;
1864         BOOLEAN         bAPSDAC_VI;
1865         BOOLEAN         bAPSDAC_VO;
1866         BOOLEAN         bNeedSendTriggerFrame;
1867         BOOLEAN         bAPSDForcePowerSave;    // Force power save mode, should only use in APSD-STAUT
1868         ULONG           TriggerTimerCount;
1869         UCHAR           MaxSPLength;
1870         UCHAR           BBPCurrentBW;   // BW_10,       BW_20, BW_40
1871         REG_TRANSMIT_SETTING        RegTransmitSetting; //registry transmit setting. this is for reading registry setting only. not useful.
1872         UCHAR       TxRate;                 // Same value to fill in TXD. TxRate is 6-bit
1873         UCHAR       MaxTxRate;              // RATE_1, RATE_2, RATE_5_5, RATE_11
1874         UCHAR       TxRateIndex;            // Tx rate index in RateSwitchTable
1875         UCHAR       TxRateTableSize;        // Valid Tx rate table size in RateSwitchTable
1876         UCHAR       MinTxRate;              // RATE_1, RATE_2, RATE_5_5, RATE_11
1877         UCHAR       RtsRate;                // RATE_xxx
1878         HTTRANSMIT_SETTING      MlmeTransmit;   // MGMT frame PHY rate setting when operatin at Ht rate.
1879         UCHAR       MlmeRate;               // RATE_xxx, used to send MLME frames
1880         UCHAR       BasicMlmeRate;          // Default Rate for sending MLME frames
1881
1882         USHORT      RtsThreshold;           // in unit of BYTE
1883         USHORT      FragmentThreshold;      // in unit of BYTE
1884
1885         UCHAR       TxPower;                // in unit of mW
1886         ULONG       TxPowerPercentage;      // 0~100 %
1887         ULONG       TxPowerDefault;         // keep for TxPowerPercentage
1888
1889 #ifdef DOT11_N_SUPPORT
1890         BACAP_STRUC        BACapability; //   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0
1891         BACAP_STRUC        REGBACapability; //   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0
1892 #endif // DOT11_N_SUPPORT //
1893         IOT_STRUC               IOTestParm;     // 802.11n InterOpbility Test Parameter;
1894         ULONG       TxPreamble;             // Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto
1895         BOOLEAN     bUseZeroToDisableFragment;     // Microsoft use 0 as disable
1896         ULONG       UseBGProtection;        // 0: auto, 1: always use, 2: always not use
1897         BOOLEAN     bUseShortSlotTime;      // 0: disable, 1 - use short slot (9us)
1898         BOOLEAN     bEnableTxBurst;         // 1: enble TX PACKET BURST, 0: disable TX PACKET BURST
1899         BOOLEAN     bAggregationCapable;      // 1: enable TX aggregation when the peer supports it
1900         BOOLEAN     bPiggyBackCapable;          // 1: enable TX piggy-back according MAC's version
1901         BOOLEAN     bIEEE80211H;                        // 1: enable IEEE802.11h spec.
1902         ULONG           DisableOLBCDetect;              // 0: enable OLBC detect; 1 disable OLBC detect
1903
1904 #ifdef DOT11_N_SUPPORT
1905         BOOLEAN                         bRdg;
1906 #endif // DOT11_N_SUPPORT //
1907         BOOLEAN             bWmmCapable;        // 0:disable WMM, 1:enable WMM
1908         QOS_CAPABILITY_PARM APQosCapability;    // QOS capability of the current associated AP
1909         EDCA_PARM           APEdcaParm;         // EDCA parameters of the current associated AP
1910         QBSS_LOAD_PARM      APQbssLoad;         // QBSS load of the current associated AP
1911         UCHAR               AckPolicy[4];       // ACK policy of the specified AC. see ACK_xxx
1912 #ifdef CONFIG_STA_SUPPORT
1913         BOOLEAN                         bDLSCapable;            // 0:disable DLS, 1:enable DLS
1914 #endif // CONFIG_STA_SUPPORT //
1915         // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
1916         // BOOLEAN control, either ON or OFF. These flags should always be accessed via
1917         // OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros.
1918         // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition
1919         ULONG               OpStatusFlags;
1920
1921         BOOLEAN                         NdisRadioStateOff; //For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff.
1922         ABGBAND_STATE           BandState;              // For setting BBP used on B/G or A mode.
1923
1924         // IEEE802.11H--DFS.
1925         RADAR_DETECT_STRUCT     RadarDetect;
1926
1927 #ifdef CARRIER_DETECTION_SUPPORT
1928         CARRIER_DETECTION               CarrierDetect;
1929 #endif // CARRIER_DETECTION_SUPPORT //
1930
1931 #ifdef DOT11_N_SUPPORT
1932         // HT
1933         UCHAR                   BASize;         // USer desired BAWindowSize. Should not exceed our max capability
1934         //RT_HT_CAPABILITY      SupportedHtPhy;
1935         RT_HT_CAPABILITY        DesiredHtPhy;
1936         HT_CAPABILITY_IE                HtCapability;
1937         ADD_HT_INFO_IE          AddHTInfo;      // Useful as AP.
1938         //This IE is used with channel switch announcement element when changing to a new 40MHz.
1939         //This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp.
1940         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
1941
1942 #ifdef DOT11N_DRAFT3
1943         UCHAR                                   Bss2040CoexistFlag;             // bit 0: bBssCoexistTimerRunning, bit 1: NeedSyncAddHtInfo.
1944         RALINK_TIMER_STRUCT     Bss2040CoexistTimer;
1945
1946         //This IE is used for 20/40 BSS Coexistence.
1947         BSS_2040_COEXIST_IE             BSS2040CoexistInfo;
1948         // ====== 11n D3.0 =======================>
1949         USHORT                                  Dot11OBssScanPassiveDwell;                              // Unit : TU. 5~1000
1950         USHORT                                  Dot11OBssScanActiveDwell;                               // Unit : TU. 10~1000
1951         USHORT                                  Dot11BssWidthTriggerScanInt;                    // Unit : Second
1952         USHORT                                  Dot11OBssScanPassiveTotalPerChannel;    // Unit : TU. 200~10000
1953         USHORT                                  Dot11OBssScanActiveTotalPerChannel;     // Unit : TU. 20~10000
1954         USHORT                                  Dot11BssWidthChanTranDelayFactor;
1955         USHORT                                  Dot11OBssScanActivityThre;                              // Unit : percentage
1956
1957         ULONG                                   Dot11BssWidthChanTranDelay;                     // multiple of (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
1958         ULONG                                   CountDownCtr;   // CountDown Counter from (Dot11BssWidthTriggerScanInt * Dot11BssWidthChanTranDelayFactor)
1959
1960         NDIS_SPIN_LOCK          TriggerEventTabLock;
1961         BSS_2040_COEXIST_IE             LastBSSCoexist2040;
1962         BSS_2040_COEXIST_IE             BSSCoexist2040;
1963         TRIGGER_EVENT_TAB               TriggerEventTab;
1964         UCHAR                                   ChannelListIdx;
1965         // <====== 11n D3.0 =======================
1966         BOOLEAN                                 bOverlapScanning;
1967 #endif // DOT11N_DRAFT3 //
1968
1969     BOOLEAN                 bHTProtect;
1970     BOOLEAN                 bMIMOPSEnable;
1971     BOOLEAN                                     bBADecline;
1972         BOOLEAN                                 bDisableReordering;
1973         BOOLEAN                                 bForty_Mhz_Intolerant;
1974         BOOLEAN                                 bExtChannelSwitchAnnouncement;
1975         BOOLEAN                                 bRcvBSSWidthTriggerEvents;
1976         ULONG                                   LastRcvBSSWidthTriggerEventsTime;
1977
1978         UCHAR                                   TxBASize;
1979 #endif // DOT11_N_SUPPORT //
1980
1981         // Enable wireless event
1982         BOOLEAN                         bWirelessEvent;
1983         BOOLEAN                         bWiFiTest;                              // Enable this parameter for WiFi test
1984
1985         // Tx & Rx Stream number selection
1986         UCHAR                           TxStream;
1987         UCHAR                           RxStream;
1988
1989         // transmit phy mode, trasmit rate for Multicast.
1990 #ifdef MCAST_RATE_SPECIFIC
1991         UCHAR                           McastTransmitMcs;
1992         UCHAR                           McastTransmitPhyMode;
1993 #endif // MCAST_RATE_SPECIFIC //
1994
1995         BOOLEAN                 bHardwareRadio;     // Hardware controlled Radio enabled
1996
1997
1998
1999         NDIS_SPIN_LOCK                  MeasureReqTabLock;
2000         PMEASURE_REQ_TAB                pMeasureReqTab;
2001
2002         NDIS_SPIN_LOCK                  TpcReqTabLock;
2003         PTPC_REQ_TAB                    pTpcReqTab;
2004
2005         // transmit phy mode, trasmit rate for Multicast.
2006 #ifdef MCAST_RATE_SPECIFIC
2007         HTTRANSMIT_SETTING              MCastPhyMode;
2008 #endif // MCAST_RATE_SPECIFIC //
2009
2010 #ifdef SINGLE_SKU
2011         UINT16                                  DefineMaxTxPwr;
2012 #endif // SINGLE_SKU //
2013
2014
2015 } COMMON_CONFIG, *PCOMMON_CONFIG;
2016
2017
2018 #ifdef CONFIG_STA_SUPPORT
2019 /* Modified by Wu Xi-Kun 4/21/2006 */
2020 // STA configuration and status
2021 typedef struct _STA_ADMIN_CONFIG {
2022         // GROUP 1 -
2023         //   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
2024         //   the user intended configuration, but not necessary fully equal to the final
2025         //   settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either
2026         //   AP or IBSS holder).
2027         //   Once initialized, user configuration can only be changed via OID_xxx
2028         UCHAR       BssType;              // BSS_INFRA or BSS_ADHOC
2029         USHORT      AtimWin;          // used when starting a new IBSS
2030
2031         // GROUP 2 -
2032         //   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe
2033         //   the user intended configuration, and should be always applied to the final
2034         //   settings in ACTIVE BSS without compromising with the BSS holder.
2035         //   Once initialized, user configuration can only be changed via OID_xxx
2036         UCHAR       RssiTrigger;
2037         UCHAR       RssiTriggerMode;      // RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD
2038         USHORT      DefaultListenCount;   // default listen count;
2039         ULONG       WindowsPowerMode;           // Power mode for AC power
2040         ULONG       WindowsBatteryPowerMode;    // Power mode for battery if exists
2041         BOOLEAN     bWindowsACCAMEnable;        // Enable CAM power mode when AC on
2042         BOOLEAN     bAutoReconnect;         // Set to TRUE when setting OID_802_11_SSID with no matching BSSID
2043         ULONG       WindowsPowerProfile;    // Windows power profile, for NDIS5.1 PnP
2044
2045         // MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1)
2046         USHORT      Psm;                  // power management mode   (PWR_ACTIVE|PWR_SAVE)
2047         USHORT      DisassocReason;
2048         UCHAR       DisassocSta[MAC_ADDR_LEN];
2049         USHORT      DeauthReason;
2050         UCHAR       DeauthSta[MAC_ADDR_LEN];
2051         USHORT      AuthFailReason;
2052         UCHAR       AuthFailSta[MAC_ADDR_LEN];
2053
2054         NDIS_802_11_PRIVACY_FILTER          PrivacyFilter;  // PrivacyFilter enum for 802.1X
2055         NDIS_802_11_AUTHENTICATION_MODE     AuthMode;       // This should match to whatever microsoft defined
2056         NDIS_802_11_WEP_STATUS              WepStatus;
2057         NDIS_802_11_WEP_STATUS                          OrigWepStatus;  // Original wep status set from OID
2058
2059         // Add to support different cipher suite for WPA2/WPA mode
2060         NDIS_802_11_ENCRYPTION_STATUS           GroupCipher;            // Multicast cipher suite
2061         NDIS_802_11_ENCRYPTION_STATUS           PairCipher;                     // Unicast cipher suite
2062         BOOLEAN                                                         bMixCipher;                     // Indicate current Pair & Group use different cipher suites
2063         USHORT                                                          RsnCapability;
2064
2065         NDIS_802_11_WEP_STATUS              GroupKeyWepStatus;
2066
2067         UCHAR           PMK[32];                // WPA PSK mode PMK
2068         UCHAR       PTK[64];                // WPA PSK mode PTK
2069         UCHAR           GTK[32];                                // GTK from authenticator
2070         BSSID_INFO      SavedPMK[PMKID_NO];
2071         UINT            SavedPMKNum;                    // Saved PMKID number
2072
2073         UCHAR           DefaultKeyId;
2074
2075
2076         // WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED
2077         UCHAR       PortSecured;
2078
2079         // For WPA countermeasures
2080         ULONG       LastMicErrorTime;   // record last MIC error time
2081         ULONG       MicErrCnt;          // Should be 0, 1, 2, then reset to zero (after disassoiciation).
2082         BOOLEAN     bBlockAssoc;        // Block associate attempt for 60 seconds after counter measure occurred.
2083         // For WPA-PSK supplicant state
2084         WPA_STATE   WpaState;           // Default is SS_NOTUSE and handled by microsoft 802.1x
2085         UCHAR       ReplayCounter[8];
2086         UCHAR       ANonce[32];         // ANonce for WPA-PSK from aurhenticator
2087         UCHAR       SNonce[32];         // SNonce for WPA-PSK
2088
2089         UCHAR       LastSNR0;             // last received BEACON's SNR
2090         UCHAR       LastSNR1;            // last received BEACON's SNR for 2nd  antenna
2091         RSSI_SAMPLE RssiSample;
2092         ULONG       NumOfAvgRssiSample;
2093
2094         ULONG       LastBeaconRxTime;     // OS's timestamp of the last BEACON RX time
2095         ULONG       Last11bBeaconRxTime;  // OS's timestamp of the last 11B BEACON RX time
2096         ULONG           Last11gBeaconRxTime;    // OS's timestamp of the last 11G BEACON RX time
2097         ULONG           Last20NBeaconRxTime;    // OS's timestamp of the last 20MHz N BEACON RX time
2098
2099         ULONG       LastScanTime;       // Record last scan time for issue BSSID_SCAN_LIST
2100         ULONG       ScanCnt;            // Scan counts since most recent SSID, BSSID, SCAN OID request
2101         BOOLEAN     bSwRadio;           // Software controlled Radio On/Off, TRUE: On
2102         BOOLEAN     bHwRadio;           // Hardware controlled Radio On/Off, TRUE: On
2103         BOOLEAN     bRadio;             // Radio state, And of Sw & Hw radio state
2104         BOOLEAN     bHardwareRadio;     // Hardware controlled Radio enabled
2105         BOOLEAN     bShowHiddenSSID;    // Show all known SSID in SSID list get operation
2106
2107     BOOLEAN             AdhocBOnlyJoined;       // Indicate Adhoc B Join.
2108     BOOLEAN             AdhocBGJoined;          // Indicate Adhoc B/G Join.
2109     BOOLEAN             Adhoc20NJoined;         // Indicate Adhoc 20MHz N Join.
2110
2111         // New for WPA, windows want us to to keep association information and
2112         // Fixed IEs from last association response
2113         NDIS_802_11_ASSOCIATION_INFORMATION     AssocInfo;
2114         USHORT       ReqVarIELen;                // Length of next VIE include EID & Length
2115         UCHAR       ReqVarIEs[MAX_VIE_LEN];             // The content saved here should be little-endian format.
2116         USHORT       ResVarIELen;                // Length of next VIE include EID & Length
2117         UCHAR       ResVarIEs[MAX_VIE_LEN];
2118
2119         UCHAR       RSNIE_Len;
2120         UCHAR       RSN_IE[MAX_LEN_OF_RSNIE];   // The content saved here should be little-endian format.
2121
2122         // New variables used for CCX 1.0
2123         BOOLEAN             bCkipOn;
2124         BOOLEAN             bCkipCmicOn;
2125         UCHAR               CkipFlag;
2126         UCHAR               GIV[3];  //for CCX iv
2127         UCHAR               RxSEQ[4];
2128         UCHAR               TxSEQ[4];
2129         UCHAR               CKIPMIC[4];
2130         UCHAR               LeapAuthMode;
2131         LEAP_AUTH_INFO      LeapAuthInfo;
2132         UCHAR               HashPwd[16];
2133         UCHAR               NetworkChallenge[8];
2134         UCHAR               NetworkChallengeResponse[24];
2135         UCHAR               PeerChallenge[8];
2136
2137         UCHAR               PeerChallengeResponse[24];
2138         UCHAR               SessionKey[16]; //Network session keys (NSK)
2139         RALINK_TIMER_STRUCT LeapAuthTimer;
2140         ROGUEAP_TABLE       RogueApTab;   //Cisco CCX1 Rogue AP Detection
2141
2142         // New control flags for CCX
2143         CCX_CONTROL         CCXControl;                 // Master administration state
2144         BOOLEAN             CCXEnable;                  // Actual CCX state
2145         UCHAR               CCXScanChannel;             // Selected channel for CCX beacon request
2146         USHORT              CCXScanTime;                // Time out to wait for beacon and probe response
2147         UCHAR               CCXReqType;                 // Current processing CCX request type
2148         BSS_TABLE           CCXBssTab;                  // BSS Table
2149         UCHAR               FrameReportBuf[2048];       // Buffer for creating frame report
2150         USHORT              FrameReportLen;             // Current Frame report length
2151         ULONG               CLBusyBytes;                // Save the total bytes received durning channel load scan time
2152         USHORT              RPIDensity[8];              // Array for RPI density collection
2153         // Start address of each BSS table within FrameReportBuf
2154         // It's important to update the RxPower of the corresponding Bss
2155         USHORT              BssReportOffset[MAX_LEN_OF_BSS_TABLE];
2156         USHORT              BeaconToken;                // Token for beacon report
2157         ULONG               LastBssIndex;               // Most current reported Bss index
2158         RM_REQUEST_ACTION   MeasurementRequest[16];     // Saved measurement request
2159         UCHAR               RMReqCnt;                   // Number of measurement request saved.
2160         UCHAR               CurrentRMReqIdx;            // Number of measurement request saved.
2161         BOOLEAN             ParallelReq;                // Parallel measurement, only one request performed,
2162                                                                                                         // It must be the same channel with maximum duration
2163         USHORT              ParallelDuration;           // Maximum duration for parallel measurement
2164         UCHAR               ParallelChannel;            // Only one channel with parallel measurement
2165         USHORT              IAPPToken;                  // IAPP dialog token
2166         UCHAR               CCXQosECWMin;               // Cisco QOS ECWMin for AC 0
2167         UCHAR               CCXQosECWMax;               // Cisco QOS ECWMax for AC 0
2168         // Hack for channel load and noise histogram parameters
2169         UCHAR               NHFactor;                   // Parameter for Noise histogram
2170         UCHAR               CLFactor;                   // Parameter for channel load
2171
2172         UCHAR               KRK[16];        //Key Refresh Key.
2173         UCHAR               BTK[32];        //Base Transient Key
2174         BOOLEAN             CCKMLinkUpFlag;
2175         ULONG               CCKMRN;    //(Re)Association request number.
2176         LARGE_INTEGER       CCKMBeaconAtJoinTimeStamp;  //TSF timer for Re-assocaite to the new AP
2177         UCHAR               AironetCellPowerLimit;      //in dBm
2178         UCHAR               AironetIPAddress[4];        //eg. 192.168.1.1
2179         BOOLEAN             CCXAdjacentAPReportFlag;    //flag for determining report Assoc Lost time
2180         CHAR                CCXAdjacentAPSsid[MAX_LEN_OF_SSID]; //Adjacent AP's SSID report
2181         UCHAR               CCXAdjacentAPSsidLen;               // the actual ssid length in used
2182         UCHAR               CCXAdjacentAPBssid[MAC_ADDR_LEN];         //Adjacent AP's BSSID report
2183         USHORT              CCXAdjacentAPChannel;
2184         ULONG               CCXAdjacentAPLinkDownTime;  //for Spec S32.
2185
2186         RALINK_TIMER_STRUCT     StaQuickResponeForRateUpTimer;
2187         BOOLEAN                         StaQuickResponeForRateUpTimerRunning;
2188
2189         UCHAR                   DtimCount;      // 0.. DtimPeriod-1
2190         UCHAR                   DtimPeriod;     // default = 3
2191
2192 #ifdef QOS_DLS_SUPPORT
2193         RT_802_11_DLS           DLSEntry[MAX_NUM_OF_DLS_ENTRY];
2194         UCHAR                           DlsReplayCounter[8];
2195 #endif // QOS_DLS_SUPPORT //
2196         ////////////////////////////////////////////////////////////////////////////////////////
2197         // This is only for WHQL test.
2198         BOOLEAN                         WhqlTest;
2199         ////////////////////////////////////////////////////////////////////////////////////////
2200
2201     RALINK_TIMER_STRUCT WpaDisassocAndBlockAssocTimer;
2202     // Fast Roaming
2203         BOOLEAN                 bFastRoaming;       // 0:disable fast roaming, 1:enable fast roaming
2204         CHAR                    dBmToRoam;          // the condition to roam when receiving Rssi less than this value. It's negative value.
2205
2206 #ifdef WPA_SUPPLICANT_SUPPORT
2207     BOOLEAN             IEEE8021X;
2208     BOOLEAN             IEEE8021x_required_keys;
2209     CIPHER_KEY          DesireSharedKey[4];     // Record user desired WEP keys
2210     UCHAR               DesireSharedKeyId;
2211
2212     // 0: driver ignores wpa_supplicant
2213     // 1: wpa_supplicant initiates scanning and AP selection
2214     // 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters
2215     UCHAR               WpaSupplicantUP;
2216         UCHAR                           WpaSupplicantScanCount;
2217 #endif // WPA_SUPPLICANT_SUPPORT //
2218
2219     CHAR                dev_name[16];
2220     USHORT              OriDevType;
2221
2222     BOOLEAN             bTGnWifiTest;
2223         BOOLEAN                     bScanReqIsFromWebUI;
2224
2225         HTTRANSMIT_SETTING                              HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
2226         DESIRED_TRANSMIT_SETTING        DesiredTransmitSetting;
2227         RT_HT_PHY_INFO                                  DesiredHtPhyInfo;
2228         BOOLEAN                                                 bAutoTxRateSwitch;
2229
2230     UCHAR       BBPR3;
2231
2232 #ifdef EXT_BUILD_CHANNEL_LIST
2233         UCHAR                           IEEE80211dClientMode;
2234         UCHAR                           StaOriCountryCode[3];
2235         UCHAR                           StaOriGeography;
2236 #endif // EXT_BUILD_CHANNEL_LIST //
2237 } STA_ADMIN_CONFIG, *PSTA_ADMIN_CONFIG;
2238
2239 // This data structure keep the current active BSS/IBSS's configuration that this STA
2240 // had agreed upon joining the network. Which means these parameters are usually decided
2241 // by the BSS/IBSS creator instead of user configuration. Data in this data structurre
2242 // is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE.
2243 // Normally, after SCAN or failed roaming attempts, we need to recover back to
2244 // the current active settings.
2245 typedef struct _STA_ACTIVE_CONFIG {
2246         USHORT      Aid;
2247         USHORT      AtimWin;                // in kusec; IBSS parameter set element
2248         USHORT      CapabilityInfo;
2249         USHORT      CfpMaxDuration;
2250         USHORT      CfpPeriod;
2251
2252         // Copy supported rate from desired AP's beacon. We are trying to match
2253         // AP's supported and extended rate settings.
2254         UCHAR       SupRate[MAX_LEN_OF_SUPPORTED_RATES];
2255         UCHAR       ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
2256         UCHAR       SupRateLen;
2257         UCHAR       ExtRateLen;
2258         // Copy supported ht from desired AP's beacon. We are trying to match
2259         RT_HT_PHY_INFO          SupportedPhyInfo;
2260         RT_HT_CAPABILITY        SupportedHtPhy;
2261 } STA_ACTIVE_CONFIG, *PSTA_ACTIVE_CONFIG;
2262 #endif // CONFIG_STA_SUPPORT //
2263
2264 // ----------- start of AP --------------------------
2265 // AUTH-RSP State Machine Aux data structure
2266 typedef struct _AP_MLME_AUX {
2267         UCHAR               Addr[MAC_ADDR_LEN];
2268         USHORT              Alg;
2269         CHAR                Challenge[CIPHER_TEXT_LEN];
2270 } AP_MLME_AUX, *PAP_MLME_AUX;
2271
2272 // structure to define WPA Group Key Rekey Interval
2273 typedef struct PACKED _RT_802_11_WPA_REKEY {
2274         ULONG ReKeyMethod;          // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
2275         ULONG ReKeyInterval;        // time-based: seconds, packet-based: kilo-packets
2276 } RT_WPA_REKEY,*PRT_WPA_REKEY, RT_802_11_WPA_REKEY, *PRT_802_11_WPA_REKEY;
2277
2278 typedef struct _MAC_TABLE_ENTRY {
2279         //Choose 1 from ValidAsWDS and ValidAsCLI  to validize.
2280         BOOLEAN         ValidAsCLI;             // Sta mode, set this TRUE after Linkup,too.
2281         BOOLEAN         ValidAsWDS;     // This is WDS Entry. only for AP mode.
2282         BOOLEAN         ValidAsApCli;   //This is a AP-Client entry, only for AP mode which enable AP-Client functions.
2283         BOOLEAN         ValidAsMesh;
2284         BOOLEAN         ValidAsDls;     // This is DLS Entry. only for STA mode.
2285         BOOLEAN         isCached;
2286         BOOLEAN         bIAmBadAtheros; // Flag if this is Atheros chip that has IOT problem.  We need to turn on RTS/CTS protection.
2287
2288         UCHAR           EnqueueEapolStartTimerRunning;  // Enqueue EAPoL-Start for triggering EAP SM
2289         //jan for wpa
2290         // record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB
2291         UCHAR           CMTimerRunning;
2292         UCHAR           apidx;                  // MBSS number
2293         UCHAR           RSNIE_Len;
2294         UCHAR           RSN_IE[MAX_LEN_OF_RSNIE];
2295         UCHAR           ANonce[LEN_KEY_DESC_NONCE];
2296         UCHAR           R_Counter[LEN_KEY_DESC_REPLAY];
2297         UCHAR           PTK[64];
2298         UCHAR           ReTryCounter;
2299         RALINK_TIMER_STRUCT                 RetryTimer;
2300         RALINK_TIMER_STRUCT                                     EnqueueStartForPSKTimer;        // A timer which enqueue EAPoL-Start for triggering PSK SM
2301         NDIS_802_11_AUTHENTICATION_MODE     AuthMode;   // This should match to whatever microsoft defined
2302         NDIS_802_11_WEP_STATUS              WepStatus;
2303         AP_WPA_STATE    WpaState;
2304         GTK_STATE       GTKState;
2305         USHORT          PortSecured;
2306         NDIS_802_11_PRIVACY_FILTER  PrivacyFilter;      // PrivacyFilter enum for 802.1X
2307         CIPHER_KEY      PairwiseKey;
2308         PVOID           pAd;
2309     INT                         PMKID_CacheIdx;
2310     UCHAR                       PMKID[LEN_PMKID];
2311
2312
2313         UCHAR           Addr[MAC_ADDR_LEN];
2314         UCHAR           PsMode;
2315         SST             Sst;
2316         AUTH_STATE      AuthState; // for SHARED KEY authentication state machine used only
2317         BOOLEAN                 IsReassocSta;   // Indicate whether this is a reassociation procedure
2318         USHORT          Aid;
2319         USHORT          CapabilityInfo;
2320         UCHAR           LastRssi;
2321         ULONG           NoDataIdleCount;
2322         UINT16                  StationKeepAliveCount; // unit: second
2323         ULONG           PsQIdleCount;
2324         QUEUE_HEADER    PsQueue;
2325
2326         UINT32                  StaConnectTime;         // the live time of this station since associated with AP
2327
2328
2329 #ifdef DOT11_N_SUPPORT
2330         BOOLEAN                 bSendBAR;
2331         USHORT                  NoBADataCountDown;
2332
2333         UINT32                  CachedBuf[16];          // UINT (4 bytes) for alignment
2334         UINT                    TxBFCount; // 3*3
2335 #endif // DOT11_N_SUPPORT //
2336         UINT                    FIFOCount;
2337         UINT                    DebugFIFOCount;
2338         UINT                    DebugTxCount;
2339     BOOLEAN                     bDlsInit;
2340
2341
2342 //====================================================
2343 //WDS entry needs these
2344 // rt2860 add this. if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab
2345         UINT                    MatchWDSTabIdx;
2346         UCHAR           MaxSupportedRate;
2347         UCHAR           CurrTxRate;
2348         UCHAR           CurrTxRateIndex;
2349         // to record the each TX rate's quality. 0 is best, the bigger the worse.
2350         USHORT          TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
2351         UINT32                  OneSecTxNoRetryOkCount;
2352         UINT32          OneSecTxRetryOkCount;
2353         UINT32          OneSecTxFailCount;
2354         UINT32                  ContinueTxFailCnt;
2355         UINT32          CurrTxRateStableTime; // # of second in current TX rate
2356         UCHAR           TxRateUpPenalty;      // extra # of second penalty due to last unstable condition
2357 //====================================================
2358
2359
2360
2361 #ifdef CONFIG_STA_SUPPORT
2362 #ifdef QOS_DLS_SUPPORT
2363         UINT                    MatchDlsEntryIdx; // indicate the index in pAd->StaCfg.DLSEntry
2364 #endif // QOS_DLS_SUPPORT //
2365 #endif // CONFIG_STA_SUPPORT //
2366
2367         BOOLEAN         fNoisyEnvironment;
2368         BOOLEAN                 fLastSecAccordingRSSI;
2369         UCHAR           LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
2370         CHAR                    LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
2371         ULONG                   LastTxOkCount;
2372         UCHAR           PER[MAX_STEP_OF_TX_RATE_SWITCH];
2373
2374         // a bitmap of BOOLEAN flags. each bit represent an operation status of a particular
2375         // BOOLEAN control, either ON or OFF. These flags should always be accessed via
2376         // CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros.
2377         // see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED
2378         ULONG           ClientStatusFlags;
2379
2380         // TODO: Shall we move that to DOT11_N_SUPPORT???
2381         HTTRANSMIT_SETTING      HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI.
2382
2383 #ifdef DOT11_N_SUPPORT
2384         // HT EWC MIMO-N used parameters
2385         USHORT          RXBAbitmap;     // fill to on-chip  RXWI_BA_BITMASK in 8.1.3RX attribute entry format
2386         USHORT          TXBAbitmap;     // This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI
2387         USHORT          TXAutoBAbitmap;
2388         USHORT          BADeclineBitmap;
2389         USHORT          BARecWcidArray[NUM_OF_TID];     // The mapping wcid of recipient session. if RXBAbitmap bit is masked
2390         USHORT          BAOriWcidArray[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
2391         USHORT          BAOriSequence[NUM_OF_TID]; // The mapping wcid of originator session. if TXBAbitmap bit is masked
2392
2393         // 802.11n features.
2394         UCHAR           MpduDensity;
2395         UCHAR           MaxRAmpduFactor;
2396         UCHAR           AMsduSize;
2397         UCHAR           MmpsMode;       // MIMO power save more.
2398
2399         HT_CAPABILITY_IE                HTCapability;
2400
2401 #ifdef DOT11N_DRAFT3
2402         UCHAR           BSS2040CoexistenceMgmtSupport;
2403 #endif // DOT11N_DRAFT3 //
2404 #endif // DOT11_N_SUPPORT //
2405
2406         BOOLEAN         bAutoTxRateSwitch;
2407
2408         UCHAR       RateLen;
2409         struct _MAC_TABLE_ENTRY *pNext;
2410     USHORT      TxSeq[NUM_OF_TID];
2411         USHORT          NonQosDataSeq;
2412
2413         RSSI_SAMPLE     RssiSample;
2414
2415         UINT32                  TXMCSExpected[16];
2416         UINT32                  TXMCSSuccessful[16];
2417         UINT32                  TXMCSFailed[16];
2418         UINT32                  TXMCSAutoFallBack[16][16];
2419 } MAC_TABLE_ENTRY, *PMAC_TABLE_ENTRY;
2420
2421 typedef struct _MAC_TABLE {
2422         USHORT                  Size;
2423         MAC_TABLE_ENTRY *Hash[HASH_TABLE_SIZE];
2424         MAC_TABLE_ENTRY Content[MAX_LEN_OF_MAC_TABLE];
2425         QUEUE_HEADER    McastPsQueue;
2426         ULONG           PsQIdleCount;
2427         BOOLEAN         fAnyStationInPsm;
2428         BOOLEAN         fAnyStationBadAtheros;  // Check if any Station is atheros 802.11n Chip.  We need to use RTS/CTS with Atheros 802,.11n chip.
2429         BOOLEAN                 fAnyTxOPForceDisable;   // Check if it is necessary to disable BE TxOP
2430 #ifdef DOT11_N_SUPPORT
2431         BOOLEAN         fAnyStationIsLegacy;    // Check if I use legacy rate to transmit to my BSS Station/
2432         BOOLEAN         fAnyStationNonGF;               // Check if any Station can't support GF.
2433         BOOLEAN         fAnyStation20Only;              // Check if any Station can't support GF.
2434         BOOLEAN                 fAnyStationMIMOPSDynamic; // Check if any Station is MIMO Dynamic
2435         BOOLEAN         fAnyBASession;   // Check if there is BA session.  Force turn on RTS/CTS
2436 #endif // DOT11_N_SUPPORT //
2437 } MAC_TABLE, *PMAC_TABLE;
2438
2439 #ifdef DOT11_N_SUPPORT
2440 #define IS_HT_STA(_pMacEntry)   \
2441         (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
2442
2443 #define IS_HT_RATE(_pMacEntry)  \
2444         (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
2445
2446 #define PEER_IS_HT_RATE(_pMacEntry)     \
2447         (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
2448 #endif // DOT11_N_SUPPORT //
2449
2450 typedef struct _WDS_ENTRY {
2451         BOOLEAN         Valid;
2452         UCHAR           Addr[MAC_ADDR_LEN];
2453         ULONG           NoDataIdleCount;
2454         struct _WDS_ENTRY *pNext;
2455 } WDS_ENTRY, *PWDS_ENTRY;
2456
2457 typedef struct  _WDS_TABLE_ENTRY {
2458         USHORT                  Size;
2459         UCHAR           WdsAddr[MAC_ADDR_LEN];
2460         WDS_ENTRY       *Hash[HASH_TABLE_SIZE];
2461         WDS_ENTRY       Content[MAX_LEN_OF_MAC_TABLE];
2462         UCHAR           MaxSupportedRate;
2463         UCHAR           CurrTxRate;
2464         USHORT          TxQuality[MAX_LEN_OF_SUPPORTED_RATES];
2465         USHORT          OneSecTxOkCount;
2466         USHORT          OneSecTxRetryOkCount;
2467         USHORT          OneSecTxFailCount;
2468         ULONG           CurrTxRateStableTime; // # of second in current TX rate
2469         UCHAR           TxRateUpPenalty;      // extra # of second penalty due to last unstable condition
2470 } WDS_TABLE_ENTRY, *PWDS_TABLE_ENTRY;
2471
2472 typedef struct _RT_802_11_WDS_ENTRY {
2473         PNET_DEV                        dev;
2474         UCHAR                           Valid;
2475         UCHAR                           PhyMode;
2476         UCHAR                           PeerWdsAddr[MAC_ADDR_LEN];
2477         UCHAR                           MacTabMatchWCID;        // ASIC
2478         NDIS_802_11_WEP_STATUS  WepStatus;
2479         UCHAR                                   KeyIdx;
2480         CIPHER_KEY              WdsKey;
2481         HTTRANSMIT_SETTING                              HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
2482         RT_HT_PHY_INFO                                  DesiredHtPhyInfo;
2483         BOOLEAN                                                 bAutoTxRateSwitch;
2484         DESIRED_TRANSMIT_SETTING        DesiredTransmitSetting; // Desired transmit setting.
2485 } RT_802_11_WDS_ENTRY, *PRT_802_11_WDS_ENTRY;
2486
2487 typedef struct _WDS_TABLE {
2488         UCHAR               Mode;
2489         ULONG               Size;
2490         RT_802_11_WDS_ENTRY     WdsEntry[MAX_WDS_ENTRY];
2491 } WDS_TABLE, *PWDS_TABLE;
2492
2493 typedef struct _APCLI_STRUCT {
2494         PNET_DEV                                dev;
2495 #ifdef RTL865X_SOC
2496         unsigned int            mylinkid;
2497 #endif
2498         BOOLEAN                 Enable; // Set it as 1 if the apcli interface was configured to "1"  or by iwpriv cmd "ApCliEnable"
2499         BOOLEAN                 Valid;  // Set it as 1 if the apcli interface associated success to remote AP.
2500         UCHAR                                   MacTabWCID;     //WCID value, which point to the entry of ASIC Mac table.
2501         UCHAR                   SsidLen;
2502         CHAR                    Ssid[MAX_LEN_OF_SSID];
2503
2504         UCHAR                   CfgSsidLen;
2505         CHAR                    CfgSsid[MAX_LEN_OF_SSID];
2506         UCHAR                   CfgApCliBssid[ETH_LENGTH_OF_ADDRESS];
2507         UCHAR                   CurrentAddress[ETH_LENGTH_OF_ADDRESS];
2508
2509         ULONG                   ApCliRcvBeaconTime;
2510
2511         ULONG                   CtrlCurrState;
2512         ULONG                   SyncCurrState;
2513         ULONG                   AuthCurrState;
2514         ULONG                   AssocCurrState;
2515         ULONG                                   WpaPskCurrState;
2516
2517         USHORT                  AuthReqCnt;
2518         USHORT                  AssocReqCnt;
2519
2520         ULONG                   ClientStatusFlags;
2521         UCHAR                   MpduDensity;
2522
2523         NDIS_802_11_AUTHENTICATION_MODE     AuthMode;   // This should match to whatever microsoft defined
2524         NDIS_802_11_WEP_STATUS              WepStatus;
2525
2526         // Add to support different cipher suite for WPA2/WPA mode
2527         NDIS_802_11_ENCRYPTION_STATUS           GroupCipher;            // Multicast cipher suite
2528         NDIS_802_11_ENCRYPTION_STATUS           PairCipher;                     // Unicast cipher suite
2529         BOOLEAN                                                         bMixCipher;                     // Indicate current Pair & Group use different cipher suites
2530         USHORT                                                          RsnCapability;
2531
2532         UCHAR           PSK[100];                               // reserve PSK key material
2533         UCHAR       PSKLen;
2534         UCHAR       PMK[32];                // WPA PSK mode PMK
2535         UCHAR           GTK[32];                                // GTK from authenticator
2536
2537         CIPHER_KEY      SharedKey[SHARE_KEY_NUM];
2538         UCHAR           DefaultKeyId;
2539
2540         // store RSN_IE built by driver
2541         UCHAR           RSN_IE[MAX_LEN_OF_RSNIE];  // The content saved here should be convert to little-endian format.
2542         UCHAR           RSNIE_Len;
2543
2544         // For WPA countermeasures
2545         ULONG       LastMicErrorTime;   // record last MIC error time
2546         BOOLEAN                 bBlockAssoc; // Block associate attempt for 60 seconds after counter measure occurred.
2547
2548         // For WPA-PSK supplicant state
2549         UCHAR           SNonce[32];         // SNonce for WPA-PSK
2550         UCHAR                   GNonce[32];                     // GNonce for WPA-PSK from authenticator
2551
2552 #ifdef WSC_AP_SUPPORT
2553         WSC_CTRL                   WscControl;
2554 #endif // WSC_AP_SUPPORT //
2555
2556         HTTRANSMIT_SETTING                              HTPhyMode, MaxHTPhyMode, MinHTPhyMode;
2557         RT_HT_PHY_INFO                                  DesiredHtPhyInfo;
2558         BOOLEAN                                                 bAutoTxRateSwitch;
2559         DESIRED_TRANSMIT_SETTING        DesiredTransmitSetting; // Desired transmit setting.
2560 } APCLI_STRUCT, *PAPCLI_STRUCT;
2561
2562 // ----------- end of AP ----------------------------
2563
2564 #ifdef BLOCK_NET_IF
2565 typedef struct _BLOCK_QUEUE_ENTRY
2566 {
2567         BOOLEAN SwTxQueueBlockFlag;
2568         LIST_HEADER NetIfList;
2569 } BLOCK_QUEUE_ENTRY, *PBLOCK_QUEUE_ENTRY;
2570 #endif // BLOCK_NET_IF //
2571
2572 struct wificonf
2573 {
2574         BOOLEAN bShortGI;
2575         BOOLEAN bGreenField;
2576 };
2577
2578
2579
2580
2581 typedef struct _INF_PCI_CONFIG
2582 {
2583         PUCHAR                  CSRBaseAddress;     // PCI MMIO Base Address, all access will use
2584 }INF_PCI_CONFIG;
2585
2586 typedef struct _INF_USB_CONFIG
2587 {
2588         UINT                BulkInEpAddr;               // bulk-in endpoint address
2589         UINT                BulkOutEpAddr[6];   // bulk-out endpoint address
2590
2591 }INF_USB_CONFIG;
2592
2593 #ifdef IKANOS_VX_1X0
2594         typedef void (*IkanosWlanTxCbFuncP)(void *, void *);
2595
2596         struct IKANOS_TX_INFO
2597         {
2598                 struct net_device *netdev;
2599                 IkanosWlanTxCbFuncP *fp;
2600         };
2601 #endif // IKANOS_VX_1X0 //
2602
2603 #ifdef NINTENDO_AP
2604 typedef struct _NINDO_CTRL_BLOCK {
2605
2606         RT_NINTENDO_TABLE       DS_TABLE;
2607
2608 #ifdef CHIP25XX
2609         spinlock_t                      NINTENDO_TABLE_Lock;
2610 #else
2611         NDIS_SPIN_LOCK          NINTENDO_TABLE_Lock;
2612 #endif // CHIP25XX //
2613
2614         UCHAR                           NINTENDO_UP_BUFFER[512];
2615         UCHAR                           Local_KeyIdx;
2616         CIPHER_KEY                      Local_SharedKey;
2617         UCHAR                           Local_bHideSsid;
2618         UCHAR                           Local_AuthMode;
2619         UCHAR                           Local_WepStatus;
2620         USHORT                          Local_CapabilityInfo;
2621 } NINDO_CTRL_BLOCK;
2622 #endif // NINTENDO_AP //
2623
2624
2625 #ifdef DBG_DIAGNOSE
2626 #define DIAGNOSE_TIME   10   // 10 sec
2627 typedef struct _RtmpDiagStrcut_
2628 {       // Diagnosis Related element
2629         unsigned char           inited;
2630         unsigned char   qIdx;
2631         unsigned char   ArrayStartIdx;
2632         unsigned char           ArrayCurIdx;
2633         // Tx Related Count
2634         USHORT                  TxDataCnt[DIAGNOSE_TIME];
2635         USHORT                  TxFailCnt[DIAGNOSE_TIME];
2636         USHORT                  TxDescCnt[DIAGNOSE_TIME][24]; // 3*3    // TxDesc queue length in scale of 0~14, >=15
2637         USHORT                  TxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
2638         USHORT                  TxSWQueCnt[DIAGNOSE_TIME][9];           // TxSwQueue length in scale of 0, 1, 2, 3, 4, 5, 6, 7, >=8
2639
2640         USHORT                  TxAggCnt[DIAGNOSE_TIME];
2641         USHORT                  TxNonAggCnt[DIAGNOSE_TIME];
2642         USHORT                  TxAMPDUCnt[DIAGNOSE_TIME][24]; // 3*3 // 10 sec, TxDMA APMDU Aggregation count in range from 0 to 15, in setp of 1.
2643         USHORT                  TxRalinkCnt[DIAGNOSE_TIME];                     // TxRalink Aggregation Count in 1 sec scale.
2644         USHORT                  TxAMSDUCnt[DIAGNOSE_TIME];                      // TxAMSUD Aggregation Count in 1 sec scale.
2645
2646         // Rx Related Count
2647         USHORT                  RxDataCnt[DIAGNOSE_TIME];                       // Rx Total Data count.
2648         USHORT                  RxCrcErrCnt[DIAGNOSE_TIME];
2649         USHORT                  RxMcsCnt[DIAGNOSE_TIME][24]; // 3*3
2650 }RtmpDiagStruct;
2651 #endif // DBG_DIAGNOSE //
2652
2653
2654 //
2655 //  The miniport adapter structure
2656 //
2657 typedef struct _RTMP_ADAPTER
2658 {
2659         PVOID                                   OS_Cookie;      // save specific structure relative to OS
2660         PNET_DEV                                net_dev;
2661         ULONG                                   VirtualIfCnt;
2662
2663     USHORT                          LnkCtrlBitMask;
2664     USHORT                          RLnkCtrlConfiguration;
2665     USHORT                  RLnkCtrlOffset;
2666     USHORT                          HostLnkCtrlConfiguration;
2667     USHORT                  HostLnkCtrlOffset;
2668         USHORT                      PCIePowerSaveLevel;
2669         BOOLEAN                                 bPCIclkOff;                                             // flag that indicate if the PICE power status in Configuration SPace..
2670         ULONG                                   CheckDmaBusyCount;  // Check Interrupt Status Register Count.
2671         USHORT                                  ThisTbttNumToNextWakeUp;
2672         ULONG                                   SameRxByteCount;
2673
2674
2675 /*****************************************************************************************/
2676 /*      PCI related parameters                                                           */
2677 /*****************************************************************************************/
2678         PUCHAR                  CSRBaseAddress;     // PCI MMIO Base Address, all access will use
2679
2680         UINT                                    int_enable_reg;
2681         UINT                                    int_disable_mask;
2682         UINT                                    int_pending;
2683
2684
2685         RTMP_DMABUF             TxBufSpace[NUM_OF_TX_RING]; // Shared memory of all 1st pre-allocated TxBuf associated with each TXD
2686         RTMP_DMABUF             RxDescRing;                 // Shared memory for RX descriptors
2687         RTMP_DMABUF             TxDescRing[NUM_OF_TX_RING];     // Shared memory for Tx descriptors
2688         RTMP_TX_RING            TxRing[NUM_OF_TX_RING];         // AC0~4 + HCCA
2689
2690
2691         NDIS_SPIN_LOCK          irq_lock;
2692         UCHAR                   irq_disabled;
2693
2694
2695
2696 /*****************************************************************************************/
2697         /*      Both PCI/USB related parameters                                                  */
2698 /*****************************************************************************************/
2699
2700
2701 /*****************************************************************************************/
2702 /*      Tx related parameters                                                           */
2703 /*****************************************************************************************/
2704         BOOLEAN                 DeQueueRunning[NUM_OF_TX_RING];  // for ensuring RTUSBDeQueuePacket get call once
2705         NDIS_SPIN_LOCK          DeQueueLock[NUM_OF_TX_RING];
2706
2707
2708         // resource for software backlog queues
2709         QUEUE_HEADER            TxSwQueue[NUM_OF_TX_RING];  // 4 AC + 1 HCCA
2710         NDIS_SPIN_LOCK          TxSwQueueLock[NUM_OF_TX_RING];  // TxSwQueue spinlock
2711
2712         RTMP_DMABUF             MgmtDescRing;                   // Shared memory for MGMT descriptors
2713         RTMP_MGMT_RING          MgmtRing;
2714         NDIS_SPIN_LOCK          MgmtRingLock;                   // Prio Ring spinlock
2715
2716
2717 /*****************************************************************************************/
2718 /*      Rx related parameters                                                           */
2719 /*****************************************************************************************/
2720
2721         RTMP_RX_RING            RxRing;
2722         NDIS_SPIN_LOCK          RxRingLock;                 // Rx Ring spinlock
2723
2724
2725
2726 /*****************************************************************************************/
2727 /*      ASIC related parameters                                                          */
2728 /*****************************************************************************************/
2729         UINT32                  MACVersion;             // MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101)..
2730
2731         // ---------------------------
2732         // E2PROM
2733         // ---------------------------
2734         ULONG                   EepromVersion;          // byte 0: version, byte 1: revision, byte 2~3: unused
2735         UCHAR                   EEPROMAddressNum;       // 93c46=6  93c66=8
2736         USHORT                  EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
2737         ULONG                   FirmwareVersion;        // byte 0: Minor version, byte 1: Major version, otherwise unused.
2738
2739         // ---------------------------
2740         // BBP Control
2741         // ---------------------------
2742         UCHAR                   BbpWriteLatch[140];     // record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID
2743         UCHAR                   BbpRssiToDbmDelta;
2744         BBP_R66_TUNING          BbpTuning;
2745
2746         // ----------------------------
2747         // RFIC control
2748         // ----------------------------
2749         UCHAR                   RfIcType;       // RFIC_xxx
2750         ULONG                   RfFreqOffset;   // Frequency offset for channel switching
2751         RTMP_RF_REGS            LatchRfRegs;    // latch th latest RF programming value since RF IC doesn't support READ
2752
2753         EEPROM_ANTENNA_STRUC    Antenna;                            // Since ANtenna definition is different for a & g. We need to save it for future reference.
2754         EEPROM_NIC_CONFIG2_STRUC    NicConfig2;
2755
2756         // This soft Rx Antenna Diversity mechanism is used only when user set
2757         // RX Antenna = DIVERSITY ON
2758         SOFT_RX_ANT_DIVERSITY   RxAnt;
2759
2760         UCHAR                   RFProgSeq;
2761         CHANNEL_TX_POWER        TxPower[MAX_NUM_OF_CHANNELS];       // Store Tx power value for all channels.
2762         CHANNEL_TX_POWER        ChannelList[MAX_NUM_OF_CHANNELS];   // list all supported channels for site survey
2763         CHANNEL_11J_TX_POWER    TxPower11J[MAX_NUM_OF_11JCHANNELS];       // 802.11j channel and bw
2764         CHANNEL_11J_TX_POWER    ChannelList11J[MAX_NUM_OF_11JCHANNELS];   // list all supported channels for site survey
2765
2766         UCHAR                   ChannelListNum;                     // number of channel in ChannelList[]
2767         UCHAR                                   Bbp94;
2768         BOOLEAN                                 BbpForCCK;
2769         ULONG           Tx20MPwrCfgABand[5];
2770         ULONG           Tx20MPwrCfgGBand[5];
2771         ULONG           Tx40MPwrCfgABand[5];
2772         ULONG           Tx40MPwrCfgGBand[5];
2773
2774         BOOLEAN     bAutoTxAgcA;                // Enable driver auto Tx Agc control
2775         UCHAR       TssiRefA;                                   // Store Tssi reference value as 25 temperature.
2776         UCHAR       TssiPlusBoundaryA[5];               // Tssi boundary for increase Tx power to compensate.
2777         UCHAR       TssiMinusBoundaryA[5];              // Tssi boundary for decrease Tx power to compensate.
2778         UCHAR       TxAgcStepA;                                 // Store Tx TSSI delta increment / decrement value
2779         CHAR            TxAgcCompensateA;                       // Store the compensation (TxAgcStep * (idx-1))
2780
2781         BOOLEAN     bAutoTxAgcG;                // Enable driver auto Tx Agc control
2782         UCHAR       TssiRefG;                                   // Store Tssi reference value as 25 temperature.
2783         UCHAR       TssiPlusBoundaryG[5];               // Tssi boundary for increase Tx power to compensate.
2784         UCHAR       TssiMinusBoundaryG[5];              // Tssi boundary for decrease Tx power to compensate.
2785         UCHAR       TxAgcStepG;                                 // Store Tx TSSI delta increment / decrement value
2786         CHAR            TxAgcCompensateG;                       // Store the compensation (TxAgcStep * (idx-1))
2787
2788         //+++For RT2870, the parameteres is start from BGRssiOffset1 ~ BGRssiOffset3
2789         CHAR            BGRssiOffset0;                          // Store B/G RSSI#0 Offset value on EEPROM 0x46h
2790         CHAR            BGRssiOffset1;                          // Store B/G RSSI#1 Offset value
2791         CHAR            BGRssiOffset2;                          // Store B/G RSSI#2 Offset value
2792         //---
2793
2794         //+++For RT2870, the parameteres is start from ARssiOffset1 ~ ARssiOffset3
2795         CHAR            ARssiOffset0;                           // Store A RSSI#0 Offset value on EEPROM 0x4Ah
2796         CHAR            ARssiOffset1;                           // Store A RSSI#1 Offset value
2797         CHAR            ARssiOffset2;                           // Store A RSSI#2 Offset value
2798         //---
2799
2800         CHAR            BLNAGain;                                       // Store B/G external LNA#0 value on EEPROM 0x44h
2801         CHAR            ALNAGain0;                                      // Store A external LNA#0 value for ch36~64
2802         CHAR            ALNAGain1;                                      // Store A external LNA#1 value for ch100~128
2803         CHAR            ALNAGain2;                                      // Store A external LNA#2 value for ch132~165
2804
2805         // ----------------------------
2806         // LED control
2807         // ----------------------------
2808         MCU_LEDCS_STRUC         LedCntl;
2809         USHORT                          Led1;   // read from EEPROM 0x3c
2810         USHORT                          Led2;   // EEPROM 0x3e
2811         USHORT                          Led3;   // EEPROM 0x40
2812         UCHAR                           LedIndicatorStregth;
2813         UCHAR                           RssiSingalstrengthOffet;
2814     BOOLEAN                             bLedOnScanning;
2815         UCHAR                           LedStatus;
2816
2817 /*****************************************************************************************/
2818 /*      802.11 related parameters                                                        */
2819 /*****************************************************************************************/
2820         // outgoing BEACON frame buffer and corresponding TXD
2821         TXWI_STRUC                      BeaconTxWI;
2822         PUCHAR                                          BeaconBuf;
2823         USHORT                                          BeaconOffset[HW_BEACON_MAX_COUNT];
2824
2825         // pre-build PS-POLL and NULL frame upon link up. for efficiency purpose.
2826         PSPOLL_FRAME                    PsPollFrame;
2827         HEADER_802_11                   NullFrame;
2828
2829 //=========AP===========
2830
2831
2832 //=======STA===========
2833 #ifdef CONFIG_STA_SUPPORT
2834 /* Modified by Wu Xi-Kun 4/21/2006 */
2835         // -----------------------------------------------
2836         // STA specific configuration & operation status
2837         // used only when pAd->OpMode == OPMODE_STA
2838         // -----------------------------------------------
2839         STA_ADMIN_CONFIG        StaCfg;           // user desired settings
2840         STA_ACTIVE_CONFIG       StaActive;         // valid only when ADHOC_ON(pAd) || INFRA_ON(pAd)
2841         CHAR                    nickname[IW_ESSID_MAX_SIZE+1]; // nickname, only used in the iwconfig i/f
2842         NDIS_MEDIA_STATE        PreMediaState;
2843 #endif // CONFIG_STA_SUPPORT //
2844
2845 //=======Common===========
2846         // OP mode: either AP or STA
2847         UCHAR                   OpMode;                     // OPMODE_STA, OPMODE_AP
2848
2849         NDIS_MEDIA_STATE        IndicateMediaState;                     // Base on Indication state, default is NdisMediaStateDisConnected
2850
2851         // MAT related parameters
2852
2853         // configuration: read from Registry & E2PROM
2854         BOOLEAN                 bLocalAdminMAC;             // Use user changed MAC
2855         UCHAR                   PermanentAddress[MAC_ADDR_LEN];    // Factory default MAC address
2856         UCHAR                   CurrentAddress[MAC_ADDR_LEN];      // User changed MAC address
2857
2858         // ------------------------------------------------------
2859         // common configuration to both OPMODE_STA and OPMODE_AP
2860         // ------------------------------------------------------
2861         COMMON_CONFIG           CommonCfg;
2862         MLME_STRUCT             Mlme;
2863
2864         // AP needs those vaiables for site survey feature.
2865         MLME_AUX                MlmeAux;           // temporary settings used during MLME state machine
2866         BSS_TABLE               ScanTab;           // store the latest SCAN result
2867
2868         //About MacTab, the sta driver will use #0 and #1 for multicast and AP.
2869         MAC_TABLE                 MacTab;     // ASIC on-chip WCID entry table.  At TX, ASIC always use key according to this on-chip table.
2870         NDIS_SPIN_LOCK          MacTabLock;
2871
2872 #ifdef DOT11_N_SUPPORT
2873         BA_TABLE                        BATable;
2874 #endif // DOT11_N_SUPPORT //
2875         NDIS_SPIN_LOCK          BATabLock;
2876         RALINK_TIMER_STRUCT RECBATimer;
2877
2878         // encryption/decryption KEY tables
2879         CIPHER_KEY              SharedKey[MAX_MBSSID_NUM][4]; // STA always use SharedKey[BSS0][0..3]
2880
2881                 // RX re-assembly buffer for fragmentation
2882         FRAGMENT_FRAME          FragFrame;                  // Frame storage for fragment frame
2883
2884         // various Counters
2885         COUNTER_802_3           Counters8023;               // 802.3 counters
2886         COUNTER_802_11          WlanCounters;               // 802.11 MIB counters
2887         COUNTER_RALINK          RalinkCounters;             // Ralink propriety counters
2888         COUNTER_DRS             DrsCounters;                // counters for Dynamic TX Rate Switching
2889         PRIVATE_STRUC           PrivateInfo;                // Private information & counters
2890
2891         // flags, see fRTMP_ADAPTER_xxx flags
2892         ULONG                   Flags;                      // Represent current device status
2893         ULONG                   PSFlags;                    // Power Save operation flag.
2894
2895         // current TX sequence #
2896         USHORT                  Sequence;
2897
2898 #ifdef UNDER_CE
2899         NDIS_HANDLE             hGiISR;
2900 #endif
2901
2902
2903         // Control disconnect / connect event generation
2904         //+++Didn't used anymore
2905         ULONG                   LinkDownTime;
2906         //---
2907         ULONG                   LastRxRate;
2908         ULONG                   LastTxRate;
2909         //+++Used only for Station
2910         BOOLEAN                 bConfigChanged;         // Config Change flag for the same SSID setting
2911         //---
2912
2913         ULONG                   ExtraInfo;              // Extra information for displaying status
2914         ULONG                   SystemErrorBitmap;      // b0: E2PROM version error
2915
2916         //+++Didn't used anymore
2917         ULONG                   MacIcVersion;           // MAC/BBP serial interface issue solved after ver.D
2918         //---
2919
2920         // ---------------------------
2921         // System event log
2922         // ---------------------------
2923         RT_802_11_EVENT_TABLE   EventTab;
2924
2925
2926         BOOLEAN         HTCEnable;
2927
2928         /*****************************************************************************************/
2929         /*      Statistic related parameters                                                     */
2930         /*****************************************************************************************/
2931
2932         BOOLEAN                                         bUpdateBcnCntDone;
2933         ULONG                                           watchDogMacDeadlock;    // prevent MAC/BBP into deadlock condition
2934         // ----------------------------
2935         // DEBUG paramerts
2936         // ----------------------------
2937         BOOLEAN         bBanAllBaSetup;
2938         BOOLEAN         bPromiscuous;
2939
2940         // ----------------------------
2941         // rt2860c emulation-use Parameters
2942         // ----------------------------
2943         ULONG           rtsaccu[30];
2944         ULONG           ctsaccu[30];
2945         ULONG           cfendaccu[30];
2946         ULONG           bacontent[16];
2947         ULONG           rxint[RX_RING_SIZE+1];
2948         UCHAR           rcvba[60];
2949         BOOLEAN         bLinkAdapt;
2950         BOOLEAN         bForcePrintTX;
2951         BOOLEAN         bForcePrintRX;
2952         BOOLEAN         bDisablescanning;               //defined in RT2870 USB
2953         BOOLEAN         bStaFifoTest;
2954         BOOLEAN         bProtectionTest;
2955         BOOLEAN         bHCCATest;
2956         BOOLEAN         bGenOneHCCA;
2957         BOOLEAN         bBroadComHT;
2958         //+++Following add from RT2870 USB.
2959         ULONG           BulkOutReq;
2960         ULONG           BulkOutComplete;
2961         ULONG           BulkOutCompleteOther;
2962         ULONG           BulkOutCompleteCancel;  // seems not use now?
2963         ULONG           BulkInReq;
2964         ULONG           BulkInComplete;
2965         ULONG           BulkInCompleteFail;
2966         //---
2967
2968     struct wificonf                     WIFItestbed;
2969
2970 #ifdef RALINK_ATE
2971         ATE_INFO                                ate;
2972 #endif // RALINK_ATE //
2973
2974 #ifdef DOT11_N_SUPPORT
2975         struct reordering_mpdu_pool mpdu_blk_pool;
2976 #endif // DOT11_N_SUPPORT //
2977
2978         ULONG                                   OneSecondnonBEpackets;          // record non BE packets per second
2979
2980 #if WIRELESS_EXT >= 12
2981     struct iw_statistics    iw_stats;
2982 #endif
2983
2984         struct net_device_stats stats;
2985
2986 #ifdef BLOCK_NET_IF
2987         BLOCK_QUEUE_ENTRY               blockQueueTab[NUM_OF_TX_RING];
2988 #endif // BLOCK_NET_IF //
2989
2990
2991
2992 #ifdef MULTIPLE_CARD_SUPPORT
2993         INT32                                   MC_RowID;
2994         UCHAR                                   MC_FileName[256];
2995 #endif // MULTIPLE_CARD_SUPPORT //
2996
2997         ULONG                                   TbttTickCount;
2998 #ifdef PCI_MSI_SUPPORT
2999         BOOLEAN                                 HaveMsi;
3000 #endif // PCI_MSI_SUPPORT //
3001
3002
3003         UCHAR                                   is_on;
3004
3005 #define TIME_BASE                       (1000000/OS_HZ)
3006 #define TIME_ONE_SECOND         (1000000/TIME_BASE)
3007         UCHAR                                   flg_be_adjust;
3008         ULONG                                   be_adjust_last_time;
3009
3010 #ifdef NINTENDO_AP
3011         NINDO_CTRL_BLOCK                nindo_ctrl_block;
3012 #endif // NINTENDO_AP //
3013
3014
3015 #ifdef IKANOS_VX_1X0
3016         struct IKANOS_TX_INFO   IkanosTxInfo;
3017         struct IKANOS_TX_INFO   IkanosRxInfo[MAX_MBSSID_NUM + MAX_WDS_ENTRY + MAX_APCLI_NUM + MAX_MESH_NUM];
3018 #endif // IKANOS_VX_1X0 //
3019
3020
3021 #ifdef DBG_DIAGNOSE
3022         RtmpDiagStruct  DiagStruct;
3023 #endif // DBG_DIAGNOSE //
3024
3025
3026         UINT8                                   PM_FlgSuspend;
3027 } RTMP_ADAPTER, *PRTMP_ADAPTER;
3028
3029 //
3030 // Cisco IAPP format
3031 //
3032 typedef struct  _CISCO_IAPP_CONTENT_
3033 {
3034         USHORT     Length;        //IAPP Length
3035         UCHAR      MessageType;      //IAPP type
3036         UCHAR      FunctionCode;     //IAPP function type
3037         UCHAR      DestinaionMAC[MAC_ADDR_LEN];
3038         UCHAR      SourceMAC[MAC_ADDR_LEN];
3039         USHORT     Tag;           //Tag(element IE) - Adjacent AP report
3040         USHORT     TagLength;     //Length of element not including 4 byte header
3041         UCHAR      OUI[4];           //0x00, 0x40, 0x96, 0x00
3042         UCHAR      PreviousAP[MAC_ADDR_LEN];       //MAC Address of access point
3043         USHORT     Channel;
3044         USHORT     SsidLen;
3045         UCHAR      Ssid[MAX_LEN_OF_SSID];
3046         USHORT     Seconds;          //Seconds that the client has been disassociated.
3047 } CISCO_IAPP_CONTENT, *PCISCO_IAPP_CONTENT;
3048
3049 #define DELAYINTMASK            0x0003fffb
3050 #define INTMASK                         0x0003fffb
3051 #define IndMask                         0x0003fffc
3052 #define RxINT                           0x00000005      // Delayed Rx or indivi rx
3053 #define TxDataInt                       0x000000fa      // Delayed Tx or indivi tx
3054 #define TxMgmtInt                       0x00000102      // Delayed Tx or indivi tx
3055 #define TxCoherent                      0x00020000      // tx coherent
3056 #define RxCoherent                      0x00010000      // rx coherent
3057 #define McuCommand                      0x00000200      // mcu
3058 #define PreTBTTInt                      0x00001000      // Pre-TBTT interrupt
3059 #define TBTTInt                         0x00000800              // TBTT interrupt
3060 #define GPTimeOutInt                    0x00008000              // GPtimeout interrupt
3061 #define AutoWakeupInt           0x00004000              // AutoWakeupInt interrupt
3062 #define FifoStaFullInt                  0x00002000      //  fifo statistics full interrupt
3063
3064
3065 typedef struct _RX_BLK_
3066 {
3067         RT28XX_RXD_STRUC        RxD;
3068         PRXWI_STRUC                     pRxWI;
3069         PHEADER_802_11          pHeader;
3070         PNDIS_PACKET            pRxPacket;
3071         UCHAR                           *pData;
3072         USHORT                          DataSize;
3073         USHORT                          Flags;
3074         UCHAR                           UserPriority;   // for calculate TKIP MIC using
3075 } RX_BLK;
3076
3077
3078 #define RX_BLK_SET_FLAG(_pRxBlk, _flag)         (_pRxBlk->Flags |= _flag)
3079 #define RX_BLK_TEST_FLAG(_pRxBlk, _flag)        (_pRxBlk->Flags & _flag)
3080 #define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag)       (_pRxBlk->Flags &= ~(_flag))
3081
3082
3083 #define fRX_WDS                 0x0001
3084 #define fRX_AMSDU       0x0002
3085 #define fRX_ARALINK     0x0004
3086 #define fRX_HTC         0x0008
3087 #define fRX_PAD         0x0010
3088 #define fRX_AMPDU       0x0020
3089 #define fRX_QOS                 0x0040
3090 #define fRX_INFRA               0x0080
3091 #define fRX_EAP                 0x0100
3092 #define fRX_MESH                0x0200
3093 #define fRX_APCLI               0x0400
3094 #define fRX_DLS                 0x0800
3095 #define fRX_WPI                 0x1000
3096
3097 #define LENGTH_AMSDU_SUBFRAMEHEAD       14
3098 #define LENGTH_ARALINK_SUBFRAMEHEAD     14
3099 #define LENGTH_ARALINK_HEADER_FIELD      2
3100
3101 #define TX_UNKOWN_FRAME                 0x00
3102 #define TX_MCAST_FRAME                  0x01
3103 #define TX_LEGACY_FRAME                 0x02
3104 #define TX_AMPDU_FRAME                  0x04
3105 #define TX_AMSDU_FRAME                  0x08
3106 #define TX_RALINK_FRAME                 0x10
3107 #define TX_FRAG_FRAME                   0x20
3108
3109
3110 //      Currently the sizeof(TX_BLK) is 148 bytes.
3111 typedef struct _TX_BLK_
3112 {
3113         UCHAR                           QueIdx;
3114         UCHAR                           TxFrameType;                            // Indicate the Transmission type of the all frames in one batch
3115         UCHAR                           TotalFrameNum;                          // Total frame number want to send-out in one batch
3116         USHORT                          TotalFragNum;                           // Total frame fragments required in one batch
3117         USHORT                          TotalFrameLen;                          // Total length of all frames want to send-out in one batch
3118
3119         QUEUE_HEADER            TxPacketList;
3120         MAC_TABLE_ENTRY         *pMacEntry;                                     // NULL: packet with 802.11 RA field is multicast/broadcast address
3121         HTTRANSMIT_SETTING      *pTransmit;
3122
3123         // Following structure used for the characteristics of a specific packet.
3124         PNDIS_PACKET            pPacket;
3125         PUCHAR                          pSrcBufHeader;                          // Reference to the head of sk_buff->data
3126         PUCHAR                          pSrcBufData;                            // Reference to the sk_buff->data, will changed depends on hanlding progresss
3127         UINT                            SrcBufLen;                                      // Length of packet payload which not including Layer 2 header
3128         PUCHAR                          pExtraLlcSnapEncap;                     // NULL means no extra LLC/SNAP is required
3129         UCHAR                           HeaderBuf[80];                          // TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP
3130         UCHAR                           MpduHeaderLen;                          // 802.11 header length NOT including the padding
3131         UCHAR                           HdrPadLen;                                      // recording Header Padding Length;
3132         UCHAR                           apidx;                                          // The interface associated to this packet
3133         UCHAR                           Wcid;                                           // The MAC entry associated to this packet
3134         UCHAR                           UserPriority;                           // priority class of packet
3135         UCHAR                           FrameGap;                                       // what kind of IFS this packet use
3136         UCHAR                           MpduReqNum;                                     // number of fragments of this frame
3137         UCHAR                           TxRate;                                         // TODO: Obsoleted? Should change to MCS?
3138         UCHAR                           CipherAlg;                                      // cipher alogrithm
3139         PCIPHER_KEY                     pKey;
3140
3141
3142
3143         USHORT                          Flags;                                          //See following definitions for detail.
3144
3145         //YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer.
3146         ULONG                           Priv;                                           // Hardware specific value saved in here.
3147 } TX_BLK, *PTX_BLK;
3148
3149
3150 #define fTX_bRtsRequired                0x0001  // Indicate if need send RTS frame for protection. Not used in RT2860/RT2870.
3151 #define fTX_bAckRequired        0x0002  // the packet need ack response
3152 #define fTX_bPiggyBack                  0x0004  // Legacy device use Piggback or not
3153 #define fTX_bHTRate             0x0008  // allow to use HT rate
3154 #define fTX_bForceNonQoS        0x0010  // force to transmit frame without WMM-QoS in HT mode
3155 #define fTX_bAllowFrag          0x0020  // allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment
3156 #define fTX_bMoreData                   0x0040  // there are more data packets in PowerSave Queue
3157 #define fTX_bWMM                                0x0080  // QOS Data
3158
3159 #define fTX_bClearEAPFrame              0x0100
3160
3161 #define TX_BLK_ASSIGN_FLAG(_pTxBlk, _flag, value)       \
3162                 do {                                                                            \
3163                         if (value)                                                              \
3164                                 (_pTxBlk->Flags |= _flag)                       \
3165                         else                                                                    \
3166                                 (_pTxBlk->Flags &= ~(_flag))            \
3167                 }while(0)
3168
3169 #define TX_BLK_SET_FLAG(_pTxBlk, _flag)         (_pTxBlk->Flags |= _flag)
3170 #define TX_BLK_TEST_FLAG(_pTxBlk, _flag)        (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
3171 #define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag)       (_pTxBlk->Flags &= ~(_flag))
3172
3173
3174
3175
3176
3177 //------------------------------------------------------------------------------------------
3178
3179
3180 //
3181 // Enable & Disable NIC interrupt via writing interrupt mask register
3182 // Since it use ADAPTER structure, it have to be put after structure definition.
3183 //
3184 __inline    VOID    NICDisableInterrupt(
3185     IN  PRTMP_ADAPTER   pAd)
3186 {
3187         RTMP_IO_WRITE32(pAd, INT_MASK_CSR, 0x0);     // 0: disable
3188         //RTMP_IO_WRITE32(pAd, PBF_INT_ENA, 0x0);               // 0x418 is for firmware . SW doesn't handle here.
3189         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
3190 }
3191
3192 __inline    VOID    NICEnableInterrupt(
3193     IN  PRTMP_ADAPTER   pAd)
3194 {
3195         //
3196         // Flag "fOP_STATUS_DOZE" On, means ASIC put to sleep, else means ASIC WakeUp
3197         // To prevent System hang, we should enalbe the interrupt when
3198         // ASIC is already Wake Up.
3199         //
3200     // RT2661 => when ASIC is sleeping, MAC register cannot be read and written.
3201         // RT2860 => when ASIC is sleeping, MAC register can be read and written.
3202         //if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
3203         {
3204                 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, pAd->int_enable_reg /*DELAYINTMASK*/);     // 1:enable
3205         }
3206         //else
3207         //      DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_DOZE !\n"));
3208
3209         //RTMP_IO_WRITE32(pAd, PBF_INT_ENA, 0x00000030); // 1 : enable
3210         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
3211 }
3212
3213 #ifdef RT_BIG_ENDIAN
3214 static inline VOID      WriteBackToDescriptor(
3215         IN  PUCHAR                      Dest,
3216         IN      PUCHAR                  Src,
3217     IN  BOOLEAN                 DoEncrypt,
3218         IN  ULONG           DescriptorType)
3219 {
3220         UINT32 *p1, *p2;
3221
3222         p1 = ((UINT32 *)Dest);
3223         p2 = ((UINT32 *)Src);
3224
3225         *p1 = *p2;
3226         *(p1+2) = *(p2+2);
3227         *(p1+3) = *(p2+3);
3228         *(p1+1) = *(p2+1); // Word 1; this must be written back last
3229 }
3230
3231 /*
3232         ========================================================================
3233
3234         Routine Description:
3235                 Endian conversion of Tx/Rx descriptor .
3236
3237         Arguments:
3238                 pAd     Pointer to our adapter
3239                 pData                   Pointer to Tx/Rx descriptor
3240                 DescriptorType  Direction of the frame
3241
3242         Return Value:
3243                 None
3244
3245         Note:
3246                 Call this function when read or update descriptor
3247         ========================================================================
3248 */
3249 static inline VOID      RTMPWIEndianChange(
3250         IN      PUCHAR                  pData,
3251         IN      ULONG                   DescriptorType)
3252 {
3253         int size;
3254         int i;
3255
3256         size = ((DescriptorType == TYPE_TXWI) ? TXWI_SIZE : RXWI_SIZE);
3257
3258         if(DescriptorType == TYPE_TXWI)
3259         {
3260                 *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData)));            // Byte 0~3
3261                 *((UINT32 *)(pData + 4)) = SWAP32(*((UINT32 *)(pData+4)));      // Byte 4~7
3262         }
3263         else
3264         {
3265                 for(i=0; i < size/4 ; i++)
3266                         *(((UINT32 *)pData) +i) = SWAP32(*(((UINT32 *)pData)+i));
3267         }
3268 }
3269
3270 /*
3271         ========================================================================
3272
3273         Routine Description:
3274                 Endian conversion of Tx/Rx descriptor .
3275
3276         Arguments:
3277                 pAd     Pointer to our adapter
3278                 pData                   Pointer to Tx/Rx descriptor
3279                 DescriptorType  Direction of the frame
3280
3281         Return Value:
3282                 None
3283
3284         Note:
3285                 Call this function when read or update descriptor
3286         ========================================================================
3287 */
3288 static inline VOID      RTMPDescriptorEndianChange(
3289         IN      PUCHAR                  pData,
3290         IN      ULONG                   DescriptorType)
3291 {
3292         *((UINT32 *)(pData)) = SWAP32(*((UINT32 *)(pData)));            // Byte 0~3
3293         *((UINT32 *)(pData + 8)) = SWAP32(*((UINT32 *)(pData+8)));      // Byte 8~11
3294         *((UINT32 *)(pData +12)) = SWAP32(*((UINT32 *)(pData + 12)));   // Byte 12~15
3295         *((UINT32 *)(pData + 4)) = SWAP32(*((UINT32 *)(pData + 4)));                            // Byte 4~7, this must be swapped last
3296 }
3297
3298 /*
3299         ========================================================================
3300
3301         Routine Description:
3302                 Endian conversion of all kinds of 802.11 frames .
3303
3304         Arguments:
3305                 pAd     Pointer to our adapter
3306                 pData                   Pointer to the 802.11 frame structure
3307                 Dir                     Direction of the frame
3308                 FromRxDoneInt   Caller is from RxDone interrupt
3309
3310         Return Value:
3311                 None
3312
3313         Note:
3314                 Call this function when read or update buffer data
3315         ========================================================================
3316 */
3317 static inline VOID      RTMPFrameEndianChange(
3318         IN      PRTMP_ADAPTER   pAd,
3319         IN      PUCHAR                  pData,
3320         IN      ULONG                   Dir,
3321         IN      BOOLEAN                 FromRxDoneInt)
3322 {
3323         PHEADER_802_11 pFrame;
3324         PUCHAR  pMacHdr;
3325
3326         // swab 16 bit fields - Frame Control field
3327         if(Dir == DIR_READ)
3328         {
3329                 *(USHORT *)pData = SWAP16(*(USHORT *)pData);
3330         }
3331
3332         pFrame = (PHEADER_802_11) pData;
3333         pMacHdr = (PUCHAR) pFrame;
3334
3335         // swab 16 bit fields - Duration/ID field
3336         *(USHORT *)(pMacHdr + 2) = SWAP16(*(USHORT *)(pMacHdr + 2));
3337
3338         // swab 16 bit fields - Sequence Control field
3339         *(USHORT *)(pMacHdr + 22) = SWAP16(*(USHORT *)(pMacHdr + 22));
3340
3341         if(pFrame->FC.Type == BTYPE_MGMT)
3342         {
3343                 switch(pFrame->FC.SubType)
3344                 {
3345                         case SUBTYPE_ASSOC_REQ:
3346                         case SUBTYPE_REASSOC_REQ:
3347                                 // swab 16 bit fields - CapabilityInfo field
3348                                 pMacHdr += sizeof(HEADER_802_11);
3349                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3350
3351                                 // swab 16 bit fields - Listen Interval field
3352                                 pMacHdr += 2;
3353                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3354                                 break;
3355
3356                         case SUBTYPE_ASSOC_RSP:
3357                         case SUBTYPE_REASSOC_RSP:
3358                                 // swab 16 bit fields - CapabilityInfo field
3359                                 pMacHdr += sizeof(HEADER_802_11);
3360                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3361
3362                                 // swab 16 bit fields - Status Code field
3363                                 pMacHdr += 2;
3364                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3365
3366                                 // swab 16 bit fields - AID field
3367                                 pMacHdr += 2;
3368                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3369                                 break;
3370
3371                         case SUBTYPE_AUTH:
3372                                 // If from APHandleRxDoneInterrupt routine, it is still a encrypt format.
3373                                 // The convertion is delayed to RTMPHandleDecryptionDoneInterrupt.
3374                                 if(!FromRxDoneInt && pFrame->FC.Wep == 1)
3375                                         break;
3376                                 else
3377                                 {
3378                                         // swab 16 bit fields - Auth Alg No. field
3379                                         pMacHdr += sizeof(HEADER_802_11);
3380                                         *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3381
3382                                         // swab 16 bit fields - Auth Seq No. field
3383                                         pMacHdr += 2;
3384                                         *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3385
3386                                         // swab 16 bit fields - Status Code field
3387                                         pMacHdr += 2;
3388                                         *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3389                                 }
3390                                 break;
3391
3392                         case SUBTYPE_BEACON:
3393                         case SUBTYPE_PROBE_RSP:
3394                                 // swab 16 bit fields - BeaconInterval field
3395                                 pMacHdr += (sizeof(HEADER_802_11) + TIMESTAMP_LEN);
3396                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3397
3398                                 // swab 16 bit fields - CapabilityInfo field
3399                                 pMacHdr += sizeof(USHORT);
3400                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3401                                 break;
3402
3403                         case SUBTYPE_DEAUTH:
3404                         case SUBTYPE_DISASSOC:
3405                                 // swab 16 bit fields - Reason code field
3406                                 pMacHdr += sizeof(HEADER_802_11);
3407                                 *(USHORT *)pMacHdr = SWAP16(*(USHORT *)pMacHdr);
3408                                 break;
3409                 }
3410         }
3411         else if( pFrame->FC.Type == BTYPE_DATA )
3412         {
3413         }
3414         else if(pFrame->FC.Type == BTYPE_CNTL)
3415         {
3416                 switch(pFrame->FC.SubType)
3417                 {
3418                         case SUBTYPE_BLOCK_ACK_REQ:
3419                                 {
3420                                         PFRAME_BA_REQ pBAReq = (PFRAME_BA_REQ)pFrame;
3421                                         *(USHORT *)(&pBAReq->BARControl) = SWAP16(*(USHORT *)(&pBAReq->BARControl));
3422                                         pBAReq->BAStartingSeq.word = SWAP16(pBAReq->BAStartingSeq.word);
3423                                 }
3424                                 break;
3425                         case SUBTYPE_BLOCK_ACK:
3426                                 // For Block Ack packet, the HT_CONTROL field is in the same offset with Addr3
3427                                 *(UINT32 *)(&pFrame->Addr3[0]) = SWAP32(*(UINT32 *)(&pFrame->Addr3[0]));
3428                                 break;
3429
3430                         case SUBTYPE_ACK:
3431                                 //For ACK packet, the HT_CONTROL field is in the same offset with Addr2
3432                                 *(UINT32 *)(&pFrame->Addr2[0])= SWAP32(*(UINT32 *)(&pFrame->Addr2[0]));
3433                                 break;
3434                 }
3435         }
3436         else
3437         {
3438                 DBGPRINT(RT_DEBUG_ERROR,("Invalid Frame Type!!!\n"));
3439         }
3440
3441         // swab 16 bit fields - Frame Control
3442         if(Dir == DIR_WRITE)
3443         {
3444                 *(USHORT *)pData = SWAP16(*(USHORT *)pData);
3445         }
3446 }
3447 #endif // RT_BIG_ENDIAN //
3448
3449
3450 static inline VOID ConvertMulticastIP2MAC(
3451         IN PUCHAR pIpAddr,
3452         IN PUCHAR *ppMacAddr,
3453         IN UINT16 ProtoType)
3454 {
3455         if (pIpAddr == NULL)
3456                 return;
3457
3458         if (ppMacAddr == NULL || *ppMacAddr == NULL)
3459                 return;
3460
3461         switch (ProtoType)
3462         {
3463                 case ETH_P_IPV6:
3464 //                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
3465                         *(*ppMacAddr) = 0x33;
3466                         *(*ppMacAddr + 1) = 0x33;
3467                         *(*ppMacAddr + 2) = pIpAddr[12];
3468                         *(*ppMacAddr + 3) = pIpAddr[13];
3469                         *(*ppMacAddr + 4) = pIpAddr[14];
3470                         *(*ppMacAddr + 5) = pIpAddr[15];
3471                         break;
3472
3473                 case ETH_P_IP:
3474                 default:
3475 //                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS);
3476                         *(*ppMacAddr) = 0x01;
3477                         *(*ppMacAddr + 1) = 0x00;
3478                         *(*ppMacAddr + 2) = 0x5e;
3479                         *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
3480                         *(*ppMacAddr + 4) = pIpAddr[2];
3481                         *(*ppMacAddr + 5) = pIpAddr[3];
3482                         break;
3483         }
3484
3485         return;
3486 }
3487
3488 BOOLEAN RTMPCheckForHang(
3489         IN  NDIS_HANDLE MiniportAdapterContext
3490         );
3491
3492 VOID  RTMPHalt(
3493         IN  NDIS_HANDLE MiniportAdapterContext
3494         );
3495
3496 //
3497 //  Private routines in rtmp_init.c
3498 //
3499 NDIS_STATUS RTMPAllocAdapterBlock(
3500         IN PVOID                        handle,
3501         OUT PRTMP_ADAPTER   *ppAdapter
3502         );
3503
3504 NDIS_STATUS RTMPAllocTxRxRingMemory(
3505         IN  PRTMP_ADAPTER   pAd
3506         );
3507
3508 NDIS_STATUS RTMPFindAdapter(
3509         IN  PRTMP_ADAPTER   pAd,
3510         IN  NDIS_HANDLE     WrapperConfigurationContext
3511         );
3512
3513 NDIS_STATUS     RTMPReadParametersHook(
3514         IN      PRTMP_ADAPTER pAd
3515         );
3516
3517 VOID RTMPFreeAdapter(
3518         IN  PRTMP_ADAPTER   pAd
3519         );
3520
3521 NDIS_STATUS NICReadRegParameters(
3522         IN  PRTMP_ADAPTER       pAd,
3523         IN  NDIS_HANDLE         WrapperConfigurationContext
3524         );
3525
3526
3527 VOID NICReadEEPROMParameters(
3528         IN  PRTMP_ADAPTER       pAd,
3529         IN      PUCHAR                          mac_addr);
3530
3531 VOID NICInitAsicFromEEPROM(
3532         IN  PRTMP_ADAPTER       pAd);
3533
3534 VOID NICInitTxRxRingAndBacklogQueue(
3535         IN  PRTMP_ADAPTER   pAd);
3536
3537 NDIS_STATUS NICInitializeAdapter(
3538         IN  PRTMP_ADAPTER   pAd,
3539         IN   BOOLEAN    bHardReset);
3540
3541 NDIS_STATUS NICInitializeAsic(
3542         IN  PRTMP_ADAPTER   pAd,
3543         IN  BOOLEAN             bHardReset);
3544
3545 VOID NICRestoreBBPValue(
3546         IN PRTMP_ADAPTER pAd);
3547
3548 VOID NICIssueReset(
3549         IN  PRTMP_ADAPTER   pAd);
3550
3551 VOID RTMPRingCleanUp(
3552         IN  PRTMP_ADAPTER   pAd,
3553         IN  UCHAR           RingType);
3554
3555 VOID RxTest(
3556         IN  PRTMP_ADAPTER   pAd);
3557
3558 NDIS_STATUS DbgSendPacket(
3559         IN  PRTMP_ADAPTER   pAd,
3560         IN  PNDIS_PACKET    pPacket);
3561
3562 VOID UserCfgInit(
3563         IN  PRTMP_ADAPTER   pAd);
3564
3565 VOID NICResetFromError(
3566         IN  PRTMP_ADAPTER   pAd);
3567
3568 VOID NICEraseFirmware(
3569         IN PRTMP_ADAPTER pAd);
3570
3571 NDIS_STATUS NICLoadFirmware(
3572         IN  PRTMP_ADAPTER   pAd);
3573
3574 NDIS_STATUS NICLoadRateSwitchingParams(
3575         IN PRTMP_ADAPTER pAd);
3576
3577 BOOLEAN NICCheckForHang(
3578         IN  PRTMP_ADAPTER   pAd);
3579
3580 VOID NICUpdateFifoStaCounters(
3581         IN PRTMP_ADAPTER pAd);
3582
3583 VOID NICUpdateRawCounters(
3584         IN  PRTMP_ADAPTER   pAd);
3585
3586 ULONG   RTMPNotAllZero(
3587         IN      PVOID   pSrc1,
3588         IN      ULONG   Length);
3589
3590 VOID RTMPZeroMemory(
3591         IN  PVOID   pSrc,
3592         IN  ULONG   Length);
3593
3594 ULONG RTMPCompareMemory(
3595         IN  PVOID   pSrc1,
3596         IN  PVOID   pSrc2,
3597         IN  ULONG   Length);
3598
3599 VOID RTMPMoveMemory(
3600         OUT PVOID   pDest,
3601         IN  PVOID   pSrc,
3602         IN  ULONG   Length);
3603
3604 VOID AtoH(
3605         char    *src,
3606         UCHAR   *dest,
3607         int             destlen);
3608
3609 UCHAR BtoH(
3610         char ch);
3611
3612 VOID RTMPPatchMacBbpBug(
3613         IN  PRTMP_ADAPTER   pAd);
3614
3615 VOID RTMPPatchCardBus(
3616         IN      PRTMP_ADAPTER   pAdapter);
3617
3618 VOID RTMPPatchRalinkCardBus(
3619         IN      PRTMP_ADAPTER   pAdapter,
3620         IN      ULONG                   Bus);
3621
3622 ULONG RTMPReadCBConfig(
3623         IN      ULONG   Bus,
3624         IN      ULONG   Slot,
3625         IN      ULONG   Func,
3626         IN      ULONG   Offset);
3627
3628 VOID RTMPWriteCBConfig(
3629         IN      ULONG   Bus,
3630         IN      ULONG   Slot,
3631         IN      ULONG   Func,
3632         IN      ULONG   Offset,
3633         IN      ULONG   Value);
3634
3635 VOID RTMPInitTimer(
3636         IN  PRTMP_ADAPTER           pAd,
3637         IN  PRALINK_TIMER_STRUCT    pTimer,
3638         IN  PVOID                   pTimerFunc,
3639         IN      PVOID                                   pData,
3640         IN  BOOLEAN                 Repeat);
3641
3642 VOID RTMPSetTimer(
3643         IN  PRALINK_TIMER_STRUCT    pTimer,
3644         IN  ULONG                   Value);
3645
3646
3647 VOID RTMPModTimer(
3648         IN      PRALINK_TIMER_STRUCT    pTimer,
3649         IN      ULONG                                   Value);
3650
3651 VOID RTMPCancelTimer(
3652         IN  PRALINK_TIMER_STRUCT    pTimer,
3653         OUT BOOLEAN                 *pCancelled);
3654
3655 VOID RTMPSetLED(
3656         IN PRTMP_ADAPTER        pAd,
3657         IN UCHAR                        Status);
3658
3659 VOID RTMPSetSignalLED(
3660         IN PRTMP_ADAPTER        pAd,
3661         IN NDIS_802_11_RSSI Dbm);
3662
3663 VOID RTMPEnableRxTx(
3664         IN PRTMP_ADAPTER        pAd);
3665
3666 //
3667 // prototype in action.c
3668 //
3669 VOID ActionStateMachineInit(
3670     IN  PRTMP_ADAPTER   pAd,
3671     IN  STATE_MACHINE *S,
3672     OUT STATE_MACHINE_FUNC Trans[]);
3673
3674 VOID MlmeADDBAAction(
3675     IN PRTMP_ADAPTER pAd,
3676     IN MLME_QUEUE_ELEM *Elem);
3677
3678 VOID MlmeDELBAAction(
3679     IN PRTMP_ADAPTER pAd,
3680     IN MLME_QUEUE_ELEM *Elem);
3681
3682 VOID MlmeDLSAction(
3683     IN PRTMP_ADAPTER pAd,
3684     IN MLME_QUEUE_ELEM *Elem);
3685
3686 VOID MlmeInvalidAction(
3687     IN PRTMP_ADAPTER pAd,
3688     IN MLME_QUEUE_ELEM *Elem);
3689
3690 VOID MlmeQOSAction(
3691     IN PRTMP_ADAPTER pAd,
3692     IN MLME_QUEUE_ELEM *Elem);
3693
3694 #ifdef DOT11_N_SUPPORT
3695 VOID PeerAddBAReqAction(
3696         IN PRTMP_ADAPTER pAd,
3697         IN MLME_QUEUE_ELEM *Elem);
3698
3699 VOID PeerAddBARspAction(
3700         IN PRTMP_ADAPTER pAd,
3701         IN MLME_QUEUE_ELEM *Elem);
3702
3703 VOID PeerDelBAAction(
3704         IN PRTMP_ADAPTER pAd,
3705         IN MLME_QUEUE_ELEM *Elem);
3706
3707 VOID PeerBAAction(
3708     IN PRTMP_ADAPTER pAd,
3709     IN MLME_QUEUE_ELEM *Elem);
3710 #endif // DOT11_N_SUPPORT //
3711
3712 VOID SendPSMPAction(
3713         IN PRTMP_ADAPTER        pAd,
3714         IN UCHAR                        Wcid,
3715         IN UCHAR                        Psmp);
3716
3717
3718 #ifdef DOT11N_DRAFT3
3719 VOID SendBSS2040CoexistMgmtAction(
3720         IN      PRTMP_ADAPTER   pAd,
3721         IN      UCHAR   Wcid,
3722         IN      UCHAR   apidx,
3723         IN      UCHAR   InfoReq);
3724
3725 VOID SendNotifyBWActionFrame(
3726         IN PRTMP_ADAPTER pAd,
3727         IN UCHAR  Wcid,
3728         IN UCHAR apidx);
3729
3730 BOOLEAN ChannelSwitchSanityCheck(
3731         IN      PRTMP_ADAPTER   pAd,
3732         IN    UCHAR  Wcid,
3733         IN    UCHAR  NewChannel,
3734         IN    UCHAR  Secondary);
3735
3736 VOID ChannelSwitchAction(
3737         IN      PRTMP_ADAPTER   pAd,
3738         IN    UCHAR  Wcid,
3739         IN    UCHAR  Channel,
3740         IN    UCHAR  Secondary);
3741
3742 ULONG BuildIntolerantChannelRep(
3743         IN      PRTMP_ADAPTER   pAd,
3744         IN    PUCHAR  pDest);
3745
3746 VOID Update2040CoexistFrameAndNotify(
3747         IN      PRTMP_ADAPTER   pAd,
3748         IN    UCHAR  Wcid,
3749         IN      BOOLEAN bAddIntolerantCha);
3750
3751 VOID Send2040CoexistAction(
3752         IN      PRTMP_ADAPTER   pAd,
3753         IN    UCHAR  Wcid,
3754         IN      BOOLEAN bAddIntolerantCha);
3755 #endif // DOT11N_DRAFT3 //
3756
3757 VOID PeerRMAction(
3758         IN PRTMP_ADAPTER pAd,
3759         IN MLME_QUEUE_ELEM *Elem);
3760
3761 VOID PeerPublicAction(
3762         IN PRTMP_ADAPTER pAd,
3763         IN MLME_QUEUE_ELEM *Elem);
3764
3765 #ifdef CONFIG_STA_SUPPORT
3766 VOID StaPublicAction(
3767         IN PRTMP_ADAPTER pAd,
3768         IN UCHAR Bss2040Coexist);
3769 #endif // CONFIG_STA_SUPPORT //
3770
3771
3772 VOID PeerBSSTranAction(
3773         IN PRTMP_ADAPTER pAd,
3774         IN MLME_QUEUE_ELEM *Elem);
3775
3776 #ifdef DOT11_N_SUPPORT
3777 VOID PeerHTAction(
3778         IN PRTMP_ADAPTER pAd,
3779         IN MLME_QUEUE_ELEM *Elem);
3780 #endif // DOT11_N_SUPPORT //
3781
3782 VOID PeerQOSAction(
3783     IN PRTMP_ADAPTER pAd,
3784     IN MLME_QUEUE_ELEM *Elem);
3785
3786 #ifdef QOS_DLS_SUPPORT
3787 VOID PeerDLSAction(
3788     IN PRTMP_ADAPTER pAd,
3789     IN MLME_QUEUE_ELEM *Elem);
3790 #endif // QOS_DLS_SUPPORT //
3791
3792 #ifdef CONFIG_STA_SUPPORT
3793 #ifdef QOS_DLS_SUPPORT
3794 VOID DlsParmFill(
3795         IN PRTMP_ADAPTER pAd,
3796         IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
3797         IN PRT_802_11_DLS pDls,
3798         IN USHORT reason);
3799 #endif // QOS_DLS_SUPPORT //
3800 #endif // CONFIG_STA_SUPPORT //
3801
3802 #ifdef DOT11_N_SUPPORT
3803 VOID RECBATimerTimeout(
3804     IN PVOID SystemSpecific1,
3805     IN PVOID FunctionContext,
3806     IN PVOID SystemSpecific2,
3807     IN PVOID SystemSpecific3);
3808
3809 VOID ORIBATimerTimeout(
3810         IN      PRTMP_ADAPTER   pAd);
3811
3812 VOID SendRefreshBAR(
3813         IN      PRTMP_ADAPTER   pAd,
3814         IN      MAC_TABLE_ENTRY *pEntry);
3815 #endif // DOT11_N_SUPPORT //
3816
3817 VOID ActHeaderInit(
3818     IN  PRTMP_ADAPTER   pAd,
3819     IN OUT PHEADER_802_11 pHdr80211,
3820     IN PUCHAR Addr1,
3821     IN PUCHAR Addr2,
3822     IN PUCHAR Addr3);
3823
3824 VOID BarHeaderInit(
3825         IN      PRTMP_ADAPTER   pAd,
3826         IN OUT PFRAME_BAR pCntlBar,
3827         IN PUCHAR pDA,
3828         IN PUCHAR pSA);
3829
3830 VOID InsertActField(
3831         IN PRTMP_ADAPTER pAd,
3832         OUT PUCHAR pFrameBuf,
3833         OUT PULONG pFrameLen,
3834         IN UINT8 Category,
3835         IN UINT8 ActCode);
3836
3837 BOOLEAN QosBADataParse(
3838         IN PRTMP_ADAPTER        pAd,
3839         IN BOOLEAN bAMSDU,
3840         IN PUCHAR p8023Header,
3841         IN UCHAR        WCID,
3842         IN UCHAR        TID,
3843         IN USHORT Sequence,
3844         IN UCHAR DataOffset,
3845         IN USHORT Datasize,
3846         IN UINT   CurRxIndex);
3847
3848 #ifdef DOT11_N_SUPPORT
3849 BOOLEAN CntlEnqueueForRecv(
3850     IN  PRTMP_ADAPTER   pAd,
3851         IN ULONG Wcid,
3852     IN ULONG MsgLen,
3853         IN PFRAME_BA_REQ pMsg);
3854
3855 VOID BaAutoManSwitch(
3856         IN      PRTMP_ADAPTER   pAd);
3857 #endif // DOT11_N_SUPPORT //
3858
3859 VOID HTIOTCheck(
3860         IN      PRTMP_ADAPTER   pAd,
3861         IN    UCHAR     BatRecIdx);
3862
3863 //
3864 // Private routines in rtmp_data.c
3865 //
3866 BOOLEAN RTMPHandleRxDoneInterrupt(
3867         IN  PRTMP_ADAPTER   pAd);
3868
3869 VOID RTMPHandleTxDoneInterrupt(
3870         IN  PRTMP_ADAPTER   pAd);
3871
3872 BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(
3873         IN  PRTMP_ADAPTER   pAd,
3874         IN  INT_SOURCE_CSR_STRUC TxRingBitmap);
3875
3876 VOID RTMPHandleMgmtRingDmaDoneInterrupt(
3877         IN  PRTMP_ADAPTER   pAd);
3878
3879 VOID RTMPHandleTBTTInterrupt(
3880         IN  PRTMP_ADAPTER   pAd);
3881
3882 VOID RTMPHandlePreTBTTInterrupt(
3883         IN  PRTMP_ADAPTER   pAd);
3884
3885 void RTMPHandleTwakeupInterrupt(
3886         IN PRTMP_ADAPTER pAd);
3887
3888 VOID    RTMPHandleRxCoherentInterrupt(
3889         IN      PRTMP_ADAPTER   pAd);
3890
3891 BOOLEAN TxFrameIsAggregatible(
3892         IN  PRTMP_ADAPTER   pAd,
3893         IN  PUCHAR          pPrevAddr1,
3894         IN  PUCHAR          p8023hdr);
3895
3896 BOOLEAN PeerIsAggreOn(
3897     IN  PRTMP_ADAPTER   pAd,
3898     IN  ULONG          TxRate,
3899     IN  PMAC_TABLE_ENTRY pMacEntry);
3900
3901 NDIS_STATUS Sniff2BytesFromNdisBuffer(
3902         IN  PNDIS_BUFFER    pFirstBuffer,
3903         IN  UCHAR           DesiredOffset,
3904         OUT PUCHAR          pByte0,
3905         OUT PUCHAR          pByte1);
3906
3907 NDIS_STATUS STASendPacket(
3908         IN  PRTMP_ADAPTER   pAd,
3909         IN  PNDIS_PACKET    pPacket);
3910
3911 VOID STASendPackets(
3912         IN  NDIS_HANDLE     MiniportAdapterContext,
3913         IN  PPNDIS_PACKET   ppPacketArray,
3914         IN  UINT            NumberOfPackets);
3915
3916 VOID RTMPDeQueuePacket(
3917         IN  PRTMP_ADAPTER   pAd,
3918         IN      BOOLEAN                 bIntContext,
3919         IN  UCHAR                       QueIdx,
3920         IN      UCHAR                   Max_Tx_Packets);
3921
3922 NDIS_STATUS     RTMPHardTransmit(
3923         IN PRTMP_ADAPTER        pAd,
3924         IN PNDIS_PACKET         pPacket,
3925         IN  UCHAR                       QueIdx,
3926         OUT     PULONG                  pFreeTXDLeft);
3927
3928 NDIS_STATUS     STAHardTransmit(
3929         IN PRTMP_ADAPTER        pAd,
3930         IN TX_BLK                       *pTxBlk,
3931         IN  UCHAR                       QueIdx);
3932
3933 VOID STARxEAPOLFrameIndicate(
3934         IN      PRTMP_ADAPTER   pAd,
3935         IN      MAC_TABLE_ENTRY *pEntry,
3936         IN      RX_BLK                  *pRxBlk,
3937         IN      UCHAR                   FromWhichBSSID);
3938
3939 NDIS_STATUS RTMPFreeTXDRequest(
3940         IN  PRTMP_ADAPTER   pAd,
3941         IN  UCHAR           RingType,
3942         IN  UCHAR           NumberRequired,
3943         IN      PUCHAR          FreeNumberIs);
3944
3945 NDIS_STATUS MlmeHardTransmit(
3946         IN  PRTMP_ADAPTER   pAd,
3947         IN  UCHAR       QueIdx,
3948         IN  PNDIS_PACKET    pPacket);
3949
3950 NDIS_STATUS MlmeHardTransmitMgmtRing(
3951         IN  PRTMP_ADAPTER   pAd,
3952         IN  UCHAR       QueIdx,
3953         IN  PNDIS_PACKET    pPacket);
3954
3955 NDIS_STATUS MlmeHardTransmitTxRing(
3956         IN  PRTMP_ADAPTER   pAd,
3957         IN  UCHAR       QueIdx,
3958         IN  PNDIS_PACKET    pPacket);
3959
3960 USHORT  RTMPCalcDuration(
3961         IN  PRTMP_ADAPTER   pAd,
3962         IN  UCHAR           Rate,
3963         IN  ULONG           Size);
3964
3965 VOID RTMPWriteTxWI(
3966         IN      PRTMP_ADAPTER   pAd,
3967         IN      PTXWI_STRUC             pTxWI,
3968         IN  BOOLEAN             FRAG,
3969         IN  BOOLEAN             CFACK,
3970         IN  BOOLEAN             InsTimestamp,
3971         IN      BOOLEAN                 AMPDU,
3972         IN      BOOLEAN                 Ack,
3973         IN      BOOLEAN                 NSeq,           // HW new a sequence.
3974         IN      UCHAR                   BASize,
3975         IN      UCHAR                   WCID,
3976         IN      ULONG                   Length,
3977         IN  UCHAR               PID,
3978         IN      UCHAR                   TID,
3979         IN      UCHAR                   TxRate,
3980         IN      UCHAR                   Txopmode,
3981         IN      BOOLEAN                 CfAck,
3982         IN      HTTRANSMIT_SETTING      *pTransmit);
3983
3984
3985 VOID RTMPWriteTxWI_Data(
3986         IN      PRTMP_ADAPTER           pAd,
3987         IN      OUT PTXWI_STRUC         pTxWI,
3988         IN      TX_BLK                          *pTxBlk);
3989
3990
3991 VOID RTMPWriteTxWI_Cache(
3992         IN      PRTMP_ADAPTER           pAd,
3993         IN      OUT PTXWI_STRUC         pTxWI,
3994         IN      TX_BLK                          *pTxBlk);
3995
3996 VOID RTMPWriteTxDescriptor(
3997         IN      PRTMP_ADAPTER   pAd,
3998         IN      PTXD_STRUC              pTxD,
3999         IN      BOOLEAN                 bWIV,
4000         IN      UCHAR                   QSEL);
4001
4002 VOID RTMPSuspendMsduTransmission(
4003         IN  PRTMP_ADAPTER   pAd);
4004
4005 VOID RTMPResumeMsduTransmission(
4006         IN  PRTMP_ADAPTER   pAd);
4007
4008 NDIS_STATUS MiniportMMRequest(
4009         IN  PRTMP_ADAPTER   pAd,
4010         IN      UCHAR                   QueIdx,
4011         IN      PUCHAR                  pData,
4012         IN  UINT            Length);
4013
4014 VOID RTMPSendNullFrame(
4015         IN  PRTMP_ADAPTER   pAd,
4016         IN  UCHAR           TxRate,
4017         IN      BOOLEAN                 bQosNull);
4018
4019 VOID RTMPSendDisassociationFrame(
4020         IN      PRTMP_ADAPTER   pAd);
4021
4022 VOID RTMPSendRTSFrame(
4023         IN  PRTMP_ADAPTER   pAd,
4024         IN  PUCHAR          pDA,
4025         IN      unsigned int    NextMpduSize,
4026         IN  UCHAR           TxRate,
4027         IN  UCHAR           RTSRate,
4028         IN  USHORT          AckDuration,
4029         IN  UCHAR           QueIdx,
4030         IN  UCHAR                       FrameGap);
4031
4032
4033 NDIS_STATUS RTMPApplyPacketFilter(
4034         IN  PRTMP_ADAPTER   pAd,
4035         IN  PRT28XX_RXD_STRUC      pRxD,
4036         IN  PHEADER_802_11  pHeader);
4037
4038 PQUEUE_HEADER   RTMPCheckTxSwQueue(
4039         IN  PRTMP_ADAPTER   pAd,
4040         OUT UCHAR           *QueIdx);
4041
4042 #ifdef CONFIG_STA_SUPPORT
4043 VOID RTMPReportMicError(
4044         IN  PRTMP_ADAPTER   pAd,
4045         IN  PCIPHER_KEY     pWpaKey);
4046
4047 VOID    WpaMicFailureReportFrame(
4048         IN  PRTMP_ADAPTER    pAd,
4049         IN  MLME_QUEUE_ELEM *Elem);
4050
4051 VOID    WpaDisassocApAndBlockAssoc(
4052     IN  PVOID SystemSpecific1,
4053     IN  PVOID FunctionContext,
4054     IN  PVOID SystemSpecific2,
4055     IN  PVOID SystemSpecific3);
4056 #endif // CONFIG_STA_SUPPORT //
4057
4058 NDIS_STATUS RTMPCloneNdisPacket(
4059         IN  PRTMP_ADAPTER   pAd,
4060         IN      BOOLEAN    pInsAMSDUHdr,
4061         IN  PNDIS_PACKET    pInPacket,
4062         OUT PNDIS_PACKET   *ppOutPacket);
4063
4064 NDIS_STATUS RTMPAllocateNdisPacket(
4065         IN  PRTMP_ADAPTER   pAd,
4066         IN  PNDIS_PACKET    *pPacket,
4067         IN  PUCHAR          pHeader,
4068         IN  UINT            HeaderLen,
4069         IN  PUCHAR          pData,
4070         IN  UINT            DataLen);
4071
4072 VOID RTMPFreeNdisPacket(
4073         IN  PRTMP_ADAPTER   pAd,
4074         IN  PNDIS_PACKET    pPacket);
4075
4076 BOOLEAN RTMPFreeTXDUponTxDmaDone(
4077         IN PRTMP_ADAPTER    pAd,
4078         IN UCHAR            QueIdx);
4079
4080 BOOLEAN RTMPCheckDHCPFrame(
4081         IN      PRTMP_ADAPTER   pAd,
4082         IN      PNDIS_PACKET    pPacket);
4083
4084
4085 BOOLEAN RTMPCheckEtherType(
4086         IN      PRTMP_ADAPTER   pAd,
4087         IN      PNDIS_PACKET    pPacket);
4088
4089
4090 VOID RTMPCckBbpTuning(
4091         IN      PRTMP_ADAPTER   pAd,
4092         IN      UINT                    TxRate);
4093
4094 //
4095 // Private routines in rtmp_wep.c
4096 //
4097 VOID RTMPInitWepEngine(
4098         IN  PRTMP_ADAPTER   pAd,
4099         IN  PUCHAR          pKey,
4100         IN  UCHAR           KeyId,
4101         IN  UCHAR           KeyLen,
4102         IN  PUCHAR          pDest);
4103
4104 VOID RTMPEncryptData(
4105         IN  PRTMP_ADAPTER   pAd,
4106         IN  PUCHAR          pSrc,
4107         IN  PUCHAR          pDest,
4108         IN  UINT            Len);
4109
4110 BOOLEAN RTMPDecryptData(
4111         IN      PRTMP_ADAPTER   pAdapter,
4112         IN      PUCHAR                  pSrc,
4113         IN      UINT                    Len,
4114         IN      UINT                    idx);
4115
4116 BOOLEAN RTMPSoftDecryptWEP(
4117         IN PRTMP_ADAPTER        pAd,
4118         IN PUCHAR                       pData,
4119         IN ULONG                        DataByteCnt,
4120         IN PCIPHER_KEY          pGroupKey);
4121
4122 VOID RTMPSetICV(
4123         IN  PRTMP_ADAPTER   pAd,
4124         IN  PUCHAR          pDest);
4125
4126 VOID ARCFOUR_INIT(
4127         IN  PARCFOURCONTEXT Ctx,
4128         IN  PUCHAR          pKey,
4129         IN  UINT            KeyLen);
4130
4131 UCHAR   ARCFOUR_BYTE(
4132         IN  PARCFOURCONTEXT     Ctx);
4133
4134 VOID ARCFOUR_DECRYPT(
4135         IN  PARCFOURCONTEXT Ctx,
4136         IN  PUCHAR          pDest,
4137         IN  PUCHAR          pSrc,
4138         IN  UINT            Len);
4139
4140 VOID ARCFOUR_ENCRYPT(
4141         IN  PARCFOURCONTEXT Ctx,
4142         IN  PUCHAR          pDest,
4143         IN  PUCHAR          pSrc,
4144         IN  UINT            Len);
4145
4146 VOID WPAARCFOUR_ENCRYPT(
4147         IN  PARCFOURCONTEXT Ctx,
4148         IN  PUCHAR          pDest,
4149         IN  PUCHAR          pSrc,
4150         IN  UINT            Len);
4151
4152 UINT RTMP_CALC_FCS32(
4153         IN  UINT   Fcs,
4154         IN  PUCHAR  Cp,
4155         IN  INT     Len);
4156
4157 //
4158 // MLME routines
4159 //
4160
4161 // Asic/RF/BBP related functions
4162
4163 VOID AsicAdjustTxPower(
4164         IN PRTMP_ADAPTER pAd);
4165
4166 VOID    AsicUpdateProtect(
4167         IN              PRTMP_ADAPTER   pAd,
4168         IN              USHORT                  OperaionMode,
4169         IN              UCHAR                   SetMask,
4170         IN              BOOLEAN                 bDisableBGProtect,
4171         IN              BOOLEAN                 bNonGFExist);
4172
4173 VOID AsicSwitchChannel(
4174         IN  PRTMP_ADAPTER   pAd,
4175         IN      UCHAR                   Channel,
4176         IN      BOOLEAN                 bScan);
4177
4178 VOID AsicLockChannel(
4179         IN PRTMP_ADAPTER pAd,
4180         IN UCHAR Channel) ;
4181
4182 VOID AsicAntennaSelect(
4183         IN  PRTMP_ADAPTER   pAd,
4184         IN  UCHAR           Channel);
4185
4186 VOID AsicAntennaSetting(
4187         IN      PRTMP_ADAPTER   pAd,
4188         IN      ABGBAND_STATE   BandState);
4189
4190 VOID AsicRfTuningExec(
4191         IN PVOID SystemSpecific1,
4192         IN PVOID FunctionContext,
4193         IN PVOID SystemSpecific2,
4194         IN PVOID SystemSpecific3);
4195
4196 #ifdef CONFIG_STA_SUPPORT
4197 VOID AsicSleepThenAutoWakeup(
4198         IN  PRTMP_ADAPTER   pAd,
4199         IN  USHORT TbttNumToNextWakeUp);
4200
4201 VOID AsicForceSleep(
4202         IN PRTMP_ADAPTER pAd);
4203
4204 VOID AsicForceWakeup(
4205         IN PRTMP_ADAPTER pAd,
4206         IN UCHAR         Level);
4207 #endif // CONFIG_STA_SUPPORT //
4208
4209 VOID AsicSetBssid(
4210         IN  PRTMP_ADAPTER   pAd,
4211         IN  PUCHAR pBssid);
4212
4213 VOID AsicSetMcastWC(
4214         IN PRTMP_ADAPTER pAd);
4215
4216 VOID AsicDelWcidTab(
4217         IN PRTMP_ADAPTER pAd,
4218         IN UCHAR        Wcid);
4219
4220 VOID AsicEnableRDG(
4221         IN PRTMP_ADAPTER pAd);
4222
4223 VOID AsicDisableRDG(
4224         IN PRTMP_ADAPTER pAd);
4225
4226 VOID AsicDisableSync(
4227         IN  PRTMP_ADAPTER   pAd);
4228
4229 VOID AsicEnableBssSync(
4230         IN  PRTMP_ADAPTER   pAd);
4231
4232 VOID AsicEnableIbssSync(
4233         IN  PRTMP_ADAPTER   pAd);
4234
4235 VOID AsicSetEdcaParm(
4236         IN PRTMP_ADAPTER pAd,
4237         IN PEDCA_PARM    pEdcaParm);
4238
4239 VOID AsicSetSlotTime(
4240         IN PRTMP_ADAPTER pAd,
4241         IN BOOLEAN bUseShortSlotTime);
4242
4243 VOID AsicAddSharedKeyEntry(
4244         IN PRTMP_ADAPTER pAd,
4245         IN UCHAR         BssIndex,
4246         IN UCHAR         KeyIdx,
4247         IN UCHAR         CipherAlg,
4248         IN PUCHAR        pKey,
4249         IN PUCHAR        pTxMic,
4250         IN PUCHAR        pRxMic);
4251
4252 VOID AsicRemoveSharedKeyEntry(
4253         IN PRTMP_ADAPTER pAd,
4254         IN UCHAR         BssIndex,
4255         IN UCHAR         KeyIdx);
4256
4257 VOID AsicUpdateWCIDAttribute(
4258         IN PRTMP_ADAPTER pAd,
4259         IN USHORT               WCID,
4260         IN UCHAR                BssIndex,
4261         IN UCHAR        CipherAlg,
4262         IN BOOLEAN              bUsePairewiseKeyTable);
4263
4264 VOID AsicUpdateWCIDIVEIV(
4265         IN PRTMP_ADAPTER pAd,
4266         IN USHORT               WCID,
4267         IN ULONG        uIV,
4268         IN ULONG        uEIV);
4269
4270 VOID AsicUpdateRxWCIDTable(
4271         IN PRTMP_ADAPTER pAd,
4272         IN USHORT               WCID,
4273         IN PUCHAR        pAddr);
4274
4275 VOID AsicAddKeyEntry(
4276         IN PRTMP_ADAPTER pAd,
4277         IN USHORT               WCID,
4278         IN UCHAR                BssIndex,
4279         IN UCHAR                KeyIdx,
4280         IN PCIPHER_KEY  pCipherKey,
4281         IN BOOLEAN              bUsePairewiseKeyTable,
4282         IN BOOLEAN              bTxKey);
4283
4284 VOID AsicAddPairwiseKeyEntry(
4285         IN PRTMP_ADAPTER pAd,
4286         IN PUCHAR        pAddr,
4287         IN UCHAR                WCID,
4288         IN CIPHER_KEY            *pCipherKey);
4289
4290 VOID AsicRemovePairwiseKeyEntry(
4291         IN PRTMP_ADAPTER  pAd,
4292         IN UCHAR                 BssIdx,
4293         IN UCHAR                 Wcid);
4294
4295 BOOLEAN AsicSendCommandToMcu(
4296         IN PRTMP_ADAPTER pAd,
4297         IN UCHAR         Command,
4298         IN UCHAR         Token,
4299         IN UCHAR         Arg0,
4300         IN UCHAR         Arg1);
4301
4302 BOOLEAN AsicCheckCommanOk(
4303         IN PRTMP_ADAPTER pAd,
4304         IN UCHAR                 Command);
4305
4306 VOID MacAddrRandomBssid(
4307         IN  PRTMP_ADAPTER   pAd,
4308         OUT PUCHAR pAddr);
4309
4310 VOID MgtMacHeaderInit(
4311         IN  PRTMP_ADAPTER     pAd,
4312         IN OUT PHEADER_802_11 pHdr80211,
4313         IN UCHAR SubType,
4314         IN UCHAR ToDs,
4315         IN PUCHAR pDA,
4316         IN PUCHAR pBssid);
4317
4318 VOID MlmeRadioOff(
4319         IN PRTMP_ADAPTER pAd);
4320
4321 VOID MlmeRadioOn(
4322         IN PRTMP_ADAPTER pAd);
4323
4324
4325 VOID BssTableInit(
4326         IN BSS_TABLE *Tab);
4327
4328 #ifdef DOT11_N_SUPPORT
4329 VOID BATableInit(
4330         IN PRTMP_ADAPTER pAd,
4331     IN BA_TABLE *Tab);
4332 #endif // DOT11_N_SUPPORT //
4333
4334 ULONG BssTableSearch(
4335         IN BSS_TABLE *Tab,
4336         IN PUCHAR pBssid,
4337         IN UCHAR Channel);
4338
4339 ULONG BssSsidTableSearch(
4340         IN BSS_TABLE *Tab,
4341         IN PUCHAR    pBssid,
4342         IN PUCHAR    pSsid,
4343         IN UCHAR     SsidLen,
4344         IN UCHAR     Channel);
4345
4346 ULONG BssTableSearchWithSSID(
4347         IN BSS_TABLE *Tab,
4348         IN PUCHAR    Bssid,
4349         IN PUCHAR    pSsid,
4350         IN UCHAR     SsidLen,
4351         IN UCHAR     Channel);
4352
4353 VOID BssTableDeleteEntry(
4354         IN OUT  PBSS_TABLE pTab,
4355         IN      PUCHAR pBssid,
4356         IN      UCHAR Channel);
4357
4358 #ifdef DOT11_N_SUPPORT
4359 VOID BATableDeleteORIEntry(
4360         IN OUT  PRTMP_ADAPTER pAd,
4361         IN              BA_ORI_ENTRY    *pBAORIEntry);
4362
4363 VOID BATableDeleteRECEntry(
4364         IN OUT  PRTMP_ADAPTER pAd,
4365         IN              BA_REC_ENTRY    *pBARECEntry);
4366
4367 VOID BATableTearORIEntry(
4368         IN OUT  PRTMP_ADAPTER pAd,
4369         IN              UCHAR TID,
4370         IN              UCHAR Wcid,
4371         IN              BOOLEAN bForceDelete,
4372         IN              BOOLEAN ALL);
4373
4374 VOID BATableTearRECEntry(
4375         IN OUT  PRTMP_ADAPTER pAd,
4376         IN              UCHAR TID,
4377         IN              UCHAR WCID,
4378         IN              BOOLEAN ALL);
4379 #endif // DOT11_N_SUPPORT //
4380
4381 VOID  BssEntrySet(
4382         IN  PRTMP_ADAPTER   pAd,
4383         OUT PBSS_ENTRY pBss,
4384         IN PUCHAR pBssid,
4385         IN CHAR Ssid[],
4386         IN UCHAR SsidLen,
4387         IN UCHAR BssType,
4388         IN USHORT BeaconPeriod,
4389         IN PCF_PARM CfParm,
4390         IN USHORT AtimWin,
4391         IN USHORT CapabilityInfo,
4392         IN UCHAR SupRate[],
4393         IN UCHAR SupRateLen,
4394         IN UCHAR ExtRate[],
4395         IN UCHAR ExtRateLen,
4396         IN HT_CAPABILITY_IE *pHtCapability,
4397         IN ADD_HT_INFO_IE *pAddHtInfo,  // AP might use this additional ht info IE
4398         IN UCHAR                        HtCapabilityLen,
4399         IN UCHAR                        AddHtInfoLen,
4400         IN UCHAR                        NewExtChanOffset,
4401         IN UCHAR Channel,
4402         IN CHAR Rssi,
4403         IN LARGE_INTEGER TimeStamp,
4404         IN UCHAR CkipFlag,
4405         IN PEDCA_PARM pEdcaParm,
4406         IN PQOS_CAPABILITY_PARM pQosCapability,
4407         IN PQBSS_LOAD_PARM pQbssLoad,
4408         IN USHORT LengthVIE,
4409         IN PNDIS_802_11_VARIABLE_IEs pVIE);
4410
4411 ULONG  BssTableSetEntry(
4412         IN  PRTMP_ADAPTER   pAd,
4413         OUT PBSS_TABLE pTab,
4414         IN PUCHAR pBssid,
4415         IN CHAR Ssid[],
4416         IN UCHAR SsidLen,
4417         IN UCHAR BssType,
4418         IN USHORT BeaconPeriod,
4419         IN CF_PARM *CfParm,
4420         IN USHORT AtimWin,
4421         IN USHORT CapabilityInfo,
4422         IN UCHAR SupRate[],
4423         IN UCHAR SupRateLen,
4424         IN UCHAR ExtRate[],
4425         IN UCHAR ExtRateLen,
4426         IN HT_CAPABILITY_IE *pHtCapability,
4427         IN ADD_HT_INFO_IE *pAddHtInfo,  // AP might use this additional ht info IE
4428         IN UCHAR                        HtCapabilityLen,
4429         IN UCHAR                        AddHtInfoLen,
4430         IN UCHAR                        NewExtChanOffset,
4431         IN UCHAR Channel,
4432         IN CHAR Rssi,
4433         IN LARGE_INTEGER TimeStamp,
4434         IN UCHAR CkipFlag,
4435         IN PEDCA_PARM pEdcaParm,
4436         IN PQOS_CAPABILITY_PARM pQosCapability,
4437         IN PQBSS_LOAD_PARM pQbssLoad,
4438         IN USHORT LengthVIE,
4439         IN PNDIS_802_11_VARIABLE_IEs pVIE);
4440
4441 #ifdef DOT11_N_SUPPORT
4442 VOID BATableInsertEntry(
4443     IN  PRTMP_ADAPTER   pAd,
4444         IN USHORT Aid,
4445     IN USHORT           TimeOutValue,
4446         IN USHORT               StartingSeq,
4447     IN UCHAR TID,
4448         IN UCHAR BAWinSize,
4449         IN UCHAR OriginatorStatus,
4450     IN BOOLEAN IsRecipient);
4451
4452 #ifdef DOT11N_DRAFT3
4453 VOID Bss2040CoexistTimeOut(
4454         IN PVOID SystemSpecific1,
4455         IN PVOID FunctionContext,
4456         IN PVOID SystemSpecific2,
4457         IN PVOID SystemSpecific3);
4458
4459
4460 VOID  TriEventInit(
4461         IN      PRTMP_ADAPTER   pAd);
4462
4463 ULONG TriEventTableSetEntry(
4464         IN      PRTMP_ADAPTER   pAd,
4465         OUT TRIGGER_EVENT_TAB *Tab,
4466         IN PUCHAR pBssid,
4467         IN HT_CAPABILITY_IE *pHtCapability,
4468         IN UCHAR                        HtCapabilityLen,
4469         IN UCHAR                        RegClass,
4470         IN UCHAR ChannelNo);
4471
4472 VOID TriEventCounterMaintenance(
4473         IN      PRTMP_ADAPTER   pAd);
4474 #endif // DOT11N_DRAFT3 //
4475 #endif // DOT11_N_SUPPORT //
4476
4477 VOID BssTableSsidSort(
4478         IN  PRTMP_ADAPTER   pAd,
4479         OUT BSS_TABLE *OutTab,
4480         IN  CHAR Ssid[],
4481         IN  UCHAR SsidLen);
4482
4483 VOID  BssTableSortByRssi(
4484         IN OUT BSS_TABLE *OutTab);
4485
4486 VOID BssCipherParse(
4487         IN OUT  PBSS_ENTRY  pBss);
4488
4489 NDIS_STATUS  MlmeQueueInit(
4490         IN MLME_QUEUE *Queue);
4491
4492 VOID  MlmeQueueDestroy(
4493         IN MLME_QUEUE *Queue);
4494
4495 BOOLEAN MlmeEnqueue(
4496         IN PRTMP_ADAPTER pAd,
4497         IN ULONG Machine,
4498         IN ULONG MsgType,
4499         IN ULONG MsgLen,
4500         IN VOID *Msg);
4501
4502 BOOLEAN MlmeEnqueueForRecv(
4503         IN  PRTMP_ADAPTER   pAd,
4504         IN ULONG Wcid,
4505         IN ULONG TimeStampHigh,
4506         IN ULONG TimeStampLow,
4507         IN UCHAR Rssi0,
4508         IN UCHAR Rssi1,
4509         IN UCHAR Rssi2,
4510         IN ULONG MsgLen,
4511         IN PVOID Msg,
4512         IN UCHAR Signal);
4513
4514
4515 BOOLEAN MlmeDequeue(
4516         IN MLME_QUEUE *Queue,
4517         OUT MLME_QUEUE_ELEM **Elem);
4518
4519 VOID    MlmeRestartStateMachine(
4520         IN  PRTMP_ADAPTER   pAd);
4521
4522 BOOLEAN  MlmeQueueEmpty(
4523         IN MLME_QUEUE *Queue);
4524
4525 BOOLEAN  MlmeQueueFull(
4526         IN MLME_QUEUE *Queue);
4527
4528 BOOLEAN  MsgTypeSubst(
4529         IN PRTMP_ADAPTER pAd,
4530         IN PFRAME_802_11 pFrame,
4531         OUT INT *Machine,
4532         OUT INT *MsgType);
4533
4534 VOID StateMachineInit(
4535         IN STATE_MACHINE *Sm,
4536         IN STATE_MACHINE_FUNC Trans[],
4537         IN ULONG StNr,
4538         IN ULONG MsgNr,
4539         IN STATE_MACHINE_FUNC DefFunc,
4540         IN ULONG InitState,
4541         IN ULONG Base);
4542
4543 VOID StateMachineSetAction(
4544         IN STATE_MACHINE *S,
4545         IN ULONG St,
4546         ULONG Msg,
4547         IN STATE_MACHINE_FUNC F);
4548
4549 VOID StateMachinePerformAction(
4550         IN  PRTMP_ADAPTER   pAd,
4551         IN STATE_MACHINE *S,
4552         IN MLME_QUEUE_ELEM *Elem);
4553
4554 VOID Drop(
4555         IN  PRTMP_ADAPTER   pAd,
4556         IN MLME_QUEUE_ELEM *Elem);
4557
4558 VOID AssocStateMachineInit(
4559         IN  PRTMP_ADAPTER   pAd,
4560         IN  STATE_MACHINE *Sm,
4561         OUT STATE_MACHINE_FUNC Trans[]);
4562
4563 VOID ReassocTimeout(
4564         IN PVOID SystemSpecific1,
4565         IN PVOID FunctionContext,
4566         IN PVOID SystemSpecific2,
4567         IN PVOID SystemSpecific3);
4568
4569 VOID AssocTimeout(
4570         IN PVOID SystemSpecific1,
4571         IN PVOID FunctionContext,
4572         IN PVOID SystemSpecific2,
4573         IN PVOID SystemSpecific3);
4574
4575 VOID DisassocTimeout(
4576         IN PVOID SystemSpecific1,
4577         IN PVOID FunctionContext,
4578         IN PVOID SystemSpecific2,
4579         IN PVOID SystemSpecific3);
4580
4581 //----------------------------------------------
4582 VOID MlmeDisassocReqAction(
4583         IN  PRTMP_ADAPTER   pAd,
4584         IN  MLME_QUEUE_ELEM *Elem);
4585
4586 VOID MlmeAssocReqAction(
4587         IN  PRTMP_ADAPTER   pAd,
4588         IN  MLME_QUEUE_ELEM *Elem);
4589
4590 VOID MlmeReassocReqAction(
4591         IN  PRTMP_ADAPTER   pAd,
4592         IN  MLME_QUEUE_ELEM *Elem);
4593
4594 VOID MlmeDisassocReqAction(
4595         IN  PRTMP_ADAPTER   pAd,
4596         IN  MLME_QUEUE_ELEM *Elem);
4597
4598 VOID PeerAssocRspAction(
4599         IN  PRTMP_ADAPTER   pAd,
4600         IN  MLME_QUEUE_ELEM *Elem);
4601
4602 VOID PeerReassocRspAction(
4603         IN  PRTMP_ADAPTER   pAd,
4604         IN  MLME_QUEUE_ELEM *Elem);
4605
4606 VOID PeerDisassocAction(
4607         IN  PRTMP_ADAPTER   pAd,
4608         IN  MLME_QUEUE_ELEM *Elem);
4609
4610 VOID DisassocTimeoutAction(
4611         IN  PRTMP_ADAPTER   pAd,
4612         IN  MLME_QUEUE_ELEM *Elem);
4613
4614 VOID AssocTimeoutAction(
4615         IN  PRTMP_ADAPTER   pAd,
4616         IN  MLME_QUEUE_ELEM *Elem);
4617
4618 VOID  ReassocTimeoutAction(
4619         IN  PRTMP_ADAPTER   pAd,
4620         IN  MLME_QUEUE_ELEM *Elem);
4621
4622 VOID  Cls3errAction(
4623         IN  PRTMP_ADAPTER   pAd,
4624         IN  PUCHAR pAddr);
4625
4626 VOID SwitchBetweenWepAndCkip(
4627         IN PRTMP_ADAPTER pAd);
4628
4629 VOID  InvalidStateWhenAssoc(
4630         IN  PRTMP_ADAPTER   pAd,
4631         IN  MLME_QUEUE_ELEM *Elem);
4632
4633 VOID  InvalidStateWhenReassoc(
4634         IN  PRTMP_ADAPTER   pAd,
4635         IN  MLME_QUEUE_ELEM *Elem);
4636
4637 VOID InvalidStateWhenDisassociate(
4638         IN  PRTMP_ADAPTER pAd,
4639         IN  MLME_QUEUE_ELEM *Elem);
4640
4641
4642 VOID  ComposePsPoll(
4643         IN  PRTMP_ADAPTER   pAd);
4644
4645 VOID  ComposeNullFrame(
4646         IN  PRTMP_ADAPTER pAd);
4647
4648 VOID  AssocPostProc(
4649         IN  PRTMP_ADAPTER   pAd,
4650         IN  PUCHAR pAddr2,
4651         IN  USHORT CapabilityInfo,
4652         IN  USHORT Aid,
4653         IN  UCHAR SupRate[],
4654         IN  UCHAR SupRateLen,
4655         IN  UCHAR ExtRate[],
4656         IN  UCHAR ExtRateLen,
4657         IN PEDCA_PARM pEdcaParm,
4658         IN HT_CAPABILITY_IE             *pHtCapability,
4659         IN  UCHAR HtCapabilityLen,
4660         IN ADD_HT_INFO_IE               *pAddHtInfo);
4661
4662 VOID AuthStateMachineInit(
4663         IN  PRTMP_ADAPTER   pAd,
4664         IN PSTATE_MACHINE sm,
4665         OUT STATE_MACHINE_FUNC Trans[]);
4666
4667 VOID AuthTimeout(
4668         IN PVOID SystemSpecific1,
4669         IN PVOID FunctionContext,
4670         IN PVOID SystemSpecific2,
4671         IN PVOID SystemSpecific3);
4672
4673 VOID MlmeAuthReqAction(
4674         IN  PRTMP_ADAPTER   pAd,
4675         IN  MLME_QUEUE_ELEM *Elem);
4676
4677 VOID PeerAuthRspAtSeq2Action(
4678         IN  PRTMP_ADAPTER   pAd,
4679         IN  MLME_QUEUE_ELEM *Elem);
4680
4681 VOID PeerAuthRspAtSeq4Action(
4682         IN  PRTMP_ADAPTER   pAd,
4683         IN  MLME_QUEUE_ELEM *Elem);
4684
4685 VOID AuthTimeoutAction(
4686         IN  PRTMP_ADAPTER   pAd,
4687         IN  MLME_QUEUE_ELEM *Elem);
4688
4689 VOID Cls2errAction(
4690         IN  PRTMP_ADAPTER   pAd,
4691         IN  PUCHAR pAddr);
4692
4693 VOID MlmeDeauthReqAction(
4694         IN  PRTMP_ADAPTER   pAd,
4695         IN  MLME_QUEUE_ELEM *Elem);
4696
4697 VOID InvalidStateWhenAuth(
4698         IN  PRTMP_ADAPTER   pAd,
4699         IN  MLME_QUEUE_ELEM *Elem);
4700
4701 //=============================================
4702
4703 VOID AuthRspStateMachineInit(
4704         IN  PRTMP_ADAPTER   pAd,
4705         IN  PSTATE_MACHINE Sm,
4706         IN  STATE_MACHINE_FUNC Trans[]);
4707
4708 VOID PeerDeauthAction(
4709         IN PRTMP_ADAPTER pAd,
4710         IN MLME_QUEUE_ELEM *Elem);
4711
4712 VOID PeerAuthSimpleRspGenAndSend(
4713         IN  PRTMP_ADAPTER   pAd,
4714         IN  PHEADER_802_11  pHdr80211,
4715         IN  USHORT Alg,
4716         IN  USHORT Seq,
4717         IN  USHORT Reason,
4718         IN  USHORT Status);
4719
4720 //
4721 // Private routines in dls.c
4722 //
4723
4724 #ifdef CONFIG_STA_SUPPORT
4725 #ifdef QOS_DLS_SUPPORT
4726 void DlsStateMachineInit(
4727     IN PRTMP_ADAPTER pAd,
4728     IN STATE_MACHINE *Sm,
4729     OUT STATE_MACHINE_FUNC Trans[]);
4730
4731 VOID MlmeDlsReqAction(
4732     IN PRTMP_ADAPTER pAd,
4733     IN MLME_QUEUE_ELEM *Elem);
4734
4735 VOID PeerDlsReqAction(
4736     IN PRTMP_ADAPTER    pAd,
4737     IN MLME_QUEUE_ELEM  *Elem);
4738
4739 VOID PeerDlsRspAction(
4740     IN PRTMP_ADAPTER    pAd,
4741     IN MLME_QUEUE_ELEM  *Elem);
4742
4743 VOID MlmeDlsTearDownAction(
4744     IN PRTMP_ADAPTER pAd,
4745     IN MLME_QUEUE_ELEM *Elem);
4746
4747 VOID PeerDlsTearDownAction(
4748     IN PRTMP_ADAPTER    pAd,
4749     IN MLME_QUEUE_ELEM  *Elem);
4750
4751 VOID RTMPCheckDLSTimeOut(
4752         IN PRTMP_ADAPTER        pAd);
4753
4754 BOOLEAN RTMPRcvFrameDLSCheck(
4755         IN PRTMP_ADAPTER        pAd,
4756         IN PHEADER_802_11       pHeader,
4757         IN ULONG                        Len,
4758         IN PRT28XX_RXD_STRUC    pRxD);
4759
4760 INT     RTMPCheckDLSFrame(
4761         IN      PRTMP_ADAPTER   pAd,
4762         IN  PUCHAR          pDA);
4763
4764 VOID RTMPSendDLSTearDownFrame(
4765         IN      PRTMP_ADAPTER   pAd,
4766         IN  PUCHAR          pDA);
4767
4768 NDIS_STATUS RTMPSendSTAKeyRequest(
4769         IN      PRTMP_ADAPTER   pAd,
4770         IN      PUCHAR                  pDA);
4771
4772 NDIS_STATUS RTMPSendSTAKeyHandShake(
4773         IN      PRTMP_ADAPTER   pAd,
4774         IN      PUCHAR                  pDA);
4775
4776 VOID DlsTimeoutAction(
4777         IN PVOID SystemSpecific1,
4778         IN PVOID FunctionContext,
4779         IN PVOID SystemSpecific2,
4780         IN PVOID SystemSpecific3);
4781
4782 BOOLEAN MlmeDlsReqSanity(
4783         IN PRTMP_ADAPTER pAd,
4784     IN VOID *Msg,
4785     IN ULONG MsgLen,
4786     OUT PRT_802_11_DLS *pDLS,
4787     OUT PUSHORT pReason);
4788
4789 INT Set_DlsEntryInfo_Display_Proc(
4790         IN PRTMP_ADAPTER pAd,
4791         IN PUCHAR arg);
4792
4793 MAC_TABLE_ENTRY *MacTableInsertDlsEntry(
4794         IN  PRTMP_ADAPTER   pAd,
4795         IN  PUCHAR      pAddr,
4796         IN  UINT        DlsEntryIdx);
4797
4798 BOOLEAN MacTableDeleteDlsEntry(
4799         IN PRTMP_ADAPTER pAd,
4800         IN USHORT wcid,
4801         IN PUCHAR pAddr);
4802
4803 MAC_TABLE_ENTRY *DlsEntryTableLookup(
4804         IN PRTMP_ADAPTER pAd,
4805         IN PUCHAR       pAddr,
4806         IN BOOLEAN      bResetIdelCount);
4807
4808 MAC_TABLE_ENTRY *DlsEntryTableLookupByWcid(
4809         IN PRTMP_ADAPTER pAd,
4810         IN UCHAR        wcid,
4811         IN PUCHAR       pAddr,
4812         IN BOOLEAN      bResetIdelCount);
4813
4814 INT     Set_DlsAddEntry_Proc(
4815         IN      PRTMP_ADAPTER   pAd,
4816         IN      PUCHAR                  arg);
4817
4818 INT     Set_DlsTearDownEntry_Proc(
4819         IN      PRTMP_ADAPTER   pAd,
4820         IN      PUCHAR                  arg);
4821 #endif // QOS_DLS_SUPPORT //
4822 #endif // CONFIG_STA_SUPPORT //
4823
4824 #ifdef QOS_DLS_SUPPORT
4825 BOOLEAN PeerDlsReqSanity(
4826     IN PRTMP_ADAPTER pAd,
4827     IN VOID *Msg,
4828     IN ULONG MsgLen,
4829     OUT PUCHAR pDA,
4830     OUT PUCHAR pSA,
4831     OUT USHORT *pCapabilityInfo,
4832     OUT USHORT *pDlsTimeout,
4833     OUT UCHAR *pRatesLen,
4834     OUT UCHAR Rates[],
4835     OUT UCHAR *pHtCapabilityLen,
4836     OUT HT_CAPABILITY_IE *pHtCapability);
4837
4838 BOOLEAN PeerDlsRspSanity(
4839     IN PRTMP_ADAPTER pAd,
4840     IN VOID *Msg,
4841     IN ULONG MsgLen,
4842     OUT PUCHAR pDA,
4843     OUT PUCHAR pSA,
4844     OUT USHORT *pCapabilityInfo,
4845     OUT USHORT *pStatus,
4846     OUT UCHAR *pRatesLen,
4847     OUT UCHAR Rates[],
4848     OUT UCHAR *pHtCapabilityLen,
4849     OUT HT_CAPABILITY_IE *pHtCapability);
4850
4851 BOOLEAN PeerDlsTearDownSanity(
4852     IN PRTMP_ADAPTER pAd,
4853     IN VOID *Msg,
4854     IN ULONG MsgLen,
4855     OUT PUCHAR pDA,
4856     OUT PUCHAR pSA,
4857     OUT USHORT *pReason);
4858 #endif // QOS_DLS_SUPPORT //
4859
4860 //========================================
4861
4862 VOID SyncStateMachineInit(
4863         IN  PRTMP_ADAPTER   pAd,
4864         IN  STATE_MACHINE *Sm,
4865         OUT STATE_MACHINE_FUNC Trans[]);
4866
4867 VOID BeaconTimeout(
4868         IN PVOID SystemSpecific1,
4869         IN PVOID FunctionContext,
4870         IN PVOID SystemSpecific2,
4871         IN PVOID SystemSpecific3);
4872
4873 VOID ScanTimeout(
4874         IN PVOID SystemSpecific1,
4875         IN PVOID FunctionContext,
4876         IN PVOID SystemSpecific2,
4877         IN PVOID SystemSpecific3);
4878
4879 VOID MlmeScanReqAction(
4880         IN  PRTMP_ADAPTER   pAd,
4881         IN  MLME_QUEUE_ELEM *Elem);
4882
4883 VOID InvalidStateWhenScan(
4884         IN  PRTMP_ADAPTER   pAd,
4885         IN  MLME_QUEUE_ELEM *Elem);
4886
4887 VOID InvalidStateWhenJoin(
4888         IN  PRTMP_ADAPTER   pAd,
4889         IN  MLME_QUEUE_ELEM *Elem);
4890
4891 VOID InvalidStateWhenStart(
4892         IN  PRTMP_ADAPTER   pAd,
4893         IN  MLME_QUEUE_ELEM *Elem);
4894
4895 VOID PeerBeacon(
4896         IN  PRTMP_ADAPTER   pAd,
4897         IN  MLME_QUEUE_ELEM *Elem);
4898
4899 VOID EnqueueProbeRequest(
4900         IN PRTMP_ADAPTER pAd);
4901
4902 BOOLEAN ScanRunning(
4903                 IN PRTMP_ADAPTER pAd);
4904 //=========================================
4905
4906 VOID MlmeCntlInit(
4907         IN  PRTMP_ADAPTER   pAd,
4908         IN  STATE_MACHINE *S,
4909         OUT STATE_MACHINE_FUNC Trans[]);
4910
4911 VOID MlmeCntlMachinePerformAction(
4912         IN  PRTMP_ADAPTER   pAd,
4913         IN  STATE_MACHINE *S,
4914         IN  MLME_QUEUE_ELEM *Elem);
4915
4916 VOID CntlIdleProc(
4917         IN  PRTMP_ADAPTER   pAd,
4918         IN  MLME_QUEUE_ELEM *Elem);
4919
4920 VOID CntlOidScanProc(
4921         IN  PRTMP_ADAPTER pAd,
4922         IN  MLME_QUEUE_ELEM *Elem);
4923
4924 VOID CntlOidSsidProc(
4925         IN  PRTMP_ADAPTER   pAd,
4926         IN  MLME_QUEUE_ELEM * Elem);
4927
4928 VOID CntlOidRTBssidProc(
4929         IN  PRTMP_ADAPTER   pAd,
4930         IN  MLME_QUEUE_ELEM * Elem);
4931
4932 VOID CntlMlmeRoamingProc(
4933         IN  PRTMP_ADAPTER   pAd,
4934         IN  MLME_QUEUE_ELEM * Elem);
4935
4936 VOID CntlWaitDisassocProc(
4937         IN  PRTMP_ADAPTER   pAd,
4938         IN  MLME_QUEUE_ELEM *Elem);
4939
4940 VOID CntlWaitJoinProc(
4941         IN  PRTMP_ADAPTER   pAd,
4942         IN  MLME_QUEUE_ELEM *Elem);
4943
4944 VOID CntlWaitReassocProc(
4945         IN  PRTMP_ADAPTER   pAd,
4946         IN  MLME_QUEUE_ELEM *Elem);
4947
4948 VOID CntlWaitStartProc(
4949         IN  PRTMP_ADAPTER   pAd,
4950         IN  MLME_QUEUE_ELEM *Elem);
4951
4952 VOID CntlWaitAuthProc(
4953         IN  PRTMP_ADAPTER   pAd,
4954         IN  MLME_QUEUE_ELEM *Elem);
4955
4956 VOID CntlWaitAuthProc2(
4957         IN  PRTMP_ADAPTER pAd,
4958         IN  MLME_QUEUE_ELEM *Elem);
4959
4960 VOID CntlWaitAssocProc(
4961         IN  PRTMP_ADAPTER   pAd,
4962         IN  MLME_QUEUE_ELEM *Elem);
4963
4964 #ifdef QOS_DLS_SUPPORT
4965 VOID CntlOidDLSSetupProc(
4966         IN PRTMP_ADAPTER pAd,
4967         IN MLME_QUEUE_ELEM *Elem);
4968 #endif // QOS_DLS_SUPPORT //
4969
4970 VOID LinkUp(
4971         IN  PRTMP_ADAPTER   pAd,
4972         IN  UCHAR BssType);
4973
4974 VOID LinkDown(
4975         IN  PRTMP_ADAPTER   pAd,
4976         IN  BOOLEAN         IsReqFromAP);
4977
4978 VOID IterateOnBssTab(
4979         IN  PRTMP_ADAPTER   pAd);
4980
4981 VOID IterateOnBssTab2(
4982         IN  PRTMP_ADAPTER   pAd);;
4983
4984 VOID JoinParmFill(
4985         IN  PRTMP_ADAPTER   pAd,
4986         IN  OUT MLME_JOIN_REQ_STRUCT *JoinReq,
4987         IN  ULONG BssIdx);
4988
4989 VOID AssocParmFill(
4990         IN  PRTMP_ADAPTER   pAd,
4991         IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
4992         IN  PUCHAR pAddr,
4993         IN  USHORT CapabilityInfo,
4994         IN  ULONG Timeout,
4995         IN  USHORT ListenIntv);
4996
4997 VOID ScanParmFill(
4998         IN  PRTMP_ADAPTER   pAd,
4999         IN  OUT MLME_SCAN_REQ_STRUCT *ScanReq,
5000         IN  CHAR Ssid[],
5001         IN  UCHAR SsidLen,
5002         IN  UCHAR BssType,
5003         IN  UCHAR ScanType);
5004
5005 VOID DisassocParmFill(
5006         IN  PRTMP_ADAPTER   pAd,
5007         IN  OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
5008         IN  PUCHAR pAddr,
5009         IN  USHORT Reason);
5010
5011 VOID StartParmFill(
5012         IN  PRTMP_ADAPTER   pAd,
5013         IN  OUT MLME_START_REQ_STRUCT *StartReq,
5014         IN  CHAR Ssid[],
5015         IN  UCHAR SsidLen);
5016
5017 VOID AuthParmFill(
5018         IN  PRTMP_ADAPTER   pAd,
5019         IN  OUT MLME_AUTH_REQ_STRUCT *AuthReq,
5020         IN  PUCHAR pAddr,
5021         IN  USHORT Alg);
5022
5023 VOID EnqueuePsPoll(
5024         IN  PRTMP_ADAPTER   pAd);
5025
5026 VOID EnqueueBeaconFrame(
5027         IN  PRTMP_ADAPTER   pAd);
5028
5029 VOID MlmeJoinReqAction(
5030         IN  PRTMP_ADAPTER   pAd,
5031         IN  MLME_QUEUE_ELEM *Elem);
5032
5033 VOID MlmeScanReqAction(
5034         IN  PRTMP_ADAPTER   pAd,
5035         IN  MLME_QUEUE_ELEM *Elem);
5036
5037 VOID MlmeStartReqAction(
5038         IN  PRTMP_ADAPTER   pAd,
5039         IN  MLME_QUEUE_ELEM *Elem);
5040
5041 VOID ScanTimeoutAction(
5042         IN  PRTMP_ADAPTER   pAd,
5043         IN  MLME_QUEUE_ELEM *Elem);
5044
5045 VOID BeaconTimeoutAtJoinAction(
5046         IN  PRTMP_ADAPTER   pAd,
5047         IN  MLME_QUEUE_ELEM *Elem);
5048
5049 VOID PeerBeaconAtScanAction(
5050         IN  PRTMP_ADAPTER   pAd,
5051         IN  MLME_QUEUE_ELEM *Elem);
5052
5053 VOID PeerBeaconAtJoinAction(
5054         IN  PRTMP_ADAPTER   pAd,
5055         IN  MLME_QUEUE_ELEM *Elem);
5056
5057 VOID PeerBeacon(
5058         IN  PRTMP_ADAPTER   pAd,
5059         IN  MLME_QUEUE_ELEM *Elem);
5060
5061 VOID PeerProbeReqAction(
5062         IN  PRTMP_ADAPTER pAd,
5063         IN  MLME_QUEUE_ELEM *Elem);
5064
5065 VOID ScanNextChannel(
5066         IN  PRTMP_ADAPTER   pAd);
5067
5068 ULONG MakeIbssBeacon(
5069         IN  PRTMP_ADAPTER   pAd);
5070
5071 VOID CCXAdjacentAPReport(
5072         IN  PRTMP_ADAPTER   pAd);
5073
5074 BOOLEAN MlmeScanReqSanity(
5075         IN  PRTMP_ADAPTER   pAd,
5076         IN  VOID *Msg,
5077         IN  ULONG MsgLen,
5078         OUT UCHAR *BssType,
5079         OUT CHAR ssid[],
5080         OUT UCHAR *SsidLen,
5081         OUT UCHAR *ScanType);
5082
5083 BOOLEAN PeerBeaconAndProbeRspSanity(
5084         IN  PRTMP_ADAPTER   pAd,
5085         IN  VOID *Msg,
5086         IN  ULONG MsgLen,
5087         IN  UCHAR MsgChannel,
5088         OUT PUCHAR pAddr2,
5089         OUT PUCHAR pBssid,
5090         OUT CHAR Ssid[],
5091         OUT UCHAR *pSsidLen,
5092         OUT UCHAR *pBssType,
5093         OUT USHORT *pBeaconPeriod,
5094         OUT UCHAR *pChannel,
5095         OUT UCHAR *pNewChannel,
5096         OUT LARGE_INTEGER *pTimestamp,
5097         OUT CF_PARM *pCfParm,
5098         OUT USHORT *pAtimWin,
5099         OUT USHORT *pCapabilityInfo,
5100         OUT UCHAR *pErp,
5101         OUT UCHAR *pDtimCount,
5102         OUT UCHAR *pDtimPeriod,
5103         OUT UCHAR *pBcastFlag,
5104         OUT UCHAR *pMessageToMe,
5105         OUT UCHAR SupRate[],
5106         OUT UCHAR *pSupRateLen,
5107         OUT UCHAR ExtRate[],
5108         OUT UCHAR *pExtRateLen,
5109         OUT     UCHAR *pCkipFlag,
5110         OUT     UCHAR *pAironetCellPowerLimit,
5111         OUT PEDCA_PARM       pEdcaParm,
5112         OUT PQBSS_LOAD_PARM  pQbssLoad,
5113         OUT PQOS_CAPABILITY_PARM pQosCapability,
5114         OUT ULONG *pRalinkIe,
5115         OUT UCHAR                *pHtCapabilityLen,
5116 #ifdef CONFIG_STA_SUPPORT
5117         OUT UCHAR                *pPreNHtCapabilityLen,
5118 #endif // CONFIG_STA_SUPPORT //
5119         OUT HT_CAPABILITY_IE *pHtCapability,
5120         OUT UCHAR                *AddHtInfoLen,
5121         OUT ADD_HT_INFO_IE *AddHtInfo,
5122         OUT UCHAR *NewExtChannel,
5123         OUT USHORT *LengthVIE,
5124         OUT PNDIS_802_11_VARIABLE_IEs pVIE);
5125
5126 BOOLEAN PeerAddBAReqActionSanity(
5127     IN PRTMP_ADAPTER pAd,
5128     IN VOID *pMsg,
5129     IN ULONG MsgLen,
5130         OUT PUCHAR pAddr2);
5131
5132 BOOLEAN PeerAddBARspActionSanity(
5133     IN PRTMP_ADAPTER pAd,
5134     IN VOID *pMsg,
5135     IN ULONG MsgLen);
5136
5137 BOOLEAN PeerDelBAActionSanity(
5138     IN PRTMP_ADAPTER pAd,
5139     IN UCHAR Wcid,
5140     IN VOID *pMsg,
5141     IN ULONG MsgLen);
5142
5143 BOOLEAN MlmeAssocReqSanity(
5144         IN  PRTMP_ADAPTER   pAd,
5145         IN  VOID *Msg,
5146         IN  ULONG MsgLen,
5147         OUT PUCHAR pApAddr,
5148         OUT USHORT *CapabilityInfo,
5149         OUT ULONG *Timeout,
5150         OUT USHORT *ListenIntv);
5151
5152 BOOLEAN MlmeAuthReqSanity(
5153         IN  PRTMP_ADAPTER   pAd,
5154         IN  VOID *Msg,
5155         IN  ULONG MsgLen,
5156         OUT PUCHAR pAddr,
5157         OUT ULONG *Timeout,
5158         OUT USHORT *Alg);
5159
5160 BOOLEAN MlmeStartReqSanity(
5161         IN  PRTMP_ADAPTER   pAd,
5162         IN  VOID *Msg,
5163         IN  ULONG MsgLen,
5164         OUT CHAR Ssid[],
5165         OUT UCHAR *Ssidlen);
5166
5167 BOOLEAN PeerAuthSanity(
5168         IN  PRTMP_ADAPTER   pAd,
5169         IN  VOID *Msg,
5170         IN  ULONG MsgLen,
5171         OUT PUCHAR pAddr,
5172         OUT USHORT *Alg,
5173         OUT USHORT *Seq,
5174         OUT USHORT *Status,
5175         OUT CHAR ChlgText[]);
5176
5177 BOOLEAN PeerAssocRspSanity(
5178         IN  PRTMP_ADAPTER   pAd,
5179     IN VOID *pMsg,
5180         IN  ULONG MsgLen,
5181         OUT PUCHAR pAddr2,
5182         OUT USHORT *pCapabilityInfo,
5183         OUT USHORT *pStatus,
5184         OUT USHORT *pAid,
5185         OUT UCHAR SupRate[],
5186         OUT UCHAR *pSupRateLen,
5187         OUT UCHAR ExtRate[],
5188         OUT UCHAR *pExtRateLen,
5189     OUT HT_CAPABILITY_IE                *pHtCapability,
5190     OUT ADD_HT_INFO_IE          *pAddHtInfo,    // AP might use this additional ht info IE
5191     OUT UCHAR                   *pHtCapabilityLen,
5192     OUT UCHAR                   *pAddHtInfoLen,
5193     OUT UCHAR                   *pNewExtChannelOffset,
5194         OUT PEDCA_PARM pEdcaParm,
5195         OUT UCHAR *pCkipFlag);
5196
5197 BOOLEAN PeerDisassocSanity(
5198         IN  PRTMP_ADAPTER   pAd,
5199         IN  VOID *Msg,
5200         IN  ULONG MsgLen,
5201         OUT PUCHAR pAddr2,
5202         OUT USHORT *Reason);
5203
5204 BOOLEAN PeerWpaMessageSanity(
5205     IN  PRTMP_ADAPTER           pAd,
5206     IN  PEAPOL_PACKET           pMsg,
5207     IN  ULONG                           MsgLen,
5208     IN  UCHAR                           MsgType,
5209     IN  MAC_TABLE_ENTRY         *pEntry);
5210
5211 BOOLEAN PeerDeauthSanity(
5212         IN  PRTMP_ADAPTER   pAd,
5213         IN  VOID *Msg,
5214         IN  ULONG MsgLen,
5215         OUT PUCHAR pAddr2,
5216         OUT USHORT *Reason);
5217
5218 BOOLEAN PeerProbeReqSanity(
5219         IN  PRTMP_ADAPTER   pAd,
5220         IN  VOID *Msg,
5221         IN  ULONG MsgLen,
5222         OUT PUCHAR pAddr2,
5223         OUT CHAR Ssid[],
5224         OUT UCHAR *pSsidLen);
5225
5226 BOOLEAN GetTimBit(
5227         IN  CHAR *Ptr,
5228         IN  USHORT Aid,
5229         OUT UCHAR *TimLen,
5230         OUT UCHAR *BcastFlag,
5231         OUT UCHAR *DtimCount,
5232         OUT UCHAR *DtimPeriod,
5233         OUT UCHAR *MessageToMe);
5234
5235 UCHAR ChannelSanity(
5236         IN PRTMP_ADAPTER pAd,
5237         IN UCHAR channel);
5238
5239 NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(
5240         IN PBSS_ENTRY pBss);
5241
5242 BOOLEAN MlmeDelBAReqSanity(
5243     IN PRTMP_ADAPTER pAd,
5244     IN VOID *Msg,
5245     IN ULONG MsgLen);
5246
5247 BOOLEAN MlmeAddBAReqSanity(
5248     IN PRTMP_ADAPTER pAd,
5249     IN VOID *Msg,
5250     IN ULONG MsgLen,
5251     OUT PUCHAR pAddr2);
5252
5253 ULONG MakeOutgoingFrame(
5254         OUT CHAR *Buffer,
5255         OUT ULONG *Length, ...);
5256
5257 VOID  LfsrInit(
5258         IN  PRTMP_ADAPTER   pAd,
5259         IN  ULONG Seed);
5260
5261 UCHAR RandomByte(
5262         IN  PRTMP_ADAPTER   pAd);
5263
5264 VOID AsicUpdateAutoFallBackTable(
5265         IN      PRTMP_ADAPTER   pAd,
5266         IN      PUCHAR                  pTxRate);
5267
5268 VOID  MlmePeriodicExec(
5269         IN PVOID SystemSpecific1,
5270         IN PVOID FunctionContext,
5271         IN PVOID SystemSpecific2,
5272         IN PVOID SystemSpecific3);
5273
5274 VOID LinkDownExec(
5275         IN PVOID SystemSpecific1,
5276         IN PVOID FunctionContext,
5277         IN PVOID SystemSpecific2,
5278         IN PVOID SystemSpecific3);
5279
5280 VOID LinkUpExec(
5281         IN PVOID SystemSpecific1,
5282         IN PVOID FunctionContext,
5283         IN PVOID SystemSpecific2,
5284         IN PVOID SystemSpecific3);
5285
5286 VOID STAMlmePeriodicExec(
5287         PRTMP_ADAPTER pAd);
5288
5289 VOID MlmeAutoScan(
5290         IN PRTMP_ADAPTER pAd);
5291
5292 VOID MlmeAutoReconnectLastSSID(
5293         IN PRTMP_ADAPTER pAd);
5294
5295 BOOLEAN MlmeValidateSSID(
5296         IN PUCHAR pSsid,
5297         IN UCHAR  SsidLen);
5298
5299 VOID MlmeCheckForRoaming(
5300         IN PRTMP_ADAPTER pAd,
5301         IN ULONG    Now32);
5302
5303 VOID MlmeCheckForFastRoaming(
5304         IN  PRTMP_ADAPTER   pAd,
5305         IN  ULONG           Now);
5306
5307 VOID MlmeDynamicTxRateSwitching(
5308         IN PRTMP_ADAPTER pAd);
5309
5310 VOID MlmeSetTxRate(
5311         IN PRTMP_ADAPTER                pAd,
5312         IN PMAC_TABLE_ENTRY             pEntry,
5313         IN PRTMP_TX_RATE_SWITCH pTxRate);
5314
5315 VOID MlmeSelectTxRateTable(
5316         IN PRTMP_ADAPTER                pAd,
5317         IN PMAC_TABLE_ENTRY             pEntry,
5318         IN PUCHAR                               *ppTable,
5319         IN PUCHAR                               pTableSize,
5320         IN PUCHAR                               pInitTxRateIdx);
5321
5322 VOID MlmeCalculateChannelQuality(
5323         IN PRTMP_ADAPTER pAd,
5324         IN ULONG Now);
5325
5326 VOID MlmeCheckPsmChange(
5327         IN PRTMP_ADAPTER pAd,
5328         IN ULONG    Now32);
5329
5330 VOID MlmeSetPsmBit(
5331         IN PRTMP_ADAPTER pAd,
5332         IN USHORT psm);
5333
5334 VOID MlmeSetTxPreamble(
5335         IN PRTMP_ADAPTER pAd,
5336         IN USHORT TxPreamble);
5337
5338 VOID UpdateBasicRateBitmap(
5339         IN      PRTMP_ADAPTER   pAd);
5340
5341 VOID MlmeUpdateTxRates(
5342         IN PRTMP_ADAPTER        pAd,
5343         IN      BOOLEAN                 bLinkUp,
5344         IN      UCHAR                   apidx);
5345
5346 #ifdef DOT11_N_SUPPORT
5347 VOID MlmeUpdateHtTxRates(
5348         IN PRTMP_ADAPTER                pAd,
5349         IN      UCHAR                           apidx);
5350 #endif // DOT11_N_SUPPORT //
5351
5352 VOID    RTMPCheckRates(
5353         IN      PRTMP_ADAPTER   pAd,
5354         IN OUT  UCHAR           SupRate[],
5355         IN OUT  UCHAR           *SupRateLen);
5356
5357 #ifdef CONFIG_STA_SUPPORT
5358 BOOLEAN RTMPCheckChannel(
5359         IN PRTMP_ADAPTER pAd,
5360         IN UCHAR                CentralChannel,
5361         IN UCHAR                Channel);
5362 #endif // CONFIG_STA_SUPPORT //
5363
5364 BOOLEAN         RTMPCheckHt(
5365         IN              PRTMP_ADAPTER   pAd,
5366         IN              UCHAR   Wcid,
5367         IN OUT  HT_CAPABILITY_IE                        *pHtCapability,
5368         IN OUT  ADD_HT_INFO_IE                  *pAddHtInfo);
5369
5370 VOID StaQuickResponeForRateUpExec(
5371         IN PVOID SystemSpecific1,
5372         IN PVOID FunctionContext,
5373         IN PVOID SystemSpecific2,
5374         IN PVOID SystemSpecific3);
5375
5376 VOID AsicBbpTuning1(
5377         IN PRTMP_ADAPTER pAd);
5378
5379 VOID AsicBbpTuning2(
5380         IN PRTMP_ADAPTER pAd);
5381
5382 VOID RTMPUpdateMlmeRate(
5383         IN PRTMP_ADAPTER        pAd);
5384
5385 CHAR RTMPMaxRssi(
5386         IN PRTMP_ADAPTER        pAd,
5387         IN CHAR                         Rssi0,
5388         IN CHAR                         Rssi1,
5389         IN CHAR                         Rssi2);
5390
5391 VOID AsicEvaluateRxAnt(
5392         IN PRTMP_ADAPTER        pAd);
5393
5394 VOID AsicRxAntEvalTimeout(
5395         IN PVOID SystemSpecific1,
5396         IN PVOID FunctionContext,
5397         IN PVOID SystemSpecific2,
5398         IN PVOID SystemSpecific3);
5399
5400 VOID APSDPeriodicExec(
5401         IN PVOID SystemSpecific1,
5402         IN PVOID FunctionContext,
5403         IN PVOID SystemSpecific2,
5404         IN PVOID SystemSpecific3);
5405
5406 BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(
5407         IN PRTMP_ADAPTER    pAd,
5408         IN PMAC_TABLE_ENTRY     pEntry);
5409
5410 UCHAR RTMPStaFixedTxMode(
5411         IN PRTMP_ADAPTER    pAd,
5412         IN PMAC_TABLE_ENTRY     pEntry);
5413
5414 VOID RTMPUpdateLegacyTxSetting(
5415                 UCHAR                           fixed_tx_mode,
5416                 PMAC_TABLE_ENTRY        pEntry);
5417
5418 BOOLEAN RTMPAutoRateSwitchCheck(
5419         IN PRTMP_ADAPTER    pAd);
5420
5421 NDIS_STATUS MlmeInit(
5422         IN  PRTMP_ADAPTER   pAd);
5423
5424 VOID MlmeHandler(
5425         IN  PRTMP_ADAPTER   pAd);
5426
5427 VOID MlmeHalt(
5428         IN  PRTMP_ADAPTER   pAd);
5429
5430 VOID MlmeResetRalinkCounters(
5431         IN  PRTMP_ADAPTER   pAd);
5432
5433 VOID BuildChannelList(
5434         IN PRTMP_ADAPTER pAd);
5435
5436 UCHAR FirstChannel(
5437         IN  PRTMP_ADAPTER   pAd);
5438
5439 UCHAR NextChannel(
5440         IN  PRTMP_ADAPTER   pAd,
5441         IN  UCHAR channel);
5442
5443 VOID ChangeToCellPowerLimit(
5444         IN PRTMP_ADAPTER pAd,
5445         IN UCHAR         AironetCellPowerLimit);
5446
5447 VOID RaiseClock(
5448         IN  PRTMP_ADAPTER   pAd,
5449         IN  UINT32 *x);
5450
5451 VOID LowerClock(
5452         IN  PRTMP_ADAPTER   pAd,
5453         IN  UINT32 *x);
5454
5455 USHORT ShiftInBits(
5456         IN  PRTMP_ADAPTER   pAd);
5457
5458 VOID ShiftOutBits(
5459         IN  PRTMP_ADAPTER   pAd,
5460         IN  USHORT data,
5461         IN  USHORT count);
5462
5463 VOID EEpromCleanup(
5464         IN  PRTMP_ADAPTER   pAd);
5465
5466 VOID EWDS(
5467         IN  PRTMP_ADAPTER   pAd);
5468
5469 VOID EWEN(
5470         IN  PRTMP_ADAPTER   pAd);
5471
5472 USHORT RTMP_EEPROM_READ16(
5473         IN  PRTMP_ADAPTER   pAd,
5474         IN  USHORT Offset);
5475
5476 VOID RTMP_EEPROM_WRITE16(
5477         IN  PRTMP_ADAPTER   pAd,
5478         IN  USHORT Offset,
5479         IN  USHORT Data);
5480
5481 //
5482 // Prototypes of function definition in rtmp_tkip.c
5483 //
5484 VOID    RTMPInitTkipEngine(
5485         IN  PRTMP_ADAPTER   pAd,
5486         IN  PUCHAR          pTKey,
5487         IN  UCHAR           KeyId,
5488         IN  PUCHAR          pTA,
5489         IN  PUCHAR          pMICKey,
5490         IN  PUCHAR          pTSC,
5491         OUT PULONG          pIV16,
5492         OUT PULONG          pIV32);
5493
5494 VOID    RTMPInitMICEngine(
5495         IN  PRTMP_ADAPTER   pAd,
5496         IN  PUCHAR          pKey,
5497         IN  PUCHAR          pDA,
5498         IN  PUCHAR          pSA,
5499         IN  UCHAR           UserPriority,
5500         IN  PUCHAR          pMICKey);
5501
5502 BOOLEAN RTMPTkipCompareMICValue(
5503         IN  PRTMP_ADAPTER   pAd,
5504         IN  PUCHAR          pSrc,
5505         IN  PUCHAR          pDA,
5506         IN  PUCHAR          pSA,
5507         IN  PUCHAR          pMICKey,
5508         IN      UCHAR                   UserPriority,
5509         IN  UINT            Len);
5510
5511 VOID    RTMPCalculateMICValue(
5512         IN  PRTMP_ADAPTER   pAd,
5513         IN  PNDIS_PACKET    pPacket,
5514         IN  PUCHAR          pEncap,
5515         IN  PCIPHER_KEY     pKey,
5516         IN      UCHAR                   apidx);
5517
5518 BOOLEAN RTMPTkipCompareMICValueWithLLC(
5519         IN  PRTMP_ADAPTER   pAd,
5520         IN  PUCHAR          pLLC,
5521         IN  PUCHAR          pSrc,
5522         IN  PUCHAR          pDA,
5523         IN  PUCHAR          pSA,
5524         IN  PUCHAR          pMICKey,
5525         IN  UINT            Len);
5526
5527 VOID    RTMPTkipAppendByte(
5528         IN  PTKIP_KEY_INFO  pTkip,
5529         IN  UCHAR           uChar);
5530
5531 VOID    RTMPTkipAppend(
5532         IN  PTKIP_KEY_INFO  pTkip,
5533         IN  PUCHAR          pSrc,
5534         IN  UINT            nBytes);
5535
5536 VOID    RTMPTkipGetMIC(
5537         IN  PTKIP_KEY_INFO  pTkip);
5538
5539 BOOLEAN RTMPSoftDecryptTKIP(
5540         IN PRTMP_ADAPTER pAd,
5541         IN PUCHAR       pData,
5542         IN ULONG        DataByteCnt,
5543         IN UCHAR    UserPriority,
5544         IN PCIPHER_KEY  pWpaKey);
5545
5546 BOOLEAN RTMPSoftDecryptAES(
5547         IN PRTMP_ADAPTER pAd,
5548         IN PUCHAR       pData,
5549         IN ULONG        DataByteCnt,
5550         IN PCIPHER_KEY  pWpaKey);
5551
5552 //
5553 // Prototypes of function definition in cmm_info.c
5554 //
5555 NDIS_STATUS RTMPWPARemoveKeyProc(
5556         IN  PRTMP_ADAPTER   pAd,
5557         IN  PVOID           pBuf);
5558
5559 VOID    RTMPWPARemoveAllKeys(
5560         IN  PRTMP_ADAPTER   pAd);
5561
5562 BOOLEAN RTMPCheckStrPrintAble(
5563     IN  CHAR *pInPutStr,
5564     IN  UCHAR strLen);
5565
5566 VOID    RTMPSetPhyMode(
5567         IN  PRTMP_ADAPTER   pAd,
5568         IN  ULONG phymode);
5569
5570 VOID    RTMPUpdateHTIE(
5571         IN      RT_HT_CAPABILITY        *pRtHt,
5572         IN              UCHAR                           *pMcsSet,
5573         OUT             HT_CAPABILITY_IE *pHtCapability,
5574         OUT             ADD_HT_INFO_IE          *pAddHtInfo);
5575
5576 VOID    RTMPAddWcidAttributeEntry(
5577         IN      PRTMP_ADAPTER   pAd,
5578         IN      UCHAR                   BssIdx,
5579         IN      UCHAR                   KeyIdx,
5580         IN      UCHAR                   CipherAlg,
5581         IN      MAC_TABLE_ENTRY *pEntry);
5582
5583 CHAR *GetEncryptType(
5584         CHAR enc);
5585
5586 CHAR *GetAuthMode(
5587         CHAR auth);
5588
5589 VOID RTMPIoctlGetSiteSurvey(
5590         IN      PRTMP_ADAPTER   pAdapter,
5591         IN      struct iwreq    *wrq);
5592
5593 VOID RTMPIoctlGetMacTable(
5594         IN PRTMP_ADAPTER pAd,
5595         IN struct iwreq *wrq);
5596
5597 VOID RTMPIndicateWPA2Status(
5598         IN  PRTMP_ADAPTER  pAdapter);
5599
5600 VOID    RTMPOPModeSwitching(
5601         IN      PRTMP_ADAPTER   pAd);
5602
5603 #ifdef CONFIG_STA_SUPPORT
5604 VOID    RTMPAddBSSIDCipher(
5605     IN  PRTMP_ADAPTER   pAd,
5606         IN      UCHAR   Aid,
5607     IN  PNDIS_802_11_KEY    pKey,
5608     IN  UCHAR   CipherAlg);
5609 #endif // CONFIG_STA_SUPPORT //
5610
5611 #ifdef DOT11_N_SUPPORT
5612 VOID    RTMPSetHT(
5613         IN      PRTMP_ADAPTER   pAd,
5614         IN      OID_SET_HT_PHYMODE *pHTPhyMode);
5615
5616 VOID    RTMPSetIndividualHT(
5617         IN      PRTMP_ADAPTER           pAd,
5618         IN      UCHAR                           apidx);
5619 #endif // DOT11_N_SUPPORT //
5620
5621 VOID RTMPSendWirelessEvent(
5622         IN      PRTMP_ADAPTER   pAd,
5623         IN      USHORT                  Event_flag,
5624         IN      PUCHAR                  pAddr,
5625         IN  UCHAR                       BssIdx,
5626         IN      CHAR                    Rssi);
5627
5628 VOID    NICUpdateCntlCounters(
5629         IN      PRTMP_ADAPTER   pAd,
5630         IN      PHEADER_802_11  pHeader,
5631         IN    UCHAR                     SubType,
5632         IN      PRXWI_STRUC     pRxWI);
5633 //
5634 // prototype in wpa.c
5635 //
5636 BOOLEAN WpaMsgTypeSubst(
5637         IN  UCHAR   EAPType,
5638         OUT INT         *MsgType);
5639
5640 VOID WpaPskStateMachineInit(
5641         IN  PRTMP_ADAPTER       pAd,
5642         IN  STATE_MACHINE       *S,
5643         OUT STATE_MACHINE_FUNC Trans[]);
5644
5645 VOID WpaEAPOLKeyAction(
5646         IN  PRTMP_ADAPTER   pAd,
5647         IN  MLME_QUEUE_ELEM *Elem);
5648
5649 VOID    WpaPairMsg1Action(
5650         IN  PRTMP_ADAPTER   pAd,
5651         IN  MLME_QUEUE_ELEM *Elem);
5652
5653 VOID    WpaPairMsg3Action(
5654         IN  PRTMP_ADAPTER   pAd,
5655         IN  MLME_QUEUE_ELEM *Elem);
5656
5657 VOID    WpaGroupMsg1Action(
5658         IN  PRTMP_ADAPTER   pAd,
5659         IN  MLME_QUEUE_ELEM *Elem);
5660
5661 VOID    WpaMacHeaderInit(
5662         IN      PRTMP_ADAPTER   pAd,
5663         IN OUT  PHEADER_802_11  pHdr80211,
5664         IN      UCHAR           wep,
5665         IN      PUCHAR          pAddr1);
5666
5667 VOID    Wpa2PairMsg1Action(
5668     IN  PRTMP_ADAPTER   pAd,
5669     IN  MLME_QUEUE_ELEM *Elem);
5670
5671 VOID    Wpa2PairMsg3Action(
5672     IN  PRTMP_ADAPTER   pAd,
5673     IN  MLME_QUEUE_ELEM *Elem);
5674
5675 BOOLEAN ParseKeyData(
5676     IN  PRTMP_ADAPTER   pAd,
5677     IN  PUCHAR          pKeyData,
5678     IN  UCHAR           KeyDataLen,
5679         IN      UCHAR                   bPairewise);
5680
5681 VOID    RTMPToWirelessSta(
5682         IN  PRTMP_ADAPTER   pAd,
5683         IN  PUCHAR          pHeader802_3,
5684     IN  UINT            HdrLen,
5685         IN  PUCHAR          pData,
5686     IN  UINT            DataLen,
5687     IN  BOOLEAN                 is4wayFrame);
5688
5689 VOID    HMAC_SHA1(
5690         IN  UCHAR   *text,
5691         IN  UINT    text_len,
5692         IN  UCHAR   *key,
5693         IN  UINT    key_len,
5694         IN  UCHAR   *digest);
5695
5696 VOID    PRF(
5697         IN  UCHAR   *key,
5698         IN  INT     key_len,
5699         IN  UCHAR   *prefix,
5700         IN  INT     prefix_len,
5701         IN  UCHAR   *data,
5702         IN  INT     data_len,
5703         OUT UCHAR   *output,
5704         IN  INT     len);
5705
5706 VOID    CCKMPRF(
5707         IN  UCHAR   *key,
5708         IN  INT     key_len,
5709         IN  UCHAR   *data,
5710         IN  INT     data_len,
5711         OUT UCHAR   *output,
5712         IN  INT     len);
5713
5714 VOID WpaCountPTK(
5715         IN  PRTMP_ADAPTER   pAd,
5716         IN  UCHAR   *PMK,
5717         IN  UCHAR   *ANonce,
5718         IN  UCHAR   *AA,
5719         IN  UCHAR   *SNonce,
5720         IN  UCHAR   *SA,
5721         OUT UCHAR   *output,
5722         IN  UINT    len);
5723
5724 VOID    GenRandom(
5725         IN  PRTMP_ADAPTER   pAd,
5726         IN      UCHAR                   *macAddr,
5727         OUT     UCHAR                   *random);
5728
5729 //
5730 // prototype in aironet.c
5731 //
5732 VOID    AironetStateMachineInit(
5733         IN  PRTMP_ADAPTER       pAd,
5734         IN  STATE_MACHINE       *S,
5735         OUT STATE_MACHINE_FUNC  Trans[]);
5736
5737 VOID    AironetMsgAction(
5738         IN  PRTMP_ADAPTER   pAd,
5739         IN  MLME_QUEUE_ELEM *Elem);
5740
5741 VOID    AironetRequestAction(
5742         IN  PRTMP_ADAPTER   pAd,
5743         IN  MLME_QUEUE_ELEM *Elem);
5744
5745 VOID    ChannelLoadRequestAction(
5746         IN  PRTMP_ADAPTER   pAd,
5747         IN  UCHAR           Index);
5748
5749 VOID    NoiseHistRequestAction(
5750         IN  PRTMP_ADAPTER   pAd,
5751         IN  UCHAR           Index);
5752
5753 VOID    BeaconRequestAction(
5754         IN  PRTMP_ADAPTER   pAd,
5755         IN  UCHAR           Index);
5756
5757 VOID    AironetReportAction(
5758         IN  PRTMP_ADAPTER   pAd,
5759         IN  MLME_QUEUE_ELEM *Elem);
5760
5761 VOID    ChannelLoadReportAction(
5762         IN  PRTMP_ADAPTER   pAd,
5763         IN  UCHAR           Index);
5764
5765 VOID    NoiseHistReportAction(
5766         IN  PRTMP_ADAPTER   pAd,
5767         IN  UCHAR           Index);
5768
5769 VOID    AironetFinalReportAction(
5770         IN  PRTMP_ADAPTER   pAd);
5771
5772 VOID    BeaconReportAction(
5773         IN  PRTMP_ADAPTER   pAd,
5774         IN  UCHAR           Index);
5775
5776 VOID    AironetAddBeaconReport(
5777         IN  PRTMP_ADAPTER       pAd,
5778         IN  ULONG               Index,
5779         IN  PMLME_QUEUE_ELEM    pElem);
5780
5781 VOID    AironetCreateBeaconReportFromBssTable(
5782         IN  PRTMP_ADAPTER       pAd);
5783
5784 VOID    DBGPRINT_TX_RING(
5785         IN PRTMP_ADAPTER  pAd,
5786         IN UCHAR          QueIdx);
5787
5788 VOID DBGPRINT_RX_RING(
5789         IN PRTMP_ADAPTER  pAd);
5790
5791 CHAR    ConvertToRssi(
5792         IN PRTMP_ADAPTER  pAd,
5793         IN CHAR                         Rssi,
5794         IN UCHAR    RssiNumber);
5795
5796
5797 #ifdef DOT11N_DRAFT3
5798 VOID BuildEffectedChannelList(
5799         IN PRTMP_ADAPTER pAd);
5800 #endif // DOT11N_DRAFT3 //
5801
5802
5803 VOID APAsicEvaluateRxAnt(
5804         IN PRTMP_ADAPTER        pAd);
5805
5806
5807 VOID APAsicRxAntEvalTimeout(
5808         IN PRTMP_ADAPTER        pAd);
5809
5810 //
5811 // function prototype in cmm_wpa.c
5812 //
5813 BOOLEAN RTMPCheckWPAframe(
5814         IN PRTMP_ADAPTER pAd,
5815         IN PMAC_TABLE_ENTRY     pEntry,
5816         IN PUCHAR                       pData,
5817         IN ULONG                        DataByteCount,
5818         IN UCHAR                        FromWhichBSSID);
5819
5820 VOID AES_GTK_KEY_UNWRAP(
5821         IN  UCHAR   *key,
5822         OUT UCHAR   *plaintext,
5823         IN      UCHAR   c_len,
5824         IN  UCHAR   *ciphertext);
5825
5826 BOOLEAN RTMPCheckRSNIE(
5827         IN  PRTMP_ADAPTER   pAd,
5828         IN  PUCHAR          pData,
5829         IN  UCHAR           DataLen,
5830         IN  MAC_TABLE_ENTRY *pEntry,
5831         OUT     UCHAR                   *Offset);
5832
5833 BOOLEAN RTMPParseEapolKeyData(
5834         IN  PRTMP_ADAPTER   pAd,
5835         IN  PUCHAR          pKeyData,
5836         IN  UCHAR           KeyDataLen,
5837         IN      UCHAR                   GroupKeyIndex,
5838         IN      UCHAR                   MsgType,
5839         IN      BOOLEAN                 bWPA2,
5840         IN  MAC_TABLE_ENTRY *pEntry);
5841
5842 VOID    ConstructEapolMsg(
5843         IN      PRTMP_ADAPTER           pAd,
5844     IN  UCHAR                           PeerAuthMode,
5845     IN  UCHAR                           PeerWepStatus,
5846     IN  UCHAR                           MyGroupKeyWepStatus,
5847     IN  UCHAR                           MsgType,
5848     IN  UCHAR                           DefaultKeyIdx,
5849     IN  UCHAR                           *ReplayCounter,
5850         IN      UCHAR                           *KeyNonce,
5851         IN      UCHAR                           *TxRSC,
5852         IN      UCHAR                           *PTK,
5853         IN      UCHAR                           *GTK,
5854         IN      UCHAR                           *RSNIE,
5855         IN      UCHAR                           RSNIE_Len,
5856     OUT PEAPOL_PACKET       pMsg);
5857
5858 VOID    CalculateMIC(
5859         IN      PRTMP_ADAPTER   pAd,
5860         IN      UCHAR                   PeerWepStatus,
5861         IN      UCHAR                   *PTK,
5862         OUT PEAPOL_PACKET   pMsg);
5863
5864 NDIS_STATUS     RTMPSoftDecryptBroadCastData(
5865         IN      PRTMP_ADAPTER                                   pAd,
5866         IN      RX_BLK                                                  *pRxBlk,
5867         IN  NDIS_802_11_ENCRYPTION_STATUS       GroupCipher,
5868         IN  PCIPHER_KEY                                         pShard_key);
5869
5870 VOID    ConstructEapolKeyData(
5871         IN      PRTMP_ADAPTER   pAd,
5872         IN      UCHAR                   PeerAuthMode,
5873         IN      UCHAR                   PeerWepStatus,
5874         IN      UCHAR                   GroupKeyWepStatus,
5875         IN      UCHAR                   MsgType,
5876         IN      UCHAR                   DefaultKeyIdx,
5877         IN      BOOLEAN                 bWPA2Capable,
5878         IN      UCHAR                   *PTK,
5879         IN      UCHAR                   *GTK,
5880         IN      UCHAR                   *RSNIE,
5881         IN      UCHAR                   RSNIE_LEN,
5882         OUT PEAPOL_PACKET   pMsg);
5883
5884 VOID RTMPMakeRSNIE(
5885         IN  PRTMP_ADAPTER   pAd,
5886         IN  UINT            AuthMode,
5887         IN  UINT            WepStatus,
5888         IN      UCHAR                   apidx);
5889
5890 //
5891 // function prototype in ap_wpa.c
5892 //
5893
5894 BOOLEAN APWpaMsgTypeSubst(
5895         IN UCHAR    EAPType,
5896         OUT INT *MsgType) ;
5897
5898 MAC_TABLE_ENTRY *PACInquiry(
5899         IN  PRTMP_ADAPTER   pAd,
5900         IN  ULONG           Wcid);
5901
5902 BOOLEAN RTMPCheckMcast(
5903         IN PRTMP_ADAPTER pAd,
5904         IN PEID_STRUCT      eid_ptr,
5905         IN MAC_TABLE_ENTRY  *pEntry);
5906
5907 BOOLEAN RTMPCheckUcast(
5908         IN PRTMP_ADAPTER pAd,
5909         IN PEID_STRUCT      eid_ptr,
5910         IN MAC_TABLE_ENTRY  *pEntry);
5911
5912 BOOLEAN RTMPCheckAUTH(
5913         IN PRTMP_ADAPTER pAd,
5914         IN PEID_STRUCT      eid_ptr,
5915         IN MAC_TABLE_ENTRY  *pEntry);
5916
5917 VOID WPAStart4WayHS(
5918         IN  PRTMP_ADAPTER   pAd,
5919         IN  MAC_TABLE_ENTRY *pEntry,
5920         IN      ULONG                   TimeInterval);
5921
5922 VOID WPAStart2WayGroupHS(
5923         IN  PRTMP_ADAPTER   pAd,
5924         IN  MAC_TABLE_ENTRY *pEntry);
5925
5926 VOID APWpaEAPPacketAction(
5927         IN PRTMP_ADAPTER pAd,
5928         IN MLME_QUEUE_ELEM *Elem);
5929
5930 VOID APWpaEAPOLStartAction(
5931         IN PRTMP_ADAPTER pAd,
5932         IN MLME_QUEUE_ELEM *Elem);
5933
5934 VOID APWpaEAPOLLogoffAction(
5935         IN PRTMP_ADAPTER pAd,
5936         IN MLME_QUEUE_ELEM *Elem);
5937
5938 VOID APWpaEAPOLKeyAction(
5939         IN PRTMP_ADAPTER pAd,
5940         IN MLME_QUEUE_ELEM *Elem);
5941
5942 VOID APWpaEAPOLASFAlertAction(
5943         IN  PRTMP_ADAPTER    pAd,
5944         IN  MLME_QUEUE_ELEM  *Elem);
5945
5946 VOID HandleCounterMeasure(
5947         IN PRTMP_ADAPTER pAd,
5948         IN MAC_TABLE_ENTRY  *pEntry);
5949
5950 VOID PeerPairMsg2Action(
5951         IN PRTMP_ADAPTER pAd,
5952         IN MAC_TABLE_ENTRY  *pEntry,
5953         IN MLME_QUEUE_ELEM *Elem);
5954
5955 VOID PeerPairMsg4Action(
5956         IN PRTMP_ADAPTER pAd,
5957         IN MAC_TABLE_ENTRY  *pEntry,
5958         IN MLME_QUEUE_ELEM *Elem);
5959
5960 VOID CMTimerExec(
5961         IN PVOID SystemSpecific1,
5962         IN PVOID FunctionContext,
5963         IN PVOID SystemSpecific2,
5964         IN PVOID SystemSpecific3);
5965
5966 VOID WPARetryExec(
5967         IN PVOID SystemSpecific1,
5968         IN PVOID FunctionContext,
5969         IN PVOID SystemSpecific2,
5970         IN PVOID SystemSpecific3);
5971
5972 VOID EnqueueStartForPSKExec(
5973     IN PVOID SystemSpecific1,
5974     IN PVOID FunctionContext,
5975     IN PVOID SystemSpecific2,
5976     IN PVOID SystemSpecific3);
5977
5978 VOID RTMPHandleSTAKey(
5979     IN PRTMP_ADAPTER    pAdapter,
5980     IN MAC_TABLE_ENTRY  *pEntry,
5981     IN MLME_QUEUE_ELEM  *Elem);
5982
5983 VOID PeerGroupMsg2Action(
5984         IN  PRTMP_ADAPTER    pAd,
5985         IN  PMAC_TABLE_ENTRY pEntry,
5986         IN  VOID             *Msg,
5987         IN  UINT             MsgLen);
5988
5989 VOID PairDisAssocAction(
5990         IN  PRTMP_ADAPTER    pAd,
5991         IN  PMAC_TABLE_ENTRY pEntry,
5992         IN  USHORT           Reason);
5993
5994 VOID MlmeDeAuthAction(
5995         IN  PRTMP_ADAPTER    pAd,
5996         IN  PMAC_TABLE_ENTRY pEntry,
5997         IN  USHORT           Reason);
5998
5999 VOID GREKEYPeriodicExec(
6000         IN  PVOID   SystemSpecific1,
6001         IN  PVOID   FunctionContext,
6002         IN  PVOID   SystemSpecific2,
6003         IN  PVOID   SystemSpecific3);
6004
6005 VOID CountGTK(
6006         IN  UCHAR   *PMK,
6007         IN  UCHAR   *GNonce,
6008         IN  UCHAR   *AA,
6009         OUT UCHAR   *output,
6010         IN  UINT    len);
6011
6012 VOID    GetSmall(
6013         IN  PVOID   pSrc1,
6014         IN  PVOID   pSrc2,
6015         OUT PUCHAR  out,
6016         IN  ULONG   Length);
6017
6018 VOID    GetLarge(
6019         IN  PVOID   pSrc1,
6020         IN  PVOID   pSrc2,
6021         OUT PUCHAR  out,
6022         IN  ULONG   Length);
6023
6024 VOID APGenRandom(
6025         IN PRTMP_ADAPTER pAd,
6026         OUT UCHAR       *random);
6027
6028 VOID AES_GTK_KEY_WRAP(
6029         IN UCHAR *key,
6030         IN UCHAR *plaintext,
6031         IN UCHAR p_len,
6032         OUT UCHAR *ciphertext);
6033
6034 VOID    WpaSend(
6035     IN  PRTMP_ADAPTER   pAdapter,
6036     IN  PUCHAR          pPacket,
6037     IN  ULONG           Len);
6038
6039 VOID    APToWirelessSta(
6040         IN  PRTMP_ADAPTER   pAd,
6041         IN  MAC_TABLE_ENTRY *pEntry,
6042         IN  PUCHAR          pHeader802_3,
6043         IN  UINT            HdrLen,
6044         IN  PUCHAR          pData,
6045         IN  UINT            DataLen,
6046     IN  BOOLEAN                 bClearFrame);
6047
6048 VOID RTMPAddPMKIDCache(
6049         IN  PRTMP_ADAPTER               pAd,
6050         IN      INT                                             apidx,
6051         IN      PUCHAR                          pAddr,
6052         IN      UCHAR                                   *PMKID,
6053         IN      UCHAR                                   *PMK);
6054
6055 INT RTMPSearchPMKIDCache(
6056         IN  PRTMP_ADAPTER   pAd,
6057         IN      INT                             apidx,
6058         IN      PUCHAR          pAddr);
6059
6060 VOID RTMPDeletePMKIDCache(
6061         IN  PRTMP_ADAPTER   pAd,
6062         IN      INT                             apidx,
6063         IN  INT                         idx);
6064
6065 VOID RTMPMaintainPMKIDCache(
6066         IN  PRTMP_ADAPTER   pAd);
6067
6068 VOID    RTMPSendTriggerFrame(
6069         IN      PRTMP_ADAPTER   pAd,
6070         IN      PVOID                   pBuffer,
6071         IN      ULONG                   Length,
6072         IN  UCHAR           TxRate,
6073         IN      BOOLEAN                 bQosNull);
6074
6075
6076 /* timeout -- ms */
6077 VOID RTMP_SetPeriodicTimer(
6078         IN      NDIS_MINIPORT_TIMER *pTimer,
6079         IN      unsigned long timeout);
6080
6081 VOID RTMP_OS_Init_Timer(
6082         IN      PRTMP_ADAPTER pAd,
6083         IN      NDIS_MINIPORT_TIMER *pTimer,
6084         IN      TIMER_FUNCTION function,
6085         IN      PVOID data);
6086
6087 VOID RTMP_OS_Add_Timer(
6088         IN      NDIS_MINIPORT_TIMER     *pTimer,
6089         IN      unsigned long timeout);
6090
6091 VOID RTMP_OS_Mod_Timer(
6092         IN      NDIS_MINIPORT_TIMER     *pTimer,
6093         IN      unsigned long timeout);
6094
6095
6096 VOID RTMP_OS_Del_Timer(
6097         IN      NDIS_MINIPORT_TIMER     *pTimer,
6098         OUT     BOOLEAN                          *pCancelled);
6099
6100
6101 VOID RTMP_OS_Release_Packet(
6102         IN      PRTMP_ADAPTER pAd,
6103         IN      PQUEUE_ENTRY  pEntry);
6104
6105 VOID RTMPusecDelay(
6106         IN      ULONG   usec);
6107
6108 NDIS_STATUS os_alloc_mem(
6109         IN      PRTMP_ADAPTER pAd,
6110         OUT     PUCHAR *mem,
6111         IN      ULONG  size);
6112
6113 NDIS_STATUS os_free_mem(
6114         IN      PRTMP_ADAPTER pAd,
6115         IN      PUCHAR mem);
6116
6117
6118 void RTMP_AllocateSharedMemory(
6119         IN      PRTMP_ADAPTER pAd,
6120         IN      ULONG   Length,
6121         IN      BOOLEAN Cached,
6122         OUT     PVOID   *VirtualAddress,
6123         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6124
6125 VOID RTMPFreeTxRxRingMemory(
6126     IN  PRTMP_ADAPTER   pAd);
6127
6128 NDIS_STATUS AdapterBlockAllocateMemory(
6129         IN PVOID        handle,
6130         OUT     PVOID   *ppAd);
6131
6132 void RTMP_AllocateTxDescMemory(
6133         IN      PRTMP_ADAPTER pAd,
6134         IN      UINT    Index,
6135         IN      ULONG   Length,
6136         IN      BOOLEAN Cached,
6137         OUT     PVOID   *VirtualAddress,
6138         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6139
6140 void RTMP_AllocateFirstTxBuffer(
6141         IN      PRTMP_ADAPTER pAd,
6142         IN      UINT    Index,
6143         IN      ULONG   Length,
6144         IN      BOOLEAN Cached,
6145         OUT     PVOID   *VirtualAddress,
6146         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6147
6148 void RTMP_AllocateMgmtDescMemory(
6149         IN      PRTMP_ADAPTER pAd,
6150         IN      ULONG   Length,
6151         IN      BOOLEAN Cached,
6152         OUT     PVOID   *VirtualAddress,
6153         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6154
6155 void RTMP_AllocateRxDescMemory(
6156         IN      PRTMP_ADAPTER pAd,
6157         IN      ULONG   Length,
6158         IN      BOOLEAN Cached,
6159         OUT     PVOID   *VirtualAddress,
6160         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6161
6162 PNDIS_PACKET RTMP_AllocateRxPacketBuffer(
6163         IN      PRTMP_ADAPTER pAd,
6164         IN      ULONG   Length,
6165         IN      BOOLEAN Cached,
6166         OUT     PVOID   *VirtualAddress,
6167         OUT     PNDIS_PHYSICAL_ADDRESS PhysicalAddress);
6168
6169 PNDIS_PACKET RTMP_AllocateTxPacketBuffer(
6170         IN      PRTMP_ADAPTER pAd,
6171         IN      ULONG   Length,
6172         IN      BOOLEAN Cached,
6173         OUT     PVOID   *VirtualAddress);
6174
6175 PNDIS_PACKET RTMP_AllocateFragPacketBuffer(
6176         IN      PRTMP_ADAPTER pAd,
6177         IN      ULONG   Length);
6178
6179 void RTMP_QueryPacketInfo(
6180         IN  PNDIS_PACKET pPacket,
6181         OUT PACKET_INFO  *pPacketInfo,
6182         OUT PUCHAR               *pSrcBufVA,
6183         OUT     UINT             *pSrcBufLen);
6184
6185 void RTMP_QueryNextPacketInfo(
6186         IN  PNDIS_PACKET *ppPacket,
6187         OUT PACKET_INFO  *pPacketInfo,
6188         OUT PUCHAR               *pSrcBufVA,
6189         OUT     UINT             *pSrcBufLen);
6190
6191
6192 BOOLEAN RTMP_FillTxBlkInfo(
6193         IN RTMP_ADAPTER *pAd,
6194         IN TX_BLK *pTxBlk);
6195
6196
6197 PRTMP_SCATTER_GATHER_LIST
6198 rt_get_sg_list_from_packet(PNDIS_PACKET pPacket, RTMP_SCATTER_GATHER_LIST *sg);
6199
6200
6201  void announce_802_3_packet(
6202         IN      PRTMP_ADAPTER   pAd,
6203         IN      PNDIS_PACKET    pPacket);
6204
6205
6206 UINT BA_Reorder_AMSDU_Annnounce(
6207         IN      PRTMP_ADAPTER   pAd,
6208         IN      PNDIS_PACKET    pPacket);
6209
6210
6211 UINT Handle_AMSDU_Packet(
6212         IN      PRTMP_ADAPTER   pAd,
6213         IN      PUCHAR                  pData,
6214         IN      ULONG                   DataSize,
6215         IN  UCHAR                       FromWhichBSSID);
6216
6217
6218 void convert_802_11_to_802_3_packet(
6219         IN      PRTMP_ADAPTER   pAd,
6220         IN      PNDIS_PACKET    pPacket,
6221         IN      PUCHAR                  p8023hdr,
6222         IN      PUCHAR                  pData,
6223         IN      ULONG                   DataSize,
6224         IN  UCHAR                       FromWhichBSSID);
6225
6226
6227 PNET_DEV get_netdev_from_bssid(
6228         IN      PRTMP_ADAPTER   pAd,
6229         IN      UCHAR                   FromWhichBSSID);
6230
6231
6232 PNDIS_PACKET duplicate_pkt(
6233         IN      PRTMP_ADAPTER   pAd,
6234         IN      PUCHAR                  pHeader802_3,
6235     IN  UINT            HdrLen,
6236         IN      PUCHAR                  pData,
6237         IN      ULONG                   DataSize,
6238         IN      UCHAR                   FromWhichBSSID);
6239
6240
6241 PNDIS_PACKET duplicate_pkt_with_TKIP_MIC(
6242         IN      PRTMP_ADAPTER   pAd,
6243         IN      PNDIS_PACKET    pOldPkt);
6244
6245 PNDIS_PACKET duplicate_pkt_with_VLAN(
6246         IN      PRTMP_ADAPTER   pAd,
6247         IN      PUCHAR                  pHeader802_3,
6248     IN  UINT            HdrLen,
6249         IN      PUCHAR                  pData,
6250         IN      ULONG                   DataSize,
6251         IN      UCHAR                   FromWhichBSSID);
6252
6253 PNDIS_PACKET duplicate_pkt_with_WPI(
6254         IN      PRTMP_ADAPTER   pAd,
6255         IN      PNDIS_PACKET    pPacket,
6256         IN      UINT32                  ext_head_len,
6257         IN      UINT32                  ext_tail_len);
6258
6259 UCHAR VLAN_8023_Header_Copy(
6260         IN      PRTMP_ADAPTER   pAd,
6261         IN      PUCHAR                  pHeader802_3,
6262         IN      UINT            HdrLen,
6263         OUT PUCHAR                      pData,
6264         IN      UCHAR                   FromWhichBSSID);
6265
6266 #ifdef DOT11_N_SUPPORT
6267 void ba_flush_reordering_timeout_mpdus(
6268         IN PRTMP_ADAPTER        pAd,
6269         IN PBA_REC_ENTRY        pBAEntry,
6270         IN ULONG                        Now32);
6271
6272
6273 VOID BAOriSessionSetUp(
6274                         IN PRTMP_ADAPTER    pAd,
6275                         IN MAC_TABLE_ENTRY      *pEntry,
6276                         IN UCHAR                        TID,
6277                         IN USHORT                       TimeOut,
6278                         IN ULONG                        DelayTime,
6279                         IN BOOLEAN              isForced);
6280
6281 VOID BASessionTearDownALL(
6282         IN OUT  PRTMP_ADAPTER pAd,
6283         IN              UCHAR Wcid);
6284 #endif // DOT11_N_SUPPORT //
6285
6286 BOOLEAN OS_Need_Clone_Packet(void);
6287
6288
6289 VOID build_tx_packet(
6290         IN      PRTMP_ADAPTER   pAd,
6291         IN      PNDIS_PACKET    pPacket,
6292         IN      PUCHAR  pFrame,
6293         IN      ULONG   FrameLen);
6294
6295
6296 VOID BAOriSessionTearDown(
6297         IN OUT  PRTMP_ADAPTER   pAd,
6298         IN              UCHAR                   Wcid,
6299         IN              UCHAR                   TID,
6300         IN              BOOLEAN                 bPassive,
6301         IN              BOOLEAN                 bForceSend);
6302
6303 VOID BARecSessionTearDown(
6304         IN OUT  PRTMP_ADAPTER   pAd,
6305         IN              UCHAR                   Wcid,
6306         IN              UCHAR                   TID,
6307         IN              BOOLEAN                 bPassive);
6308
6309 BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
6310 void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
6311
6312 ULONG AutoChBssInsertEntry(
6313         IN PRTMP_ADAPTER pAd,
6314         IN PUCHAR pBssid,
6315         IN CHAR Ssid[],
6316         IN UCHAR SsidLen,
6317         IN UCHAR ChannelNo,
6318         IN CHAR Rssi);
6319
6320 void AutoChBssTableInit(
6321         IN PRTMP_ADAPTER pAd);
6322
6323 void ChannelInfoInit(
6324         IN PRTMP_ADAPTER pAd);
6325
6326 void AutoChBssTableDestroy(
6327         IN PRTMP_ADAPTER pAd);
6328
6329 void ChannelInfoDestroy(
6330         IN PRTMP_ADAPTER pAd);
6331
6332 UCHAR New_ApAutoSelectChannel(
6333         IN PRTMP_ADAPTER pAd);
6334
6335 BOOLEAN rtstrmactohex(
6336         IN char *s1,
6337         IN char *s2);
6338
6339 BOOLEAN rtstrcasecmp(
6340         IN char *s1,
6341         IN char *s2);
6342
6343 char *rtstrstruncasecmp(
6344         IN char *s1,
6345         IN char *s2);
6346
6347 char    *rtstrstr(
6348         IN      const char * s1,
6349         IN      const char * s2);
6350
6351 char *rstrtok(
6352         IN char * s,
6353         IN const char * ct);
6354
6355 int rtinet_aton(
6356         const char *cp,
6357         unsigned int *addr);
6358
6359 ////////// common ioctl functions //////////
6360 INT Set_DriverVersion_Proc(
6361         IN      PRTMP_ADAPTER   pAd,
6362         IN      PUCHAR                  arg);
6363
6364 INT Set_CountryRegion_Proc(
6365         IN      PRTMP_ADAPTER   pAd,
6366         IN      PUCHAR                  arg);
6367
6368 INT Set_CountryRegionABand_Proc(
6369         IN      PRTMP_ADAPTER   pAd,
6370         IN      PUCHAR                  arg);
6371
6372 INT Set_WirelessMode_Proc(
6373         IN      PRTMP_ADAPTER   pAd,
6374         IN      PUCHAR                  arg);
6375
6376 INT Set_Channel_Proc(
6377         IN      PRTMP_ADAPTER   pAd,
6378         IN      PUCHAR                  arg);
6379
6380 INT     Set_ShortSlot_Proc(
6381         IN      PRTMP_ADAPTER   pAd,
6382         IN      PUCHAR                  arg);
6383
6384 INT     Set_TxPower_Proc(
6385         IN      PRTMP_ADAPTER   pAd,
6386         IN      PUCHAR                  arg);
6387
6388 INT Set_BGProtection_Proc(
6389         IN  PRTMP_ADAPTER               pAd,
6390         IN  PUCHAR                      arg);
6391
6392 INT Set_TxPreamble_Proc(
6393         IN  PRTMP_ADAPTER               pAd,
6394         IN  PUCHAR                      arg);
6395
6396 INT Set_RTSThreshold_Proc(
6397         IN  PRTMP_ADAPTER               pAd,
6398         IN  PUCHAR                      arg);
6399
6400 INT Set_FragThreshold_Proc(
6401         IN  PRTMP_ADAPTER               pAd,
6402         IN  PUCHAR                      arg);
6403
6404 INT Set_TxBurst_Proc(
6405         IN  PRTMP_ADAPTER               pAd,
6406         IN  PUCHAR                      arg);
6407
6408 #ifdef AGGREGATION_SUPPORT
6409 INT     Set_PktAggregate_Proc(
6410         IN  PRTMP_ADAPTER               pAd,
6411         IN  PUCHAR                      arg);
6412 #endif
6413
6414 INT     Set_IEEE80211H_Proc(
6415         IN      PRTMP_ADAPTER   pAd,
6416         IN      PUCHAR                  arg);
6417
6418 #ifdef DBG
6419 INT     Set_Debug_Proc(
6420         IN      PRTMP_ADAPTER   pAd,
6421         IN      PUCHAR                  arg);
6422 #endif
6423
6424 INT     Show_DescInfo_Proc(
6425         IN      PRTMP_ADAPTER   pAd,
6426         IN      PUCHAR                  arg);
6427
6428 INT     Set_ResetStatCounter_Proc(
6429         IN      PRTMP_ADAPTER   pAd,
6430         IN      PUCHAR                  arg);
6431
6432 #ifdef DOT11_N_SUPPORT
6433 INT     Set_BASetup_Proc(
6434         IN      PRTMP_ADAPTER   pAd,
6435         IN      PUCHAR                  arg);
6436
6437 INT     Set_BADecline_Proc(
6438         IN      PRTMP_ADAPTER   pAd,
6439         IN      PUCHAR                  arg);
6440
6441 INT     Set_BAOriTearDown_Proc(
6442         IN      PRTMP_ADAPTER   pAd,
6443         IN      PUCHAR                  arg);
6444
6445 INT     Set_BARecTearDown_Proc(
6446         IN      PRTMP_ADAPTER   pAd,
6447         IN      PUCHAR                  arg);
6448
6449 INT     Set_HtBw_Proc(
6450         IN      PRTMP_ADAPTER   pAd,
6451         IN      PUCHAR                  arg);
6452
6453 INT     Set_HtMcs_Proc(
6454         IN      PRTMP_ADAPTER   pAd,
6455         IN      PUCHAR                  arg);
6456
6457 INT     Set_HtGi_Proc(
6458         IN      PRTMP_ADAPTER   pAd,
6459         IN      PUCHAR                  arg);
6460
6461 INT     Set_HtOpMode_Proc(
6462         IN      PRTMP_ADAPTER   pAd,
6463         IN      PUCHAR                  arg);
6464
6465 INT     Set_HtStbc_Proc(
6466         IN      PRTMP_ADAPTER   pAd,
6467         IN      PUCHAR                  arg);
6468
6469 INT     Set_HtHtc_Proc(
6470         IN      PRTMP_ADAPTER   pAd,
6471         IN      PUCHAR                  arg);
6472
6473 INT     Set_HtExtcha_Proc(
6474         IN      PRTMP_ADAPTER   pAd,
6475         IN      PUCHAR                  arg);
6476
6477 INT     Set_HtMpduDensity_Proc(
6478         IN      PRTMP_ADAPTER   pAd,
6479         IN      PUCHAR                  arg);
6480
6481 INT     Set_HtBaWinSize_Proc(
6482         IN      PRTMP_ADAPTER   pAd,
6483         IN      PUCHAR                  arg);
6484
6485 INT     Set_HtRdg_Proc(
6486         IN      PRTMP_ADAPTER   pAd,
6487         IN      PUCHAR                  arg);
6488
6489 INT     Set_HtLinkAdapt_Proc(
6490         IN      PRTMP_ADAPTER   pAd,
6491         IN      PUCHAR                  arg);
6492
6493 INT     Set_HtAmsdu_Proc(
6494         IN      PRTMP_ADAPTER   pAd,
6495         IN      PUCHAR                  arg);
6496
6497 INT     Set_HtAutoBa_Proc(
6498         IN      PRTMP_ADAPTER   pAd,
6499         IN      PUCHAR                  arg);
6500
6501 INT     Set_HtProtect_Proc(
6502         IN      PRTMP_ADAPTER   pAd,
6503         IN      PUCHAR                  arg);
6504
6505 INT     Set_HtMimoPs_Proc(
6506         IN      PRTMP_ADAPTER   pAd,
6507         IN      PUCHAR                  arg);
6508
6509
6510 INT     Set_ForceShortGI_Proc(
6511         IN      PRTMP_ADAPTER   pAd,
6512         IN      PUCHAR                  arg);
6513
6514 INT     Set_ForceGF_Proc(
6515         IN      PRTMP_ADAPTER   pAd,
6516         IN      PUCHAR                  arg);
6517
6518 INT     SetCommonHT(
6519         IN      PRTMP_ADAPTER   pAd);
6520
6521 INT     Set_SendPSMPAction_Proc(
6522         IN      PRTMP_ADAPTER   pAd,
6523         IN      PUCHAR                  arg);
6524
6525 INT     Set_HtMIMOPSmode_Proc(
6526         IN      PRTMP_ADAPTER   pAd,
6527         IN      PUCHAR                  arg);
6528
6529
6530 INT     Set_HtTxBASize_Proc(
6531         IN      PRTMP_ADAPTER   pAd,
6532         IN      PUCHAR                  arg);
6533 #endif // DOT11_N_SUPPORT //
6534
6535
6536
6537 #ifdef CONFIG_STA_SUPPORT
6538 //Dls , kathy
6539 VOID RTMPSendDLSTearDownFrame(
6540         IN      PRTMP_ADAPTER   pAd,
6541         IN      PUCHAR                  pDA);
6542
6543 #ifdef DOT11_N_SUPPORT
6544 //Block ACK
6545 VOID QueryBATABLE(
6546         IN  PRTMP_ADAPTER pAd,
6547         OUT PQUERYBA_TABLE pBAT);
6548 #endif // DOT11_N_SUPPORT //
6549
6550 #ifdef WPA_SUPPLICANT_SUPPORT
6551 INT         WpaCheckEapCode(
6552         IN  PRTMP_ADAPTER       pAd,
6553         IN  PUCHAR                              pFrame,
6554         IN  USHORT                              FrameLen,
6555         IN  USHORT                              OffSet);
6556
6557 VOID    WpaSendMicFailureToWpaSupplicant(
6558     IN  PRTMP_ADAPTER       pAd,
6559     IN  BOOLEAN             bUnicast);
6560
6561 VOID    SendAssocIEsToWpaSupplicant(
6562     IN  PRTMP_ADAPTER       pAd);
6563 #endif // WPA_SUPPLICANT_SUPPORT //
6564
6565 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
6566 int wext_notify_event_assoc(
6567         IN  RTMP_ADAPTER *pAd);
6568 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
6569
6570 #endif // CONFIG_STA_SUPPORT //
6571
6572
6573
6574 #ifdef DOT11_N_SUPPORT
6575 VOID Handle_BSS_Width_Trigger_Events(
6576         IN PRTMP_ADAPTER pAd);
6577
6578 void build_ext_channel_switch_ie(
6579         IN PRTMP_ADAPTER pAd,
6580         IN HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE *pIE);
6581 #endif // DOT11_N_SUPPORT //
6582
6583
6584 BOOLEAN APRxDoneInterruptHandle(
6585         IN      PRTMP_ADAPTER   pAd);
6586
6587 BOOLEAN STARxDoneInterruptHandle(
6588         IN      PRTMP_ADAPTER   pAd,
6589         IN      BOOLEAN                 argc);
6590
6591 #ifdef DOT11_N_SUPPORT
6592 // AMPDU packet indication
6593 VOID Indicate_AMPDU_Packet(
6594         IN      PRTMP_ADAPTER   pAd,
6595         IN      RX_BLK                  *pRxBlk,
6596         IN      UCHAR                   FromWhichBSSID);
6597
6598 // AMSDU packet indication
6599 VOID Indicate_AMSDU_Packet(
6600         IN      PRTMP_ADAPTER   pAd,
6601         IN      RX_BLK                  *pRxBlk,
6602         IN      UCHAR                   FromWhichBSSID);
6603 #endif // DOT11_N_SUPPORT //
6604
6605 // Normal legacy Rx packet indication
6606 VOID Indicate_Legacy_Packet(
6607         IN      PRTMP_ADAPTER   pAd,
6608         IN      RX_BLK                  *pRxBlk,
6609         IN      UCHAR                   FromWhichBSSID);
6610
6611 VOID Indicate_EAPOL_Packet(
6612         IN      PRTMP_ADAPTER   pAd,
6613         IN      RX_BLK                  *pRxBlk,
6614         IN      UCHAR                   FromWhichBSSID);
6615
6616 void  update_os_packet_info(
6617         IN      PRTMP_ADAPTER   pAd,
6618         IN      RX_BLK                  *pRxBlk,
6619         IN      UCHAR                   FromWhichBSSID);
6620
6621 void wlan_802_11_to_802_3_packet(
6622         IN      PRTMP_ADAPTER   pAd,
6623         IN      RX_BLK                  *pRxBlk,
6624         IN      PUCHAR                  pHeader802_3,
6625         IN  UCHAR                       FromWhichBSSID);
6626
6627 UINT deaggregate_AMSDU_announce(
6628         IN      PRTMP_ADAPTER   pAd,
6629         PNDIS_PACKET            pPacket,
6630         IN      PUCHAR                  pData,
6631         IN      ULONG                   DataSize);
6632
6633
6634 #ifdef CONFIG_STA_SUPPORT
6635 // remove LLC and get 802_3 Header
6636 #define  RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3)    \
6637 {                                                                                                                                                               \
6638         PUCHAR _pRemovedLLCSNAP = NULL, _pDA, _pSA;                                 \
6639                                                                                                                                                                 \
6640         if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH))                                    \
6641         {                                                                           \
6642                 _pDA = _pRxBlk->pHeader->Addr3;                                         \
6643                 _pSA = (PUCHAR)_pRxBlk->pHeader + sizeof(HEADER_802_11);                \
6644         }                                                                           \
6645         else                                                                        \
6646         {                                                                           \
6647                 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA))                               \
6648                 {                                                                       \
6649                         _pDA = _pRxBlk->pHeader->Addr1;                                     \
6650                 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS))                                                                 \
6651                         _pSA = _pRxBlk->pHeader->Addr2;                                                                         \
6652                 else                                                                                                                                    \
6653                         _pSA = _pRxBlk->pHeader->Addr3;                                     \
6654                 }                                                                       \
6655                 else                                                                    \
6656                 {                                                                       \
6657                         _pDA = _pRxBlk->pHeader->Addr1;                                     \
6658                         _pSA = _pRxBlk->pHeader->Addr2;                                     \
6659                 }                                                                       \
6660         }                                                                           \
6661                                                                                                                                                                 \
6662         CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData,                             \
6663                 _pRxBlk->DataSize, _pRemovedLLCSNAP);                                   \
6664 }
6665 #endif // CONFIG_STA_SUPPORT //
6666
6667
6668 BOOLEAN APFowardWirelessStaToWirelessSta(
6669         IN      PRTMP_ADAPTER   pAd,
6670         IN      PNDIS_PACKET    pPacket,
6671         IN      ULONG                   FromWhichBSSID);
6672
6673 VOID Announce_or_Forward_802_3_Packet(
6674         IN      PRTMP_ADAPTER   pAd,
6675         IN      PNDIS_PACKET    pPacket,
6676         IN      UCHAR                   FromWhichBSSID);
6677
6678 VOID Sta_Announce_or_Forward_802_3_Packet(
6679         IN      PRTMP_ADAPTER   pAd,
6680         IN      PNDIS_PACKET    pPacket,
6681         IN      UCHAR                   FromWhichBSSID);
6682
6683
6684 #ifdef CONFIG_STA_SUPPORT
6685 #define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
6686                         Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
6687                         //announce_802_3_packet(_pAd, _pPacket);
6688 #endif // CONFIG_STA_SUPPORT //
6689
6690
6691 PNDIS_PACKET DuplicatePacket(
6692         IN      PRTMP_ADAPTER   pAd,
6693         IN      PNDIS_PACKET    pPacket,
6694         IN      UCHAR                   FromWhichBSSID);
6695
6696
6697 PNDIS_PACKET ClonePacket(
6698         IN      PRTMP_ADAPTER   pAd,
6699         IN      PNDIS_PACKET    pPacket,
6700         IN      PUCHAR                  pData,
6701         IN      ULONG                   DataSize);
6702
6703
6704 // Normal, AMPDU or AMSDU
6705 VOID CmmRxnonRalinkFrameIndicate(
6706         IN      PRTMP_ADAPTER   pAd,
6707         IN      RX_BLK                  *pRxBlk,
6708         IN      UCHAR                   FromWhichBSSID);
6709
6710 VOID CmmRxRalinkFrameIndicate(
6711         IN      PRTMP_ADAPTER   pAd,
6712         IN      MAC_TABLE_ENTRY *pEntry,
6713         IN      RX_BLK                  *pRxBlk,
6714         IN      UCHAR                   FromWhichBSSID);
6715
6716 VOID Update_Rssi_Sample(
6717         IN PRTMP_ADAPTER        pAd,
6718         IN RSSI_SAMPLE          *pRssi,
6719         IN PRXWI_STRUC          pRxWI);
6720
6721 PNDIS_PACKET GetPacketFromRxRing(
6722         IN              PRTMP_ADAPTER   pAd,
6723         OUT             PRT28XX_RXD_STRUC               pSaveRxD,
6724         OUT             BOOLEAN                 *pbReschedule,
6725         IN OUT  UINT32                  *pRxPending);
6726
6727 PNDIS_PACKET RTMPDeFragmentDataFrame(
6728         IN      PRTMP_ADAPTER   pAd,
6729         IN      RX_BLK                  *pRxBlk);
6730
6731 ////////////////////////////////////////
6732
6733
6734
6735
6736
6737 #ifdef SNMP_SUPPORT
6738 //for snmp , kathy
6739 typedef struct _DefaultKeyIdxValue
6740 {
6741         UCHAR   KeyIdx;
6742         UCHAR   Value[16];
6743 } DefaultKeyIdxValue, *PDefaultKeyIdxValue;
6744 #endif
6745
6746
6747 #ifdef CONFIG_STA_SUPPORT
6748 enum {
6749         DIDmsg_lnxind_wlansniffrm               = 0x00000044,
6750         DIDmsg_lnxind_wlansniffrm_hosttime      = 0x00010044,
6751         DIDmsg_lnxind_wlansniffrm_mactime       = 0x00020044,
6752         DIDmsg_lnxind_wlansniffrm_channel       = 0x00030044,
6753         DIDmsg_lnxind_wlansniffrm_rssi          = 0x00040044,
6754         DIDmsg_lnxind_wlansniffrm_sq            = 0x00050044,
6755         DIDmsg_lnxind_wlansniffrm_signal        = 0x00060044,
6756         DIDmsg_lnxind_wlansniffrm_noise         = 0x00070044,
6757         DIDmsg_lnxind_wlansniffrm_rate          = 0x00080044,
6758         DIDmsg_lnxind_wlansniffrm_istx          = 0x00090044,
6759         DIDmsg_lnxind_wlansniffrm_frmlen        = 0x000A0044
6760 };
6761 enum {
6762         P80211ENUM_msgitem_status_no_value      = 0x00
6763 };
6764 enum {
6765         P80211ENUM_truth_false                  = 0x00,
6766         P80211ENUM_truth_true                   = 0x01
6767 };
6768
6769 /* Definition from madwifi */
6770 typedef struct {
6771         UINT32 did;
6772         UINT16 status;
6773         UINT16 len;
6774         UINT32 data;
6775 } p80211item_uint32_t;
6776
6777 typedef struct {
6778         UINT32 msgcode;
6779         UINT32 msglen;
6780 #define WLAN_DEVNAMELEN_MAX 16
6781         UINT8 devname[WLAN_DEVNAMELEN_MAX];
6782         p80211item_uint32_t hosttime;
6783         p80211item_uint32_t mactime;
6784         p80211item_uint32_t channel;
6785         p80211item_uint32_t rssi;
6786         p80211item_uint32_t sq;
6787         p80211item_uint32_t signal;
6788         p80211item_uint32_t noise;
6789         p80211item_uint32_t rate;
6790         p80211item_uint32_t istx;
6791         p80211item_uint32_t frmlen;
6792 } wlan_ng_prism2_header;
6793
6794 /* The radio capture header precedes the 802.11 header. */
6795 typedef struct PACKED _ieee80211_radiotap_header {
6796     UINT8       it_version;     /* Version 0. Only increases
6797                                  * for drastic changes,
6798                                  * introduction of compatible
6799                                  * new fields does not count.
6800                                  */
6801     UINT8       it_pad;
6802     UINT16     it_len;         /* length of the whole
6803                                  * header in bytes, including
6804                                  * it_version, it_pad,
6805                                  * it_len, and data fields.
6806                                  */
6807     UINT32   it_present;        /* A bitmap telling which
6808                                          * fields are present. Set bit 31
6809                                          * (0x80000000) to extend the
6810                                          * bitmap by another 32 bits.
6811                                          * Additional extensions are made
6812                                          * by setting bit 31.
6813                                          */
6814 }ieee80211_radiotap_header ;
6815
6816 enum ieee80211_radiotap_type {
6817     IEEE80211_RADIOTAP_TSFT = 0,
6818     IEEE80211_RADIOTAP_FLAGS = 1,
6819     IEEE80211_RADIOTAP_RATE = 2,
6820     IEEE80211_RADIOTAP_CHANNEL = 3,
6821     IEEE80211_RADIOTAP_FHSS = 4,
6822     IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
6823     IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
6824     IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
6825     IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
6826     IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
6827     IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
6828     IEEE80211_RADIOTAP_ANTENNA = 11,
6829     IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
6830     IEEE80211_RADIOTAP_DB_ANTNOISE = 13
6831 };
6832
6833 #define WLAN_RADIOTAP_PRESENT (                 \
6834         (1 << IEEE80211_RADIOTAP_TSFT)  |       \
6835         (1 << IEEE80211_RADIOTAP_FLAGS) |       \
6836         (1 << IEEE80211_RADIOTAP_RATE)  |       \
6837          0)
6838
6839 typedef struct _wlan_radiotap_header {
6840         ieee80211_radiotap_header wt_ihdr;
6841         INT64 wt_tsft;
6842         UINT8 wt_flags;
6843         UINT8 wt_rate;
6844 } wlan_radiotap_header;
6845 /* Definition from madwifi */
6846
6847 void send_monitor_packets(
6848         IN      PRTMP_ADAPTER   pAd,
6849         IN      RX_BLK                  *pRxBlk);
6850
6851 #if WIRELESS_EXT >= 12
6852 // This function will be called when query /proc
6853 struct iw_statistics *rt28xx_get_wireless_stats(
6854     IN struct net_device *net_dev);
6855 #endif
6856
6857 VOID    RTMPSetDesiredRates(
6858     IN  PRTMP_ADAPTER   pAdapter,
6859     IN  LONG            Rates);
6860 #endif // CONFIG_STA_SUPPORT //
6861
6862 INT     Set_FixedTxMode_Proc(
6863         IN      PRTMP_ADAPTER   pAd,
6864         IN      PUCHAR                  arg);
6865
6866 #ifdef CONFIG_APSTA_MIXED_SUPPORT
6867 INT     Set_OpMode_Proc(
6868         IN      PRTMP_ADAPTER   pAd,
6869         IN      PUCHAR                  arg);
6870 #endif // CONFIG_APSTA_MIXED_SUPPORT //
6871
6872 static inline char* GetPhyMode(
6873         int Mode)
6874 {
6875         switch(Mode)
6876         {
6877                 case MODE_CCK:
6878                         return "CCK";
6879
6880                 case MODE_OFDM:
6881                         return "OFDM";
6882 #ifdef DOT11_N_SUPPORT
6883                 case MODE_HTMIX:
6884                         return "HTMIX";
6885
6886                 case MODE_HTGREENFIELD:
6887                         return "GREEN";
6888 #endif // DOT11_N_SUPPORT //
6889                 default:
6890                         return "N/A";
6891         }
6892 }
6893
6894
6895 static inline char* GetBW(
6896         int BW)
6897 {
6898         switch(BW)
6899         {
6900                 case BW_10:
6901                         return "10M";
6902
6903                 case BW_20:
6904                         return "20M";
6905 #ifdef DOT11_N_SUPPORT
6906                 case BW_40:
6907                         return "40M";
6908 #endif // DOT11_N_SUPPORT //
6909                 default:
6910                         return "N/A";
6911         }
6912 }
6913
6914
6915 VOID RT28xxThreadTerminate(
6916         IN RTMP_ADAPTER *pAd);
6917
6918 BOOLEAN RT28XXChipsetCheck(
6919         IN void *_dev_p);
6920
6921 BOOLEAN RT28XXNetDevInit(
6922         IN void                                 *_dev_p,
6923         IN struct  net_device   *net_dev,
6924         IN RTMP_ADAPTER                 *pAd);
6925
6926 BOOLEAN RT28XXProbePostConfig(
6927         IN void                                 *_dev_p,
6928         IN RTMP_ADAPTER                 *pAd,
6929         IN INT32                                argc);
6930
6931 VOID RT28XXDMADisable(
6932         IN RTMP_ADAPTER                 *pAd);
6933
6934 VOID RT28XXDMAEnable(
6935         IN RTMP_ADAPTER                 *pAd);
6936
6937 VOID RT28xx_UpdateBeaconToAsic(
6938         IN RTMP_ADAPTER * pAd,
6939         IN INT apidx,
6940         IN ULONG BeaconLen,
6941         IN ULONG UpdatePos);
6942
6943 INT rt28xx_ioctl(
6944         IN      struct net_device       *net_dev,
6945         IN      OUT     struct ifreq    *rq,
6946         IN      INT                     cmd);
6947
6948
6949 #ifdef CONFIG_STA_SUPPORT
6950 INT rt28xx_sta_ioctl(
6951         IN      struct net_device       *net_dev,
6952         IN      OUT     struct ifreq    *rq,
6953         IN      INT                     cmd);
6954 #endif // CONFIG_STA_SUPPORT //
6955
6956 BOOLEAN RT28XXSecurityKeyAdd(
6957         IN              PRTMP_ADAPTER           pAd,
6958         IN              ULONG                           apidx,
6959         IN              ULONG                           KeyIdx,
6960         IN              MAC_TABLE_ENTRY         *pEntry);
6961
6962 ////////////////////////////////////////
6963 PNDIS_PACKET GetPacketFromRxRing(
6964         IN              PRTMP_ADAPTER   pAd,
6965         OUT             PRT28XX_RXD_STRUC       pSaveRxD,
6966         OUT             BOOLEAN                 *pbReschedule,
6967         IN OUT  UINT32                  *pRxPending);
6968
6969
6970 void kill_thread_task(PRTMP_ADAPTER pAd);
6971
6972 void tbtt_tasklet(unsigned long data);
6973
6974 //
6975 // Function Prototype in cmm_data_2860.c
6976 //
6977 USHORT RtmpPCI_WriteTxResource(
6978         IN      PRTMP_ADAPTER   pAd,
6979         IN      TX_BLK                  *pTxBlk,
6980         IN      BOOLEAN                 bIsLast,
6981         OUT     USHORT                  *FreeNumber);
6982
6983 USHORT RtmpPCI_WriteSingleTxResource(
6984         IN      PRTMP_ADAPTER   pAd,
6985         IN      TX_BLK                  *pTxBlk,
6986         IN      BOOLEAN                 bIsLast,
6987         OUT     USHORT                  *FreeNumber);
6988
6989 USHORT RtmpPCI_WriteMultiTxResource(
6990         IN      PRTMP_ADAPTER   pAd,
6991         IN      TX_BLK                  *pTxBlk,
6992         IN      UCHAR                   frameNum,
6993         OUT     USHORT                  *FreeNumber);
6994
6995 USHORT  RtmpPCI_WriteFragTxResource(
6996         IN      PRTMP_ADAPTER   pAd,
6997         IN      TX_BLK                  *pTxBlk,
6998         IN      UCHAR                   fragNum,
6999         OUT     USHORT                  *FreeNumber);
7000
7001 USHORT RtmpPCI_WriteSubTxResource(
7002         IN      PRTMP_ADAPTER   pAd,
7003         IN      TX_BLK                  *pTxBlk,
7004         IN      BOOLEAN                 bIsLast,
7005         OUT     USHORT                  *FreeNumber);
7006
7007 VOID RtmpPCI_FinalWriteTxResource(
7008         IN      PRTMP_ADAPTER   pAd,
7009         IN      TX_BLK                  *pTxBlk,
7010         IN      USHORT                  totalMPDUSize,
7011         IN      USHORT                  FirstTxIdx);
7012
7013 VOID RtmpPCIDataLastTxIdx(
7014         IN      PRTMP_ADAPTER   pAd,
7015         IN      UCHAR                   QueIdx,
7016         IN      USHORT                  LastTxIdx);
7017
7018 VOID RtmpPCIDataKickOut(
7019         IN      PRTMP_ADAPTER   pAd,
7020         IN      TX_BLK                  *pTxBlk,
7021         IN      UCHAR                   QueIdx);
7022
7023
7024 int RtmpPCIMgmtKickOut(
7025         IN RTMP_ADAPTER         *pAd,
7026         IN UCHAR                        QueIdx,
7027         IN PNDIS_PACKET         pPacket,
7028         IN PUCHAR                       pSrcBufVA,
7029         IN UINT                         SrcBufLen);
7030
7031
7032 NDIS_STATUS RTMPCheckRxError(
7033         IN  PRTMP_ADAPTER   pAd,
7034         IN  PHEADER_802_11  pHeader,
7035         IN      PRXWI_STRUC     pRxWI,
7036         IN  PRT28XX_RXD_STRUC      pRxD);
7037
7038 #ifdef CONFIG_STA_SUPPORT
7039 VOID RTMPInitPCIeLinkCtrlValue(
7040         IN      PRTMP_ADAPTER   pAd);
7041
7042 VOID RTMPFindHostPCIDev(
7043     IN  PRTMP_ADAPTER   pAd);
7044
7045 VOID RTMPPCIeLinkCtrlValueRestore(
7046         IN      PRTMP_ADAPTER   pAd,
7047         IN   UCHAR              Level);
7048
7049 VOID RTMPPCIeLinkCtrlSetting(
7050         IN      PRTMP_ADAPTER   pAd,
7051         IN      USHORT          Max);
7052
7053 VOID RT28xxPciAsicRadioOff(
7054         IN PRTMP_ADAPTER    pAd,
7055         IN UCHAR            Level,
7056         IN USHORT           TbttNumToNextWakeUp);
7057
7058 BOOLEAN RT28xxPciAsicRadioOn(
7059         IN PRTMP_ADAPTER pAd,
7060         IN UCHAR     Level);
7061
7062 VOID RT28xxPciStaAsicForceWakeup(
7063         IN PRTMP_ADAPTER pAd,
7064         IN UCHAR         Level);
7065
7066 VOID RT28xxPciStaAsicSleepThenAutoWakeup(
7067         IN PRTMP_ADAPTER pAd,
7068         IN USHORT TbttNumToNextWakeUp);
7069
7070 VOID PsPollWakeExec(
7071         IN PVOID SystemSpecific1,
7072         IN PVOID FunctionContext,
7073         IN PVOID SystemSpecific2,
7074         IN PVOID SystemSpecific3);
7075
7076 VOID  RadioOnExec(
7077         IN PVOID SystemSpecific1,
7078         IN PVOID FunctionContext,
7079         IN PVOID SystemSpecific2,
7080         IN PVOID SystemSpecific3);
7081 #endif // CONFIG_STA_SUPPORT //
7082
7083 VOID RT28xxPciMlmeRadioOn(
7084         IN PRTMP_ADAPTER pAd);
7085
7086 VOID RT28xxPciMlmeRadioOFF(
7087         IN PRTMP_ADAPTER pAd);
7088
7089 VOID AsicTurnOffRFClk(
7090         IN PRTMP_ADAPTER    pAd,
7091         IN      UCHAR           Channel);
7092
7093 VOID AsicTurnOnRFClk(
7094         IN PRTMP_ADAPTER        pAd,
7095         IN      UCHAR                   Channel);
7096
7097
7098 ////////////////////////////////////////
7099
7100 VOID QBSS_LoadInit(
7101         IN              RTMP_ADAPTER    *pAd);
7102
7103 UINT32 QBSS_LoadElementAppend(
7104         IN              RTMP_ADAPTER    *pAd,
7105         OUT             UINT8                   *buf_p);
7106
7107 VOID QBSS_LoadUpdate(
7108         IN              RTMP_ADAPTER    *pAd);
7109
7110 ///////////////////////////////////////
7111 INT RTMPShowCfgValue(
7112         IN      PRTMP_ADAPTER   pAd,
7113         IN      PUCHAR                  pName,
7114         IN      PUCHAR                  pBuf);
7115
7116 PCHAR   RTMPGetRalinkAuthModeStr(
7117     IN  NDIS_802_11_AUTHENTICATION_MODE authMode);
7118
7119 PCHAR   RTMPGetRalinkEncryModeStr(
7120     IN  USHORT encryMode);
7121 //////////////////////////////////////
7122
7123 #ifdef CONFIG_STA_SUPPORT
7124 VOID AsicStaBbpTuning(
7125         IN PRTMP_ADAPTER pAd);
7126
7127 VOID AsicResetFromDMABusy(
7128         IN PRTMP_ADAPTER pAd);
7129
7130 VOID AsicResetBBP(
7131         IN PRTMP_ADAPTER pAd);
7132
7133 VOID AsicResetMAC(
7134         IN PRTMP_ADAPTER pAd);
7135
7136 VOID AsicResetPBF(
7137         IN PRTMP_ADAPTER pAd);
7138 #endif // CONFIG_STA_SUPPORT //
7139
7140 void RTMP_IndicateMediaState(
7141         IN      PRTMP_ADAPTER   pAd);
7142
7143 VOID ReSyncBeaconTime(
7144         IN  PRTMP_ADAPTER   pAd);
7145
7146 VOID RTMPSetAGCInitValue(
7147         IN PRTMP_ADAPTER        pAd,
7148         IN UCHAR                        BandWidth);
7149
7150 int rt28xx_close(IN PNET_DEV dev);
7151 int rt28xx_open(IN PNET_DEV dev);
7152
7153 __inline INT VIRTUAL_IF_UP(PRTMP_ADAPTER pAd)
7154 {
7155 extern VOID MeshMakeBeacon(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
7156 extern VOID MeshUpdateBeaconFrame(IN PRTMP_ADAPTER pAd, IN UCHAR idx);
7157
7158         if (VIRTUAL_IF_NUM(pAd) == 0)
7159         {
7160                 if (rt28xx_open(pAd->net_dev) != 0)
7161                         return -1;
7162         }
7163         else
7164         {
7165         }
7166         VIRTUAL_IF_INC(pAd);
7167         return 0;
7168 }
7169
7170 __inline VOID VIRTUAL_IF_DOWN(PRTMP_ADAPTER pAd)
7171 {
7172         VIRTUAL_IF_DEC(pAd);
7173         if (VIRTUAL_IF_NUM(pAd) == 0)
7174                 rt28xx_close(pAd->net_dev);
7175         return;
7176 }
7177
7178
7179 #endif  // __RTMP_H__
7180