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