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