159fddf628e20fce08f9e098d1253e29b56c5b56
[pandora-kernel.git] / drivers / staging / rtl8192su / 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/module.h>
30 #include <linux/jiffies.h>
31 #include <linux/timer.h>
32 #include <linux/sched.h>
33
34 #include <linux/delay.h>
35 #include <linux/wireless.h>
36 #include <linux/ieee80211.h>
37
38 #include "rtl819x_HT.h"
39 #include "rtl819x_BA.h"
40 #include "rtl819x_TS.h"
41
42 #define KEY_TYPE_NA             0x0
43 #define KEY_TYPE_WEP40          0x1
44 #define KEY_TYPE_TKIP           0x2
45 #define KEY_TYPE_CCMP           0x4
46 #define KEY_TYPE_WEP104         0x5
47
48 #define aSifsTime (((priv->ieee80211->current_network.mode == IEEE_A) || \
49                     (priv->ieee80211->current_network.mode == IEEE_N_24G) || \
50                     (priv->ieee80211->current_network.mode == IEEE_N_5G)) \
51                    ? 16 : 10)
52
53 #define MGMT_QUEUE_NUM 5
54
55 #define IEEE_CMD_SET_WPA_PARAM                  1
56 #define IEEE_CMD_SET_WPA_IE                     2
57 #define IEEE_CMD_SET_ENCRYPTION                 3
58 #define IEEE_CMD_MLME                           4
59
60 #define IEEE_PARAM_WPA_ENABLED                  1
61 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
62 #define IEEE_PARAM_DROP_UNENCRYPTED             3
63 #define IEEE_PARAM_PRIVACY_INVOKED              4
64 #define IEEE_PARAM_AUTH_ALGS                    5
65 #define IEEE_PARAM_IEEE_802_1X                  6
66 //It should consistent with the driver_XXX.c
67 //   David, 2006.9.26
68 #define IEEE_PARAM_WPAX_SELECT                  7
69 //Added for notify the encryption type selection
70 //   David, 2006.9.26
71 #define IEEE_PROTO_WPA                          1
72 #define IEEE_PROTO_RSN                          2
73 //Added for notify the encryption type selection
74 //   David, 2006.9.26
75 #define IEEE_WPAX_USEGROUP                      0
76 #define IEEE_WPAX_WEP40                         1
77 #define IEEE_WPAX_TKIP                          2
78 #define IEEE_WPAX_WRAP                          3
79 #define IEEE_WPAX_CCMP                          4
80 #define IEEE_WPAX_WEP104                        5
81
82 #define IEEE_KEY_MGMT_IEEE8021X                 1
83 #define IEEE_KEY_MGMT_PSK                       2
84
85 #define IEEE_MLME_STA_DEAUTH                    1
86 #define IEEE_MLME_STA_DISASSOC                  2
87
88
89 #define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
90 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
91 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED        4
92 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
93 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED        6
94 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
95
96
97 #define IEEE_CRYPT_ALG_NAME_LEN                 16
98
99 #define MAX_IE_LEN  0xff
100
101 typedef struct ieee_param {
102         u32 cmd;
103         u8 sta_addr[ETH_ALEN];
104         union {
105                 struct {
106                         u8 name;
107                         u32 value;
108                 } wpa_param;
109                 struct {
110                         u32 len;
111                         u8 reserved[32];
112                         u8 data[0];
113                 } wpa_ie;
114                 struct{
115                         int command;
116                         int reason_code;
117                 } mlme;
118                 struct {
119                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
120                         u8 set_tx;
121                         u32 err;
122                         u8 idx;
123                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
124                         u16 key_len;
125                         u8 key[0];
126                 } crypt;
127         } u;
128 }ieee_param;
129
130 #define MSECS(t) msecs_to_jiffies(t)
131 #define msleep_interruptible_rsl  msleep_interruptible
132
133 #define IEEE80211_DATA_LEN              2304
134 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
135    6.2.1.1.2.
136
137    The figure in section 7.1.2 suggests a body size of up to 2312
138    bytes is allowed, which is a bit confusing, I suspect this
139    represents the 2304 bytes of real data, plus a possible 8 bytes of
140    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
141 #define IEEE80211_1ADDR_LEN 10
142 #define IEEE80211_2ADDR_LEN 16
143 #define IEEE80211_3ADDR_LEN 24
144 #define IEEE80211_4ADDR_LEN 30
145 #define IEEE80211_FCS_LEN    4
146 #define IEEE80211_HLEN                  IEEE80211_4ADDR_LEN
147 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
148 #define IEEE80211_MGMT_HDR_LEN 24
149 #define IEEE80211_DATA_HDR3_LEN 24
150 #define IEEE80211_DATA_HDR4_LEN 30
151
152 #define MIN_FRAG_THRESHOLD     256U
153 #define MAX_FRAG_THRESHOLD     2346U
154
155
156 /* Frame control field constants */
157 #define IEEE80211_FCTL_FRAMETYPE        0x00fc
158 #define IEEE80211_FCTL_DSTODS           0x0300 //added by david
159 #define IEEE80211_FCTL_WEP              0x4000
160
161 /* management */
162 #define IEEE80211_STYPE_MANAGE_ACT      0x00D0
163
164 /* control */
165 #define IEEE80211_STYPE_BLOCKACK   0x0094
166
167 /* QOS control */
168 #define IEEE80211_QCTL_TID              0x000F
169
170 /* debug macros */
171 #define CONFIG_IEEE80211_DEBUG
172 #ifdef CONFIG_IEEE80211_DEBUG
173 extern u32 ieee80211_debug_level;
174 #define IEEE80211_DEBUG(level, fmt, args...) \
175         do { \
176                 if (ieee80211_debug_level & (level)) \
177                         printk(KERN_DEBUG "ieee80211: " fmt, ## args); \
178         } while (0)
179 #define IEEE80211_DEBUG_DATA(level, data, datalen) \
180         do { \
181                 if ((ieee80211_debug_level & (level)) == (level)) { \
182                         u8 *pdata = (u8 *)data; \
183                         int i; \
184                         printk(KERN_DEBUG "ieee80211: %s()\n", __func__); \
185                         for (i = 0; i < (int)(datalen); i++) { \
186                                 printk("%2x ", pdata[i]); \
187                                 if ((i + 1) % 16 == 0) \
188                                         printk("\n"); \
189                         } \
190                         printk("\n"); \
191                 } \
192         } while (0)
193 #else
194 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
195 #define IEEE80211_DEBUG_DATA(level, data, datalen) do {} while(0)
196 #endif  /* CONFIG_IEEE80211_DEBUG */
197
198 /*
199  * To use the debug system;
200  *
201  * If you are defining a new debug classification, simply add it to the #define
202  * list here in the form of:
203  *
204  * #define IEEE80211_DL_xxxx VALUE
205  *
206  * shifting value to the left one bit from the previous entry.  xxxx should be
207  * the name of the classification (for example, WEP)
208  *
209  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
210  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
211  * to send output to that classification.
212  *
213  * To add your debug level to the list of levels seen when you perform
214  *
215  * % cat /proc/net/ipw/debug_level
216  *
217  * you simply need to add your entry to the ipw_debug_levels array.
218  *
219  * If you do not see debug_level in /proc/net/ipw then you do not have
220  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
221  *
222  */
223
224 #define IEEE80211_DL_INFO          (1<<0)
225 #define IEEE80211_DL_WX            (1<<1)
226 #define IEEE80211_DL_SCAN          (1<<2)
227 #define IEEE80211_DL_STATE         (1<<3)
228 #define IEEE80211_DL_MGMT          (1<<4)
229 #define IEEE80211_DL_FRAG          (1<<5)
230 #define IEEE80211_DL_EAP           (1<<6)
231 #define IEEE80211_DL_DROP          (1<<7)
232
233 #define IEEE80211_DL_TX            (1<<8)
234 #define IEEE80211_DL_RX            (1<<9)
235
236 #define IEEE80211_DL_HT            (1 << 10)
237 #define IEEE80211_DL_BA            (1 << 11)
238 #define IEEE80211_DL_TS            (1 << 12)
239 #define IEEE80211_DL_QOS           (1 << 13)
240 #define IEEE80211_DL_REORDER       (1 << 14)
241 #define IEEE80211_DL_IOT           (1 << 15)
242 #define IEEE80211_DL_IPS           (1 << 16)
243 #define IEEE80211_DL_TRACE         (1 << 29)
244 #define IEEE80211_DL_DATA          (1 << 30)
245 #define IEEE80211_DL_ERR           (1 << 31)
246
247 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
248 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
249 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
250
251 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
252 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
253 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
254 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
255 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
256 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
257 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
258 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
259 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
260 #define IEEE80211_DEBUG_QOS(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_QOS, f, ## a)
261
262 #include <linux/netdevice.h>
263 #include <linux/if_arp.h> /* ARPHRD_ETHER */
264
265 #ifndef WIRELESS_SPY
266 #define WIRELESS_SPY            // enable iwspy support
267 #endif
268 #include <net/iw_handler.h>     // new driver API
269
270 #ifndef ETH_P_PAE
271 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
272 #endif /* ETH_P_PAE */
273
274 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
275
276 #ifndef ETH_P_80211_RAW
277 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
278 #endif
279
280 /* IEEE 802.11 defines */
281
282 #define P80211_OUI_LEN 3
283
284 struct ieee80211_snap_hdr {
285
286         u8    dsap;   /* always 0xAA */
287         u8    ssap;   /* always 0xAA */
288         u8    ctrl;   /* always 0x03 */
289         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
290
291 } __attribute__ ((packed));
292
293 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
294
295 #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
296 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
297 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
298
299 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & IEEE80211_FCTL_FRAMETYPE)
300 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
301 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & IEEE80211_SCTL_SEQ) >> 4)
302
303 #define RTL_WLAN_AUTH_LEAP 2
304
305 #define WLAN_CAPABILITY_BSS (1<<0)
306 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
307
308 #define IEEE80211_STATMASK_SIGNAL (1<<0)
309 #define IEEE80211_STATMASK_RSSI (1<<1)
310 #define IEEE80211_STATMASK_NOISE (1<<2)
311 #define IEEE80211_STATMASK_RATE (1<<3)
312 #define IEEE80211_STATMASK_WEMASK 0x7
313
314 #define IEEE80211_CCK_MODULATION    (1<<0)
315 #define IEEE80211_OFDM_MODULATION   (1<<1)
316
317 #define IEEE80211_24GHZ_BAND     (1<<0)
318 #define IEEE80211_52GHZ_BAND     (1<<1)
319
320 #define IEEE80211_CCK_RATE_LEN                  4
321 #define IEEE80211_CCK_RATE_1MB                  0x02
322 #define IEEE80211_CCK_RATE_2MB                  0x04
323 #define IEEE80211_CCK_RATE_5MB                  0x0B
324 #define IEEE80211_CCK_RATE_11MB                 0x16
325 #define IEEE80211_OFDM_RATE_LEN                 8
326 #define IEEE80211_OFDM_RATE_6MB                 0x0C
327 #define IEEE80211_OFDM_RATE_9MB                 0x12
328 #define IEEE80211_OFDM_RATE_12MB                0x18
329 #define IEEE80211_OFDM_RATE_18MB                0x24
330 #define IEEE80211_OFDM_RATE_24MB                0x30
331 #define IEEE80211_OFDM_RATE_36MB                0x48
332 #define IEEE80211_OFDM_RATE_48MB                0x60
333 #define IEEE80211_OFDM_RATE_54MB                0x6C
334 #define IEEE80211_BASIC_RATE_MASK               0x80
335
336 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
337 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
338 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
339 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
340 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
341 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
342 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
343 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
344 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
345 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
346 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
347 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
348
349 #define IEEE80211_CCK_RATES_MASK                0x0000000F
350 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
351         IEEE80211_CCK_RATE_2MB_MASK)
352 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
353         IEEE80211_CCK_RATE_5MB_MASK | \
354         IEEE80211_CCK_RATE_11MB_MASK)
355
356 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
357 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
358         IEEE80211_OFDM_RATE_12MB_MASK | \
359         IEEE80211_OFDM_RATE_24MB_MASK)
360 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
361         IEEE80211_OFDM_RATE_9MB_MASK  | \
362         IEEE80211_OFDM_RATE_18MB_MASK | \
363         IEEE80211_OFDM_RATE_36MB_MASK | \
364         IEEE80211_OFDM_RATE_48MB_MASK | \
365         IEEE80211_OFDM_RATE_54MB_MASK)
366 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
367                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
368
369 #define IEEE80211_NUM_OFDM_RATES            8
370 #define IEEE80211_NUM_CCK_RATES             4
371 #define IEEE80211_OFDM_SHIFT_MASK_A         4
372
373
374 /* this is stolen and modified from the madwifi driver*/
375 #define IEEE80211_FC0_TYPE_MASK         0x0c
376 #define IEEE80211_FC0_TYPE_DATA         0x08
377 #define IEEE80211_FC0_SUBTYPE_MASK      0xB0
378 #define IEEE80211_FC0_SUBTYPE_QOS       0x80
379
380 #define IEEE80211_QOS_HAS_SEQ(fc) \
381         (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
382          (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
383
384 /* this is stolen from ipw2200 driver */
385 #define IEEE_IBSS_MAC_HASH_SIZE 31
386 struct ieee_ibss_seq {
387         u8 mac[ETH_ALEN];
388         u16 seq_num[17];
389         u16 frag_num[17];
390         unsigned long packet_time[17];
391         struct list_head list;
392 };
393
394 /* NOTE: This data is for statistical purposes; not all hardware provides this
395  *       information for frames received.  Not setting these will not cause
396  *       any adverse affects. */
397 struct ieee80211_rx_stats {
398         u32 mac_time[2];
399         s8 rssi;
400         u8 signal;
401         u8 noise;
402         u16 rate; /* in 100 kbps */
403         u8 received_channel;
404         u8 control;
405         u8 mask;
406         u8 freq;
407         u16 len;
408         u64 tsf;
409         u32 beacon_time;
410         u8 nic_type;
411
412         u16       Length;
413         u8        SignalQuality;        /* in 0-100 index */
414         /* real power in dBm for this packet, no beautification & aggregation */
415         s32       RecvSignalPower;
416         s8        RxPower;              /* in dBm Translate from PWdB */
417         u8        SignalStrength;       /* in 0-100 index */
418         u16       bHwError:1;
419         u16       bCRC:1;
420         u16       bICV:1;
421         u16       bShortPreamble:1;
422         u16       Antenna:1;            /* RTL8185 */
423         u16       Decrypted:1;          /* RTL8185, RTL8187 */
424         u16       Wakeup:1;             /* RTL8185 */
425         u16       Reserved0:1;          /* RTL8185 */
426         u8        AGC;
427         u32       TimeStampLow;
428         u32       TimeStampHigh;
429         bool      bShift;
430         bool      bIsQosData;
431         u8        UserPriority;
432
433         /* < 11n or 8190 specific code */
434         u8        RxDrvInfoSize;
435         u8        RxBufShift;
436         bool      bIsAMPDU;
437         bool      bFirstMPDU;
438         bool      bContainHTC;
439         bool      RxIs40MHzPacket;
440         u32       RxPWDBAll;
441         u8        RxMIMOSignalStrength[4]; /* in 0~100 index */
442         s8        RxMIMOSignalQuality[2];
443         bool      bPacketMatchBSSID;
444         bool      bIsCCK;
445         bool      bPacketToSelf;
446
447         u8        *virtual_address;
448         /* total packet length: must equal to sum of all FragLength */
449         u16       packetlength;
450         /* FragLength should equal to PacketLength in non-fragment case */
451         u16       fraglength;
452         u16       fragoffset;           /* data offset for this fragment */
453         u16       ntotalfrag;
454         bool      bisrxaggrsubframe;
455         bool      bPacketBeacon;        /* for rssi */
456         bool      bToSelfBA;            /* for rssi */
457         char      cck_adc_pwdb[4];      /* for rx path selection */
458         u16       Seq_Num;
459         u8        nTotalAggPkt;         /* number of aggregated packets */
460 };
461
462 /* IEEE 802.11 requires that STA supports concurrent reception of at least
463  * three fragmented frames. This define can be increased to support more
464  * concurrent frames, but it should be noted that each entry can consume about
465  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
466 #define IEEE80211_FRAG_CACHE_LEN 4
467
468 struct ieee80211_frag_entry {
469         unsigned long first_frag_time;
470         unsigned int seq;
471         unsigned int last_frag;
472         struct sk_buff *skb;
473         u8 src_addr[ETH_ALEN];
474         u8 dst_addr[ETH_ALEN];
475 };
476
477 struct ieee80211_stats {
478         unsigned int tx_unicast_frames;
479         unsigned int tx_multicast_frames;
480         unsigned int tx_fragments;
481         unsigned int tx_unicast_octets;
482         unsigned int tx_multicast_octets;
483         unsigned int tx_deferred_transmissions;
484         unsigned int tx_single_retry_frames;
485         unsigned int tx_multiple_retry_frames;
486         unsigned int tx_retry_limit_exceeded;
487         unsigned int tx_discards;
488         unsigned int rx_unicast_frames;
489         unsigned int rx_multicast_frames;
490         unsigned int rx_fragments;
491         unsigned int rx_unicast_octets;
492         unsigned int rx_multicast_octets;
493         unsigned int rx_fcs_errors;
494         unsigned int rx_discards_no_buffer;
495         unsigned int tx_discards_wrong_sa;
496         unsigned int rx_discards_undecryptable;
497         unsigned int rx_message_in_msg_fragments;
498         unsigned int rx_message_in_bad_msg_fragments;
499 };
500
501 struct ieee80211_device;
502
503 #include "ieee80211_crypt.h"
504
505 #define SEC_KEY_1         (1<<0)
506 #define SEC_KEY_2         (1<<1)
507 #define SEC_KEY_3         (1<<2)
508 #define SEC_KEY_4         (1<<3)
509 #define SEC_ACTIVE_KEY    (1<<4)
510 #define SEC_AUTH_MODE     (1<<5)
511 #define SEC_UNICAST_GROUP (1<<6)
512 #define SEC_LEVEL         (1<<7)
513 #define SEC_ENABLED       (1<<8)
514
515 #define SEC_LEVEL_0      0 /* None */
516 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
517 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
518 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
519 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
520
521 #define WEP_KEYS                4
522 #define WEP_KEY_LEN             13
523 #define SCM_KEY_LEN             32
524
525 struct ieee80211_security {
526         u16 active_key:2,
527             enabled:1,
528             auth_mode:2,
529             auth_algo:4,
530             unicast_uses_group:1,
531             encrypt:1;
532         u8 key_sizes[WEP_KEYS];
533         u8 keys[WEP_KEYS][SCM_KEY_LEN];
534         u8 level;
535         u16 flags;
536 } __attribute__ ((packed));
537
538
539 /*
540  802.11 data frame from AP
541       ,-------------------------------------------------------------------.
542 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
543       |------|------|---------|---------|---------|------|---------|------|
544 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
545       |      | tion | (BSSID) |         |         | ence |  data   |      |
546       `-------------------------------------------------------------------'
547 Total: 28-2340 bytes
548 */
549
550 /* Management Frame Information Element Types */
551 enum {
552         MFIE_TYPE_SSID = 0,
553         MFIE_TYPE_RATES = 1,
554         MFIE_TYPE_FH_SET = 2,
555         MFIE_TYPE_DS_SET = 3,
556         MFIE_TYPE_CF_SET = 4,
557         MFIE_TYPE_TIM = 5,
558         MFIE_TYPE_IBSS_SET = 6,
559         MFIE_TYPE_COUNTRY = 7,
560         MFIE_TYPE_HOP_PARAMS = 8,
561         MFIE_TYPE_HOP_TABLE = 9,
562         MFIE_TYPE_REQUEST = 10,
563         MFIE_TYPE_CHALLENGE = 16,
564         MFIE_TYPE_POWER_CONSTRAINT = 32,
565         MFIE_TYPE_POWER_CAPABILITY = 33,
566         MFIE_TYPE_TPC_REQUEST = 34,
567         MFIE_TYPE_TPC_REPORT = 35,
568         MFIE_TYPE_SUPP_CHANNELS = 36,
569         MFIE_TYPE_CSA = 37,
570         MFIE_TYPE_MEASURE_REQUEST = 38,
571         MFIE_TYPE_MEASURE_REPORT = 39,
572         MFIE_TYPE_QUIET = 40,
573         MFIE_TYPE_IBSS_DFS = 41,
574         MFIE_TYPE_ERP = 42,
575         MFIE_TYPE_RSN = 48,
576         MFIE_TYPE_RATES_EX = 50,
577         MFIE_TYPE_HT_CAP= 45,
578          MFIE_TYPE_HT_INFO= 61,
579          MFIE_TYPE_AIRONET=133,
580         MFIE_TYPE_GENERIC = 221,
581         MFIE_TYPE_QOS_PARAMETER = 222,
582 };
583
584 /* Minimal header; can be used for passing 802.11 frames with sufficient
585  * information to determine what type of underlying data type is actually
586  * stored in the data. */
587 struct rtl_ieee80211_hdr {
588         __le16 frame_ctl;
589         __le16 duration_id;
590         u8 payload[0];
591 } __attribute__ ((packed));
592
593 struct ieee80211_hdr_1addr {
594         __le16 frame_ctl;
595         __le16 duration_id;
596         u8 addr1[ETH_ALEN];
597         u8 payload[0];
598 } __attribute__ ((packed));
599
600 struct ieee80211_hdr_2addr {
601         __le16 frame_ctl;
602         __le16 duration_id;
603         u8 addr1[ETH_ALEN];
604         u8 addr2[ETH_ALEN];
605         u8 payload[0];
606 } __attribute__ ((packed));
607
608 struct ieee80211_hdr_3addr {
609         __le16 frame_ctl;
610         __le16 duration_id;
611         u8 addr1[ETH_ALEN];
612         u8 addr2[ETH_ALEN];
613         u8 addr3[ETH_ALEN];
614         __le16 seq_ctl;
615         u8 payload[0];
616 } __attribute__ ((packed));
617
618 struct ieee80211_hdr_4addr {
619         __le16 frame_ctl;
620         __le16 duration_id;
621         u8 addr1[ETH_ALEN];
622         u8 addr2[ETH_ALEN];
623         u8 addr3[ETH_ALEN];
624         __le16 seq_ctl;
625         u8 addr4[ETH_ALEN];
626         u8 payload[0];
627 } __attribute__ ((packed));
628
629 struct ieee80211_hdr_3addrqos {
630         __le16 frame_ctl;
631         __le16 duration_id;
632         u8 addr1[ETH_ALEN];
633         u8 addr2[ETH_ALEN];
634         u8 addr3[ETH_ALEN];
635         __le16 seq_ctl;
636         u8 payload[0];
637         __le16 qos_ctl;
638 } __attribute__ ((packed));
639
640 struct ieee80211_hdr_4addrqos {
641         __le16 frame_ctl;
642         __le16 duration_id;
643         u8 addr1[ETH_ALEN];
644         u8 addr2[ETH_ALEN];
645         u8 addr3[ETH_ALEN];
646         __le16 seq_ctl;
647         u8 addr4[ETH_ALEN];
648         u8 payload[0];
649         __le16 qos_ctl;
650 } __attribute__ ((packed));
651
652 struct ieee80211_info_element {
653         u8 id;
654         u8 len;
655         u8 data[0];
656 } __attribute__ ((packed));
657
658 struct ieee80211_authentication {
659         struct ieee80211_hdr_3addr header;
660         __le16 algorithm;
661         __le16 transaction;
662         __le16 status;
663         /* challenge */
664         struct ieee80211_info_element info_element[0];
665 } __attribute__ ((packed));
666
667 struct ieee80211_disassoc {
668         struct ieee80211_hdr_3addr header;
669         __le16 reason;
670 } __attribute__ ((packed));
671
672 struct ieee80211_probe_request {
673         struct ieee80211_hdr_3addr header;
674         /* SSID, supported rates */
675         struct ieee80211_info_element info_element[0];
676 } __attribute__ ((packed));
677
678 struct ieee80211_probe_response {
679         struct ieee80211_hdr_3addr header;
680         u32 time_stamp[2];
681         __le16 beacon_interval;
682         __le16 capability;
683         /* SSID, supported rates, FH params, DS params,
684          * CF params, IBSS params, TIM (if beacon), RSN */
685         struct ieee80211_info_element info_element[0];
686 } __attribute__ ((packed));
687
688 struct ieee80211_assoc_request_frame {
689         struct ieee80211_hdr_3addr header;
690         __le16 capability;
691         __le16 listen_interval;
692         /* SSID, supported rates, RSN */
693         struct ieee80211_info_element info_element[0];
694 } __attribute__ ((packed));
695
696 struct ieee80211_reassoc_request_frame {
697         struct ieee80211_hdr_3addr header;
698         __le16 capability;
699         __le16 listen_interval;
700         u8 current_ap[ETH_ALEN];
701         /* SSID, supported rates, RSN */
702         struct ieee80211_info_element info_element[0];
703 } __attribute__ ((packed));
704
705 struct ieee80211_assoc_response_frame {
706         struct ieee80211_hdr_3addr header;
707         __le16 capability;
708         __le16 status;
709         __le16 aid;
710         struct ieee80211_info_element info_element[0]; /* supported rates */
711 } __attribute__ ((packed));
712
713 struct ieee80211_txb {
714         u8 nr_frags;
715         u8 encrypted;
716         u8 queue_index;
717         u8 rts_included;
718         u16 reserved;
719         __le16 frag_size;
720         __le16 payload_size;
721         struct sk_buff *fragments[0];
722 };
723
724 #define MAX_SUBFRAME_COUNT                64
725 struct ieee80211_rxb {
726         u8 nr_subframes;
727         struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
728         u8 dst[ETH_ALEN];
729         u8 src[ETH_ALEN];
730 }__attribute__((packed));
731
732 /* SWEEP TABLE ENTRIES NUMBER */
733 #define MAX_SWEEP_TAB_ENTRIES             42
734 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
735 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
736  * only use 8, and then use extended rates for the remaining supported
737  * rates.  Other APs, however, stick all of their supported rates on the
738  * main rates information element... */
739 #define MAX_RATES_LENGTH                  ((u8)12)
740 #define MAX_RATES_EX_LENGTH               ((u8)16)
741 #define MAX_NETWORK_COUNT                  128
742
743 #define MAX_CHANNEL_NUMBER                 161
744
745 #define IEEE80211_SOFTMAC_SCAN_TIME        100 /* (HZ / 2) */
746 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
747
748 #define CRC_LENGTH                 4U
749
750 #define MAX_WPA_IE_LEN 64
751
752 #define NETWORK_EMPTY_ESSID     (1 << 0)
753 #define NETWORK_HAS_OFDM        (1 << 1)
754 #define NETWORK_HAS_CCK         (1 << 2)
755
756 /* QoS structure */
757 #define NETWORK_HAS_QOS_PARAMETERS      (1 << 3)
758 #define NETWORK_HAS_QOS_INFORMATION     (1 << 4)
759 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
760                                          NETWORK_HAS_QOS_INFORMATION)
761
762 #define NETWORK_HAS_ERP_VALUE           (1 << 10)
763
764 #define QOS_QUEUE_NUM                   4
765 #define QOS_OUI_LEN                     3
766 #define QOS_OUI_TYPE                    2
767 #define QOS_ELEMENT_ID                  221
768 #define QOS_OUI_INFO_SUB_TYPE           0
769 #define QOS_OUI_PARAM_SUB_TYPE          1
770 #define QOS_VERSION_1                   1
771 #define QOS_AIFSN_MIN_VALUE             2
772
773 struct ieee80211_qos_information_element {
774         u8 elementID;
775         u8 length;
776         u8 qui[QOS_OUI_LEN];
777         u8 qui_type;
778         u8 qui_subtype;
779         u8 version;
780         u8 ac_info;
781 } __attribute__ ((packed));
782
783 struct ieee80211_qos_ac_parameter {
784         u8 aci_aifsn;
785         u8 ecw_min_max;
786         __le16 tx_op_limit;
787 } __attribute__ ((packed));
788
789 struct ieee80211_qos_parameter_info {
790         struct ieee80211_qos_information_element info_element;
791         u8 reserved;
792         struct ieee80211_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
793 } __attribute__ ((packed));
794
795 struct ieee80211_qos_parameters {
796         __le16 cw_min[QOS_QUEUE_NUM];
797         __le16 cw_max[QOS_QUEUE_NUM];
798         u8 aifs[QOS_QUEUE_NUM];
799         u8 flag[QOS_QUEUE_NUM];
800         __le16 tx_op_limit[QOS_QUEUE_NUM];
801 } __attribute__ ((packed));
802
803 struct ieee80211_qos_data {
804         struct ieee80211_qos_parameters parameters;
805         int active;
806         int supported;
807         u8 param_count;
808         u8 old_param_count;
809 };
810
811 struct ieee80211_tim_parameters {
812         u8 tim_count;
813         u8 tim_period;
814 } __attribute__ ((packed));
815
816 struct ieee80211_wmm_ac_param {
817         u8 ac_aci_acm_aifsn;
818         u8 ac_ecwmin_ecwmax;
819         u16 ac_txop_limit;
820 };
821
822 struct ieee80211_wmm_ts_info {
823         u8 ac_dir_tid;
824         u8 ac_up_psb;
825         u8 reserved;
826 } __attribute__ ((packed));
827
828 struct ieee80211_wmm_tspec_elem {
829         struct ieee80211_wmm_ts_info ts_info;
830         u16 norm_msdu_size;
831         u16 max_msdu_size;
832         u32 min_serv_inter;
833         u32 max_serv_inter;
834         u32 inact_inter;
835         u32 suspen_inter;
836         u32 serv_start_time;
837         u32 min_data_rate;
838         u32 mean_data_rate;
839         u32 peak_data_rate;
840         u32 max_burst_size;
841         u32 delay_bound;
842         u32 min_phy_rate;
843         u16 surp_band_allow;
844         u16 medium_time;
845 }__attribute__((packed));
846
847 enum eap_type {
848         EAP_PACKET = 0,
849         EAPOL_START,
850         EAPOL_LOGOFF,
851         EAPOL_KEY,
852         EAPOL_ENCAP_ASF_ALERT
853 };
854
855 static const char *eap_types[] = {
856         [EAP_PACKET]            = "EAP-Packet",
857         [EAPOL_START]           = "EAPOL-Start",
858         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
859         [EAPOL_KEY]             = "EAPOL-Key",
860         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
861 };
862
863 static inline const char *eap_get_type(int type)
864 {
865         return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
866 }
867
868 struct eapol {
869         u8 snap[6];
870         u16 ethertype;
871         u8 version;
872         u8 type;
873         u16 length;
874 } __attribute__ ((packed));
875
876 struct ieee80211_softmac_stats {
877         unsigned int rx_ass_ok;
878         unsigned int rx_ass_err;
879         unsigned int rx_probe_rq;
880         unsigned int tx_probe_rs;
881         unsigned int tx_beacons;
882         unsigned int rx_auth_rq;
883         unsigned int rx_auth_rs_ok;
884         unsigned int rx_auth_rs_err;
885         unsigned int tx_auth_rq;
886         unsigned int no_auth_rs;
887         unsigned int no_ass_rs;
888         unsigned int tx_ass_rq;
889         unsigned int rx_ass_rq;
890         unsigned int tx_probe_rq;
891         unsigned int reassoc;
892         unsigned int swtxstop;
893         unsigned int swtxawake;
894         unsigned char CurrentShowTxate;
895         unsigned char last_packet_rate;
896         unsigned int txretrycount;
897 };
898
899 #define BEACON_PROBE_SSID_ID_POSITION 12
900
901 struct ieee80211_info_element_hdr {
902         u8 id;
903         u8 len;
904 } __attribute__ ((packed));
905
906 /*
907  * These are the data types that can make up management packets
908  *
909         u16 auth_algorithm;
910         u16 auth_sequence;
911         u16 beacon_interval;
912         u16 capability;
913         u8 current_ap[ETH_ALEN];
914         u16 listen_interval;
915         struct {
916                 u16 association_id:14, reserved:2;
917         } __attribute__ ((packed));
918         u32 time_stamp[2];
919         u16 reason;
920         u16 status;
921 */
922
923 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
924 #define IEEE80211_DEFAULT_BASIC_RATE 2 /* 1Mbps */
925
926 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
927 #define MAX_SP_Len  (WMM_all_frame << 4)
928 #define IEEE80211_QOS_TID 0x0f
929 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
930
931 #define IEEE80211_DTIM_MBCAST 4
932 #define IEEE80211_DTIM_UCAST 2
933 #define IEEE80211_DTIM_VALID 1
934 #define IEEE80211_DTIM_INVALID 0
935
936 #define IEEE80211_PS_DISABLED 0
937 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
938 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
939
940 //added by David for QoS 2006/6/30
941 //#define WMM_Hang_8187
942 #ifdef WMM_Hang_8187
943 #undef WMM_Hang_8187
944 #endif
945
946 #define WME_AC_BK   0x00
947 #define WME_AC_BE   0x01
948 #define WME_AC_VI   0x02
949 #define WME_AC_VO   0x03
950 #define WME_ACI_MASK 0x03
951 #define WME_AIFSN_MASK 0x03
952 #define WME_AC_PRAM_LEN 16
953
954 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
955 //#define UP2AC(up)     ((up<3) ? ((up==0)?1:0) : (up>>1))
956 #define UP2AC(up) (                \
957         ((up) < 1) ? WME_AC_BE : \
958         ((up) < 3) ? WME_AC_BK : \
959         ((up) < 4) ? WME_AC_BE : \
960         ((up) < 6) ? WME_AC_VI : \
961         WME_AC_VO)
962
963 //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
964 #define AC2UP(_ac)      (       \
965         ((_ac) == WME_AC_VO) ? 6 : \
966         ((_ac) == WME_AC_VI) ? 5 : \
967         ((_ac) == WME_AC_BK) ? 1 : \
968         0)
969
970 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
971
972 /* length of two Ethernet address plus ether type */
973 #define ETHERNET_HEADER_SIZE    14
974
975 struct  ether_header {
976         u8 ether_dhost[ETHER_ADDR_LEN];
977         u8 ether_shost[ETHER_ADDR_LEN];
978         u16 ether_type;
979 } __attribute__((packed));
980
981 #ifndef ETHERTYPE_PAE
982 #define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
983 #endif
984 #ifndef ETHERTYPE_IP
985 #define ETHERTYPE_IP    0x0800          /* IP protocol */
986 #endif
987
988 struct ieee80211_network {
989         /* These entries are used to identify a unique network */
990         u8 bssid[ETH_ALEN];
991         u8 channel;
992         /* Ensure null-terminated for any debug msgs */
993         u8 ssid[IW_ESSID_MAX_SIZE + 1];
994         u8 ssid_len;
995
996         struct ieee80211_qos_data qos_data;
997
998         /* for LEAP */
999         bool    bWithAironetIE;
1000         bool    bCkipSupported;
1001         bool    bCcxRmEnable;
1002         u16     CcxRmState[2];
1003
1004         /* CCXv4 S59, MBSSID. */
1005         bool    bMBssidValid;
1006         u8      MBssidMask;
1007         u8      MBssid[6];
1008
1009         /* CCX 2 S38, WLAN Device Version Number element. */
1010         bool    bWithCcxVerNum;
1011         u8      BssCcxVerNumber;
1012
1013         /* These are network statistics */
1014         struct ieee80211_rx_stats stats;
1015         u16 capability;
1016         u8  rates[MAX_RATES_LENGTH];
1017         u8  rates_len;
1018         u8  rates_ex[MAX_RATES_EX_LENGTH];
1019         u8  rates_ex_len;
1020         unsigned long last_scanned;
1021         u8  mode;
1022         u32 flags;
1023         u32 last_associate;
1024         u32 time_stamp[2];
1025         u16 beacon_interval;
1026         u16 listen_interval;
1027         u16 atim_window;
1028         u8  erp_value;
1029         u8  wpa_ie[MAX_WPA_IE_LEN];
1030         size_t wpa_ie_len;
1031         u8  rsn_ie[MAX_WPA_IE_LEN];
1032         size_t rsn_ie_len;
1033
1034         struct ieee80211_tim_parameters tim;
1035         u8  dtim_period;
1036         u8  dtim_data;
1037         u32 last_dtim_sta_time[2];
1038
1039         //appeded for QoS
1040         u8 wmm_info;
1041         struct ieee80211_wmm_ac_param wmm_param[4];
1042         u8 QoS_Enable;
1043         u8 Turbo_Enable;//enable turbo mode, added by thomas
1044         u16 CountryIeLen;
1045         u8 CountryIeBuf[MAX_IE_LEN];
1046
1047         /* HT Related */
1048         BSS_HT  bssht;
1049         /* Added to handle broadcom AP management frame CCK rate. */
1050         bool broadcom_cap_exist;
1051         bool realtek_cap_exit;
1052         bool marvell_cap_exist;
1053         bool ralink_cap_exist;
1054         bool atheros_cap_exist;
1055         bool cisco_cap_exist;
1056         bool unknown_cap_exist;
1057         bool berp_info_valid;
1058         bool buseprotection;
1059
1060         struct list_head list;  /* put at the end of the structure */
1061 };
1062
1063 enum ieee80211_state {
1064
1065         /* the card is not linked at all */
1066         IEEE80211_NOLINK = 0,
1067
1068         /* IEEE80211_ASSOCIATING* are for BSS client mode
1069          * the driver shall not perform RX filtering unless
1070          * the state is LINKED.
1071          * The driver shall just check for the state LINKED and
1072          * defaults to NOLINK for ALL the other states (including
1073          * LINKED_SCANNING)
1074          */
1075
1076         /* the association procedure will start (wq scheduling)*/
1077         IEEE80211_ASSOCIATING,
1078         IEEE80211_ASSOCIATING_RETRY,
1079
1080         /* the association procedure is sending AUTH request*/
1081         IEEE80211_ASSOCIATING_AUTHENTICATING,
1082
1083         /* the association procedure has successfully authentcated
1084          * and is sending association request
1085          */
1086         IEEE80211_ASSOCIATING_AUTHENTICATED,
1087
1088         /* the link is ok. the card associated to a BSS or linked
1089          * to a ibss cell or acting as an AP and creating the bss
1090          */
1091         IEEE80211_LINKED,
1092
1093         /* same as LINKED, but the driver shall apply RX filter
1094          * rules as we are in NO_LINK mode. As the card is still
1095          * logically linked, but it is doing a syncro site survey
1096          * then it will be back to LINKED state.
1097          */
1098         IEEE80211_LINKED_SCANNING,
1099
1100 };
1101
1102 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1103 #define DEFAULT_FTS 2346
1104
1105 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
1106 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
1107
1108 #define IEEE80211_24GHZ_MIN_CHANNEL 1
1109 #define IEEE80211_24GHZ_MAX_CHANNEL 14
1110 #define IEEE80211_24GHZ_CHANNELS (IEEE80211_24GHZ_MAX_CHANNEL - \
1111                                   IEEE80211_24GHZ_MIN_CHANNEL + 1)
1112
1113 #define IEEE80211_52GHZ_MIN_CHANNEL 34
1114 #define IEEE80211_52GHZ_MAX_CHANNEL 165
1115 #define IEEE80211_52GHZ_CHANNELS (IEEE80211_52GHZ_MAX_CHANNEL - \
1116                                   IEEE80211_52GHZ_MIN_CHANNEL + 1)
1117
1118 typedef struct tx_pending_t{
1119         int frag;
1120         struct ieee80211_txb *txb;
1121 }tx_pending_t;
1122
1123 enum {
1124         COUNTRY_CODE_FCC = 0,
1125         COUNTRY_CODE_IC = 1,
1126         COUNTRY_CODE_ETSI = 2,
1127         COUNTRY_CODE_SPAIN = 3,
1128         COUNTRY_CODE_FRANCE = 4,
1129         COUNTRY_CODE_MKK = 5,
1130         COUNTRY_CODE_MKK1 = 6,
1131         COUNTRY_CODE_ISRAEL = 7,
1132         COUNTRY_CODE_TELEC,
1133         COUNTRY_CODE_MIC,
1134         COUNTRY_CODE_GLOBAL_DOMAIN
1135 };
1136
1137 #include "ieee80211_r8192s.h"
1138
1139 struct ieee80211_device {
1140         struct net_device *dev;
1141         struct ieee80211_security sec;
1142
1143         /* hw security related */
1144         u8 hwsec_active;
1145         bool is_silent_reset;
1146         bool is_roaming;
1147         bool ieee_up;
1148         bool bSupportRemoteWakeUp;
1149         RT_PS_MODE dot11PowerSaveMode;
1150         bool actscanning;
1151         bool be_scan_inprogress;
1152         bool beinretry;
1153         RT_RF_POWER_STATE eRFPowerState;
1154         u32 RfOffReason;
1155         bool is_set_key;
1156
1157         /* 11n HT below */
1158         PRT_HIGH_THROUGHPUT pHTInfo;
1159         spinlock_t bw_spinlock;
1160
1161         spinlock_t reorder_spinlock;
1162         /*
1163          * for HT operation rate set, we use this one for HT data rate to
1164          * seperate different descriptors the way fill this is the same as
1165          * in the IE
1166          */
1167         u8      Regdot11HTOperationalRateSet[16];       /* use RATR format */
1168         u8      dot11HTOperationalRateSet[16];          /* use RATR format */
1169         u8      RegHTSuppRateSet[16];
1170         u8      HTCurrentOperaRate;
1171         u8      HTHighestOperaRate;
1172         /* for rate operation mode to firmware */
1173         u8      bTxDisableRateFallBack;
1174         u8      bTxUseDriverAssingedRate;
1175         atomic_t        atm_chnlop;
1176         atomic_t        atm_swbw;
1177
1178         /* 802.11e and WMM Traffic Stream Info (TX) */
1179         struct list_head        Tx_TS_Admit_List;
1180         struct list_head        Tx_TS_Pending_List;
1181         struct list_head        Tx_TS_Unused_List;
1182         TX_TS_RECORD            TxTsRecord[TOTAL_TS_NUM];
1183         /* 802.11e and WMM Traffic Stream Info (RX) */
1184         struct list_head        Rx_TS_Admit_List;
1185         struct list_head        Rx_TS_Pending_List;
1186         struct list_head        Rx_TS_Unused_List;
1187         RX_TS_RECORD            RxTsRecord[TOTAL_TS_NUM];
1188
1189         RX_REORDER_ENTRY        RxReorderEntry[128];
1190         struct list_head        RxReorder_Unused_List;
1191
1192         /* Qos related */
1193         /* Force per-packet priority 1~7. (default: 0, not to force it.) */
1194         u8 ForcedPriority;
1195
1196         /* Bookkeeping structures */
1197         struct net_device_stats stats;
1198         struct ieee80211_stats ieee_stats;
1199         struct ieee80211_softmac_stats softmac_stats;
1200
1201         /* Probe / Beacon management */
1202         struct list_head network_free_list;
1203         struct list_head network_list;
1204         struct ieee80211_network *networks;
1205         int scans;
1206         int scan_age;
1207
1208         int iw_mode; /* operating mode (IW_MODE_*) */
1209         struct iw_spy_data spy_data;
1210
1211         spinlock_t lock;
1212         spinlock_t wpax_suitlist_lock;
1213
1214         int tx_headroom; /* Set to size of any additional room needed at front
1215                           * of allocated Tx SKBs */
1216         u32 config;
1217
1218         /* WEP and other encryption related settings at the device level */
1219         int open_wep; /* Set to 1 to allow unencrypted frames */
1220         int auth_mode;
1221         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1222                                  * WEP key changes */
1223
1224         /* If the host performs {en,de}cryption, then set to 1 */
1225         int host_encrypt;
1226         int host_encrypt_msdu;
1227         int host_decrypt;
1228         /* host performs multicast decryption */
1229         int host_mc_decrypt;
1230
1231         /* host should strip IV and ICV from protected frames */
1232         /* meaningful only when hardware decryption is being used */
1233         int host_strip_iv_icv;
1234
1235         int host_open_frag;
1236         int host_build_iv;
1237         int ieee802_1x; /* is IEEE 802.1X used */
1238
1239         /* WPA data */
1240         bool bHalfWirelessN24GMode;
1241         int wpa_enabled;
1242         int drop_unencrypted;
1243         int tkip_countermeasures;
1244         int privacy_invoked;
1245         size_t wpa_ie_len;
1246         u8 *wpa_ie;
1247         u8 ap_mac_addr[6];
1248         u16 pairwise_key_type;
1249         u16 group_key_type;
1250         struct list_head crypt_deinit_list;
1251         struct ieee80211_crypt_data *crypt[WEP_KEYS];
1252         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
1253         struct timer_list crypt_deinit_timer;
1254         int crypt_quiesced;
1255
1256         int bcrx_sta_key; /* use individual keys to override default keys even
1257                            * with RX of broad/multicast frames */
1258
1259         /* Fragmentation structures */
1260         // each streaming contain a entry
1261         struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
1262         unsigned int frag_next_idx[17];
1263         u16 fts; /* Fragmentation Threshold */
1264 #define DEFAULT_RTS_THRESHOLD 2346U
1265 #define MIN_RTS_THRESHOLD 1
1266 #define MAX_RTS_THRESHOLD 2346U
1267         u16 rts; /* RTS threshold */
1268
1269         /* Association info */
1270         u8 bssid[ETH_ALEN];
1271
1272         /* This stores infos for the current network.
1273          * Either the network we are associated in INFRASTRUCTURE
1274          * or the network that we are creating in MASTER mode.
1275          * ad-hoc is a mixture ;-).
1276          * Note that in infrastructure mode, even when not associated,
1277          * fields bssid and essid may be valid (if wpa_set and essid_set
1278          * are true) as thy carry the value set by the user via iwconfig
1279          */
1280         struct ieee80211_network current_network;
1281
1282         enum ieee80211_state state;
1283
1284         int short_slot;
1285         int reg_mode;
1286         int mode;       /* A, B, G */
1287         int modulation; /* CCK, OFDM */
1288         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
1289         int abg_true;   /* ABG flag              */
1290
1291         /* used for forcing the ibss workqueue to terminate
1292          * without wait for the syncro scan to terminate
1293          */
1294         short sync_scan_hurryup;
1295         u16 scan_watch_dog;
1296         int perfect_rssi;
1297         int worst_rssi;
1298
1299         u16 prev_seq_ctl;       /* used to drop duplicate frames */
1300
1301         /*
1302          * map of allowed channels. 0 is dummy, FIXME: remeber to default to
1303          * a basic channel plan depending of the PHY type
1304          */
1305         void *pDot11dInfo;
1306         bool bGlobalDomain;
1307         int rate;       /* current rate */
1308         int basic_rate;
1309         //FIXME: pleace callback, see if redundant with softmac_features
1310         short active_scan;
1311
1312         /* this contains flags for selectively enable softmac support */
1313         u16 softmac_features;
1314
1315         /* if the sequence control field is not filled by HW */
1316         u16 seq_ctrl[5];
1317
1318         /* association procedure transaction sequence number */
1319         u16 associate_seq;
1320
1321         /* AID for RTXed association responses */
1322         u16 assoc_id;
1323
1324         /* power save mode related*/
1325         u8 ack_tx_to_ieee;
1326         short ps;
1327         short sta_sleep;
1328         int ps_timeout;
1329         int ps_period;
1330         struct tasklet_struct ps_task;
1331         u32 ps_th;
1332         u32 ps_tl;
1333
1334         short raw_tx;
1335         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1336         short queue_stop;
1337         short scanning;
1338         short proto_started;
1339
1340         struct semaphore wx_sem;
1341         struct semaphore scan_sem;
1342
1343         spinlock_t mgmt_tx_lock;
1344         spinlock_t beacon_lock;
1345
1346         short beacon_txing;
1347
1348         short wap_set;
1349         short ssid_set;
1350
1351         u8  wpax_type_set;    //{added by David, 2006.9.28}
1352         u32 wpax_type_notify; //{added by David, 2006.9.26}
1353
1354         /* QoS related flag */
1355         char init_wmmparam_flag;
1356         /* set on initialization */
1357         u8  qos_support;
1358
1359         /* for discarding duplicated packets in IBSS */
1360         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1361
1362         /* for discarding duplicated packets in BSS */
1363         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1364         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1365         unsigned long last_packet_time[17];
1366
1367         /* for PS mode */
1368         unsigned long last_rx_ps_time;
1369
1370         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1371         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1372         int mgmt_queue_head;
1373         int mgmt_queue_tail;
1374
1375 /* rtl819x start */
1376         u8 AsocRetryCount;
1377         unsigned int hw_header;
1378         struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
1379         struct sk_buff_head skb_aggQ[MAX_QUEUE_SIZE];
1380         struct sk_buff_head skb_drv_aggQ[MAX_QUEUE_SIZE];
1381         u32 sta_edca_param[4];
1382         bool aggregation;
1383         /* Enable/Disable Rx immediate BA capability. */
1384         bool enable_rx_imm_BA;
1385         bool bibsscoordinator;
1386
1387         /* Dynamic Tx power for near/far range enable/disable. */
1388         bool bdynamic_txpower_enable;
1389
1390         bool bCTSToSelfEnable;
1391         u8 CTSToSelfTH;
1392
1393         u32     fsync_time_interval;
1394         u32     fsync_rate_bitmap;
1395         u8      fsync_rssi_threshold;
1396         bool    bfsync_enable;
1397
1398         u8      fsync_multiple_timeinterval;    /* value * FsyncTimeInterval */
1399         u32     fsync_firstdiff_ratethreshold;  /* low threshold */
1400         u32     fsync_seconddiff_ratethreshold; /* decrease threshold */
1401         Fsync_State     fsync_state;
1402         bool            bis_any_nonbepkts;
1403         /* 20Mhz 40Mhz AutoSwitch Threshold */
1404         struct bandwidth_autoswitch bandwidth_auto_switch;
1405         /* for txpower tracking */
1406         bool FwRWRF;
1407
1408         /* for AP roaming */
1409         struct rt_link_detect LinkDetectInfo;
1410
1411         struct rt_power_save_control PowerSaveControl;
1412 /* rtl819x end */
1413
1414         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1415         struct  tx_pending_t tx_pending;
1416
1417         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1418         struct timer_list associate_timer;
1419
1420         /* used if IEEE_SOFTMAC_BEACONS is set */
1421         struct timer_list beacon_timer;
1422         struct work_struct associate_complete_wq;
1423         struct work_struct associate_procedure_wq;
1424         struct delayed_work softmac_scan_wq;
1425         struct delayed_work associate_retry_wq;
1426         struct delayed_work start_ibss_wq;
1427         struct delayed_work hw_wakeup_wq;
1428         struct delayed_work hw_sleep_wq;
1429         struct delayed_work link_change_wq;
1430         struct work_struct wx_sync_scan_wq;
1431         struct workqueue_struct *wq;
1432
1433         /* Callback functions */
1434         void (*set_security)(struct net_device *dev,
1435                              struct ieee80211_security *sec);
1436
1437         /* Used to TX data frame by using txb structs.
1438          * this is not used if in the softmac_features
1439          * is set the flag IEEE_SOFTMAC_TX_QUEUE
1440          */
1441         int (*hard_start_xmit)(struct ieee80211_txb *txb,
1442                                struct net_device *dev);
1443
1444         int (*reset_port)(struct net_device *dev);
1445         int (*is_queue_full)(struct net_device *dev, int pri);
1446
1447         int (*handle_management)(struct net_device *dev,
1448                                  struct ieee80211_network *network, u16 type);
1449         int (*is_qos_active)(struct net_device *dev, struct sk_buff *skb);
1450
1451         /* Softmac-generated frames (mamagement) are TXed via this
1452          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1453          * not set. As some cards may have different HW queues that
1454          * one might want to use for data and management frames
1455          * the option to have two callbacks might be useful.
1456          * This fucntion can't sleep.
1457          */
1458         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1459                                struct net_device *dev);
1460
1461         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1462          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1463          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1464          * then also management frames are sent via this callback.
1465          * This function can't sleep.
1466          */
1467         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1468                                struct net_device *dev,int rate);
1469
1470         /* stops the HW queue for DATA frames. Useful to avoid
1471          * waste time to TX data frame when we are reassociating
1472          * This function can sleep.
1473          */
1474         void (*data_hard_stop)(struct net_device *dev);
1475
1476         /* OK this is complementar to data_poll_hard_stop */
1477         void (*data_hard_resume)(struct net_device *dev);
1478
1479         /* ask to the driver to retune the radio .
1480          * This function can sleep. the driver should ensure
1481          * the radio has been swithced before return.
1482          */
1483         void (*set_chan)(struct net_device *dev,short ch);
1484
1485         /* These are not used if the ieee stack takes care of
1486          * scanning (IEEE_SOFTMAC_SCAN feature set).
1487          * In this case only the set_chan is used.
1488          *
1489          * The syncro version is similar to the start_scan but
1490          * does not return until all channels has been scanned.
1491          * this is called in user context and should sleep,
1492          * it is called in a work_queue when swithcing to ad-hoc mode
1493          * or in behalf of iwlist scan when the card is associated
1494          * and root user ask for a scan.
1495          * the fucntion stop_scan should stop both the syncro and
1496          * background scanning and can sleep.
1497          * The fucntion start_scan should initiate the background
1498          * scanning and can't sleep.
1499          */
1500         void (*scan_syncro)(struct net_device *dev);
1501         void (*start_scan)(struct net_device *dev);
1502         void (*stop_scan)(struct net_device *dev);
1503
1504         /* indicate the driver that the link state is changed
1505          * for example it may indicate the card is associated now.
1506          * Driver might be interested in this to apply RX filter
1507          * rules or simply light the LINK led
1508          */
1509         void (*link_change)(struct net_device *dev);
1510
1511         /* these two function indicates to the HW when to start
1512          * and stop to send beacons. This is used when the
1513          * IEEE_SOFTMAC_BEACONS is not set. For now the
1514          * stop_send_bacons is NOT guaranteed to be called only
1515          * after start_send_beacons.
1516          */
1517         void (*start_send_beacons) (struct net_device *dev);
1518         void (*stop_send_beacons) (struct net_device *dev);
1519
1520         /* power save mode related */
1521         void (*sta_wake_up) (struct net_device *dev);
1522         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
1523         short (*ps_is_queue_empty) (struct net_device *dev);
1524
1525         int (*handle_beacon)(struct net_device *dev,
1526                              struct ieee80211_probe_response *beacon,
1527                              struct ieee80211_network *network);
1528         int (*handle_assoc_response)(struct net_device *dev,
1529                                 struct ieee80211_assoc_response_frame *resp,
1530                                 struct ieee80211_network *network);
1531
1532         /* check whether Tx hw resouce available */
1533         short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
1534         /* HT related */
1535         void (*SetBWModeHandler)(struct net_device *dev,
1536                                  HT_CHANNEL_WIDTH Bandwidth,
1537                                  HT_EXTCHNL_OFFSET Offset);
1538         bool (*GetNmodeSupportBySecCfg)(struct net_device* dev);
1539         void (*SetWirelessMode)(struct net_device* dev, u8 wireless_mode);
1540         bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device* dev);
1541         bool (*is_ap_in_wep_tkip)(struct net_device* dev);
1542         void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
1543         bool (*SetFwCmdHandler)(struct net_device *dev, FW_CMD_IO_TYPE FwCmdIO);
1544         void (*LedControlHandler)(struct net_device *dev,
1545                                   LED_CTL_MODE LedAction);
1546         /* This must be the last item so that it points to the data
1547          * allocated beyond this structure by alloc_ieee80211 */
1548         u8 priv[0];
1549 };
1550
1551 #define IEEE_A            (1<<0)
1552 #define IEEE_B            (1<<1)
1553 #define IEEE_G            (1<<2)
1554 #define IEEE_N_24G                (1<<4)
1555 #define IEEE_N_5G                 (1<<5)
1556 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1557
1558 /* Generate a 802.11 header */
1559
1560 /* Uses the channel change callback directly
1561  * instead of [start/stop] scan callbacks
1562  */
1563 #define IEEE_SOFTMAC_SCAN (1<<2)
1564
1565 /* Perform authentication and association handshake */
1566 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1567
1568 /* Generate probe requests */
1569 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1570
1571 /* Generate respones to probe requests */
1572 #define IEEE_SOFTMAC_PROBERS (1<<5)
1573
1574 /* The ieee802.11 stack will manages the netif queue
1575  * wake/stop for the driver, taking care of 802.11
1576  * fragmentation. See softmac.c for details. */
1577 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1578
1579 /* Uses only the softmac_data_hard_start_xmit
1580  * even for TX management frames.
1581  */
1582 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1583
1584 /* Generate beacons.  The stack will enqueue beacons
1585  * to the card
1586  */
1587 #define IEEE_SOFTMAC_BEACONS (1<<6)
1588
1589 static inline void *ieee80211_priv(struct net_device *dev)
1590 {
1591         return ((struct ieee80211_device *)netdev_priv(dev))->priv;
1592 }
1593
1594 extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
1595 {
1596         /* Single white space is for Linksys APs */
1597         if (essid_len == 1 && essid[0] == ' ')
1598                 return 1;
1599
1600         /* Otherwise, if the entire essid is 0, we assume it is hidden */
1601         while (essid_len) {
1602                 essid_len--;
1603                 if (essid[essid_len] != '\0')
1604                         return 0;
1605         }
1606
1607         return 1;
1608 }
1609
1610 extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
1611 {
1612         /*
1613          * It is possible for both access points and our device to support
1614          * combinations of modes, so as long as there is one valid combination
1615          * of ap/device supported modes, then return success
1616          *
1617          */
1618         if ((mode & IEEE_A) &&
1619             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1620             (ieee->freq_band & IEEE80211_52GHZ_BAND))
1621                 return 1;
1622
1623         if ((mode & IEEE_G) &&
1624             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1625             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1626                 return 1;
1627
1628         if ((mode & IEEE_B) &&
1629             (ieee->modulation & IEEE80211_CCK_MODULATION) &&
1630             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1631                 return 1;
1632
1633         return 0;
1634 }
1635
1636 extern inline int ieee80211_get_hdrlen(u16 fc)
1637 {
1638         int hdrlen = IEEE80211_3ADDR_LEN;
1639
1640         switch (WLAN_FC_GET_TYPE(fc)) {
1641         case IEEE80211_FTYPE_DATA:
1642                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
1643                         hdrlen = IEEE80211_4ADDR_LEN; /* Addr4 */
1644                 if(IEEE80211_QOS_HAS_SEQ(fc))
1645                         hdrlen += 2; /* QOS ctrl*/
1646                 break;
1647         case IEEE80211_FTYPE_CTL:
1648                 switch (WLAN_FC_GET_STYPE(fc)) {
1649                 case IEEE80211_STYPE_CTS:
1650                 case IEEE80211_STYPE_ACK:
1651                         hdrlen = IEEE80211_1ADDR_LEN;
1652                         break;
1653                 default:
1654                         hdrlen = IEEE80211_2ADDR_LEN;
1655                         break;
1656                 }
1657                 break;
1658         }
1659
1660         return hdrlen;
1661 }
1662
1663 static inline u8 *ieee80211_get_payload(struct rtl_ieee80211_hdr *hdr)
1664 {
1665         switch (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
1666         case IEEE80211_1ADDR_LEN:
1667                 return ((struct ieee80211_hdr_1addr *)hdr)->payload;
1668         case IEEE80211_2ADDR_LEN:
1669                 return ((struct ieee80211_hdr_2addr *)hdr)->payload;
1670         case IEEE80211_3ADDR_LEN:
1671                 return ((struct ieee80211_hdr_3addr *)hdr)->payload;
1672         case IEEE80211_4ADDR_LEN:
1673                 return ((struct ieee80211_hdr_4addr *)hdr)->payload;
1674         }
1675         return NULL;
1676 }
1677
1678 static inline int ieee80211_is_ofdm_rate(u8 rate)
1679 {
1680         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
1681         case IEEE80211_OFDM_RATE_6MB:
1682         case IEEE80211_OFDM_RATE_9MB:
1683         case IEEE80211_OFDM_RATE_12MB:
1684         case IEEE80211_OFDM_RATE_18MB:
1685         case IEEE80211_OFDM_RATE_24MB:
1686         case IEEE80211_OFDM_RATE_36MB:
1687         case IEEE80211_OFDM_RATE_48MB:
1688         case IEEE80211_OFDM_RATE_54MB:
1689                 return 1;
1690         }
1691         return 0;
1692 }
1693
1694 static inline int ieee80211_is_cck_rate(u8 rate)
1695 {
1696         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
1697         case IEEE80211_CCK_RATE_1MB:
1698         case IEEE80211_CCK_RATE_2MB:
1699         case IEEE80211_CCK_RATE_5MB:
1700         case IEEE80211_CCK_RATE_11MB:
1701                 return 1;
1702         }
1703         return 0;
1704 }
1705
1706
1707 /* ieee80211.c */
1708 extern void free_ieee80211(struct net_device *dev);
1709 extern struct net_device *alloc_ieee80211(int sizeof_priv);
1710
1711 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
1712
1713 /* ieee80211_tx.c */
1714
1715 extern int ieee80211_encrypt_fragment(
1716         struct ieee80211_device *ieee,
1717         struct sk_buff *frag,
1718         int hdr_len);
1719
1720 extern int rtl8192_ieee80211_rtl_xmit(struct sk_buff *skb,
1721                           struct net_device *dev);
1722 extern void ieee80211_txb_free(struct ieee80211_txb *);
1723
1724
1725 /* ieee80211_rx.c */
1726 extern int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1727                         struct ieee80211_rx_stats *rx_stats);
1728 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1729                              struct ieee80211_hdr_4addr *header,
1730                              struct ieee80211_rx_stats *stats);
1731
1732 /* ieee80211_wx.c */
1733 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
1734                                  struct iw_request_info *info,
1735                                  union iwreq_data *wrqu, char *key);
1736 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
1737                                    struct iw_request_info *info,
1738                                    union iwreq_data *wrqu, char *key);
1739 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
1740                                    struct iw_request_info *info,
1741                                    union iwreq_data *wrqu, char *key);
1742 extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
1743                             struct iw_request_info *info,
1744                             union iwreq_data* wrqu, char *extra);
1745 extern int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
1746                                struct iw_request_info *info,
1747                                struct iw_param *data, char *extra);
1748 extern int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
1749                                struct iw_request_info *info,
1750                                union iwreq_data *wrqu, char *extra);
1751 extern int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
1752
1753 /* ieee80211_softmac.c */
1754 extern short ieee80211_is_54g(struct ieee80211_network net);
1755 extern short ieee80211_is_shortslot(struct ieee80211_network net);
1756 extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1757                         struct ieee80211_rx_stats *rx_stats, u16 type,
1758                         u16 stype);
1759 extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net);
1760
1761 void SendDisassociation(struct ieee80211_device *ieee, u8* asSta, u8 asRsn);
1762 extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee);
1763
1764 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
1765 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
1766 extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
1767 extern void ieee80211_start_bss(struct ieee80211_device *ieee);
1768 extern void ieee80211_start_master_bss(struct ieee80211_device *ieee);
1769 extern void ieee80211_start_ibss(struct ieee80211_device *ieee);
1770 extern void ieee80211_softmac_init(struct ieee80211_device *ieee);
1771 extern void ieee80211_softmac_free(struct ieee80211_device *ieee);
1772 extern void ieee80211_associate_abort(struct ieee80211_device *ieee);
1773 extern void ieee80211_disassociate(struct ieee80211_device *ieee);
1774 extern void ieee80211_stop_scan(struct ieee80211_device *ieee);
1775 extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
1776 extern void ieee80211_check_all_nets(struct ieee80211_device *ieee);
1777 extern void ieee80211_start_protocol(struct ieee80211_device *ieee);
1778 extern void ieee80211_stop_protocol(struct ieee80211_device *ieee);
1779 extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
1780 extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
1781 extern void ieee80211_reset_queue(struct ieee80211_device *ieee);
1782 extern void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee);
1783 extern void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee);
1784 extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
1785 extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
1786 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
1787 extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p);
1788 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
1789 extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
1790
1791 extern void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee);
1792
1793 /* ieee80211_crypt_ccmp&tkip&wep.c */
1794 extern void ieee80211_tkip_null(void);
1795 extern void ieee80211_wep_null(void);
1796 extern void ieee80211_ccmp_null(void);
1797
1798 /* ieee80211_softmac_wx.c */
1799
1800 extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
1801                             struct iw_request_info *info,
1802                             union iwreq_data *wrqu, char *ext);
1803
1804 extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
1805                          struct iw_request_info *info,
1806                          union iwreq_data *awrq,
1807                          char *extra);
1808
1809 extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
1810
1811 extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
1812                              struct iw_request_info *info,
1813                              union iwreq_data *wrqu, char *extra);
1814
1815 extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
1816                              struct iw_request_info *info,
1817                              union iwreq_data *wrqu, char *extra);
1818
1819 extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1820                              union iwreq_data *wrqu, char *b);
1821
1822 extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
1823                              union iwreq_data *wrqu, char *b);
1824
1825 extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
1826                               struct iw_request_info *a,
1827                               union iwreq_data *wrqu, char *extra);
1828
1829 extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1830                              union iwreq_data *wrqu, char *b);
1831
1832 extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1833                              union iwreq_data *wrqu, char *b);
1834
1835 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1836                              union iwreq_data *wrqu, char *b);
1837
1838 extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
1839
1840 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
1841                                struct iw_request_info *info,
1842                                union iwreq_data *wrqu, char *extra);
1843
1844 extern int ieee80211_wx_get_name(struct ieee80211_device *ieee,
1845                              struct iw_request_info *info,
1846                              union iwreq_data *wrqu, char *extra);
1847
1848 extern int ieee80211_wx_set_power(struct ieee80211_device *ieee,
1849                                  struct iw_request_info *info,
1850                                  union iwreq_data *wrqu, char *extra);
1851
1852 extern int ieee80211_wx_get_power(struct ieee80211_device *ieee,
1853                                  struct iw_request_info *info,
1854                                  union iwreq_data *wrqu, char *extra);
1855
1856 extern int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
1857                              struct iw_request_info *info,
1858                              union iwreq_data *wrqu, char *extra);
1859
1860 extern int ieee80211_wx_get_rts(struct ieee80211_device *ieee,
1861                              struct iw_request_info *info,
1862                              union iwreq_data *wrqu, char *extra);
1863
1864 extern void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee);
1865
1866 extern const long ieee80211_wlan_frequencies[];
1867
1868 extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
1869 {
1870         ieee->scans++;
1871 }
1872
1873 extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
1874 {
1875         return ieee->scans;
1876 }
1877
1878 static inline const char *escape_essid(const char *essid, u8 essid_len) {
1879         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
1880         const char *s = essid;
1881         char *d = escaped;
1882
1883         if (ieee80211_is_empty_essid(essid, essid_len)) {
1884                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
1885                 return escaped;
1886         }
1887
1888         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
1889         while (essid_len--) {
1890                 if (*s == '\0') {
1891                         *d++ = '\\';
1892                         *d++ = '0';
1893                         s++;
1894                 } else {
1895                         *d++ = *s++;
1896                 }
1897         }
1898         *d = '\0';
1899         return escaped;
1900 }
1901
1902 /* For the function is more related to hardware setting, it's better to use the
1903  * ieee handler to refer to it.
1904  */
1905 extern short check_nic_enough_desc(struct net_device *dev, int queue_index);
1906 extern int ieee80211_data_xmit(struct sk_buff *skb, struct net_device *dev);
1907 extern int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1908                 struct ieee80211_info_element *info_element,
1909                 u16 length,
1910                 struct ieee80211_network *network,
1911                 struct ieee80211_rx_stats *stats);
1912
1913 extern void ieee80211_indicate_packets(struct ieee80211_device *ieee,
1914                                        struct ieee80211_rxb **prxbIndicateArray,
1915                                        u8 index);
1916 #define RT_ASOC_RETRY_LIMIT     5
1917 #endif /* IEEE80211_H */