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