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