ieee80211.h revision 124457
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002, 2003 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 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: head/sys/net80211/ieee80211.h 124457 2004-01-13 06:22:55Z sam $
33 */
34#ifndef _NET80211_IEEE80211_H_
35#define _NET80211_IEEE80211_H_
36
37/*
38 * 802.11 protocol definitions.
39 */
40
41#define	IEEE80211_ADDR_LEN	6		/* size of 802.11 address */
42/* is 802.11 address multicast/broadcast? */
43#define	IEEE80211_IS_MULTICAST(_a)	(*(_a) & 0x01)
44
45/* IEEE 802.11 PLCP header */
46struct ieee80211_plcp_hdr {
47	u_int16_t	i_sfd;
48	u_int8_t	i_signal;
49	u_int8_t	i_service;
50	u_int16_t	i_length;
51	u_int16_t	i_crc;
52} __attribute__((__packed__));
53
54/*
55 * generic definitions for IEEE 802.11 frames
56 */
57struct ieee80211_frame {
58	u_int8_t	i_fc[2];
59	u_int8_t	i_dur[2];
60	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
61	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
62	u_int8_t	i_addr3[IEEE80211_ADDR_LEN];
63	u_int8_t	i_seq[2];
64	/* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
65	/* see below */
66} __attribute__((__packed__));
67
68struct ieee80211_frame_addr4 {
69	u_int8_t	i_fc[2];
70	u_int8_t	i_dur[2];
71	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
72	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
73	u_int8_t	i_addr3[IEEE80211_ADDR_LEN];
74	u_int8_t	i_seq[2];
75	u_int8_t	i_addr4[IEEE80211_ADDR_LEN];
76} __attribute__((__packed__));
77
78#define	IEEE80211_FC0_VERSION_MASK		0x03
79#define	IEEE80211_FC0_VERSION_SHIFT		0
80#define	IEEE80211_FC0_VERSION_0			0x00
81#define	IEEE80211_FC0_TYPE_MASK			0x0c
82#define	IEEE80211_FC0_TYPE_SHIFT		2
83#define	IEEE80211_FC0_TYPE_MGT			0x00
84#define	IEEE80211_FC0_TYPE_CTL			0x04
85#define	IEEE80211_FC0_TYPE_DATA			0x08
86
87#define	IEEE80211_FC0_SUBTYPE_MASK		0xf0
88#define	IEEE80211_FC0_SUBTYPE_SHIFT		4
89/* for TYPE_MGT */
90#define	IEEE80211_FC0_SUBTYPE_ASSOC_REQ		0x00
91#define	IEEE80211_FC0_SUBTYPE_ASSOC_RESP	0x10
92#define	IEEE80211_FC0_SUBTYPE_REASSOC_REQ	0x20
93#define	IEEE80211_FC0_SUBTYPE_REASSOC_RESP	0x30
94#define	IEEE80211_FC0_SUBTYPE_PROBE_REQ		0x40
95#define	IEEE80211_FC0_SUBTYPE_PROBE_RESP	0x50
96#define	IEEE80211_FC0_SUBTYPE_BEACON		0x80
97#define	IEEE80211_FC0_SUBTYPE_ATIM		0x90
98#define	IEEE80211_FC0_SUBTYPE_DISASSOC		0xa0
99#define	IEEE80211_FC0_SUBTYPE_AUTH		0xb0
100#define	IEEE80211_FC0_SUBTYPE_DEAUTH		0xc0
101/* for TYPE_CTL */
102#define	IEEE80211_FC0_SUBTYPE_PS_POLL		0xa0
103#define	IEEE80211_FC0_SUBTYPE_RTS		0xb0
104#define	IEEE80211_FC0_SUBTYPE_CTS		0xc0
105#define	IEEE80211_FC0_SUBTYPE_ACK		0xd0
106#define	IEEE80211_FC0_SUBTYPE_CF_END		0xe0
107#define	IEEE80211_FC0_SUBTYPE_CF_END_ACK	0xf0
108/* for TYPE_DATA (bit combination) */
109#define	IEEE80211_FC0_SUBTYPE_DATA		0x00
110#define	IEEE80211_FC0_SUBTYPE_CF_ACK		0x10
111#define	IEEE80211_FC0_SUBTYPE_CF_POLL		0x20
112#define	IEEE80211_FC0_SUBTYPE_CF_ACPL		0x30
113#define	IEEE80211_FC0_SUBTYPE_NODATA		0x40
114#define	IEEE80211_FC0_SUBTYPE_CFACK		0x50
115#define	IEEE80211_FC0_SUBTYPE_CFPOLL		0x60
116#define	IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK	0x70
117
118#define	IEEE80211_FC1_DIR_MASK			0x03
119#define	IEEE80211_FC1_DIR_NODS			0x00	/* STA->STA */
120#define	IEEE80211_FC1_DIR_TODS			0x01	/* STA->AP  */
121#define	IEEE80211_FC1_DIR_FROMDS		0x02	/* AP ->STA */
122#define	IEEE80211_FC1_DIR_DSTODS		0x03	/* AP ->AP  */
123
124#define	IEEE80211_FC1_MORE_FRAG			0x04
125#define	IEEE80211_FC1_RETRY			0x08
126#define	IEEE80211_FC1_PWR_MGT			0x10
127#define	IEEE80211_FC1_MORE_DATA			0x20
128#define	IEEE80211_FC1_WEP			0x40
129#define	IEEE80211_FC1_ORDER			0x80
130
131#define	IEEE80211_SEQ_FRAG_MASK			0x000f
132#define	IEEE80211_SEQ_FRAG_SHIFT		0
133#define	IEEE80211_SEQ_SEQ_MASK			0xfff0
134#define	IEEE80211_SEQ_SEQ_SHIFT			4
135
136#define	IEEE80211_NWID_LEN			32
137
138/*
139 * Control frames.
140 */
141struct ieee80211_frame_min {
142	u_int8_t	i_fc[2];
143	u_int8_t	i_dur[2];
144	u_int8_t	i_addr1[IEEE80211_ADDR_LEN];
145	u_int8_t	i_addr2[IEEE80211_ADDR_LEN];
146	/* FCS */
147} __attribute__((__packed__));
148
149struct ieee80211_frame_rts {
150	u_int8_t	i_fc[2];
151	u_int8_t	i_dur[2];
152	u_int8_t	i_ra[IEEE80211_ADDR_LEN];
153	u_int8_t	i_ta[IEEE80211_ADDR_LEN];
154	/* FCS */
155} __attribute__((__packed__));
156
157struct ieee80211_frame_cts {
158	u_int8_t	i_fc[2];
159	u_int8_t	i_dur[2];
160	u_int8_t	i_ra[IEEE80211_ADDR_LEN];
161	/* FCS */
162} __attribute__((__packed__));
163
164struct ieee80211_frame_ack {
165	u_int8_t	i_fc[2];
166	u_int8_t	i_dur[2];
167	u_int8_t	i_ra[IEEE80211_ADDR_LEN];
168	/* FCS */
169} __attribute__((__packed__));
170
171struct ieee80211_frame_pspoll {
172	u_int8_t	i_fc[2];
173	u_int8_t	i_aid[2];
174	u_int8_t	i_bssid[IEEE80211_ADDR_LEN];
175	u_int8_t	i_ta[IEEE80211_ADDR_LEN];
176	/* FCS */
177} __attribute__((__packed__));
178
179struct ieee80211_frame_cfend {		/* NB: also CF-End+CF-Ack */
180	u_int8_t	i_fc[2];
181	u_int8_t	i_dur[2];	/* should be zero */
182	u_int8_t	i_ra[IEEE80211_ADDR_LEN];
183	u_int8_t	i_bssid[IEEE80211_ADDR_LEN];
184	/* FCS */
185} __attribute__((__packed__));
186
187/*
188 * BEACON management packets
189 *
190 *	octet timestamp[8]
191 *	octet beacon interval[2]
192 *	octet capability information[2]
193 *	information element
194 *		octet elemid
195 *		octet length
196 *		octet information[length]
197 */
198
199typedef uint8_t *ieee80211_mgt_beacon_t;
200
201#define	IEEE80211_BEACON_INTERVAL(beacon) \
202	((beacon)[8] | ((beacon)[9] << 8))
203#define	IEEE80211_BEACON_CAPABILITY(beacon) \
204	((beacon)[10] | ((beacon)[11] << 8))
205
206#define	IEEE80211_CAPINFO_ESS			0x0001
207#define	IEEE80211_CAPINFO_IBSS			0x0002
208#define	IEEE80211_CAPINFO_CF_POLLABLE		0x0004
209#define	IEEE80211_CAPINFO_CF_POLLREQ		0x0008
210#define	IEEE80211_CAPINFO_PRIVACY		0x0010
211#define	IEEE80211_CAPINFO_SHORT_PREAMBLE	0x0020
212#define	IEEE80211_CAPINFO_PBCC			0x0040
213#define	IEEE80211_CAPINFO_CHNL_AGILITY		0x0080
214/* bits 8-9 are reserved */
215#define	IEEE80211_CAPINFO_SHORT_SLOTTIME	0x0400
216/* bits 11-12 are reserved */
217#define	IEEE80211_CAPINFO_DSSSOFDM		0x2000
218/* bits 14-15 are reserved */
219
220/*
221 * Management information elements
222 */
223struct ieee80211_information {
224	char	ssid[IEEE80211_NWID_LEN+1];
225	struct rates {
226		u_int8_t	*p;
227	} rates;
228	struct fh {
229		u_int16_t	dwell;
230		u_int8_t	set;
231		u_int8_t	pattern;
232		u_int8_t	index;
233	} fh;
234	struct ds {
235		u_int8_t	channel;
236	} ds;
237	struct cf {
238		u_int8_t	count;
239		u_int8_t	period;
240		u_int8_t	maxdur[2];
241		u_int8_t	dur[2];
242	} cf;
243	struct tim {
244		u_int8_t	count;
245		u_int8_t	period;
246		u_int8_t	bitctl;
247		/* u_int8_t	pvt[251]; The driver needs to use this. */
248	} tim;
249	struct ibss {
250		u_int16_t	atim;
251	} ibss;
252	struct challenge {
253		u_int8_t	*p;
254		u_int8_t	len;
255	} challenge;
256	struct erp {
257		u_int8_t	flags;
258	} erp;
259};
260
261enum {
262	IEEE80211_ELEMID_SSID			= 0,
263	IEEE80211_ELEMID_RATES			= 1,
264	IEEE80211_ELEMID_FHPARMS		= 2,
265	IEEE80211_ELEMID_DSPARMS		= 3,
266	IEEE80211_ELEMID_CFPARMS		= 4,
267	IEEE80211_ELEMID_TIM			= 5,
268	IEEE80211_ELEMID_IBSSPARMS		= 6,
269	IEEE80211_ELEMID_COUNTRY		= 7,
270	IEEE80211_ELEMID_CHALLENGE		= 16,
271	IEEE80211_ELEMID_ERP			= 42,
272	IEEE80211_ELEMID_XRATES			= 50,
273};
274
275#define	IEEE80211_RATE_BASIC			0x80
276#define	IEEE80211_RATE_VAL			0x7f
277
278/* EPR information element flags */
279#define	IEEE80211_ERP_NON_ERP_PRESENT		0x01
280#define	IEEE80211_ERP_USE_PROTECTION		0x02
281#define	IEEE80211_ERP_BARKER_MODE		0x04
282
283/*
284 * AUTH management packets
285 *
286 *	octet algo[2]
287 *	octet seq[2]
288 *	octet status[2]
289 *	octet chal.id
290 *	octet chal.length
291 *	octet chal.text[253]
292 */
293
294typedef u_int8_t *ieee80211_mgt_auth_t;
295
296#define	IEEE80211_AUTH_ALGORITHM(auth) \
297	((auth)[0] | ((auth)[1] << 8))
298#define	IEEE80211_AUTH_TRANSACTION(auth) \
299	((auth)[2] | ((auth)[3] << 8))
300#define	IEEE80211_AUTH_STATUS(auth) \
301	((auth)[4] | ((auth)[5] << 8))
302
303#define	IEEE80211_AUTH_ALG_OPEN			0x0000
304#define	IEEE80211_AUTH_ALG_SHARED		0x0001
305
306enum {
307	IEEE80211_AUTH_OPEN_REQUEST		= 1,
308	IEEE80211_AUTH_OPEN_RESPONSE		= 2,
309};
310
311enum {
312	IEEE80211_AUTH_SHARED_REQUEST		= 1,
313	IEEE80211_AUTH_SHARED_CHALLENGE		= 2,
314	IEEE80211_AUTH_SHARED_RESPONSE		= 3,
315	IEEE80211_AUTH_SHARED_PASS		= 4,
316};
317
318/*
319 * Reason codes
320 *
321 * Unlisted codes are reserved
322 */
323
324enum {
325	IEEE80211_REASON_UNSPECIFIED		= 1,
326	IEEE80211_REASON_AUTH_EXPIRE		= 2,
327	IEEE80211_REASON_AUTH_LEAVE		= 3,
328	IEEE80211_REASON_ASSOC_EXPIRE		= 4,
329	IEEE80211_REASON_ASSOC_TOOMANY		= 5,
330	IEEE80211_REASON_NOT_AUTHED		= 6,
331	IEEE80211_REASON_NOT_ASSOCED		= 7,
332	IEEE80211_REASON_ASSOC_LEAVE		= 8,
333	IEEE80211_REASON_ASSOC_NOT_AUTHED	= 9,
334
335	IEEE80211_STATUS_SUCCESS		= 0,
336	IEEE80211_STATUS_UNSPECIFIED		= 1,
337	IEEE80211_STATUS_CAPINFO		= 10,
338	IEEE80211_STATUS_NOT_ASSOCED		= 11,
339	IEEE80211_STATUS_OTHER			= 12,
340	IEEE80211_STATUS_ALG			= 13,
341	IEEE80211_STATUS_SEQUENCE		= 14,
342	IEEE80211_STATUS_CHALLENGE		= 15,
343	IEEE80211_STATUS_TIMEOUT		= 16,
344	IEEE80211_STATUS_TOOMANY		= 17,
345	IEEE80211_STATUS_BASIC_RATE		= 18,
346	IEEE80211_STATUS_SP_REQUIRED		= 19,
347	IEEE80211_STATUS_PBCC_REQUIRED		= 20,
348	IEEE80211_STATUS_CA_REQUIRED		= 21,
349	IEEE80211_STATUS_TOO_MANY_STATIONS	= 22,
350	IEEE80211_STATUS_RATES			= 23,
351	IEEE80211_STATUS_SHORTSLOT_REQUIRED	= 25,
352	IEEE80211_STATUS_DSSSOFDM_REQUIRED	= 26,
353};
354
355#define	IEEE80211_WEP_KEYLEN			5	/* 40bit */
356#define	IEEE80211_WEP_IVLEN			3	/* 24bit */
357#define	IEEE80211_WEP_KIDLEN			1	/* 1 octet */
358#define	IEEE80211_WEP_CRCLEN			4	/* CRC-32 */
359#define	IEEE80211_WEP_NKID			4	/* number of key ids */
360
361#define	IEEE80211_CRC_LEN			4
362
363/*
364 * Maximum acceptable MTU is:
365 *	IEEE80211_MAX_LEN - WEP overhead - CRC -
366 *		QoS overhead - RSN/WPA overhead
367 * Min is arbitrarily chosen > IEEE80211_MIN_LEN.  The default
368 * mtu is Ethernet-compatible; it's set by ether_ifattach.
369 */
370#define	IEEE80211_MTU_MAX			2290
371#define	IEEE80211_MTU_MIN			32
372
373#define	IEEE80211_MAX_LEN			(2300 + IEEE80211_CRC_LEN + \
374    (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
375#define	IEEE80211_MIN_LEN \
376	(sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
377
378/*
379 * RTS frame length parameters.  The default is specified in
380 * the 802.11 spec.  The max may be wrong for jumbo frames.
381 */
382#define	IEEE80211_RTS_DEFAULT			512
383#define	IEEE80211_RTS_MIN			1
384#define	IEEE80211_RTS_MAX			IEEE80211_MAX_LEN
385
386enum {
387	IEEE80211_AUTH_NONE	= 0,
388	IEEE80211_AUTH_OPEN	= 1,
389	IEEE80211_AUTH_SHARED	= 2,
390};
391
392#endif /* _NET80211_IEEE80211_H_ */
393