3cda38bb6b7718f5ab9f12e6939b0c20c8900aa7
[pandora-kernel.git] / drivers / staging / rtl8192u / 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
37 #include "rtl819x_HT.h"
38 #include "rtl819x_BA.h"
39 #include "rtl819x_TS.h"
40
41
42 #ifndef IW_MODE_MONITOR
43 #define IW_MODE_MONITOR 6
44 #endif
45
46 #ifndef IWEVCUSTOM
47 #define IWEVCUSTOM 0x8c02
48 #endif
49
50
51 #ifndef container_of
52 /**
53  * container_of - cast a member of a structure out to the containing structure
54  *
55  * @ptr:        the pointer to the member.
56  * @type:       the type of the container struct this is embedded in.
57  * @member:     the name of the member within the struct.
58  *
59  */
60 #define container_of(ptr, type, member) ({                      \
61         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
62         (type *)( (char *)__mptr - offsetof(type,member) );})
63 #endif
64
65 #define KEY_TYPE_NA             0x0
66 #define KEY_TYPE_WEP40          0x1
67 #define KEY_TYPE_TKIP           0x2
68 #define KEY_TYPE_CCMP           0x4
69 #define KEY_TYPE_WEP104         0x5
70
71 /* added for rtl819x tx procedure */
72 #define MAX_QUEUE_SIZE          0x10
73
74 //
75 // 8190 queue mapping
76 //
77 #define BK_QUEUE                               0
78 #define BE_QUEUE                               1
79 #define VI_QUEUE                               2
80 #define VO_QUEUE                               3
81 #define HCCA_QUEUE                             4
82 #define TXCMD_QUEUE                            5
83 #define MGNT_QUEUE                             6
84 #define HIGH_QUEUE                             7
85 #define BEACON_QUEUE                           8
86
87 #define LOW_QUEUE                              BE_QUEUE
88 #define NORMAL_QUEUE                           MGNT_QUEUE
89
90 //added by amy for ps
91 #define SWRF_TIMEOUT                            50
92
93 //added by amy for LEAP related
94 #define IE_CISCO_FLAG_POSITION          0x08    // Flag byte: byte 8, numbered from 0.
95 #define SUPPORT_CKIP_MIC                        0x08    // bit3
96 #define SUPPORT_CKIP_PK                 0x10    // bit4
97 /* defined for skb cb field */
98 /* At most 28 byte */
99 typedef struct cb_desc {
100         /* Tx Desc Related flags (8-9) */
101         u8 bLastIniPkt:1;
102         u8 bCmdOrInit:1;
103         u8 bFirstSeg:1;
104         u8 bLastSeg:1;
105         u8 bEncrypt:1;
106         u8 bTxDisableRateFallBack:1;
107         u8 bTxUseDriverAssingedRate:1;
108         u8 bHwSec:1; //indicate whether use Hw security. WB
109
110         u8 reserved1;
111
112         /* Tx Firmware Relaged flags (10-11)*/
113         u8 bCTSEnable:1;
114         u8 bRTSEnable:1;
115         u8 bUseShortGI:1;
116         u8 bUseShortPreamble:1;
117         u8 bTxEnableFwCalcDur:1;
118         u8 bAMPDUEnable:1;
119         u8 bRTSSTBC:1;
120         u8 RTSSC:1;
121
122         u8 bRTSBW:1;
123         u8 bPacketBW:1;
124         u8 bRTSUseShortPreamble:1;
125         u8 bRTSUseShortGI:1;
126         u8 bMulticast:1;
127         u8 bBroadcast:1;
128         //u8 reserved2:2;
129         u8 drv_agg_enable:1;
130         u8 reserved2:1;
131
132         /* Tx Desc related element(12-19) */
133         u8 rata_index;
134         u8 queue_index;
135         //u8 reserved3;
136         //u8 reserved4;
137         u16 txbuf_size;
138         //u8 reserved5;
139         u8 RATRIndex;
140         u8 reserved6;
141         u8 reserved7;
142         u8 reserved8;
143
144         /* Tx firmware related element(20-27) */
145         u8 data_rate;
146         u8 rts_rate;
147         u8 ampdu_factor;
148         u8 ampdu_density;
149         //u8 reserved9;
150         //u8 reserved10;
151         //u8 reserved11;
152         u8 DrvAggrNum;
153         u16 pkt_size;
154         u8 reserved12;
155 }cb_desc, *pcb_desc;
156
157 /*--------------------------Define -------------------------------------------*/
158 #define MGN_1M                  0x02
159 #define MGN_2M                  0x04
160 #define MGN_5_5M                0x0b
161 #define MGN_11M                 0x16
162
163 #define MGN_6M                  0x0c
164 #define MGN_9M                  0x12
165 #define MGN_12M                 0x18
166 #define MGN_18M                 0x24
167 #define MGN_24M                 0x30
168 #define MGN_36M                 0x48
169 #define MGN_48M                 0x60
170 #define MGN_54M                 0x6c
171
172 #define MGN_MCS0                0x80
173 #define MGN_MCS1                0x81
174 #define MGN_MCS2                0x82
175 #define MGN_MCS3                0x83
176 #define MGN_MCS4                0x84
177 #define MGN_MCS5                0x85
178 #define MGN_MCS6                0x86
179 #define MGN_MCS7                0x87
180 #define MGN_MCS8                0x88
181 #define MGN_MCS9                0x89
182 #define MGN_MCS10               0x8a
183 #define MGN_MCS11               0x8b
184 #define MGN_MCS12               0x8c
185 #define MGN_MCS13               0x8d
186 #define MGN_MCS14               0x8e
187 #define MGN_MCS15               0x8f
188
189 //----------------------------------------------------------------------------
190 //              802.11 Management frame Reason Code field
191 //----------------------------------------------------------------------------
192 enum    _ReasonCode{
193         unspec_reason   = 0x1,
194         auth_not_valid  = 0x2,
195         deauth_lv_ss    = 0x3,
196         inactivity              = 0x4,
197         ap_overload     = 0x5,
198         class2_err              = 0x6,
199         class3_err              = 0x7,
200         disas_lv_ss     = 0x8,
201         asoc_not_auth   = 0x9,
202
203         //----MIC_CHECK
204         mic_failure     = 0xe,
205         //----END MIC_CHECK
206
207         // Reason code defined in 802.11i D10.0 p.28.
208         invalid_IE              = 0x0d,
209         four_way_tmout  = 0x0f,
210         two_way_tmout   = 0x10,
211         IE_dismatch     = 0x11,
212         invalid_Gcipher = 0x12,
213         invalid_Pcipher = 0x13,
214         invalid_AKMP    = 0x14,
215         unsup_RSNIEver = 0x15,
216         invalid_RSNIE   = 0x16,
217         auth_802_1x_fail= 0x17,
218         ciper_reject            = 0x18,
219
220         // Reason code defined in 7.3.1.7, 802.1e D13.0, p.42. Added by Annie, 2005-11-15.
221         QoS_unspec              = 0x20, // 32
222         QAP_bandwidth   = 0x21, // 33
223         poor_condition  = 0x22, // 34
224         no_facility     = 0x23, // 35
225                                                         // Where is 36???
226         req_declined    = 0x25, // 37
227         invalid_param   = 0x26, // 38
228         req_not_honored= 0x27,  // 39
229         TS_not_created  = 0x2F, // 47
230         DL_not_allowed  = 0x30, // 48
231         dest_not_exist  = 0x31, // 49
232         dest_not_QSTA   = 0x32, // 50
233 };
234
235
236
237 #define aSifsTime        ((priv->ieee80211->current_network.mode == IEEE_A)||(priv->ieee80211->current_network.mode == IEEE_N_24G)||(priv->ieee80211->current_network.mode == IEEE_N_5G))? 16 : 10
238
239 #define MGMT_QUEUE_NUM 5
240
241 #define IEEE_CMD_SET_WPA_PARAM                  1
242 #define IEEE_CMD_SET_WPA_IE                     2
243 #define IEEE_CMD_SET_ENCRYPTION                 3
244 #define IEEE_CMD_MLME                           4
245
246 #define IEEE_PARAM_WPA_ENABLED                  1
247 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
248 #define IEEE_PARAM_DROP_UNENCRYPTED             3
249 #define IEEE_PARAM_PRIVACY_INVOKED              4
250 #define IEEE_PARAM_AUTH_ALGS                    5
251 #define IEEE_PARAM_IEEE_802_1X                  6
252 //It should consistent with the driver_XXX.c
253 //   David, 2006.9.26
254 #define IEEE_PARAM_WPAX_SELECT                  7
255 //Added for notify the encryption type selection
256 //   David, 2006.9.26
257 #define IEEE_PROTO_WPA                          1
258 #define IEEE_PROTO_RSN                          2
259 //Added for notify the encryption type selection
260 //   David, 2006.9.26
261 #define IEEE_WPAX_USEGROUP                      0
262 #define IEEE_WPAX_WEP40                         1
263 #define IEEE_WPAX_TKIP                          2
264 #define IEEE_WPAX_WRAP                          3
265 #define IEEE_WPAX_CCMP                          4
266 #define IEEE_WPAX_WEP104                        5
267
268 #define IEEE_KEY_MGMT_IEEE8021X                 1
269 #define IEEE_KEY_MGMT_PSK                       2
270
271 #define IEEE_MLME_STA_DEAUTH                    1
272 #define IEEE_MLME_STA_DISASSOC                  2
273
274
275 #define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
276 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
277 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED        4
278 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
279 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED        6
280 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
281
282
283 #define IEEE_CRYPT_ALG_NAME_LEN                 16
284
285 #define MAX_IE_LEN  0xff
286
287 // added for kernel conflict
288 #define ieee80211_crypt_deinit_entries  ieee80211_crypt_deinit_entries_rsl
289 #define ieee80211_crypt_deinit_handler  ieee80211_crypt_deinit_handler_rsl
290 #define ieee80211_crypt_delayed_deinit  ieee80211_crypt_delayed_deinit_rsl
291 #define ieee80211_register_crypto_ops   ieee80211_register_crypto_ops_rsl
292 #define ieee80211_unregister_crypto_ops ieee80211_unregister_crypto_ops_rsl
293 #define ieee80211_get_crypto_ops        ieee80211_get_crypto_ops_rsl
294
295 #define ieee80211_ccmp_null             ieee80211_ccmp_null_rsl
296
297 #define ieee80211_tkip_null             ieee80211_tkip_null_rsl
298
299 #define ieee80211_wep_null              ieee80211_wep_null_rsl
300
301 #define free_ieee80211                  free_ieee80211_rsl
302 #define alloc_ieee80211                 alloc_ieee80211_rsl
303
304 #define ieee80211_rx                    ieee80211_rx_rsl
305 #define ieee80211_rx_mgt                ieee80211_rx_mgt_rsl
306
307 #define ieee80211_get_beacon            ieee80211_get_beacon_rsl
308 #define ieee80211_wake_queue            ieee80211_wake_queue_rsl
309 #define ieee80211_stop_queue            ieee80211_stop_queue_rsl
310 #define ieee80211_reset_queue           ieee80211_reset_queue_rsl
311 #define ieee80211_softmac_stop_protocol ieee80211_softmac_stop_protocol_rsl
312 #define ieee80211_softmac_start_protocol ieee80211_softmac_start_protocol_rsl
313 #define ieee80211_is_shortslot          ieee80211_is_shortslot_rsl
314 #define ieee80211_is_54g                ieee80211_is_54g_rsl
315 #define ieee80211_wpa_supplicant_ioctl  ieee80211_wpa_supplicant_ioctl_rsl
316 #define ieee80211_ps_tx_ack             ieee80211_ps_tx_ack_rsl
317 #define ieee80211_softmac_xmit          ieee80211_softmac_xmit_rsl
318 #define ieee80211_stop_send_beacons     ieee80211_stop_send_beacons_rsl
319 #define notify_wx_assoc_event           notify_wx_assoc_event_rsl
320 #define SendDisassociation              SendDisassociation_rsl
321 #define ieee80211_disassociate          ieee80211_disassociate_rsl
322 #define ieee80211_start_send_beacons    ieee80211_start_send_beacons_rsl
323 #define ieee80211_stop_scan             ieee80211_stop_scan_rsl
324 #define ieee80211_send_probe_requests   ieee80211_send_probe_requests_rsl
325 #define ieee80211_softmac_scan_syncro   ieee80211_softmac_scan_syncro_rsl
326 #define ieee80211_start_scan_syncro     ieee80211_start_scan_syncro_rsl
327
328 #define ieee80211_wx_get_essid          ieee80211_wx_get_essid_rsl
329 #define ieee80211_wx_set_essid          ieee80211_wx_set_essid_rsl
330 #define ieee80211_wx_set_rate           ieee80211_wx_set_rate_rsl
331 #define ieee80211_wx_get_rate           ieee80211_wx_get_rate_rsl
332 #define ieee80211_wx_set_wap            ieee80211_wx_set_wap_rsl
333 #define ieee80211_wx_get_wap            ieee80211_wx_get_wap_rsl
334 #define ieee80211_wx_set_mode           ieee80211_wx_set_mode_rsl
335 #define ieee80211_wx_get_mode           ieee80211_wx_get_mode_rsl
336 #define ieee80211_wx_set_scan           ieee80211_wx_set_scan_rsl
337 #define ieee80211_wx_get_freq           ieee80211_wx_get_freq_rsl
338 #define ieee80211_wx_set_freq           ieee80211_wx_set_freq_rsl
339 #define ieee80211_wx_set_rawtx          ieee80211_wx_set_rawtx_rsl
340 #define ieee80211_wx_get_name           ieee80211_wx_get_name_rsl
341 #define ieee80211_wx_set_power          ieee80211_wx_set_power_rsl
342 #define ieee80211_wx_get_power          ieee80211_wx_get_power_rsl
343 #define ieee80211_wlan_frequencies      ieee80211_wlan_frequencies_rsl
344 #define ieee80211_wx_set_rts            ieee80211_wx_set_rts_rsl
345 #define ieee80211_wx_get_rts            ieee80211_wx_get_rts_rsl
346
347 #define ieee80211_txb_free              ieee80211_txb_free_rsl
348
349 #define ieee80211_wx_set_gen_ie         ieee80211_wx_set_gen_ie_rsl
350 #define ieee80211_wx_get_scan           ieee80211_wx_get_scan_rsl
351 #define ieee80211_wx_set_encode         ieee80211_wx_set_encode_rsl
352 #define ieee80211_wx_get_encode         ieee80211_wx_get_encode_rsl
353 #if WIRELESS_EXT >= 18
354 #define ieee80211_wx_set_mlme           ieee80211_wx_set_mlme_rsl
355 #define ieee80211_wx_set_auth           ieee80211_wx_set_auth_rsl
356 #define ieee80211_wx_set_encode_ext     ieee80211_wx_set_encode_ext_rsl
357 #define ieee80211_wx_get_encode_ext     ieee80211_wx_get_encode_ext_rsl
358 #endif
359
360
361 typedef struct ieee_param {
362         u32 cmd;
363         u8 sta_addr[ETH_ALEN];
364         union {
365                 struct {
366                         u8 name;
367                         u32 value;
368                 } wpa_param;
369                 struct {
370                         u32 len;
371                         u8 reserved[32];
372                         u8 data[0];
373                 } wpa_ie;
374                 struct{
375                         int command;
376                         int reason_code;
377                 } mlme;
378                 struct {
379                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
380                         u8 set_tx;
381                         u32 err;
382                         u8 idx;
383                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
384                         u16 key_len;
385                         u8 key[0];
386                 } crypt;
387         } u;
388 }ieee_param;
389
390
391 #if WIRELESS_EXT < 17
392 #define IW_QUAL_QUAL_INVALID   0x10
393 #define IW_QUAL_LEVEL_INVALID  0x20
394 #define IW_QUAL_NOISE_INVALID  0x40
395 #define IW_QUAL_QUAL_UPDATED   0x1
396 #define IW_QUAL_LEVEL_UPDATED  0x2
397 #define IW_QUAL_NOISE_UPDATED  0x4
398 #endif
399
400
401 // linux under 2.6.9 release may not support it, so modify it for common use
402 #define MSECS(t) msecs_to_jiffies(t)
403 #define msleep_interruptible_rsl  msleep_interruptible
404
405 #define IEEE80211_DATA_LEN              2304
406 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
407    6.2.1.1.2.
408
409    The figure in section 7.1.2 suggests a body size of up to 2312
410    bytes is allowed, which is a bit confusing, I suspect this
411    represents the 2304 bytes of real data, plus a possible 8 bytes of
412    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
413 #define IEEE80211_1ADDR_LEN 10
414 #define IEEE80211_2ADDR_LEN 16
415 #define IEEE80211_3ADDR_LEN 24
416 #define IEEE80211_4ADDR_LEN 30
417 #define IEEE80211_FCS_LEN    4
418 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
419 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
420 #define IEEE80211_MGMT_HDR_LEN 24
421 #define IEEE80211_DATA_HDR3_LEN 24
422 #define IEEE80211_DATA_HDR4_LEN 30
423
424 #define MIN_FRAG_THRESHOLD     256U
425 #define MAX_FRAG_THRESHOLD     2346U
426
427
428 /* Frame control field constants */
429 #define IEEE80211_FCTL_VERS             0x0003
430 #define IEEE80211_FCTL_FTYPE            0x000c
431 #define IEEE80211_FCTL_STYPE            0x00f0
432 #define IEEE80211_FCTL_FRAMETYPE        0x00fc
433 #define IEEE80211_FCTL_TODS             0x0100
434 #define IEEE80211_FCTL_FROMDS           0x0200
435 #define IEEE80211_FCTL_DSTODS           0x0300 //added by david
436 #define IEEE80211_FCTL_MOREFRAGS        0x0400
437 #define IEEE80211_FCTL_RETRY            0x0800
438 #define IEEE80211_FCTL_PM               0x1000
439 #define IEEE80211_FCTL_MOREDATA         0x2000
440 #define IEEE80211_FCTL_WEP              0x4000
441 #define IEEE80211_FCTL_ORDER            0x8000
442
443 #define IEEE80211_FTYPE_MGMT            0x0000
444 #define IEEE80211_FTYPE_CTL             0x0004
445 #define IEEE80211_FTYPE_DATA            0x0008
446
447 /* management */
448 #define IEEE80211_STYPE_ASSOC_REQ       0x0000
449 #define IEEE80211_STYPE_ASSOC_RESP      0x0010
450 #define IEEE80211_STYPE_REASSOC_REQ     0x0020
451 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
452 #define IEEE80211_STYPE_PROBE_REQ       0x0040
453 #define IEEE80211_STYPE_PROBE_RESP      0x0050
454 #define IEEE80211_STYPE_BEACON          0x0080
455 #define IEEE80211_STYPE_ATIM            0x0090
456 #define IEEE80211_STYPE_DISASSOC        0x00A0
457 #define IEEE80211_STYPE_AUTH            0x00B0
458 #define IEEE80211_STYPE_DEAUTH          0x00C0
459 #define IEEE80211_STYPE_MANAGE_ACT      0x00D0
460
461 /* control */
462 #define IEEE80211_STYPE_PSPOLL          0x00A0
463 #define IEEE80211_STYPE_RTS             0x00B0
464 #define IEEE80211_STYPE_CTS             0x00C0
465 #define IEEE80211_STYPE_ACK             0x00D0
466 #define IEEE80211_STYPE_CFEND           0x00E0
467 #define IEEE80211_STYPE_CFENDACK        0x00F0
468 #define IEEE80211_STYPE_BLOCKACK   0x0094
469
470 /* data */
471 #define IEEE80211_STYPE_DATA            0x0000
472 #define IEEE80211_STYPE_DATA_CFACK      0x0010
473 #define IEEE80211_STYPE_DATA_CFPOLL     0x0020
474 #define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
475 #define IEEE80211_STYPE_NULLFUNC        0x0040
476 #define IEEE80211_STYPE_CFACK           0x0050
477 #define IEEE80211_STYPE_CFPOLL          0x0060
478 #define IEEE80211_STYPE_CFACKPOLL       0x0070
479 #define IEEE80211_STYPE_QOS_DATA        0x0080 //added for WMM 2006/8/2
480 #define IEEE80211_STYPE_QOS_NULL        0x00C0
481
482 #define IEEE80211_SCTL_FRAG             0x000F
483 #define IEEE80211_SCTL_SEQ              0xFFF0
484
485 /* QOS control */
486 #define IEEE80211_QCTL_TID              0x000F
487
488 #define FC_QOS_BIT                                      BIT7
489 #define IsDataFrame(pdu)                        ( ((pdu[0] & 0x0C)==0x08) ? true : false )
490 #define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)) )
491 //added by wb. Is this right?
492 #define IsQoSDataFrame(pframe)  ((*(u16*)pframe&(IEEE80211_STYPE_QOS_DATA|IEEE80211_FTYPE_DATA)) == (IEEE80211_STYPE_QOS_DATA|IEEE80211_FTYPE_DATA))
493 #define Frame_Order(pframe)     (*(u16*)pframe&IEEE80211_FCTL_ORDER)
494 #define SN_LESS(a, b)           (((a-b)&0x800)!=0)
495 #define SN_EQUAL(a, b)  (a == b)
496 #define MAX_DEV_ADDR_SIZE 8
497 typedef enum _ACT_CATEGORY{
498         ACT_CAT_QOS = 1,
499         ACT_CAT_DLS = 2,
500         ACT_CAT_BA  = 3,
501         ACT_CAT_HT  = 7,
502         ACT_CAT_WMM = 17,
503 } ACT_CATEGORY, *PACT_CATEGORY;
504
505 typedef enum _TS_ACTION{
506         ACT_ADDTSREQ = 0,
507         ACT_ADDTSRSP = 1,
508         ACT_DELTS    = 2,
509         ACT_SCHEDULE = 3,
510 } TS_ACTION, *PTS_ACTION;
511
512 typedef enum _BA_ACTION{
513         ACT_ADDBAREQ = 0,
514         ACT_ADDBARSP = 1,
515         ACT_DELBA    = 2,
516 } BA_ACTION, *PBA_ACTION;
517
518 typedef enum _InitialGainOpType{
519         IG_Backup=0,
520         IG_Restore,
521         IG_Max
522 }InitialGainOpType;
523
524 /* debug macros */
525 #define CONFIG_IEEE80211_DEBUG
526 #ifdef CONFIG_IEEE80211_DEBUG
527 extern u32 ieee80211_debug_level;
528 #define IEEE80211_DEBUG(level, fmt, args...) \
529 do { if (ieee80211_debug_level & (level)) \
530   printk(KERN_DEBUG "ieee80211: " fmt, ## args); } while (0)
531 //wb added to debug out data buf
532 //if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA
533 #define IEEE80211_DEBUG_DATA(level, data, datalen)      \
534         do{ if ((ieee80211_debug_level & (level)) == (level))   \
535                 {       \
536                         int i;                                  \
537                         u8* pdata = (u8*) data;                 \
538                         printk(KERN_DEBUG "ieee80211: %s()\n", __FUNCTION__);   \
539                         for(i=0; i<(int)(datalen); i++)                 \
540                         {                                               \
541                                 printk("%2x ", pdata[i]);               \
542                                 if ((i+1)%16 == 0) printk("\n");        \
543                         }                               \
544                         printk("\n");                   \
545                 }                                       \
546         } while (0)
547 #else
548 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
549 #define IEEE80211_DEBUG_DATA(level, data, datalen) do {} while(0)
550 #endif  /* CONFIG_IEEE80211_DEBUG */
551
552 /* debug macros not dependent on CONFIG_IEEE80211_DEBUG */
553
554 /*
555  * To use the debug system;
556  *
557  * If you are defining a new debug classification, simply add it to the #define
558  * list here in the form of:
559  *
560  * #define IEEE80211_DL_xxxx VALUE
561  *
562  * shifting value to the left one bit from the previous entry.  xxxx should be
563  * the name of the classification (for example, WEP)
564  *
565  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
566  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
567  * to send output to that classification.
568  *
569  * To add your debug level to the list of levels seen when you perform
570  *
571  * % cat /proc/net/ipw/debug_level
572  *
573  * you simply need to add your entry to the ipw_debug_levels array.
574  *
575  * If you do not see debug_level in /proc/net/ipw then you do not have
576  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
577  *
578  */
579
580 #define IEEE80211_DL_INFO          (1<<0)
581 #define IEEE80211_DL_WX            (1<<1)
582 #define IEEE80211_DL_SCAN          (1<<2)
583 #define IEEE80211_DL_STATE         (1<<3)
584 #define IEEE80211_DL_MGMT          (1<<4)
585 #define IEEE80211_DL_FRAG          (1<<5)
586 #define IEEE80211_DL_EAP           (1<<6)
587 #define IEEE80211_DL_DROP          (1<<7)
588
589 #define IEEE80211_DL_TX            (1<<8)
590 #define IEEE80211_DL_RX            (1<<9)
591
592 #define IEEE80211_DL_HT            (1<<10)  //HT
593 #define IEEE80211_DL_BA            (1<<11)  //ba
594 #define IEEE80211_DL_TS            (1<<12)  //TS
595 #define IEEE80211_DL_QOS           (1<<13)
596 #define IEEE80211_DL_REORDER       (1<<14)
597 #define IEEE80211_DL_IOT           (1<<15)
598 #define IEEE80211_DL_IPS           (1<<16)
599 #define IEEE80211_DL_TRACE         (1<<29)  //trace function, need to user net_ratelimit() together in order not to print too much to the screen
600 #define IEEE80211_DL_DATA          (1<<30)   //use this flag to control whether print data buf out.
601 #define IEEE80211_DL_ERR           (1<<31)   //always open
602 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
603 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
604 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
605
606 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
607 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
608 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
609 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
610 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
611 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
612 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
613 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
614 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
615 #define IEEE80211_DEBUG_QOS(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_QOS, f, ## a)
616
617 #ifdef CONFIG_IEEE80211_DEBUG
618 /* Added by Annie, 2005-11-22. */
619 #define MAX_STR_LEN     64
620 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. Annie, 2005-11-22.*/
621 #define PRINTABLE(_ch)  (_ch>'!' && _ch<'~')
622 #define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len)                                    \
623                         if((_Comp) & level)                                                     \
624                         {                                                                       \
625                                 int             __i;                                            \
626                                 u8  buffer[MAX_STR_LEN];                                        \
627                                 int length = (_Len<MAX_STR_LEN)? _Len : (MAX_STR_LEN-1) ;       \
628                                 memset(buffer, 0, MAX_STR_LEN);                                 \
629                                 memcpy(buffer, (u8 *)_Ptr, length );                            \
630                                 for( __i=0; __i<MAX_STR_LEN; __i++ )                            \
631                                 {                                                               \
632                                      if( !PRINTABLE(buffer[__i]) )   buffer[__i] = '?';         \
633                                 }                                                               \
634                                 buffer[length] = '\0';                                          \
635                                 printk("Rtl819x: ");                                            \
636                                 printk(_TitleString);                                         \
637                                 printk(": %d, <%s>\n", _Len, buffer);                         \
638                         }
639 #else
640 #define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len)  do {} while (0)
641 #endif
642
643 #include <linux/netdevice.h>
644 #include <linux/if_arp.h> /* ARPHRD_ETHER */
645
646 #ifndef WIRELESS_SPY
647 #define WIRELESS_SPY            // enable iwspy support
648 #endif
649 #include <net/iw_handler.h>     // new driver API
650
651 #ifndef ETH_P_PAE
652 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
653 #endif /* ETH_P_PAE */
654
655 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
656
657 #ifndef ETH_P_80211_RAW
658 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
659 #endif
660
661 /* IEEE 802.11 defines */
662
663 #define P80211_OUI_LEN 3
664
665 struct ieee80211_snap_hdr {
666
667         u8    dsap;   /* always 0xAA */
668         u8    ssap;   /* always 0xAA */
669         u8    ctrl;   /* always 0x03 */
670         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
671
672 } __attribute__ ((packed));
673
674 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
675
676 #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
677 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
678 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
679
680 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & IEEE80211_FCTL_FRAMETYPE)
681 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
682 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & IEEE80211_SCTL_SEQ) >> 4)
683
684 /* Authentication algorithms */
685 #define WLAN_AUTH_OPEN 0
686 #define WLAN_AUTH_SHARED_KEY 1
687 #define WLAN_AUTH_LEAP 2
688
689 #define WLAN_AUTH_CHALLENGE_LEN 128
690
691 #define WLAN_CAPABILITY_BSS (1<<0)
692 #define WLAN_CAPABILITY_IBSS (1<<1)
693 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
694 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
695 #define WLAN_CAPABILITY_PRIVACY (1<<4)
696 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
697 #define WLAN_CAPABILITY_PBCC (1<<6)
698 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
699 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
700 #define WLAN_CAPABILITY_QOS (1<<9)
701 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
702 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
703
704 /* 802.11g ERP information element */
705 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
706 #define WLAN_ERP_USE_PROTECTION (1<<1)
707 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
708
709 /* Status codes */
710 enum ieee80211_statuscode {
711         WLAN_STATUS_SUCCESS = 0,
712         WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
713         WLAN_STATUS_CAPS_UNSUPPORTED = 10,
714         WLAN_STATUS_REASSOC_NO_ASSOC = 11,
715         WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
716         WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
717         WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
718         WLAN_STATUS_CHALLENGE_FAIL = 15,
719         WLAN_STATUS_AUTH_TIMEOUT = 16,
720         WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
721         WLAN_STATUS_ASSOC_DENIED_RATES = 18,
722         /* 802.11b */
723         WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
724         WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
725         WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
726         /* 802.11h */
727         WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
728         WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
729         WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
730         /* 802.11g */
731         WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
732         WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
733         /* 802.11i */
734         WLAN_STATUS_INVALID_IE = 40,
735         WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
736         WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
737         WLAN_STATUS_INVALID_AKMP = 43,
738         WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
739         WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
740         WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
741 };
742
743 /* Reason codes */
744 enum ieee80211_reasoncode {
745         WLAN_REASON_UNSPECIFIED = 1,
746         WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
747         WLAN_REASON_DEAUTH_LEAVING = 3,
748         WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
749         WLAN_REASON_DISASSOC_AP_BUSY = 5,
750         WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
751         WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
752         WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
753         WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
754         /* 802.11h */
755         WLAN_REASON_DISASSOC_BAD_POWER = 10,
756         WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
757         /* 802.11i */
758         WLAN_REASON_INVALID_IE = 13,
759         WLAN_REASON_MIC_FAILURE = 14,
760         WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
761         WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
762         WLAN_REASON_IE_DIFFERENT = 17,
763         WLAN_REASON_INVALID_GROUP_CIPHER = 18,
764         WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
765         WLAN_REASON_INVALID_AKMP = 20,
766         WLAN_REASON_UNSUPP_RSN_VERSION = 21,
767         WLAN_REASON_INVALID_RSN_IE_CAP = 22,
768         WLAN_REASON_IEEE8021X_FAILED = 23,
769         WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
770 };
771
772 #define IEEE80211_STATMASK_SIGNAL (1<<0)
773 #define IEEE80211_STATMASK_RSSI (1<<1)
774 #define IEEE80211_STATMASK_NOISE (1<<2)
775 #define IEEE80211_STATMASK_RATE (1<<3)
776 #define IEEE80211_STATMASK_WEMASK 0x7
777
778 #define IEEE80211_CCK_MODULATION    (1<<0)
779 #define IEEE80211_OFDM_MODULATION   (1<<1)
780
781 #define IEEE80211_24GHZ_BAND     (1<<0)
782 #define IEEE80211_52GHZ_BAND     (1<<1)
783
784 #define IEEE80211_CCK_RATE_LEN                  4
785 #define IEEE80211_CCK_RATE_1MB                  0x02
786 #define IEEE80211_CCK_RATE_2MB                  0x04
787 #define IEEE80211_CCK_RATE_5MB                  0x0B
788 #define IEEE80211_CCK_RATE_11MB                 0x16
789 #define IEEE80211_OFDM_RATE_LEN                 8
790 #define IEEE80211_OFDM_RATE_6MB                 0x0C
791 #define IEEE80211_OFDM_RATE_9MB                 0x12
792 #define IEEE80211_OFDM_RATE_12MB                0x18
793 #define IEEE80211_OFDM_RATE_18MB                0x24
794 #define IEEE80211_OFDM_RATE_24MB                0x30
795 #define IEEE80211_OFDM_RATE_36MB                0x48
796 #define IEEE80211_OFDM_RATE_48MB                0x60
797 #define IEEE80211_OFDM_RATE_54MB                0x6C
798 #define IEEE80211_BASIC_RATE_MASK               0x80
799
800 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
801 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
802 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
803 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
804 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
805 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
806 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
807 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
808 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
809 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
810 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
811 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
812
813 #define IEEE80211_CCK_RATES_MASK                0x0000000F
814 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
815         IEEE80211_CCK_RATE_2MB_MASK)
816 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
817         IEEE80211_CCK_RATE_5MB_MASK | \
818         IEEE80211_CCK_RATE_11MB_MASK)
819
820 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
821 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
822         IEEE80211_OFDM_RATE_12MB_MASK | \
823         IEEE80211_OFDM_RATE_24MB_MASK)
824 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
825         IEEE80211_OFDM_RATE_9MB_MASK  | \
826         IEEE80211_OFDM_RATE_18MB_MASK | \
827         IEEE80211_OFDM_RATE_36MB_MASK | \
828         IEEE80211_OFDM_RATE_48MB_MASK | \
829         IEEE80211_OFDM_RATE_54MB_MASK)
830 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
831                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
832
833 #define IEEE80211_NUM_OFDM_RATES            8
834 #define IEEE80211_NUM_CCK_RATES             4
835 #define IEEE80211_OFDM_SHIFT_MASK_A         4
836
837
838 /* this is stolen and modified from the madwifi driver*/
839 #define IEEE80211_FC0_TYPE_MASK         0x0c
840 #define IEEE80211_FC0_TYPE_DATA         0x08
841 #define IEEE80211_FC0_SUBTYPE_MASK      0xB0
842 #define IEEE80211_FC0_SUBTYPE_QOS       0x80
843
844 #define IEEE80211_QOS_HAS_SEQ(fc) \
845         (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
846          (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
847
848 /* this is stolen from ipw2200 driver */
849 #define IEEE_IBSS_MAC_HASH_SIZE 31
850 struct ieee_ibss_seq {
851         u8 mac[ETH_ALEN];
852         u16 seq_num[17];
853         u16 frag_num[17];
854         unsigned long packet_time[17];
855         struct list_head list;
856 };
857
858 /* NOTE: This data is for statistical purposes; not all hardware provides this
859  *       information for frames received.  Not setting these will not cause
860  *       any adverse affects. */
861 struct ieee80211_rx_stats {
862         u32 mac_time[2];
863         s8 rssi;
864         u8 signal;
865         u8 noise;
866         u16 rate; /* in 100 kbps */
867         u8 received_channel;
868         u8 control;
869         u8 mask;
870         u8 freq;
871         u16 len;
872         u64 tsf;
873         u32 beacon_time;
874         u8 nic_type;
875         u16       Length;
876         //      u8        DataRate;      // In 0.5 Mbps
877         u8        SignalQuality; // in 0-100 index.
878         s32       RecvSignalPower; // Real power in dBm for this packet, no beautification and aggregation.
879         s8        RxPower; // in dBm Translate from PWdB
880         u8        SignalStrength; // in 0-100 index.
881         u16       bHwError:1;
882         u16       bCRC:1;
883         u16       bICV:1;
884         u16       bShortPreamble:1;
885         u16       Antenna:1;      //for rtl8185
886         u16       Decrypted:1;    //for rtl8185, rtl8187
887         u16       Wakeup:1;       //for rtl8185
888         u16       Reserved0:1;    //for rtl8185
889         u8        AGC;
890         u32       TimeStampLow;
891         u32       TimeStampHigh;
892         bool      bShift;
893         bool      bIsQosData;             // Added by Annie, 2005-12-22.
894         u8        UserPriority;
895
896         //1!!!!!!!!!!!!!!!!!!!!!!!!!!!
897         //1Attention Please!!!<11n or 8190 specific code should be put below this line>
898         //1!!!!!!!!!!!!!!!!!!!!!!!!!!!
899
900         u8        RxDrvInfoSize;
901         u8        RxBufShift;
902         bool      bIsAMPDU;
903         bool      bFirstMPDU;
904         bool      bContainHTC;
905         bool      RxIs40MHzPacket;
906         u32       RxPWDBAll;
907         u8        RxMIMOSignalStrength[4];        // in 0~100 index
908         s8        RxMIMOSignalQuality[2];
909         bool      bPacketMatchBSSID;
910         bool      bIsCCK;
911         bool      bPacketToSelf;
912         //added by amy
913         u8*       virtual_address;
914         u16          packetlength;              // Total packet length: Must equal to sum of all FragLength
915         u16          fraglength;                        // FragLength should equal to PacketLength in non-fragment case
916         u16          fragoffset;                        // Data offset for this fragment
917         u16          ntotalfrag;
918         bool              bisrxaggrsubframe;
919         bool              bPacketBeacon;        //cosa add for rssi
920         bool              bToSelfBA;            //cosa add for rssi
921         char      cck_adc_pwdb[4];      //cosa add for rx path selection
922         u16               Seq_Num;
923
924 };
925
926 /* IEEE 802.11 requires that STA supports concurrent reception of at least
927  * three fragmented frames. This define can be increased to support more
928  * concurrent frames, but it should be noted that each entry can consume about
929  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
930 #define IEEE80211_FRAG_CACHE_LEN 4
931
932 struct ieee80211_frag_entry {
933         unsigned long first_frag_time;
934         unsigned int seq;
935         unsigned int last_frag;
936         struct sk_buff *skb;
937         u8 src_addr[ETH_ALEN];
938         u8 dst_addr[ETH_ALEN];
939 };
940
941 struct ieee80211_stats {
942         unsigned int tx_unicast_frames;
943         unsigned int tx_multicast_frames;
944         unsigned int tx_fragments;
945         unsigned int tx_unicast_octets;
946         unsigned int tx_multicast_octets;
947         unsigned int tx_deferred_transmissions;
948         unsigned int tx_single_retry_frames;
949         unsigned int tx_multiple_retry_frames;
950         unsigned int tx_retry_limit_exceeded;
951         unsigned int tx_discards;
952         unsigned int rx_unicast_frames;
953         unsigned int rx_multicast_frames;
954         unsigned int rx_fragments;
955         unsigned int rx_unicast_octets;
956         unsigned int rx_multicast_octets;
957         unsigned int rx_fcs_errors;
958         unsigned int rx_discards_no_buffer;
959         unsigned int tx_discards_wrong_sa;
960         unsigned int rx_discards_undecryptable;
961         unsigned int rx_message_in_msg_fragments;
962         unsigned int rx_message_in_bad_msg_fragments;
963 };
964
965 struct ieee80211_device;
966
967 #include "ieee80211_crypt.h"
968
969 #define SEC_KEY_1         (1<<0)
970 #define SEC_KEY_2         (1<<1)
971 #define SEC_KEY_3         (1<<2)
972 #define SEC_KEY_4         (1<<3)
973 #define SEC_ACTIVE_KEY    (1<<4)
974 #define SEC_AUTH_MODE     (1<<5)
975 #define SEC_UNICAST_GROUP (1<<6)
976 #define SEC_LEVEL         (1<<7)
977 #define SEC_ENABLED       (1<<8)
978 #define SEC_ENCRYPT       (1<<9)
979
980 #define SEC_LEVEL_0      0 /* None */
981 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
982 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
983 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
984 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
985
986 #define SEC_ALG_NONE            0
987 #define SEC_ALG_WEP             1
988 #define SEC_ALG_TKIP            2
989 #define SEC_ALG_CCMP            3
990
991 #define WEP_KEYS                4
992 #define WEP_KEY_LEN             13
993 #define SCM_KEY_LEN             32
994 #define SCM_TEMPORAL_KEY_LENGTH 16
995
996 struct ieee80211_security {
997         u16 active_key:2,
998             enabled:1,
999             auth_mode:2,
1000             auth_algo:4,
1001             unicast_uses_group:1,
1002             encrypt:1;
1003         u8 key_sizes[WEP_KEYS];
1004         u8 keys[WEP_KEYS][SCM_KEY_LEN];
1005         u8 level;
1006         u16 flags;
1007 } __attribute__ ((packed));
1008
1009
1010 /*
1011  802.11 data frame from AP
1012       ,-------------------------------------------------------------------.
1013 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
1014       |------|------|---------|---------|---------|------|---------|------|
1015 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
1016       |      | tion | (BSSID) |         |         | ence |  data   |      |
1017       `-------------------------------------------------------------------'
1018 Total: 28-2340 bytes
1019 */
1020
1021 /* Management Frame Information Element Types */
1022 enum ieee80211_mfie {
1023         MFIE_TYPE_SSID = 0,
1024         MFIE_TYPE_RATES = 1,
1025         MFIE_TYPE_FH_SET = 2,
1026         MFIE_TYPE_DS_SET = 3,
1027         MFIE_TYPE_CF_SET = 4,
1028         MFIE_TYPE_TIM = 5,
1029         MFIE_TYPE_IBSS_SET = 6,
1030         MFIE_TYPE_COUNTRY = 7,
1031         MFIE_TYPE_HOP_PARAMS = 8,
1032         MFIE_TYPE_HOP_TABLE = 9,
1033         MFIE_TYPE_REQUEST = 10,
1034         MFIE_TYPE_CHALLENGE = 16,
1035         MFIE_TYPE_POWER_CONSTRAINT = 32,
1036         MFIE_TYPE_POWER_CAPABILITY = 33,
1037         MFIE_TYPE_TPC_REQUEST = 34,
1038         MFIE_TYPE_TPC_REPORT = 35,
1039         MFIE_TYPE_SUPP_CHANNELS = 36,
1040         MFIE_TYPE_CSA = 37,
1041         MFIE_TYPE_MEASURE_REQUEST = 38,
1042         MFIE_TYPE_MEASURE_REPORT = 39,
1043         MFIE_TYPE_QUIET = 40,
1044         MFIE_TYPE_IBSS_DFS = 41,
1045         MFIE_TYPE_ERP = 42,
1046         MFIE_TYPE_RSN = 48,
1047         MFIE_TYPE_RATES_EX = 50,
1048         MFIE_TYPE_HT_CAP= 45,
1049          MFIE_TYPE_HT_INFO= 61,
1050          MFIE_TYPE_AIRONET=133,
1051         MFIE_TYPE_GENERIC = 221,
1052         MFIE_TYPE_QOS_PARAMETER = 222,
1053 };
1054
1055 /* Minimal header; can be used for passing 802.11 frames with sufficient
1056  * information to determine what type of underlying data type is actually
1057  * stored in the data. */
1058 struct ieee80211_hdr {
1059         __le16 frame_ctl;
1060         __le16 duration_id;
1061         u8 payload[0];
1062 } __attribute__ ((packed));
1063
1064 struct ieee80211_hdr_1addr {
1065         __le16 frame_ctl;
1066         __le16 duration_id;
1067         u8 addr1[ETH_ALEN];
1068         u8 payload[0];
1069 } __attribute__ ((packed));
1070
1071 struct ieee80211_hdr_2addr {
1072         __le16 frame_ctl;
1073         __le16 duration_id;
1074         u8 addr1[ETH_ALEN];
1075         u8 addr2[ETH_ALEN];
1076         u8 payload[0];
1077 } __attribute__ ((packed));
1078
1079 struct ieee80211_hdr_3addr {
1080         __le16 frame_ctl;
1081         __le16 duration_id;
1082         u8 addr1[ETH_ALEN];
1083         u8 addr2[ETH_ALEN];
1084         u8 addr3[ETH_ALEN];
1085         __le16 seq_ctl;
1086         u8 payload[0];
1087 } __attribute__ ((packed));
1088
1089 struct ieee80211_hdr_4addr {
1090         __le16 frame_ctl;
1091         __le16 duration_id;
1092         u8 addr1[ETH_ALEN];
1093         u8 addr2[ETH_ALEN];
1094         u8 addr3[ETH_ALEN];
1095         __le16 seq_ctl;
1096         u8 addr4[ETH_ALEN];
1097         u8 payload[0];
1098 } __attribute__ ((packed));
1099
1100 struct ieee80211_hdr_3addrqos {
1101         __le16 frame_ctl;
1102         __le16 duration_id;
1103         u8 addr1[ETH_ALEN];
1104         u8 addr2[ETH_ALEN];
1105         u8 addr3[ETH_ALEN];
1106         __le16 seq_ctl;
1107         u8 payload[0];
1108         __le16 qos_ctl;
1109 } __attribute__ ((packed));
1110
1111 struct ieee80211_hdr_4addrqos {
1112         __le16 frame_ctl;
1113         __le16 duration_id;
1114         u8 addr1[ETH_ALEN];
1115         u8 addr2[ETH_ALEN];
1116         u8 addr3[ETH_ALEN];
1117         __le16 seq_ctl;
1118         u8 addr4[ETH_ALEN];
1119         u8 payload[0];
1120         __le16 qos_ctl;
1121 } __attribute__ ((packed));
1122
1123 struct ieee80211_info_element {
1124         u8 id;
1125         u8 len;
1126         u8 data[0];
1127 } __attribute__ ((packed));
1128
1129 struct ieee80211_authentication {
1130         struct ieee80211_hdr_3addr header;
1131         __le16 algorithm;
1132         __le16 transaction;
1133         __le16 status;
1134         /*challenge*/
1135         struct ieee80211_info_element info_element[0];
1136 } __attribute__ ((packed));
1137
1138 struct ieee80211_disassoc {
1139         struct ieee80211_hdr_3addr header;
1140         __le16 reason;
1141 } __attribute__ ((packed));
1142
1143 struct ieee80211_probe_request {
1144         struct ieee80211_hdr_3addr header;
1145         /* SSID, supported rates */
1146         struct ieee80211_info_element info_element[0];
1147 } __attribute__ ((packed));
1148
1149 struct ieee80211_probe_response {
1150         struct ieee80211_hdr_3addr header;
1151         u32 time_stamp[2];
1152         __le16 beacon_interval;
1153         __le16 capability;
1154         /* SSID, supported rates, FH params, DS params,
1155          * CF params, IBSS params, TIM (if beacon), RSN */
1156         struct ieee80211_info_element info_element[0];
1157 } __attribute__ ((packed));
1158
1159 /* Alias beacon for probe_response */
1160 #define ieee80211_beacon ieee80211_probe_response
1161
1162 struct ieee80211_assoc_request_frame {
1163         struct ieee80211_hdr_3addr header;
1164         __le16 capability;
1165         __le16 listen_interval;
1166         /* SSID, supported rates, RSN */
1167         struct ieee80211_info_element info_element[0];
1168 } __attribute__ ((packed));
1169
1170 struct ieee80211_reassoc_request_frame {
1171         struct ieee80211_hdr_3addr header;
1172         __le16 capability;
1173         __le16 listen_interval;
1174         u8 current_ap[ETH_ALEN];
1175         /* SSID, supported rates, RSN */
1176         struct ieee80211_info_element info_element[0];
1177 } __attribute__ ((packed));
1178
1179 struct ieee80211_assoc_response_frame {
1180         struct ieee80211_hdr_3addr header;
1181         __le16 capability;
1182         __le16 status;
1183         __le16 aid;
1184         struct ieee80211_info_element info_element[0]; /* supported rates */
1185 } __attribute__ ((packed));
1186
1187 struct ieee80211_txb {
1188         u8 nr_frags;
1189         u8 encrypted;
1190         u8 queue_index;
1191         u8 rts_included;
1192         u16 reserved;
1193         __le16 frag_size;
1194         __le16 payload_size;
1195         struct sk_buff *fragments[0];
1196 };
1197
1198 #define MAX_TX_AGG_COUNT                  16
1199 struct ieee80211_drv_agg_txb {
1200         u8 nr_drv_agg_frames;
1201         struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT];
1202 }__attribute__((packed));
1203
1204 #define MAX_SUBFRAME_COUNT                64
1205 struct ieee80211_rxb {
1206         u8 nr_subframes;
1207         struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
1208         u8 dst[ETH_ALEN];
1209         u8 src[ETH_ALEN];
1210 }__attribute__((packed));
1211
1212 typedef union _frameqos {
1213         u16 shortdata;
1214         u8  chardata[2];
1215         struct {
1216                 u16 tid:4;
1217                 u16 eosp:1;
1218                 u16 ack_policy:2;
1219                 u16 reserved:1;
1220                 u16 txop:8;
1221         }field;
1222 }frameqos,*pframeqos;
1223
1224 /* SWEEP TABLE ENTRIES NUMBER*/
1225 #define MAX_SWEEP_TAB_ENTRIES             42
1226 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
1227 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
1228  * only use 8, and then use extended rates for the remaining supported
1229  * rates.  Other APs, however, stick all of their supported rates on the
1230  * main rates information element... */
1231 #define MAX_RATES_LENGTH                  ((u8)12)
1232 #define MAX_RATES_EX_LENGTH               ((u8)16)
1233 #define MAX_NETWORK_COUNT                  128
1234
1235 #define MAX_CHANNEL_NUMBER                 161
1236 #define IEEE80211_SOFTMAC_SCAN_TIME        100
1237 //(HZ / 2)
1238 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
1239
1240 #define CRC_LENGTH                 4U
1241
1242 #define MAX_WPA_IE_LEN 64
1243
1244 #define NETWORK_EMPTY_ESSID (1<<0)
1245 #define NETWORK_HAS_OFDM    (1<<1)
1246 #define NETWORK_HAS_CCK     (1<<2)
1247
1248 /* QoS structure */
1249 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
1250 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
1251 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
1252                                          NETWORK_HAS_QOS_INFORMATION)
1253 /* 802.11h */
1254 #define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
1255 #define NETWORK_HAS_CSA                 (1<<6)
1256 #define NETWORK_HAS_QUIET               (1<<7)
1257 #define NETWORK_HAS_IBSS_DFS            (1<<8)
1258 #define NETWORK_HAS_TPC_REPORT          (1<<9)
1259
1260 #define NETWORK_HAS_ERP_VALUE           (1<<10)
1261
1262 #define QOS_QUEUE_NUM                   4
1263 #define QOS_OUI_LEN                     3
1264 #define QOS_OUI_TYPE                    2
1265 #define QOS_ELEMENT_ID                  221
1266 #define QOS_OUI_INFO_SUB_TYPE           0
1267 #define QOS_OUI_PARAM_SUB_TYPE          1
1268 #define QOS_VERSION_1                   1
1269 #define QOS_AIFSN_MIN_VALUE             2
1270 struct ieee80211_qos_information_element {
1271         u8 elementID;
1272         u8 length;
1273         u8 qui[QOS_OUI_LEN];
1274         u8 qui_type;
1275         u8 qui_subtype;
1276         u8 version;
1277         u8 ac_info;
1278 } __attribute__ ((packed));
1279
1280 struct ieee80211_qos_ac_parameter {
1281         u8 aci_aifsn;
1282         u8 ecw_min_max;
1283         __le16 tx_op_limit;
1284 } __attribute__ ((packed));
1285
1286 struct ieee80211_qos_parameter_info {
1287         struct ieee80211_qos_information_element info_element;
1288         u8 reserved;
1289         struct ieee80211_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
1290 } __attribute__ ((packed));
1291
1292 struct ieee80211_qos_parameters {
1293         __le16 cw_min[QOS_QUEUE_NUM];
1294         __le16 cw_max[QOS_QUEUE_NUM];
1295         u8 aifs[QOS_QUEUE_NUM];
1296         u8 flag[QOS_QUEUE_NUM];
1297         __le16 tx_op_limit[QOS_QUEUE_NUM];
1298 } __attribute__ ((packed));
1299
1300 struct ieee80211_qos_data {
1301         struct ieee80211_qos_parameters parameters;
1302         int active;
1303         int supported;
1304         u8 param_count;
1305         u8 old_param_count;
1306 };
1307
1308 struct ieee80211_tim_parameters {
1309         u8 tim_count;
1310         u8 tim_period;
1311 } __attribute__ ((packed));
1312
1313 //#else
1314 struct ieee80211_wmm_ac_param {
1315         u8 ac_aci_acm_aifsn;
1316         u8 ac_ecwmin_ecwmax;
1317         u16 ac_txop_limit;
1318 };
1319
1320 struct ieee80211_wmm_ts_info {
1321         u8 ac_dir_tid;
1322         u8 ac_up_psb;
1323         u8 reserved;
1324 } __attribute__ ((packed));
1325
1326 struct ieee80211_wmm_tspec_elem {
1327         struct ieee80211_wmm_ts_info ts_info;
1328         u16 norm_msdu_size;
1329         u16 max_msdu_size;
1330         u32 min_serv_inter;
1331         u32 max_serv_inter;
1332         u32 inact_inter;
1333         u32 suspen_inter;
1334         u32 serv_start_time;
1335         u32 min_data_rate;
1336         u32 mean_data_rate;
1337         u32 peak_data_rate;
1338         u32 max_burst_size;
1339         u32 delay_bound;
1340         u32 min_phy_rate;
1341         u16 surp_band_allow;
1342         u16 medium_time;
1343 }__attribute__((packed));
1344 enum eap_type {
1345         EAP_PACKET = 0,
1346         EAPOL_START,
1347         EAPOL_LOGOFF,
1348         EAPOL_KEY,
1349         EAPOL_ENCAP_ASF_ALERT
1350 };
1351
1352 static const char *eap_types[] = {
1353         [EAP_PACKET]            = "EAP-Packet",
1354         [EAPOL_START]           = "EAPOL-Start",
1355         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
1356         [EAPOL_KEY]             = "EAPOL-Key",
1357         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
1358 };
1359
1360 static inline const char *eap_get_type(int type)
1361 {
1362         return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
1363 }
1364 //added by amy for reorder
1365 static inline u8 Frame_QoSTID(u8* buf)
1366 {
1367         struct ieee80211_hdr_3addr *hdr;
1368         u16 fc;
1369         hdr = (struct ieee80211_hdr_3addr *)buf;
1370         fc = le16_to_cpu(hdr->frame_ctl);
1371         return (u8)((frameqos*)(buf + (((fc & IEEE80211_FCTL_TODS)&&(fc & IEEE80211_FCTL_FROMDS))? 30 : 24)))->field.tid;
1372 }
1373
1374 //added by amy for reorder
1375
1376 struct eapol {
1377         u8 snap[6];
1378         u16 ethertype;
1379         u8 version;
1380         u8 type;
1381         u16 length;
1382 } __attribute__ ((packed));
1383
1384 struct ieee80211_softmac_stats{
1385         unsigned int rx_ass_ok;
1386         unsigned int rx_ass_err;
1387         unsigned int rx_probe_rq;
1388         unsigned int tx_probe_rs;
1389         unsigned int tx_beacons;
1390         unsigned int rx_auth_rq;
1391         unsigned int rx_auth_rs_ok;
1392         unsigned int rx_auth_rs_err;
1393         unsigned int tx_auth_rq;
1394         unsigned int no_auth_rs;
1395         unsigned int no_ass_rs;
1396         unsigned int tx_ass_rq;
1397         unsigned int rx_ass_rq;
1398         unsigned int tx_probe_rq;
1399         unsigned int reassoc;
1400         unsigned int swtxstop;
1401         unsigned int swtxawake;
1402         unsigned char CurrentShowTxate;
1403         unsigned char last_packet_rate;
1404         unsigned int txretrycount;
1405 };
1406
1407 #define BEACON_PROBE_SSID_ID_POSITION 12
1408
1409 struct ieee80211_info_element_hdr {
1410         u8 id;
1411         u8 len;
1412 } __attribute__ ((packed));
1413
1414 /*
1415  * These are the data types that can make up management packets
1416  *
1417         u16 auth_algorithm;
1418         u16 auth_sequence;
1419         u16 beacon_interval;
1420         u16 capability;
1421         u8 current_ap[ETH_ALEN];
1422         u16 listen_interval;
1423         struct {
1424                 u16 association_id:14, reserved:2;
1425         } __attribute__ ((packed));
1426         u32 time_stamp[2];
1427         u16 reason;
1428         u16 status;
1429 */
1430
1431 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
1432 #define IEEE80211_DEFAULT_BASIC_RATE 2 //1Mbps
1433
1434 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1435 #define MAX_SP_Len  (WMM_all_frame << 4)
1436 #define IEEE80211_QOS_TID 0x0f
1437 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1438
1439 #define IEEE80211_DTIM_MBCAST 4
1440 #define IEEE80211_DTIM_UCAST 2
1441 #define IEEE80211_DTIM_VALID 1
1442 #define IEEE80211_DTIM_INVALID 0
1443
1444 #define IEEE80211_PS_DISABLED 0
1445 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
1446 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
1447
1448 //added by David for QoS 2006/6/30
1449 //#define WMM_Hang_8187
1450 #ifdef WMM_Hang_8187
1451 #undef WMM_Hang_8187
1452 #endif
1453
1454 #define WME_AC_BK   0x00
1455 #define WME_AC_BE   0x01
1456 #define WME_AC_VI   0x02
1457 #define WME_AC_VO   0x03
1458 #define WME_ACI_MASK 0x03
1459 #define WME_AIFSN_MASK 0x03
1460 #define WME_AC_PRAM_LEN 16
1461
1462 #define MAX_RECEIVE_BUFFER_SIZE 9100
1463
1464 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
1465 //#define UP2AC(up)     ((up<3) ? ((up==0)?1:0) : (up>>1))
1466 #define UP2AC(up) (                \
1467         ((up) < 1) ? WME_AC_BE : \
1468         ((up) < 3) ? WME_AC_BK : \
1469         ((up) < 4) ? WME_AC_BE : \
1470         ((up) < 6) ? WME_AC_VI : \
1471         WME_AC_VO)
1472 //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
1473 #define AC2UP(_ac)      (       \
1474         ((_ac) == WME_AC_VO) ? 6 : \
1475         ((_ac) == WME_AC_VI) ? 5 : \
1476         ((_ac) == WME_AC_BK) ? 1 : \
1477         0)
1478
1479 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
1480 #define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address plus ether type*/
1481
1482 struct  ether_header {
1483         u8 ether_dhost[ETHER_ADDR_LEN];
1484         u8 ether_shost[ETHER_ADDR_LEN];
1485         u16 ether_type;
1486 } __attribute__((packed));
1487
1488 #ifndef ETHERTYPE_PAE
1489 #define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
1490 #endif
1491 #ifndef ETHERTYPE_IP
1492 #define ETHERTYPE_IP    0x0800          /* IP protocol */
1493 #endif
1494
1495 typedef struct _bss_ht{
1496
1497         bool                            support_ht;
1498
1499         // HT related elements
1500         u8                                      ht_cap_buf[32];
1501         u16                                     ht_cap_len;
1502         u8                                      ht_info_buf[32];
1503         u16                                     ht_info_len;
1504
1505         HT_SPEC_VER                     ht_spec_ver;
1506         //HT_CAPABILITY_ELE                     bdHTCapEle;
1507         //HT_INFORMATION_ELE            bdHTInfoEle;
1508
1509         bool                            aggregation;
1510         bool                            long_slot_time;
1511 }bss_ht, *pbss_ht;
1512
1513 typedef enum _erp_t{
1514         ERP_NonERPpresent       = 0x01,
1515         ERP_UseProtection       = 0x02,
1516         ERP_BarkerPreambleMode = 0x04,
1517 } erp_t;
1518
1519
1520 struct ieee80211_network {
1521         /* These entries are used to identify a unique network */
1522         u8 bssid[ETH_ALEN];
1523         u8 channel;
1524         /* Ensure null-terminated for any debug msgs */
1525         u8 ssid[IW_ESSID_MAX_SIZE + 1];
1526         u8 ssid_len;
1527         struct ieee80211_qos_data qos_data;
1528
1529         //added by amy for LEAP
1530         bool    bWithAironetIE;
1531         bool    bCkipSupported;
1532         bool    bCcxRmEnable;
1533         u16     CcxRmState[2];
1534         // CCXv4 S59, MBSSID.
1535         bool    bMBssidValid;
1536         u8      MBssidMask;
1537         u8      MBssid[6];
1538         // CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20.
1539         bool    bWithCcxVerNum;
1540         u8      BssCcxVerNumber;
1541         /* These are network statistics */
1542         struct ieee80211_rx_stats stats;
1543         u16 capability;
1544         u8  rates[MAX_RATES_LENGTH];
1545         u8  rates_len;
1546         u8  rates_ex[MAX_RATES_EX_LENGTH];
1547         u8  rates_ex_len;
1548         unsigned long last_scanned;
1549         u8  mode;
1550         u32 flags;
1551         u32 last_associate;
1552         u32 time_stamp[2];
1553         u16 beacon_interval;
1554         u16 listen_interval;
1555         u16 atim_window;
1556         u8  erp_value;
1557         u8  wpa_ie[MAX_WPA_IE_LEN];
1558         size_t wpa_ie_len;
1559         u8  rsn_ie[MAX_WPA_IE_LEN];
1560         size_t rsn_ie_len;
1561
1562         struct ieee80211_tim_parameters tim;
1563         u8  dtim_period;
1564         u8  dtim_data;
1565         u32 last_dtim_sta_time[2];
1566
1567         //appeded for QoS
1568         u8 wmm_info;
1569         struct ieee80211_wmm_ac_param wmm_param[4];
1570         u8 QoS_Enable;
1571 #ifdef THOMAS_TURBO
1572         u8 Turbo_Enable;//enable turbo mode, added by thomas
1573 #endif
1574 #ifdef ENABLE_DOT11D
1575         u16 CountryIeLen;
1576         u8 CountryIeBuf[MAX_IE_LEN];
1577 #endif
1578         // HT Related, by amy, 2008.04.29
1579         BSS_HT  bssht;
1580         // Add to handle broadcom AP management frame CCK rate.
1581         bool broadcom_cap_exist;
1582         bool ralink_cap_exist;
1583         bool atheros_cap_exist;
1584         bool cisco_cap_exist;
1585         bool unknown_cap_exist;
1586 //      u8      berp_info;
1587         bool    berp_info_valid;
1588         bool buseprotection;
1589         //put at the end of the structure.
1590         struct list_head list;
1591 };
1592
1593 enum ieee80211_state {
1594
1595         /* the card is not linked at all */
1596         IEEE80211_NOLINK = 0,
1597
1598         /* IEEE80211_ASSOCIATING* are for BSS client mode
1599          * the driver shall not perform RX filtering unless
1600          * the state is LINKED.
1601          * The driver shall just check for the state LINKED and
1602          * defaults to NOLINK for ALL the other states (including
1603          * LINKED_SCANNING)
1604          */
1605
1606         /* the association procedure will start (wq scheduling)*/
1607         IEEE80211_ASSOCIATING,
1608         IEEE80211_ASSOCIATING_RETRY,
1609
1610         /* the association procedure is sending AUTH request*/
1611         IEEE80211_ASSOCIATING_AUTHENTICATING,
1612
1613         /* the association procedure has successfully authentcated
1614          * and is sending association request
1615          */
1616         IEEE80211_ASSOCIATING_AUTHENTICATED,
1617
1618         /* the link is ok. the card associated to a BSS or linked
1619          * to a ibss cell or acting as an AP and creating the bss
1620          */
1621         IEEE80211_LINKED,
1622
1623         /* same as LINKED, but the driver shall apply RX filter
1624          * rules as we are in NO_LINK mode. As the card is still
1625          * logically linked, but it is doing a syncro site survey
1626          * then it will be back to LINKED state.
1627          */
1628         IEEE80211_LINKED_SCANNING,
1629
1630 };
1631
1632 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1633 #define DEFAULT_FTS 2346
1634
1635 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
1636 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
1637 #define CFG_IEEE80211_RTS (1<<2)
1638
1639 #define IEEE80211_24GHZ_MIN_CHANNEL 1
1640 #define IEEE80211_24GHZ_MAX_CHANNEL 14
1641 #define IEEE80211_24GHZ_CHANNELS (IEEE80211_24GHZ_MAX_CHANNEL - \
1642                                   IEEE80211_24GHZ_MIN_CHANNEL + 1)
1643
1644 #define IEEE80211_52GHZ_MIN_CHANNEL 34
1645 #define IEEE80211_52GHZ_MAX_CHANNEL 165
1646 #define IEEE80211_52GHZ_CHANNELS (IEEE80211_52GHZ_MAX_CHANNEL - \
1647                                   IEEE80211_52GHZ_MIN_CHANNEL + 1)
1648
1649
1650
1651 typedef struct tx_pending_t{
1652         int frag;
1653         struct ieee80211_txb *txb;
1654 }tx_pending_t;
1655
1656 typedef struct _bandwidth_autoswitch
1657 {
1658         long threshold_20Mhzto40Mhz;
1659         long    threshold_40Mhzto20Mhz;
1660         bool bforced_tx20Mhz;
1661         bool bautoswitch_enable;
1662 }bandwidth_autoswitch,*pbandwidth_autoswitch;
1663
1664
1665 //added by amy for order
1666
1667 #define REORDER_WIN_SIZE        128
1668 #define REORDER_ENTRY_NUM       128
1669 typedef struct _RX_REORDER_ENTRY
1670 {
1671         struct list_head        List;
1672         u16                     SeqNum;
1673         struct ieee80211_rxb* prxb;
1674 } RX_REORDER_ENTRY, *PRX_REORDER_ENTRY;
1675 //added by amy for order
1676 typedef enum _Fsync_State{
1677         Default_Fsync,
1678         HW_Fsync,
1679         SW_Fsync
1680 }Fsync_State;
1681
1682 // Power save mode configured.
1683 typedef enum _RT_PS_MODE
1684 {
1685         eActive,        // Active/Continuous access.
1686         eMaxPs,         // Max power save mode.
1687         eFastPs         // Fast power save mode.
1688 }RT_PS_MODE;
1689
1690 typedef enum _IPS_CALLBACK_FUNCION
1691 {
1692         IPS_CALLBACK_NONE = 0,
1693         IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1694         IPS_CALLBACK_JOIN_REQUEST = 2,
1695 }IPS_CALLBACK_FUNCION;
1696
1697 typedef enum _RT_JOIN_ACTION{
1698         RT_JOIN_INFRA   = 1,
1699         RT_JOIN_IBSS  = 2,
1700         RT_START_IBSS = 3,
1701         RT_NO_ACTION  = 4,
1702 }RT_JOIN_ACTION;
1703
1704 typedef struct _IbssParms{
1705         u16   atimWin;
1706 }IbssParms, *PIbssParms;
1707 #define MAX_NUM_RATES   264 // Max num of support rates element: 8,  Max num of ext. support rate: 255. 061122, by rcnjko.
1708
1709 // RF state.
1710 typedef enum _RT_RF_POWER_STATE
1711 {
1712         eRfOn,
1713         eRfSleep,
1714         eRfOff
1715 }RT_RF_POWER_STATE;
1716
1717 typedef struct _RT_POWER_SAVE_CONTROL
1718 {
1719
1720         //
1721         // Inactive Power Save(IPS) : Disable RF when disconnected
1722         //
1723         bool                            bInactivePs;
1724         bool                            bIPSModeBackup;
1725         bool                            bSwRfProcessing;
1726         RT_RF_POWER_STATE       eInactivePowerState;
1727         struct work_struct      InactivePsWorkItem;
1728         struct timer_list       InactivePsTimer;
1729
1730         // Return point for join action
1731         IPS_CALLBACK_FUNCION    ReturnPoint;
1732
1733         // Recored Parameters for rescheduled JoinRequest
1734         bool                            bTmpBssDesc;
1735         RT_JOIN_ACTION          tmpJoinAction;
1736         struct ieee80211_network tmpBssDesc;
1737
1738         // Recored Parameters for rescheduled MgntLinkRequest
1739         bool                            bTmpScanOnly;
1740         bool                            bTmpActiveScan;
1741         bool                            bTmpFilterHiddenAP;
1742         bool                            bTmpUpdateParms;
1743         u8                                      tmpSsidBuf[33];
1744         OCTET_STRING                    tmpSsid2Scan;
1745         bool                            bTmpSsid2Scan;
1746         u8                                      tmpNetworkType;
1747         u8                                      tmpChannelNumber;
1748         u16                                     tmpBcnPeriod;
1749         u8                                      tmpDtimPeriod;
1750         u16                                     tmpmCap;
1751         OCTET_STRING                    tmpSuppRateSet;
1752         u8                                      tmpSuppRateBuf[MAX_NUM_RATES];
1753         bool                            bTmpSuppRate;
1754         IbssParms                               tmpIbpm;
1755         bool                            bTmpIbpm;
1756
1757         //
1758         // Leisre Poswer Save : Disable RF if connected but traffic is not busy
1759         //
1760         bool                            bLeisurePs;
1761
1762 }RT_POWER_SAVE_CONTROL,*PRT_POWER_SAVE_CONTROL;
1763
1764 typedef u32 RT_RF_CHANGE_SOURCE;
1765 #define RF_CHANGE_BY_SW BIT31
1766 #define RF_CHANGE_BY_HW BIT30
1767 #define RF_CHANGE_BY_PS BIT29
1768 #define RF_CHANGE_BY_IPS BIT28
1769 #define RF_CHANGE_BY_INIT       0       // Do not change the RFOff reason. Defined by Bruce, 2008-01-17.
1770
1771 #ifdef ENABLE_DOT11D
1772 typedef enum
1773 {
1774         COUNTRY_CODE_FCC = 0,
1775         COUNTRY_CODE_IC = 1,
1776         COUNTRY_CODE_ETSI = 2,
1777         COUNTRY_CODE_SPAIN = 3,
1778         COUNTRY_CODE_FRANCE = 4,
1779         COUNTRY_CODE_MKK = 5,
1780         COUNTRY_CODE_MKK1 = 6,
1781         COUNTRY_CODE_ISRAEL = 7,
1782         COUNTRY_CODE_TELEC,
1783         COUNTRY_CODE_MIC,
1784         COUNTRY_CODE_GLOBAL_DOMAIN
1785 }country_code_type_t;
1786 #endif
1787
1788 #define RT_MAX_LD_SLOT_NUM      10
1789 typedef struct _RT_LINK_DETECT_T{
1790
1791         u32                             NumRecvBcnInPeriod;
1792         u32                             NumRecvDataInPeriod;
1793
1794         u32                             RxBcnNum[RT_MAX_LD_SLOT_NUM];   // number of Rx beacon / CheckForHang_period  to determine link status
1795         u32                             RxDataNum[RT_MAX_LD_SLOT_NUM];  // number of Rx data / CheckForHang_period  to determine link status
1796         u16                             SlotNum;        // number of CheckForHang period to determine link status
1797         u16                             SlotIndex;
1798
1799         u32                             NumTxOkInPeriod;
1800         u32                             NumRxOkInPeriod;
1801         bool                            bBusyTraffic;
1802 }RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
1803
1804
1805 struct ieee80211_device {
1806         struct net_device *dev;
1807         struct ieee80211_security sec;
1808
1809         //hw security related
1810 //      u8 hwsec_support; //support?
1811         u8 hwsec_active;  //hw security active.
1812         bool is_silent_reset;
1813         bool ieee_up;
1814         //added by amy
1815         bool bSupportRemoteWakeUp;
1816         RT_PS_MODE      dot11PowerSaveMode; // Power save mode configured.
1817         bool actscanning;
1818         bool beinretry;
1819         RT_RF_POWER_STATE               eRFPowerState;
1820         RT_RF_CHANGE_SOURCE     RfOffReason;
1821         bool is_set_key;
1822         //11n spec related I wonder if These info structure need to be moved out of ieee80211_device
1823
1824         //11n HT below
1825         PRT_HIGH_THROUGHPUT     pHTInfo;
1826         //struct timer_list             SwBwTimer;
1827 //      spinlock_t chnlop_spinlock;
1828         spinlock_t bw_spinlock;
1829
1830         spinlock_t reorder_spinlock;
1831         // for HT operation rate set.  we use this one for HT data rate to seperate different descriptors
1832         //the way fill this is the same as in the IE
1833         u8      Regdot11HTOperationalRateSet[16];               //use RATR format
1834         u8      dot11HTOperationalRateSet[16];          //use RATR format
1835         u8      RegHTSuppRateSet[16];
1836         u8                              HTCurrentOperaRate;
1837         u8                              HTHighestOperaRate;
1838         //wb added for rate operation mode to firmware
1839         u8      bTxDisableRateFallBack;
1840         u8      bTxUseDriverAssingedRate;
1841         atomic_t        atm_chnlop;
1842         atomic_t        atm_swbw;
1843 //      u8      HTHighestOperaRate;
1844 //      u8      HTCurrentOperaRate;
1845
1846         // 802.11e and WMM Traffic Stream Info (TX)
1847         struct list_head                Tx_TS_Admit_List;
1848         struct list_head                Tx_TS_Pending_List;
1849         struct list_head                Tx_TS_Unused_List;
1850         TX_TS_RECORD            TxTsRecord[TOTAL_TS_NUM];
1851         // 802.11e and WMM Traffic Stream Info (RX)
1852         struct list_head                Rx_TS_Admit_List;
1853         struct list_head                Rx_TS_Pending_List;
1854         struct list_head                Rx_TS_Unused_List;
1855         RX_TS_RECORD            RxTsRecord[TOTAL_TS_NUM];
1856 //#ifdef TO_DO_LIST
1857         RX_REORDER_ENTRY        RxReorderEntry[128];
1858         struct list_head                RxReorder_Unused_List;
1859 //#endif
1860         // Qos related. Added by Annie, 2005-11-01.
1861 //      PSTA_QOS                        pStaQos;
1862         u8                              ForcedPriority;         // Force per-packet priority 1~7. (default: 0, not to force it.)
1863
1864
1865         /* Bookkeeping structures */
1866         struct net_device_stats stats;
1867         struct ieee80211_stats ieee_stats;
1868         struct ieee80211_softmac_stats softmac_stats;
1869
1870         /* Probe / Beacon management */
1871         struct list_head network_free_list;
1872         struct list_head network_list;
1873         struct ieee80211_network *networks;
1874         int scans;
1875         int scan_age;
1876
1877         int iw_mode; /* operating mode (IW_MODE_*) */
1878         struct iw_spy_data spy_data;
1879
1880         spinlock_t lock;
1881         spinlock_t wpax_suitlist_lock;
1882
1883         int tx_headroom; /* Set to size of any additional room needed at front
1884                           * of allocated Tx SKBs */
1885         u32 config;
1886
1887         /* WEP and other encryption related settings at the device level */
1888         int open_wep; /* Set to 1 to allow unencrypted frames */
1889         int auth_mode;
1890         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1891                                  * WEP key changes */
1892
1893         /* If the host performs {en,de}cryption, then set to 1 */
1894         int host_encrypt;
1895         int host_encrypt_msdu;
1896         int host_decrypt;
1897         /* host performs multicast decryption */
1898         int host_mc_decrypt;
1899
1900         /* host should strip IV and ICV from protected frames */
1901         /* meaningful only when hardware decryption is being used */
1902         int host_strip_iv_icv;
1903
1904         int host_open_frag;
1905         int host_build_iv;
1906         int ieee802_1x; /* is IEEE 802.1X used */
1907
1908         /* WPA data */
1909         bool bHalfWirelessN24GMode;
1910         int wpa_enabled;
1911         int drop_unencrypted;
1912         int tkip_countermeasures;
1913         int privacy_invoked;
1914         size_t wpa_ie_len;
1915         u8 *wpa_ie;
1916         u8 ap_mac_addr[6];
1917         u16 pairwise_key_type;
1918         u16 group_key_type;
1919         struct list_head crypt_deinit_list;
1920         struct ieee80211_crypt_data *crypt[WEP_KEYS];
1921         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
1922         struct timer_list crypt_deinit_timer;
1923         int crypt_quiesced;
1924
1925         int bcrx_sta_key; /* use individual keys to override default keys even
1926                            * with RX of broad/multicast frames */
1927
1928         /* Fragmentation structures */
1929         // each streaming contain a entry
1930         struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
1931         unsigned int frag_next_idx[17];
1932         u16 fts; /* Fragmentation Threshold */
1933 #define DEFAULT_RTS_THRESHOLD 2346U
1934 #define MIN_RTS_THRESHOLD 1
1935 #define MAX_RTS_THRESHOLD 2346U
1936         u16 rts; /* RTS threshold */
1937
1938         /* Association info */
1939         u8 bssid[ETH_ALEN];
1940
1941         /* This stores infos for the current network.
1942          * Either the network we are associated in INFRASTRUCTURE
1943          * or the network that we are creating in MASTER mode.
1944          * ad-hoc is a mixture ;-).
1945          * Note that in infrastructure mode, even when not associated,
1946          * fields bssid and essid may be valid (if wpa_set and essid_set
1947          * are true) as thy carry the value set by the user via iwconfig
1948          */
1949         struct ieee80211_network current_network;
1950
1951         enum ieee80211_state state;
1952
1953         int short_slot;
1954         int reg_mode;
1955         int mode;       /* A, B, G */
1956         int modulation; /* CCK, OFDM */
1957         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
1958         int abg_true;   /* ABG flag              */
1959
1960         /* used for forcing the ibss workqueue to terminate
1961          * without wait for the syncro scan to terminate
1962          */
1963         short sync_scan_hurryup;
1964
1965         int perfect_rssi;
1966         int worst_rssi;
1967
1968         u16 prev_seq_ctl;       /* used to drop duplicate frames */
1969
1970         /* map of allowed channels. 0 is dummy */
1971         // FIXME: remeber to default to a basic channel plan depending of the PHY type
1972 #ifdef ENABLE_DOT11D
1973         void* pDot11dInfo;
1974         bool bGlobalDomain;
1975 #else
1976         int channel_map[MAX_CHANNEL_NUMBER+1];
1977 #endif
1978         int rate;       /* current rate */
1979         int basic_rate;
1980         //FIXME: pleace callback, see if redundant with softmac_features
1981         short active_scan;
1982
1983         /* this contains flags for selectively enable softmac support */
1984         u16 softmac_features;
1985
1986         /* if the sequence control field is not filled by HW */
1987         u16 seq_ctrl[5];
1988
1989         /* association procedure transaction sequence number */
1990         u16 associate_seq;
1991
1992         /* AID for RTXed association responses */
1993         u16 assoc_id;
1994
1995         /* power save mode related*/
1996         short ps;
1997         short sta_sleep;
1998         int ps_timeout;
1999         int ps_period;
2000         struct tasklet_struct ps_task;
2001         u32 ps_th;
2002         u32 ps_tl;
2003
2004         short raw_tx;
2005         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2006         short queue_stop;
2007         short scanning;
2008         short proto_started;
2009
2010         struct semaphore wx_sem;
2011         struct semaphore scan_sem;
2012
2013         spinlock_t mgmt_tx_lock;
2014         spinlock_t beacon_lock;
2015
2016         short beacon_txing;
2017
2018         short wap_set;
2019         short ssid_set;
2020
2021         u8  wpax_type_set;    //{added by David, 2006.9.28}
2022         u32 wpax_type_notify; //{added by David, 2006.9.26}
2023
2024         /* QoS related flag */
2025         char init_wmmparam_flag;
2026         /* set on initialization */
2027         u8  qos_support;
2028
2029         /* for discarding duplicated packets in IBSS */
2030         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
2031
2032         /* for discarding duplicated packets in BSS */
2033         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
2034         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
2035         unsigned long last_packet_time[17];
2036
2037         /* for PS mode */
2038         unsigned long last_rx_ps_time;
2039
2040         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
2041         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
2042         int mgmt_queue_head;
2043         int mgmt_queue_tail;
2044 //{ added for rtl819x
2045 #define IEEE80211_QUEUE_LIMIT 128
2046         u8 AsocRetryCount;
2047         unsigned int hw_header;
2048         struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
2049         struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
2050         struct sk_buff_head  skb_drv_aggQ[MAX_QUEUE_SIZE];
2051         u32     sta_edca_param[4];
2052         bool aggregation;
2053         // Enable/Disable Rx immediate BA capability.
2054         bool enable_rx_imm_BA;
2055         bool bibsscoordinator;
2056
2057         //+by amy for DM ,080515
2058         //Dynamic Tx power for near/far range enable/Disable  , by amy , 2008-05-15
2059         bool    bdynamic_txpower_enable;
2060
2061         bool bCTSToSelfEnable;
2062         u8      CTSToSelfTH;
2063
2064         u32     fsync_time_interval;
2065         u32     fsync_rate_bitmap;
2066         u8      fsync_rssi_threshold;
2067         bool    bfsync_enable;
2068
2069         u8      fsync_multiple_timeinterval;            // FsyncMultipleTimeInterval * FsyncTimeInterval
2070         u32     fsync_firstdiff_ratethreshold;          // low threshold
2071         u32     fsync_seconddiff_ratethreshold;  // decrease threshold
2072         Fsync_State                     fsync_state;
2073         bool            bis_any_nonbepkts;
2074         //20Mhz 40Mhz AutoSwitch Threshold
2075         bandwidth_autoswitch bandwidth_auto_switch;
2076         //for txpower tracking
2077         bool FwRWRF;
2078
2079         //added by amy for AP roaming
2080         RT_LINK_DETECT_T        LinkDetectInfo;
2081         //added by amy for ps
2082         RT_POWER_SAVE_CONTROL   PowerSaveControl;
2083 //}
2084         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2085         struct  tx_pending_t tx_pending;
2086
2087         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
2088         struct timer_list associate_timer;
2089
2090         /* used if IEEE_SOFTMAC_BEACONS is set */
2091         struct timer_list beacon_timer;
2092         struct work_struct associate_complete_wq;
2093         struct work_struct associate_procedure_wq;
2094         struct delayed_work softmac_scan_wq;
2095         struct delayed_work associate_retry_wq;
2096          struct delayed_work start_ibss_wq;
2097         struct work_struct wx_sync_scan_wq;
2098         struct workqueue_struct *wq;
2099         // Qos related. Added by Annie, 2005-11-01.
2100         //STA_QOS  StaQos;
2101
2102         //u32 STA_EDCA_PARAM[4];
2103         //CHANNEL_ACCESS_SETTING ChannelAccessSetting;
2104
2105
2106         /* Callback functions */
2107         void (*set_security)(struct net_device *dev,
2108                              struct ieee80211_security *sec);
2109
2110         /* Used to TX data frame by using txb structs.
2111          * this is not used if in the softmac_features
2112          * is set the flag IEEE_SOFTMAC_TX_QUEUE
2113          */
2114         int (*hard_start_xmit)(struct ieee80211_txb *txb,
2115                                struct net_device *dev);
2116
2117         int (*reset_port)(struct net_device *dev);
2118         int (*is_queue_full) (struct net_device * dev, int pri);
2119
2120         int (*handle_management) (struct net_device * dev,
2121                                   struct ieee80211_network * network, u16 type);
2122         int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
2123
2124         /* Softmac-generated frames (mamagement) are TXed via this
2125          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
2126          * not set. As some cards may have different HW queues that
2127          * one might want to use for data and management frames
2128          * the option to have two callbacks might be useful.
2129          * This fucntion can't sleep.
2130          */
2131         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
2132                                struct net_device *dev);
2133
2134         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
2135          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
2136          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
2137          * then also management frames are sent via this callback.
2138          * This function can't sleep.
2139          */
2140         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
2141                                struct net_device *dev,int rate);
2142
2143         /* stops the HW queue for DATA frames. Useful to avoid
2144          * waste time to TX data frame when we are reassociating
2145          * This function can sleep.
2146          */
2147         void (*data_hard_stop)(struct net_device *dev);
2148
2149         /* OK this is complementar to data_poll_hard_stop */
2150         void (*data_hard_resume)(struct net_device *dev);
2151
2152         /* ask to the driver to retune the radio .
2153          * This function can sleep. the driver should ensure
2154          * the radio has been swithced before return.
2155          */
2156         void (*set_chan)(struct net_device *dev,short ch);
2157
2158         /* These are not used if the ieee stack takes care of
2159          * scanning (IEEE_SOFTMAC_SCAN feature set).
2160          * In this case only the set_chan is used.
2161          *
2162          * The syncro version is similar to the start_scan but
2163          * does not return until all channels has been scanned.
2164          * this is called in user context and should sleep,
2165          * it is called in a work_queue when swithcing to ad-hoc mode
2166          * or in behalf of iwlist scan when the card is associated
2167          * and root user ask for a scan.
2168          * the fucntion stop_scan should stop both the syncro and
2169          * background scanning and can sleep.
2170          * The fucntion start_scan should initiate the background
2171          * scanning and can't sleep.
2172          */
2173         void (*scan_syncro)(struct net_device *dev);
2174         void (*start_scan)(struct net_device *dev);
2175         void (*stop_scan)(struct net_device *dev);
2176
2177         /* indicate the driver that the link state is changed
2178          * for example it may indicate the card is associated now.
2179          * Driver might be interested in this to apply RX filter
2180          * rules or simply light the LINK led
2181          */
2182         void (*link_change)(struct net_device *dev);
2183
2184         /* these two function indicates to the HW when to start
2185          * and stop to send beacons. This is used when the
2186          * IEEE_SOFTMAC_BEACONS is not set. For now the
2187          * stop_send_bacons is NOT guaranteed to be called only
2188          * after start_send_beacons.
2189          */
2190         void (*start_send_beacons) (struct net_device *dev,u16 tx_rate);
2191         void (*stop_send_beacons) (struct net_device *dev);
2192
2193         /* power save mode related */
2194         void (*sta_wake_up) (struct net_device *dev);
2195         void (*ps_request_tx_ack) (struct net_device *dev);
2196         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
2197         short (*ps_is_queue_empty) (struct net_device *dev);
2198         int (*handle_beacon) (struct net_device * dev, struct ieee80211_beacon * beacon, struct ieee80211_network * network);
2199         int (*handle_assoc_response) (struct net_device * dev, struct ieee80211_assoc_response_frame * resp, struct ieee80211_network * network);
2200
2201
2202         /* check whether Tx hw resouce available */
2203         short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
2204         //added by wb for HT related
2205 //      void (*SwChnlByTimerHandler)(struct net_device *dev, int channel);
2206         void (*SetBWModeHandler)(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset);
2207 //      void (*UpdateHalRATRTableHandler)(struct net_device* dev, u8* pMcsRate);
2208         bool (*GetNmodeSupportBySecCfg)(struct net_device* dev);
2209         void (*SetWirelessMode)(struct net_device* dev, u8 wireless_mode);
2210         bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device* dev);
2211         void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2212
2213         /* This must be the last item so that it points to the data
2214          * allocated beyond this structure by alloc_ieee80211 */
2215         u8 priv[0];
2216 };
2217
2218 #define IEEE_A            (1<<0)
2219 #define IEEE_B            (1<<1)
2220 #define IEEE_G            (1<<2)
2221 #define IEEE_N_24G                (1<<4)
2222 #define IEEE_N_5G                 (1<<5)
2223 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
2224
2225 /* Generate a 802.11 header */
2226
2227 /* Uses the channel change callback directly
2228  * instead of [start/stop] scan callbacks
2229  */
2230 #define IEEE_SOFTMAC_SCAN (1<<2)
2231
2232 /* Perform authentication and association handshake */
2233 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
2234
2235 /* Generate probe requests */
2236 #define IEEE_SOFTMAC_PROBERQ (1<<4)
2237
2238 /* Generate respones to probe requests */
2239 #define IEEE_SOFTMAC_PROBERS (1<<5)
2240
2241 /* The ieee802.11 stack will manages the netif queue
2242  * wake/stop for the driver, taking care of 802.11
2243  * fragmentation. See softmac.c for details. */
2244 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2245
2246 /* Uses only the softmac_data_hard_start_xmit
2247  * even for TX management frames.
2248  */
2249 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
2250
2251 /* Generate beacons.  The stack will enqueue beacons
2252  * to the card
2253  */
2254 #define IEEE_SOFTMAC_BEACONS (1<<6)
2255
2256 static inline void *ieee80211_priv(struct net_device *dev)
2257 {
2258         return ((struct ieee80211_device *)netdev_priv(dev))->priv;
2259 }
2260
2261 extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
2262 {
2263         /* Single white space is for Linksys APs */
2264         if (essid_len == 1 && essid[0] == ' ')
2265                 return 1;
2266
2267         /* Otherwise, if the entire essid is 0, we assume it is hidden */
2268         while (essid_len) {
2269                 essid_len--;
2270                 if (essid[essid_len] != '\0')
2271                         return 0;
2272         }
2273
2274         return 1;
2275 }
2276
2277 extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
2278 {
2279         /*
2280          * It is possible for both access points and our device to support
2281          * combinations of modes, so as long as there is one valid combination
2282          * of ap/device supported modes, then return success
2283          *
2284          */
2285         if ((mode & IEEE_A) &&
2286             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
2287             (ieee->freq_band & IEEE80211_52GHZ_BAND))
2288                 return 1;
2289
2290         if ((mode & IEEE_G) &&
2291             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
2292             (ieee->freq_band & IEEE80211_24GHZ_BAND))
2293                 return 1;
2294
2295         if ((mode & IEEE_B) &&
2296             (ieee->modulation & IEEE80211_CCK_MODULATION) &&
2297             (ieee->freq_band & IEEE80211_24GHZ_BAND))
2298                 return 1;
2299
2300         return 0;
2301 }
2302
2303 extern inline int ieee80211_get_hdrlen(u16 fc)
2304 {
2305         int hdrlen = IEEE80211_3ADDR_LEN;
2306
2307         switch (WLAN_FC_GET_TYPE(fc)) {
2308         case IEEE80211_FTYPE_DATA:
2309                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
2310                         hdrlen = IEEE80211_4ADDR_LEN; /* Addr4 */
2311                 if(IEEE80211_QOS_HAS_SEQ(fc))
2312                         hdrlen += 2; /* QOS ctrl*/
2313                 break;
2314         case IEEE80211_FTYPE_CTL:
2315                 switch (WLAN_FC_GET_STYPE(fc)) {
2316                 case IEEE80211_STYPE_CTS:
2317                 case IEEE80211_STYPE_ACK:
2318                         hdrlen = IEEE80211_1ADDR_LEN;
2319                         break;
2320                 default:
2321                         hdrlen = IEEE80211_2ADDR_LEN;
2322                         break;
2323                 }
2324                 break;
2325         }
2326
2327         return hdrlen;
2328 }
2329
2330 static inline u8 *ieee80211_get_payload(struct ieee80211_hdr *hdr)
2331 {
2332         switch (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
2333         case IEEE80211_1ADDR_LEN:
2334                 return ((struct ieee80211_hdr_1addr *)hdr)->payload;
2335         case IEEE80211_2ADDR_LEN:
2336                 return ((struct ieee80211_hdr_2addr *)hdr)->payload;
2337         case IEEE80211_3ADDR_LEN:
2338                 return ((struct ieee80211_hdr_3addr *)hdr)->payload;
2339         case IEEE80211_4ADDR_LEN:
2340                 return ((struct ieee80211_hdr_4addr *)hdr)->payload;
2341         }
2342         return NULL;
2343 }
2344
2345 static inline int ieee80211_is_ofdm_rate(u8 rate)
2346 {
2347         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
2348         case IEEE80211_OFDM_RATE_6MB:
2349         case IEEE80211_OFDM_RATE_9MB:
2350         case IEEE80211_OFDM_RATE_12MB:
2351         case IEEE80211_OFDM_RATE_18MB:
2352         case IEEE80211_OFDM_RATE_24MB:
2353         case IEEE80211_OFDM_RATE_36MB:
2354         case IEEE80211_OFDM_RATE_48MB:
2355         case IEEE80211_OFDM_RATE_54MB:
2356                 return 1;
2357         }
2358         return 0;
2359 }
2360
2361 static inline int ieee80211_is_cck_rate(u8 rate)
2362 {
2363         switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
2364         case IEEE80211_CCK_RATE_1MB:
2365         case IEEE80211_CCK_RATE_2MB:
2366         case IEEE80211_CCK_RATE_5MB:
2367         case IEEE80211_CCK_RATE_11MB:
2368                 return 1;
2369         }
2370         return 0;
2371 }
2372
2373
2374 /* ieee80211.c */
2375 extern void free_ieee80211(struct net_device *dev);
2376 extern struct net_device *alloc_ieee80211(int sizeof_priv);
2377
2378 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
2379
2380 /* ieee80211_tx.c */
2381
2382 extern int ieee80211_encrypt_fragment(
2383         struct ieee80211_device *ieee,
2384         struct sk_buff *frag,
2385         int hdr_len);
2386
2387 extern int ieee80211_xmit(struct sk_buff *skb,
2388                           struct net_device *dev);
2389 extern void ieee80211_txb_free(struct ieee80211_txb *);
2390
2391
2392 /* ieee80211_rx.c */
2393 extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
2394                         struct ieee80211_rx_stats *rx_stats);
2395 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2396                              struct ieee80211_hdr_4addr *header,
2397                              struct ieee80211_rx_stats *stats);
2398
2399 /* ieee80211_wx.c */
2400 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
2401                                  struct iw_request_info *info,
2402                                  union iwreq_data *wrqu, char *key);
2403 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
2404                                    struct iw_request_info *info,
2405                                    union iwreq_data *wrqu, char *key);
2406 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
2407                                    struct iw_request_info *info,
2408                                    union iwreq_data *wrqu, char *key);
2409 #if WIRELESS_EXT >= 18
2410 extern int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
2411                             struct iw_request_info *info,
2412                             union iwreq_data* wrqu, char *extra);
2413 extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
2414                             struct iw_request_info *info,
2415                             union iwreq_data* wrqu, char *extra);
2416 extern int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
2417                                struct iw_request_info *info,
2418                                struct iw_param *data, char *extra);
2419 extern int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
2420                                struct iw_request_info *info,
2421                                union iwreq_data *wrqu, char *extra);
2422 #endif
2423 extern int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
2424
2425 /* ieee80211_softmac.c */
2426 extern short ieee80211_is_54g(struct ieee80211_network net);
2427 extern short ieee80211_is_shortslot(struct ieee80211_network net);
2428 extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
2429                         struct ieee80211_rx_stats *rx_stats, u16 type,
2430                         u16 stype);
2431 extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net);
2432
2433 void SendDisassociation(struct ieee80211_device *ieee, u8* asSta, u8 asRsn);
2434 extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee);
2435
2436 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
2437 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
2438 extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
2439 extern void ieee80211_start_bss(struct ieee80211_device *ieee);
2440 extern void ieee80211_start_master_bss(struct ieee80211_device *ieee);
2441 extern void ieee80211_start_ibss(struct ieee80211_device *ieee);
2442 extern void ieee80211_softmac_init(struct ieee80211_device *ieee);
2443 extern void ieee80211_softmac_free(struct ieee80211_device *ieee);
2444 extern void ieee80211_associate_abort(struct ieee80211_device *ieee);
2445 extern void ieee80211_disassociate(struct ieee80211_device *ieee);
2446 extern void ieee80211_stop_scan(struct ieee80211_device *ieee);
2447 extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
2448 extern void ieee80211_check_all_nets(struct ieee80211_device *ieee);
2449 extern void ieee80211_start_protocol(struct ieee80211_device *ieee);
2450 extern void ieee80211_stop_protocol(struct ieee80211_device *ieee);
2451 extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
2452 extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
2453 extern void ieee80211_reset_queue(struct ieee80211_device *ieee);
2454 extern void ieee80211_wake_queue(struct ieee80211_device *ieee);
2455 extern void ieee80211_stop_queue(struct ieee80211_device *ieee);
2456 extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
2457 extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
2458 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
2459 extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p);
2460 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
2461 extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
2462
2463 extern void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee);
2464
2465 /* ieee80211_crypt_ccmp&tkip&wep.c */
2466 extern void ieee80211_tkip_null(void);
2467 extern void ieee80211_wep_null(void);
2468 extern void ieee80211_ccmp_null(void);
2469
2470 /* ieee80211_softmac_wx.c */
2471
2472 extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
2473                             struct iw_request_info *info,
2474                             union iwreq_data *wrqu, char *ext);
2475
2476 extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
2477                          struct iw_request_info *info,
2478                          union iwreq_data *awrq,
2479                          char *extra);
2480
2481 extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
2482
2483 extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
2484                              struct iw_request_info *info,
2485                              union iwreq_data *wrqu, char *extra);
2486
2487 extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
2488                              struct iw_request_info *info,
2489                              union iwreq_data *wrqu, char *extra);
2490
2491 extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
2492                              union iwreq_data *wrqu, char *b);
2493
2494 extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
2495                              union iwreq_data *wrqu, char *b);
2496
2497 extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
2498                               struct iw_request_info *a,
2499                               union iwreq_data *wrqu, char *extra);
2500
2501 extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
2502                              union iwreq_data *wrqu, char *b);
2503
2504 extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
2505                              union iwreq_data *wrqu, char *b);
2506
2507 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
2508                              union iwreq_data *wrqu, char *b);
2509
2510 //extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee);
2511 extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
2512
2513
2514 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
2515                                struct iw_request_info *info,
2516                                union iwreq_data *wrqu, char *extra);
2517
2518 extern int ieee80211_wx_get_name(struct ieee80211_device *ieee,
2519                              struct iw_request_info *info,
2520                              union iwreq_data *wrqu, char *extra);
2521
2522 extern int ieee80211_wx_set_power(struct ieee80211_device *ieee,
2523                                  struct iw_request_info *info,
2524                                  union iwreq_data *wrqu, char *extra);
2525
2526 extern int ieee80211_wx_get_power(struct ieee80211_device *ieee,
2527                                  struct iw_request_info *info,
2528                                  union iwreq_data *wrqu, char *extra);
2529
2530 extern int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
2531                              struct iw_request_info *info,
2532                              union iwreq_data *wrqu, char *extra);
2533
2534 extern int ieee80211_wx_get_rts(struct ieee80211_device *ieee,
2535                              struct iw_request_info *info,
2536                              union iwreq_data *wrqu, char *extra);
2537 //HT
2538 #define MAX_RECEIVE_BUFFER_SIZE 9100  //
2539 extern void HTDebugHTCapability(u8* CapIE, u8* TitleString );
2540 extern void HTDebugHTInfo(u8*  InfoIE, u8* TitleString);
2541
2542 void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
2543 extern void HTUpdateDefaultSetting(struct ieee80211_device* ieee);
2544 extern void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 isEncrypt);
2545 extern void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* len, u8 isEncrypt);
2546 extern void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg, u8* len);
2547 extern void HTOnAssocRsp(struct ieee80211_device *ieee);
2548 extern void HTInitializeHTInfo(struct ieee80211_device* ieee);
2549 extern void HTInitializeBssDesc(PBSS_HT pBssHT);
2550 extern void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork);
2551 extern void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee,   struct ieee80211_network * pNetwork);
2552 extern u8 HTGetHighestMCSRate(struct ieee80211_device* ieee, u8* pMCSRateSet, u8* pMCSFilter);
2553 extern u8 MCS_FILTER_ALL[];
2554 extern u16 MCS_DATA_RATE[2][2][77] ;
2555 extern u8 HTCCheck(struct ieee80211_device* ieee, u8*   pFrame);
2556 //extern void HTSetConnectBwModeCallback(unsigned long data);
2557 extern void HTResetIOTSetting(PRT_HIGH_THROUGHPUT  pHTInfo);
2558 extern bool IsHTHalfNmodeAPs(struct ieee80211_device* ieee);
2559 extern u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee,  u8      nMcsRate);
2560 extern u16 HTMcsToDataRate( struct ieee80211_device* ieee, u8 nMcsRate);
2561 extern u16  TxCountToDataRate( struct ieee80211_device* ieee, u8 nDataRate);
2562 //function in BAPROC.c
2563 extern int ieee80211_rx_ADDBAReq( struct ieee80211_device* ieee, struct sk_buff *skb);
2564 extern int ieee80211_rx_ADDBARsp( struct ieee80211_device* ieee, struct sk_buff *skb);
2565 extern int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb);
2566 extern void TsInitAddBA( struct ieee80211_device* ieee, PTX_TS_RECORD   pTS, u8 Policy, u8 bOverwritePending);
2567 extern void TsInitDelBA( struct ieee80211_device* ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect);
2568 extern void BaSetupTimeOut(unsigned long data);
2569 extern void TxBaInactTimeout(unsigned long data);
2570 extern void RxBaInactTimeout(unsigned long data);
2571 extern void ResetBaEntry( PBA_RECORD pBA);
2572 //function in TS.c
2573 extern bool GetTs(
2574         struct ieee80211_device*        ieee,
2575         PTS_COMMON_INFO                 *ppTS,
2576         u8*                             Addr,
2577         u8                              TID,
2578         TR_SELECT                       TxRxSelect,  //Rx:1, Tx:0
2579         bool                            bAddNewTs
2580         );
2581 extern void TSInitialize(struct ieee80211_device *ieee);
2582 extern  void TsStartAddBaProcess(struct ieee80211_device* ieee, PTX_TS_RECORD   pTxTS);
2583 extern void RemovePeerTS(struct ieee80211_device* ieee, u8* Addr);
2584 extern void RemoveAllTS(struct ieee80211_device* ieee);
2585 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee);
2586
2587 extern const long ieee80211_wlan_frequencies[];
2588
2589 extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
2590 {
2591         ieee->scans++;
2592 }
2593
2594 extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
2595 {
2596         return ieee->scans;
2597 }
2598
2599 static inline const char *escape_essid(const char *essid, u8 essid_len) {
2600         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2601         const char *s = essid;
2602         char *d = escaped;
2603
2604         if (ieee80211_is_empty_essid(essid, essid_len)) {
2605                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2606                 return escaped;
2607         }
2608
2609         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
2610         while (essid_len--) {
2611                 if (*s == '\0') {
2612                         *d++ = '\\';
2613                         *d++ = '0';
2614                         s++;
2615                 } else {
2616                         *d++ = *s++;
2617                 }
2618         }
2619         *d = '\0';
2620         return escaped;
2621 }
2622
2623 /* For the function is more related to hardware setting, it's better to use the
2624  * ieee handler to refer to it.
2625  */
2626 extern short check_nic_enough_desc(struct net_device *dev, int queue_index);
2627 extern int ieee80211_data_xmit(struct sk_buff *skb, struct net_device *dev);
2628 extern int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2629                 struct ieee80211_info_element *info_element,
2630                 u16 length,
2631                 struct ieee80211_network *network,
2632                 struct ieee80211_rx_stats *stats);
2633
2634 void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_rxb** prxbIndicateArray,u8  index);
2635 #define RT_ASOC_RETRY_LIMIT     5
2636 #endif /* IEEE80211_H */