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