fix headers_install
[linux-2.6] / include / linux / ieee80211.h
1 /*
2  * IEEE 802.11 defines
3  *
4  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
5  * <jkmaline@cc.hut.fi>
6  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
7  * Copyright (c) 2005, Devicescape Software, Inc.
8  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #ifndef IEEE80211_H
16 #define IEEE80211_H
17
18 #include <linux/types.h>
19 #include <asm/byteorder.h>
20
21 #define FCS_LEN 4
22
23 #define IEEE80211_FCTL_VERS             0x0003
24 #define IEEE80211_FCTL_FTYPE            0x000c
25 #define IEEE80211_FCTL_STYPE            0x00f0
26 #define IEEE80211_FCTL_TODS             0x0100
27 #define IEEE80211_FCTL_FROMDS           0x0200
28 #define IEEE80211_FCTL_MOREFRAGS        0x0400
29 #define IEEE80211_FCTL_RETRY            0x0800
30 #define IEEE80211_FCTL_PM               0x1000
31 #define IEEE80211_FCTL_MOREDATA         0x2000
32 #define IEEE80211_FCTL_PROTECTED        0x4000
33 #define IEEE80211_FCTL_ORDER            0x8000
34
35 #define IEEE80211_SCTL_FRAG             0x000F
36 #define IEEE80211_SCTL_SEQ              0xFFF0
37
38 #define IEEE80211_FTYPE_MGMT            0x0000
39 #define IEEE80211_FTYPE_CTL             0x0004
40 #define IEEE80211_FTYPE_DATA            0x0008
41
42 /* management */
43 #define IEEE80211_STYPE_ASSOC_REQ       0x0000
44 #define IEEE80211_STYPE_ASSOC_RESP      0x0010
45 #define IEEE80211_STYPE_REASSOC_REQ     0x0020
46 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
47 #define IEEE80211_STYPE_PROBE_REQ       0x0040
48 #define IEEE80211_STYPE_PROBE_RESP      0x0050
49 #define IEEE80211_STYPE_BEACON          0x0080
50 #define IEEE80211_STYPE_ATIM            0x0090
51 #define IEEE80211_STYPE_DISASSOC        0x00A0
52 #define IEEE80211_STYPE_AUTH            0x00B0
53 #define IEEE80211_STYPE_DEAUTH          0x00C0
54 #define IEEE80211_STYPE_ACTION          0x00D0
55
56 /* control */
57 #define IEEE80211_STYPE_PSPOLL          0x00A0
58 #define IEEE80211_STYPE_RTS             0x00B0
59 #define IEEE80211_STYPE_CTS             0x00C0
60 #define IEEE80211_STYPE_ACK             0x00D0
61 #define IEEE80211_STYPE_CFEND           0x00E0
62 #define IEEE80211_STYPE_CFENDACK        0x00F0
63
64 /* data */
65 #define IEEE80211_STYPE_DATA                    0x0000
66 #define IEEE80211_STYPE_DATA_CFACK              0x0010
67 #define IEEE80211_STYPE_DATA_CFPOLL             0x0020
68 #define IEEE80211_STYPE_DATA_CFACKPOLL          0x0030
69 #define IEEE80211_STYPE_NULLFUNC                0x0040
70 #define IEEE80211_STYPE_CFACK                   0x0050
71 #define IEEE80211_STYPE_CFPOLL                  0x0060
72 #define IEEE80211_STYPE_CFACKPOLL               0x0070
73 #define IEEE80211_STYPE_QOS_DATA                0x0080
74 #define IEEE80211_STYPE_QOS_DATA_CFACK          0x0090
75 #define IEEE80211_STYPE_QOS_DATA_CFPOLL         0x00A0
76 #define IEEE80211_STYPE_QOS_DATA_CFACKPOLL      0x00B0
77 #define IEEE80211_STYPE_QOS_NULLFUNC            0x00C0
78 #define IEEE80211_STYPE_QOS_CFACK               0x00D0
79 #define IEEE80211_STYPE_QOS_CFPOLL              0x00E0
80 #define IEEE80211_STYPE_QOS_CFACKPOLL           0x00F0
81
82
83 /* miscellaneous IEEE 802.11 constants */
84 #define IEEE80211_MAX_FRAG_THRESHOLD    2346
85 #define IEEE80211_MAX_RTS_THRESHOLD     2347
86 #define IEEE80211_MAX_AID               2007
87 #define IEEE80211_MAX_TIM_LEN           251
88 #define IEEE80211_MAX_DATA_LEN          2304
89 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
90    6.2.1.1.2.
91
92    The figure in section 7.1.2 suggests a body size of up to 2312
93    bytes is allowed, which is a bit confusing, I suspect this
94    represents the 2304 bytes of real data, plus a possible 8 bytes of
95    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
96
97 #define IEEE80211_MAX_SSID_LEN          32
98
99 struct ieee80211_hdr {
100         __le16 frame_control;
101         __le16 duration_id;
102         u8 addr1[6];
103         u8 addr2[6];
104         u8 addr3[6];
105         __le16 seq_ctrl;
106         u8 addr4[6];
107 } __attribute__ ((packed));
108
109
110 struct ieee80211_mgmt {
111         __le16 frame_control;
112         __le16 duration;
113         u8 da[6];
114         u8 sa[6];
115         u8 bssid[6];
116         __le16 seq_ctrl;
117         union {
118                 struct {
119                         __le16 auth_alg;
120                         __le16 auth_transaction;
121                         __le16 status_code;
122                         /* possibly followed by Challenge text */
123                         u8 variable[0];
124                 } __attribute__ ((packed)) auth;
125                 struct {
126                         __le16 reason_code;
127                 } __attribute__ ((packed)) deauth;
128                 struct {
129                         __le16 capab_info;
130                         __le16 listen_interval;
131                         /* followed by SSID and Supported rates */
132                         u8 variable[0];
133                 } __attribute__ ((packed)) assoc_req;
134                 struct {
135                         __le16 capab_info;
136                         __le16 status_code;
137                         __le16 aid;
138                         /* followed by Supported rates */
139                         u8 variable[0];
140                 } __attribute__ ((packed)) assoc_resp, reassoc_resp;
141                 struct {
142                         __le16 capab_info;
143                         __le16 listen_interval;
144                         u8 current_ap[6];
145                         /* followed by SSID and Supported rates */
146                         u8 variable[0];
147                 } __attribute__ ((packed)) reassoc_req;
148                 struct {
149                         __le16 reason_code;
150                 } __attribute__ ((packed)) disassoc;
151                 struct {
152                         __le64 timestamp;
153                         __le16 beacon_int;
154                         __le16 capab_info;
155                         /* followed by some of SSID, Supported rates,
156                          * FH Params, DS Params, CF Params, IBSS Params, TIM */
157                         u8 variable[0];
158                 } __attribute__ ((packed)) beacon;
159                 struct {
160                         /* only variable items: SSID, Supported rates */
161                         u8 variable[0];
162                 } __attribute__ ((packed)) probe_req;
163                 struct {
164                         __le64 timestamp;
165                         __le16 beacon_int;
166                         __le16 capab_info;
167                         /* followed by some of SSID, Supported rates,
168                          * FH Params, DS Params, CF Params, IBSS Params */
169                         u8 variable[0];
170                 } __attribute__ ((packed)) probe_resp;
171                 struct {
172                         u8 category;
173                         union {
174                                 struct {
175                                         u8 action_code;
176                                         u8 dialog_token;
177                                         u8 status_code;
178                                         u8 variable[0];
179                                 } __attribute__ ((packed)) wme_action;
180                                 struct{
181                                         u8 action_code;
182                                         u8 element_id;
183                                         u8 length;
184                                         u8 switch_mode;
185                                         u8 new_chan;
186                                         u8 switch_count;
187                                 } __attribute__((packed)) chan_switch;
188                         } u;
189                 } __attribute__ ((packed)) action;
190         } u;
191 } __attribute__ ((packed));
192
193
194 /* Control frames */
195 struct ieee80211_rts {
196         __le16 frame_control;
197         __le16 duration;
198         u8 ra[6];
199         u8 ta[6];
200 } __attribute__ ((packed));
201
202 struct ieee80211_cts {
203         __le16 frame_control;
204         __le16 duration;
205         u8 ra[6];
206 } __attribute__ ((packed));
207
208
209 /* Authentication algorithms */
210 #define WLAN_AUTH_OPEN 0
211 #define WLAN_AUTH_SHARED_KEY 1
212 #define WLAN_AUTH_FAST_BSS_TRANSITION 2
213 #define WLAN_AUTH_LEAP 128
214
215 #define WLAN_AUTH_CHALLENGE_LEN 128
216
217 #define WLAN_CAPABILITY_ESS             (1<<0)
218 #define WLAN_CAPABILITY_IBSS            (1<<1)
219 #define WLAN_CAPABILITY_CF_POLLABLE     (1<<2)
220 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
221 #define WLAN_CAPABILITY_PRIVACY         (1<<4)
222 #define WLAN_CAPABILITY_SHORT_PREAMBLE  (1<<5)
223 #define WLAN_CAPABILITY_PBCC            (1<<6)
224 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
225 /* 802.11h */
226 #define WLAN_CAPABILITY_SPECTRUM_MGMT   (1<<8)
227 #define WLAN_CAPABILITY_QOS             (1<<9)
228 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
229 #define WLAN_CAPABILITY_DSSS_OFDM       (1<<13)
230
231 /* 802.11g ERP information element */
232 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
233 #define WLAN_ERP_USE_PROTECTION (1<<1)
234 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
235
236 /* WLAN_ERP_BARKER_PREAMBLE values */
237 enum {
238         WLAN_ERP_PREAMBLE_SHORT = 0,
239         WLAN_ERP_PREAMBLE_LONG = 1,
240 };
241
242 /* Status codes */
243 enum ieee80211_statuscode {
244         WLAN_STATUS_SUCCESS = 0,
245         WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
246         WLAN_STATUS_CAPS_UNSUPPORTED = 10,
247         WLAN_STATUS_REASSOC_NO_ASSOC = 11,
248         WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
249         WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
250         WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
251         WLAN_STATUS_CHALLENGE_FAIL = 15,
252         WLAN_STATUS_AUTH_TIMEOUT = 16,
253         WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
254         WLAN_STATUS_ASSOC_DENIED_RATES = 18,
255         /* 802.11b */
256         WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
257         WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
258         WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
259         /* 802.11h */
260         WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
261         WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
262         WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
263         /* 802.11g */
264         WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
265         WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
266         /* 802.11i */
267         WLAN_STATUS_INVALID_IE = 40,
268         WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
269         WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
270         WLAN_STATUS_INVALID_AKMP = 43,
271         WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
272         WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
273         WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
274 };
275
276
277 /* Reason codes */
278 enum ieee80211_reasoncode {
279         WLAN_REASON_UNSPECIFIED = 1,
280         WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
281         WLAN_REASON_DEAUTH_LEAVING = 3,
282         WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
283         WLAN_REASON_DISASSOC_AP_BUSY = 5,
284         WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
285         WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
286         WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
287         WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
288         /* 802.11h */
289         WLAN_REASON_DISASSOC_BAD_POWER = 10,
290         WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
291         /* 802.11i */
292         WLAN_REASON_INVALID_IE = 13,
293         WLAN_REASON_MIC_FAILURE = 14,
294         WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
295         WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
296         WLAN_REASON_IE_DIFFERENT = 17,
297         WLAN_REASON_INVALID_GROUP_CIPHER = 18,
298         WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
299         WLAN_REASON_INVALID_AKMP = 20,
300         WLAN_REASON_UNSUPP_RSN_VERSION = 21,
301         WLAN_REASON_INVALID_RSN_IE_CAP = 22,
302         WLAN_REASON_IEEE8021X_FAILED = 23,
303         WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
304 };
305
306
307 /* Information Element IDs */
308 enum ieee80211_eid {
309         WLAN_EID_SSID = 0,
310         WLAN_EID_SUPP_RATES = 1,
311         WLAN_EID_FH_PARAMS = 2,
312         WLAN_EID_DS_PARAMS = 3,
313         WLAN_EID_CF_PARAMS = 4,
314         WLAN_EID_TIM = 5,
315         WLAN_EID_IBSS_PARAMS = 6,
316         WLAN_EID_CHALLENGE = 16,
317         /* 802.11d */
318         WLAN_EID_COUNTRY = 7,
319         WLAN_EID_HP_PARAMS = 8,
320         WLAN_EID_HP_TABLE = 9,
321         WLAN_EID_REQUEST = 10,
322         /* 802.11h */
323         WLAN_EID_PWR_CONSTRAINT = 32,
324         WLAN_EID_PWR_CAPABILITY = 33,
325         WLAN_EID_TPC_REQUEST = 34,
326         WLAN_EID_TPC_REPORT = 35,
327         WLAN_EID_SUPPORTED_CHANNELS = 36,
328         WLAN_EID_CHANNEL_SWITCH = 37,
329         WLAN_EID_MEASURE_REQUEST = 38,
330         WLAN_EID_MEASURE_REPORT = 39,
331         WLAN_EID_QUIET = 40,
332         WLAN_EID_IBSS_DFS = 41,
333         /* 802.11g */
334         WLAN_EID_ERP_INFO = 42,
335         WLAN_EID_EXT_SUPP_RATES = 50,
336         /* 802.11i */
337         WLAN_EID_RSN = 48,
338         WLAN_EID_WPA = 221,
339         WLAN_EID_GENERIC = 221,
340         WLAN_EID_VENDOR_SPECIFIC = 221,
341         WLAN_EID_QOS_PARAMETER = 222
342 };
343
344 /* cipher suite selectors */
345 #define WLAN_CIPHER_SUITE_USE_GROUP     0x000FAC00
346 #define WLAN_CIPHER_SUITE_WEP40         0x000FAC01
347 #define WLAN_CIPHER_SUITE_TKIP          0x000FAC02
348 /* reserved:                            0x000FAC03 */
349 #define WLAN_CIPHER_SUITE_CCMP          0x000FAC04
350 #define WLAN_CIPHER_SUITE_WEP104        0x000FAC05
351
352 #define WLAN_MAX_KEY_LEN                32
353
354 /**
355  * ieee80211_get_SA - get pointer to SA
356  *
357  * Given an 802.11 frame, this function returns the offset
358  * to the source address (SA). It does not verify that the
359  * header is long enough to contain the address, and the
360  * header must be long enough to contain the frame control
361  * field.
362  *
363  * @hdr: the frame
364  */
365 static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
366 {
367         u8 *raw = (u8 *) hdr;
368         u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
369
370         switch (tofrom) {
371                 case 2:
372                         return hdr->addr3;
373                 case 3:
374                         return hdr->addr4;
375         }
376         return hdr->addr2;
377 }
378
379 /**
380  * ieee80211_get_DA - get pointer to DA
381  *
382  * Given an 802.11 frame, this function returns the offset
383  * to the destination address (DA). It does not verify that
384  * the header is long enough to contain the address, and the
385  * header must be long enough to contain the frame control
386  * field.
387  *
388  * @hdr: the frame
389  */
390 static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
391 {
392         u8 *raw = (u8 *) hdr;
393         u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
394
395         if (to_ds)
396                 return hdr->addr3;
397         return hdr->addr1;
398 }
399
400 /**
401  * ieee80211_get_morefrag - determine whether the MOREFRAGS bit is set
402  *
403  * This function determines whether the "more fragments" bit is set
404  * in the frame.
405  *
406  * @hdr: the frame
407  */
408 static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
409 {
410         return (le16_to_cpu(hdr->frame_control) &
411                 IEEE80211_FCTL_MOREFRAGS) != 0;
412 }
413
414 #endif /* IEEE80211_H */