Merge branch 'upstream-fixes'
[sfrench/cifs-2.6.git] / include / net / ieee80211.h
1 /*
2  * Merged with mainline ieee80211.h in Aug 2004.  Original ieee802_11
3  * remains copyright by the original authors
4  *
5  * Portions of the merged code are based on Host AP (software wireless
6  * LAN access point) driver for Intersil Prism2/2.5/3.
7  *
8  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
9  * <jkmaline@cc.hut.fi>
10  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
11  *
12  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13  * <jketreno@linux.intel.com>
14  * Copyright (c) 2004-2005, Intel Corporation
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License version 2 as
18  * published by the Free Software Foundation. See README and COPYING for
19  * more details.
20  *
21  * API Version History
22  * 1.0.x -- Initial version
23  * 1.1.x -- Added radiotap, QoS, TIM, ieee80211_geo APIs,
24  *          various structure changes, and crypto API init method
25  */
26 #ifndef IEEE80211_H
27 #define IEEE80211_H
28 #include <linux/if_ether.h>     /* ETH_ALEN */
29 #include <linux/kernel.h>       /* ARRAY_SIZE */
30 #include <linux/wireless.h>
31
32 #define IEEE80211_VERSION "git-1.1.7"
33
34 #define IEEE80211_DATA_LEN              2304
35 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
36    6.2.1.1.2.
37
38    The figure in section 7.1.2 suggests a body size of up to 2312
39    bytes is allowed, which is a bit confusing, I suspect this
40    represents the 2304 bytes of real data, plus a possible 8 bytes of
41    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
42
43 #define IEEE80211_1ADDR_LEN 10
44 #define IEEE80211_2ADDR_LEN 16
45 #define IEEE80211_3ADDR_LEN 24
46 #define IEEE80211_4ADDR_LEN 30
47 #define IEEE80211_FCS_LEN    4
48 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
49 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
50
51 #define MIN_FRAG_THRESHOLD     256U
52 #define MAX_FRAG_THRESHOLD     2346U
53
54 /* Frame control field constants */
55 #define IEEE80211_FCTL_VERS             0x0003
56 #define IEEE80211_FCTL_FTYPE            0x000c
57 #define IEEE80211_FCTL_STYPE            0x00f0
58 #define IEEE80211_FCTL_TODS             0x0100
59 #define IEEE80211_FCTL_FROMDS           0x0200
60 #define IEEE80211_FCTL_MOREFRAGS        0x0400
61 #define IEEE80211_FCTL_RETRY            0x0800
62 #define IEEE80211_FCTL_PM               0x1000
63 #define IEEE80211_FCTL_MOREDATA         0x2000
64 #define IEEE80211_FCTL_PROTECTED        0x4000
65 #define IEEE80211_FCTL_ORDER            0x8000
66
67 #define IEEE80211_FTYPE_MGMT            0x0000
68 #define IEEE80211_FTYPE_CTL             0x0004
69 #define IEEE80211_FTYPE_DATA            0x0008
70
71 /* management */
72 #define IEEE80211_STYPE_ASSOC_REQ       0x0000
73 #define IEEE80211_STYPE_ASSOC_RESP      0x0010
74 #define IEEE80211_STYPE_REASSOC_REQ     0x0020
75 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
76 #define IEEE80211_STYPE_PROBE_REQ       0x0040
77 #define IEEE80211_STYPE_PROBE_RESP      0x0050
78 #define IEEE80211_STYPE_BEACON          0x0080
79 #define IEEE80211_STYPE_ATIM            0x0090
80 #define IEEE80211_STYPE_DISASSOC        0x00A0
81 #define IEEE80211_STYPE_AUTH            0x00B0
82 #define IEEE80211_STYPE_DEAUTH          0x00C0
83 #define IEEE80211_STYPE_ACTION          0x00D0
84
85 /* control */
86 #define IEEE80211_STYPE_PSPOLL          0x00A0
87 #define IEEE80211_STYPE_RTS             0x00B0
88 #define IEEE80211_STYPE_CTS             0x00C0
89 #define IEEE80211_STYPE_ACK             0x00D0
90 #define IEEE80211_STYPE_CFEND           0x00E0
91 #define IEEE80211_STYPE_CFENDACK        0x00F0
92
93 /* data */
94 #define IEEE80211_STYPE_DATA            0x0000
95 #define IEEE80211_STYPE_DATA_CFACK      0x0010
96 #define IEEE80211_STYPE_DATA_CFPOLL     0x0020
97 #define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
98 #define IEEE80211_STYPE_NULLFUNC        0x0040
99 #define IEEE80211_STYPE_CFACK           0x0050
100 #define IEEE80211_STYPE_CFPOLL          0x0060
101 #define IEEE80211_STYPE_CFACKPOLL       0x0070
102 #define IEEE80211_STYPE_QOS_DATA        0x0080
103
104 #define IEEE80211_SCTL_FRAG             0x000F
105 #define IEEE80211_SCTL_SEQ              0xFFF0
106
107 /* debug macros */
108
109 #ifdef CONFIG_IEEE80211_DEBUG
110 extern u32 ieee80211_debug_level;
111 #define IEEE80211_DEBUG(level, fmt, args...) \
112 do { if (ieee80211_debug_level & (level)) \
113   printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
114          in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0)
115 #else
116 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
117 #endif                          /* CONFIG_IEEE80211_DEBUG */
118
119 /* debug macros not dependent on CONFIG_IEEE80211_DEBUG */
120
121 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
122 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
123
124 /* escape_essid() is intended to be used in debug (and possibly error)
125  * messages. It should never be used for passing essid to user space. */
126 const char *escape_essid(const char *essid, u8 essid_len);
127
128 /*
129  * To use the debug system:
130  *
131  * If you are defining a new debug classification, simply add it to the #define
132  * list here in the form of:
133  *
134  * #define IEEE80211_DL_xxxx VALUE
135  *
136  * shifting value to the left one bit from the previous entry.  xxxx should be
137  * the name of the classification (for example, WEP)
138  *
139  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
140  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
141  * to send output to that classification.
142  *
143  * To add your debug level to the list of levels seen when you perform
144  *
145  * % cat /proc/net/ieee80211/debug_level
146  *
147  * you simply need to add your entry to the ieee80211_debug_level array.
148  *
149  * If you do not see debug_level in /proc/net/ieee80211 then you do not have
150  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
151  *
152  */
153
154 #define IEEE80211_DL_INFO          (1<<0)
155 #define IEEE80211_DL_WX            (1<<1)
156 #define IEEE80211_DL_SCAN          (1<<2)
157 #define IEEE80211_DL_STATE         (1<<3)
158 #define IEEE80211_DL_MGMT          (1<<4)
159 #define IEEE80211_DL_FRAG          (1<<5)
160 #define IEEE80211_DL_DROP          (1<<7)
161
162 #define IEEE80211_DL_TX            (1<<8)
163 #define IEEE80211_DL_RX            (1<<9)
164 #define IEEE80211_DL_QOS           (1<<31)
165
166 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
167 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
168 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
169
170 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
171 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
172 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
173 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
174 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
175 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
176 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
177 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
178 #define IEEE80211_DEBUG_QOS(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_QOS, f, ## a)
179 #include <linux/netdevice.h>
180 #include <linux/wireless.h>
181 #include <linux/if_arp.h>       /* ARPHRD_ETHER */
182
183 #ifndef WIRELESS_SPY
184 #define WIRELESS_SPY            /* enable iwspy support */
185 #endif
186 #include <net/iw_handler.h>     /* new driver API */
187
188 #ifndef ETH_P_PAE
189 #define ETH_P_PAE 0x888E        /* Port Access Entity (IEEE 802.1X) */
190 #endif                          /* ETH_P_PAE */
191
192 #define ETH_P_PREAUTH 0x88C7    /* IEEE 802.11i pre-authentication */
193
194 #ifndef ETH_P_80211_RAW
195 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
196 #endif
197
198 /* IEEE 802.11 defines */
199
200 #define P80211_OUI_LEN 3
201
202 struct ieee80211_snap_hdr {
203
204         u8 dsap;                /* always 0xAA */
205         u8 ssap;                /* always 0xAA */
206         u8 ctrl;                /* always 0x03 */
207         u8 oui[P80211_OUI_LEN]; /* organizational universal id */
208
209 } __attribute__ ((packed));
210
211 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
212
213 #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
214 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
215 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
216
217 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
218 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & IEEE80211_SCTL_SEQ)
219
220 /* Authentication algorithms */
221 #define WLAN_AUTH_OPEN 0
222 #define WLAN_AUTH_SHARED_KEY 1
223 #define WLAN_AUTH_LEAP 2
224
225 #define WLAN_AUTH_CHALLENGE_LEN 128
226
227 #define WLAN_CAPABILITY_ESS (1<<0)
228 #define WLAN_CAPABILITY_IBSS (1<<1)
229 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
230 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
231 #define WLAN_CAPABILITY_PRIVACY (1<<4)
232 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
233 #define WLAN_CAPABILITY_PBCC (1<<6)
234 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
235 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
236 #define WLAN_CAPABILITY_QOS (1<<9)
237 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
238 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
239
240 /* Status codes */
241 enum ieee80211_statuscode {
242         WLAN_STATUS_SUCCESS = 0,
243         WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
244         WLAN_STATUS_CAPS_UNSUPPORTED = 10,
245         WLAN_STATUS_REASSOC_NO_ASSOC = 11,
246         WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
247         WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
248         WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
249         WLAN_STATUS_CHALLENGE_FAIL = 15,
250         WLAN_STATUS_AUTH_TIMEOUT = 16,
251         WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
252         WLAN_STATUS_ASSOC_DENIED_RATES = 18,
253         /* 802.11b */
254         WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
255         WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
256         WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
257         /* 802.11h */
258         WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
259         WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
260         WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
261         /* 802.11g */
262         WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
263         WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
264         /* 802.11i */
265         WLAN_STATUS_INVALID_IE = 40,
266         WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
267         WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
268         WLAN_STATUS_INVALID_AKMP = 43,
269         WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
270         WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
271         WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
272 };
273
274 /* Reason codes */
275 enum ieee80211_reasoncode {
276         WLAN_REASON_UNSPECIFIED = 1,
277         WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
278         WLAN_REASON_DEAUTH_LEAVING = 3,
279         WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
280         WLAN_REASON_DISASSOC_AP_BUSY = 5,
281         WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
282         WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
283         WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
284         WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
285         /* 802.11h */
286         WLAN_REASON_DISASSOC_BAD_POWER = 10,
287         WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
288         /* 802.11i */
289         WLAN_REASON_INVALID_IE = 13,
290         WLAN_REASON_MIC_FAILURE = 14,
291         WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
292         WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
293         WLAN_REASON_IE_DIFFERENT = 17,
294         WLAN_REASON_INVALID_GROUP_CIPHER = 18,
295         WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
296         WLAN_REASON_INVALID_AKMP = 20,
297         WLAN_REASON_UNSUPP_RSN_VERSION = 21,
298         WLAN_REASON_INVALID_RSN_IE_CAP = 22,
299         WLAN_REASON_IEEE8021X_FAILED = 23,
300         WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
301 };
302
303 /* Action categories - 802.11h */
304 enum ieee80211_actioncategories {
305         WLAN_ACTION_SPECTRUM_MGMT = 0,
306         /* Reserved 1-127  */
307         /* Error    128-255 */
308 };
309
310 /* Action details - 802.11h */
311 enum ieee80211_actiondetails {
312         WLAN_ACTION_CATEGORY_MEASURE_REQUEST = 0,
313         WLAN_ACTION_CATEGORY_MEASURE_REPORT = 1,
314         WLAN_ACTION_CATEGORY_TPC_REQUEST = 2,
315         WLAN_ACTION_CATEGORY_TPC_REPORT = 3,
316         WLAN_ACTION_CATEGORY_CHANNEL_SWITCH = 4,
317         /* 5 - 255 Reserved */
318 };
319
320 #define IEEE80211_STATMASK_SIGNAL (1<<0)
321 #define IEEE80211_STATMASK_RSSI (1<<1)
322 #define IEEE80211_STATMASK_NOISE (1<<2)
323 #define IEEE80211_STATMASK_RATE (1<<3)
324 #define IEEE80211_STATMASK_WEMASK 0x7
325
326 #define IEEE80211_CCK_MODULATION    (1<<0)
327 #define IEEE80211_OFDM_MODULATION   (1<<1)
328
329 #define IEEE80211_24GHZ_BAND     (1<<0)
330 #define IEEE80211_52GHZ_BAND     (1<<1)
331
332 #define IEEE80211_CCK_RATE_1MB                  0x02
333 #define IEEE80211_CCK_RATE_2MB                  0x04
334 #define IEEE80211_CCK_RATE_5MB                  0x0B
335 #define IEEE80211_CCK_RATE_11MB                 0x16
336 #define IEEE80211_OFDM_RATE_6MB                 0x0C
337 #define IEEE80211_OFDM_RATE_9MB                 0x12
338 #define IEEE80211_OFDM_RATE_12MB                0x18
339 #define IEEE80211_OFDM_RATE_18MB                0x24
340 #define IEEE80211_OFDM_RATE_24MB                0x30
341 #define IEEE80211_OFDM_RATE_36MB                0x48
342 #define IEEE80211_OFDM_RATE_48MB                0x60
343 #define IEEE80211_OFDM_RATE_54MB                0x6C
344 #define IEEE80211_BASIC_RATE_MASK               0x80
345
346 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
347 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
348 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
349 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
350 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
351 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
352 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
353 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
354 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
355 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
356 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
357 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
358
359 #define IEEE80211_CCK_RATES_MASK                0x0000000F
360 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
361         IEEE80211_CCK_RATE_2MB_MASK)
362 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
363         IEEE80211_CCK_RATE_5MB_MASK | \
364         IEEE80211_CCK_RATE_11MB_MASK)
365
366 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
367 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
368         IEEE80211_OFDM_RATE_12MB_MASK | \
369         IEEE80211_OFDM_RATE_24MB_MASK)
370 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
371         IEEE80211_OFDM_RATE_9MB_MASK  | \
372         IEEE80211_OFDM_RATE_18MB_MASK | \
373         IEEE80211_OFDM_RATE_36MB_MASK | \
374         IEEE80211_OFDM_RATE_48MB_MASK | \
375         IEEE80211_OFDM_RATE_54MB_MASK)
376 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
377                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
378
379 #define IEEE80211_NUM_OFDM_RATES            8
380 #define IEEE80211_NUM_CCK_RATES             4
381 #define IEEE80211_OFDM_SHIFT_MASK_A         4
382
383 /* NOTE: This data is for statistical purposes; not all hardware provides this
384  *       information for frames received.
385  *       For ieee80211_rx_mgt, you need to set at least the 'len' parameter.
386  */
387 struct ieee80211_rx_stats {
388         u32 mac_time;
389         s8 rssi;
390         u8 signal;
391         u8 noise;
392         u16 rate;               /* in 100 kbps */
393         u8 received_channel;
394         u8 control;
395         u8 mask;
396         u8 freq;
397         u16 len;
398         u64 tsf;
399         u32 beacon_time;
400 };
401
402 /* IEEE 802.11 requires that STA supports concurrent reception of at least
403  * three fragmented frames. This define can be increased to support more
404  * concurrent frames, but it should be noted that each entry can consume about
405  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
406 #define IEEE80211_FRAG_CACHE_LEN 4
407
408 struct ieee80211_frag_entry {
409         unsigned long first_frag_time;
410         unsigned int seq;
411         unsigned int last_frag;
412         struct sk_buff *skb;
413         u8 src_addr[ETH_ALEN];
414         u8 dst_addr[ETH_ALEN];
415 };
416
417 struct ieee80211_stats {
418         unsigned int tx_unicast_frames;
419         unsigned int tx_multicast_frames;
420         unsigned int tx_fragments;
421         unsigned int tx_unicast_octets;
422         unsigned int tx_multicast_octets;
423         unsigned int tx_deferred_transmissions;
424         unsigned int tx_single_retry_frames;
425         unsigned int tx_multiple_retry_frames;
426         unsigned int tx_retry_limit_exceeded;
427         unsigned int tx_discards;
428         unsigned int rx_unicast_frames;
429         unsigned int rx_multicast_frames;
430         unsigned int rx_fragments;
431         unsigned int rx_unicast_octets;
432         unsigned int rx_multicast_octets;
433         unsigned int rx_fcs_errors;
434         unsigned int rx_discards_no_buffer;
435         unsigned int tx_discards_wrong_sa;
436         unsigned int rx_discards_undecryptable;
437         unsigned int rx_message_in_msg_fragments;
438         unsigned int rx_message_in_bad_msg_fragments;
439 };
440
441 struct ieee80211_device;
442
443 #include "ieee80211_crypt.h"
444
445 #define SEC_KEY_1               (1<<0)
446 #define SEC_KEY_2               (1<<1)
447 #define SEC_KEY_3               (1<<2)
448 #define SEC_KEY_4               (1<<3)
449 #define SEC_ACTIVE_KEY          (1<<4)
450 #define SEC_AUTH_MODE           (1<<5)
451 #define SEC_UNICAST_GROUP       (1<<6)
452 #define SEC_LEVEL               (1<<7)
453 #define SEC_ENABLED             (1<<8)
454 #define SEC_ENCRYPT             (1<<9)
455
456 #define SEC_LEVEL_0             0       /* None */
457 #define SEC_LEVEL_1             1       /* WEP 40 and 104 bit */
458 #define SEC_LEVEL_2             2       /* Level 1 + TKIP */
459 #define SEC_LEVEL_2_CKIP        3       /* Level 1 + CKIP */
460 #define SEC_LEVEL_3             4       /* Level 2 + CCMP */
461
462 #define SEC_ALG_NONE            0
463 #define SEC_ALG_WEP             1
464 #define SEC_ALG_TKIP            2
465 #define SEC_ALG_CCMP            3
466
467 #define WEP_KEYS                4
468 #define WEP_KEY_LEN             13
469 #define SCM_KEY_LEN             32
470 #define SCM_TEMPORAL_KEY_LENGTH 16
471
472 struct ieee80211_security {
473         u16 active_key:2,
474             enabled:1,
475             auth_mode:2, auth_algo:4, unicast_uses_group:1, encrypt:1;
476         u8 encode_alg[WEP_KEYS];
477         u8 key_sizes[WEP_KEYS];
478         u8 keys[WEP_KEYS][SCM_KEY_LEN];
479         u8 level;
480         u16 flags;
481 } __attribute__ ((packed));
482
483 /*
484
485  802.11 data frame from AP
486
487       ,-------------------------------------------------------------------.
488 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
489       |------|------|---------|---------|---------|------|---------|------|
490 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
491       |      | tion | (BSSID) |         |         | ence |  data   |      |
492       `-------------------------------------------------------------------'
493
494 Total: 28-2340 bytes
495
496 */
497
498 #define BEACON_PROBE_SSID_ID_POSITION 12
499
500 /* Management Frame Information Element Types */
501 enum ieee80211_mfie {
502         MFIE_TYPE_SSID = 0,
503         MFIE_TYPE_RATES = 1,
504         MFIE_TYPE_FH_SET = 2,
505         MFIE_TYPE_DS_SET = 3,
506         MFIE_TYPE_CF_SET = 4,
507         MFIE_TYPE_TIM = 5,
508         MFIE_TYPE_IBSS_SET = 6,
509         MFIE_TYPE_COUNTRY = 7,
510         MFIE_TYPE_HOP_PARAMS = 8,
511         MFIE_TYPE_HOP_TABLE = 9,
512         MFIE_TYPE_REQUEST = 10,
513         MFIE_TYPE_CHALLENGE = 16,
514         MFIE_TYPE_POWER_CONSTRAINT = 32,
515         MFIE_TYPE_POWER_CAPABILITY = 33,
516         MFIE_TYPE_TPC_REQUEST = 34,
517         MFIE_TYPE_TPC_REPORT = 35,
518         MFIE_TYPE_SUPP_CHANNELS = 36,
519         MFIE_TYPE_CSA = 37,
520         MFIE_TYPE_MEASURE_REQUEST = 38,
521         MFIE_TYPE_MEASURE_REPORT = 39,
522         MFIE_TYPE_QUIET = 40,
523         MFIE_TYPE_IBSS_DFS = 41,
524         MFIE_TYPE_ERP_INFO = 42,
525         MFIE_TYPE_RSN = 48,
526         MFIE_TYPE_RATES_EX = 50,
527         MFIE_TYPE_GENERIC = 221,
528         MFIE_TYPE_QOS_PARAMETER = 222,
529 };
530
531 /* Minimal header; can be used for passing 802.11 frames with sufficient
532  * information to determine what type of underlying data type is actually
533  * stored in the data. */
534 struct ieee80211_hdr {
535         __le16 frame_ctl;
536         __le16 duration_id;
537         u8 payload[0];
538 } __attribute__ ((packed));
539
540 struct ieee80211_hdr_1addr {
541         __le16 frame_ctl;
542         __le16 duration_id;
543         u8 addr1[ETH_ALEN];
544         u8 payload[0];
545 } __attribute__ ((packed));
546
547 struct ieee80211_hdr_2addr {
548         __le16 frame_ctl;
549         __le16 duration_id;
550         u8 addr1[ETH_ALEN];
551         u8 addr2[ETH_ALEN];
552         u8 payload[0];
553 } __attribute__ ((packed));
554
555 struct ieee80211_hdr_3addr {
556         __le16 frame_ctl;
557         __le16 duration_id;
558         u8 addr1[ETH_ALEN];
559         u8 addr2[ETH_ALEN];
560         u8 addr3[ETH_ALEN];
561         __le16 seq_ctl;
562         u8 payload[0];
563 } __attribute__ ((packed));
564
565 struct ieee80211_hdr_4addr {
566         __le16 frame_ctl;
567         __le16 duration_id;
568         u8 addr1[ETH_ALEN];
569         u8 addr2[ETH_ALEN];
570         u8 addr3[ETH_ALEN];
571         __le16 seq_ctl;
572         u8 addr4[ETH_ALEN];
573         u8 payload[0];
574 } __attribute__ ((packed));
575
576 struct ieee80211_hdr_3addrqos {
577         __le16 frame_ctl;
578         __le16 duration_id;
579         u8 addr1[ETH_ALEN];
580         u8 addr2[ETH_ALEN];
581         u8 addr3[ETH_ALEN];
582         __le16 seq_ctl;
583         u8 payload[0];
584         __le16 qos_ctl;
585 } __attribute__ ((packed));
586
587 struct ieee80211_hdr_4addrqos {
588         __le16 frame_ctl;
589         __le16 duration_id;
590         u8 addr1[ETH_ALEN];
591         u8 addr2[ETH_ALEN];
592         u8 addr3[ETH_ALEN];
593         __le16 seq_ctl;
594         u8 addr4[ETH_ALEN];
595         u8 payload[0];
596         __le16 qos_ctl;
597 } __attribute__ ((packed));
598
599 struct ieee80211_info_element {
600         u8 id;
601         u8 len;
602         u8 data[0];
603 } __attribute__ ((packed));
604
605 /*
606  * These are the data types that can make up management packets
607  *
608         u16 auth_algorithm;
609         u16 auth_sequence;
610         u16 beacon_interval;
611         u16 capability;
612         u8 current_ap[ETH_ALEN];
613         u16 listen_interval;
614         struct {
615                 u16 association_id:14, reserved:2;
616         } __attribute__ ((packed));
617         u32 time_stamp[2];
618         u16 reason;
619         u16 status;
620 */
621
622 struct ieee80211_auth {
623         struct ieee80211_hdr_3addr header;
624         __le16 algorithm;
625         __le16 transaction;
626         __le16 status;
627         /* challenge */
628         struct ieee80211_info_element info_element[0];
629 } __attribute__ ((packed));
630
631 struct ieee80211_channel_switch {
632         u8 id;
633         u8 len;
634         u8 mode;
635         u8 channel;
636         u8 count;
637 } __attribute__ ((packed));
638
639 struct ieee80211_action {
640         struct ieee80211_hdr_3addr header;
641         u8 category;
642         u8 action;
643         union {
644                 struct ieee80211_action_exchange {
645                         u8 token;
646                         struct ieee80211_info_element info_element[0];
647                 } exchange;
648                 struct ieee80211_channel_switch channel_switch;
649
650         } format;
651 } __attribute__ ((packed));
652
653 struct ieee80211_disassoc {
654         struct ieee80211_hdr_3addr header;
655         __le16 reason;
656 } __attribute__ ((packed));
657
658 /* Alias deauth for disassoc */
659 #define ieee80211_deauth ieee80211_disassoc
660
661 struct ieee80211_probe_request {
662         struct ieee80211_hdr_3addr header;
663         /* SSID, supported rates */
664         struct ieee80211_info_element info_element[0];
665 } __attribute__ ((packed));
666
667 struct ieee80211_probe_response {
668         struct ieee80211_hdr_3addr header;
669         u32 time_stamp[2];
670         __le16 beacon_interval;
671         __le16 capability;
672         /* SSID, supported rates, FH params, DS params,
673          * CF params, IBSS params, TIM (if beacon), RSN */
674         struct ieee80211_info_element info_element[0];
675 } __attribute__ ((packed));
676
677 /* Alias beacon for probe_response */
678 #define ieee80211_beacon ieee80211_probe_response
679
680 struct ieee80211_assoc_request {
681         struct ieee80211_hdr_3addr header;
682         __le16 capability;
683         __le16 listen_interval;
684         /* SSID, supported rates, RSN */
685         struct ieee80211_info_element info_element[0];
686 } __attribute__ ((packed));
687
688 struct ieee80211_reassoc_request {
689         struct ieee80211_hdr_3addr header;
690         __le16 capability;
691         __le16 listen_interval;
692         u8 current_ap[ETH_ALEN];
693         struct ieee80211_info_element info_element[0];
694 } __attribute__ ((packed));
695
696 struct ieee80211_assoc_response {
697         struct ieee80211_hdr_3addr header;
698         __le16 capability;
699         __le16 status;
700         __le16 aid;
701         /* supported rates */
702         struct ieee80211_info_element info_element[0];
703 } __attribute__ ((packed));
704
705 struct ieee80211_txb {
706         u8 nr_frags;
707         u8 encrypted;
708         u8 rts_included;
709         u8 reserved;
710         __le16 frag_size;
711         __le16 payload_size;
712         struct sk_buff *fragments[0];
713 };
714
715 /* SWEEP TABLE ENTRIES NUMBER */
716 #define MAX_SWEEP_TAB_ENTRIES             42
717 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
718 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
719  * only use 8, and then use extended rates for the remaining supported
720  * rates.  Other APs, however, stick all of their supported rates on the
721  * main rates information element... */
722 #define MAX_RATES_LENGTH                  ((u8)12)
723 #define MAX_RATES_EX_LENGTH               ((u8)16)
724 #define MAX_NETWORK_COUNT                  128
725
726 #define CRC_LENGTH                 4U
727
728 #define MAX_WPA_IE_LEN 64
729
730 #define NETWORK_EMPTY_ESSID    (1<<0)
731 #define NETWORK_HAS_OFDM       (1<<1)
732 #define NETWORK_HAS_CCK        (1<<2)
733
734 /* QoS structure */
735 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
736 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
737 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
738                                          NETWORK_HAS_QOS_INFORMATION)
739
740 /* 802.11h */
741 #define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
742 #define NETWORK_HAS_CSA                 (1<<6)
743 #define NETWORK_HAS_QUIET               (1<<7)
744 #define NETWORK_HAS_IBSS_DFS            (1<<8)
745 #define NETWORK_HAS_TPC_REPORT          (1<<9)
746
747 #define QOS_QUEUE_NUM                   4
748 #define QOS_OUI_LEN                     3
749 #define QOS_OUI_TYPE                    2
750 #define QOS_ELEMENT_ID                  221
751 #define QOS_OUI_INFO_SUB_TYPE           0
752 #define QOS_OUI_PARAM_SUB_TYPE          1
753 #define QOS_VERSION_1                   1
754 #define QOS_AIFSN_MIN_VALUE             2
755
756 struct ieee80211_qos_information_element {
757         u8 elementID;
758         u8 length;
759         u8 qui[QOS_OUI_LEN];
760         u8 qui_type;
761         u8 qui_subtype;
762         u8 version;
763         u8 ac_info;
764 } __attribute__ ((packed));
765
766 struct ieee80211_qos_ac_parameter {
767         u8 aci_aifsn;
768         u8 ecw_min_max;
769         __le16 tx_op_limit;
770 } __attribute__ ((packed));
771
772 struct ieee80211_qos_parameter_info {
773         struct ieee80211_qos_information_element info_element;
774         u8 reserved;
775         struct ieee80211_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
776 } __attribute__ ((packed));
777
778 struct ieee80211_qos_parameters {
779         __le16 cw_min[QOS_QUEUE_NUM];
780         __le16 cw_max[QOS_QUEUE_NUM];
781         u8 aifs[QOS_QUEUE_NUM];
782         u8 flag[QOS_QUEUE_NUM];
783         __le16 tx_op_limit[QOS_QUEUE_NUM];
784 } __attribute__ ((packed));
785
786 struct ieee80211_qos_data {
787         struct ieee80211_qos_parameters parameters;
788         int active;
789         int supported;
790         u8 param_count;
791         u8 old_param_count;
792 };
793
794 struct ieee80211_tim_parameters {
795         u8 tim_count;
796         u8 tim_period;
797 } __attribute__ ((packed));
798
799 /*******************************************************/
800
801 enum {                          /* ieee80211_basic_report.map */
802         IEEE80211_BASIC_MAP_BSS = (1 << 0),
803         IEEE80211_BASIC_MAP_OFDM = (1 << 1),
804         IEEE80211_BASIC_MAP_UNIDENTIFIED = (1 << 2),
805         IEEE80211_BASIC_MAP_RADAR = (1 << 3),
806         IEEE80211_BASIC_MAP_UNMEASURED = (1 << 4),
807         /* Bits 5-7 are reserved */
808
809 };
810 struct ieee80211_basic_report {
811         u8 channel;
812         __le64 start_time;
813         __le16 duration;
814         u8 map;
815 } __attribute__ ((packed));
816
817 enum {                          /* ieee80211_measurement_request.mode */
818         /* Bit 0 is reserved */
819         IEEE80211_MEASUREMENT_ENABLE = (1 << 1),
820         IEEE80211_MEASUREMENT_REQUEST = (1 << 2),
821         IEEE80211_MEASUREMENT_REPORT = (1 << 3),
822         /* Bits 4-7 are reserved */
823 };
824
825 enum {
826         IEEE80211_REPORT_BASIC = 0,     /* required */
827         IEEE80211_REPORT_CCA = 1,       /* optional */
828         IEEE80211_REPORT_RPI = 2,       /* optional */
829         /* 3-255 reserved */
830 };
831
832 struct ieee80211_measurement_params {
833         u8 channel;
834         __le64 start_time;
835         __le16 duration;
836 } __attribute__ ((packed));
837
838 struct ieee80211_measurement_request {
839         struct ieee80211_info_element ie;
840         u8 token;
841         u8 mode;
842         u8 type;
843         struct ieee80211_measurement_params params[0];
844 } __attribute__ ((packed));
845
846 struct ieee80211_measurement_report {
847         struct ieee80211_info_element ie;
848         u8 token;
849         u8 mode;
850         u8 type;
851         union {
852                 struct ieee80211_basic_report basic[0];
853         } u;
854 } __attribute__ ((packed));
855
856 struct ieee80211_tpc_report {
857         u8 transmit_power;
858         u8 link_margin;
859 } __attribute__ ((packed));
860
861 struct ieee80211_channel_map {
862         u8 channel;
863         u8 map;
864 } __attribute__ ((packed));
865
866 struct ieee80211_ibss_dfs {
867         struct ieee80211_info_element ie;
868         u8 owner[ETH_ALEN];
869         u8 recovery_interval;
870         struct ieee80211_channel_map channel_map[0];
871 };
872
873 struct ieee80211_csa {
874         u8 mode;
875         u8 channel;
876         u8 count;
877 } __attribute__ ((packed));
878
879 struct ieee80211_quiet {
880         u8 count;
881         u8 period;
882         u8 duration;
883         u8 offset;
884 } __attribute__ ((packed));
885
886 struct ieee80211_network {
887         /* These entries are used to identify a unique network */
888         u8 bssid[ETH_ALEN];
889         u8 channel;
890         /* Ensure null-terminated for any debug msgs */
891         u8 ssid[IW_ESSID_MAX_SIZE + 1];
892         u8 ssid_len;
893
894         struct ieee80211_qos_data qos_data;
895
896         /* These are network statistics */
897         struct ieee80211_rx_stats stats;
898         u16 capability;
899         u8 rates[MAX_RATES_LENGTH];
900         u8 rates_len;
901         u8 rates_ex[MAX_RATES_EX_LENGTH];
902         u8 rates_ex_len;
903         unsigned long last_scanned;
904         u8 mode;
905         u32 flags;
906         u32 last_associate;
907         u32 time_stamp[2];
908         u16 beacon_interval;
909         u16 listen_interval;
910         u16 atim_window;
911         u8 erp_value;
912         u8 wpa_ie[MAX_WPA_IE_LEN];
913         size_t wpa_ie_len;
914         u8 rsn_ie[MAX_WPA_IE_LEN];
915         size_t rsn_ie_len;
916         struct ieee80211_tim_parameters tim;
917
918         /* 802.11h info */
919
920         /* Power Constraint - mandatory if spctrm mgmt required */
921         u8 power_constraint;
922
923         /* TPC Report - mandatory if spctrm mgmt required */
924         struct ieee80211_tpc_report tpc_report;
925
926         /* IBSS DFS - mandatory if spctrm mgmt required and IBSS
927          * NOTE: This is variable length and so must be allocated dynamically */
928         struct ieee80211_ibss_dfs *ibss_dfs;
929
930         /* Channel Switch Announcement - optional if spctrm mgmt required */
931         struct ieee80211_csa csa;
932
933         /* Quiet - optional if spctrm mgmt required */
934         struct ieee80211_quiet quiet;
935
936         struct list_head list;
937 };
938
939 enum ieee80211_state {
940         IEEE80211_UNINITIALIZED = 0,
941         IEEE80211_INITIALIZED,
942         IEEE80211_ASSOCIATING,
943         IEEE80211_ASSOCIATED,
944         IEEE80211_AUTHENTICATING,
945         IEEE80211_AUTHENTICATED,
946         IEEE80211_SHUTDOWN
947 };
948
949 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
950 #define DEFAULT_FTS 2346
951
952 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
953 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
954 #define CFG_IEEE80211_RTS (1<<2)
955
956 #define IEEE80211_24GHZ_MIN_CHANNEL 1
957 #define IEEE80211_24GHZ_MAX_CHANNEL 14
958 #define IEEE80211_24GHZ_CHANNELS    14
959
960 #define IEEE80211_52GHZ_MIN_CHANNEL 34
961 #define IEEE80211_52GHZ_MAX_CHANNEL 165
962 #define IEEE80211_52GHZ_CHANNELS    131
963
964 enum {
965         IEEE80211_CH_PASSIVE_ONLY = (1 << 0),
966         IEEE80211_CH_B_ONLY = (1 << 2),
967         IEEE80211_CH_NO_IBSS = (1 << 3),
968         IEEE80211_CH_UNIFORM_SPREADING = (1 << 4),
969         IEEE80211_CH_RADAR_DETECT = (1 << 5),
970         IEEE80211_CH_INVALID = (1 << 6),
971 };
972
973 struct ieee80211_channel {
974         u32 freq;
975         u8 channel;
976         u8 flags;
977         u8 max_power;
978 };
979
980 struct ieee80211_geo {
981         u8 name[4];
982         u8 bg_channels;
983         u8 a_channels;
984         struct ieee80211_channel bg[IEEE80211_24GHZ_CHANNELS];
985         struct ieee80211_channel a[IEEE80211_52GHZ_CHANNELS];
986 };
987
988 struct ieee80211_device {
989         struct net_device *dev;
990         struct ieee80211_security sec;
991
992         /* Bookkeeping structures */
993         struct net_device_stats stats;
994         struct ieee80211_stats ieee_stats;
995
996         struct ieee80211_geo geo;
997
998         /* Probe / Beacon management */
999         struct list_head network_free_list;
1000         struct list_head network_list;
1001         struct ieee80211_network *networks;
1002         int scans;
1003         int scan_age;
1004
1005         int iw_mode;            /* operating mode (IW_MODE_*) */
1006         struct iw_spy_data spy_data;    /* iwspy support */
1007
1008         spinlock_t lock;
1009
1010         int tx_headroom;        /* Set to size of any additional room needed at front
1011                                  * of allocated Tx SKBs */
1012         u32 config;
1013
1014         /* WEP and other encryption related settings at the device level */
1015         int open_wep;           /* Set to 1 to allow unencrypted frames */
1016
1017         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1018                                  * WEP key changes */
1019
1020         /* If the host performs {en,de}cryption, then set to 1 */
1021         int host_encrypt;
1022         int host_encrypt_msdu;
1023         int host_decrypt;
1024         /* host performs multicast decryption */
1025         int host_mc_decrypt;
1026
1027         int host_open_frag;
1028         int host_build_iv;
1029         int ieee802_1x;         /* is IEEE 802.1X used */
1030
1031         /* WPA data */
1032         int wpa_enabled;
1033         int drop_unencrypted;
1034         int privacy_invoked;
1035         size_t wpa_ie_len;
1036         u8 *wpa_ie;
1037
1038         struct list_head crypt_deinit_list;
1039         struct ieee80211_crypt_data *crypt[WEP_KEYS];
1040         int tx_keyidx;          /* default TX key index (crypt[tx_keyidx]) */
1041         struct timer_list crypt_deinit_timer;
1042         int crypt_quiesced;
1043
1044         int bcrx_sta_key;       /* use individual keys to override default keys even
1045                                  * with RX of broad/multicast frames */
1046
1047         /* Fragmentation structures */
1048         struct ieee80211_frag_entry frag_cache[IEEE80211_FRAG_CACHE_LEN];
1049         unsigned int frag_next_idx;
1050         u16 fts;                /* Fragmentation Threshold */
1051         u16 rts;                /* RTS threshold */
1052
1053         /* Association info */
1054         u8 bssid[ETH_ALEN];
1055
1056         enum ieee80211_state state;
1057
1058         int mode;               /* A, B, G */
1059         int modulation;         /* CCK, OFDM */
1060         int freq_band;          /* 2.4Ghz, 5.2Ghz, Mixed */
1061         int abg_true;           /* ABG flag              */
1062
1063         int perfect_rssi;
1064         int worst_rssi;
1065
1066         /* Callback functions */
1067         void (*set_security) (struct net_device * dev,
1068                               struct ieee80211_security * sec);
1069         int (*hard_start_xmit) (struct ieee80211_txb * txb,
1070                                 struct net_device * dev, int pri);
1071         int (*reset_port) (struct net_device * dev);
1072         int (*is_queue_full) (struct net_device * dev, int pri);
1073
1074         int (*handle_management) (struct net_device * dev,
1075                                   struct ieee80211_network * network, u16 type);
1076
1077         /* Typical STA methods */
1078         int (*handle_auth) (struct net_device * dev,
1079                             struct ieee80211_auth * auth);
1080         int (*handle_deauth) (struct net_device * dev,
1081                               struct ieee80211_deauth * auth);
1082         int (*handle_action) (struct net_device * dev,
1083                               struct ieee80211_action * action,
1084                               struct ieee80211_rx_stats * stats);
1085         int (*handle_disassoc) (struct net_device * dev,
1086                                 struct ieee80211_disassoc * assoc);
1087         int (*handle_beacon) (struct net_device * dev,
1088                               struct ieee80211_beacon * beacon,
1089                               struct ieee80211_network * network);
1090         int (*handle_probe_response) (struct net_device * dev,
1091                                       struct ieee80211_probe_response * resp,
1092                                       struct ieee80211_network * network);
1093         int (*handle_probe_request) (struct net_device * dev,
1094                                      struct ieee80211_probe_request * req,
1095                                      struct ieee80211_rx_stats * stats);
1096         int (*handle_assoc_response) (struct net_device * dev,
1097                                       struct ieee80211_assoc_response * resp,
1098                                       struct ieee80211_network * network);
1099
1100         /* Typical AP methods */
1101         int (*handle_assoc_request) (struct net_device * dev);
1102         int (*handle_reassoc_request) (struct net_device * dev,
1103                                        struct ieee80211_reassoc_request * req);
1104
1105         /* This must be the last item so that it points to the data
1106          * allocated beyond this structure by alloc_ieee80211 */
1107         u8 priv[0];
1108 };
1109
1110 #define IEEE_A            (1<<0)
1111 #define IEEE_B            (1<<1)
1112 #define IEEE_G            (1<<2)
1113 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1114
1115 static inline void *ieee80211_priv(struct net_device *dev)
1116 {
1117         return ((struct ieee80211_device *)netdev_priv(dev))->priv;
1118 }
1119
1120 static inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
1121 {
1122         /* Single white space is for Linksys APs */
1123         if (essid_len == 1 && essid[0] == ' ')
1124                 return 1;
1125
1126         /* Otherwise, if the entire essid is 0, we assume it is hidden */
1127         while (essid_len) {
1128                 essid_len--;
1129                 if (essid[essid_len] != '\0')
1130                         return 0;
1131         }
1132
1133         return 1;
1134 }
1135
1136 static inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee,
1137                                           int mode)
1138 {
1139         /*
1140          * It is possible for both access points and our device to support
1141          * combinations of modes, so as long as there is one valid combination
1142          * of ap/device supported modes, then return success
1143          *
1144          */
1145         if ((mode & IEEE_A) &&
1146             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1147             (ieee->freq_band & IEEE80211_52GHZ_BAND))
1148                 return 1;
1149
1150         if ((mode & IEEE_G) &&
1151             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1152             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1153                 return 1;
1154
1155         if ((mode & IEEE_B) &&
1156             (ieee->modulation & IEEE80211_CCK_MODULATION) &&
1157             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1158                 return 1;
1159
1160         return 0;
1161 }
1162
1163 static inline int ieee80211_get_hdrlen(u16 fc)
1164 {
1165         int hdrlen = IEEE80211_3ADDR_LEN;
1166         u16 stype = WLAN_FC_GET_STYPE(fc);
1167
1168         switch (WLAN_FC_GET_TYPE(fc)) {
1169         case IEEE80211_FTYPE_DATA:
1170                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
1171                         hdrlen = IEEE80211_4ADDR_LEN;
1172                 if (stype & IEEE80211_STYPE_QOS_DATA)
1173                         hdrlen += 2;
1174                 break;
1175         case IEEE80211_FTYPE_CTL:
1176                 switch (WLAN_FC_GET_STYPE(fc)) {
1177                 case IEEE80211_STYPE_CTS:
1178                 case IEEE80211_STYPE_ACK:
1179                         hdrlen = IEEE80211_1ADDR_LEN;
1180                         break;
1181                 default:
1182                         hdrlen = IEEE80211_2ADDR_LEN;
1183                         break;
1184                 }
1185                 break;
1186         }
1187
1188         return hdrlen;
1189 }
1190
1191 static inline u8 *ieee80211_get_payload(struct ieee80211_hdr *hdr)
1192 {
1193         switch (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
1194         case IEEE80211_1ADDR_LEN:
1195                 return ((struct ieee80211_hdr_1addr *)hdr)->payload;
1196         case IEEE80211_2ADDR_LEN:
1197                 return ((struct ieee80211_hdr_2addr *)hdr)->payload;
1198         case IEEE80211_3ADDR_LEN:
1199                 return ((struct ieee80211_hdr_3addr *)hdr)->payload;
1200         case IEEE80211_4ADDR_LEN:
1201                 return ((struct ieee80211_hdr_4addr *)hdr)->payload;
1202         }
1203         return NULL;
1204 }
1205
1206 static inline int ieee80211_is_ofdm_rate(u8 rate)
1207 {
1208         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
1209         case IEEE80211_OFDM_RATE_6MB:
1210         case IEEE80211_OFDM_RATE_9MB:
1211         case IEEE80211_OFDM_RATE_12MB:
1212         case IEEE80211_OFDM_RATE_18MB:
1213         case IEEE80211_OFDM_RATE_24MB:
1214         case IEEE80211_OFDM_RATE_36MB:
1215         case IEEE80211_OFDM_RATE_48MB:
1216         case IEEE80211_OFDM_RATE_54MB:
1217                 return 1;
1218         }
1219         return 0;
1220 }
1221
1222 static inline int ieee80211_is_cck_rate(u8 rate)
1223 {
1224         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
1225         case IEEE80211_CCK_RATE_1MB:
1226         case IEEE80211_CCK_RATE_2MB:
1227         case IEEE80211_CCK_RATE_5MB:
1228         case IEEE80211_CCK_RATE_11MB:
1229                 return 1;
1230         }
1231         return 0;
1232 }
1233
1234 /* ieee80211.c */
1235 extern void free_ieee80211(struct net_device *dev);
1236 extern struct net_device *alloc_ieee80211(int sizeof_priv);
1237
1238 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
1239
1240 /* ieee80211_tx.c */
1241 extern int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev);
1242 extern void ieee80211_txb_free(struct ieee80211_txb *);
1243 extern int ieee80211_tx_frame(struct ieee80211_device *ieee,
1244                               struct ieee80211_hdr *frame, int len);
1245
1246 /* ieee80211_rx.c */
1247 extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1248                         struct ieee80211_rx_stats *rx_stats);
1249 /* make sure to set stats->len */
1250 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1251                              struct ieee80211_hdr_4addr *header,
1252                              struct ieee80211_rx_stats *stats);
1253 extern void ieee80211_network_reset(struct ieee80211_network *network);
1254
1255 /* ieee80211_geo.c */
1256 extern const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device
1257                                                      *ieee);
1258 extern int ieee80211_set_geo(struct ieee80211_device *ieee,
1259                              const struct ieee80211_geo *geo);
1260
1261 extern int ieee80211_is_valid_channel(struct ieee80211_device *ieee,
1262                                       u8 channel);
1263 extern int ieee80211_channel_to_index(struct ieee80211_device *ieee,
1264                                       u8 channel);
1265 extern u8 ieee80211_freq_to_channel(struct ieee80211_device *ieee, u32 freq);
1266 extern u8 ieee80211_get_channel_flags(struct ieee80211_device *ieee,
1267                                       u8 channel);
1268 extern const struct ieee80211_channel *ieee80211_get_channel(struct
1269                                                              ieee80211_device
1270                                                              *ieee, u8 channel);
1271
1272 /* ieee80211_wx.c */
1273 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
1274                                  struct iw_request_info *info,
1275                                  union iwreq_data *wrqu, char *key);
1276 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
1277                                    struct iw_request_info *info,
1278                                    union iwreq_data *wrqu, char *key);
1279 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
1280                                    struct iw_request_info *info,
1281                                    union iwreq_data *wrqu, char *key);
1282 extern int ieee80211_wx_set_encodeext(struct ieee80211_device *ieee,
1283                                       struct iw_request_info *info,
1284                                       union iwreq_data *wrqu, char *extra);
1285 extern int ieee80211_wx_get_encodeext(struct ieee80211_device *ieee,
1286                                       struct iw_request_info *info,
1287                                       union iwreq_data *wrqu, char *extra);
1288 extern int ieee80211_wx_set_auth(struct net_device *dev,
1289                                  struct iw_request_info *info,
1290                                  union iwreq_data *wrqu,
1291                                  char *extra);
1292 extern int ieee80211_wx_get_auth(struct net_device *dev,
1293                                  struct iw_request_info *info,
1294                                  union iwreq_data *wrqu,
1295                                  char *extra);
1296
1297 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
1298 {
1299         ieee->scans++;
1300 }
1301
1302 static inline int ieee80211_get_scans(struct ieee80211_device *ieee)
1303 {
1304         return ieee->scans;
1305 }
1306
1307 #endif                          /* IEEE80211_H */