]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net80211/ieee80211.h
correct status code returned for ht capability mismatch on assoc/reassoc
[FreeBSD/FreeBSD.git] / sys / net80211 / ieee80211.h
1 /*-
2  * Copyright (c) 2001 Atsushi Onoe
3  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _NET80211_IEEE80211_H_
29 #define _NET80211_IEEE80211_H_
30
31 /*
32  * 802.11 protocol definitions.
33  */
34
35 #define IEEE80211_ADDR_LEN      6               /* size of 802.11 address */
36 /* is 802.11 address multicast/broadcast? */
37 #define IEEE80211_IS_MULTICAST(_a)      (*(_a) & 0x01)
38
39 typedef uint16_t ieee80211_seq;
40
41 /* IEEE 802.11 PLCP header */
42 struct ieee80211_plcp_hdr {
43         uint16_t        i_sfd;
44         uint8_t         i_signal;
45         uint8_t         i_service;
46         uint16_t        i_length;
47         uint16_t        i_crc;
48 } __packed;
49
50 #define IEEE80211_PLCP_SFD      0xF3A0 
51 #define IEEE80211_PLCP_SERVICE  0x00
52 #define IEEE80211_PLCP_SERVICE_LOCKED   0x04
53 #define IEEE80211_PLCL_SERVICE_PBCC     0x08
54 #define IEEE80211_PLCP_SERVICE_LENEXT5  0x20
55 #define IEEE80211_PLCP_SERVICE_LENEXT6  0x40
56 #define IEEE80211_PLCP_SERVICE_LENEXT7  0x80
57
58 /*
59  * generic definitions for IEEE 802.11 frames
60  */
61 struct ieee80211_frame {
62         uint8_t         i_fc[2];
63         uint8_t         i_dur[2];
64         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
65         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
66         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
67         uint8_t         i_seq[2];
68         /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
69         /* see below */
70 } __packed;
71
72 struct ieee80211_qosframe {
73         uint8_t         i_fc[2];
74         uint8_t         i_dur[2];
75         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
76         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
77         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
78         uint8_t         i_seq[2];
79         uint8_t         i_qos[2];
80         /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
81         /* see below */
82 } __packed;
83
84 struct ieee80211_qoscntl {
85         uint8_t         i_qos[2];
86 };
87
88 struct ieee80211_frame_addr4 {
89         uint8_t         i_fc[2];
90         uint8_t         i_dur[2];
91         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
92         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
93         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
94         uint8_t         i_seq[2];
95         uint8_t         i_addr4[IEEE80211_ADDR_LEN];
96 } __packed;
97
98
99 struct ieee80211_qosframe_addr4 {
100         uint8_t         i_fc[2];
101         uint8_t         i_dur[2];
102         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
103         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
104         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
105         uint8_t         i_seq[2];
106         uint8_t         i_addr4[IEEE80211_ADDR_LEN];
107         uint8_t         i_qos[2];
108 } __packed;
109
110 #define IEEE80211_FC0_VERSION_MASK              0x03
111 #define IEEE80211_FC0_VERSION_SHIFT             0
112 #define IEEE80211_FC0_VERSION_0                 0x00
113 #define IEEE80211_FC0_TYPE_MASK                 0x0c
114 #define IEEE80211_FC0_TYPE_SHIFT                2
115 #define IEEE80211_FC0_TYPE_MGT                  0x00
116 #define IEEE80211_FC0_TYPE_CTL                  0x04
117 #define IEEE80211_FC0_TYPE_DATA                 0x08
118
119 #define IEEE80211_FC0_SUBTYPE_MASK              0xf0
120 #define IEEE80211_FC0_SUBTYPE_SHIFT             4
121 /* for TYPE_MGT */
122 #define IEEE80211_FC0_SUBTYPE_ASSOC_REQ         0x00
123 #define IEEE80211_FC0_SUBTYPE_ASSOC_RESP        0x10
124 #define IEEE80211_FC0_SUBTYPE_REASSOC_REQ       0x20
125 #define IEEE80211_FC0_SUBTYPE_REASSOC_RESP      0x30
126 #define IEEE80211_FC0_SUBTYPE_PROBE_REQ         0x40
127 #define IEEE80211_FC0_SUBTYPE_PROBE_RESP        0x50
128 #define IEEE80211_FC0_SUBTYPE_BEACON            0x80
129 #define IEEE80211_FC0_SUBTYPE_ATIM              0x90
130 #define IEEE80211_FC0_SUBTYPE_DISASSOC          0xa0
131 #define IEEE80211_FC0_SUBTYPE_AUTH              0xb0
132 #define IEEE80211_FC0_SUBTYPE_DEAUTH            0xc0
133 #define IEEE80211_FC0_SUBTYPE_ACTION            0xd0
134 /* for TYPE_CTL */
135 #define IEEE80211_FC0_SUBTYPE_BAR               0x80
136 #define IEEE80211_FC0_SUBTYPE_BA                0x90
137 #define IEEE80211_FC0_SUBTYPE_PS_POLL           0xa0
138 #define IEEE80211_FC0_SUBTYPE_RTS               0xb0
139 #define IEEE80211_FC0_SUBTYPE_CTS               0xc0
140 #define IEEE80211_FC0_SUBTYPE_ACK               0xd0
141 #define IEEE80211_FC0_SUBTYPE_CF_END            0xe0
142 #define IEEE80211_FC0_SUBTYPE_CF_END_ACK        0xf0
143 /* for TYPE_DATA (bit combination) */
144 #define IEEE80211_FC0_SUBTYPE_DATA              0x00
145 #define IEEE80211_FC0_SUBTYPE_CF_ACK            0x10
146 #define IEEE80211_FC0_SUBTYPE_CF_POLL           0x20
147 #define IEEE80211_FC0_SUBTYPE_CF_ACPL           0x30
148 #define IEEE80211_FC0_SUBTYPE_NODATA            0x40
149 #define IEEE80211_FC0_SUBTYPE_CFACK             0x50
150 #define IEEE80211_FC0_SUBTYPE_CFPOLL            0x60
151 #define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK     0x70
152 #define IEEE80211_FC0_SUBTYPE_QOS               0x80
153 #define IEEE80211_FC0_SUBTYPE_QOS_NULL          0xc0
154
155 #define IEEE80211_FC1_DIR_MASK                  0x03
156 #define IEEE80211_FC1_DIR_NODS                  0x00    /* STA->STA */
157 #define IEEE80211_FC1_DIR_TODS                  0x01    /* STA->AP  */
158 #define IEEE80211_FC1_DIR_FROMDS                0x02    /* AP ->STA */
159 #define IEEE80211_FC1_DIR_DSTODS                0x03    /* AP ->AP  */
160
161 #define IEEE80211_FC1_MORE_FRAG                 0x04
162 #define IEEE80211_FC1_RETRY                     0x08
163 #define IEEE80211_FC1_PWR_MGT                   0x10
164 #define IEEE80211_FC1_MORE_DATA                 0x20
165 #define IEEE80211_FC1_WEP                       0x40
166 #define IEEE80211_FC1_ORDER                     0x80
167
168 #define IEEE80211_SEQ_FRAG_MASK                 0x000f
169 #define IEEE80211_SEQ_FRAG_SHIFT                0
170 #define IEEE80211_SEQ_SEQ_MASK                  0xfff0
171 #define IEEE80211_SEQ_SEQ_SHIFT                 4
172 #define IEEE80211_SEQ_RANGE                     4096
173
174 #define IEEE80211_SEQ_ADD(seq, incr) \
175         (((seq) + (incr)) & (IEEE80211_SEQ_RANGE-1))
176 #define IEEE80211_SEQ_INC(seq)  IEEE80211_SEQ_ADD(seq,1)
177 #define IEEE80211_SEQ_SUB(a, b) \
178         (((a) + IEEE80211_SEQ_RANGE - (b)) & (IEEE80211_SEQ_RANGE-1))
179
180 #define IEEE80211_SEQ_BA_RANGE                  2048    /* 2^11 */
181 #define IEEE80211_SEQ_BA_BEFORE(a, b) \
182         (IEEE80211_SEQ_SUB(b, a+1) < IEEE80211_SEQ_BA_RANGE-1)
183
184 #define IEEE80211_NWID_LEN                      32
185
186 #define IEEE80211_QOS_TXOP                      0x00ff
187 /* bit 8 is reserved */
188 #define IEEE80211_QOS_AMSDU                     0x80
189 #define IEEE80211_QOS_AMSDU_S                   7
190 #define IEEE80211_QOS_ACKPOLICY                 0x60
191 #define IEEE80211_QOS_ACKPOLICY_S               5
192 #define IEEE80211_QOS_ACKPOLICY_NOACK           0x20    /* No ACK required */
193 #define IEEE80211_QOS_ACKPOLICY_BA              0x60    /* Block ACK */
194 #define IEEE80211_QOS_EOSP                      0x10    /* EndOfService Period*/
195 #define IEEE80211_QOS_EOSP_S                    4
196 #define IEEE80211_QOS_TID                       0x0f
197
198 /* does frame have QoS sequence control data */
199 #define IEEE80211_QOS_HAS_SEQ(wh) \
200         (((wh)->i_fc[0] & \
201           (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
202           (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
203
204 /*
205  * WME/802.11e information element.
206  */
207 struct ieee80211_wme_info {
208         uint8_t         wme_id;         /* IEEE80211_ELEMID_VENDOR */
209         uint8_t         wme_len;        /* length in bytes */
210         uint8_t         wme_oui[3];     /* 0x00, 0x50, 0xf2 */
211         uint8_t         wme_type;       /* OUI type */
212         uint8_t         wme_subtype;    /* OUI subtype */
213         uint8_t         wme_version;    /* spec revision */
214         uint8_t         wme_info;       /* QoS info */
215 } __packed;
216
217 /*
218  * WME/802.11e Tspec Element
219  */
220 struct ieee80211_wme_tspec {
221         uint8_t         ts_id;
222         uint8_t         ts_len;
223         uint8_t         ts_oui[3];
224         uint8_t         ts_oui_type;
225         uint8_t         ts_oui_subtype;
226         uint8_t         ts_version;
227         uint8_t         ts_tsinfo[3];
228         uint8_t         ts_nom_msdu[2];
229         uint8_t         ts_max_msdu[2];
230         uint8_t         ts_min_svc[4];
231         uint8_t         ts_max_svc[4];
232         uint8_t         ts_inactv_intv[4];
233         uint8_t         ts_susp_intv[4];
234         uint8_t         ts_start_svc[4];
235         uint8_t         ts_min_rate[4];
236         uint8_t         ts_mean_rate[4];
237         uint8_t         ts_max_burst[4];
238         uint8_t         ts_min_phy[4];
239         uint8_t         ts_peak_rate[4];
240         uint8_t         ts_delay[4];
241         uint8_t         ts_surplus[2];
242         uint8_t         ts_medium_time[2];
243 } __packed;
244
245 /*
246  * WME AC parameter field
247  */
248 struct ieee80211_wme_acparams {
249         uint8_t         acp_aci_aifsn;
250         uint8_t         acp_logcwminmax;
251         uint16_t        acp_txop;
252 } __packed;
253
254 #define WME_NUM_AC              4       /* 4 AC categories */
255 #define WME_NUM_TID             16      /* 16 tids */
256
257 #define WME_PARAM_ACI           0x60    /* Mask for ACI field */
258 #define WME_PARAM_ACI_S         5       /* Shift for ACI field */
259 #define WME_PARAM_ACM           0x10    /* Mask for ACM bit */
260 #define WME_PARAM_ACM_S         4       /* Shift for ACM bit */
261 #define WME_PARAM_AIFSN         0x0f    /* Mask for aifsn field */
262 #define WME_PARAM_AIFSN_S       0       /* Shift for aifsn field */
263 #define WME_PARAM_LOGCWMIN      0x0f    /* Mask for CwMin field (in log) */
264 #define WME_PARAM_LOGCWMIN_S    0       /* Shift for CwMin field */
265 #define WME_PARAM_LOGCWMAX      0xf0    /* Mask for CwMax field (in log) */
266 #define WME_PARAM_LOGCWMAX_S    4       /* Shift for CwMax field */
267
268 #define WME_AC_TO_TID(_ac) (       \
269         ((_ac) == WME_AC_VO) ? 6 : \
270         ((_ac) == WME_AC_VI) ? 5 : \
271         ((_ac) == WME_AC_BK) ? 1 : \
272         0)
273
274 #define TID_TO_WME_AC(_tid) (      \
275         ((_tid) == 0 || (_tid) == 3) ? WME_AC_BE : \
276         ((_tid) < 3) ? WME_AC_BK : \
277         ((_tid) < 6) ? WME_AC_VI : \
278         WME_AC_VO)
279
280 /*
281  * WME Parameter Element
282  */
283 struct ieee80211_wme_param {
284         uint8_t         param_id;
285         uint8_t         param_len;
286         uint8_t         param_oui[3];
287         uint8_t         param_oui_type;
288         uint8_t         param_oui_subtype;
289         uint8_t         param_version;
290         uint8_t         param_qosInfo;
291 #define WME_QOSINFO_COUNT       0x0f    /* Mask for param count field */
292         uint8_t         param_reserved;
293         struct ieee80211_wme_acparams   params_acParams[WME_NUM_AC];
294 } __packed;
295
296 /*
297  * Management Notification Frame
298  */
299 struct ieee80211_mnf {
300         uint8_t         mnf_category;
301         uint8_t         mnf_action;
302         uint8_t         mnf_dialog;
303         uint8_t         mnf_status;
304 } __packed;
305 #define MNF_SETUP_REQ   0
306 #define MNF_SETUP_RESP  1
307 #define MNF_TEARDOWN    2
308
309 /* 
310  * 802.11n Management Action Frames 
311  */
312 /* generic frame format */
313 struct ieee80211_action {
314         uint8_t         ia_category;
315         uint8_t         ia_action;
316 } __packed;
317
318 #define IEEE80211_ACTION_CAT_SM         0       /* Spectrum Management */
319 #define IEEE80211_ACTION_CAT_QOS        1       /* QoS */
320 #define IEEE80211_ACTION_CAT_DLS        2       /* DLS */
321 #define IEEE80211_ACTION_CAT_BA         3       /* BA */
322 #define IEEE80211_ACTION_CAT_HT         7       /* HT */
323 #define IEEE80211_ACTION_CAT_VENDOR     127     /* Vendor Specific */
324
325 #define IEEE80211_ACTION_HT_TXCHWIDTH   0       /* recommended xmit chan width*/
326 #define IEEE80211_ACTION_HT_MIMOPWRSAVE 1       /* MIMO power save */
327
328 /* HT - recommended transmission channel width */
329 struct ieee80211_action_ht_txchwidth {
330         struct ieee80211_action at_header;
331         uint8_t         at_chwidth;     
332 } __packed;
333
334 #define IEEE80211_A_HT_TXCHWIDTH_20     0
335 #define IEEE80211_A_HT_TXCHWIDTH_2040   1
336
337 /* HT - MIMO Power Save (NB: D2.04) */
338 struct ieee80211_action_ht_mimopowersave {
339         struct ieee80211_action am_header;
340         uint8_t         am_control;
341 } __packed;
342
343 #define IEEE80211_A_HT_MIMOPWRSAVE_ENA          0x01    /* PS enabled */
344 #define IEEE80211_A_HT_MIMOPWRSAVE_MODE         0x02
345 #define IEEE80211_A_HT_MIMOPWRSAVE_MODE_S       1
346 #define IEEE80211_A_HT_MIMOPWRSAVE_DYNAMIC      0x02    /* Dynamic Mode */
347 #define IEEE80211_A_HT_MIMOPWRSAVE_STATIC       0x00    /* no SM packets */
348 /* bits 2-7 reserved */
349
350 /* Block Ack actions */
351 #define IEEE80211_ACTION_BA_ADDBA_REQUEST       0   /* ADDBA request */
352 #define IEEE80211_ACTION_BA_ADDBA_RESPONSE      1   /* ADDBA response */
353 #define IEEE80211_ACTION_BA_DELBA               2   /* DELBA */
354
355 /* Block Ack Parameter Set */
356 #define IEEE80211_BAPS_BUFSIZ   0xffc0          /* buffer size */
357 #define IEEE80211_BAPS_BUFSIZ_S 6
358 #define IEEE80211_BAPS_TID      0x003c          /* TID */
359 #define IEEE80211_BAPS_TID_S    2
360 #define IEEE80211_BAPS_POLICY   0x0002          /* block ack policy */
361 #define IEEE80211_BAPS_POLICY_S 1
362
363 #define IEEE80211_BAPS_POLICY_DELAYED   (0<<IEEE80211_BAPS_POLICY_S)
364 #define IEEE80211_BAPS_POLICY_IMMEDIATE (1<<IEEE80211_BAPS_POLICY_S)
365
366 /* Block Ack Sequence Control */
367 #define IEEE80211_BASEQ_START   0xfff0          /* starting seqnum */
368 #define IEEE80211_BASEQ_START_S 4
369 #define IEEE80211_BASEQ_FRAG    0x000f          /* fragment number */
370 #define IEEE80211_BASEQ_FRAG_S  0
371
372 /* Delayed Block Ack Parameter Set */
373 #define IEEE80211_DELBAPS_TID   0xf000          /* TID */
374 #define IEEE80211_DELBAPS_TID_S 12
375 #define IEEE80211_DELBAPS_INIT  0x0800          /* initiator */
376 #define IEEE80211_DELBAPS_INIT_S 11
377
378 /* BA - ADDBA request */
379 struct ieee80211_action_ba_addbarequest {
380         struct ieee80211_action rq_header;
381         uint8_t         rq_dialogtoken;
382         uint16_t        rq_baparamset;
383         uint16_t        rq_batimeout;           /* in TUs */
384         uint16_t        rq_baseqctl;
385 } __packed;
386
387 /* BA - ADDBA response */
388 struct ieee80211_action_ba_addbaresponse {
389         struct ieee80211_action rs_header;
390         uint8_t         rs_dialogtoken;
391         uint16_t        rs_statuscode;
392         uint16_t        rs_baparamset; 
393         uint16_t        rs_batimeout;           /* in TUs */
394 } __packed;
395
396 /* BA - DELBA */
397 struct ieee80211_action_ba_delba {
398         struct ieee80211_action dl_header;
399         uint16_t        dl_baparamset;
400         uint16_t        dl_reasoncode;
401 } __packed;
402
403 /* BAR Control */
404 #define IEEE80211_BAR_TID       0xf000          /* TID */
405 #define IEEE80211_BAR_TID_S     12
406 #define IEEE80211_BAR_COMP      0x0004          /* Compressed Bitmap */
407 #define IEEE80211_BAR_MTID      0x0002          /* Multi-TID */
408 #define IEEE80211_BAR_NOACK     0x0001          /* No-Ack policy */
409
410 /* BAR Starting Sequence Control */
411 #define IEEE80211_BAR_SEQ_START 0xfff0          /* starting seqnum */
412 #define IEEE80211_BAR_SEQ_START_S       4
413
414 struct ieee80211_ba_request {
415         uint16_t        rq_barctl;
416         uint16_t        rq_barseqctl;
417 } __packed;
418
419 /*
420  * Control frames.
421  */
422 struct ieee80211_frame_min {
423         uint8_t         i_fc[2];
424         uint8_t         i_dur[2];
425         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
426         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
427         /* FCS */
428 } __packed;
429
430 struct ieee80211_frame_rts {
431         uint8_t         i_fc[2];
432         uint8_t         i_dur[2];
433         uint8_t         i_ra[IEEE80211_ADDR_LEN];
434         uint8_t         i_ta[IEEE80211_ADDR_LEN];
435         /* FCS */
436 } __packed;
437
438 struct ieee80211_frame_cts {
439         uint8_t         i_fc[2];
440         uint8_t         i_dur[2];
441         uint8_t         i_ra[IEEE80211_ADDR_LEN];
442         /* FCS */
443 } __packed;
444
445 struct ieee80211_frame_ack {
446         uint8_t         i_fc[2];
447         uint8_t         i_dur[2];
448         uint8_t         i_ra[IEEE80211_ADDR_LEN];
449         /* FCS */
450 } __packed;
451
452 struct ieee80211_frame_pspoll {
453         uint8_t         i_fc[2];
454         uint8_t         i_aid[2];
455         uint8_t         i_bssid[IEEE80211_ADDR_LEN];
456         uint8_t         i_ta[IEEE80211_ADDR_LEN];
457         /* FCS */
458 } __packed;
459
460 struct ieee80211_frame_cfend {          /* NB: also CF-End+CF-Ack */
461         uint8_t         i_fc[2];
462         uint8_t         i_dur[2];       /* should be zero */
463         uint8_t         i_ra[IEEE80211_ADDR_LEN];
464         uint8_t         i_bssid[IEEE80211_ADDR_LEN];
465         /* FCS */
466 } __packed;
467
468 struct ieee80211_frame_bar {
469         uint8_t         i_fc[2];
470         uint8_t         i_dur[2];
471         uint8_t         i_ra[IEEE80211_ADDR_LEN];
472         uint8_t         i_ta[IEEE80211_ADDR_LEN];
473         uint16_t        i_ctl;
474         uint16_t        i_seq;
475         /* FCS */
476 } __packed;
477
478 /*
479  * BEACON management packets
480  *
481  *      octet timestamp[8]
482  *      octet beacon interval[2]
483  *      octet capability information[2]
484  *      information element
485  *              octet elemid
486  *              octet length
487  *              octet information[length]
488  */
489
490 #define IEEE80211_BEACON_INTERVAL(beacon) \
491         ((beacon)[8] | ((beacon)[9] << 8))
492 #define IEEE80211_BEACON_CAPABILITY(beacon) \
493         ((beacon)[10] | ((beacon)[11] << 8))
494
495 #define IEEE80211_CAPINFO_ESS                   0x0001
496 #define IEEE80211_CAPINFO_IBSS                  0x0002
497 #define IEEE80211_CAPINFO_CF_POLLABLE           0x0004
498 #define IEEE80211_CAPINFO_CF_POLLREQ            0x0008
499 #define IEEE80211_CAPINFO_PRIVACY               0x0010
500 #define IEEE80211_CAPINFO_SHORT_PREAMBLE        0x0020
501 #define IEEE80211_CAPINFO_PBCC                  0x0040
502 #define IEEE80211_CAPINFO_CHNL_AGILITY          0x0080
503 #define IEEE80211_CAPINFO_SPECTRUM_MGMT         0x0100
504 /* bit 9 is reserved */
505 #define IEEE80211_CAPINFO_SHORT_SLOTTIME        0x0400
506 #define IEEE80211_CAPINFO_RSN                   0x0800
507 /* bit 12 is reserved */
508 #define IEEE80211_CAPINFO_DSSSOFDM              0x2000
509 /* bits 14-15 are reserved */
510
511 #define IEEE80211_CAPINFO_BITS \
512         "\20\1ESS\2IBSS\3CF_POLLABLE\4CF_POLLREQ\5PRIVACY\6SHORT_PREAMBLE" \
513         "\7PBCC\10CHNL_AGILITY\11SPECTRUM_MGMT\13SHORT_SLOTTIME\14RSN" \
514         "\16DSSOFDM"
515
516 /*
517  * 802.11i/WPA information element (maximally sized).
518  */
519 struct ieee80211_ie_wpa {
520         uint8_t         wpa_id;         /* IEEE80211_ELEMID_VENDOR */
521         uint8_t         wpa_len;        /* length in bytes */
522         uint8_t         wpa_oui[3];     /* 0x00, 0x50, 0xf2 */
523         uint8_t         wpa_type;       /* OUI type */
524         uint16_t        wpa_version;    /* spec revision */
525         uint32_t        wpa_mcipher[1]; /* multicast/group key cipher */
526         uint16_t        wpa_uciphercnt; /* # pairwise key ciphers */
527         uint32_t        wpa_uciphers[8];/* ciphers */
528         uint16_t        wpa_authselcnt; /* authentication selector cnt*/
529         uint32_t        wpa_authsels[8];/* selectors */
530         uint16_t        wpa_caps;       /* 802.11i capabilities */
531         uint16_t        wpa_pmkidcnt;   /* 802.11i pmkid count */
532         uint16_t        wpa_pmkids[8];  /* 802.11i pmkids */
533 } __packed;
534
535 /*
536  * 802.11n HT Capability IE
537  * NB: these reflect D1.10 
538  */
539 struct ieee80211_ie_htcap {
540         uint8_t         hc_id;                  /* element ID */
541         uint8_t         hc_len;                 /* length in bytes */
542         uint16_t        hc_cap;                 /* HT caps (see below) */
543         uint8_t         hc_param;               /* HT params (see below) */
544         uint8_t         hc_mcsset[16];          /* supported MCS set */
545         uint16_t        hc_extcap;              /* extended HT capabilities */
546         uint32_t        hc_txbf;                /* txbf capabilities */
547         uint8_t         hc_antenna;             /* antenna capabilities */
548 } __packed;
549
550 /* HT capability flags (ht_cap) */
551 #define IEEE80211_HTCAP_LDPC            0x0001  /* LDPC supported */
552 #define IEEE80211_HTCAP_CHWIDTH40       0x0002  /* 20/40 supported */
553 #define IEEE80211_HTCAP_SMPS            0x000c  /* SM Power Save mode */
554 #define IEEE80211_HTCAP_SMPS_OFF        0x000c  /* disabled */
555 #define IEEE80211_HTCAP_SMPS_DYNAMIC    0x0004  /* send RTS first */
556 /* NB: SMPS value 2 is reserved */
557 #define IEEE80211_HTCAP_SMPS_ENA        0x0000  /* enabled (static mode) */
558 #define IEEE80211_HTCAP_GREENFIELD      0x0010  /* Greenfield supported */
559 #define IEEE80211_HTCAP_SHORTGI20       0x0020  /* Short GI in 20MHz */
560 #define IEEE80211_HTCAP_SHORTGI40       0x0040  /* Short GI in 40MHz */
561 #define IEEE80211_HTCAP_TXSTBC          0x0080  /* STBC tx ok */
562 #define IEEE80211_HTCAP_RXSTBC          0x0300  /* STBC rx support */
563 #define IEEE80211_HTCAP_RXSTBC_S        8
564 #define IEEE80211_HTCAP_RXSTBC_1STREAM  0x0100  /* 1 spatial stream */
565 #define IEEE80211_HTCAP_RXSTBC_2STREAM  0x0200  /* 1-2 spatial streams*/
566 #define IEEE80211_HTCAP_RXSTBC_3STREAM  0x0300  /* 1-3 spatial streams*/
567 #define IEEE80211_HTCAP_DELBA           0x0400  /* HT DELBA supported */
568 #define IEEE80211_HTCAP_MAXAMSDU        0x0800  /* max A-MSDU length */
569 #define IEEE80211_HTCAP_MAXAMSDU_7935   0x0800  /* 7935 octets */
570 #define IEEE80211_HTCAP_MAXAMSDU_3839   0x0000  /* 3839 octets */
571 #define IEEE80211_HTCAP_DSSSCCK40       0x1000  /* DSSS/CCK in 40MHz */
572 #define IEEE80211_HTCAP_PSMP            0x2000  /* PSMP supported */
573 #define IEEE80211_HTCAP_40INTOLERANT    0x4000  /* 40MHz intolerant */
574 #define IEEE80211_HTCAP_LSIGTXOPPROT    0x8000  /* L-SIG TXOP prot */
575
576 #define IEEE80211_HTCAP_BITS \
577         "\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
578         "\13DELBA\14AMSDU(7935)\15DSSSCCK40\16PSMP\1740INTOLERANT" \
579         "\20LSIGTXOPPROT"
580
581 /* HT parameters (hc_param) */
582 #define IEEE80211_HTCAP_MAXRXAMPDU      0x03    /* max rx A-MPDU factor */
583 #define IEEE80211_HTCAP_MAXRXAMPDU_S    0
584 #define IEEE80211_HTCAP_MAXRXAMPDU_8K   0
585 #define IEEE80211_HTCAP_MAXRXAMPDU_16K  1
586 #define IEEE80211_HTCAP_MAXRXAMPDU_32K  2
587 #define IEEE80211_HTCAP_MAXRXAMPDU_64K  3
588 #define IEEE80211_HTCAP_MPDUDENSITY     0x1c    /* min MPDU start spacing */
589 #define IEEE80211_HTCAP_MPDUDENSITY_S   2
590 #define IEEE80211_HTCAP_MPDUDENSITY_NA  0       /* no time restriction */
591 #define IEEE80211_HTCAP_MPDUDENSITY_025 1       /* 1/4 us */
592 #define IEEE80211_HTCAP_MPDUDENSITY_05  2       /* 1/2 us */
593 #define IEEE80211_HTCAP_MPDUDENSITY_1   3       /* 1 us */
594 #define IEEE80211_HTCAP_MPDUDENSITY_2   4       /* 2 us */
595 #define IEEE80211_HTCAP_MPDUDENSITY_4   5       /* 4 us */
596 #define IEEE80211_HTCAP_MPDUDENSITY_8   6       /* 8 us */
597 #define IEEE80211_HTCAP_MPDUDENSITY_16  7       /* 16 us */
598
599 /* HT extended capabilities (hc_extcap) */
600 #define IEEE80211_HTCAP_PCO             0x0001  /* PCO capable */
601 #define IEEE80211_HTCAP_PCOTRANS        0x0006  /* PCO transition time */
602 #define IEEE80211_HTCAP_PCOTRANS_S      1
603 #define IEEE80211_HTCAP_PCOTRANS_04     0x0002  /* 400 us */
604 #define IEEE80211_HTCAP_PCOTRANS_15     0x0004  /* 1.5 ms */
605 #define IEEE80211_HTCAP_PCOTRANS_5      0x0006  /* 5 ms */
606 /* bits 3-7 reserved */
607 #define IEEE80211_HTCAP_MCSFBACK        0x0300  /* MCS feedback */
608 #define IEEE80211_HTCAP_MCSFBACK_S      8
609 #define IEEE80211_HTCAP_MCSFBACK_NONE   0x0000  /* nothing provided */
610 #define IEEE80211_HTCAP_MCSFBACK_UNSOL  0x0200  /* unsolicited feedback */
611 #define IEEE80211_HTCAP_MCSFBACK_MRQ    0x0300  /* " "+respond to MRQ */
612 #define IEEE80211_HTCAP_HTC             0x0400  /* +HTC support */
613 #define IEEE80211_HTCAP_RDR             0x0800  /* reverse direction responder*/
614 /* bits 12-15 reserved */
615
616 /*
617  * 802.11n HT Information IE
618  */
619 struct ieee80211_ie_htinfo {
620         uint8_t         hi_id;                  /* element ID */
621         uint8_t         hi_len;                 /* length in bytes */
622         uint8_t         hi_ctrlchannel;         /* primary channel */
623         uint8_t         hi_byte1;               /* ht ie byte 1 */
624         uint8_t         hi_byte2;               /* ht ie byte 2 */
625         uint8_t         hi_byte3;               /* ht ie byte 3 */
626         uint16_t        hi_byte45;              /* ht ie bytes 4+5 */
627         uint8_t         hi_basicmcsset[16];     /* basic MCS set */
628 } __packed;
629
630 /* byte1 */
631 #define IEEE80211_HTINFO_2NDCHAN        0x03    /* secondary/ext chan offset */
632 #define IEEE80211_HTINFO_2NDCHAN_S      0
633 #define IEEE80211_HTINFO_2NDCHAN_NONE   0x00    /* no secondary/ext channel */
634 #define IEEE80211_HTINFO_2NDCHAN_ABOVE  0x01    /* above private channel */
635 /* NB: 2 is reserved */
636 #define IEEE80211_HTINFO_2NDCHAN_BELOW  0x03    /* below primary channel */ 
637 #define IEEE80211_HTINFO_TXWIDTH        0x04    /* tx channel width */
638 #define IEEE80211_HTINFO_TXWIDTH_20     0x00    /* 20MHz width */
639 #define IEEE80211_HTINFO_TXWIDTH_2040   0x04    /* any supported width */
640 #define IEEE80211_HTINFO_RIFSMODE       0x08    /* Reduced IFS (RIFS) use */
641 #define IEEE80211_HTINFO_RIFSMODE_PROH  0x00    /* RIFS use prohibited */
642 #define IEEE80211_HTINFO_RIFSMODE_PERM  0x08    /* RIFS use permitted */
643 #define IEEE80211_HTINFO_PMSPONLY       0x10    /* PSMP required to associate */
644 #define IEEE80211_HTINFO_SIGRAN         0xe0    /* shortest Service Interval */
645 #define IEEE80211_HTINFO_SIGRAN_S       5
646 #define IEEE80211_HTINFO_SIGRAN_5       0x00    /* 5 ms */
647 /* XXX add rest */
648
649 /* bytes 2+3 */
650 #define IEEE80211_HTINFO_OPMODE         0x03    /* operating mode */
651 #define IEEE80211_HTINFO_OPMODE_S       0
652 #define IEEE80211_HTINFO_OPMODE_PURE    0x00    /* no protection */
653 #define IEEE80211_HTINFO_OPMODE_PROTOPT 0x01    /* protection optional */
654 #define IEEE80211_HTINFO_OPMODE_HT20PR  0x02    /* protection for HT20 sta's */
655 #define IEEE80211_HTINFO_OPMODE_MIXED   0x03    /* protection for legacy sta's*/
656 #define IEEE80211_HTINFO_NONGF_PRESENT  0x04    /* non-GF sta's present */
657 #define IEEE80211_HTINFO_TXBL           0x08    /* transmit burst limit */
658 #define IEEE80211_HTINFO_NONHT_PRESENT  0x10    /* non-HT sta's present */
659 /* bits 5-15 reserved */
660
661 /* bytes 4+5 */
662 #define IEEE80211_HTINFO_2NDARYBEACON   0x01
663 #define IEEE80211_HTINFO_LSIGTXOPPROT   0x02
664 #define IEEE80211_HTINFO_PCO_ACTIVE     0x04
665 #define IEEE80211_HTINFO_40MHZPHASE     0x08
666
667 /* byte5 */
668 #define IEEE80211_HTINFO_BASIC_STBCMCS  0x7f
669 #define IEEE80211_HTINFO_BASIC_STBCMCS_S 0
670 #define IEEE80211_HTINFO_DUALPROTECTED  0x80
671
672 /*
673  * Management information element payloads.
674  */
675
676 enum {
677         IEEE80211_ELEMID_SSID           = 0,
678         IEEE80211_ELEMID_RATES          = 1,
679         IEEE80211_ELEMID_FHPARMS        = 2,
680         IEEE80211_ELEMID_DSPARMS        = 3,
681         IEEE80211_ELEMID_CFPARMS        = 4,
682         IEEE80211_ELEMID_TIM            = 5,
683         IEEE80211_ELEMID_IBSSPARMS      = 6,
684         IEEE80211_ELEMID_COUNTRY        = 7,
685         IEEE80211_ELEMID_CHALLENGE      = 16,
686         /* 17-31 reserved for challenge text extension */
687         IEEE80211_ELEMID_PWRCNSTR       = 32,
688         IEEE80211_ELEMID_PWRCAP         = 33,
689         IEEE80211_ELEMID_TPCREQ         = 34,
690         IEEE80211_ELEMID_TPCREP         = 35,
691         IEEE80211_ELEMID_SUPPCHAN       = 36,
692         IEEE80211_ELEMID_CSA            = 37,
693         IEEE80211_ELEMID_MEASREQ        = 38,
694         IEEE80211_ELEMID_MEASREP        = 39,
695         IEEE80211_ELEMID_QUIET          = 40,
696         IEEE80211_ELEMID_IBSSDFS        = 41,
697         IEEE80211_ELEMID_ERP            = 42,
698         IEEE80211_ELEMID_HTCAP          = 45,
699         IEEE80211_ELEMID_RSN            = 48,
700         IEEE80211_ELEMID_XRATES         = 50,
701         IEEE80211_ELEMID_HTINFO         = 61,
702         IEEE80211_ELEMID_TPC            = 150,
703         IEEE80211_ELEMID_CCKM           = 156,
704         IEEE80211_ELEMID_VENDOR         = 221,  /* vendor private */
705 };
706
707 struct ieee80211_tim_ie {
708         uint8_t         tim_ie;                 /* IEEE80211_ELEMID_TIM */
709         uint8_t         tim_len;
710         uint8_t         tim_count;              /* DTIM count */
711         uint8_t         tim_period;             /* DTIM period */
712         uint8_t         tim_bitctl;             /* bitmap control */
713         uint8_t         tim_bitmap[1];          /* variable-length bitmap */
714 } __packed;
715
716 struct ieee80211_country_ie {
717         uint8_t         ie;                     /* IEEE80211_ELEMID_COUNTRY */
718         uint8_t         len;
719         uint8_t         cc[3];                  /* ISO CC+(I)ndoor/(O)utdoor */
720         struct {
721                 uint8_t schan;                  /* starting channel */
722                 uint8_t nchan;                  /* number channels */
723                 uint8_t maxtxpwr;               /* tx power cap */
724         } __packed band[1];                     /* sub bands (NB: var size) */
725 } __packed;
726
727 #define IEEE80211_COUNTRY_MAX_BANDS     84      /* max possible bands */
728 #define IEEE80211_COUNTRY_MAX_SIZE \
729         (sizeof(struct ieee80211_country_ie) + 3*(IEEE80211_COUNTRY_MAX_BANDS-1))
730
731 /*
732  * 802.11h Channel Switch Announcement (CSA).
733  */
734 struct ieee80211_csa_ie {
735         uint8_t         csa_ie;         /* IEEE80211_ELEMID_CHANSWITCHANN */
736         uint8_t         csa_len;
737         uint8_t         csa_mode;               /* Channel Switch Mode */
738         uint8_t         csa_newchan;            /* New Channel Number */
739         uint8_t         csa_count;              /* Channel Switch Count */
740 } __packed;
741
742 /*
743  * Note the min acceptable CSA count is used to guard against
744  * malicious CSA injection in station mode.  Defining this value
745  * as other than 0 violates the 11h spec.
746  */
747 #define IEEE80211_CSA_COUNT_MIN 2
748 #define IEEE80211_CSA_COUNT_MAX 255
749
750 /* rate set entries are in .5 Mb/s units, and potentially marked as basic */
751 #define IEEE80211_RATE_BASIC            0x80
752 #define IEEE80211_RATE_VAL              0x7f
753
754 /* EPR information element flags */
755 #define IEEE80211_ERP_NON_ERP_PRESENT   0x01
756 #define IEEE80211_ERP_USE_PROTECTION    0x02
757 #define IEEE80211_ERP_LONG_PREAMBLE     0x04
758
759 #define IEEE80211_ERP_BITS \
760         "\20\1NON_ERP_PRESENT\2USE_PROTECTION\3LONG_PREAMBLE"
761
762 #define ATH_OUI                 0x7f0300        /* Atheros OUI */
763 #define ATH_OUI_TYPE            0x01            /* Atheros protocol ie */
764
765 /* NB: Atheros allocated the OUI for this purpose ~2005 but beware ... */
766 #define TDMA_OUI                ATH_OUI
767 #define TDMA_OUI_TYPE           0x02            /* TDMA protocol ie */
768
769 #define BCM_OUI                 0x4c9000        /* Broadcom OUI */
770 #define BCM_OUI_HTCAP           51              /* pre-draft HTCAP ie */
771 #define BCM_OUI_HTINFO          52              /* pre-draft HTINFO ie */
772
773 #define WPA_OUI                 0xf25000
774 #define WPA_OUI_TYPE            0x01
775 #define WPA_VERSION             1               /* current supported version */
776
777 #define WPA_CSE_NULL            0x00
778 #define WPA_CSE_WEP40           0x01
779 #define WPA_CSE_TKIP            0x02
780 #define WPA_CSE_CCMP            0x04
781 #define WPA_CSE_WEP104          0x05
782
783 #define WPA_ASE_NONE            0x00
784 #define WPA_ASE_8021X_UNSPEC    0x01
785 #define WPA_ASE_8021X_PSK       0x02
786
787 #define WPS_OUI_TYPE            0x04
788
789 #define RSN_OUI                 0xac0f00
790 #define RSN_VERSION             1               /* current supported version */
791
792 #define RSN_CSE_NULL            0x00
793 #define RSN_CSE_WEP40           0x01
794 #define RSN_CSE_TKIP            0x02
795 #define RSN_CSE_WRAP            0x03
796 #define RSN_CSE_CCMP            0x04
797 #define RSN_CSE_WEP104          0x05
798
799 #define RSN_ASE_NONE            0x00
800 #define RSN_ASE_8021X_UNSPEC    0x01
801 #define RSN_ASE_8021X_PSK       0x02
802
803 #define RSN_CAP_PREAUTH         0x01
804
805 #define WME_OUI                 0xf25000
806 #define WME_OUI_TYPE            0x02
807 #define WME_INFO_OUI_SUBTYPE    0x00
808 #define WME_PARAM_OUI_SUBTYPE   0x01
809 #define WME_VERSION             1
810
811 /* WME stream classes */
812 #define WME_AC_BE       0               /* best effort */
813 #define WME_AC_BK       1               /* background */
814 #define WME_AC_VI       2               /* video */
815 #define WME_AC_VO       3               /* voice */
816
817 /*
818  * AUTH management packets
819  *
820  *      octet algo[2]
821  *      octet seq[2]
822  *      octet status[2]
823  *      octet chal.id
824  *      octet chal.length
825  *      octet chal.text[253]            NB: 1-253 bytes
826  */
827
828 /* challenge length for shared key auth */
829 #define IEEE80211_CHALLENGE_LEN         128
830
831 #define IEEE80211_AUTH_ALG_OPEN         0x0000
832 #define IEEE80211_AUTH_ALG_SHARED       0x0001
833 #define IEEE80211_AUTH_ALG_LEAP         0x0080
834
835 enum {
836         IEEE80211_AUTH_OPEN_REQUEST             = 1,
837         IEEE80211_AUTH_OPEN_RESPONSE            = 2,
838 };
839
840 enum {
841         IEEE80211_AUTH_SHARED_REQUEST           = 1,
842         IEEE80211_AUTH_SHARED_CHALLENGE         = 2,
843         IEEE80211_AUTH_SHARED_RESPONSE          = 3,
844         IEEE80211_AUTH_SHARED_PASS              = 4,
845 };
846
847 /*
848  * Reason and status codes.
849  *
850  * Reason codes are used in management frames to indicate why an
851  * action took place (e.g. on disassociation).  Status codes are
852  * used in management frames to indicate the result of an operation.
853  *
854  * Unlisted codes are reserved
855  */
856
857 enum {
858         IEEE80211_REASON_UNSPECIFIED            = 1,
859         IEEE80211_REASON_AUTH_EXPIRE            = 2,
860         IEEE80211_REASON_AUTH_LEAVE             = 3,
861         IEEE80211_REASON_ASSOC_EXPIRE           = 4,
862         IEEE80211_REASON_ASSOC_TOOMANY          = 5,
863         IEEE80211_REASON_NOT_AUTHED             = 6,
864         IEEE80211_REASON_NOT_ASSOCED            = 7,
865         IEEE80211_REASON_ASSOC_LEAVE            = 8,
866         IEEE80211_REASON_ASSOC_NOT_AUTHED       = 9,
867         IEEE80211_REASON_DISASSOC_PWRCAP_BAD    = 10,   /* 11h */
868         IEEE80211_REASON_DISASSOC_SUPCHAN_BAD   = 11,   /* 11h */
869         IEEE80211_REASON_IE_INVALID             = 13,   /* 11i */
870         IEEE80211_REASON_MIC_FAILURE            = 14,   /* 11i */
871         IEEE80211_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,   /* 11i */
872         IEEE80211_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, /* 11i */
873         IEEE80211_REASON_IE_IN_4WAY_DIFFERS     = 17,   /* 11i */
874         IEEE80211_REASON_GROUP_CIPHER_INVALID   = 18,   /* 11i */
875         IEEE80211_REASON_PAIRWISE_CIPHER_INVALID= 19,   /* 11i */
876         IEEE80211_REASON_AKMP_INVALID           = 20,   /* 11i */
877         IEEE80211_REASON_UNSUPP_RSN_IE_VERSION  = 21,   /* 11i */
878         IEEE80211_REASON_INVALID_RSN_IE_CAP     = 22,   /* 11i */
879         IEEE80211_REASON_802_1X_AUTH_FAILED     = 23,   /* 11i */
880         IEEE80211_REASON_CIPHER_SUITE_REJECTED  = 24,   /* 11i */
881         IEEE80211_REASON_UNSPECIFIED_QOS        = 32,   /* 11e */
882         IEEE80211_REASON_INSUFFICIENT_BW        = 33,   /* 11e */
883         IEEE80211_REASON_TOOMANY_FRAMES         = 34,   /* 11e */
884         IEEE80211_REASON_OUTSIDE_TXOP           = 35,   /* 11e */
885         IEEE80211_REASON_LEAVING_QBSS           = 36,   /* 11e */
886         IEEE80211_REASON_BAD_MECHANISM          = 37,   /* 11e */
887         IEEE80211_REASON_SETUP_NEEDED           = 38,   /* 11e */
888         IEEE80211_REASON_TIMEOUT                = 39,   /* 11e */
889
890         IEEE80211_STATUS_SUCCESS                = 0,
891         IEEE80211_STATUS_UNSPECIFIED            = 1,
892         IEEE80211_STATUS_CAPINFO                = 10,
893         IEEE80211_STATUS_NOT_ASSOCED            = 11,
894         IEEE80211_STATUS_OTHER                  = 12,
895         IEEE80211_STATUS_ALG                    = 13,
896         IEEE80211_STATUS_SEQUENCE               = 14,
897         IEEE80211_STATUS_CHALLENGE              = 15,
898         IEEE80211_STATUS_TIMEOUT                = 16,
899         IEEE80211_STATUS_TOOMANY                = 17,
900         IEEE80211_STATUS_BASIC_RATE             = 18,
901         IEEE80211_STATUS_SP_REQUIRED            = 19,   /* 11b */
902         IEEE80211_STATUS_PBCC_REQUIRED          = 20,   /* 11b */
903         IEEE80211_STATUS_CA_REQUIRED            = 21,   /* 11b */
904         IEEE80211_STATUS_SPECMGMT_REQUIRED      = 22,   /* 11h */
905         IEEE80211_STATUS_PWRCAP_REQUIRED        = 23,   /* 11h */
906         IEEE80211_STATUS_SUPCHAN_REQUIRED       = 24,   /* 11h */
907         IEEE80211_STATUS_SHORTSLOT_REQUIRED     = 25,   /* 11g */
908         IEEE80211_STATUS_DSSSOFDM_REQUIRED      = 26,   /* 11g */
909         IEEE80211_STATUS_MISSING_HT_CAPS        = 27,   /* 11n D3.0 */
910         IEEE80211_STATUS_INVALID_IE             = 40,   /* 11i */
911         IEEE80211_STATUS_GROUP_CIPHER_INVALID   = 41,   /* 11i */
912         IEEE80211_STATUS_PAIRWISE_CIPHER_INVALID = 42,  /* 11i */
913         IEEE80211_STATUS_AKMP_INVALID           = 43,   /* 11i */
914         IEEE80211_STATUS_UNSUPP_RSN_IE_VERSION  = 44,   /* 11i */
915         IEEE80211_STATUS_INVALID_RSN_IE_CAP     = 45,   /* 11i */
916         IEEE80211_STATUS_CIPHER_SUITE_REJECTED  = 46,   /* 11i */
917 };
918
919 #define IEEE80211_WEP_KEYLEN            5       /* 40bit */
920 #define IEEE80211_WEP_IVLEN             3       /* 24bit */
921 #define IEEE80211_WEP_KIDLEN            1       /* 1 octet */
922 #define IEEE80211_WEP_CRCLEN            4       /* CRC-32 */
923 #define IEEE80211_WEP_TOTLEN            (IEEE80211_WEP_IVLEN + \
924                                          IEEE80211_WEP_KIDLEN + \
925                                          IEEE80211_WEP_CRCLEN)
926 #define IEEE80211_WEP_NKID              4       /* number of key ids */
927
928 /*
929  * 802.11i defines an extended IV for use with non-WEP ciphers.
930  * When the EXTIV bit is set in the key id byte an additional
931  * 4 bytes immediately follow the IV for TKIP.  For CCMP the
932  * EXTIV bit is likewise set but the 8 bytes represent the
933  * CCMP header rather than IV+extended-IV.
934  */
935 #define IEEE80211_WEP_EXTIV             0x20
936 #define IEEE80211_WEP_EXTIVLEN          4       /* extended IV length */
937 #define IEEE80211_WEP_MICLEN            8       /* trailing MIC */
938
939 #define IEEE80211_CRC_LEN               4
940
941 /*
942  * Maximum acceptable MTU is:
943  *      IEEE80211_MAX_LEN - WEP overhead - CRC -
944  *              QoS overhead - RSN/WPA overhead
945  * Min is arbitrarily chosen > IEEE80211_MIN_LEN.  The default
946  * mtu is Ethernet-compatible; it's set by ether_ifattach.
947  */
948 #define IEEE80211_MTU_MAX               2290
949 #define IEEE80211_MTU_MIN               32
950
951 #define IEEE80211_MAX_LEN               (2300 + IEEE80211_CRC_LEN + \
952     (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
953 #define IEEE80211_ACK_LEN \
954         (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
955 #define IEEE80211_MIN_LEN \
956         (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
957
958 /*
959  * The 802.11 spec says at most 2007 stations may be
960  * associated at once.  For most AP's this is way more
961  * than is feasible so we use a default of IEEE80211_AID_DEF.
962  * This number may be overridden by the driver and/or by
963  * user configuration but may not be less than IEEE80211_AID_MIN
964  * (see _ieee80211.h for implementation-specific settings).
965  */
966 #define IEEE80211_AID_MAX               2007
967
968 #define IEEE80211_AID(b)        ((b) &~ 0xc000)
969
970 /* 
971  * RTS frame length parameters.  The default is specified in
972  * the 802.11 spec as 512; we treat it as implementation-dependent
973  * so it's defined in ieee80211_var.h.  The max may be wrong
974  * for jumbo frames.
975  */
976 #define IEEE80211_RTS_MIN               1
977 #define IEEE80211_RTS_MAX               2346
978
979 /* 
980  * TX fragmentation parameters.  As above for RTS, we treat
981  * default as implementation-dependent so define it elsewhere.
982  */
983 #define IEEE80211_FRAG_MIN              256
984 #define IEEE80211_FRAG_MAX              2346
985
986 /*
987  * Beacon interval (TU's).  Min+max come from WiFi requirements.
988  * As above, we treat default as implementation-dependent so
989  * define it elsewhere.
990  */
991 #define IEEE80211_BINTVAL_MAX   1000    /* max beacon interval (TU's) */
992 #define IEEE80211_BINTVAL_MIN   25      /* min beacon interval (TU's) */
993
994 /*
995  * DTIM period (beacons).  Min+max are not really defined
996  * by the protocol but we want them publicly visible so
997  * define them here.
998  */
999 #define IEEE80211_DTIM_MAX      15      /* max DTIM period */
1000 #define IEEE80211_DTIM_MIN      1       /* min DTIM period */
1001
1002 /*
1003  * Beacon miss threshold (beacons).  As for DTIM, we define
1004  * them here to be publicly visible.  Note the max may be
1005  * clamped depending on device capabilities.
1006  */
1007 #define IEEE80211_HWBMISS_MIN   1
1008 #define IEEE80211_HWBMISS_MAX   255
1009
1010 /*
1011  * 802.11 frame duration definitions.
1012  */
1013
1014 struct ieee80211_duration {
1015         uint16_t        d_rts_dur;
1016         uint16_t        d_data_dur;
1017         uint16_t        d_plcp_len;
1018         uint8_t         d_residue;      /* unused octets in time slot */
1019 };
1020
1021 /* One Time Unit (TU) is 1Kus = 1024 microseconds. */
1022 #define IEEE80211_DUR_TU                1024
1023
1024 /* IEEE 802.11b durations for DSSS PHY in microseconds */
1025 #define IEEE80211_DUR_DS_LONG_PREAMBLE  144
1026 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72
1027
1028 #define IEEE80211_DUR_DS_SLOW_PLCPHDR   48
1029 #define IEEE80211_DUR_DS_FAST_PLCPHDR   24
1030 #define IEEE80211_DUR_DS_SLOW_ACK       112
1031 #define IEEE80211_DUR_DS_FAST_ACK       56
1032 #define IEEE80211_DUR_DS_SLOW_CTS       112
1033 #define IEEE80211_DUR_DS_FAST_CTS       56
1034
1035 #define IEEE80211_DUR_DS_SLOT           20
1036 #define IEEE80211_DUR_DS_SIFS           10
1037 #define IEEE80211_DUR_DS_PIFS   (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT)
1038 #define IEEE80211_DUR_DS_DIFS   (IEEE80211_DUR_DS_SIFS + \
1039                                  2 * IEEE80211_DUR_DS_SLOT)
1040 #define IEEE80211_DUR_DS_EIFS   (IEEE80211_DUR_DS_SIFS + \
1041                                  IEEE80211_DUR_DS_SLOW_ACK + \
1042                                  IEEE80211_DUR_DS_LONG_PREAMBLE + \
1043                                  IEEE80211_DUR_DS_SLOW_PLCPHDR + \
1044                                  IEEE80211_DUR_DIFS)
1045
1046 #endif /* _NET80211_IEEE80211_H_ */