ieee80211.h revision 1.1 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: src/sys/net80211/ieee80211.h,v 1.2 2003/06/27 05:13:52 sam Exp $
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 */
46 struct 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 */
57 struct 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
68 struct 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 * BEACON management packets
140 *
141 * octet timestamp[8]
142 * octet beacon interval[2]
143 * octet capability information[2]
144 * information element
145 * octet elemid
146 * octet length
147 * octet information[length]
148 */
149
150 typedef uint8_t *ieee80211_mgt_beacon_t;
151
152 #define IEEE80211_BEACON_INTERVAL(beacon) \
153 ((beacon)[8] | ((beacon)[9] << 8))
154 #define IEEE80211_BEACON_CAPABILITY(beacon) \
155 ((beacon)[10] | ((beacon)[11] << 8))
156
157 #define IEEE80211_CAPINFO_ESS 0x0001
158 #define IEEE80211_CAPINFO_IBSS 0x0002
159 #define IEEE80211_CAPINFO_CF_POLLABLE 0x0004
160 #define IEEE80211_CAPINFO_CF_POLLREQ 0x0008
161 #define IEEE80211_CAPINFO_PRIVACY 0x0010
162 #define IEEE80211_CAPINFO_SHORT_PREAMBLE 0x0020
163 #define IEEE80211_CAPINFO_PBCC 0x0040
164 #define IEEE80211_CAPINFO_CHNL_AGILITY 0x0080
165 /* bits 8-9 are reserved */
166 #define IEEE80211_CAPINFO_SHORT_SLOTTIME 0x0400
167 /* bits 11-12 are reserved */
168 #define IEEE80211_CAPINFO_DSSSOFDM 0x2000
169 /* bits 14-15 are reserved */
170
171 /*
172 * Management information elements
173 */
174 struct ieee80211_information {
175 char ssid[IEEE80211_NWID_LEN+1];
176 struct rates {
177 u_int8_t *p;
178 } rates;
179 struct fh {
180 u_int16_t dwell;
181 u_int8_t set;
182 u_int8_t pattern;
183 u_int8_t index;
184 } fh;
185 struct ds {
186 u_int8_t channel;
187 } ds;
188 struct cf {
189 u_int8_t count;
190 u_int8_t period;
191 u_int8_t maxdur[2];
192 u_int8_t dur[2];
193 } cf;
194 struct tim {
195 u_int8_t count;
196 u_int8_t period;
197 u_int8_t bitctl;
198 /* u_int8_t pvt[251]; The driver needs to use this. */
199 } tim;
200 struct ibss {
201 u_int16_t atim;
202 } ibss;
203 struct challenge {
204 u_int8_t *p;
205 u_int8_t len;
206 } challenge;
207 struct erp {
208 u_int8_t flags;
209 } erp;
210 };
211
212 enum {
213 IEEE80211_ELEMID_SSID = 0,
214 IEEE80211_ELEMID_RATES = 1,
215 IEEE80211_ELEMID_FHPARMS = 2,
216 IEEE80211_ELEMID_DSPARMS = 3,
217 IEEE80211_ELEMID_CFPARMS = 4,
218 IEEE80211_ELEMID_TIM = 5,
219 IEEE80211_ELEMID_IBSSPARMS = 6,
220 IEEE80211_ELEMID_COUNTRY = 7,
221 IEEE80211_ELEMID_CHALLENGE = 16,
222 IEEE80211_ELEMID_ERP = 42,
223 IEEE80211_ELEMID_XRATES = 50,
224 };
225
226 #define IEEE80211_RATE_BASIC 0x80
227 #define IEEE80211_RATE_VAL 0x7f
228
229 /* EPR information element flags */
230 #define IEEE80211_ERP_NON_ERP_PRESENT 0x01
231 #define IEEE80211_ERP_USE_PROTECTION 0x02
232 #define IEEE80211_ERP_BARKER_MODE 0x04
233
234 /*
235 * AUTH management packets
236 *
237 * octet algo[2]
238 * octet seq[2]
239 * octet status[2]
240 * octet chal.id
241 * octet chal.length
242 * octet chal.text[253]
243 */
244
245 typedef u_int8_t *ieee80211_mgt_auth_t;
246
247 #define IEEE80211_AUTH_ALGORITHM(auth) \
248 ((auth)[0] | ((auth)[1] << 8))
249 #define IEEE80211_AUTH_TRANSACTION(auth) \
250 ((auth)[2] | ((auth)[3] << 8))
251 #define IEEE80211_AUTH_STATUS(auth) \
252 ((auth)[4] | ((auth)[5] << 8))
253
254 #define IEEE80211_AUTH_ALG_OPEN 0x0000
255 #define IEEE80211_AUTH_ALG_SHARED 0x0001
256
257 enum {
258 IEEE80211_AUTH_OPEN_REQUEST = 1,
259 IEEE80211_AUTH_OPEN_RESPONSE = 2,
260 };
261
262 enum {
263 IEEE80211_AUTH_SHARED_REQUEST = 1,
264 IEEE80211_AUTH_SHARED_CHALLENGE = 2,
265 IEEE80211_AUTH_SHARED_RESPONSE = 3,
266 IEEE80211_AUTH_SHARED_PASS = 4,
267 };
268
269 /*
270 * Reason codes
271 *
272 * Unlisted codes are reserved
273 */
274
275 enum {
276 IEEE80211_REASON_UNSPECIFIED = 1,
277 IEEE80211_REASON_AUTH_EXPIRE = 2,
278 IEEE80211_REASON_AUTH_LEAVE = 3,
279 IEEE80211_REASON_ASSOC_EXPIRE = 4,
280 IEEE80211_REASON_ASSOC_TOOMANY = 5,
281 IEEE80211_REASON_NOT_AUTHED = 6,
282 IEEE80211_REASON_NOT_ASSOCED = 7,
283 IEEE80211_REASON_ASSOC_LEAVE = 8,
284 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
285
286 IEEE80211_STATUS_SUCCESS = 0,
287 IEEE80211_STATUS_UNSPECIFIED = 1,
288 IEEE80211_STATUS_CAPINFO = 10,
289 IEEE80211_STATUS_NOT_ASSOCED = 11,
290 IEEE80211_STATUS_OTHER = 12,
291 IEEE80211_STATUS_ALG = 13,
292 IEEE80211_STATUS_SEQUENCE = 14,
293 IEEE80211_STATUS_CHALLENGE = 15,
294 IEEE80211_STATUS_TIMEOUT = 16,
295 IEEE80211_STATUS_TOOMANY = 17,
296 IEEE80211_STATUS_BASIC_RATE = 18,
297 IEEE80211_STATUS_SP_REQUIRED = 19,
298 IEEE80211_STATUS_PBCC_REQUIRED = 20,
299 IEEE80211_STATUS_CA_REQUIRED = 21,
300 IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
301 IEEE80211_STATUS_RATES = 23,
302 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
303 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
304 };
305
306 #define IEEE80211_WEP_KEYLEN 5 /* 40bit */
307 #define IEEE80211_WEP_IVLEN 3 /* 24bit */
308 #define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
309 #define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
310 #define IEEE80211_WEP_NKID 4 /* number of key ids */
311
312 #define IEEE80211_CRC_LEN 4
313
314 #define IEEE80211_MTU 1500
315 #define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \
316 (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
317
318 /*
319 * RTS frame length parameters. The default is specified in
320 * the 802.11 spec. The max may be wrong for jumbo frames.
321 */
322 #define IEEE80211_RTS_DEFAULT 512
323 #define IEEE80211_RTS_MIN 1
324 #define IEEE80211_RTS_MAX IEEE80211_MAX_LEN
325
326 enum {
327 IEEE80211_AUTH_NONE = 0,
328 IEEE80211_AUTH_OPEN = 1,
329 IEEE80211_AUTH_SHARED = 2,
330 };
331
332 #endif /* _NET80211_IEEE80211_H_ */
333