ieee802_11.h revision 195684
1/* $FreeBSD: head/contrib/tcpdump/ieee802_11.h 195684 2009-07-14 17:11:06Z sam $ */
2/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.12 2007-07-22 19:59:06 guy Exp $ (LBL) */
3/*
4 * Copyright (c) 2001
5 *	Fortress Technologies
6 *      Charlie Lenahan ( clenahan@fortresstech.com )
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
19 * written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 */
24
25/* Lengths of 802.11 header components. */
26#define	IEEE802_11_FC_LEN		2
27#define	IEEE802_11_DUR_LEN		2
28#define	IEEE802_11_DA_LEN		6
29#define	IEEE802_11_SA_LEN		6
30#define	IEEE802_11_BSSID_LEN		6
31#define	IEEE802_11_RA_LEN		6
32#define	IEEE802_11_TA_LEN		6
33#define	IEEE802_11_SEQ_LEN		2
34#define	IEEE802_11_CTL_LEN		2
35#define	IEEE802_11_IV_LEN		3
36#define	IEEE802_11_KID_LEN		1
37
38/* Frame check sequence length. */
39#define	IEEE802_11_FCS_LEN		4
40
41/* Lengths of beacon components. */
42#define	IEEE802_11_TSTAMP_LEN		8
43#define	IEEE802_11_BCNINT_LEN		2
44#define	IEEE802_11_CAPINFO_LEN		2
45#define	IEEE802_11_LISTENINT_LEN	2
46
47#define	IEEE802_11_AID_LEN		2
48#define	IEEE802_11_STATUS_LEN		2
49#define	IEEE802_11_REASON_LEN		2
50
51/* Length of previous AP in reassocation frame */
52#define	IEEE802_11_AP_LEN		6
53
54#define	T_MGMT 0x0  /* management */
55#define	T_CTRL 0x1  /* control */
56#define	T_DATA 0x2 /* data */
57#define	T_RESV 0x3  /* reserved */
58
59#define	ST_ASSOC_REQUEST   	0x0
60#define	ST_ASSOC_RESPONSE 	0x1
61#define	ST_REASSOC_REQUEST   	0x2
62#define	ST_REASSOC_RESPONSE  	0x3
63#define	ST_PROBE_REQUEST   	0x4
64#define	ST_PROBE_RESPONSE   	0x5
65/* RESERVED 			0x6  */
66/* RESERVED 			0x7  */
67#define	ST_BEACON   		0x8
68#define	ST_ATIM			0x9
69#define	ST_DISASSOC		0xA
70#define	ST_AUTH			0xB
71#define	ST_DEAUTH		0xC
72#define	ST_ACTION		0xD
73/* RESERVED 			0xE  */
74/* RESERVED 			0xF  */
75
76
77#define	CTRL_BAR	0x8
78#define	CTRL_BA		0x9
79#define	CTRL_PS_POLL	0xA
80#define	CTRL_RTS	0xB
81#define	CTRL_CTS	0xC
82#define	CTRL_ACK	0xD
83#define	CTRL_CF_END	0xE
84#define	CTRL_END_ACK	0xF
85
86#define	DATA_DATA			0x0
87#define	DATA_DATA_CF_ACK		0x1
88#define	DATA_DATA_CF_POLL		0x2
89#define	DATA_DATA_CF_ACK_POLL		0x3
90#define	DATA_NODATA			0x4
91#define	DATA_NODATA_CF_ACK		0x5
92#define	DATA_NODATA_CF_POLL		0x6
93#define	DATA_NODATA_CF_ACK_POLL		0x7
94
95#define DATA_QOS_DATA			0x8
96#define DATA_QOS_DATA_CF_ACK		0x9
97#define DATA_QOS_DATA_CF_POLL		0xA
98#define DATA_QOS_DATA_CF_ACK_POLL	0xB
99#define DATA_QOS_NODATA			0xC
100#define DATA_QOS_CF_POLL_NODATA		0xE
101#define DATA_QOS_CF_ACK_POLL_NODATA	0xF
102
103/*
104 * The subtype field of a data frame is, in effect, composed of 4 flag
105 * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
106 * any data), and QoS.
107 */
108#define DATA_FRAME_IS_CF_ACK(x)		((x) & 0x01)
109#define DATA_FRAME_IS_CF_POLL(x)	((x) & 0x02)
110#define DATA_FRAME_IS_NULL(x)		((x) & 0x04)
111#define DATA_FRAME_IS_QOS(x)		((x) & 0x08)
112
113/*
114 * Bits in the frame control field.
115 */
116#define	FC_VERSION(fc)		((fc) & 0x3)
117#define	FC_TYPE(fc)		(((fc) >> 2) & 0x3)
118#define	FC_SUBTYPE(fc)		(((fc) >> 4) & 0xF)
119#define	FC_TO_DS(fc)		((fc) & 0x0100)
120#define	FC_FROM_DS(fc)		((fc) & 0x0200)
121#define	FC_MORE_FLAG(fc)	((fc) & 0x0400)
122#define	FC_RETRY(fc)		((fc) & 0x0800)
123#define	FC_POWER_MGMT(fc)	((fc) & 0x1000)
124#define	FC_MORE_DATA(fc)	((fc) & 0x2000)
125#define	FC_WEP(fc)		((fc) & 0x4000)
126#define	FC_ORDER(fc)		((fc) & 0x8000)
127
128struct mgmt_header_t {
129	u_int16_t	fc;
130	u_int16_t 	duration;
131	u_int8_t	da[6];
132	u_int8_t	sa[6];
133	u_int8_t	bssid[6];
134	u_int16_t	seq_ctrl;
135};
136
137#define	MGMT_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
138			 IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
139			 IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
140
141#define	CAPABILITY_ESS(cap)	((cap) & 0x0001)
142#define	CAPABILITY_IBSS(cap)	((cap) & 0x0002)
143#define	CAPABILITY_CFP(cap)	((cap) & 0x0004)
144#define	CAPABILITY_CFP_REQ(cap)	((cap) & 0x0008)
145#define	CAPABILITY_PRIVACY(cap)	((cap) & 0x0010)
146
147typedef enum {
148	NOT_PRESENT,
149	PRESENT,
150	TRUNCATED
151} elem_status_t;
152
153struct ssid_t {
154	u_int8_t	element_id;
155	u_int8_t	length;
156	u_char		ssid[33];  /* 32 + 1 for null */
157};
158
159struct rates_t {
160	u_int8_t	element_id;
161	u_int8_t	length;
162	u_int8_t	rate[16];
163};
164
165struct challenge_t {
166	u_int8_t	element_id;
167	u_int8_t	length;
168	u_int8_t	text[254]; /* 1-253 + 1 for null */
169};
170
171struct fh_t {
172	u_int8_t	element_id;
173	u_int8_t	length;
174	u_int16_t	dwell_time;
175	u_int8_t	hop_set;
176	u_int8_t 	hop_pattern;
177	u_int8_t	hop_index;
178};
179
180struct ds_t {
181	u_int8_t	element_id;
182	u_int8_t	length;
183	u_int8_t	channel;
184};
185
186struct cf_t {
187	u_int8_t	element_id;
188	u_int8_t	length;
189	u_int8_t	count;
190	u_int8_t	period;
191	u_int16_t	max_duration;
192	u_int16_t	dur_remaing;
193};
194
195struct tim_t {
196	u_int8_t	element_id;
197	u_int8_t	length;
198	u_int8_t	count;
199	u_int8_t	period;
200	u_int8_t	bitmap_control;
201	u_int8_t	bitmap[251];
202};
203
204#define	E_SSID 		0
205#define	E_RATES 	1
206#define	E_FH	 	2
207#define	E_DS 		3
208#define	E_CF	 	4
209#define	E_TIM	 	5
210#define	E_IBSS 		6
211/* reserved 		7 */
212/* reserved 		8 */
213/* reserved 		9 */
214/* reserved 		10 */
215/* reserved 		11 */
216/* reserved 		12 */
217/* reserved 		13 */
218/* reserved 		14 */
219/* reserved 		15 */
220/* reserved 		16 */
221
222#define	E_CHALLENGE 	16
223/* reserved 		17 */
224/* reserved 		18 */
225/* reserved 		19 */
226/* reserved 		16 */
227/* reserved 		16 */
228
229
230struct mgmt_body_t {
231	u_int8_t   	timestamp[IEEE802_11_TSTAMP_LEN];
232	u_int16_t  	beacon_interval;
233	u_int16_t 	listen_interval;
234	u_int16_t 	status_code;
235	u_int16_t 	aid;
236	u_char		ap[IEEE802_11_AP_LEN];
237	u_int16_t	reason_code;
238	u_int16_t	auth_alg;
239	u_int16_t	auth_trans_seq_num;
240	elem_status_t	challenge_status;
241	struct challenge_t  challenge;
242	u_int16_t	capability_info;
243	elem_status_t	ssid_status;
244	struct ssid_t	ssid;
245	elem_status_t	rates_status;
246	struct rates_t 	rates;
247	elem_status_t	ds_status;
248	struct ds_t	ds;
249	elem_status_t	cf_status;
250	struct cf_t	cf;
251	elem_status_t	fh_status;
252	struct fh_t	fh;
253	elem_status_t	tim_status;
254	struct tim_t	tim;
255};
256
257struct ctrl_rts_t {
258	u_int16_t	fc;
259	u_int16_t	duration;
260	u_int8_t	ra[6];
261	u_int8_t	ta[6];
262	u_int8_t	fcs[4];
263};
264
265#define	CTRL_RTS_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
266			 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
267
268struct ctrl_cts_t {
269	u_int16_t	fc;
270	u_int16_t	duration;
271	u_int8_t	ra[6];
272	u_int8_t	fcs[4];
273};
274
275#define	CTRL_CTS_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
276
277struct ctrl_ack_t {
278	u_int16_t	fc;
279	u_int16_t	duration;
280	u_int8_t	ra[6];
281	u_int8_t	fcs[4];
282};
283
284#define	CTRL_ACK_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
285
286struct ctrl_ps_poll_t {
287	u_int16_t	fc;
288	u_int16_t	aid;
289	u_int8_t	bssid[6];
290	u_int8_t	ta[6];
291	u_int8_t	fcs[4];
292};
293
294#define	CTRL_PS_POLL_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
295				 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
296
297struct ctrl_end_t {
298	u_int16_t	fc;
299	u_int16_t	duration;
300	u_int8_t	ra[6];
301	u_int8_t	bssid[6];
302	u_int8_t	fcs[4];
303};
304
305#define	CTRL_END_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
306			 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
307
308struct ctrl_end_ack_t {
309	u_int16_t	fc;
310	u_int16_t	duration;
311	u_int8_t	ra[6];
312	u_int8_t	bssid[6];
313	u_int8_t	fcs[4];
314};
315
316#define	CTRL_END_ACK_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
317				 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
318
319struct ctrl_ba_t {
320	u_int16_t	fc;
321	u_int16_t	duration;
322	u_int8_t	ra[6];
323	u_int8_t	fcs[4];
324};
325
326#define	CTRL_BA_HDRLEN	(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
327
328struct ctrl_bar_t {
329	u_int16_t	fc;
330	u_int16_t	dur;
331	u_int8_t	ra[6];
332	u_int8_t	ta[6];
333	u_int16_t	ctl;
334	u_int16_t	seq;
335	u_int8_t	fcs[4];
336};
337
338#define	CTRL_BAR_HDRLEN		(IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
339				 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
340				 IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
341
342struct meshcntl_t {
343	u_int8_t	flags;
344	u_int8_t	ttl;
345	u_int8_t	seq[4];
346	u_int8_t	addr4[6];
347	u_int8_t	addr5[6];
348	u_int8_t	addr6[6];
349};
350
351#define	IV_IV(iv)	((iv) & 0xFFFFFF)
352#define	IV_PAD(iv)	(((iv) >> 24) & 0x3F)
353#define	IV_KEYID(iv)	(((iv) >> 30) & 0x03)
354