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