Merge commit 'v2.6.34-rc1' into for-2.6.35
[pandora-kernel.git] / drivers / staging / rtl8187se / 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  * Modified for Realtek's wi-fi cards by Andrea Merello
17  * <andreamrl@tiscali.it>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License version 2 as
21  * published by the Free Software Foundation. See README and COPYING for
22  * more details.
23  */
24 #ifndef IEEE80211_H
25 #define IEEE80211_H
26 #include <linux/if_ether.h> /* ETH_ALEN */
27 #include <linux/kernel.h>   /* ARRAY_SIZE */
28 #include <linux/version.h>
29 #include <linux/jiffies.h>
30 #include <linux/timer.h>
31 #include <linux/sched.h>
32 #include <linux/semaphore.h>
33 #include <linux/wireless.h>
34 #include <linux/ieee80211.h>
35
36 #define KEY_TYPE_NA             0x0
37 #define KEY_TYPE_WEP40          0x1
38 #define KEY_TYPE_TKIP           0x2
39 #define KEY_TYPE_CCMP           0x4
40 #define KEY_TYPE_WEP104         0x5
41
42 #define aSifsTime                                       10
43
44 #define MGMT_QUEUE_NUM 5
45
46
47 #define IEEE_CMD_SET_WPA_PARAM                  1
48 #define IEEE_CMD_SET_WPA_IE                     2
49 #define IEEE_CMD_SET_ENCRYPTION                 3
50 #define IEEE_CMD_MLME                           4
51
52 #define IEEE_PARAM_WPA_ENABLED                  1
53 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
54 #define IEEE_PARAM_DROP_UNENCRYPTED             3
55 #define IEEE_PARAM_PRIVACY_INVOKED              4
56 #define IEEE_PARAM_AUTH_ALGS                    5
57 #define IEEE_PARAM_IEEE_802_1X                  6
58 //It should consistent with the driver_XXX.c
59 //   David, 2006.9.26
60 #define IEEE_PARAM_WPAX_SELECT                  7
61 //Added for notify the encryption type selection
62 //   David, 2006.9.26
63 #define IEEE_PROTO_WPA                          1
64 #define IEEE_PROTO_RSN                          2
65 //Added for notify the encryption type selection
66 //   David, 2006.9.26
67 #define IEEE_WPAX_USEGROUP                      0
68 #define IEEE_WPAX_WEP40                         1
69 #define IEEE_WPAX_TKIP                          2
70 #define IEEE_WPAX_WRAP                          3
71 #define IEEE_WPAX_CCMP                          4
72 #define IEEE_WPAX_WEP104                        5
73
74 #define IEEE_KEY_MGMT_IEEE8021X                 1
75 #define IEEE_KEY_MGMT_PSK                       2
76
77
78
79 #define IEEE_MLME_STA_DEAUTH                    1
80 #define IEEE_MLME_STA_DISASSOC                  2
81
82
83 #define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
84 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
85 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED                4
86 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
87 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED                6
88 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
89
90
91 #define IEEE_CRYPT_ALG_NAME_LEN                 16
92
93 //by amy for ps
94 typedef struct ieee_param {
95         u32 cmd;
96         u8 sta_addr[ETH_ALEN];
97         union {
98                 struct {
99                         u8 name;
100                         u32 value;
101                 } wpa_param;
102                 struct {
103                         u32 len;
104                         u8 reserved[32];
105                         u8 data[0];
106                 } wpa_ie;
107                 struct{
108                         int command;
109                         int reason_code;
110                 } mlme;
111                 struct {
112                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
113                         u8 set_tx;
114                         u32 err;
115                         u8 idx;
116                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
117                         u16 key_len;
118                         u8 key[0];
119                 } crypt;
120
121         } u;
122 }ieee_param;
123
124
125 #define MSECS(t) msecs_to_jiffies(t)
126 #define msleep_interruptible_rtl  msleep_interruptible
127
128 #define IEEE80211_DATA_LEN              2304
129 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
130    6.2.1.1.2.
131
132    The figure in section 7.1.2 suggests a body size of up to 2312
133    bytes is allowed, which is a bit confusing, I suspect this
134    represents the 2304 bytes of real data, plus a possible 8 bytes of
135    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
136
137 #define IEEE80211_3ADDR_LEN 24
138 #define IEEE80211_4ADDR_LEN 30
139 #define IEEE80211_FCS_LEN    4
140 #define IEEE80211_HLEN                  IEEE80211_4ADDR_LEN
141 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
142 #define IEEE80211_MGMT_HDR_LEN 24
143 #define IEEE80211_DATA_HDR3_LEN 24
144 #define IEEE80211_DATA_HDR4_LEN 30
145
146 #define MIN_FRAG_THRESHOLD     256U
147 #define MAX_FRAG_THRESHOLD     2346U
148
149 /* Frame control field constants */
150 #define IEEE80211_FCTL_DSTODS           0x0300 //added by david
151 #define IEEE80211_FCTL_WEP              0x4000
152
153 /* debug macros */
154
155 #ifdef CONFIG_IEEE80211_DEBUG
156 extern u32 ieee80211_debug_level;
157 #define IEEE80211_DEBUG(level, fmt, args...) \
158 do { if (ieee80211_debug_level & (level)) \
159   printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
160          in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
161 #else
162 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
163 #endif  /* CONFIG_IEEE80211_DEBUG */
164
165 /*
166  * To use the debug system;
167  *
168  * If you are defining a new debug classification, simply add it to the #define
169  * list here in the form of:
170  *
171  * #define IEEE80211_DL_xxxx VALUE
172  *
173  * shifting value to the left one bit from the previous entry.  xxxx should be
174  * the name of the classification (for example, WEP)
175  *
176  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
177  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
178  * to send output to that classification.
179  *
180  * To add your debug level to the list of levels seen when you perform
181  *
182  * % cat /proc/net/ipw/debug_level
183  *
184  * you simply need to add your entry to the ipw_debug_levels array.
185  *
186  * If you do not see debug_level in /proc/net/ipw then you do not have
187  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
188  *
189  */
190
191 #define IEEE80211_DL_INFO          (1<<0)
192 #define IEEE80211_DL_WX            (1<<1)
193 #define IEEE80211_DL_SCAN          (1<<2)
194 #define IEEE80211_DL_STATE         (1<<3)
195 #define IEEE80211_DL_MGMT          (1<<4)
196 #define IEEE80211_DL_FRAG          (1<<5)
197 #define IEEE80211_DL_EAP           (1<<6)
198 #define IEEE80211_DL_DROP          (1<<7)
199
200 #define IEEE80211_DL_TX            (1<<8)
201 #define IEEE80211_DL_RX            (1<<9)
202
203 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
204 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
205 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
206
207 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
208 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
209 //#define IEEE_DEBUG_SCAN  IEEE80211_WARNING
210 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
211 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
212 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
213 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
214 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
215 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
216 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
217 #include <linux/netdevice.h>
218 #include <linux/wireless.h>
219 #include <linux/if_arp.h> /* ARPHRD_ETHER */
220
221 #ifndef WIRELESS_SPY
222 #define WIRELESS_SPY            // enable iwspy support
223 #endif
224 #include <net/iw_handler.h>     // new driver API
225
226 #ifndef ETH_P_PAE
227 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
228 #endif /* ETH_P_PAE */
229
230 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
231
232 #ifndef ETH_P_80211_RAW
233 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
234 #endif
235
236 /* IEEE 802.11 defines */
237
238 #define P80211_OUI_LEN 3
239
240 struct ieee80211_snap_hdr {
241
242         u8    dsap;   /* always 0xAA */
243         u8    ssap;   /* always 0xAA */
244         u8    ctrl;   /* always 0x03 */
245         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
246
247 } __attribute__ ((packed));
248
249 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
250
251 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
252 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
253
254 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
255 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & IEEE80211_SCTL_SEQ)
256
257 #define WLAN_CAPABILITY_BSS (1<<0)
258 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
259
260 #define IEEE80211_STATMASK_SIGNAL (1<<0)
261 #define IEEE80211_STATMASK_RSSI (1<<1)
262 #define IEEE80211_STATMASK_NOISE (1<<2)
263 #define IEEE80211_STATMASK_RATE (1<<3)
264 #define IEEE80211_STATMASK_WEMASK 0x7
265
266
267 #define IEEE80211_CCK_MODULATION    (1<<0)
268 #define IEEE80211_OFDM_MODULATION   (1<<1)
269
270 #define IEEE80211_24GHZ_BAND     (1<<0)
271 #define IEEE80211_52GHZ_BAND     (1<<1)
272
273 #define IEEE80211_CCK_RATE_LEN                  4
274 #define IEEE80211_CCK_RATE_1MB                  0x02
275 #define IEEE80211_CCK_RATE_2MB                  0x04
276 #define IEEE80211_CCK_RATE_5MB                  0x0B
277 #define IEEE80211_CCK_RATE_11MB                 0x16
278 #define IEEE80211_OFDM_RATE_LEN                 8
279 #define IEEE80211_OFDM_RATE_6MB                 0x0C
280 #define IEEE80211_OFDM_RATE_9MB                 0x12
281 #define IEEE80211_OFDM_RATE_12MB                0x18
282 #define IEEE80211_OFDM_RATE_18MB                0x24
283 #define IEEE80211_OFDM_RATE_24MB                0x30
284 #define IEEE80211_OFDM_RATE_36MB                0x48
285 #define IEEE80211_OFDM_RATE_48MB                0x60
286 #define IEEE80211_OFDM_RATE_54MB                0x6C
287 #define IEEE80211_BASIC_RATE_MASK               0x80
288
289 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
290 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
291 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
292 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
293 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
294 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
295 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
296 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
297 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
298 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
299 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
300 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
301
302 #define IEEE80211_CCK_RATES_MASK                0x0000000F
303 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
304         IEEE80211_CCK_RATE_2MB_MASK)
305 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
306         IEEE80211_CCK_RATE_5MB_MASK | \
307         IEEE80211_CCK_RATE_11MB_MASK)
308
309 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
310 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
311         IEEE80211_OFDM_RATE_12MB_MASK | \
312         IEEE80211_OFDM_RATE_24MB_MASK)
313 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
314         IEEE80211_OFDM_RATE_9MB_MASK  | \
315         IEEE80211_OFDM_RATE_18MB_MASK | \
316         IEEE80211_OFDM_RATE_36MB_MASK | \
317         IEEE80211_OFDM_RATE_48MB_MASK | \
318         IEEE80211_OFDM_RATE_54MB_MASK)
319 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
320                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
321
322 #define IEEE80211_NUM_OFDM_RATES            8
323 #define IEEE80211_NUM_CCK_RATES             4
324 #define IEEE80211_OFDM_SHIFT_MASK_A         4
325
326 /* this is stolen and modified from the madwifi driver*/
327 #define IEEE80211_FC0_TYPE_MASK         0x0c
328 #define IEEE80211_FC0_TYPE_DATA         0x08
329 #define IEEE80211_FC0_SUBTYPE_MASK      0xB0
330 #define IEEE80211_FC0_SUBTYPE_QOS       0x80
331
332 #define IEEE80211_QOS_HAS_SEQ(fc) \
333         (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
334          (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
335
336 /* this is stolen from ipw2200 driver */
337 #define IEEE_IBSS_MAC_HASH_SIZE 31
338 struct ieee_ibss_seq {
339         u8 mac[ETH_ALEN];
340         u16 seq_num[17];
341         u16 frag_num[17];
342         unsigned long packet_time[17];
343         struct list_head list;
344 };
345
346 /* NOTE: This data is for statistical purposes; not all hardware provides this
347  *       information for frames received.  Not setting these will not cause
348  *       any adverse affects. */
349 struct ieee80211_rx_stats {
350         u32 mac_time[2];
351         u8 signalstrength;
352         s8 rssi;
353         u8 signal;
354         u8 noise;
355         u16 rate; /* in 100 kbps */
356         u8 received_channel;
357         u8 control;
358         u8 mask;
359         u8 freq;
360         u16 len;
361         u8 nic_type;
362 };
363
364 /* IEEE 802.11 requires that STA supports concurrent reception of at least
365  * three fragmented frames. This define can be increased to support more
366  * concurrent frames, but it should be noted that each entry can consume about
367  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
368 #define IEEE80211_FRAG_CACHE_LEN 4
369
370 struct ieee80211_frag_entry {
371         unsigned long first_frag_time;
372         unsigned int seq;
373         unsigned int last_frag;
374         struct sk_buff *skb;
375         u8 src_addr[ETH_ALEN];
376         u8 dst_addr[ETH_ALEN];
377 };
378
379 struct ieee80211_stats {
380         unsigned int tx_unicast_frames;
381         unsigned int tx_multicast_frames;
382         unsigned int tx_fragments;
383         unsigned int tx_unicast_octets;
384         unsigned int tx_multicast_octets;
385         unsigned int tx_deferred_transmissions;
386         unsigned int tx_single_retry_frames;
387         unsigned int tx_multiple_retry_frames;
388         unsigned int tx_retry_limit_exceeded;
389         unsigned int tx_discards;
390         unsigned int rx_unicast_frames;
391         unsigned int rx_multicast_frames;
392         unsigned int rx_fragments;
393         unsigned int rx_unicast_octets;
394         unsigned int rx_multicast_octets;
395         unsigned int rx_fcs_errors;
396         unsigned int rx_discards_no_buffer;
397         unsigned int tx_discards_wrong_sa;
398         unsigned int rx_discards_undecryptable;
399         unsigned int rx_message_in_msg_fragments;
400         unsigned int rx_message_in_bad_msg_fragments;
401 };
402
403 struct ieee80211_device;
404
405 #include "ieee80211_crypt.h"
406
407 #define SEC_KEY_1         (1<<0)
408 #define SEC_KEY_2         (1<<1)
409 #define SEC_KEY_3         (1<<2)
410 #define SEC_KEY_4         (1<<3)
411 #define SEC_ACTIVE_KEY    (1<<4)
412 #define SEC_AUTH_MODE     (1<<5)
413 #define SEC_UNICAST_GROUP (1<<6)
414 #define SEC_LEVEL         (1<<7)
415 #define SEC_ENABLED       (1<<8)
416
417 #define SEC_LEVEL_0      0 /* None */
418 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
419 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
420 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
421 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
422
423 #define WEP_KEYS 4
424 #define WEP_KEY_LEN 13
425
426 #define WEP_KEY_LEN_MODIF 32
427
428 struct ieee80211_security {
429         u16 active_key:2,
430             enabled:1,
431             auth_mode:2,
432             auth_algo:4,
433             unicast_uses_group:1;
434         u8 key_sizes[WEP_KEYS];
435         u8 keys[WEP_KEYS][WEP_KEY_LEN_MODIF];
436         u8 level;
437         u16 flags;
438 } __attribute__ ((packed));
439
440
441 /*
442
443  802.11 data frame from AP
444
445       ,-------------------------------------------------------------------.
446 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
447       |------|------|---------|---------|---------|------|---------|------|
448 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
449       |      | tion | (BSSID) |         |         | ence |  data   |      |
450       `-------------------------------------------------------------------'
451
452 Total: 28-2340 bytes
453
454 */
455
456 /* Management Frame Information Element Types */
457 enum {
458         MFIE_TYPE_SSID = 0,
459         MFIE_TYPE_RATES = 1,
460         MFIE_TYPE_FH_SET = 2,
461         MFIE_TYPE_DS_SET = 3,
462         MFIE_TYPE_CF_SET = 4,
463         MFIE_TYPE_TIM = 5,
464         MFIE_TYPE_IBSS_SET = 6,
465         MFIE_TYPE_COUNTRY = 7,
466         MFIE_TYPE_CHALLENGE = 16,
467         MFIE_TYPE_ERP = 42,
468         MFIE_TYPE_RSN = 48,
469         MFIE_TYPE_RATES_EX = 50,
470         MFIE_TYPE_GENERIC = 221,
471 };
472
473 struct ieee80211_header_data {
474         u16 frame_ctl;
475         u16 duration_id;
476         u8 addr1[6];
477         u8 addr2[6];
478         u8 addr3[6];
479         u16 seq_ctrl;
480 };
481
482 struct ieee80211_hdr_4addr {
483         u16 frame_ctl;
484         u16 duration_id;
485         u8 addr1[ETH_ALEN];
486         u8 addr2[ETH_ALEN];
487         u8 addr3[ETH_ALEN];
488         u16 seq_ctl;
489         u8 addr4[ETH_ALEN];
490 } __attribute__ ((packed));
491
492 struct ieee80211_hdr_3addrqos {
493         u16 frame_ctl;
494         u16 duration_id;
495         u8 addr1[ETH_ALEN];
496         u8 addr2[ETH_ALEN];
497         u8 addr3[ETH_ALEN];
498         u16 seq_ctl;
499         u16 qos_ctl;
500 } __attribute__ ((packed));
501
502 struct ieee80211_hdr_4addrqos {
503         u16 frame_ctl;
504         u16 duration_id;
505         u8 addr1[ETH_ALEN];
506         u8 addr2[ETH_ALEN];
507         u8 addr3[ETH_ALEN];
508         u16 seq_ctl;
509         u8 addr4[ETH_ALEN];
510         u16 qos_ctl;
511 } __attribute__ ((packed));
512
513 struct ieee80211_info_element_hdr {
514         u8 id;
515         u8 len;
516 } __attribute__ ((packed));
517
518 struct ieee80211_info_element {
519         u8 id;
520         u8 len;
521         u8 data[0];
522 } __attribute__ ((packed));
523
524 struct ieee80211_authentication {
525         struct ieee80211_header_data header;
526         u16 algorithm;
527         u16 transaction;
528         u16 status;
529         //struct ieee80211_info_element_hdr info_element;
530 } __attribute__ ((packed));
531
532 struct ieee80211_disassoc_frame {
533         struct ieee80211_hdr_3addr header;
534         u16    reasoncode;
535 } __attribute__ ((packed));
536
537 struct ieee80211_probe_request {
538         struct ieee80211_header_data header;
539         /* struct ieee80211_info_element info_element; */
540 } __attribute__ ((packed));
541
542 struct ieee80211_probe_response {
543         struct ieee80211_header_data header;
544         u32 time_stamp[2];
545         u16 beacon_interval;
546         u16 capability;
547         struct ieee80211_info_element info_element;
548 } __attribute__ ((packed));
549
550 struct ieee80211_assoc_request_frame {
551         struct ieee80211_hdr_3addr header;
552         u16 capability;
553         u16 listen_interval;
554         //u8 current_ap[ETH_ALEN];
555         struct ieee80211_info_element_hdr info_element;
556 } __attribute__ ((packed));
557
558 struct ieee80211_assoc_response_frame {
559         struct ieee80211_hdr_3addr header;
560         u16 capability;
561         u16 status;
562         u16 aid;
563         struct ieee80211_info_element info_element; /* supported rates */
564 } __attribute__ ((packed));
565
566 struct ieee80211_txb {
567         u8 nr_frags;
568         u8 encrypted;
569         u16 reserved;
570         u16 frag_size;
571         u16 payload_size;
572         struct sk_buff *fragments[0];
573 };
574
575 /* SWEEP TABLE ENTRIES NUMBER */
576 #define MAX_SWEEP_TAB_ENTRIES                   42
577 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET        7
578
579 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
580  * only use 8, and then use extended rates for the remaining supported
581  * rates.  Other APs, however, stick all of their supported rates on the
582  * main rates information element... */
583 #define MAX_RATES_LENGTH                        ((u8)12)
584 #define MAX_RATES_EX_LENGTH                     ((u8)16)
585
586 #define MAX_NETWORK_COUNT                       128
587
588 #define MAX_CHANNEL_NUMBER                      165
589
590 #define IEEE80211_SOFTMAC_SCAN_TIME             100 /* (HZ / 2) */
591 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME      (HZ * 2)
592
593 #define CRC_LENGTH      4U
594
595 #define MAX_WPA_IE_LEN  64
596
597 #define NETWORK_EMPTY_ESSID     (1 << 0)
598 #define NETWORK_HAS_OFDM        (1 << 1)
599 #define NETWORK_HAS_CCK         (1 << 2)
600
601 struct ieee80211_wmm_ac_param {
602         u8 ac_aci_acm_aifsn;
603         u8 ac_ecwmin_ecwmax;
604         u16 ac_txop_limit;
605 };
606
607 struct ieee80211_wmm_ts_info {
608         u8 ac_dir_tid;
609         u8 ac_up_psb;
610         u8 reserved;
611 } __attribute__ ((packed));
612
613 struct ieee80211_wmm_tspec_elem {
614         struct ieee80211_wmm_ts_info ts_info;
615         u16 norm_msdu_size;
616         u16 max_msdu_size;
617         u32 min_serv_inter;
618         u32 max_serv_inter;
619         u32 inact_inter;
620         u32 suspen_inter;
621         u32 serv_start_time;
622         u32 min_data_rate;
623         u32 mean_data_rate;
624         u32 peak_data_rate;
625         u32 max_burst_size;
626         u32 delay_bound;
627         u32 min_phy_rate;
628         u16 surp_band_allow;
629         u16 medium_time;
630 }__attribute__((packed));
631
632 enum eap_type {
633         EAP_PACKET = 0,
634         EAPOL_START,
635         EAPOL_LOGOFF,
636         EAPOL_KEY,
637         EAPOL_ENCAP_ASF_ALERT
638 };
639
640 static const char *eap_types[] = {
641         [EAP_PACKET]            = "EAP-Packet",
642         [EAPOL_START]           = "EAPOL-Start",
643         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
644         [EAPOL_KEY]             = "EAPOL-Key",
645         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
646 };
647
648 static inline const char *eap_get_type(int type)
649 {
650         return (type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
651 }
652
653 struct eapol {
654         u8 snap[6];
655         u16 ethertype;
656         u8 version;
657         u8 type;
658         u16 length;
659 } __attribute__ ((packed));
660
661 struct ieee80211_softmac_stats {
662         unsigned int rx_ass_ok;
663         unsigned int rx_ass_err;
664         unsigned int rx_probe_rq;
665         unsigned int tx_probe_rs;
666         unsigned int tx_beacons;
667         unsigned int rx_auth_rq;
668         unsigned int rx_auth_rs_ok;
669         unsigned int rx_auth_rs_err;
670         unsigned int tx_auth_rq;
671         unsigned int no_auth_rs;
672         unsigned int no_ass_rs;
673         unsigned int tx_ass_rq;
674         unsigned int rx_ass_rq;
675         unsigned int tx_probe_rq;
676         unsigned int reassoc;
677         unsigned int swtxstop;
678         unsigned int swtxawake;
679 };
680
681 #define BEACON_PROBE_SSID_ID_POSITION 12
682
683 /*
684  * These are the data types that can make up management packets
685  *
686         u16 auth_algorithm;
687         u16 auth_sequence;
688         u16 beacon_interval;
689         u16 capability;
690         u8 current_ap[ETH_ALEN];
691         u16 listen_interval;
692         struct {
693                 u16 association_id:14, reserved:2;
694         } __attribute__ ((packed));
695         u32 time_stamp[2];
696         u16 reason;
697         u16 status;
698 */
699
700 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
701 #define IEEE80211_DEFAULT_BASIC_RATE 10
702
703 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
704 #define MAX_SP_Len  (WMM_all_frame << 4)
705 #define IEEE80211_QOS_TID 0x0f
706 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
707
708 #define MAX_IE_LEN                                              0xFF //+YJ,080625
709
710 typedef struct _CHANNEL_LIST{
711         u8      Channel[MAX_CHANNEL_NUMBER + 1];
712         u8      Len;
713 }CHANNEL_LIST, *PCHANNEL_LIST;
714
715 //by amy for ps
716 #define IEEE80211_WATCH_DOG_TIME    2000
717 //by amy for ps
718 //by amy for antenna
719 #define ANTENNA_DIVERSITY_TIMER_PERIOD          1000 // 1000 m
720 //by amy for antenna
721
722 #define IEEE80211_DTIM_MBCAST 4
723 #define IEEE80211_DTIM_UCAST 2
724 #define IEEE80211_DTIM_VALID 1
725 #define IEEE80211_DTIM_INVALID 0
726
727 #define IEEE80211_PS_DISABLED 0
728 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
729 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
730 #define IEEE80211_PS_ENABLE   IEEE80211_DTIM_VALID
731 //added by David for QoS 2006/6/30
732 //#define WMM_Hang_8187
733 #ifdef WMM_Hang_8187
734 #undef WMM_Hang_8187
735 #endif
736
737 #define WME_AC_BE   0x00
738 #define WME_AC_BK   0x01
739 #define WME_AC_VI   0x02
740 #define WME_AC_VO   0x03
741 #define WME_ACI_MASK 0x03
742 #define WME_AIFSN_MASK 0x03
743 #define WME_AC_PRAM_LEN 16
744
745 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
746 //#define UP2AC(up)     ((up<3) ? ((up==0)?1:0) : (up>>1))
747 #define UP2AC(up) (                \
748         ((up) < 1) ? WME_AC_BE : \
749         ((up) < 3) ? WME_AC_BK : \
750         ((up) < 4) ? WME_AC_BE : \
751         ((up) < 6) ? WME_AC_VI : \
752         WME_AC_VO)
753 //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
754 #define AC2UP(_ac)      (       \
755         ((_ac) == WME_AC_VO) ? 6 : \
756         ((_ac) == WME_AC_VI) ? 5 : \
757         ((_ac) == WME_AC_BK) ? 1 : \
758         0)
759
760 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
761 struct  ether_header {
762         u8 ether_dhost[ETHER_ADDR_LEN];
763         u8 ether_shost[ETHER_ADDR_LEN];
764         u16 ether_type;
765 } __attribute__((packed));
766
767 #ifndef ETHERTYPE_PAE
768 #define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
769 #endif
770 #ifndef ETHERTYPE_IP
771 #define ETHERTYPE_IP    0x0800          /* IP protocol */
772 #endif
773
774 struct ieee80211_network {
775         /* These entries are used to identify a unique network */
776         u8 bssid[ETH_ALEN];
777         u8 channel;
778         /* Ensure null-terminated for any debug msgs */
779         u8 ssid[IW_ESSID_MAX_SIZE + 1];
780         u8 ssid_len;
781
782         /* These are network statistics */
783         struct ieee80211_rx_stats stats;
784         u16 capability;
785         u8 rates[MAX_RATES_LENGTH];
786         u8 rates_len;
787         u8 rates_ex[MAX_RATES_EX_LENGTH];
788         u8 rates_ex_len;
789         unsigned long last_scanned;
790         u8 mode;
791         u8 flags;
792         u32 last_associate;
793         u32 time_stamp[2];
794         u16 beacon_interval;
795         u16 listen_interval;
796         u16 atim_window;
797         u8 wpa_ie[MAX_WPA_IE_LEN];
798         size_t wpa_ie_len;
799         u8 rsn_ie[MAX_WPA_IE_LEN];
800         size_t rsn_ie_len;
801         u8 dtim_period;
802         u8 dtim_data;
803         u32 last_dtim_sta_time[2];
804         struct list_head list;
805         //appeded for QoS
806         u8 wmm_info;
807         struct ieee80211_wmm_ac_param wmm_param[4];
808         u8 QoS_Enable;
809         u8 SignalStrength;
810 //by amy 080312
811         u8 HighestOperaRate;
812 //by amy 080312
813         u8 Turbo_Enable;//enable turbo mode, added by thomas
814         u16 CountryIeLen;
815         u8 CountryIeBuf[MAX_IE_LEN];
816 };
817
818 enum ieee80211_state {
819
820         /* the card is not linked at all */
821         IEEE80211_NOLINK = 0,
822
823         /* IEEE80211_ASSOCIATING* are for BSS client mode
824          * the driver shall not perform RX filtering unless
825          * the state is LINKED.
826          * The driver shall just check for the state LINKED and
827          * defaults to NOLINK for ALL the other states (including
828          * LINKED_SCANNING)
829          */
830
831         /* the association procedure will start (wq scheduling)*/
832         IEEE80211_ASSOCIATING,
833         IEEE80211_ASSOCIATING_RETRY,
834
835         /* the association procedure is sending AUTH request*/
836         IEEE80211_ASSOCIATING_AUTHENTICATING,
837
838         /* the association procedure has successfully authentcated
839          * and is sending association request
840          */
841         IEEE80211_ASSOCIATING_AUTHENTICATED,
842
843         /* the link is ok. the card associated to a BSS or linked
844          * to a ibss cell or acting as an AP and creating the bss
845          */
846         IEEE80211_LINKED,
847
848         /* same as LINKED, but the driver shall apply RX filter
849          * rules as we are in NO_LINK mode. As the card is still
850          * logically linked, but it is doing a syncro site survey
851          * then it will be back to LINKED state.
852          */
853         IEEE80211_LINKED_SCANNING,
854
855 };
856
857 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
858 #define DEFAULT_FTS 2346
859
860 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
861 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
862
863 typedef struct tx_pending_t{
864         int frag;
865         struct ieee80211_txb *txb;
866 }tx_pending_t;
867
868 enum {
869         COUNTRY_CODE_FCC = 0,
870         COUNTRY_CODE_IC = 1,
871         COUNTRY_CODE_ETSI = 2,
872         COUNTRY_CODE_SPAIN = 3,
873         COUNTRY_CODE_FRANCE = 4,
874         COUNTRY_CODE_MKK = 5,
875         COUNTRY_CODE_MKK1 = 6,
876         COUNTRY_CODE_ISRAEL = 7,
877         COUNTRY_CODE_TELEC = 8,
878         COUNTRY_CODE_GLOBAL_DOMAIN = 9,
879         COUNTRY_CODE_WORLD_WIDE_13_INDEX = 10
880 };
881
882 struct ieee80211_device {
883         struct net_device *dev;
884
885         /* Bookkeeping structures */
886         struct net_device_stats stats;
887         struct ieee80211_stats ieee_stats;
888         struct ieee80211_softmac_stats softmac_stats;
889
890         /* Probe / Beacon management */
891         struct list_head network_free_list;
892         struct list_head network_list;
893         struct ieee80211_network *networks;
894         int scans;
895         int scan_age;
896
897         int iw_mode; /* operating mode (IW_MODE_*) */
898
899         spinlock_t lock;
900         spinlock_t wpax_suitlist_lock;
901
902         int tx_headroom; /* Set to size of any additional room needed at front
903                           * of allocated Tx SKBs */
904         u32 config;
905
906         /* WEP and other encryption related settings at the device level */
907         int open_wep; /* Set to 1 to allow unencrypted frames */
908
909         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
910                                  * WEP key changes */
911
912         /* If the host performs {en,de}cryption, then set to 1 */
913         int host_encrypt;
914         int host_decrypt;
915         int ieee802_1x; /* is IEEE 802.1X used */
916
917         /* WPA data */
918         int wpa_enabled;
919         int drop_unencrypted;
920         int tkip_countermeasures;
921         int privacy_invoked;
922         size_t wpa_ie_len;
923         u8 *wpa_ie;
924
925         u8 ap_mac_addr[6];
926         u16 pairwise_key_type;
927         u16 broadcast_key_type;
928
929         struct list_head crypt_deinit_list;
930         struct ieee80211_crypt_data *crypt[WEP_KEYS];
931         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
932         struct timer_list crypt_deinit_timer;
933
934         int bcrx_sta_key; /* use individual keys to override default keys even
935                            * with RX of broad/multicast frames */
936
937         /* Fragmentation structures */
938         // each streaming contain a entry
939         struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
940         unsigned int frag_next_idx[17];
941         u16 fts; /* Fragmentation Threshold */
942
943         /* This stores infos for the current network.
944          * Either the network we are associated in INFRASTRUCTURE
945          * or the network that we are creating in MASTER mode.
946          * ad-hoc is a mixture ;-).
947          * Note that in infrastructure mode, even when not associated,
948          * fields bssid and essid may be valid (if wpa_set and essid_set
949          * are true) as thy carry the value set by the user via iwconfig
950          */
951         struct ieee80211_network current_network;
952
953
954         enum ieee80211_state state;
955
956         int short_slot;
957         int mode;       /* A, B, G */
958         int modulation; /* CCK, OFDM */
959         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
960         int abg_true;   /* ABG flag              */
961
962         /* used for forcing the ibss workqueue to terminate
963          * without wait for the syncro scan to terminate
964          */
965         short sync_scan_hurryup;
966
967         void * pDot11dInfo;
968         bool bGlobalDomain;
969
970         // For Liteon Ch12~13 passive scan
971         u8      MinPassiveChnlNum;
972         u8      IbssStartChnl;
973
974         int rate;       /* current rate */
975         int basic_rate;
976         //FIXME: pleace callback, see if redundant with softmac_features
977         short active_scan;
978
979         /* this contains flags for selectively enable softmac support */
980         u16 softmac_features;
981
982         /* if the sequence control field is not filled by HW */
983         u16 seq_ctrl[5];
984
985         /* association procedure transaction sequence number */
986         u16 associate_seq;
987
988         /* AID for RTXed association responses */
989         u16 assoc_id;
990
991         /* power save mode related*/
992         short ps;
993         short sta_sleep;
994         int ps_timeout;
995         struct tasklet_struct ps_task;
996         u32 ps_th;
997         u32 ps_tl;
998
999         short raw_tx;
1000         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1001         short queue_stop;
1002         short scanning;
1003         short proto_started;
1004
1005         struct semaphore wx_sem;
1006         struct semaphore scan_sem;
1007
1008         spinlock_t mgmt_tx_lock;
1009         spinlock_t beacon_lock;
1010
1011         short beacon_txing;
1012
1013         short wap_set;
1014         short ssid_set;
1015
1016         u8  wpax_type_set;    //{added by David, 2006.9.28}
1017         u32 wpax_type_notify; //{added by David, 2006.9.26}
1018
1019         /* QoS related flag */
1020         char init_wmmparam_flag;
1021
1022         /* for discarding duplicated packets in IBSS */
1023         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1024
1025         /* for discarding duplicated packets in BSS */
1026         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1027         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1028         unsigned long last_packet_time[17];
1029
1030         /* for PS mode */
1031         unsigned long last_rx_ps_time;
1032
1033         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1034         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1035         int mgmt_queue_head;
1036         int mgmt_queue_tail;
1037
1038
1039         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1040         struct  tx_pending_t tx_pending;
1041
1042         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1043         struct timer_list associate_timer;
1044
1045         /* used if IEEE_SOFTMAC_BEACONS is set */
1046         struct timer_list beacon_timer;
1047
1048         struct work_struct associate_complete_wq;
1049 //      struct work_struct associate_retry_wq;
1050         struct work_struct associate_procedure_wq;
1051 //      struct work_struct softmac_scan_wq;
1052         struct work_struct wx_sync_scan_wq;
1053         struct work_struct wmm_param_update_wq;
1054         struct work_struct ps_request_tx_ack_wq;//for ps
1055 //      struct work_struct hw_wakeup_wq;
1056 //      struct work_struct hw_sleep_wq;
1057 //      struct work_struct watch_dog_wq;
1058         bool bInactivePs;
1059         bool actscanning;
1060         bool beinretry;
1061         u16 ListenInterval;
1062         unsigned long NumRxDataInPeriod; //YJ,add,080828
1063         unsigned long NumRxBcnInPeriod;  //YJ,add,080828
1064         unsigned long NumRxOkTotal;
1065         unsigned long NumRxUnicast;//YJ,add,080828,for keep alive
1066         bool bHwRadioOff;
1067         struct delayed_work softmac_scan_wq;
1068         struct delayed_work associate_retry_wq;
1069         struct delayed_work hw_wakeup_wq;
1070         struct delayed_work hw_sleep_wq;//+by amy 080324
1071         struct delayed_work watch_dog_wq;
1072         struct delayed_work sw_antenna_wq;
1073         struct delayed_work  start_ibss_wq;
1074 //by amy for rate adaptive 080312
1075     struct delayed_work rate_adapter_wq;
1076 //by amy for rate adaptive
1077         struct delayed_work hw_dig_wq;
1078         struct delayed_work tx_pw_wq;
1079
1080 //Added for RF power on power off by lizhaoming 080512
1081         struct delayed_work GPIOChangeRFWorkItem;
1082
1083         struct workqueue_struct *wq;
1084
1085         /* Callback functions */
1086         void (*set_security)(struct net_device *dev,
1087                              struct ieee80211_security *sec);
1088
1089         /* Used to TX data frame by using txb structs.
1090          * this is not used if in the softmac_features
1091          * is set the flag IEEE_SOFTMAC_TX_QUEUE
1092          */
1093         int (*hard_start_xmit)(struct ieee80211_txb *txb,
1094                                struct net_device *dev);
1095
1096         int (*reset_port)(struct net_device *dev);
1097
1098         /* Softmac-generated frames (mamagement) are TXed via this
1099          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1100          * not set. As some cards may have different HW queues that
1101          * one might want to use for data and management frames
1102          * the option to have two callbacks might be useful.
1103          * This fucntion can't sleep.
1104          */
1105         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1106                                struct net_device *dev);
1107
1108         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1109          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1110          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1111          * then also management frames are sent via this callback.
1112          * This function can't sleep.
1113          */
1114         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1115                                struct net_device *dev,int rate);
1116
1117         /* stops the HW queue for DATA frames. Useful to avoid
1118          * waste time to TX data frame when we are reassociating
1119          * This function can sleep.
1120          */
1121         void (*data_hard_stop)(struct net_device *dev);
1122
1123         /* OK this is complementar to data_poll_hard_stop */
1124         void (*data_hard_resume)(struct net_device *dev);
1125
1126         /* ask to the driver to retune the radio .
1127          * This function can sleep. the driver should ensure
1128          * the radio has been swithced before return.
1129          */
1130         void (*set_chan)(struct net_device *dev,short ch);
1131
1132         /* These are not used if the ieee stack takes care of
1133          * scanning (IEEE_SOFTMAC_SCAN feature set).
1134          * In this case only the set_chan is used.
1135          *
1136          * The syncro version is similar to the start_scan but
1137          * does not return until all channels has been scanned.
1138          * this is called in user context and should sleep,
1139          * it is called in a work_queue when swithcing to ad-hoc mode
1140          * or in behalf of iwlist scan when the card is associated
1141          * and root user ask for a scan.
1142          * the fucntion stop_scan should stop both the syncro and
1143          * background scanning and can sleep.
1144          * The fucntion start_scan should initiate the background
1145          * scanning and can't sleep.
1146          */
1147         void (*scan_syncro)(struct net_device *dev);
1148         void (*start_scan)(struct net_device *dev);
1149         void (*stop_scan)(struct net_device *dev);
1150
1151         /* indicate the driver that the link state is changed
1152          * for example it may indicate the card is associated now.
1153          * Driver might be interested in this to apply RX filter
1154          * rules or simply light the LINK led
1155          */
1156         void (*link_change)(struct net_device *dev);
1157
1158         /* these two function indicates to the HW when to start
1159          * and stop to send beacons. This is used when the
1160          * IEEE_SOFTMAC_BEACONS is not set. For now the
1161          * stop_send_bacons is NOT guaranteed to be called only
1162          * after start_send_beacons.
1163          */
1164         void (*start_send_beacons) (struct net_device *dev);
1165         void (*stop_send_beacons) (struct net_device *dev);
1166
1167         /* power save mode related */
1168         void (*sta_wake_up) (struct net_device *dev);
1169         void (*ps_request_tx_ack) (struct net_device *dev);
1170         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
1171         short (*ps_is_queue_empty) (struct net_device *dev);
1172
1173         /* QoS related */
1174         //void (*wmm_param_update) (struct net_device *dev, u8 *ac_param);
1175         //void (*wmm_param_update) (struct ieee80211_device *ieee);
1176
1177         /* This must be the last item so that it points to the data
1178          * allocated beyond this structure by alloc_ieee80211 */
1179         u8 priv[0];
1180 };
1181
1182 #define IEEE_A            (1<<0)
1183 #define IEEE_B            (1<<1)
1184 #define IEEE_G            (1<<2)
1185 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1186
1187 /* Generate a 802.11 header */
1188
1189 /* Uses the channel change callback directly
1190  * instead of [start/stop] scan callbacks
1191  */
1192 #define IEEE_SOFTMAC_SCAN (1<<2)
1193
1194 /* Perform authentication and association handshake */
1195 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1196
1197 /* Generate probe requests */
1198 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1199
1200 /* Generate respones to probe requests */
1201 #define IEEE_SOFTMAC_PROBERS (1<<5)
1202
1203 /* The ieee802.11 stack will manages the netif queue
1204  * wake/stop for the driver, taking care of 802.11
1205  * fragmentation. See softmac.c for details. */
1206 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1207
1208 /* Uses only the softmac_data_hard_start_xmit
1209  * even for TX management frames.
1210  */
1211 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1212
1213 /* Generate beacons.  The stack will enqueue beacons
1214  * to the card
1215  */
1216 #define IEEE_SOFTMAC_BEACONS (1<<6)
1217
1218
1219
1220 static inline void *ieee80211_priv(struct net_device *dev)
1221 {
1222         return ((struct ieee80211_device *)netdev_priv(dev))->priv;
1223 }
1224
1225 extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
1226 {
1227         /* Single white space is for Linksys APs */
1228         if (essid_len == 1 && essid[0] == ' ')
1229                 return 1;
1230
1231         /* Otherwise, if the entire essid is 0, we assume it is hidden */
1232         while (essid_len) {
1233                 essid_len--;
1234                 if (essid[essid_len] != '\0')
1235                         return 0;
1236         }
1237
1238         return 1;
1239 }
1240
1241 extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
1242 {
1243         /*
1244          * It is possible for both access points and our device to support
1245          * combinations of modes, so as long as there is one valid combination
1246          * of ap/device supported modes, then return success
1247          *
1248          */
1249         if ((mode & IEEE_A) &&
1250             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1251             (ieee->freq_band & IEEE80211_52GHZ_BAND))
1252                 return 1;
1253
1254         if ((mode & IEEE_G) &&
1255             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1256             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1257                 return 1;
1258
1259         if ((mode & IEEE_B) &&
1260             (ieee->modulation & IEEE80211_CCK_MODULATION) &&
1261             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1262                 return 1;
1263
1264         return 0;
1265 }
1266
1267 extern inline int ieee80211_get_hdrlen(u16 fc)
1268 {
1269         int hdrlen = 24;
1270
1271         switch (WLAN_FC_GET_TYPE(fc)) {
1272         case IEEE80211_FTYPE_DATA:
1273                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
1274                         hdrlen = 30; /* Addr4 */
1275                 if(IEEE80211_QOS_HAS_SEQ(fc))
1276                         hdrlen += 2; /* QOS ctrl*/
1277                 break;
1278         case IEEE80211_FTYPE_CTL:
1279                 switch (WLAN_FC_GET_STYPE(fc)) {
1280                 case IEEE80211_STYPE_CTS:
1281                 case IEEE80211_STYPE_ACK:
1282                         hdrlen = 10;
1283                         break;
1284                 default:
1285                         hdrlen = 16;
1286                         break;
1287                 }
1288                 break;
1289         }
1290
1291         return hdrlen;
1292 }
1293
1294
1295
1296 /* ieee80211.c */
1297 extern void free_ieee80211(struct net_device *dev);
1298 extern struct net_device *alloc_ieee80211(int sizeof_priv);
1299
1300 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
1301
1302 /* ieee80211_tx.c */
1303
1304 extern int ieee80211_encrypt_fragment(
1305         struct ieee80211_device *ieee,
1306         struct sk_buff *frag,
1307         int hdr_len);
1308
1309 extern int ieee80211_rtl_xmit(struct sk_buff *skb,
1310                           struct net_device *dev);
1311 extern void ieee80211_txb_free(struct ieee80211_txb *);
1312
1313
1314 /* ieee80211_rx.c */
1315 extern int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1316                         struct ieee80211_rx_stats *rx_stats);
1317 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1318                              struct ieee80211_hdr_4addr *header,
1319                              struct ieee80211_rx_stats *stats);
1320
1321 /* ieee80211_wx.c */
1322 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
1323                                  struct iw_request_info *info,
1324                                  union iwreq_data *wrqu, char *key);
1325 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
1326                                    struct iw_request_info *info,
1327                                    union iwreq_data *wrqu, char *key);
1328 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
1329                                    struct iw_request_info *info,
1330                                    union iwreq_data *wrqu, char *key);
1331 extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
1332                             struct iw_request_info *info,
1333                             union iwreq_data* wrqu, char *extra);
1334 int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
1335                                struct iw_request_info *info,
1336                                struct iw_param *data, char *extra);
1337 int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
1338                                struct iw_request_info *info,
1339                                union iwreq_data *wrqu, char *extra);
1340
1341 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
1342 /* ieee80211_softmac.c */
1343 extern short ieee80211_is_54g(struct ieee80211_network net);
1344 extern short ieee80211_is_shortslot(struct ieee80211_network net);
1345 extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1346                         struct ieee80211_rx_stats *rx_stats, u16 type,
1347                         u16 stype);
1348 extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net);
1349
1350 extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee);
1351 extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
1352 extern void ieee80211_start_bss(struct ieee80211_device *ieee);
1353 extern void ieee80211_start_master_bss(struct ieee80211_device *ieee);
1354 extern void ieee80211_start_ibss(struct ieee80211_device *ieee);
1355 extern void ieee80211_softmac_init(struct ieee80211_device *ieee);
1356 extern void ieee80211_softmac_free(struct ieee80211_device *ieee);
1357 extern void ieee80211_associate_abort(struct ieee80211_device *ieee);
1358 extern void ieee80211_disassociate(struct ieee80211_device *ieee);
1359 extern void ieee80211_stop_scan(struct ieee80211_device *ieee);
1360 extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
1361 extern void ieee80211_check_all_nets(struct ieee80211_device *ieee);
1362 extern void ieee80211_start_protocol(struct ieee80211_device *ieee);
1363 extern void ieee80211_stop_protocol(struct ieee80211_device *ieee);
1364 extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
1365 extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
1366 extern void ieee80211_reset_queue(struct ieee80211_device *ieee);
1367 extern void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee);
1368 extern void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee);
1369 extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
1370 extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
1371 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
1372 extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p);
1373 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
1374 extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
1375 extern void SendDisassociation(struct ieee80211_device *ieee,u8* asSta,u8 asRsn);
1376 extern void ieee80211_rtl_start_scan(struct ieee80211_device *ieee);
1377
1378 //Add for RF power on power off by lizhaoming 080512
1379 extern void SendDisassociation(struct ieee80211_device *ieee,
1380                          u8*                     asSta,
1381                          u8                      asRsn);
1382
1383 /* ieee80211_crypt_ccmp&tkip&wep.c */
1384 extern void ieee80211_tkip_null(void);
1385 extern void ieee80211_wep_null(void);
1386 extern void ieee80211_ccmp_null(void);
1387 /* ieee80211_softmac_wx.c */
1388
1389 extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
1390                             struct iw_request_info *info,
1391                             union iwreq_data *wrqu, char *ext);
1392
1393 extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
1394                          struct iw_request_info *info,
1395                          union iwreq_data *awrq,
1396                          char *extra);
1397
1398 extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
1399
1400 extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
1401                              struct iw_request_info *info,
1402                              union iwreq_data *wrqu, char *extra);
1403
1404 extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
1405                              struct iw_request_info *info,
1406                              union iwreq_data *wrqu, char *extra);
1407
1408 extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1409                              union iwreq_data *wrqu, char *b);
1410
1411 extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
1412                              union iwreq_data *wrqu, char *b);
1413
1414 extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
1415                               struct iw_request_info *a,
1416                               union iwreq_data *wrqu, char *extra);
1417
1418 extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1419                              union iwreq_data *wrqu, char *b);
1420
1421 extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1422                              union iwreq_data *wrqu, char *b);
1423
1424 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1425                              union iwreq_data *wrqu, char *b);
1426
1427 extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
1428
1429 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
1430                                struct iw_request_info *info,
1431                                union iwreq_data *wrqu, char *extra);
1432
1433 extern int ieee80211_wx_get_name(struct ieee80211_device *ieee,
1434                              struct iw_request_info *info,
1435                              union iwreq_data *wrqu, char *extra);
1436
1437 extern int ieee80211_wx_set_power(struct ieee80211_device *ieee,
1438                                  struct iw_request_info *info,
1439                                  union iwreq_data *wrqu, char *extra);
1440
1441 extern int ieee80211_wx_get_power(struct ieee80211_device *ieee,
1442                                  struct iw_request_info *info,
1443                                  union iwreq_data *wrqu, char *extra);
1444
1445 extern void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee);
1446
1447 extern void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr);
1448
1449 extern const long ieee80211_wlan_frequencies[];
1450
1451 extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
1452 {
1453         ieee->scans++;
1454 }
1455
1456 extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
1457 {
1458         return ieee->scans;
1459 }
1460
1461 static inline const char *escape_essid(const char *essid, u8 essid_len) {
1462         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
1463         const char *s = essid;
1464         char *d = escaped;
1465
1466         if (ieee80211_is_empty_essid(essid, essid_len)) {
1467                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
1468                 return escaped;
1469         }
1470
1471         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
1472         while (essid_len--) {
1473                 if (*s == '\0') {
1474                         *d++ = '\\';
1475                         *d++ = '0';
1476                         s++;
1477                 } else {
1478                         *d++ = *s++;
1479                 }
1480         }
1481         *d = '\0';
1482         return escaped;
1483 }
1484 #endif /* IEEE80211_H */