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