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