This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / net / wireless / ieee80211 / 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, 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 #ifndef IEEE80211_H
22 #define IEEE80211_H
23 #include <linux/if_ether.h> /* ETH_ALEN */
24
25 #define IEEE80211_DATA_LEN              2304
26 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
27    6.2.1.1.2.
28
29    The figure in section 7.1.2 suggests a body size of up to 2312
30    bytes is allowed, which is a bit confusing, I suspect this
31    represents the 2304 bytes of real data, plus a possible 8 bytes of
32    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
33
34
35 #define IEEE80211_HLEN                  30
36 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
37
38 struct ieee80211_hdr {
39         u16 frame_ctl;
40         u16 duration_id;
41         u8 addr1[ETH_ALEN];
42         u8 addr2[ETH_ALEN];
43         u8 addr3[ETH_ALEN];
44         u16 seq_ctl;
45         u8 addr4[ETH_ALEN];
46 } __attribute__ ((packed));
47
48 #define IEEE80211_3ADDR_SIZE (24)
49 #define IEEE80211_4ADDR_SIZE (30)
50
51 #define MIN_FRAG_THRESHOLD     256U
52 #define MAX_FRAG_THRESHOLD     2342U
53
54 /* Frame control field constants */
55 #define IEEE80211_FCTL_VERS             0x0002
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_WEP              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
84 /* control */
85 #define IEEE80211_STYPE_PSPOLL          0x00A0
86 #define IEEE80211_STYPE_RTS             0x00B0
87 #define IEEE80211_STYPE_CTS             0x00C0
88 #define IEEE80211_STYPE_ACK             0x00D0
89 #define IEEE80211_STYPE_CFEND           0x00E0
90 #define IEEE80211_STYPE_CFENDACK        0x00F0
91
92 /* data */
93 #define IEEE80211_STYPE_DATA            0x0000
94 #define IEEE80211_STYPE_DATA_CFACK      0x0010
95 #define IEEE80211_STYPE_DATA_CFPOLL     0x0020
96 #define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
97 #define IEEE80211_STYPE_NULLFUNC        0x0040
98 #define IEEE80211_STYPE_CFACK           0x0050
99 #define IEEE80211_STYPE_CFPOLL          0x0060
100 #define IEEE80211_STYPE_CFACKPOLL       0x0070
101
102 #define IEEE80211_SCTL_FRAG             0x000F
103 #define IEEE80211_SCTL_SEQ              0xFFF0
104
105
106 /* debug macros */
107
108 #ifdef CONFIG_IEEE80211_DEBUG
109 extern u32 ieee80211_debug_level;
110 #define IEEE80211_DEBUG(level, fmt, args...) \
111 do { if (ieee80211_debug_level & (level)) \
112   printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
113          in_interrupt() ? 'I' : 'U', __FUNCTION__, ## args); } while (0)
114 #else
115 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0);
116 #endif  /* CONFIG_IEEE80211_DEBUG */
117
118 /*
119  * To use the debug system;
120  *
121  * If you are defining a new debug classification, simply add it to the #define
122  * list here in the form of:
123  *
124  * #define IEEE80211_DL_xxxx VALUE
125  * 
126  * shifting value to the left one bit from the previous entry.  xxxx should be
127  * the name of the classification (for example, WEP)
128  *
129  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
130  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
131  * to send output to that classification.
132  *
133  * To add your debug level to the list of levels seen when you perform
134  *
135  * % cat /proc/net/ipw/debug_level
136  *
137  * you simply need to add your entry to the ipw_debug_levels array.
138  *
139  * If you do not see debug_level in /proc/net/ipw then you do not have 
140  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
141  *
142  */
143
144 #define IEEE80211_DL_INFO          BIT(0)
145 #define IEEE80211_DL_WX            BIT(1)
146 #define IEEE80211_DL_SCAN          BIT(2)
147 #define IEEE80211_DL_STATE         BIT(3)
148 #define IEEE80211_DL_MGMT          BIT(4)
149 #define IEEE80211_DL_FRAG          BIT(5)
150 #define IEEE80211_DL_EAP           BIT(6)
151
152 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
153 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
154 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
155
156 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
157 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
158 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
159 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
160 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
161 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
162 #include <linux/netdevice.h>
163 #include <linux/wireless.h>
164 #include <linux/if_arp.h> /* ARPHRD_ETHER */
165
166 #ifndef WIRELESS_SPY
167 #define WIRELESS_SPY            // enable iwspy support
168 #endif
169 #include <net/iw_handler.h>     // new driver API
170
171 #define BIT(x) (1 << (x))
172
173 #ifndef ETH_P_PAE
174 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
175 #endif /* ETH_P_PAE */
176
177 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
178
179 #ifndef ETH_P_80211_RAW
180 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
181 #endif
182
183 /* IEEE 802.11 defines */
184
185 #define P80211_OUI_LEN 3
186
187 struct ieee80211_snap_hdr {
188
189         u8    dsap;   /* always 0xAA */
190         u8    ssap;   /* always 0xAA */
191         u8    ctrl;   /* always 0x03 */
192         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
193
194 } __attribute__ ((packed));
195
196 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
197
198 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
199 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
200
201 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
202 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & IEEE80211_SCTL_SEQ)
203
204 /* Authentication algorithms */
205 #define WLAN_AUTH_OPEN 0
206 #define WLAN_AUTH_SHARED_KEY 1
207
208 #define WLAN_AUTH_CHALLENGE_LEN 128
209
210 #define WLAN_CAPABILITY_BSS BIT(0)
211 #define WLAN_CAPABILITY_IBSS BIT(1)
212 #define WLAN_CAPABILITY_CF_POLLABLE BIT(2)
213 #define WLAN_CAPABILITY_CF_POLL_REQUEST BIT(3)
214 #define WLAN_CAPABILITY_PRIVACY BIT(4)
215 #define WLAN_CAPABILITY_SHORT_PREAMBLE BIT(5)
216 #define WLAN_CAPABILITY_PBCC BIT(6)
217 #define WLAN_CAPABILITY_CHANNEL_AGILITY BIT(7)
218
219 /* Status codes */
220 #define WLAN_STATUS_SUCCESS 0
221 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
222 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
223 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
224 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
225 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
226 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
227 #define WLAN_STATUS_CHALLENGE_FAIL 15
228 #define WLAN_STATUS_AUTH_TIMEOUT 16
229 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
230 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
231 /* 802.11b */
232 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
233 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
234 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
235
236 /* Reason codes */
237 #define WLAN_REASON_UNSPECIFIED 1
238 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
239 #define WLAN_REASON_DEAUTH_LEAVING 3
240 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
241 #define WLAN_REASON_DISASSOC_AP_BUSY 5
242 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
243 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
244 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
245 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
246
247
248 /* Information Element IDs */
249 #define WLAN_EID_SSID 0
250 #define WLAN_EID_SUPP_RATES 1
251 #define WLAN_EID_FH_PARAMS 2
252 #define WLAN_EID_DS_PARAMS 3
253 #define WLAN_EID_CF_PARAMS 4
254 #define WLAN_EID_TIM 5
255 #define WLAN_EID_IBSS_PARAMS 6
256 #define WLAN_EID_CHALLENGE 16
257 #define WLAN_EID_RSN 48
258 #define WLAN_EID_GENERIC 221
259
260 #define IEEE80211_MGMT_HDR_LEN 24
261 #define IEEE80211_DATA_HDR3_LEN 24
262 #define IEEE80211_DATA_HDR4_LEN 30
263
264
265 #define IEEE80211_STATMASK_SIGNAL BIT(0)
266 #define IEEE80211_STATMASK_RSSI BIT(1)
267 #define IEEE80211_STATMASK_NOISE BIT(2)
268 #define IEEE80211_STATMASK_RATE BIT(3)
269 #define IEEE80211_STATMASK_WEMASK 0x7
270
271
272 #define IEEE80211_CCK_MODULATION    BIT(0)
273 #define IEEE80211_OFDM_MODULATION   BIT(1)
274
275 #define IEEE80211_24GHZ_BAND     BIT(0)
276 #define IEEE80211_52GHZ_BAND     BIT(1)
277
278 #define IEEE80211_CCK_RATE_1MB          0x02    
279 #define IEEE80211_CCK_RATE_2MB          0x04    
280 #define IEEE80211_CCK_RATE_5MB          0x0B
281 #define IEEE80211_CCK_RATE_11MB         0x16
282 #define IEEE80211_OFDM_RATE_6MB         0x0C    
283 #define IEEE80211_OFDM_RATE_9MB         0x12
284 #define IEEE80211_OFDM_RATE_12MB                0x18    
285 #define IEEE80211_OFDM_RATE_18MB                0x24
286 #define IEEE80211_OFDM_RATE_24MB                0x30
287 #define IEEE80211_OFDM_RATE_36MB                0x48
288 #define IEEE80211_OFDM_RATE_48MB                0x60
289 #define IEEE80211_OFDM_RATE_54MB                0x6C
290 #define IEEE80211_BASIC_RATE_MASK               0x80
291
292 #define IEEE80211_CCK_RATE_1MB_MASK             BIT(0)  
293 #define IEEE80211_CCK_RATE_2MB_MASK             BIT(1)
294 #define IEEE80211_CCK_RATE_5MB_MASK             BIT(2)
295 #define IEEE80211_CCK_RATE_11MB_MASK            BIT(3)
296 #define IEEE80211_OFDM_RATE_6MB_MASK            BIT(4)
297 #define IEEE80211_OFDM_RATE_9MB_MASK            BIT(5)
298 #define IEEE80211_OFDM_RATE_12MB_MASK           BIT(6)
299 #define IEEE80211_OFDM_RATE_18MB_MASK           BIT(7)
300 #define IEEE80211_OFDM_RATE_24MB_MASK           BIT(8)  
301 #define IEEE80211_OFDM_RATE_36MB_MASK           BIT(9)
302 #define IEEE80211_OFDM_RATE_48MB_MASK           BIT(10)
303 #define IEEE80211_OFDM_RATE_54MB_MASK           BIT(11)
304
305 #define IEEE80211_CCK_RATES_MASK                0x0000000F
306 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
307         IEEE80211_CCK_RATE_2MB_MASK)
308 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
309         IEEE80211_CCK_RATE_5MB_MASK | \
310         IEEE80211_CCK_RATE_11MB_MASK)
311
312 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
313 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
314         IEEE80211_OFDM_RATE_12MB_MASK | \
315         IEEE80211_OFDM_RATE_24MB_MASK)
316 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
317         IEEE80211_OFDM_RATE_9MB_MASK  | \
318         IEEE80211_OFDM_RATE_18MB_MASK | \
319         IEEE80211_OFDM_RATE_36MB_MASK | \
320         IEEE80211_OFDM_RATE_48MB_MASK | \
321         IEEE80211_OFDM_RATE_54MB_MASK)
322 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
323                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
324
325 #define IEEE80211_NUM_OFDM_RATES            8
326 #define IEEE80211_NUM_CCK_RATES     4
327 #define IEEE80211_OFDM_SHIFT_MASK_A       4
328
329
330
331
332 /* NOTE: This data is for statistical purposes; not all hardware provides this
333  *       information for frames received.  Not setting these will not cause
334  *       any adverse affects. */
335 struct ieee80211_rx_stats {
336         u32 mac_time;
337         u8 rssi;
338         u8 signal;
339         u8 noise;
340         u16 rate; /* in 100 kbps */
341         u8 received_channel;
342         u8 control;
343         u8 mask;
344         u8 freq;
345         u16 len;
346 };
347
348 /* IEEE 802.11 requires that STA supports concurrent reception of at least
349  * three fragmented frames. This define can be increased to support more
350  * concurrent frames, but it should be noted that each entry can consume about
351  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
352 #define IEEE80211_FRAG_CACHE_LEN 4
353
354 struct ieee80211_frag_entry {
355         unsigned long first_frag_time;
356         unsigned int seq;
357         unsigned int last_frag;
358         struct sk_buff *skb;
359         u8 src_addr[ETH_ALEN];
360         u8 dst_addr[ETH_ALEN];
361 };
362
363 struct ieee80211_stats {
364         unsigned int tx_unicast_frames;
365         unsigned int tx_multicast_frames;
366         unsigned int tx_fragments;
367         unsigned int tx_unicast_octets;
368         unsigned int tx_multicast_octets;
369         unsigned int tx_deferred_transmissions;
370         unsigned int tx_single_retry_frames;
371         unsigned int tx_multiple_retry_frames;
372         unsigned int tx_retry_limit_exceeded;
373         unsigned int tx_discards;
374         unsigned int rx_unicast_frames;
375         unsigned int rx_multicast_frames;
376         unsigned int rx_fragments;
377         unsigned int rx_unicast_octets;
378         unsigned int rx_multicast_octets;
379         unsigned int rx_fcs_errors;
380         unsigned int rx_discards_no_buffer;
381         unsigned int tx_discards_wrong_sa;
382         unsigned int rx_discards_wep_undecryptable;
383         unsigned int rx_message_in_msg_fragments;
384         unsigned int rx_message_in_bad_msg_fragments;
385 };
386
387 struct ieee80211_device;
388
389 #include "ieee80211_crypt.h"
390  
391 #define SEC_KEY_1         BIT(0)
392 #define SEC_KEY_2         BIT(1)
393 #define SEC_KEY_3         BIT(2)
394 #define SEC_KEY_4         BIT(3)
395 #define SEC_ACTIVE_KEY    BIT(4)
396 #define SEC_AUTH_MODE     BIT(5)
397 #define SEC_UNICAST_GROUP BIT(6)
398 #define SEC_LEVEL         BIT(7)
399 #define SEC_ENABLED       BIT(8)
400
401 #define SEC_LEVEL_0      0 /* None */
402 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
403 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
404 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
405 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
406
407 #define WEP_KEYS 4
408 #define WEP_KEY_LEN 13
409
410 struct ieee80211_security {
411         u16 active_key:1, 
412             enabled:1, 
413             auth_mode:2, 
414             auth_algo:4, 
415             unicast_uses_group:1;
416         u8 key_sizes[WEP_KEYS];
417         u8 keys[WEP_KEYS][WEP_KEY_LEN];
418         u8 level;
419         u16 flags;
420 } __attribute__ ((packed));
421
422
423 /*
424
425  802.11 data frame from AP
426
427       ,-------------------------------------------------------------------.
428 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
429       |------|------|---------|---------|---------|------|---------|------|
430 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
431       |      | tion | (BSSID) |         |         | ence |  data   |      |
432       `-------------------------------------------------------------------'
433
434 Total: 28-2340 bytes
435
436 */
437
438 struct ieee80211_header_data {
439         u16 frame_ctl;
440         u16 duration_id;
441         u8 addr1[6];
442         u8 addr2[6];
443         u8 addr3[6];
444         u16 seq_ctrl;
445 };
446
447 #define BEACON_PROBE_SSID_ID_POSITION 12
448
449 /* Management Frame Information Element Types */
450 #define MFIE_TYPE_SSID       0
451 #define MFIE_TYPE_RATES      1
452 #define MFIE_TYPE_FH_SET     2
453 #define MFIE_TYPE_DS_SET     3
454 #define MFIE_TYPE_CF_SET     4
455 #define MFIE_TYPE_TIM        5
456 #define MFIE_TYPE_IBSS_SET   6
457 #define MFIE_TYPE_CHALLENGE  16
458 #define MFIE_TYPE_RSN        48
459 #define MFIE_TYPE_RATES_EX   50
460 #define MFIE_TYPE_GENERIC    221
461
462 struct ieee80211_info_element_hdr {
463         u8 id;
464         u8 len;
465 } __attribute__ ((packed));
466
467 struct ieee80211_info_element {
468         u8 id;
469         u8 len;
470         u8 data[0];
471 } __attribute__ ((packed));
472
473 /*
474  * These are the data types that can make up management packets
475  *
476         u16 auth_algorithm;
477         u16 auth_sequence;
478         u16 beacon_interval;
479         u16 capability;
480         u8 current_ap[ETH_ALEN];
481         u16 listen_interval;
482         struct {
483                 u16 association_id:14, reserved:2;
484         } __attribute__ ((packed));
485         u32 time_stamp[2];
486         u16 reason;
487         u16 status;
488 */
489
490 struct ieee80211_authentication {
491         struct ieee80211_header_data header;
492         u16 algorithm;
493         u16 transaction;
494         u16 status;
495         struct ieee80211_info_element info_element;
496 } __attribute__ ((packed));
497
498
499 struct ieee80211_probe_response {
500         struct ieee80211_header_data header;
501         u32 time_stamp[2];
502         u16 beacon_interval;
503         u16 capability;
504         struct ieee80211_info_element info_element;
505 } __attribute__ ((packed));
506
507 struct ieee80211_assoc_request_frame {
508         u16 capability;
509         u16 listen_interval;
510         u8 current_ap[ETH_ALEN];
511         struct ieee80211_info_element info_element;
512 } __attribute__ ((packed));
513
514 struct ieee80211_helper_functions {
515         void (*set_security)(struct ieee80211_device *ieee, 
516                              struct ieee80211_security *sec);
517
518         /* these functions are defined in hardware model specific files
519          * (hostap_{cs,plx,pci}.c */
520         int (*card_present)(struct ieee80211_device *ieee);
521         void (*cor_sreset)(struct ieee80211_device *ieee);
522         int (*dev_open)(struct ieee80211_device *ieee);
523         int (*dev_close)(struct ieee80211_device *ieee);
524         void (*genesis_reset)(struct ieee80211_device *ieee, int hcr);
525
526         
527         /* Turn on unencrypted packet filtering at the HW level */
528         void (*set_unencrypted_filter)(struct ieee80211_device *ieee, int flag);
529
530         /* the following functions are from hostap_hw.c, but they may have some
531          * hardware model specific code */
532
533         int (*hw_enable)(struct net_device *dev, int initial);
534         int (*hw_config)(struct net_device *dev, int initial);
535         void (*hw_reset)(struct net_device *dev);
536         void (*hw_shutdown)(struct net_device *dev, int no_disable);
537         int (*reset_port)(struct net_device *dev);
538         int (*tx)(struct sk_buff *skb, struct net_device *dev);
539         void (*schedule_reset)(struct ieee80211_device *ieee);
540         int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
541 };
542
543
544
545 /* SWEEP TABLE ENTRIES NUMBER*/
546 #define MAX_SWEEP_TAB_ENTRIES             42
547 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
548 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
549  * only use 8, and then use extended rates for the remaining supported
550  * rates.  Other APs, however, stick all of their supported rates on the
551  * main rates information element... */
552 #define MAX_RATES_LENGTH                  ((u8)12)
553 #define MAX_RATES_EX_LENGTH               ((u8)16)
554 #define MAX_NETWORK_COUNT                  128
555
556 #define CRC_LENGTH                 4U
557
558 #define MAX_WPA_IE_LEN 64
559
560 #define NETWORK_EMPTY_ESSID BIT(0)
561 #define NETWORK_HAS_OFDM    BIT(1)
562
563 struct ieee80211_network {
564         u8 bssid[ETH_ALEN];
565         u8 ssid_len;
566         struct ieee80211_rx_stats stats;
567         u16 capability;
568         u8 channel;
569         u8 rates[MAX_RATES_LENGTH];
570         u8 rates_len;
571         u8 rates_ex[MAX_RATES_EX_LENGTH];
572         u8 rates_ex_len;
573         unsigned long last_scanned;
574         u8 mode;
575         u8 flags;
576         u32 last_associate;
577         /* Ensure null-terminated for any debug msgs */
578         u8 ssid[IW_ESSID_MAX_SIZE + 1];
579         u32 time_stamp[2];
580         u16 beacon_interval;
581         u16 listen_interval;
582         u16 atim_window;
583 #ifdef CONFIG_IEEE80211_WPA             
584         u8 wpa_ie[MAX_WPA_IE_LEN];
585         size_t wpa_ie_len;
586         u8 rsn_ie[MAX_WPA_IE_LEN];
587         size_t rsn_ie_len;      
588 #endif /* CONFIG_IEEE80211_WPA */       
589         struct list_head list;
590 };
591
592 enum ieee80211_state {
593         IEEE80211_UNINITIALIZED = 0,
594         IEEE80211_INITIALIZED,
595         IEEE80211_ASSOCIATING,
596         IEEE80211_ASSOCIATED,
597         IEEE80211_AUTHENTICATING,
598         IEEE80211_AUTHENTICATED,
599         IEEE80211_SHUTDOWN
600 };
601
602 #define DEFAULT_MAX_SCAN_AGE (15 * HZ) 
603 #define DEFAULT_FTS 2342
604 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
605 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
606
607
608 extern inline int is_multicast_ether_addr(const u8 *addr)
609 {
610         return ((addr[0] != 0xff) && (0x01 & addr[0]));
611 }
612
613 extern inline int is_broadcast_ether_addr(const u8 *addr)
614 {
615         return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&   \
616                 (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
617 }
618
619
620 struct ieee80211_device {
621         struct net_device *dev;
622
623         /* Bookkeeping structures */
624         struct net_device_stats stats;
625         struct ieee80211_stats ieee_stats;
626         void *priv;
627
628         /* Probe / Beacon management */
629         struct list_head network_free_list;
630         struct list_head network_list;
631         struct ieee80211_network *networks;
632         int scans;
633         int scan_age;
634
635         int iw_mode; /* operating mode (IW_MODE_*) */
636
637         spinlock_t lock;
638
639         int tx_payload_only; /* set to 1 if HW only expects the Tx SKB 
640                               * to contain the payload (vs. a fully configured
641                               * 802.11 header for a data frame) */
642         int tx_headroom; /* Set to size of any additional room needed at front
643                           * of allocated Tx SKBs */
644
645         /* WEP and other encryption related settings at the device level */
646         int open_wep; /* Set to 1 to allow unencrypted frames */
647
648         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
649                                  * WEP key changes */
650
651         /* If the host performs {en,de}cryption, then set to 1 */
652         int host_encrypt;
653         int host_decrypt;
654
655 #ifdef CONFIG_IEEE80211_WPA
656         /* WPA data */
657         int wpa_enabled;
658         int drop_unencrypted;
659         int tkip_countermeasures;
660         int ieee_802_1x; /* is IEEE 802.1X used */
661         int privacy_invoked;
662         size_t wpa_ie_len;
663         u8 *wpa_ie;
664 #endif  /* CONFIG_IEEE80211_WPA */
665
666         struct list_head crypt_deinit_list;
667         struct ieee80211_crypt_data *crypt[WEP_KEYS];
668         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
669         struct timer_list crypt_deinit_timer;
670
671         int bcrx_sta_key; /* use individual keys to override default keys even
672                            * with RX of broad/multicast frames */
673
674         /* Fragmentation structures */
675         struct ieee80211_frag_entry frag_cache[IEEE80211_FRAG_CACHE_LEN];
676         unsigned int frag_next_idx;
677         u16 fts; /* Fragmentation Threshold */
678
679         /* Association info */
680         u8 bssid[ETH_ALEN];
681
682         /* Callback vtable */
683         struct ieee80211_helper_functions *func;
684
685         enum ieee80211_state state;
686
687         int mode;       /* A, B, G */
688         int modulation; /* CCK, OFDM */
689         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
690         int abg_ture;   /* ABG flag              */
691 };
692
693 #define IEEE_A            0
694 #define IEEE_B            1
695 #define IEEE_G            2
696 #define IEEE_MASK         (BIT(IEEE_A) | BIT(IEEE_B) | BIT(IEEE_G))
697
698 extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
699 {
700         /* Single white space is for Linksys APs */
701         if (essid_len == 1 && essid[0] == ' ')
702                 return 1;
703
704         /* Otherwise, if the entire essid is 0, we assume it is hidden */
705         while (essid_len) {
706                 essid_len--;
707                 if (essid[essid_len] != '\0')
708                         return 0;
709         }
710
711         return 1;
712 }
713
714
715 extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
716 {
717         int rc = 1;
718         switch(mode) {
719         case IEEE_A:
720                 if (!(ieee->modulation & IEEE80211_OFDM_MODULATION) ||
721                     !(ieee->freq_band & IEEE80211_52GHZ_BAND))
722                         rc = 0;
723                 break;
724
725         case IEEE_B:
726                 if (!(ieee->modulation & IEEE80211_CCK_MODULATION) ||
727                     !(ieee->freq_band & IEEE80211_24GHZ_BAND))
728                         rc = 0;
729                 break;
730
731         case IEEE_G:
732                 if (!(ieee->modulation & IEEE80211_OFDM_MODULATION) ||
733                     !(ieee->freq_band & IEEE80211_24GHZ_BAND))
734                         rc = 0;
735                 break;
736         }
737         return rc;
738 }
739
740 extern inline int ieee80211_get_hdrlen(u16 fc)
741 {
742         int hdrlen = 24;
743
744         switch (WLAN_FC_GET_TYPE(fc)) {
745         case IEEE80211_FTYPE_DATA:
746                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
747                         hdrlen = 30; /* Addr4 */
748                 break;
749         case IEEE80211_FTYPE_CTL:
750                 switch (WLAN_FC_GET_STYPE(fc)) {
751                 case IEEE80211_STYPE_CTS:
752                 case IEEE80211_STYPE_ACK:
753                         hdrlen = 10;
754                         break;
755                 default:
756                         hdrlen = 16;
757                         break;
758                 }
759                 break;
760         }
761
762         return hdrlen;
763 }
764
765
766
767 /* ieee80211.c */
768 extern struct ieee80211_device * ieee80211_alloc(struct net_device *dev,
769                                                  void *priv);
770 extern void ieee80211_free(struct ieee80211_device *ieee);
771
772 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
773
774 /* ieee80211_tx.c */
775
776 struct ieee80211_txb {
777         u8 nr_frags;
778         u8 encrypted;
779         u16 reserved;
780         u16 frag_size;
781         u16 payload_size;
782         struct sk_buff *fragments[0];
783 };
784
785 extern struct ieee80211_txb *ieee80211_skb_to_txb(struct ieee80211_device *ieee, 
786                                                   struct sk_buff *skb);
787 extern void ieee80211_txb_free(struct ieee80211_txb *);
788
789
790 /* ieee80211_rx.c */
791 extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
792                         struct ieee80211_rx_stats *rx_stats);
793 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
794                              struct ieee80211_hdr *header,
795                              struct ieee80211_rx_stats *stats);
796
797 /* iee80211_wx.c */
798 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee, 
799                                  struct iw_request_info *info, 
800                                  union iwreq_data *wrqu, char *key);
801 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee, 
802                                    struct iw_request_info *info, 
803                                    union iwreq_data *wrqu, char *key);
804 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee, 
805                                    struct iw_request_info *info, 
806                                    union iwreq_data *wrqu, char *key);
807
808
809 extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee) 
810 {
811         ieee->scans++;
812 }
813
814 extern inline int ieee80211_get_scans(struct ieee80211_device *ieee) 
815 {
816         return ieee->scans;
817 }
818
819 static inline const char *escape_essid(const char *essid, u8 essid_len) {
820         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
821         const char *s = essid;
822         char *d = escaped;
823
824         if (ieee80211_is_empty_essid(essid, essid_len)) {
825                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
826                 return escaped;
827         }
828                 
829         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
830         while (essid_len--) {
831                 if (*s == '\0') {
832                         *d++ = '\\';
833                         *d++ = '0';
834                         s++;
835                 } else {
836                         *d++ = *s++;
837                 }
838         }
839         *d = '\0';
840         return escaped;
841 }
842
843 #ifndef offset_in_page
844 #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
845 #endif
846
847 #endif /* IEEE80211_H */