Staging: rt28x0: updates from vendor's V2.1.0.0 drivers
[safe/jmp/linux-2.6] / drivers / staging / rt2860 / mlme.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         mlme.h
29
30         Abstract:
31
32         Revision History:
33         Who                     When                    What
34         --------        ----------              ----------------------------------------------
35         John Chang      2003-08-28              Created
36         John Chang  2004-09-06      modified for RT2600
37
38 */
39 #ifndef __MLME_H__
40 #define __MLME_H__
41
42 #include "rtmp_dot11.h"
43
44
45
46 // maximum supported capability information -
47 // ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot
48 #define SUPPORTED_CAPABILITY_INFO   0x0533
49
50 #define END_OF_ARGS                 -1
51 #define LFSR_MASK                   0x80000057
52 #define MLME_TASK_EXEC_INTV         100/*200*/       //
53 #define LEAD_TIME                   5
54 #define MLME_TASK_EXEC_MULTIPLE       10  /*5*/       // MLME_TASK_EXEC_MULTIPLE * MLME_TASK_EXEC_INTV = 1 sec
55 #define REORDER_EXEC_INTV               100       // 0.1 sec
56
57 // The definition of Radar detection duration region
58 #define CE              0
59 #define FCC             1
60 #define JAP             2
61 #define JAP_W53 3
62 #define JAP_W56 4
63 #define MAX_RD_REGION 5
64
65 #define BEACON_LOST_TIME            4 * OS_HZ    // 2048 msec = 2 sec
66
67 #define DLS_TIMEOUT                 1200      // unit: msec
68 #define AUTH_TIMEOUT                300       // unit: msec
69 #define ASSOC_TIMEOUT               300       // unit: msec
70 #define JOIN_TIMEOUT                2000        // unit: msec
71 #define SHORT_CHANNEL_TIME          90        // unit: msec
72 #define MIN_CHANNEL_TIME            110        // unit: msec, for dual band scan
73 #define MAX_CHANNEL_TIME            140       // unit: msec, for single band scan
74 #define FAST_ACTIVE_SCAN_TIME       30            // Active scan waiting for probe response time
75 #define CW_MIN_IN_BITS              4         // actual CwMin = 2^CW_MIN_IN_BITS - 1
76 #define LINK_DOWN_TIMEOUT           20000      // unit: msec
77 #define AUTO_WAKEUP_TIMEOUT                     70                      //unit: msec
78
79
80 #define CW_MAX_IN_BITS              10        // actual CwMax = 2^CW_MAX_IN_BITS - 1
81
82
83 // Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720).
84 // SHould not refer to this constant anymore
85 //#define RSSI_TO_DBM_OFFSET          120 // for RT2530 RSSI-115 = dBm
86 #define RSSI_FOR_MID_TX_POWER       -55  // -55 db is considered mid-distance
87 #define RSSI_FOR_LOW_TX_POWER       -45  // -45 db is considered very short distance and
88                                         // eligible to use a lower TX power
89 #define RSSI_FOR_LOWEST_TX_POWER    -30
90 //#define MID_TX_POWER_DELTA          0   // 0 db from full TX power upon mid-distance to AP
91 #define LOW_TX_POWER_DELTA          6    // -3 db from full TX power upon very short distance. 1 grade is 0.5 db
92 #define LOWEST_TX_POWER_DELTA       16   // -8 db from full TX power upon shortest distance. 1 grade is 0.5 db
93
94 #define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD     0
95 #define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD   1
96 #define RSSI_THRESHOLD_FOR_ROAMING              25
97 #define RSSI_DELTA                              5
98
99 // Channel Quality Indication
100 #define CQI_IS_GOOD(cqi)            ((cqi) >= 50)
101 //#define CQI_IS_FAIR(cqi)          (((cqi) >= 20) && ((cqi) < 50))
102 #define CQI_IS_POOR(cqi)            (cqi < 50)  //(((cqi) >= 5) && ((cqi) < 20))
103 #define CQI_IS_BAD(cqi)             (cqi < 5)
104 #define CQI_IS_DEAD(cqi)            (cqi == 0)
105
106 // weighting factor to calculate Channel quality, total should be 100%
107 #define RSSI_WEIGHTING                   50
108 #define TX_WEIGHTING                     30
109 #define RX_WEIGHTING                     20
110
111 #define BSS_NOT_FOUND                    0xFFFFFFFF
112
113 #define MAX_LEN_OF_MLME_QUEUE            40 //10
114
115 #define SCAN_PASSIVE                     18             // scan with no probe request, only wait beacon and probe response
116 #define SCAN_ACTIVE                      19             // scan with probe request, and wait beacon and probe response
117 #define SCAN_CISCO_PASSIVE                               20             // Single channel passive scan
118 #define SCAN_CISCO_ACTIVE                                21             // Single channel active scan
119 #define SCAN_CISCO_NOISE                                 22             // Single channel passive scan for noise histogram collection
120 #define SCAN_CISCO_CHANNEL_LOAD                  23             // Single channel passive scan for channel load collection
121 #define FAST_SCAN_ACTIVE                 24             // scan with probe request, and wait beacon and probe response
122
123 #define MAC_ADDR_IS_GROUP(Addr)       (((Addr[0]) & 0x01))
124 #define MAC_ADDR_HASH(Addr)            (Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
125 #define MAC_ADDR_HASH_INDEX(Addr)      (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
126 #define TID_MAC_HASH(Addr,TID)            (TID^Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
127 #define TID_MAC_HASH_INDEX(Addr,TID)      (TID_MAC_HASH(Addr,TID) % HASH_TABLE_SIZE)
128
129 // LED Control
130 // assoiation ON. one LED ON. another blinking when TX, OFF when idle
131 // no association, both LED off
132 #define ASIC_LED_ACT_ON(pAd)        RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46)
133 #define ASIC_LED_ACT_OFF(pAd)       RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46)
134
135 // bit definition of the 2-byte pBEACON->Capability field
136 #define CAP_IS_ESS_ON(x)                 (((x) & 0x0001) != 0)
137 #define CAP_IS_IBSS_ON(x)                (((x) & 0x0002) != 0)
138 #define CAP_IS_CF_POLLABLE_ON(x)         (((x) & 0x0004) != 0)
139 #define CAP_IS_CF_POLL_REQ_ON(x)         (((x) & 0x0008) != 0)
140 #define CAP_IS_PRIVACY_ON(x)             (((x) & 0x0010) != 0)
141 #define CAP_IS_SHORT_PREAMBLE_ON(x)      (((x) & 0x0020) != 0)
142 #define CAP_IS_PBCC_ON(x)                (((x) & 0x0040) != 0)
143 #define CAP_IS_AGILITY_ON(x)             (((x) & 0x0080) != 0)
144 #define CAP_IS_SPECTRUM_MGMT(x)          (((x) & 0x0100) != 0)  // 802.11e d9
145 #define CAP_IS_QOS(x)                    (((x) & 0x0200) != 0)  // 802.11e d9
146 #define CAP_IS_SHORT_SLOT(x)             (((x) & 0x0400) != 0)
147 #define CAP_IS_APSD(x)                   (((x) & 0x0800) != 0)  // 802.11e d9
148 #define CAP_IS_IMMED_BA(x)               (((x) & 0x1000) != 0)  // 802.11e d9
149 #define CAP_IS_DSSS_OFDM(x)              (((x) & 0x2000) != 0)
150 #define CAP_IS_DELAY_BA(x)               (((x) & 0x4000) != 0)  // 802.11e d9
151
152 #define CAP_GENERATE(ess,ibss,priv,s_pre,s_slot,spectrum)  (((ess) ? 0x0001 : 0x0000) | ((ibss) ? 0x0002 : 0x0000) | ((priv) ? 0x0010 : 0x0000) | ((s_pre) ? 0x0020 : 0x0000) | ((s_slot) ? 0x0400 : 0x0000) | ((spectrum) ? 0x0100 : 0x0000))
153
154 #define ERP_IS_NON_ERP_PRESENT(x)        (((x) & 0x01) != 0)    // 802.11g
155 #define ERP_IS_USE_PROTECTION(x)         (((x) & 0x02) != 0)    // 802.11g
156 #define ERP_IS_USE_BARKER_PREAMBLE(x)    (((x) & 0x04) != 0)    // 802.11g
157
158 #define DRS_TX_QUALITY_WORST_BOUND       8// 3  // just test by gary
159 #define DRS_PENALTY                      8
160
161 #define BA_NOTUSE       2
162 //BA Policy subfiled value in ADDBA frame
163 #define IMMED_BA        1
164 #define DELAY_BA        0
165
166 // BA Initiator subfield in DELBA frame
167 #define ORIGINATOR      1
168 #define RECIPIENT       0
169
170 // ADDBA Status Code
171 #define ADDBA_RESULTCODE_SUCCESS                                        0
172 #define ADDBA_RESULTCODE_REFUSED                                        37
173 #define ADDBA_RESULTCODE_INVALID_PARAMETERS                     38
174
175 // DELBA Reason Code
176 #define DELBA_REASONCODE_QSTA_LEAVING                           36
177 #define DELBA_REASONCODE_END_BA                                         37
178 #define DELBA_REASONCODE_UNKNOWN_BA                                     38
179 #define DELBA_REASONCODE_TIMEOUT                                        39
180
181 // reset all OneSecTx counters
182 #define RESET_ONE_SEC_TX_CNT(__pEntry) \
183 if (((__pEntry)) != NULL) \
184 { \
185         (__pEntry)->OneSecTxRetryOkCount = 0; \
186         (__pEntry)->OneSecTxFailCount = 0; \
187         (__pEntry)->OneSecTxNoRetryOkCount = 0; \
188 }
189
190 //
191 // 802.11 frame formats
192 //
193 //  HT Capability INFO field in HT Cap IE .
194 typedef struct PACKED {
195         USHORT  AdvCoding:1;
196         USHORT  ChannelWidth:1;
197         USHORT  MimoPs:2;//momi power safe
198         USHORT  GF:1;   //green field
199         USHORT  ShortGIfor20:1;
200         USHORT  ShortGIfor40:1; //for40MHz
201         USHORT  TxSTBC:1;
202         USHORT  RxSTBC:2;
203         USHORT  DelayedBA:1;    //rt2860c not support
204         USHORT  AMsduSize:1;    // only support as zero
205         USHORT  CCKmodein40:1;
206         USHORT  PSMP:1;
207         USHORT  Forty_Mhz_Intolerant:1;
208         USHORT  LSIGTxopProSup:1;
209 } HT_CAP_INFO, *PHT_CAP_INFO;
210
211 //  HT Capability INFO field in HT Cap IE .
212 typedef struct PACKED {
213         UCHAR   MaxRAmpduFactor:2;
214         UCHAR   MpduDensity:3;
215         UCHAR   rsv:3;//momi power safe
216 } HT_CAP_PARM, *PHT_CAP_PARM;
217
218 //  HT Capability INFO field in HT Cap IE .
219 typedef struct PACKED {
220         UCHAR   MCSSet[10];
221         UCHAR   SupRate[2];  // unit : 1Mbps
222         UCHAR   TxMCSSetDefined:1;
223         UCHAR   TxRxNotEqual:1;
224         UCHAR   TxStream:2;
225         UCHAR   MpduDensity:1;
226         UCHAR   rsv:3;
227         UCHAR   rsv3[3];
228 } HT_MCS_SET, *PHT_MCS_SET;
229
230 //  HT Capability INFO field in HT Cap IE .
231 typedef struct PACKED {
232         USHORT  Pco:1;
233         USHORT  TranTime:2;
234         USHORT  rsv:5;//momi power safe
235         USHORT  MCSFeedback:2;  //0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback,  1:rsv.
236         USHORT  PlusHTC:1;      //+HTC control field support
237         USHORT  RDGSupport:1;   //reverse Direction Grant  support
238         USHORT  rsv2:4;
239 } EXT_HT_CAP_INFO, *PEXT_HT_CAP_INFO;
240
241 //  HT Beamforming field in HT Cap IE .
242 typedef struct PACKED _HT_BF_CAP{
243         ULONG   TxBFRecCapable:1;
244         ULONG   RxSoundCapable:1;
245         ULONG   TxSoundCapable:1;
246         ULONG   RxNDPCapable:1;
247         ULONG   TxNDPCapable:1;
248         ULONG   ImpTxBFCapable:1;
249         ULONG   Calibration:2;
250         ULONG   ExpCSICapable:1;
251         ULONG   ExpNoComSteerCapable:1;
252         ULONG   ExpComSteerCapable:1;
253         ULONG   ExpCSIFbk:2;
254         ULONG   ExpNoComBF:2;
255         ULONG   ExpComBF:2;
256         ULONG   MinGrouping:2;
257         ULONG   CSIBFAntSup:2;
258         ULONG   NoComSteerBFAntSup:2;
259         ULONG   ComSteerBFAntSup:2;
260         ULONG   CSIRowBFSup:2;
261         ULONG   ChanEstimation:2;
262         ULONG   rsv:3;
263 } HT_BF_CAP, *PHT_BF_CAP;
264
265 //  HT antenna selection field in HT Cap IE .
266 typedef struct PACKED _HT_AS_CAP{
267         UCHAR   AntSelect:1;
268         UCHAR   ExpCSIFbkTxASEL:1;
269         UCHAR   AntIndFbkTxASEL:1;
270         UCHAR   ExpCSIFbk:1;
271         UCHAR   AntIndFbk:1;
272         UCHAR   RxASel:1;
273         UCHAR   TxSoundPPDU:1;
274         UCHAR   rsv:1;
275 } HT_AS_CAP, *PHT_AS_CAP;
276
277 // Draft 1.0 set IE length 26, but is extensible..
278 #define SIZE_HT_CAP_IE          26
279 // The structure for HT Capability IE.
280 typedef struct PACKED _HT_CAPABILITY_IE{
281         HT_CAP_INFO             HtCapInfo;
282         HT_CAP_PARM             HtCapParm;
283 //      HT_MCS_SET              HtMCSSet;
284         UCHAR                   MCSSet[16];
285         EXT_HT_CAP_INFO ExtHtCapInfo;
286         HT_BF_CAP               TxBFCap;        // beamforming cap. rt2860c not support beamforming.
287         HT_AS_CAP               ASCap;  //antenna selection.
288 } HT_CAPABILITY_IE, *PHT_CAPABILITY_IE;
289
290
291 // 802.11n draft3 related structure definitions.
292 // 7.3.2.60
293 #define dot11OBSSScanPassiveDwell                                                       20      // in TU. min amount of time that the STA continously scans each channel when performing an active OBSS scan.
294 #define dot11OBSSScanActiveDwell                                                        10      // in TU.min amount of time that the STA continously scans each channel when performing an passive OBSS scan.
295 #define dot11BSSWidthTriggerScanInterval                                        300  // in sec. max interval between scan operations to be performed to detect BSS channel width trigger events.
296 #define dot11OBSSScanPassiveTotalPerChannel                                     200     // in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan.
297 #define dot11OBSSScanActiveTotalPerChannel                                      20      //in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan
298 #define dot11BSSWidthChannelTransactionDelayFactor                      5       // min ratio between the delay time in performing a switch from 20MHz BSS to 20/40 BSS operation and the maximum
299                                                                                                                                 //      interval between overlapping BSS scan operations.
300 #define dot11BSSScanActivityThreshold                                           25      // in %%, max total time that a STA may be active on the medium during a period of
301                                                                                                                                 //      (dot11BSSWidthChannelTransactionDelayFactor * dot11BSSWidthTriggerScanInterval) seconds without
302                                                                                                                                 //      being obligated to perform OBSS Scan operations. default is 25(== 0.25%)
303
304 typedef struct PACKED _OVERLAP_BSS_SCAN_IE{
305         USHORT          ScanPassiveDwell;
306         USHORT          ScanActiveDwell;
307         USHORT          TriggerScanInt;                         // Trigger scan interval
308         USHORT          PassiveTalPerChannel;           // passive total per channel
309         USHORT          ActiveTalPerChannel;            // active total per channel
310         USHORT          DelayFactor;                            // BSS width channel transition delay factor
311         USHORT          ScanActThre;                            // Scan Activity threshold
312 }OVERLAP_BSS_SCAN_IE, *POVERLAP_BSS_SCAN_IE;
313
314
315 //  7.3.2.56. 20/40 Coexistence element used in  Element ID = 72 = IE_2040_BSS_COEXIST
316 typedef union PACKED _BSS_2040_COEXIST_IE{
317  struct PACKED {
318         UCHAR   InfoReq:1;
319         UCHAR   Intolerant40:1;                 // Inter-BSS. set 1 when prohibits a receiving BSS from operating as a 20/40 Mhz BSS.
320         UCHAR   BSS20WidthReq:1;                // Intra-BSS set 1 when prohibits a receiving AP from operating its BSS as a 20/40MHz BSS.
321         UCHAR   rsv:5;
322     } field;
323  UCHAR   word;
324 } BSS_2040_COEXIST_IE, *PBSS_2040_COEXIST_IE;
325
326
327 typedef struct  _TRIGGER_EVENTA{
328         BOOLEAN                 bValid;
329         UCHAR   BSSID[6];
330         UCHAR   RegClass;       // Regulatory Class
331         USHORT  Channel;
332         ULONG   CDCounter;   // Maintain a seperate count down counter for each Event A.
333 } TRIGGER_EVENTA, *PTRIGGER_EVENTA;
334
335 // 20/40 trigger event table
336 // If one Event A delete or created, or if Event B is detected or not detected, STA should send 2040BSSCoexistence to AP.
337 #define MAX_TRIGGER_EVENT               64
338 typedef struct  _TRIGGER_EVENT_TAB{
339         UCHAR   EventANo;
340         TRIGGER_EVENTA  EventA[MAX_TRIGGER_EVENT];
341         ULONG                   EventBCountDown;        // Count down counter for Event B.
342 } TRIGGER_EVENT_TAB, *PTRIGGER_EVENT_TAB;
343
344 // 7.3.27 20/40 Bss Coexistence Mgmt capability used in extended capabilities information IE( ID = 127 = IE_EXT_CAPABILITY).
345 //      This is the first octet and was defined in 802.11n D3.03 and 802.11yD9.0
346 typedef struct PACKED _EXT_CAP_INFO_ELEMENT{
347         UCHAR   BssCoexistMgmtSupport:1;
348         UCHAR   rsv:1;
349         UCHAR   ExtendChannelSwitch:1;
350         UCHAR   rsv2:5;
351 }EXT_CAP_INFO_ELEMENT, *PEXT_CAP_INFO_ELEMENT;
352
353
354 // 802.11n 7.3.2.61
355 typedef struct PACKED _BSS_2040_COEXIST_ELEMENT{
356         UCHAR                                   ElementID;              // ID = IE_2040_BSS_COEXIST = 72
357         UCHAR                                   Len;
358         BSS_2040_COEXIST_IE             BssCoexistIe;
359 }BSS_2040_COEXIST_ELEMENT, *PBSS_2040_COEXIST_ELEMENT;
360
361
362 //802.11n 7.3.2.59
363 typedef struct PACKED _BSS_2040_INTOLERANT_CH_REPORT{
364         UCHAR                           ElementID;              // ID = IE_2040_BSS_INTOLERANT_REPORT = 73
365         UCHAR                           Len;
366         UCHAR                           RegulatoryClass;
367         UCHAR                           ChList[0];
368 }BSS_2040_INTOLERANT_CH_REPORT, *PBSS_2040_INTOLERANT_CH_REPORT;
369
370
371 // The structure for channel switch annoucement IE. This is in 802.11n D3.03
372 typedef struct PACKED _CHA_SWITCH_ANNOUNCE_IE{
373         UCHAR                   SwitchMode;     //channel switch mode
374         UCHAR                   NewChannel;     //
375         UCHAR                   SwitchCount;    //
376 } CHA_SWITCH_ANNOUNCE_IE, *PCHA_SWITCH_ANNOUNCE_IE;
377
378
379 // The structure for channel switch annoucement IE. This is in 802.11n D3.03
380 typedef struct PACKED _SEC_CHA_OFFSET_IE{
381         UCHAR                   SecondaryChannelOffset;  // 1: Secondary above, 3: Secondary below, 0: no Secondary
382 } SEC_CHA_OFFSET_IE, *PSEC_CHA_OFFSET_IE;
383
384
385 // This structure is extracted from struct RT_HT_CAPABILITY
386 typedef struct {
387         BOOLEAN                 bHtEnable;       // If we should use ht rate.
388         BOOLEAN                 bPreNHt;         // If we should use ht rate.
389         //Substract from HT Capability IE
390         UCHAR                   MCSSet[16];
391 } RT_HT_PHY_INFO, *PRT_HT_PHY_INFO;
392
393 //This structure substracts ralink supports from all 802.11n-related features.
394 //Features not listed here but contained in 802.11n spec are not supported in rt2860.
395 typedef struct {
396         USHORT  ChannelWidth:1;
397         USHORT  MimoPs:2;//mimo power safe MMPS_
398         USHORT  GF:1;   //green field
399         USHORT  ShortGIfor20:1;
400         USHORT  ShortGIfor40:1; //for40MHz
401         USHORT  TxSTBC:1;
402         USHORT  RxSTBC:2;       // 2 bits
403         USHORT  AmsduEnable:1;  // Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n
404         USHORT  AmsduSize:1;    // Max receiving A-MSDU size
405         USHORT  rsv:5;
406
407         //Substract from Addiont HT INFO IE
408         UCHAR   MaxRAmpduFactor:2;
409         UCHAR   MpduDensity:3;
410         UCHAR   ExtChanOffset:2;        // Please not the difference with following     UCHAR   NewExtChannelOffset; from 802.11n
411         UCHAR   RecomWidth:1;
412
413         USHORT  OperaionMode:2;
414         USHORT  NonGfPresent:1;
415         USHORT  rsv3:1;
416         USHORT  OBSS_NonHTExist:1;
417         USHORT  rsv2:11;
418
419         // New Extension Channel Offset IE
420         UCHAR   NewExtChannelOffset;
421         // Extension Capability IE = 127
422         UCHAR   BSSCoexist2040;
423 } RT_HT_CAPABILITY, *PRT_HT_CAPABILITY;
424
425 //   field in Addtional HT Information IE .
426 typedef struct PACKED {
427         UCHAR   ExtChanOffset:2;
428         UCHAR   RecomWidth:1;
429         UCHAR   RifsMode:1;
430         UCHAR   S_PSMPSup:1;     //Indicate support for scheduled PSMP
431         UCHAR   SerInterGranu:3;         //service interval granularity
432 } ADD_HTINFO, *PADD_HTINFO;
433
434 typedef struct PACKED{
435         USHORT  OperaionMode:2;
436         USHORT  NonGfPresent:1;
437         USHORT  rsv:1;
438         USHORT  OBSS_NonHTExist:1;
439         USHORT  rsv2:11;
440 } ADD_HTINFO2, *PADD_HTINFO2;
441
442
443 // TODO: Need sync with spec about the definition of StbcMcs. In Draft 3.03, it's reserved.
444 typedef struct PACKED{
445         USHORT  StbcMcs:6;
446         USHORT  DualBeacon:1;
447         USHORT  DualCTSProtect:1;
448         USHORT  STBCBeacon:1;
449         USHORT  LsigTxopProt:1; // L-SIG TXOP protection full support
450         USHORT  PcoActive:1;
451         USHORT  PcoPhase:1;
452         USHORT  rsv:4;
453 } ADD_HTINFO3, *PADD_HTINFO3;
454
455 #define SIZE_ADD_HT_INFO_IE             22
456 typedef struct  PACKED{
457         UCHAR                           ControlChan;
458         ADD_HTINFO                      AddHtInfo;
459         ADD_HTINFO2                     AddHtInfo2;
460         ADD_HTINFO3                     AddHtInfo3;
461         UCHAR                           MCSSet[16];             // Basic MCS set
462 } ADD_HT_INFO_IE, *PADD_HT_INFO_IE;
463
464 typedef struct  PACKED{
465         UCHAR                           NewExtChanOffset;
466 } NEW_EXT_CHAN_IE, *PNEW_EXT_CHAN_IE;
467
468 typedef struct PACKED _FRAME_802_11 {
469     HEADER_802_11   Hdr;
470     UCHAR            Octet[1];
471 }   FRAME_802_11, *PFRAME_802_11;
472
473 // QoSNull embedding of management action. When HT Control MA field set to 1.
474 typedef struct PACKED _MA_BODY {
475     UCHAR            Category;
476     UCHAR            Action;
477     UCHAR            Octet[1];
478 }   MA_BODY, *PMA_BODY;
479
480 typedef struct  PACKED _HEADER_802_3    {
481     UCHAR           DAAddr1[MAC_ADDR_LEN];
482     UCHAR           SAAddr2[MAC_ADDR_LEN];
483     UCHAR           Octet[2];
484 }       HEADER_802_3, *PHEADER_802_3;
485 ////Block ACK related format
486 // 2-byte BA Parameter  field  in       DELBA frames to terminate an already set up bA
487 typedef struct PACKED{
488     USHORT      Rsv:11; // always set to 0
489     USHORT      Initiator:1;    // 1: originator    0:recipient
490     USHORT      TID:4;  // value of TC os TS
491 } DELBA_PARM, *PDELBA_PARM;
492
493 // 2-byte BA Parameter Set field  in ADDBA frames to signal parm for setting up a BA
494 typedef struct PACKED {
495     USHORT      AMSDUSupported:1;       // 0: not permitted             1: permitted
496     USHORT      BAPolicy:1;     // 1: immediately BA    0:delayed BA
497     USHORT      TID:4;  // value of TC os TS
498     USHORT      BufSize:10;     // number of buffe of size 2304 octetsr
499 } BA_PARM, *PBA_PARM;
500
501 // 2-byte BA Starting Seq CONTROL field
502 typedef union PACKED {
503     struct PACKED {
504     USHORT      FragNum:4;      // always set to 0
505         USHORT      StartSeq:12;   // sequence number of the 1st MSDU for which this BAR is sent
506     }   field;
507     USHORT           word;
508 } BASEQ_CONTROL, *PBASEQ_CONTROL;
509
510 //BAControl and BARControl are the same
511 // 2-byte BA CONTROL field in BA frame
512 typedef struct PACKED {
513     USHORT      ACKPolicy:1; // only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK  1:No ACK
514     USHORT      MTID:1;         //EWC V1.24
515     USHORT      Compressed:1;
516     USHORT      Rsv:9;
517     USHORT      TID:4;
518 } BA_CONTROL, *PBA_CONTROL;
519
520 // 2-byte BAR CONTROL field in BAR frame
521 typedef struct PACKED {
522     USHORT      ACKPolicy:1; // 0:normal ack,  1:no ack.
523     USHORT      MTID:1;         //if this bit1, use  FRAME_MTBA_REQ,  if 0, use FRAME_BA_REQ
524     USHORT      Compressed:1;
525     USHORT      Rsv1:9;
526     USHORT      TID:4;
527 } BAR_CONTROL, *PBAR_CONTROL;
528
529 // BARControl in MTBAR frame
530 typedef struct PACKED {
531     USHORT      ACKPolicy:1;
532     USHORT      MTID:1;
533     USHORT      Compressed:1;
534     USHORT      Rsv1:9;
535     USHORT      NumTID:4;
536 } MTBAR_CONTROL, *PMTBAR_CONTROL;
537
538 typedef struct PACKED {
539     USHORT      Rsv1:12;
540     USHORT      TID:4;
541 } PER_TID_INFO, *PPER_TID_INFO;
542
543 typedef struct {
544         PER_TID_INFO      PerTID;
545         BASEQ_CONTROL    BAStartingSeq;
546 } EACH_TID, *PEACH_TID;
547
548
549 // BAREQ AND MTBAREQ have the same subtype BAR, 802.11n BAR use compressed bitmap.
550 typedef struct PACKED _FRAME_BA_REQ {
551         FRAME_CONTROL   FC;
552         USHORT          Duration;
553         UCHAR           Addr1[MAC_ADDR_LEN];
554         UCHAR           Addr2[MAC_ADDR_LEN];
555         BAR_CONTROL  BARControl;
556         BASEQ_CONTROL    BAStartingSeq;
557 }   FRAME_BA_REQ, *PFRAME_BA_REQ;
558
559 typedef struct PACKED _FRAME_MTBA_REQ {
560         FRAME_CONTROL   FC;
561         USHORT          Duration;
562         UCHAR           Addr1[MAC_ADDR_LEN];
563         UCHAR           Addr2[MAC_ADDR_LEN];
564         MTBAR_CONTROL  MTBARControl;
565         PER_TID_INFO    PerTIDInfo;
566         BASEQ_CONTROL    BAStartingSeq;
567 }   FRAME_MTBA_REQ, *PFRAME_MTBA_REQ;
568
569 // Compressed format is mandantory in HT STA
570 typedef struct PACKED _FRAME_MTBA {
571         FRAME_CONTROL   FC;
572         USHORT          Duration;
573         UCHAR           Addr1[MAC_ADDR_LEN];
574         UCHAR           Addr2[MAC_ADDR_LEN];
575         BA_CONTROL  BAControl;
576         BASEQ_CONTROL    BAStartingSeq;
577         UCHAR           BitMap[8];
578 }   FRAME_MTBA, *PFRAME_MTBA;
579
580 typedef struct PACKED _FRAME_PSMP_ACTION {
581         HEADER_802_11   Hdr;
582         UCHAR   Category;
583         UCHAR   Action;
584         UCHAR   Psmp;   // 7.3.1.25
585 }   FRAME_PSMP_ACTION, *PFRAME_PSMP_ACTION;
586
587 typedef struct PACKED _FRAME_ACTION_HDR {
588         HEADER_802_11   Hdr;
589         UCHAR   Category;
590         UCHAR   Action;
591 }   FRAME_ACTION_HDR, *PFRAME_ACTION_HDR;
592
593 //Action Frame
594 //Action Frame  Category:Spectrum,  Action:Channel Switch. 7.3.2.20
595 typedef struct PACKED _CHAN_SWITCH_ANNOUNCE {
596         UCHAR                                   ElementID;      // ID = IE_CHANNEL_SWITCH_ANNOUNCEMENT = 37
597         UCHAR                                   Len;
598         CHA_SWITCH_ANNOUNCE_IE  CSAnnounceIe;
599 }   CHAN_SWITCH_ANNOUNCE, *PCHAN_SWITCH_ANNOUNCE;
600
601
602 //802.11n : 7.3.2.20a
603 typedef struct PACKED _SECOND_CHAN_OFFSET {
604         UCHAR                           ElementID;              // ID = IE_SECONDARY_CH_OFFSET = 62
605         UCHAR                           Len;
606         SEC_CHA_OFFSET_IE       SecChOffsetIe;
607 }   SECOND_CHAN_OFFSET, *PSECOND_CHAN_OFFSET;
608
609
610 typedef struct PACKED _FRAME_SPETRUM_CS {
611         HEADER_802_11   Hdr;
612         UCHAR   Category;
613         UCHAR   Action;
614         CHAN_SWITCH_ANNOUNCE    CSAnnounce;
615         SECOND_CHAN_OFFSET              SecondChannel;
616 }   FRAME_SPETRUM_CS, *PFRAME_SPETRUM_CS;
617
618
619 typedef struct PACKED _FRAME_ADDBA_REQ {
620         HEADER_802_11   Hdr;
621         UCHAR   Category;
622         UCHAR   Action;
623         UCHAR   Token;  // 1
624         BA_PARM         BaParm;       //  2 - 10
625         USHORT          TimeOutValue;   // 0 - 0
626         BASEQ_CONTROL   BaStartSeq; // 0-0
627 }   FRAME_ADDBA_REQ, *PFRAME_ADDBA_REQ;
628
629 typedef struct PACKED _FRAME_ADDBA_RSP {
630         HEADER_802_11   Hdr;
631         UCHAR   Category;
632         UCHAR   Action;
633         UCHAR   Token;
634         USHORT  StatusCode;
635         BA_PARM         BaParm; //0 - 2
636         USHORT          TimeOutValue;
637 }   FRAME_ADDBA_RSP, *PFRAME_ADDBA_RSP;
638
639 typedef struct PACKED _FRAME_DELBA_REQ {
640         HEADER_802_11   Hdr;
641         UCHAR   Category;
642         UCHAR   Action;
643         DELBA_PARM              DelbaParm;
644         USHORT  ReasonCode;
645 }   FRAME_DELBA_REQ, *PFRAME_DELBA_REQ;
646
647
648 //7.2.1.7
649 typedef struct PACKED _FRAME_BAR {
650         FRAME_CONTROL   FC;
651         USHORT          Duration;
652         UCHAR           Addr1[MAC_ADDR_LEN];
653         UCHAR           Addr2[MAC_ADDR_LEN];
654         BAR_CONTROL             BarControl;
655         BASEQ_CONTROL   StartingSeq;
656 }   FRAME_BAR, *PFRAME_BAR;
657
658 //7.2.1.7
659 typedef struct PACKED _FRAME_BA {
660         FRAME_CONTROL   FC;
661         USHORT          Duration;
662         UCHAR           Addr1[MAC_ADDR_LEN];
663         UCHAR           Addr2[MAC_ADDR_LEN];
664         BAR_CONTROL             BarControl;
665         BASEQ_CONTROL   StartingSeq;
666         UCHAR           bitmask[8];
667 }   FRAME_BA, *PFRAME_BA;
668
669
670 // Radio Measuement Request Frame Format
671 typedef struct PACKED _FRAME_RM_REQ_ACTION {
672         HEADER_802_11   Hdr;
673         UCHAR   Category;
674         UCHAR   Action;
675         UCHAR   Token;
676         USHORT  Repetition;
677         UCHAR   data[0];
678 }   FRAME_RM_REQ_ACTION, *PFRAME_RM_REQ_ACTION;
679
680 typedef struct PACKED {
681         UCHAR           ID;
682         UCHAR           Length;
683         UCHAR           ChannelSwitchMode;
684         UCHAR           NewRegClass;
685         UCHAR           NewChannelNum;
686         UCHAR           ChannelSwitchCount;
687 } HT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE, *PHT_EXT_CHANNEL_SWITCH_ANNOUNCEMENT_IE;
688
689
690 //
691 // _Limit must be the 2**n - 1
692 // _SEQ1 , _SEQ2 must be within 0 ~ _Limit
693 //
694 #define SEQ_STEPONE(_SEQ1, _SEQ2, _Limit)       ((_SEQ1 == ((_SEQ2+1) & _Limit)))
695 #define SEQ_SMALLER(_SEQ1, _SEQ2, _Limit)       (((_SEQ1-_SEQ2) & ((_Limit+1)>>1)))
696 #define SEQ_LARGER(_SEQ1, _SEQ2, _Limit)        ((_SEQ1 != _SEQ2) && !(((_SEQ1-_SEQ2) & ((_Limit+1)>>1))))
697 #define SEQ_WITHIN_WIN(_SEQ1, _SEQ2, _WIN, _Limit) (SEQ_LARGER(_SEQ1, _SEQ2, _Limit) &&  \
698                                                                                                 SEQ_SMALLER(_SEQ1, ((_SEQ2+_WIN+1)&_Limit), _Limit))
699
700 //
701 // Contention-free parameter (without ID and Length)
702 //
703 typedef struct PACKED {
704     BOOLEAN     bValid;         // 1: variable contains valid value
705     UCHAR       CfpCount;
706     UCHAR       CfpPeriod;
707     USHORT      CfpMaxDuration;
708     USHORT      CfpDurRemaining;
709 } CF_PARM, *PCF_PARM;
710
711 typedef struct  _CIPHER_SUITE   {
712         NDIS_802_11_ENCRYPTION_STATUS   PairCipher;             // Unicast cipher 1, this one has more secured cipher suite
713         NDIS_802_11_ENCRYPTION_STATUS   PairCipherAux;  // Unicast cipher 2 if AP announce two unicast cipher suite
714         NDIS_802_11_ENCRYPTION_STATUS   GroupCipher;    // Group cipher
715         USHORT                                                  RsnCapability;  // RSN capability from beacon
716         BOOLEAN                                                 bMixMode;               // Indicate Pair & Group cipher might be different
717 }       CIPHER_SUITE, *PCIPHER_SUITE;
718
719 // EDCA configuration from AP's BEACON/ProbeRsp
720 typedef struct {
721     BOOLEAN     bValid;         // 1: variable contains valid value
722     BOOLEAN     bAdd;         // 1: variable contains valid value
723     BOOLEAN     bQAck;
724     BOOLEAN     bQueueRequest;
725     BOOLEAN     bTxopRequest;
726     BOOLEAN     bAPSDCapable;
727 //  BOOLEAN     bMoreDataAck;
728     UCHAR       EdcaUpdateCount;
729     UCHAR       Aifsn[4];       // 0:AC_BK, 1:AC_BE, 2:AC_VI, 3:AC_VO
730     UCHAR       Cwmin[4];
731     UCHAR       Cwmax[4];
732     USHORT      Txop[4];      // in unit of 32-us
733     BOOLEAN     bACM[4];      // 1: Admission Control of AC_BK is mandattory
734 } EDCA_PARM, *PEDCA_PARM;
735
736 // QBSS LOAD information from QAP's BEACON/ProbeRsp
737 typedef struct {
738     BOOLEAN     bValid;                     // 1: variable contains valid value
739     USHORT      StaNum;
740     UCHAR       ChannelUtilization;
741     USHORT      RemainingAdmissionControl;  // in unit of 32-us
742 } QBSS_LOAD_PARM, *PQBSS_LOAD_PARM;
743
744 // QBSS Info field in QSTA's assoc req
745 typedef struct PACKED {
746     UCHAR               UAPSD_AC_VO:1;
747         UCHAR           UAPSD_AC_VI:1;
748         UCHAR           UAPSD_AC_BK:1;
749         UCHAR           UAPSD_AC_BE:1;
750         UCHAR           Rsv1:1;
751         UCHAR           MaxSPLength:2;
752         UCHAR           Rsv2:1;
753 } QBSS_STA_INFO_PARM, *PQBSS_STA_INFO_PARM;
754
755 // QBSS Info field in QAP's Beacon/ProbeRsp
756 typedef struct PACKED {
757     UCHAR               ParamSetCount:4;
758         UCHAR           Rsv:3;
759         UCHAR           UAPSD:1;
760 } QBSS_AP_INFO_PARM, *PQBSS_AP_INFO_PARM;
761
762 // QOS Capability reported in QAP's BEACON/ProbeRsp
763 // QOS Capability sent out in QSTA's AssociateReq/ReAssociateReq
764 typedef struct {
765     BOOLEAN     bValid;                     // 1: variable contains valid value
766     BOOLEAN     bQAck;
767     BOOLEAN     bQueueRequest;
768     BOOLEAN     bTxopRequest;
769 //  BOOLEAN     bMoreDataAck;
770     UCHAR       EdcaUpdateCount;
771 } QOS_CAPABILITY_PARM, *PQOS_CAPABILITY_PARM;
772
773 typedef struct {
774     UCHAR       IELen;
775     UCHAR       IE[MAX_CUSTOM_LEN];
776 } WPA_IE_;
777
778 typedef struct {
779     UCHAR   Bssid[MAC_ADDR_LEN];
780     UCHAR   Channel;
781         UCHAR   CentralChannel; //Store the wide-band central channel for 40MHz.  .used in 40MHz AP. Or this is the same as Channel.
782     UCHAR   BssType;
783     USHORT  AtimWin;
784     USHORT  BeaconPeriod;
785
786     UCHAR   SupRate[MAX_LEN_OF_SUPPORTED_RATES];
787     UCHAR   SupRateLen;
788     UCHAR   ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
789     UCHAR   ExtRateLen;
790         HT_CAPABILITY_IE HtCapability;
791         UCHAR                   HtCapabilityLen;
792         ADD_HT_INFO_IE AddHtInfo;       // AP might use this additional ht info IE
793         UCHAR                   AddHtInfoLen;
794         UCHAR                   NewExtChanOffset;
795         CHAR    Rssi;
796     UCHAR   Privacy;                    // Indicate security function ON/OFF. Don't mess up with auth mode.
797         UCHAR   Hidden;
798
799     USHORT  DtimPeriod;
800     USHORT  CapabilityInfo;
801
802     USHORT  CfpCount;
803     USHORT  CfpPeriod;
804     USHORT  CfpMaxDuration;
805     USHORT  CfpDurRemaining;
806     UCHAR   SsidLen;
807     CHAR    Ssid[MAX_LEN_OF_SSID];
808
809     ULONG   LastBeaconRxTime; // OS's timestamp
810
811         BOOLEAN bSES;
812
813         // New for WPA2
814         CIPHER_SUITE                                    WPA;                    // AP announced WPA cipher suite
815         CIPHER_SUITE                                    WPA2;                   // AP announced WPA2 cipher suite
816
817         // New for microsoft WPA support
818         NDIS_802_11_FIXED_IEs   FixIEs;
819         NDIS_802_11_AUTHENTICATION_MODE AuthModeAux;    // Addition mode for WPA2 / WPA capable AP
820         NDIS_802_11_AUTHENTICATION_MODE AuthMode;
821         NDIS_802_11_WEP_STATUS  WepStatus;                              // Unicast Encryption Algorithm extract from VAR_IE
822         USHORT                                  VarIELen;                               // Length of next VIE include EID & Length
823         UCHAR                                   VarIEs[MAX_VIE_LEN];
824
825         // CCX Ckip information
826     UCHAR   CkipFlag;
827
828         // CCX 2 TSF
829         UCHAR   PTSF[4];                // Parent TSF
830         UCHAR   TTSF[8];                // Target TSF
831
832     // 802.11e d9, and WMM
833         EDCA_PARM           EdcaParm;
834         QOS_CAPABILITY_PARM QosCapability;
835         QBSS_LOAD_PARM      QbssLoad;
836     WPA_IE_     WpaIE;
837     WPA_IE_     RsnIE;
838 } BSS_ENTRY, *PBSS_ENTRY;
839
840 typedef struct {
841     UCHAR           BssNr;
842     UCHAR           BssOverlapNr;
843     BSS_ENTRY       BssEntry[MAX_LEN_OF_BSS_TABLE];
844 } BSS_TABLE, *PBSS_TABLE;
845
846
847 typedef struct _MLME_QUEUE_ELEM {
848     ULONG             Machine;
849     ULONG             MsgType;
850     ULONG             MsgLen;
851     UCHAR             Msg[MGMT_DMA_BUFFER_SIZE];
852     LARGE_INTEGER     TimeStamp;
853     UCHAR             Rssi0;
854     UCHAR             Rssi1;
855     UCHAR             Rssi2;
856     UCHAR             Signal;
857     UCHAR             Channel;
858     UCHAR             Wcid;
859     BOOLEAN           Occupied;
860 } MLME_QUEUE_ELEM, *PMLME_QUEUE_ELEM;
861
862 typedef struct _MLME_QUEUE {
863     ULONG             Num;
864     ULONG             Head;
865     ULONG             Tail;
866     NDIS_SPIN_LOCK   Lock;
867     MLME_QUEUE_ELEM  Entry[MAX_LEN_OF_MLME_QUEUE];
868 } MLME_QUEUE, *PMLME_QUEUE;
869
870 typedef VOID (*STATE_MACHINE_FUNC)(VOID *Adaptor, MLME_QUEUE_ELEM *Elem);
871
872 typedef struct _STATE_MACHINE {
873     ULONG                           Base;
874     ULONG                           NrState;
875     ULONG                           NrMsg;
876     ULONG                           CurrState;
877     STATE_MACHINE_FUNC             *TransFunc;
878 } STATE_MACHINE, *PSTATE_MACHINE;
879
880
881 // MLME AUX data structure that hold temporarliy settings during a connection attempt.
882 // Once this attemp succeeds, all settings will be copy to pAd->StaActive.
883 // A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of
884 // several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely
885 // separate this under-trial settings away from pAd->StaActive so that once
886 // this new attempt failed, driver can auto-recover back to the active settings.
887 typedef struct _MLME_AUX {
888     UCHAR               BssType;
889     UCHAR               Ssid[MAX_LEN_OF_SSID];
890     UCHAR               SsidLen;
891     UCHAR               Bssid[MAC_ADDR_LEN];
892         UCHAR                           AutoReconnectSsid[MAX_LEN_OF_SSID];
893         UCHAR                           AutoReconnectSsidLen;
894     USHORT              Alg;
895     UCHAR               ScanType;
896     UCHAR               Channel;
897         UCHAR               CentralChannel;
898     USHORT              Aid;
899     USHORT              CapabilityInfo;
900     USHORT              BeaconPeriod;
901     USHORT              CfpMaxDuration;
902     USHORT              CfpPeriod;
903     USHORT              AtimWin;
904
905         // Copy supported rate from desired AP's beacon. We are trying to match
906         // AP's supported and extended rate settings.
907         UCHAR                   SupRate[MAX_LEN_OF_SUPPORTED_RATES];
908         UCHAR                   ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
909         UCHAR                   SupRateLen;
910         UCHAR                   ExtRateLen;
911         HT_CAPABILITY_IE                HtCapability;
912         UCHAR                           HtCapabilityLen;
913         ADD_HT_INFO_IE          AddHtInfo;      // AP might use this additional ht info IE
914         UCHAR                   NewExtChannelOffset;
915         //RT_HT_CAPABILITY      SupportedHtPhy;
916
917     // new for QOS
918     QOS_CAPABILITY_PARM APQosCapability;    // QOS capability of the current associated AP
919     EDCA_PARM           APEdcaParm;         // EDCA parameters of the current associated AP
920     QBSS_LOAD_PARM      APQbssLoad;         // QBSS load of the current associated AP
921
922     // new to keep Ralink specific feature
923     ULONG               APRalinkIe;
924
925     BSS_TABLE           SsidBssTab;     // AP list for the same SSID
926     BSS_TABLE           RoamTab;        // AP list eligible for roaming
927     ULONG               BssIdx;
928     ULONG               RoamIdx;
929
930         BOOLEAN                         CurrReqIsFromNdis;
931
932     RALINK_TIMER_STRUCT BeaconTimer, ScanTimer;
933     RALINK_TIMER_STRUCT AuthTimer;
934     RALINK_TIMER_STRUCT AssocTimer, ReassocTimer, DisassocTimer;
935 } MLME_AUX, *PMLME_AUX;
936
937 typedef struct _MLME_ADDBA_REQ_STRUCT{
938         UCHAR   Wcid;   //
939         UCHAR   pAddr[MAC_ADDR_LEN];
940         UCHAR   BaBufSize;
941         USHORT  TimeOutValue;
942         UCHAR   TID;
943         UCHAR   Token;
944         USHORT  BaStartSeq;
945 } MLME_ADDBA_REQ_STRUCT, *PMLME_ADDBA_REQ_STRUCT;
946
947
948 typedef struct _MLME_DELBA_REQ_STRUCT{
949         UCHAR   Wcid;   //
950         UCHAR     Addr[MAC_ADDR_LEN];
951         UCHAR   TID;
952         UCHAR   Initiator;
953 } MLME_DELBA_REQ_STRUCT, *PMLME_DELBA_REQ_STRUCT;
954
955 // assoc struct is equal to reassoc
956 typedef struct _MLME_ASSOC_REQ_STRUCT{
957     UCHAR     Addr[MAC_ADDR_LEN];
958     USHORT    CapabilityInfo;
959     USHORT    ListenIntv;
960     ULONG     Timeout;
961 } MLME_ASSOC_REQ_STRUCT, *PMLME_ASSOC_REQ_STRUCT, MLME_REASSOC_REQ_STRUCT, *PMLME_REASSOC_REQ_STRUCT;
962
963 typedef struct _MLME_DISASSOC_REQ_STRUCT{
964     UCHAR     Addr[MAC_ADDR_LEN];
965     USHORT    Reason;
966 } MLME_DISASSOC_REQ_STRUCT, *PMLME_DISASSOC_REQ_STRUCT;
967
968 typedef struct _MLME_AUTH_REQ_STRUCT {
969     UCHAR        Addr[MAC_ADDR_LEN];
970     USHORT       Alg;
971     ULONG        Timeout;
972 } MLME_AUTH_REQ_STRUCT, *PMLME_AUTH_REQ_STRUCT;
973
974 typedef struct _MLME_DEAUTH_REQ_STRUCT {
975     UCHAR        Addr[MAC_ADDR_LEN];
976     USHORT       Reason;
977 } MLME_DEAUTH_REQ_STRUCT, *PMLME_DEAUTH_REQ_STRUCT;
978
979 typedef struct {
980     ULONG      BssIdx;
981 } MLME_JOIN_REQ_STRUCT;
982
983 typedef struct _MLME_SCAN_REQ_STRUCT {
984     UCHAR      Bssid[MAC_ADDR_LEN];
985     UCHAR      BssType;
986     UCHAR      ScanType;
987     UCHAR      SsidLen;
988     CHAR       Ssid[MAX_LEN_OF_SSID];
989 } MLME_SCAN_REQ_STRUCT, *PMLME_SCAN_REQ_STRUCT;
990
991 typedef struct _MLME_START_REQ_STRUCT {
992     CHAR        Ssid[MAX_LEN_OF_SSID];
993     UCHAR       SsidLen;
994 } MLME_START_REQ_STRUCT, *PMLME_START_REQ_STRUCT;
995
996 typedef struct PACKED {
997     UCHAR   Eid;
998     UCHAR   Len;
999     UCHAR   Octet[1];
1000 } EID_STRUCT,*PEID_STRUCT, BEACON_EID_STRUCT, *PBEACON_EID_STRUCT;
1001
1002 typedef struct PACKED _RTMP_TX_RATE_SWITCH
1003 {
1004         UCHAR   ItemNo;
1005         UCHAR   STBC:1;
1006         UCHAR   ShortGI:1;
1007         UCHAR   BW:1;
1008         UCHAR   Rsv1:1;
1009         UCHAR   Mode:2;
1010         UCHAR   Rsv2:2;
1011         UCHAR   CurrMCS;
1012         UCHAR   TrainUp;
1013         UCHAR   TrainDown;
1014 } RRTMP_TX_RATE_SWITCH, *PRTMP_TX_RATE_SWITCH;
1015
1016 // ========================== AP mlme.h ===============================
1017 #define TBTT_PRELOAD_TIME       384        // usec. LomgPreamble + 24-byte at 1Mbps
1018 #define DEFAULT_DTIM_PERIOD     1
1019
1020 #define MAC_TABLE_AGEOUT_TIME                   300                     // unit: sec
1021 #define MAC_TABLE_ASSOC_TIMEOUT                 5                       // unit: sec
1022 #define MAC_TABLE_FULL(Tab)                             ((Tab).size == MAX_LEN_OF_MAC_TABLE)
1023
1024 // AP shall drop the sta if contine Tx fail count reach it.
1025 #define MAC_ENTRY_LIFE_CHECK_CNT                20                      // packet cnt.
1026
1027 // Value domain of pMacEntry->Sst
1028 typedef enum _Sst {
1029     SST_NOT_AUTH,   // 0: equivalent to IEEE 802.11/1999 state 1
1030     SST_AUTH,       // 1: equivalent to IEEE 802.11/1999 state 2
1031     SST_ASSOC       // 2: equivalent to IEEE 802.11/1999 state 3
1032 } SST;
1033
1034 // value domain of pMacEntry->AuthState
1035 typedef enum _AuthState {
1036     AS_NOT_AUTH,
1037     AS_AUTH_OPEN,       // STA has been authenticated using OPEN SYSTEM
1038     AS_AUTH_KEY,        // STA has been authenticated using SHARED KEY
1039     AS_AUTHENTICATING   // STA is waiting for AUTH seq#3 using SHARED KEY
1040 } AUTH_STATE;
1041
1042 //for-wpa value domain of pMacEntry->WpaState  802.1i D3   p.114
1043 typedef enum _ApWpaState {
1044     AS_NOTUSE,              // 0
1045     AS_DISCONNECT,          // 1
1046     AS_DISCONNECTED,        // 2
1047     AS_INITIALIZE,          // 3
1048     AS_AUTHENTICATION,      // 4
1049     AS_AUTHENTICATION2,     // 5
1050     AS_INITPMK,             // 6
1051     AS_INITPSK,             // 7
1052     AS_PTKSTART,            // 8
1053     AS_PTKINIT_NEGOTIATING, // 9
1054     AS_PTKINITDONE,         // 10
1055     AS_UPDATEKEYS,          // 11
1056     AS_INTEGRITY_FAILURE,   // 12
1057     AS_KEYUPDATE,           // 13
1058 } AP_WPA_STATE;
1059
1060 // for-wpa value domain of pMacEntry->WpaState  802.1i D3   p.114
1061 typedef enum _GTKState {
1062     REKEY_NEGOTIATING,
1063     REKEY_ESTABLISHED,
1064     KEYERROR,
1065 } GTK_STATE;
1066
1067 //  for-wpa  value domain of pMacEntry->WpaState  802.1i D3   p.114
1068 typedef enum _WpaGTKState {
1069     SETKEYS,
1070     SETKEYS_DONE,
1071 } WPA_GTK_STATE;
1072 // ====================== end of AP mlme.h ============================
1073
1074
1075 #endif  // MLME_H__