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