ieee80211.h revision 1.2 1 /* $NetBSD: ieee80211.h,v 1.2 2003/09/14 01:14:54 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.2 2003/06/27 05:13:52 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 /*
56 * generic definitions for IEEE 802.11 frames
57 */
58 struct ieee80211_frame {
59 u_int8_t i_fc[2];
60 u_int8_t i_dur[2];
61 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
62 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
63 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
64 u_int8_t i_seq[2];
65 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
66 /* see below */
67 } __attribute__((__packed__));
68
69 struct ieee80211_frame_addr4 {
70 u_int8_t i_fc[2];
71 u_int8_t i_dur[2];
72 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
73 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
74 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
75 u_int8_t i_seq[2];
76 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
77 } __attribute__((__packed__));
78
79 #define IEEE80211_FC0_VERSION_MASK 0x03
80 #define IEEE80211_FC0_VERSION_SHIFT 0
81 #define IEEE80211_FC0_VERSION_0 0x00
82 #define IEEE80211_FC0_TYPE_MASK 0x0c
83 #define IEEE80211_FC0_TYPE_SHIFT 2
84 #define IEEE80211_FC0_TYPE_MGT 0x00
85 #define IEEE80211_FC0_TYPE_CTL 0x04
86 #define IEEE80211_FC0_TYPE_DATA 0x08
87
88 #define IEEE80211_FC0_SUBTYPE_MASK 0xf0
89 #define IEEE80211_FC0_SUBTYPE_SHIFT 4
90 /* for TYPE_MGT */
91 #define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00
92 #define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10
93 #define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20
94 #define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30
95 #define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40
96 #define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50
97 #define IEEE80211_FC0_SUBTYPE_BEACON 0x80
98 #define IEEE80211_FC0_SUBTYPE_ATIM 0x90
99 #define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0
100 #define IEEE80211_FC0_SUBTYPE_AUTH 0xb0
101 #define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0
102 /* for TYPE_CTL */
103 #define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0
104 #define IEEE80211_FC0_SUBTYPE_RTS 0xb0
105 #define IEEE80211_FC0_SUBTYPE_CTS 0xc0
106 #define IEEE80211_FC0_SUBTYPE_ACK 0xd0
107 #define IEEE80211_FC0_SUBTYPE_CF_END 0xe0
108 #define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0
109 /* for TYPE_DATA (bit combination) */
110 #define IEEE80211_FC0_SUBTYPE_DATA 0x00
111 #define IEEE80211_FC0_SUBTYPE_CF_ACK 0x10
112 #define IEEE80211_FC0_SUBTYPE_CF_POLL 0x20
113 #define IEEE80211_FC0_SUBTYPE_CF_ACPL 0x30
114 #define IEEE80211_FC0_SUBTYPE_NODATA 0x40
115 #define IEEE80211_FC0_SUBTYPE_CFACK 0x50
116 #define IEEE80211_FC0_SUBTYPE_CFPOLL 0x60
117 #define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70
118
119 #define IEEE80211_FC1_DIR_MASK 0x03
120 #define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
121 #define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
122 #define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
123 #define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
124
125 #define IEEE80211_FC1_MORE_FRAG 0x04
126 #define IEEE80211_FC1_RETRY 0x08
127 #define IEEE80211_FC1_PWR_MGT 0x10
128 #define IEEE80211_FC1_MORE_DATA 0x20
129 #define IEEE80211_FC1_WEP 0x40
130 #define IEEE80211_FC1_ORDER 0x80
131
132 #define IEEE80211_SEQ_FRAG_MASK 0x000f
133 #define IEEE80211_SEQ_FRAG_SHIFT 0
134 #define IEEE80211_SEQ_SEQ_MASK 0xfff0
135 #define IEEE80211_SEQ_SEQ_SHIFT 4
136
137 #define IEEE80211_NWID_LEN 32
138
139 /*
140 * BEACON management packets
141 *
142 * octet timestamp[8]
143 * octet beacon interval[2]
144 * octet capability information[2]
145 * information element
146 * octet elemid
147 * octet length
148 * octet information[length]
149 */
150
151 typedef uint8_t *ieee80211_mgt_beacon_t;
152
153 #define IEEE80211_BEACON_INTERVAL(beacon) \
154 ((beacon)[8] | ((beacon)[9] << 8))
155 #define IEEE80211_BEACON_CAPABILITY(beacon) \
156 ((beacon)[10] | ((beacon)[11] << 8))
157
158 #define IEEE80211_CAPINFO_ESS 0x0001
159 #define IEEE80211_CAPINFO_IBSS 0x0002
160 #define IEEE80211_CAPINFO_CF_POLLABLE 0x0004
161 #define IEEE80211_CAPINFO_CF_POLLREQ 0x0008
162 #define IEEE80211_CAPINFO_PRIVACY 0x0010
163 #define IEEE80211_CAPINFO_SHORT_PREAMBLE 0x0020
164 #define IEEE80211_CAPINFO_PBCC 0x0040
165 #define IEEE80211_CAPINFO_CHNL_AGILITY 0x0080
166 /* bits 8-9 are reserved */
167 #define IEEE80211_CAPINFO_SHORT_SLOTTIME 0x0400
168 /* bits 11-12 are reserved */
169 #define IEEE80211_CAPINFO_DSSSOFDM 0x2000
170 /* bits 14-15 are reserved */
171
172 /*
173 * Management information elements
174 */
175 struct ieee80211_information {
176 char ssid[IEEE80211_NWID_LEN+1];
177 struct rates {
178 u_int8_t *p;
179 } rates;
180 struct fh {
181 u_int16_t dwell;
182 u_int8_t set;
183 u_int8_t pattern;
184 u_int8_t index;
185 } fh;
186 struct ds {
187 u_int8_t channel;
188 } ds;
189 struct cf {
190 u_int8_t count;
191 u_int8_t period;
192 u_int8_t maxdur[2];
193 u_int8_t dur[2];
194 } cf;
195 struct tim {
196 u_int8_t count;
197 u_int8_t period;
198 u_int8_t bitctl;
199 /* u_int8_t pvt[251]; The driver needs to use this. */
200 } tim;
201 struct ibss {
202 u_int16_t atim;
203 } ibss;
204 struct challenge {
205 u_int8_t *p;
206 u_int8_t len;
207 } challenge;
208 struct erp {
209 u_int8_t flags;
210 } erp;
211 };
212
213 enum {
214 IEEE80211_ELEMID_SSID = 0,
215 IEEE80211_ELEMID_RATES = 1,
216 IEEE80211_ELEMID_FHPARMS = 2,
217 IEEE80211_ELEMID_DSPARMS = 3,
218 IEEE80211_ELEMID_CFPARMS = 4,
219 IEEE80211_ELEMID_TIM = 5,
220 IEEE80211_ELEMID_IBSSPARMS = 6,
221 IEEE80211_ELEMID_COUNTRY = 7,
222 IEEE80211_ELEMID_CHALLENGE = 16,
223 IEEE80211_ELEMID_ERP = 42,
224 IEEE80211_ELEMID_XRATES = 50,
225 };
226
227 #define IEEE80211_RATE_BASIC 0x80
228 #define IEEE80211_RATE_VAL 0x7f
229
230 /* EPR information element flags */
231 #define IEEE80211_ERP_NON_ERP_PRESENT 0x01
232 #define IEEE80211_ERP_USE_PROTECTION 0x02
233 #define IEEE80211_ERP_BARKER_MODE 0x04
234
235 /*
236 * AUTH management packets
237 *
238 * octet algo[2]
239 * octet seq[2]
240 * octet status[2]
241 * octet chal.id
242 * octet chal.length
243 * octet chal.text[253]
244 */
245
246 typedef u_int8_t *ieee80211_mgt_auth_t;
247
248 #define IEEE80211_AUTH_ALGORITHM(auth) \
249 ((auth)[0] | ((auth)[1] << 8))
250 #define IEEE80211_AUTH_TRANSACTION(auth) \
251 ((auth)[2] | ((auth)[3] << 8))
252 #define IEEE80211_AUTH_STATUS(auth) \
253 ((auth)[4] | ((auth)[5] << 8))
254
255 #define IEEE80211_AUTH_ALG_OPEN 0x0000
256 #define IEEE80211_AUTH_ALG_SHARED 0x0001
257
258 enum {
259 IEEE80211_AUTH_OPEN_REQUEST = 1,
260 IEEE80211_AUTH_OPEN_RESPONSE = 2,
261 };
262
263 enum {
264 IEEE80211_AUTH_SHARED_REQUEST = 1,
265 IEEE80211_AUTH_SHARED_CHALLENGE = 2,
266 IEEE80211_AUTH_SHARED_RESPONSE = 3,
267 IEEE80211_AUTH_SHARED_PASS = 4,
268 };
269
270 /*
271 * Reason codes
272 *
273 * Unlisted codes are reserved
274 */
275
276 enum {
277 IEEE80211_REASON_UNSPECIFIED = 1,
278 IEEE80211_REASON_AUTH_EXPIRE = 2,
279 IEEE80211_REASON_AUTH_LEAVE = 3,
280 IEEE80211_REASON_ASSOC_EXPIRE = 4,
281 IEEE80211_REASON_ASSOC_TOOMANY = 5,
282 IEEE80211_REASON_NOT_AUTHED = 6,
283 IEEE80211_REASON_NOT_ASSOCED = 7,
284 IEEE80211_REASON_ASSOC_LEAVE = 8,
285 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
286
287 IEEE80211_STATUS_SUCCESS = 0,
288 IEEE80211_STATUS_UNSPECIFIED = 1,
289 IEEE80211_STATUS_CAPINFO = 10,
290 IEEE80211_STATUS_NOT_ASSOCED = 11,
291 IEEE80211_STATUS_OTHER = 12,
292 IEEE80211_STATUS_ALG = 13,
293 IEEE80211_STATUS_SEQUENCE = 14,
294 IEEE80211_STATUS_CHALLENGE = 15,
295 IEEE80211_STATUS_TIMEOUT = 16,
296 IEEE80211_STATUS_TOOMANY = 17,
297 IEEE80211_STATUS_BASIC_RATE = 18,
298 IEEE80211_STATUS_SP_REQUIRED = 19,
299 IEEE80211_STATUS_PBCC_REQUIRED = 20,
300 IEEE80211_STATUS_CA_REQUIRED = 21,
301 IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
302 IEEE80211_STATUS_RATES = 23,
303 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
304 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
305 };
306
307 #define IEEE80211_WEP_KEYLEN 5 /* 40bit */
308 #define IEEE80211_WEP_IVLEN 3 /* 24bit */
309 #define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
310 #define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
311 #define IEEE80211_WEP_NKID 4 /* number of key ids */
312
313 #define IEEE80211_CRC_LEN 4
314
315 #define IEEE80211_MTU 1500
316 #define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \
317 (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
318
319 /*
320 * RTS frame length parameters. The default is specified in
321 * the 802.11 spec. The max may be wrong for jumbo frames.
322 */
323 #define IEEE80211_RTS_DEFAULT 512
324 #define IEEE80211_RTS_MIN 1
325 #define IEEE80211_RTS_MAX IEEE80211_MAX_LEN
326
327 enum {
328 IEEE80211_AUTH_NONE = 0,
329 IEEE80211_AUTH_OPEN = 1,
330 IEEE80211_AUTH_SHARED = 2,
331 };
332
333 #endif /* _NET80211_IEEE80211_H_ */
334