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