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