]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8192e/rtllib.h
rtl8192e: Remove extra ifdefs
[karo-tx-linux.git] / drivers / staging / rtl8192e / rtllib.h
1 /*
2  * Merged with mainline rtllib.h in Aug 2004.  Original ieee802_11
3  * remains copyright by the original authors
4  *
5  * Portions of the merged code are based on Host AP (software wireless
6  * LAN access point) driver for Intersil Prism2/2.5/3.
7  *
8  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
9  * <jkmaline@cc.hut.fi>
10  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
11  *
12  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13  * <jketreno@linux.intel.com>
14  * Copyright (c) 2004, Intel Corporation
15  *
16  * Modified for Realtek's wi-fi cards by Andrea Merello
17  * <andreamrl@tiscali.it>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License version 2 as
21  * published by the Free Software Foundation. See README and COPYING for
22  * more details.
23  */
24 #ifndef RTLLIB_H
25 #define RTLLIB_H
26 #include <linux/if_ether.h> /* ETH_ALEN */
27 #include <linux/kernel.h>   /* ARRAY_SIZE */
28 #include <linux/version.h>
29 #include <linux/module.h>
30 #include <linux/interrupt.h>
31 #include <linux/jiffies.h>
32 #include <linux/timer.h>
33 #include <linux/sched.h>
34
35 #include <linux/delay.h>
36 #include <linux/wireless.h>
37
38 #ifdef CONFIG_CFG_80211
39 #include <net/cfg80211.h>
40 #endif
41
42 #include "rtl819x_HT.h"
43 #include "rtl819x_BA.h"
44 #include "rtl819x_TS.h"
45
46 #include <linux/netdevice.h>
47 #include <linux/if_arp.h> /* ARPHRD_ETHER */
48
49 #ifndef WIRELESS_SPY
50 #define WIRELESS_SPY
51 #endif
52 #include <net/iw_handler.h>
53
54 #ifndef IEEE80211_RADIOTAP_F_BADFCS
55 #define IEEE80211_RADIOTAP_F_BADFCS     0x40    /* bad FCS */
56 #endif
57
58 #ifndef IW_MODE_MONITOR
59 #define IW_MODE_MONITOR 6
60 #endif
61
62 #ifndef IWEVCUSTOM
63 #define IWEVCUSTOM 0x8c02
64 #endif
65
66 #ifndef IW_CUSTOM_MAX
67 /* Max number of char in custom event - use multiple of them if needed */
68 #define IW_CUSTOM_MAX   256     /* In bytes */
69 #endif
70
71 #ifndef container_of
72 /**
73  * container_of - cast a member of a structure out to the containing structure
74  *
75  * @ptr:        the pointer to the member.
76  * @type:       the type of the container struct this is embedded in.
77  * @member:     the name of the member within the struct.
78  *
79  */
80 #define container_of(ptr, type, member) ({                      \
81         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
82         (type *)( (char *)__mptr - offsetof(type,member) );})
83 #endif
84
85 #define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb)
86
87 #define EXPORT_SYMBOL_RSL(x) EXPORT_SYMBOL(x)
88
89
90         typedef struct delayed_work delayed_work_struct_rsl;
91         #define queue_delayed_work_rsl(x,y,z) queue_delayed_work(x,y,z)
92         #define INIT_DELAYED_WORK_RSL(x,y,z) INIT_DELAYED_WORK(x,y)
93
94         typedef struct work_struct work_struct_rsl;
95         #define queue_work_rsl(x,y) queue_work(x,y)
96         #define INIT_WORK_RSL(x,y,z) INIT_WORK(x,y)
97
98         #define container_of_work_rsl(x,y,z) container_of(x,y,z)
99         #define container_of_dwork_rsl(x,y,z) container_of(container_of(x, struct delayed_work, work), y, z)
100
101         #define iwe_stream_add_event_rsl(info,start,stop,iwe,len) iwe_stream_add_event(info,start,stop,iwe,len)
102
103         #define iwe_stream_add_point_rsl(info,start,stop,iwe,p) iwe_stream_add_point(info,start,stop,iwe,p)
104
105         #define usb_alloc_urb_rsl(x,y) usb_alloc_urb(x,y)
106         #define usb_submit_urb_rsl(x,y) usb_submit_urb(x,y)
107
108 static inline void *netdev_priv_rsl(struct net_device *dev)
109 {
110         return netdev_priv(dev);
111 }
112
113 #define KEY_TYPE_NA             0x0
114 #define KEY_TYPE_WEP40          0x1
115 #define KEY_TYPE_TKIP           0x2
116 #define KEY_TYPE_CCMP           0x4
117 #define KEY_TYPE_WEP104         0x5
118 /* added for rtl819x tx procedure */
119 #define MAX_QUEUE_SIZE          0x10
120
121 #if defined(RTL8192SU) || defined(RTL8190P) ||defined(RTL8192U) ||defined(RTL8192E)
122 #define BK_QUEUE                               0
123 #define BE_QUEUE                               1
124 #define VI_QUEUE                               2
125 #define VO_QUEUE                               3
126 #define HCCA_QUEUE                             4
127 #define TXCMD_QUEUE                            5
128 #define MGNT_QUEUE                             6
129 #define HIGH_QUEUE                             7
130 #define BEACON_QUEUE                           8
131 #elif defined(RTL8192SE)
132 #define BK_QUEUE                               0
133 #define BE_QUEUE                               1
134 #define VI_QUEUE                               2
135 #define VO_QUEUE                               3
136 #define BEACON_QUEUE                          4
137 #define TXCMD_QUEUE                            5
138 #define MGNT_QUEUE                             6
139 #define HIGH_QUEUE                             7
140 #define HCCA_QUEUE                             8
141
142 #endif
143
144 #define LOW_QUEUE                              BE_QUEUE
145 #define NORMAL_QUEUE                           MGNT_QUEUE
146
147 #ifndef IW_MODE_MESH
148 #define IW_MODE_MESH                    7
149 #endif
150 #define AMSDU_SUBHEADER_LEN 14
151 #define SWRF_TIMEOUT                            50
152
153 #define IE_CISCO_FLAG_POSITION          0x08
154 #define SUPPORT_CKIP_MIC                        0x08
155 #define SUPPORT_CKIP_PK                 0x10
156 #define RT_RF_OFF_LEVL_ASPM                     BIT0
157 #define RT_RF_OFF_LEVL_CLK_REQ          BIT1
158 #define RT_RF_OFF_LEVL_PCI_D3                   BIT2
159 #define RT_RF_OFF_LEVL_HALT_NIC         BIT3
160 #define RT_RF_OFF_LEVL_FREE_FW          BIT4
161 #define RT_RF_OFF_LEVL_FW_32K           BIT5
162 #define RT_RF_PS_LEVEL_ALWAYS_ASPM      BIT6
163 #define RT_RF_LPS_DISALBE_2R                    BIT30
164 #define RT_RF_LPS_LEVEL_ASPM                    BIT31
165 #define RT_IN_PS_LEVEL(pPSC, _PS_FLAG)  ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
166 #define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG)       (pPSC->CurPsLevel &= (~(_PS_FLAG)))
167 #define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG)
168
169 /* defined for skb cb field */
170 /* At most 28 byte */
171 typedef struct cb_desc {
172         /* Tx Desc Related flags (8-9) */
173         u8 bLastIniPkt:1;
174         u8 bCmdOrInit:1;
175         u8 bFirstSeg:1;
176         u8 bLastSeg:1;
177         u8 bEncrypt:1;
178         u8 bTxDisableRateFallBack:1;
179         u8 bTxUseDriverAssingedRate:1;
180         u8 bHwSec:1;
181
182         u8 nStuckCount;
183
184         /* Tx Firmware Relaged flags (10-11)*/
185         u8 bCTSEnable:1;
186         u8 bRTSEnable:1;
187         u8 bUseShortGI:1;
188         u8 bUseShortPreamble:1;
189         u8 bTxEnableFwCalcDur:1;
190         u8 bAMPDUEnable:1;
191         u8 bRTSSTBC:1;
192         u8 RTSSC:1;
193
194         u8 bRTSBW:1;
195         u8 bPacketBW:1;
196         u8 bRTSUseShortPreamble:1;
197         u8 bRTSUseShortGI:1;
198         u8 bMulticast:1;
199         u8 bBroadcast:1;
200         u8 drv_agg_enable:1;
201         u8 reserved2:1;
202
203         /* Tx Desc related element(12-19) */
204         u8 rata_index;
205         u8 queue_index;
206         u16 txbuf_size;
207         u8 RATRIndex;
208         u8 bAMSDU:1;
209         u8 bFromAggrQ:1;
210         u8 reserved6:6;
211         u8 macId;
212         u8 priority;
213
214         /* Tx firmware related element(20-27) */
215         u8 data_rate;
216         u8 rts_rate;
217         u8 ampdu_factor;
218         u8 ampdu_density;
219         u8 DrvAggrNum;
220         u8 bdhcp;
221         u16 pkt_size;
222         u8 bIsSpecialDataFrame;
223
224         u8 bBTTxPacket;
225         u8 bIsBTProbRsp;
226 }cb_desc, *pcb_desc;
227
228 /*--------------------------Define -------------------------------------------*/
229 #define MGN_1M                  0x02
230 #define MGN_2M                  0x04
231 #define MGN_5_5M                0x0b
232 #define MGN_11M                 0x16
233
234 #define MGN_6M                  0x0c
235 #define MGN_9M                  0x12
236 #define MGN_12M                 0x18
237 #define MGN_18M                 0x24
238 #define MGN_24M                 0x30
239 #define MGN_36M                 0x48
240 #define MGN_48M                 0x60
241 #define MGN_54M                 0x6c
242
243 #define MGN_MCS0                0x80
244 #define MGN_MCS1                0x81
245 #define MGN_MCS2                0x82
246 #define MGN_MCS3                0x83
247 #define MGN_MCS4                0x84
248 #define MGN_MCS5                0x85
249 #define MGN_MCS6                0x86
250 #define MGN_MCS7                0x87
251 #define MGN_MCS8                0x88
252 #define MGN_MCS9                0x89
253 #define MGN_MCS10               0x8a
254 #define MGN_MCS11               0x8b
255 #define MGN_MCS12               0x8c
256 #define MGN_MCS13               0x8d
257 #define MGN_MCS14               0x8e
258 #define MGN_MCS15               0x8f
259 #define MGN_MCS0_SG                     0x90
260 #define MGN_MCS1_SG                     0x91
261 #define MGN_MCS2_SG                     0x92
262 #define MGN_MCS3_SG                     0x93
263 #define MGN_MCS4_SG                     0x94
264 #define MGN_MCS5_SG                     0x95
265 #define MGN_MCS6_SG                     0x96
266 #define MGN_MCS7_SG                     0x97
267 #define MGN_MCS8_SG                     0x98
268 #define MGN_MCS9_SG                     0x99
269 #define MGN_MCS10_SG            0x9a
270 #define MGN_MCS11_SG            0x9b
271 #define MGN_MCS12_SG            0x9c
272 #define MGN_MCS13_SG            0x9d
273 #define MGN_MCS14_SG            0x9e
274 #define MGN_MCS15_SG            0x9f
275
276
277 enum    _ReasonCode{
278         unspec_reason   = 0x1,
279         auth_not_valid  = 0x2,
280         deauth_lv_ss    = 0x3,
281         inactivity              = 0x4,
282         ap_overload     = 0x5,
283         class2_err              = 0x6,
284         class3_err              = 0x7,
285         disas_lv_ss     = 0x8,
286         asoc_not_auth   = 0x9,
287
288         mic_failure     = 0xe,
289
290         invalid_IE              = 0x0d,
291         four_way_tmout  = 0x0f,
292         two_way_tmout   = 0x10,
293         IE_dismatch     = 0x11,
294         invalid_Gcipher = 0x12,
295         invalid_Pcipher = 0x13,
296         invalid_AKMP    = 0x14,
297         unsup_RSNIEver = 0x15,
298         invalid_RSNIE   = 0x16,
299         auth_802_1x_fail= 0x17,
300         ciper_reject            = 0x18,
301
302         QoS_unspec              = 0x20,
303         QAP_bandwidth   = 0x21,
304         poor_condition  = 0x22,
305         no_facility     = 0x23,
306         req_declined    = 0x25,
307         invalid_param   = 0x26,
308         req_not_honored= 0x27,
309         TS_not_created  = 0x2F,
310         DL_not_allowed  = 0x30,
311         dest_not_exist  = 0x31,
312         dest_not_QSTA   = 0x32,
313 };
314
315 typedef enum _HAL_DEF_VARIABLE{
316         HAL_DEF_TPC_ENABLE,
317         HAL_DEF_INIT_GAIN,
318         HAL_DEF_PROT_IMP_MODE,
319         HAL_DEF_HIGH_POWER_MECHANISM,
320         HAL_DEF_RATE_ADAPTIVE_MECHANISM,
321         HAL_DEF_ANTENNA_DIVERSITY_MECHANISM,
322         HAL_DEF_LED,
323         HAL_DEF_CW_MAX_MIN,
324
325         HAL_DEF_WOWLAN,
326         HAL_DEF_ENDPOINTS,
327         HAL_DEF_MIN_TX_POWER_DBM,
328         HAL_DEF_MAX_TX_POWER_DBM,
329         HW_DEF_EFUSE_REPG_SECTION1_FLAG,
330         HW_DEF_EFUSE_REPG_DATA,
331         HW_DEF_GPIO,
332         HAL_DEF_PCI_SUPPORT_ASPM,
333         HAL_DEF_THERMAL_VALUE,
334       HAL_DEF_USB_IN_TOKEN_REV,
335 }HAL_DEF_VARIABLE;
336
337
338 typedef enum _HW_VARIABLES{
339         HW_VAR_ETHER_ADDR,
340         HW_VAR_MULTICAST_REG,
341         HW_VAR_BASIC_RATE,
342         HW_VAR_BSSID,
343         HW_VAR_MEDIA_STATUS,
344         HW_VAR_SECURITY_CONF,
345         HW_VAR_BEACON_INTERVAL,
346         HW_VAR_ATIM_WINDOW,
347         HW_VAR_LISTEN_INTERVAL,
348         HW_VAR_CS_COUNTER,
349         HW_VAR_DEFAULTKEY0,
350         HW_VAR_DEFAULTKEY1,
351         HW_VAR_DEFAULTKEY2,
352         HW_VAR_DEFAULTKEY3,
353         HW_VAR_SIFS,
354         HW_VAR_DIFS,
355         HW_VAR_EIFS,
356         HW_VAR_SLOT_TIME,
357         HW_VAR_ACK_PREAMBLE,
358         HW_VAR_CW_CONFIG,
359         HW_VAR_CW_VALUES,
360         HW_VAR_RATE_FALLBACK_CONTROL,
361         HW_VAR_CONTENTION_WINDOW,
362         HW_VAR_RETRY_COUNT,
363         HW_VAR_TR_SWITCH,
364         HW_VAR_COMMAND,
365         HW_VAR_WPA_CONFIG,
366         HW_VAR_AMPDU_MIN_SPACE,
367         HW_VAR_SHORTGI_DENSITY,
368         HW_VAR_AMPDU_FACTOR,
369         HW_VAR_MCS_RATE_AVAILABLE,
370         HW_VAR_AC_PARAM,
371         HW_VAR_ACM_CTRL,
372         HW_VAR_DIS_Req_Qsize,
373         HW_VAR_CCX_CHNL_LOAD,
374         HW_VAR_CCX_NOISE_HISTOGRAM,
375         HW_VAR_CCX_CLM_NHM,
376         HW_VAR_TxOPLimit,
377         HW_VAR_TURBO_MODE,
378         HW_VAR_RF_STATE,
379         HW_VAR_RF_OFF_BY_HW,
380         HW_VAR_BUS_SPEED,
381         HW_VAR_SET_DEV_POWER,
382
383         HW_VAR_RCR,
384         HW_VAR_RATR_0,
385         HW_VAR_RRSR,
386         HW_VAR_CPU_RST,
387         HW_VAR_CECHK_BSSID,
388         HW_VAR_LBK_MODE,
389         HW_VAR_AES_11N_FIX,
390         HW_VAR_USB_RX_AGGR,
391         HW_VAR_USER_CONTROL_TURBO_MODE,
392         HW_VAR_RETRY_LIMIT,
393         HW_VAR_INIT_TX_RATE,
394         HW_VAR_TX_RATE_REG,
395         HW_VAR_EFUSE_USAGE,
396         HW_VAR_EFUSE_BYTES,
397         HW_VAR_AUTOLOAD_STATUS,
398         HW_VAR_RF_2R_DISABLE,
399         HW_VAR_SET_RPWM,
400         HW_VAR_H2C_FW_PWRMODE,
401         HW_VAR_H2C_FW_JOINBSSRPT,
402         HW_VAR_1X1_RECV_COMBINE,
403         HW_VAR_STOP_SEND_BEACON,
404         HW_VAR_TSF_TIMER,
405         HW_VAR_IO_CMD,
406
407         HW_VAR_RF_RECOVERY,
408         HW_VAR_H2C_FW_UPDATE_GTK,
409         HW_VAR_WF_MASK,
410         HW_VAR_WF_CRC,
411         HW_VAR_WF_IS_MAC_ADDR,
412         HW_VAR_H2C_FW_OFFLOAD,
413         HW_VAR_RESET_WFCRC,
414
415         HW_VAR_HANDLE_FW_C2H,
416         HW_VAR_DL_FW_RSVD_PAGE,
417         HW_VAR_AID,
418         HW_VAR_HW_SEQ_ENABLE,
419         HW_VAR_CORRECT_TSF,
420         HW_VAR_BCN_VALID,
421         HW_VAR_FWLPS_RF_ON,
422         HW_VAR_DUAL_TSF_RST,
423         HW_VAR_SWITCH_EPHY_WoWLAN,
424         HW_VAR_INT_MIGRATION,
425         HW_VAR_INT_AC,
426         HW_VAR_RF_TIMING,
427 }HW_VARIABLES;
428
429 typedef enum _RT_OP_MODE{
430         RT_OP_MODE_AP,
431         RT_OP_MODE_INFRASTRUCTURE,
432         RT_OP_MODE_IBSS,
433         RT_OP_MODE_NO_LINK,
434 }RT_OP_MODE, *PRT_OP_MODE;
435
436
437 #define aSifsTime        (((priv->rtllib->current_network.mode == IEEE_A)||(priv->rtllib->current_network.mode == IEEE_N_24G)||(priv->rtllib->current_network.mode == IEEE_N_5G))? 16 : 10)
438
439 #define MGMT_QUEUE_NUM 5
440
441 #define IEEE_CMD_SET_WPA_PARAM                  1
442 #define IEEE_CMD_SET_WPA_IE                     2
443 #define IEEE_CMD_SET_ENCRYPTION                 3
444 #define IEEE_CMD_MLME                           4
445
446 #define IEEE_PARAM_WPA_ENABLED                  1
447 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
448 #define IEEE_PARAM_DROP_UNENCRYPTED             3
449 #define IEEE_PARAM_PRIVACY_INVOKED              4
450 #define IEEE_PARAM_AUTH_ALGS                    5
451 #define IEEE_PARAM_IEEE_802_1X                  6
452 #define IEEE_PARAM_WPAX_SELECT                  7
453 #define IEEE_PROTO_WPA                          1
454 #define IEEE_PROTO_RSN                          2
455 #define IEEE_WPAX_USEGROUP                      0
456 #define IEEE_WPAX_WEP40                         1
457 #define IEEE_WPAX_TKIP                          2
458 #define IEEE_WPAX_WRAP                          3
459 #define IEEE_WPAX_CCMP                          4
460 #define IEEE_WPAX_WEP104                        5
461
462 #define IEEE_KEY_MGMT_IEEE8021X                 1
463 #define IEEE_KEY_MGMT_PSK                       2
464
465 #define IEEE_MLME_STA_DEAUTH                    1
466 #define IEEE_MLME_STA_DISASSOC                  2
467
468
469 #define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
470 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
471 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED        4
472 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
473 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED        6
474 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
475 #define IEEE_CRYPT_ALG_NAME_LEN                 16
476
477 #define MAX_IE_LEN  0xff
478 #ifdef ENABLE_NULL_PT_DEBUG
479 #define RT_ASSERT_RET(_Exp)                                                             \
480                 if (!(_Exp))                                                                    \
481                 {                                                                                       \
482                         printk("Rtl819x: ");                                    \
483                         printk( "Assertion failed! %s,%s,line=%d\n", \
484                         #_Exp,__func__,__LINE__);          \
485                         return;                                         \
486                 }
487 #define RT_ASSERT_RET_VALUE(_Exp,Ret)                                                           \
488                 if (!(_Exp))                                                                    \
489                 {                                                                                       \
490                         printk("Rtl819x: ");                                    \
491                         printk( "Assertion failed! %s,%s,line=%d\n", \
492                         #_Exp,__func__,__LINE__);          \
493                         return (Ret);                                           \
494                 }
495 #else
496 #define RT_ASSERT_RET(_Exp) do {} while(0)
497 #define RT_ASSERT_RET_VALUE(_Exp,Ret) do {} while(0)
498 #endif
499
500 typedef struct ieee_param {
501         u32 cmd;
502         u8 sta_addr[ETH_ALEN];
503         union {
504                 struct {
505                         u8 name;
506                         u32 value;
507                 } wpa_param;
508                 struct {
509                         u32 len;
510                         u8 reserved[32];
511                         u8 data[0];
512                 } wpa_ie;
513                 struct{
514                         int command;
515                         int reason_code;
516                 } mlme;
517                 struct {
518                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
519                         u8 set_tx;
520                         u32 err;
521                         u8 idx;
522                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
523                         u16 key_len;
524                         u8 key[0];
525                 } crypt;
526         } u;
527 }ieee_param;
528
529
530 #if WIRELESS_EXT < 17
531 #define IW_QUAL_QUAL_INVALID   0x10
532 #define IW_QUAL_LEVEL_INVALID  0x20
533 #define IW_QUAL_NOISE_INVALID  0x40
534 #define IW_QUAL_QUAL_UPDATED   0x1
535 #define IW_QUAL_LEVEL_UPDATED  0x2
536 #define IW_QUAL_NOISE_UPDATED  0x4
537 #endif
538
539 #define MSECS(t) msecs_to_jiffies(t)
540 #define msleep_interruptible_rsl  msleep_interruptible
541
542 #define RTLLIB_DATA_LEN         2304
543 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
544    6.2.1.1.2.
545
546    The figure in section 7.1.2 suggests a body size of up to 2312
547    bytes is allowed, which is a bit confusing, I suspect this
548    represents the 2304 bytes of real data, plus a possible 8 bytes of
549    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
550 #define RTLLIB_1ADDR_LEN 10
551 #define RTLLIB_2ADDR_LEN 16
552 #define RTLLIB_3ADDR_LEN 24
553 #define RTLLIB_4ADDR_LEN 30
554 #define RTLLIB_FCS_LEN    4
555 #define RTLLIB_HLEN                  (RTLLIB_4ADDR_LEN)
556 #define RTLLIB_FRAME_LEN             (RTLLIB_DATA_LEN + RTLLIB_HLEN)
557 #define RTLLIB_MGMT_HDR_LEN 24
558 #define RTLLIB_DATA_HDR3_LEN 24
559 #define RTLLIB_DATA_HDR4_LEN 30
560
561 #define RTLLIB_SKBBUFFER_SIZE 2500
562
563 #define MIN_FRAG_THRESHOLD     256U
564 #define MAX_FRAG_THRESHOLD     2346U
565 #define MAX_HT_DATA_FRAG_THRESHOLD 0x2000
566
567 #define HT_AMSDU_SIZE_4K 3839
568 #define HT_AMSDU_SIZE_8K 7935
569
570 /* Frame control field constants */
571 #define RTLLIB_FCTL_VERS                0x0003
572 #define RTLLIB_FCTL_FTYPE               0x000c
573 #define RTLLIB_FCTL_STYPE               0x00f0
574 #define RTLLIB_FCTL_FRAMETYPE   0x00fc
575 #define RTLLIB_FCTL_TODS                0x0100
576 #define RTLLIB_FCTL_FROMDS              0x0200
577 #define RTLLIB_FCTL_DSTODS              0x0300
578 #define RTLLIB_FCTL_MOREFRAGS   0x0400
579 #define RTLLIB_FCTL_RETRY               0x0800
580 #define RTLLIB_FCTL_PM          0x1000
581 #define RTLLIB_FCTL_MOREDATA            0x2000
582 #define RTLLIB_FCTL_WEP         0x4000
583 #define RTLLIB_FCTL_ORDER               0x8000
584
585 #define RTLLIB_FTYPE_MGMT               0x0000
586 #define RTLLIB_FTYPE_CTL                0x0004
587 #define RTLLIB_FTYPE_DATA               0x0008
588
589 /* management */
590 #define RTLLIB_STYPE_ASSOC_REQ  0x0000
591 #define RTLLIB_STYPE_ASSOC_RESP         0x0010
592 #define RTLLIB_STYPE_REASSOC_REQ        0x0020
593 #define RTLLIB_STYPE_REASSOC_RESP       0x0030
594 #define RTLLIB_STYPE_PROBE_REQ  0x0040
595 #define RTLLIB_STYPE_PROBE_RESP 0x0050
596 #define RTLLIB_STYPE_BEACON             0x0080
597 #define RTLLIB_STYPE_ATIM               0x0090
598 #define RTLLIB_STYPE_DISASSOC   0x00A0
599 #define RTLLIB_STYPE_AUTH               0x00B0
600 #define RTLLIB_STYPE_DEAUTH             0x00C0
601 #define RTLLIB_STYPE_MANAGE_ACT 0x00D0
602
603 /* control */
604 #define RTLLIB_STYPE_PSPOLL             0x00A0
605 #define RTLLIB_STYPE_RTS                0x00B0
606 #define RTLLIB_STYPE_CTS                0x00C0
607 #define RTLLIB_STYPE_ACK                0x00D0
608 #define RTLLIB_STYPE_CFEND              0x00E0
609 #define RTLLIB_STYPE_CFENDACK   0x00F0
610 #define RTLLIB_STYPE_BLOCKACK   0x0094
611
612 /* data */
613 #define RTLLIB_STYPE_DATA               0x0000
614 #define RTLLIB_STYPE_DATA_CFACK 0x0010
615 #define RTLLIB_STYPE_DATA_CFPOLL        0x0020
616 #define RTLLIB_STYPE_DATA_CFACKPOLL     0x0030
617 #define RTLLIB_STYPE_NULLFUNC   0x0040
618 #define RTLLIB_STYPE_CFACK              0x0050
619 #define RTLLIB_STYPE_CFPOLL             0x0060
620 #define RTLLIB_STYPE_CFACKPOLL  0x0070
621 #define RTLLIB_STYPE_QOS_DATA   0x0080
622 #define RTLLIB_STYPE_QOS_NULL   0x00C0
623
624 #define RTLLIB_SCTL_FRAG                0x000F
625 #define RTLLIB_SCTL_SEQ         0xFFF0
626
627 /* QOS control */
628 #define RTLLIB_QCTL_TID              0x000F
629
630 #define FC_QOS_BIT                                      BIT7
631 #define IsDataFrame(pdu)                        ( ((pdu[0] & 0x0C)==0x08) ? true : false )
632 #define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)) )
633 #define IsQoSDataFrame(pframe)  ((*(u16*)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) == (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
634 #define Frame_Order(pframe)     (*(u16*)pframe&RTLLIB_FCTL_ORDER)
635 #define SN_LESS(a, b)           (((a-b)&0x800)!=0)
636 #define SN_EQUAL(a, b)  (a == b)
637 #define MAX_DEV_ADDR_SIZE 8
638
639 typedef enum _ACT_CATEGORY{
640         ACT_CAT_QOS = 1,
641         ACT_CAT_DLS = 2,
642         ACT_CAT_BA  = 3,
643         ACT_CAT_HT  = 7,
644         ACT_CAT_WMM = 17,
645 } ACT_CATEGORY, *PACT_CATEGORY;
646
647 typedef enum _TS_ACTION{
648         ACT_ADDTSREQ = 0,
649         ACT_ADDTSRSP = 1,
650         ACT_DELTS    = 2,
651         ACT_SCHEDULE = 3,
652 } TS_ACTION, *PTS_ACTION;
653
654 typedef enum _BA_ACTION{
655         ACT_ADDBAREQ = 0,
656         ACT_ADDBARSP = 1,
657         ACT_DELBA    = 2,
658 } BA_ACTION, *PBA_ACTION;
659
660 typedef enum _InitialGainOpType{
661         IG_Backup=0,
662         IG_Restore,
663         IG_Max
664 }InitialGainOpType;
665 typedef enum _LED_CTL_MODE{
666         LED_CTL_POWER_ON = 1,
667         LED_CTL_LINK = 2,
668         LED_CTL_NO_LINK = 3,
669         LED_CTL_TX = 4,
670         LED_CTL_RX = 5,
671         LED_CTL_SITE_SURVEY = 6,
672         LED_CTL_POWER_OFF = 7,
673         LED_CTL_START_TO_LINK = 8,
674         LED_CTL_START_WPS = 9,
675         LED_CTL_STOP_WPS = 10,
676         LED_CTL_START_WPS_BOTTON = 11,
677         LED_CTL_STOP_WPS_FAIL = 12,
678          LED_CTL_STOP_WPS_FAIL_OVERLAP = 13,
679 }LED_CTL_MODE;
680
681 typedef enum _RT_RF_TYPE_DEF
682 {
683         RF_1T2R = 0,
684         RF_2T4R,
685         RF_2T2R,
686         RF_1T1R,
687         RF_2T2R_GREEN,
688         RF_819X_MAX_TYPE
689 }RT_RF_TYPE_DEF;
690
691 typedef enum _WIRELESS_MODE {
692         WIRELESS_MODE_UNKNOWN = 0x00,
693         WIRELESS_MODE_A = 0x01,
694         WIRELESS_MODE_B = 0x02,
695         WIRELESS_MODE_G = 0x04,
696         WIRELESS_MODE_AUTO = 0x08,
697         WIRELESS_MODE_N_24G = 0x10,
698         WIRELESS_MODE_N_5G = 0x20
699 } WIRELESS_MODE;
700
701 typedef enum _NETWORK_TYPE{
702         WIRELESS_11B = 1,
703         WIRELESS_11G = 2,
704         WIRELESS_11A = 4,
705         WIRELESS_11N = 8
706 } WIRELESS_NETWORK_TYPE;
707
708 #define OUI_SUBTYPE_WMM_INFO            0
709 #define OUI_SUBTYPE_WMM_PARAM   1
710 #define OUI_SUBTYPE_QOS_CAPABI  5
711
712 /* debug macros */
713 #define CONFIG_RTLLIB_DEBUG
714 #ifdef CONFIG_RTLLIB_DEBUG
715 extern u32 rtllib_debug_level;
716 #define RTLLIB_DEBUG(level, fmt, args...) \
717 do { if (rtllib_debug_level & (level)) \
718   printk(KERN_DEBUG "rtllib: " fmt, ## args); } while (0)
719 #define RTLLIB_DEBUG_DATA(level, data, datalen) \
720         do{ if ((rtllib_debug_level & (level)) == (level))      \
721                 {       \
722                         int i;                                  \
723                         u8* pdata = (u8*) data;                 \
724                         printk(KERN_DEBUG "rtllib: %s()\n", __func__);  \
725                         for (i=0; i<(int)(datalen); i++)                        \
726                         {                                               \
727                                 printk("%2.2x ", pdata[i]);             \
728                                 if ((i+1)%16 == 0) printk("\n");        \
729                         }                               \
730                         printk("\n");                   \
731                 }                                       \
732         } while (0)
733 #else
734 #define RTLLIB_DEBUG(level, fmt, args...) do {} while (0)
735 #define RTLLIB_DEBUG_DATA(level, data, datalen) do {} while(0)
736 #endif  /* CONFIG_RTLLIB_DEBUG */
737
738 /* debug macros not dependent on CONFIG_RTLLIB_DEBUG */
739
740 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
741 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
742
743 /*
744  * To use the debug system;
745  *
746  * If you are defining a new debug classification, simply add it to the #define
747  * list here in the form of:
748  *
749  * #define RTLLIB_DL_xxxx VALUE
750  *
751  * shifting value to the left one bit from the previous entry.  xxxx should be
752  * the name of the classification (for example, WEP)
753  *
754  * You then need to either add a RTLLIB_xxxx_DEBUG() macro definition for your
755  * classification, or use RTLLIB_DEBUG(RTLLIB_DL_xxxx, ...) whenever you want
756  * to send output to that classification.
757  *
758  * To add your debug level to the list of levels seen when you perform
759  *
760  * % cat /proc/net/ipw/debug_level
761  *
762  * you simply need to add your entry to the ipw_debug_levels array.
763  *
764  * If you do not see debug_level in /proc/net/ipw then you do not have
765  * CONFIG_RTLLIB_DEBUG defined in your kernel configuration
766  *
767  */
768
769 #define RTLLIB_DL_INFO          (1<<0)
770 #define RTLLIB_DL_WX            (1<<1)
771 #define RTLLIB_DL_SCAN          (1<<2)
772 #define RTLLIB_DL_STATE         (1<<3)
773 #define RTLLIB_DL_MGMT          (1<<4)
774 #define RTLLIB_DL_FRAG          (1<<5)
775 #define RTLLIB_DL_EAP           (1<<6)
776 #define RTLLIB_DL_DROP          (1<<7)
777
778 #define RTLLIB_DL_TX            (1<<8)
779 #define RTLLIB_DL_RX            (1<<9)
780
781 #define RTLLIB_DL_HT               (1<<10)
782 #define RTLLIB_DL_BA               (1<<11)
783 #define RTLLIB_DL_TS               (1<<12)
784 #define RTLLIB_DL_QOS           (1<<13)
785 #define RTLLIB_DL_REORDER          (1<<14)
786 #define RTLLIB_DL_IOT      (1<<15)
787 #define RTLLIB_DL_IPS      (1<<16)
788 #define RTLLIB_DL_TRACE    (1<<29)
789 #define RTLLIB_DL_DATA     (1<<30)
790 #define RTLLIB_DL_ERR      (1<<31)
791 #define RTLLIB_ERROR(f, a...) printk(KERN_ERR "rtllib: " f, ## a)
792 #define RTLLIB_WARNING(f, a...) printk(KERN_WARNING "rtllib: " f, ## a)
793 #define RTLLIB_DEBUG_INFO(f, a...)   RTLLIB_DEBUG(RTLLIB_DL_INFO, f, ## a)
794
795 #define RTLLIB_DEBUG_WX(f, a...)     RTLLIB_DEBUG(RTLLIB_DL_WX, f, ## a)
796 #define RTLLIB_DEBUG_SCAN(f, a...)   RTLLIB_DEBUG(RTLLIB_DL_SCAN, f, ## a)
797 #define RTLLIB_DEBUG_STATE(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_STATE, f, ## a)
798 #define RTLLIB_DEBUG_MGMT(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_MGMT, f, ## a)
799 #define RTLLIB_DEBUG_FRAG(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_FRAG, f, ## a)
800 #define RTLLIB_DEBUG_EAP(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_EAP, f, ## a)
801 #define RTLLIB_DEBUG_DROP(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_DROP, f, ## a)
802 #define RTLLIB_DEBUG_TX(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_TX, f, ## a)
803 #define RTLLIB_DEBUG_RX(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_RX, f, ## a)
804 #define RTLLIB_DEBUG_QOS(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_QOS, f, ## a)
805
806 #ifdef CONFIG_RTLLIB_DEBUG
807 /* Added by Annie, 2005-11-22. */
808 #define MAX_STR_LEN     64
809 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. Annie, 2005-11-22.*/
810 #define PRINTABLE(_ch)  (_ch>'!' && _ch<'~')
811 #define RTLLIB_PRINT_STR(_Comp, _TitleString, _Ptr, _Len)                               \
812                         if ((_Comp) & level)                                                    \
813                         {                                                                       \
814                                 int             __i;                                            \
815                                 u8  buffer[MAX_STR_LEN];                                        \
816                                 int length = (_Len<MAX_STR_LEN)? _Len : (MAX_STR_LEN-1) ;       \
817                                 memset(buffer, 0, MAX_STR_LEN);                                 \
818                                 memcpy(buffer, (u8 *)_Ptr, length );                            \
819                                 for ( __i=0; __i<MAX_STR_LEN; __i++ )                            \
820                                 {                                                               \
821                                      if ( !PRINTABLE(buffer[__i]) )   buffer[__i] = '?';                \
822                                 }                                                               \
823                                 buffer[length] = '\0';                                          \
824                                 printk("Rtl819x: ");                                            \
825                                 printk(_TitleString);                                         \
826                                 printk(": %d, <%s>\n", _Len, buffer);                         \
827                         }
828 #else
829 #define RTLLIB_PRINT_STR(_Comp, _TitleString, _Ptr, _Len)  do {} while (0)
830 #endif
831
832 #ifndef ETH_P_PAE
833 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
834 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
835 #define ETH_P_ARP       0x0806          /* Address Resolution packet    */
836 #endif /* ETH_P_PAE */
837
838 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
839
840 #ifndef ETH_P_80211_RAW
841 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
842 #endif
843
844 /* IEEE 802.11 defines */
845
846 #define P80211_OUI_LEN 3
847
848 struct rtllib_snap_hdr {
849
850         u8    dsap;   /* always 0xAA */
851         u8    ssap;   /* always 0xAA */
852         u8    ctrl;   /* always 0x03 */
853         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
854
855 } __attribute__ ((packed));
856
857 enum _REG_PREAMBLE_MODE{
858         PREAMBLE_LONG = 1,
859         PREAMBLE_AUTO = 2,
860         PREAMBLE_SHORT= 3,
861 };
862
863 #define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
864
865 #define WLAN_FC_GET_VERS(fc) ((fc) & RTLLIB_FCTL_VERS)
866 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
867 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
868 #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
869
870 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
871 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
872 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & RTLLIB_SCTL_SEQ) >> 4)
873
874 #ifndef CONFIG_CFG_80211
875 /* Authentication algorithms */
876 #define WLAN_AUTH_OPEN 0
877 #define WLAN_AUTH_SHARED_KEY 1
878 #define WLAN_AUTH_LEAP 128
879
880 #define WLAN_AUTH_CHALLENGE_LEN 128
881
882 #define WLAN_CAPABILITY_ESS (1<<0)
883 #define WLAN_CAPABILITY_IBSS (1<<1)
884 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
885 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
886 #define WLAN_CAPABILITY_PRIVACY (1<<4)
887 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
888 #define WLAN_CAPABILITY_PBCC (1<<6)
889 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
890 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
891 #define WLAN_CAPABILITY_QOS (1<<9)
892 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
893 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
894
895 /* 802.11g ERP information element */
896 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
897 #define WLAN_ERP_USE_PROTECTION (1<<1)
898 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
899
900 /* Status codes */
901 enum rtllib_statuscode {
902         WLAN_STATUS_SUCCESS = 0,
903         WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
904         WLAN_STATUS_CAPS_UNSUPPORTED = 10,
905         WLAN_STATUS_REASSOC_NO_ASSOC = 11,
906         WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
907         WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
908         WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
909         WLAN_STATUS_CHALLENGE_FAIL = 15,
910         WLAN_STATUS_AUTH_TIMEOUT = 16,
911         WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
912         WLAN_STATUS_ASSOC_DENIED_RATES = 18,
913         /* 802.11b */
914         WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
915         WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
916         WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
917         /* 802.11h */
918         WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
919         WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
920         WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
921         /* 802.11g */
922         WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
923         WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
924         /* 802.11i */
925         WLAN_STATUS_INVALID_IE = 40,
926         WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
927         WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
928         WLAN_STATUS_INVALID_AKMP = 43,
929         WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
930         WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
931         WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
932 };
933
934 /* Reason codes */
935 enum rtllib_reasoncode {
936         WLAN_REASON_UNSPECIFIED = 1,
937         WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
938         WLAN_REASON_DEAUTH_LEAVING = 3,
939         WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
940         WLAN_REASON_DISASSOC_AP_BUSY = 5,
941         WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
942         WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
943         WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
944         WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
945         /* 802.11h */
946         WLAN_REASON_DISASSOC_BAD_POWER = 10,
947         WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
948         /* 802.11i */
949         WLAN_REASON_INVALID_IE = 13,
950         WLAN_REASON_MIC_FAILURE = 14,
951         WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
952         WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
953         WLAN_REASON_IE_DIFFERENT = 17,
954         WLAN_REASON_INVALID_GROUP_CIPHER = 18,
955         WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
956         WLAN_REASON_INVALID_AKMP = 20,
957         WLAN_REASON_UNSUPP_RSN_VERSION = 21,
958         WLAN_REASON_INVALID_RSN_IE_CAP = 22,
959         WLAN_REASON_IEEE8021X_FAILED = 23,
960         WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
961 };
962 #endif
963
964 #define RTLLIB_STATMASK_SIGNAL (1<<0)
965 #define RTLLIB_STATMASK_RSSI (1<<1)
966 #define RTLLIB_STATMASK_NOISE (1<<2)
967 #define RTLLIB_STATMASK_RATE (1<<3)
968 #define RTLLIB_STATMASK_WEMASK 0x7
969
970 #define RTLLIB_CCK_MODULATION    (1<<0)
971 #define RTLLIB_OFDM_MODULATION   (1<<1)
972
973 #define RTLLIB_24GHZ_BAND     (1<<0)
974 #define RTLLIB_52GHZ_BAND     (1<<1)
975
976 #define RTLLIB_CCK_RATE_LEN             4
977 #define RTLLIB_CCK_RATE_1MB                     0x02
978 #define RTLLIB_CCK_RATE_2MB                     0x04
979 #define RTLLIB_CCK_RATE_5MB                     0x0B
980 #define RTLLIB_CCK_RATE_11MB                    0x16
981 #define RTLLIB_OFDM_RATE_LEN            8
982 #define RTLLIB_OFDM_RATE_6MB                    0x0C
983 #define RTLLIB_OFDM_RATE_9MB                    0x12
984 #define RTLLIB_OFDM_RATE_12MB           0x18
985 #define RTLLIB_OFDM_RATE_18MB           0x24
986 #define RTLLIB_OFDM_RATE_24MB           0x30
987 #define RTLLIB_OFDM_RATE_36MB           0x48
988 #define RTLLIB_OFDM_RATE_48MB           0x60
989 #define RTLLIB_OFDM_RATE_54MB           0x6C
990 #define RTLLIB_BASIC_RATE_MASK          0x80
991
992 #define RTLLIB_CCK_RATE_1MB_MASK                (1<<0)
993 #define RTLLIB_CCK_RATE_2MB_MASK                (1<<1)
994 #define RTLLIB_CCK_RATE_5MB_MASK                (1<<2)
995 #define RTLLIB_CCK_RATE_11MB_MASK               (1<<3)
996 #define RTLLIB_OFDM_RATE_6MB_MASK               (1<<4)
997 #define RTLLIB_OFDM_RATE_9MB_MASK               (1<<5)
998 #define RTLLIB_OFDM_RATE_12MB_MASK              (1<<6)
999 #define RTLLIB_OFDM_RATE_18MB_MASK              (1<<7)
1000 #define RTLLIB_OFDM_RATE_24MB_MASK              (1<<8)
1001 #define RTLLIB_OFDM_RATE_36MB_MASK              (1<<9)
1002 #define RTLLIB_OFDM_RATE_48MB_MASK              (1<<10)
1003 #define RTLLIB_OFDM_RATE_54MB_MASK              (1<<11)
1004
1005 #define RTLLIB_CCK_RATES_MASK           0x0000000F
1006 #define RTLLIB_CCK_BASIC_RATES_MASK     (RTLLIB_CCK_RATE_1MB_MASK | \
1007         RTLLIB_CCK_RATE_2MB_MASK)
1008 #define RTLLIB_CCK_DEFAULT_RATES_MASK   (RTLLIB_CCK_BASIC_RATES_MASK | \
1009         RTLLIB_CCK_RATE_5MB_MASK | \
1010         RTLLIB_CCK_RATE_11MB_MASK)
1011
1012 #define RTLLIB_OFDM_RATES_MASK          0x00000FF0
1013 #define RTLLIB_OFDM_BASIC_RATES_MASK    (RTLLIB_OFDM_RATE_6MB_MASK | \
1014         RTLLIB_OFDM_RATE_12MB_MASK | \
1015         RTLLIB_OFDM_RATE_24MB_MASK)
1016 #define RTLLIB_OFDM_DEFAULT_RATES_MASK  (RTLLIB_OFDM_BASIC_RATES_MASK | \
1017         RTLLIB_OFDM_RATE_9MB_MASK  | \
1018         RTLLIB_OFDM_RATE_18MB_MASK | \
1019         RTLLIB_OFDM_RATE_36MB_MASK | \
1020         RTLLIB_OFDM_RATE_48MB_MASK | \
1021         RTLLIB_OFDM_RATE_54MB_MASK)
1022 #define RTLLIB_DEFAULT_RATES_MASK (RTLLIB_OFDM_DEFAULT_RATES_MASK | \
1023                                 RTLLIB_CCK_DEFAULT_RATES_MASK)
1024
1025 #define RTLLIB_NUM_OFDM_RATES       8
1026 #define RTLLIB_NUM_CCK_RATES                4
1027 #define RTLLIB_OFDM_SHIFT_MASK_A         4
1028
1029
1030 /* this is stolen and modified from the madwifi driver*/
1031 #define RTLLIB_FC0_TYPE_MASK            0x0c
1032 #define RTLLIB_FC0_TYPE_DATA            0x08
1033 #define RTLLIB_FC0_SUBTYPE_MASK 0xB0
1034 #define RTLLIB_FC0_SUBTYPE_QOS  0x80
1035
1036 #define RTLLIB_QOS_HAS_SEQ(fc) \
1037         (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
1038          (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
1039
1040 /* this is stolen from ipw2200 driver */
1041 #define IEEE_IBSS_MAC_HASH_SIZE 31
1042 struct ieee_ibss_seq {
1043         u8 mac[ETH_ALEN];
1044         u16 seq_num[17];
1045         u16 frag_num[17];
1046         unsigned long packet_time[17];
1047         struct list_head list;
1048 };
1049
1050 /* NOTE: This data is for statistical purposes; not all hardware provides this
1051  *       information for frames received.  Not setting these will not cause
1052  *       any adverse affects. */
1053 struct rtllib_rx_stats {
1054 #if 1
1055         u32 mac_time[2];
1056         s8  rssi;
1057         u8  signal;
1058         u8  noise;
1059         u16 rate; /* in 100 kbps */
1060         u8  received_channel;
1061         u8  control;
1062         u8  mask;
1063         u8  freq;
1064         u16 len;
1065         u64 tsf;
1066         u32 beacon_time;
1067         u8  nic_type;
1068         u16 Length;
1069         u8  SignalQuality;
1070         s32 RecvSignalPower;
1071         s8  RxPower;
1072         u8  SignalStrength;
1073         u16 bHwError:1;
1074         u16 bCRC:1;
1075         u16 bICV:1;
1076         u16 bShortPreamble:1;
1077         u16 Antenna:1;
1078         u16 Decrypted:1;
1079         u16 Wakeup:1;
1080         u16 Reserved0:1;
1081         u8  AGC;
1082         u32 TimeStampLow;
1083         u32 TimeStampHigh;
1084         bool bShift;
1085         bool bIsQosData;
1086         u8   UserPriority;
1087
1088         u8    RxDrvInfoSize;
1089         u8    RxBufShift;
1090         bool  bIsAMPDU;
1091         bool  bFirstMPDU;
1092         bool  bContainHTC;
1093         bool  RxIs40MHzPacket;
1094         u32   RxPWDBAll;
1095         u8    RxMIMOSignalStrength[4];
1096         s8    RxMIMOSignalQuality[2];
1097         bool  bPacketMatchBSSID;
1098         bool  bIsCCK;
1099         bool  bPacketToSelf;
1100         u8*    virtual_address;
1101         u16    packetlength;
1102         u16    fraglength;
1103         u16    fragoffset;
1104         u16    ntotalfrag;
1105         bool   bisrxaggrsubframe;
1106         bool   bPacketBeacon;
1107         bool   bToSelfBA;
1108         char   cck_adc_pwdb[4];
1109         u16    Seq_Num;
1110         u8     nTotalAggPkt;
1111 #ifdef TCP_CSUM_OFFLOAD_RX
1112         u8      tcp_csum_valid;
1113 #endif
1114 #endif
1115
1116 };
1117
1118 /* IEEE 802.11 requires that STA supports concurrent reception of at least
1119  * three fragmented frames. This define can be increased to support more
1120  * concurrent frames, but it should be noted that each entry can consume about
1121  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
1122 #define RTLLIB_FRAG_CACHE_LEN 4
1123
1124 struct rtllib_frag_entry {
1125         unsigned long first_frag_time;
1126         unsigned int seq;
1127         unsigned int last_frag;
1128         struct sk_buff *skb;
1129         u8 src_addr[ETH_ALEN];
1130         u8 dst_addr[ETH_ALEN];
1131 };
1132
1133 struct rtllib_stats {
1134         unsigned int tx_unicast_frames;
1135         unsigned int tx_multicast_frames;
1136         unsigned int tx_fragments;
1137         unsigned int tx_unicast_octets;
1138         unsigned int tx_multicast_octets;
1139         unsigned int tx_deferred_transmissions;
1140         unsigned int tx_single_retry_frames;
1141         unsigned int tx_multiple_retry_frames;
1142         unsigned int tx_retry_limit_exceeded;
1143         unsigned int tx_discards;
1144         unsigned int rx_unicast_frames;
1145         unsigned int rx_multicast_frames;
1146         unsigned int rx_fragments;
1147         unsigned int rx_unicast_octets;
1148         unsigned int rx_multicast_octets;
1149         unsigned int rx_fcs_errors;
1150         unsigned int rx_discards_no_buffer;
1151         unsigned int tx_discards_wrong_sa;
1152         unsigned int rx_discards_undecryptable;
1153         unsigned int rx_message_in_msg_fragments;
1154         unsigned int rx_message_in_bad_msg_fragments;
1155 };
1156
1157 struct rtllib_device;
1158
1159 #include "rtllib_crypt.h"
1160
1161 #define SEC_KEY_1         (1<<0)
1162 #define SEC_KEY_2         (1<<1)
1163 #define SEC_KEY_3         (1<<2)
1164 #define SEC_KEY_4         (1<<3)
1165 #define SEC_ACTIVE_KEY    (1<<4)
1166 #define SEC_AUTH_MODE     (1<<5)
1167 #define SEC_UNICAST_GROUP (1<<6)
1168 #define SEC_LEVEL         (1<<7)
1169 #define SEC_ENABLED       (1<<8)
1170 #define SEC_ENCRYPT       (1<<9)
1171
1172 #define SEC_LEVEL_0      0 /* None */
1173 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
1174 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
1175 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
1176 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
1177
1178 #define SEC_ALG_NONE            0
1179 #define SEC_ALG_WEP             1
1180 #define SEC_ALG_TKIP            2
1181 #define SEC_ALG_CCMP            4
1182
1183 #define WEP_KEYS                4
1184 #define WEP_KEY_LEN             13
1185 #define SCM_KEY_LEN             32
1186 #define SCM_TEMPORAL_KEY_LENGTH 16
1187
1188 struct rtllib_security {
1189         u16 active_key:2,
1190             enabled:1,
1191             auth_mode:2,
1192             auth_algo:4,
1193             unicast_uses_group:1,
1194             encrypt:1;
1195         u8 key_sizes[WEP_KEYS];
1196         u8 keys[WEP_KEYS][SCM_KEY_LEN];
1197         u8 level;
1198         u16 flags;
1199 } __attribute__ ((packed));
1200
1201
1202 /*
1203  802.11 data frame from AP
1204       ,-------------------------------------------------------------------.
1205 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
1206       |------|------|---------|---------|---------|------|---------|------|
1207 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
1208       |      | tion | (BSSID) |         |         | ence |  data   |      |
1209       `-------------------------------------------------------------------'
1210 Total: 28-2340 bytes
1211 */
1212
1213 /* Management Frame Information Element Types */
1214 enum rtllib_mfie {
1215         MFIE_TYPE_SSID = 0,
1216         MFIE_TYPE_RATES = 1,
1217         MFIE_TYPE_FH_SET = 2,
1218         MFIE_TYPE_DS_SET = 3,
1219         MFIE_TYPE_CF_SET = 4,
1220         MFIE_TYPE_TIM = 5,
1221         MFIE_TYPE_IBSS_SET = 6,
1222         MFIE_TYPE_COUNTRY = 7,
1223         MFIE_TYPE_HOP_PARAMS = 8,
1224         MFIE_TYPE_HOP_TABLE = 9,
1225         MFIE_TYPE_REQUEST = 10,
1226         MFIE_TYPE_CHALLENGE = 16,
1227         MFIE_TYPE_POWER_CONSTRAINT = 32,
1228         MFIE_TYPE_POWER_CAPABILITY = 33,
1229         MFIE_TYPE_TPC_REQUEST = 34,
1230         MFIE_TYPE_TPC_REPORT = 35,
1231         MFIE_TYPE_SUPP_CHANNELS = 36,
1232         MFIE_TYPE_CSA = 37,
1233         MFIE_TYPE_MEASURE_REQUEST = 38,
1234         MFIE_TYPE_MEASURE_REPORT = 39,
1235         MFIE_TYPE_QUIET = 40,
1236         MFIE_TYPE_IBSS_DFS = 41,
1237         MFIE_TYPE_ERP = 42,
1238         MFIE_TYPE_HT_CAP= 45,
1239         MFIE_TYPE_RSN = 48,
1240         MFIE_TYPE_RATES_EX = 50,
1241         MFIE_TYPE_HT_INFO= 61,
1242         MFIE_TYPE_AIRONET=133,
1243         MFIE_TYPE_GENERIC = 221,
1244         MFIE_TYPE_QOS_PARAMETER = 222,
1245 };
1246
1247 /* Minimal header; can be used for passing 802.11 frames with sufficient
1248  * information to determine what type of underlying data type is actually
1249  * stored in the data. */
1250 struct rtllib_pspoll_hdr {
1251         __le16 frame_ctl;
1252         __le16 aid;
1253         u8 bssid[ETH_ALEN];
1254         u8 ta[ETH_ALEN];
1255 } __attribute__ ((packed));
1256
1257 struct rtllib_hdr {
1258         __le16 frame_ctl;
1259         __le16 duration_id;
1260         u8 payload[0];
1261 } __attribute__ ((packed));
1262
1263 struct rtllib_hdr_1addr {
1264         __le16 frame_ctl;
1265         __le16 duration_id;
1266         u8 addr1[ETH_ALEN];
1267         u8 payload[0];
1268 } __attribute__ ((packed));
1269
1270 struct rtllib_hdr_2addr {
1271         __le16 frame_ctl;
1272         __le16 duration_id;
1273         u8 addr1[ETH_ALEN];
1274         u8 addr2[ETH_ALEN];
1275         u8 payload[0];
1276 } __attribute__ ((packed));
1277
1278 struct rtllib_hdr_3addr {
1279         __le16 frame_ctl;
1280         __le16 duration_id;
1281         u8 addr1[ETH_ALEN];
1282         u8 addr2[ETH_ALEN];
1283         u8 addr3[ETH_ALEN];
1284         __le16 seq_ctl;
1285         u8 payload[0];
1286 } __attribute__ ((packed));
1287
1288 struct rtllib_hdr_4addr {
1289         __le16 frame_ctl;
1290         __le16 duration_id;
1291         u8 addr1[ETH_ALEN];
1292         u8 addr2[ETH_ALEN];
1293         u8 addr3[ETH_ALEN];
1294         __le16 seq_ctl;
1295         u8 addr4[ETH_ALEN];
1296         u8 payload[0];
1297 } __attribute__ ((packed));
1298
1299 struct rtllib_hdr_3addrqos {
1300         __le16 frame_ctl;
1301         __le16 duration_id;
1302         u8 addr1[ETH_ALEN];
1303         u8 addr2[ETH_ALEN];
1304         u8 addr3[ETH_ALEN];
1305         __le16 seq_ctl;
1306         __le16 qos_ctl;
1307         u8 payload[0];
1308 } __attribute__ ((packed));
1309
1310 struct rtllib_hdr_4addrqos {
1311         __le16 frame_ctl;
1312         __le16 duration_id;
1313         u8 addr1[ETH_ALEN];
1314         u8 addr2[ETH_ALEN];
1315         u8 addr3[ETH_ALEN];
1316         __le16 seq_ctl;
1317         u8 addr4[ETH_ALEN];
1318         __le16 qos_ctl;
1319         u8 payload[0];
1320 } __attribute__ ((packed));
1321
1322 struct rtllib_info_element {
1323         u8 id;
1324         u8 len;
1325         u8 data[0];
1326 } __attribute__ ((packed));
1327
1328 struct rtllib_authentication {
1329         struct rtllib_hdr_3addr header;
1330         __le16 algorithm;
1331         __le16 transaction;
1332         __le16 status;
1333         /*challenge*/
1334         struct rtllib_info_element info_element[0];
1335 } __attribute__ ((packed));
1336
1337 struct rtllib_disauth {
1338         struct rtllib_hdr_3addr header;
1339         __le16 reason;
1340 } __attribute__ ((packed));
1341
1342 struct rtllib_disassoc {
1343         struct rtllib_hdr_3addr header;
1344         __le16 reason;
1345 } __attribute__ ((packed));
1346
1347 struct rtllib_probe_request {
1348         struct rtllib_hdr_3addr header;
1349         /* SSID, supported rates */
1350         struct rtllib_info_element info_element[0];
1351 } __attribute__ ((packed));
1352
1353 struct rtllib_probe_response {
1354         struct rtllib_hdr_3addr header;
1355         u32 time_stamp[2];
1356         __le16 beacon_interval;
1357         __le16 capability;
1358         /* SSID, supported rates, FH params, DS params,
1359          * CF params, IBSS params, TIM (if beacon), RSN */
1360         struct rtllib_info_element info_element[0];
1361 } __attribute__ ((packed));
1362
1363 /* Alias beacon for probe_response */
1364 #define rtllib_beacon rtllib_probe_response
1365
1366 struct rtllib_assoc_request_frame {
1367         struct rtllib_hdr_3addr header;
1368         __le16 capability;
1369         __le16 listen_interval;
1370         /* SSID, supported rates, RSN */
1371         struct rtllib_info_element info_element[0];
1372 } __attribute__ ((packed));
1373
1374 struct rtllib_reassoc_request_frame {
1375         struct rtllib_hdr_3addr header;
1376         __le16 capability;
1377         __le16 listen_interval;
1378         u8 current_ap[ETH_ALEN];
1379         /* SSID, supported rates, RSN */
1380         struct rtllib_info_element info_element[0];
1381 } __attribute__ ((packed));
1382
1383 struct rtllib_assoc_response_frame {
1384         struct rtllib_hdr_3addr header;
1385         __le16 capability;
1386         __le16 status;
1387         __le16 aid;
1388         struct rtllib_info_element info_element[0]; /* supported rates */
1389 } __attribute__ ((packed));
1390
1391 struct rtllib_txb {
1392         u8 nr_frags;
1393         u8 encrypted;
1394         u8 queue_index;
1395         u8 rts_included;
1396         u16 reserved;
1397         __le16 frag_size;
1398         __le16 payload_size;
1399         struct sk_buff *fragments[0];
1400 };
1401
1402 #define MAX_TX_AGG_COUNT                  16
1403 struct rtllib_drv_agg_txb {
1404         u8 nr_drv_agg_frames;
1405         struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT];
1406 }__attribute__((packed));
1407
1408 #define MAX_SUBFRAME_COUNT                64
1409 struct rtllib_rxb {
1410         u8 nr_subframes;
1411         struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
1412         u8 dst[ETH_ALEN];
1413         u8 src[ETH_ALEN];
1414 #ifdef TCP_CSUM_OFFLOAD_RX
1415         u8 tcp_csum_valid;
1416 #endif
1417 }__attribute__((packed));
1418
1419 typedef union _frameqos {
1420         u16 shortdata;
1421         u8  chardata[2];
1422         struct {
1423                 u16 tid:4;
1424                 u16 eosp:1;
1425                 u16 ack_policy:2;
1426                 u16 reserved:1;
1427                 u16 txop:8;
1428         }field;
1429 }frameqos,*pframeqos;
1430
1431 /* SWEEP TABLE ENTRIES NUMBER*/
1432 #define MAX_SWEEP_TAB_ENTRIES             42
1433 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
1434 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
1435  * only use 8, and then use extended rates for the remaining supported
1436  * rates.  Other APs, however, stick all of their supported rates on the
1437  * main rates information element... */
1438 #define MAX_RATES_LENGTH                  ((u8)12)
1439 #define MAX_RATES_EX_LENGTH               ((u8)16)
1440 #define MAX_NETWORK_COUNT                  96
1441
1442 #define MAX_CHANNEL_NUMBER                 161
1443 #define RTLLIB_SOFTMAC_SCAN_TIME           100
1444 #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
1445
1446 #define CRC_LENGTH                 4U
1447
1448 #define MAX_WPA_IE_LEN 64
1449 #define MAX_WZC_IE_LEN 256
1450
1451 #define NETWORK_EMPTY_ESSID (1<<0)
1452 #define NETWORK_HAS_OFDM    (1<<1)
1453 #define NETWORK_HAS_CCK     (1<<2)
1454
1455 /* QoS structure */
1456 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
1457 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
1458 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
1459                                          NETWORK_HAS_QOS_INFORMATION)
1460 /* 802.11h */
1461 #define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
1462 #define NETWORK_HAS_CSA                 (1<<6)
1463 #define NETWORK_HAS_QUIET               (1<<7)
1464 #define NETWORK_HAS_IBSS_DFS            (1<<8)
1465 #define NETWORK_HAS_TPC_REPORT          (1<<9)
1466
1467 #define NETWORK_HAS_ERP_VALUE           (1<<10)
1468
1469 #define QOS_QUEUE_NUM                   4
1470 #define QOS_OUI_LEN                     3
1471 #define QOS_OUI_TYPE                    2
1472 #define QOS_ELEMENT_ID                  221
1473 #define QOS_OUI_INFO_SUB_TYPE           0
1474 #define QOS_OUI_PARAM_SUB_TYPE          1
1475 #define QOS_VERSION_1                   1
1476 #define QOS_AIFSN_MIN_VALUE             2
1477 #if 1
1478 struct rtllib_qos_information_element {
1479         u8 elementID;
1480         u8 length;
1481         u8 qui[QOS_OUI_LEN];
1482         u8 qui_type;
1483         u8 qui_subtype;
1484         u8 version;
1485         u8 ac_info;
1486 } __attribute__ ((packed));
1487
1488 struct rtllib_qos_ac_parameter {
1489         u8 aci_aifsn;
1490         u8 ecw_min_max;
1491         __le16 tx_op_limit;
1492 } __attribute__ ((packed));
1493
1494 struct rtllib_qos_parameter_info {
1495         struct rtllib_qos_information_element info_element;
1496         u8 reserved;
1497         struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
1498 } __attribute__ ((packed));
1499
1500 struct rtllib_qos_parameters {
1501         __le16 cw_min[QOS_QUEUE_NUM];
1502         __le16 cw_max[QOS_QUEUE_NUM];
1503         u8 aifs[QOS_QUEUE_NUM];
1504         u8 flag[QOS_QUEUE_NUM];
1505         __le16 tx_op_limit[QOS_QUEUE_NUM];
1506 } __attribute__ ((packed));
1507
1508 struct rtllib_qos_data {
1509         struct rtllib_qos_parameters parameters;
1510         unsigned int wmm_acm;
1511         int active;
1512         int supported;
1513         u8 param_count;
1514         u8 old_param_count;
1515 };
1516
1517 struct rtllib_tim_parameters {
1518         u8 tim_count;
1519         u8 tim_period;
1520 } __attribute__ ((packed));
1521
1522 struct rtllib_wmm_ac_param {
1523         u8 ac_aci_acm_aifsn;
1524         u8 ac_ecwmin_ecwmax;
1525         u16 ac_txop_limit;
1526 };
1527
1528 struct rtllib_wmm_ts_info {
1529         u8 ac_dir_tid;
1530         u8 ac_up_psb;
1531         u8 reserved;
1532 } __attribute__ ((packed));
1533
1534 struct rtllib_wmm_tspec_elem {
1535         struct rtllib_wmm_ts_info ts_info;
1536         u16 norm_msdu_size;
1537         u16 max_msdu_size;
1538         u32 min_serv_inter;
1539         u32 max_serv_inter;
1540         u32 inact_inter;
1541         u32 suspen_inter;
1542         u32 serv_start_time;
1543         u32 min_data_rate;
1544         u32 mean_data_rate;
1545         u32 peak_data_rate;
1546         u32 max_burst_size;
1547         u32 delay_bound;
1548         u32 min_phy_rate;
1549         u16 surp_band_allow;
1550         u16 medium_time;
1551 }__attribute__((packed));
1552 #endif
1553 enum eap_type {
1554         EAP_PACKET = 0,
1555         EAPOL_START,
1556         EAPOL_LOGOFF,
1557         EAPOL_KEY,
1558         EAPOL_ENCAP_ASF_ALERT
1559 };
1560
1561 static const char *eap_types[] = {
1562         [EAP_PACKET]            = "EAP-Packet",
1563         [EAPOL_START]           = "EAPOL-Start",
1564         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
1565         [EAPOL_KEY]             = "EAPOL-Key",
1566         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
1567 };
1568
1569 static inline const char *eap_get_type(int type)
1570 {
1571         return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
1572 }
1573 static inline u8 Frame_QoSTID(u8* buf)
1574 {
1575         struct rtllib_hdr_3addr *hdr;
1576         u16 fc;
1577         hdr = (struct rtllib_hdr_3addr *)buf;
1578         fc = le16_to_cpu(hdr->frame_ctl);
1579         return (u8)((frameqos*)(buf + (((fc & RTLLIB_FCTL_TODS)&&(fc & RTLLIB_FCTL_FROMDS))? 30 : 24)))->field.tid;
1580 }
1581
1582
1583 struct eapol {
1584         u8 snap[6];
1585         u16 ethertype;
1586         u8 version;
1587         u8 type;
1588         u16 length;
1589 } __attribute__ ((packed));
1590
1591 struct rtllib_softmac_stats{
1592         unsigned int rx_ass_ok;
1593         unsigned int rx_ass_err;
1594         unsigned int rx_probe_rq;
1595         unsigned int tx_probe_rs;
1596         unsigned int tx_beacons;
1597         unsigned int rx_auth_rq;
1598         unsigned int rx_auth_rs_ok;
1599         unsigned int rx_auth_rs_err;
1600         unsigned int tx_auth_rq;
1601         unsigned int no_auth_rs;
1602         unsigned int no_ass_rs;
1603         unsigned int tx_ass_rq;
1604         unsigned int rx_ass_rq;
1605         unsigned int tx_probe_rq;
1606         unsigned int reassoc;
1607         unsigned int swtxstop;
1608         unsigned int swtxawake;
1609         unsigned char CurrentShowTxate;
1610         unsigned char last_packet_rate;
1611         unsigned int txretrycount;
1612 };
1613
1614 #define BEACON_PROBE_SSID_ID_POSITION 12
1615
1616 struct rtllib_info_element_hdr {
1617         u8 id;
1618         u8 len;
1619 } __attribute__ ((packed));
1620
1621 /*
1622  * These are the data types that can make up management packets
1623  *
1624         u16 auth_algorithm;
1625         u16 auth_sequence;
1626         u16 beacon_interval;
1627         u16 capability;
1628         u8 current_ap[ETH_ALEN];
1629         u16 listen_interval;
1630         struct {
1631                 u16 association_id:14, reserved:2;
1632         } __attribute__ ((packed));
1633         u32 time_stamp[2];
1634         u16 reason;
1635         u16 status;
1636 */
1637
1638 #define RTLLIB_DEFAULT_TX_ESSID "Penguin"
1639 #define RTLLIB_DEFAULT_BASIC_RATE 2
1640
1641 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1642 #define MAX_SP_Len  (WMM_all_frame << 4)
1643 #define RTLLIB_QOS_TID 0x0f
1644 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1645
1646 #define RTLLIB_DTIM_MBCAST 4
1647 #define RTLLIB_DTIM_UCAST 2
1648 #define RTLLIB_DTIM_VALID 1
1649 #define RTLLIB_DTIM_INVALID 0
1650
1651 #define RTLLIB_PS_DISABLED 0
1652 #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
1653 #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
1654
1655 #ifdef WMM_Hang_8187
1656 #undef WMM_Hang_8187
1657 #endif
1658
1659 #define WME_AC_BK   0x00
1660 #define WME_AC_BE   0x01
1661 #define WME_AC_VI   0x02
1662 #define WME_AC_VO   0x03
1663 #define WME_ACI_MASK 0x03
1664 #define WME_AIFSN_MASK 0x03
1665 #define WME_AC_PRAM_LEN 16
1666
1667 #define MAX_RECEIVE_BUFFER_SIZE 9100
1668
1669 #if 1
1670 #define UP2AC(up) (                \
1671         ((up) < 1) ? WME_AC_BE : \
1672         ((up) < 3) ? WME_AC_BK : \
1673         ((up) < 4) ? WME_AC_BE : \
1674         ((up) < 6) ? WME_AC_VI : \
1675         WME_AC_VO)
1676 #endif
1677 #define AC2UP(_ac)      (       \
1678         ((_ac) == WME_AC_VO) ? 6 : \
1679         ((_ac) == WME_AC_VI) ? 5 : \
1680         ((_ac) == WME_AC_BK) ? 1 : \
1681         0)
1682
1683 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
1684 #define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address plus ether type*/
1685
1686 struct  ether_header {
1687         u8 ether_dhost[ETHER_ADDR_LEN];
1688         u8 ether_shost[ETHER_ADDR_LEN];
1689         u16 ether_type;
1690 } __attribute__((packed));
1691
1692 #ifndef ETHERTYPE_PAE
1693 #define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
1694 #endif
1695 #ifndef ETHERTYPE_IP
1696 #define ETHERTYPE_IP    0x0800          /* IP protocol */
1697 #endif
1698
1699
1700 typedef enum _erp_t{
1701         ERP_NonERPpresent       = 0x01,
1702         ERP_UseProtection       = 0x02,
1703         ERP_BarkerPreambleMode = 0x04,
1704 } erp_t;
1705
1706 struct rtllib_network {
1707         /* These entries are used to identify a unique network */
1708         u8 bssid[ETH_ALEN];
1709         u8 channel;
1710         /* Ensure null-terminated for any debug msgs */
1711         u8 ssid[IW_ESSID_MAX_SIZE + 1];
1712         u8 ssid_len;
1713         u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
1714         u8 hidden_ssid_len;
1715         struct rtllib_qos_data qos_data;
1716
1717         bool    bWithAironetIE;
1718         bool    bCkipSupported;
1719         bool    bCcxRmEnable;
1720         u16     CcxRmState[2];
1721         bool    bMBssidValid;
1722         u8      MBssidMask;
1723         u8      MBssid[6];
1724         bool    bWithCcxVerNum;
1725         u8      BssCcxVerNumber;
1726         /* These are network statistics */
1727         struct rtllib_rx_stats stats;
1728         u16 capability;
1729         u8  rates[MAX_RATES_LENGTH];
1730         u8  rates_len;
1731         u8  rates_ex[MAX_RATES_EX_LENGTH];
1732         u8  rates_ex_len;
1733         unsigned long last_scanned;
1734         u8  mode;
1735         u32 flags;
1736         u32 last_associate;
1737         u32 time_stamp[2];
1738         u16 beacon_interval;
1739         u16 listen_interval;
1740         u16 atim_window;
1741         u8  erp_value;
1742         u8  wpa_ie[MAX_WPA_IE_LEN];
1743         size_t wpa_ie_len;
1744         u8  rsn_ie[MAX_WPA_IE_LEN];
1745         size_t rsn_ie_len;
1746         u8  wzc_ie[MAX_WZC_IE_LEN];
1747         size_t wzc_ie_len;
1748
1749         struct rtllib_tim_parameters tim;
1750         u8  dtim_period;
1751         u8  dtim_data;
1752         u32 last_dtim_sta_time[2];
1753
1754         u8 wmm_info;
1755         struct rtllib_wmm_ac_param wmm_param[4];
1756         u8 Turbo_Enable;
1757 #ifdef ENABLE_DOT11D
1758         u16 CountryIeLen;
1759         u8 CountryIeBuf[MAX_IE_LEN];
1760 #endif
1761         BSS_HT  bssht;
1762         bool broadcom_cap_exist;
1763         bool realtek_cap_exit;
1764         bool marvell_cap_exist;
1765         bool ralink_cap_exist;
1766         bool atheros_cap_exist;
1767         bool cisco_cap_exist;
1768         bool airgo_cap_exist;
1769         bool unknown_cap_exist;
1770         bool    berp_info_valid;
1771         bool buseprotection;
1772         bool bIsNetgear854T;
1773         u8 SignalStrength;
1774         u8 RSSI;
1775         struct list_head list;
1776 };
1777
1778 #if 1
1779 enum rtllib_state {
1780
1781         /* the card is not linked at all */
1782         RTLLIB_NOLINK = 0,
1783
1784         /* RTLLIB_ASSOCIATING* are for BSS client mode
1785          * the driver shall not perform RX filtering unless
1786          * the state is LINKED.
1787          * The driver shall just check for the state LINKED and
1788          * defaults to NOLINK for ALL the other states (including
1789          * LINKED_SCANNING)
1790          */
1791
1792         /* the association procedure will start (wq scheduling)*/
1793         RTLLIB_ASSOCIATING,
1794         RTLLIB_ASSOCIATING_RETRY,
1795
1796         /* the association procedure is sending AUTH request*/
1797         RTLLIB_ASSOCIATING_AUTHENTICATING,
1798
1799         /* the association procedure has successfully authentcated
1800          * and is sending association request
1801          */
1802         RTLLIB_ASSOCIATING_AUTHENTICATED,
1803
1804         /* the link is ok. the card associated to a BSS or linked
1805          * to a ibss cell or acting as an AP and creating the bss
1806          */
1807         RTLLIB_LINKED,
1808
1809         /* same as LINKED, but the driver shall apply RX filter
1810          * rules as we are in NO_LINK mode. As the card is still
1811          * logically linked, but it is doing a syncro site survey
1812          * then it will be back to LINKED state.
1813          */
1814         RTLLIB_LINKED_SCANNING,
1815 };
1816 #else
1817 enum rtllib_state {
1818         RTLLIB_UNINITIALIZED = 0,
1819         RTLLIB_INITIALIZED,
1820         RTLLIB_ASSOCIATING,
1821         RTLLIB_ASSOCIATED,
1822         RTLLIB_AUTHENTICATING,
1823         RTLLIB_AUTHENTICATED,
1824         RTLLIB_SHUTDOWN
1825 };
1826 #endif
1827
1828 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1829 #define DEFAULT_FTS 2346
1830
1831 #define CFG_RTLLIB_RESERVE_FCS (1<<0)
1832 #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1833 #define CFG_RTLLIB_RTS (1<<2)
1834
1835 #define RTLLIB_24GHZ_MIN_CHANNEL 1
1836 #define RTLLIB_24GHZ_MAX_CHANNEL 14
1837 #define RTLLIB_24GHZ_CHANNELS (RTLLIB_24GHZ_MAX_CHANNEL - \
1838                                   RTLLIB_24GHZ_MIN_CHANNEL + 1)
1839
1840 #define RTLLIB_52GHZ_MIN_CHANNEL 34
1841 #define RTLLIB_52GHZ_MAX_CHANNEL 165
1842 #define RTLLIB_52GHZ_CHANNELS (RTLLIB_52GHZ_MAX_CHANNEL - \
1843                                   RTLLIB_52GHZ_MIN_CHANNEL + 1)
1844 #ifndef eqMacAddr
1845 #define eqMacAddr(a,b)          ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
1846 #endif
1847 typedef struct tx_pending_t{
1848         int frag;
1849         struct rtllib_txb *txb;
1850 }tx_pending_t;
1851
1852 typedef struct _bandwidth_autoswitch
1853 {
1854         long threshold_20Mhzto40Mhz;
1855         long    threshold_40Mhzto20Mhz;
1856         bool bforced_tx20Mhz;
1857         bool bautoswitch_enable;
1858 }bandwidth_autoswitch,*pbandwidth_autoswitch;
1859
1860
1861
1862 #define REORDER_WIN_SIZE        128
1863 #define REORDER_ENTRY_NUM       128
1864 typedef struct _RX_REORDER_ENTRY
1865 {
1866         struct list_head        List;
1867         u16                     SeqNum;
1868         struct rtllib_rxb* prxb;
1869 } RX_REORDER_ENTRY, *PRX_REORDER_ENTRY;
1870 typedef enum _Fsync_State{
1871         Default_Fsync,
1872         HW_Fsync,
1873         SW_Fsync
1874 }Fsync_State;
1875
1876 typedef enum _RT_PS_MODE
1877 {
1878         eActive,
1879         eMaxPs,
1880         eFastPs,
1881         eAutoPs,
1882 }RT_PS_MODE;
1883
1884 typedef enum _IPS_CALLBACK_FUNCION
1885 {
1886         IPS_CALLBACK_NONE = 0,
1887         IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1888         IPS_CALLBACK_JOIN_REQUEST = 2,
1889 }IPS_CALLBACK_FUNCION;
1890
1891 typedef enum _RT_JOIN_ACTION{
1892         RT_JOIN_INFRA   = 1,
1893         RT_JOIN_IBSS  = 2,
1894         RT_START_IBSS = 3,
1895         RT_NO_ACTION  = 4,
1896 }RT_JOIN_ACTION;
1897
1898 typedef struct _IbssParms{
1899         u16   atimWin;
1900 }IbssParms, *PIbssParms;
1901 #define MAX_NUM_RATES   264
1902
1903 typedef enum _RT_RF_POWER_STATE
1904 {
1905         eRfOn,
1906         eRfSleep,
1907         eRfOff
1908 }RT_RF_POWER_STATE;
1909
1910 #define MAX_SUPPORT_WOL_PATTERN_NUM             8
1911
1912 #define MAX_WOL_BIT_MASK_SIZE           16
1913 #define MAX_WOL_PATTERN_SIZE            128
1914
1915 typedef enum _WOLPATTERN_TYPE
1916 {
1917         eNetBIOS = 0,
1918         eIPv4IPv6ARP,
1919         eIPv4IPv6TCPSYN,
1920         eMACIDOnly,
1921         eNoDefined,
1922 }WOLPATTERN_TYPE;
1923
1924 typedef struct _RT_PM_WOL_PATTERN_INFO
1925 {
1926         u32     PatternId;
1927         u32     Mask[4];
1928         u16     CrcRemainder;
1929         u8      WFMIndex;
1930         WOLPATTERN_TYPE PatternType;
1931 }RT_PM_WOL_PATTERN_INFO, *PRT_PM_WOL_PATTERN_INFO;
1932
1933 typedef struct _RT_POWER_SAVE_CONTROL
1934 {
1935
1936         bool                            bInactivePs;
1937         bool                            bIPSModeBackup;
1938         bool                            bHaltAdapterClkRQ;
1939         bool                            bSwRfProcessing;
1940         RT_RF_POWER_STATE       eInactivePowerState;
1941         work_struct_rsl         InactivePsWorkItem;
1942         struct timer_list       InactivePsTimer;
1943
1944         IPS_CALLBACK_FUNCION    ReturnPoint;
1945
1946         bool                            bTmpBssDesc;
1947         RT_JOIN_ACTION          tmpJoinAction;
1948         struct rtllib_network tmpBssDesc;
1949
1950         bool                            bTmpScanOnly;
1951         bool                            bTmpActiveScan;
1952         bool                            bTmpFilterHiddenAP;
1953         bool                            bTmpUpdateParms;
1954         u8                              tmpSsidBuf[33];
1955         OCTET_STRING                    tmpSsid2Scan;
1956         bool                            bTmpSsid2Scan;
1957         u8                              tmpNetworkType;
1958         u8                              tmpChannelNumber;
1959         u16                             tmpBcnPeriod;
1960         u8                              tmpDtimPeriod;
1961         u16                             tmpmCap;
1962         OCTET_STRING                    tmpSuppRateSet;
1963         u8                              tmpSuppRateBuf[MAX_NUM_RATES];
1964         bool                            bTmpSuppRate;
1965         IbssParms                               tmpIbpm;
1966         bool                            bTmpIbpm;
1967
1968         bool                            bLeisurePs;
1969         u32                             PowerProfile;
1970         u8                              LpsIdleCount;
1971         u8                              RegMaxLPSAwakeIntvl;
1972         u8                              LPSAwakeIntvl;
1973
1974         u32                             CurPsLevel;
1975         u32                             RegRfPsLevel;
1976
1977         bool                            bFwCtrlLPS;
1978         u8                              FWCtrlPSMode;
1979
1980         bool                            LinkReqInIPSRFOffPgs;
1981         bool                            BufConnectinfoBefore;
1982
1983
1984         bool                            bGpioRfSw;
1985
1986         u8                              RegAMDPciASPM;
1987
1988         u8                              oWLANMode;
1989         RT_PM_WOL_PATTERN_INFO          PmWoLPatternInfo[MAX_SUPPORT_WOL_PATTERN_NUM];
1990
1991 }RT_POWER_SAVE_CONTROL,*PRT_POWER_SAVE_CONTROL;
1992
1993 typedef u32 RT_RF_CHANGE_SOURCE;
1994 #define RF_CHANGE_BY_SW BIT31
1995 #define RF_CHANGE_BY_HW BIT30
1996 #define RF_CHANGE_BY_PS BIT29
1997 #define RF_CHANGE_BY_IPS BIT28
1998 #define RF_CHANGE_BY_INIT       0
1999
2000 typedef enum
2001 {
2002         COUNTRY_CODE_FCC = 0,
2003         COUNTRY_CODE_IC = 1,
2004         COUNTRY_CODE_ETSI = 2,
2005         COUNTRY_CODE_SPAIN = 3,
2006         COUNTRY_CODE_FRANCE = 4,
2007         COUNTRY_CODE_MKK = 5,
2008         COUNTRY_CODE_MKK1 = 6,
2009         COUNTRY_CODE_ISRAEL = 7,
2010         COUNTRY_CODE_TELEC = 8,
2011         COUNTRY_CODE_MIC = 9,
2012         COUNTRY_CODE_GLOBAL_DOMAIN = 10,
2013         COUNTRY_CODE_WORLD_WIDE_13 = 11,
2014         COUNTRY_CODE_TELEC_NETGEAR = 12,
2015         COUNTRY_CODE_MAX
2016 }country_code_type_t;
2017
2018 typedef enum _SCAN_OPERATION_BACKUP_OPT{
2019         SCAN_OPT_BACKUP=0,
2020         SCAN_OPT_RESTORE,
2021         SCAN_OPT_MAX
2022 }SCAN_OPERATION_BACKUP_OPT;
2023
2024 typedef enum _FW_CMD_IO_TYPE{
2025         FW_CMD_DIG_ENABLE = 0,
2026         FW_CMD_DIG_DISABLE = 1,
2027         FW_CMD_DIG_HALT = 2,
2028         FW_CMD_DIG_RESUME = 3,
2029         FW_CMD_HIGH_PWR_ENABLE = 4,
2030         FW_CMD_HIGH_PWR_DISABLE = 5,
2031         FW_CMD_RA_RESET = 6,
2032         FW_CMD_RA_ACTIVE= 7,
2033         FW_CMD_RA_REFRESH_N= 8,
2034         FW_CMD_RA_REFRESH_BG= 9,
2035         FW_CMD_RA_INIT= 10,
2036         FW_CMD_IQK_ENABLE = 11,
2037         FW_CMD_TXPWR_TRACK_ENABLE = 12,
2038         FW_CMD_TXPWR_TRACK_DISABLE = 13,
2039         FW_CMD_TXPWR_TRACK_THERMAL = 14,
2040         FW_CMD_PAUSE_DM_BY_SCAN = 15,
2041         FW_CMD_RESUME_DM_BY_SCAN = 16,
2042         FW_CMD_RA_REFRESH_N_COMB = 17,
2043         FW_CMD_RA_REFRESH_BG_COMB = 18,
2044         FW_CMD_ANTENNA_SW_ENABLE = 19,
2045         FW_CMD_ANTENNA_SW_DISABLE = 20,
2046         FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
2047         FW_CMD_LPS_ENTER = 22,
2048         FW_CMD_LPS_LEAVE = 23,
2049         FW_CMD_DIG_MODE_SS = 24,
2050         FW_CMD_DIG_MODE_FA = 25,
2051         FW_CMD_ADD_A2_ENTRY = 26,
2052         FW_CMD_CTRL_DM_BY_DRIVER = 27,
2053         FW_CMD_CTRL_DM_BY_DRIVER_NEW = 28,
2054         FW_CMD_PAPE_CONTROL = 29,
2055         FW_CMD_CHAN_SET = 30,
2056 }FW_CMD_IO_TYPE,*PFW_CMD_IO_TYPE;
2057
2058 #define RT_MAX_LD_SLOT_NUM      10
2059 typedef struct _RT_LINK_DETECT_T{
2060
2061         u32                             NumRecvBcnInPeriod;
2062         u32                             NumRecvDataInPeriod;
2063
2064         u32                             RxBcnNum[RT_MAX_LD_SLOT_NUM];
2065         u32                             RxDataNum[RT_MAX_LD_SLOT_NUM];
2066         u16                             SlotNum;
2067         u16                             SlotIndex;
2068
2069         u32                             NumTxOkInPeriod;
2070         u32                             NumRxOkInPeriod;
2071         u32                             NumRxUnicastOkInPeriod;
2072         bool                            bBusyTraffic;
2073         bool                            bHigherBusyTraffic;
2074         bool                            bHigherBusyRxTraffic;
2075         u8                              IdleCount;
2076         u32                             NumTxUnicastOkInPeriod;
2077         u32                             LastNumTxUnicast;
2078         u32                             LastNumRxUnicast;
2079 }RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
2080
2081 typedef struct _SW_CAM_TABLE{
2082
2083         u8                              macaddr[6];
2084         bool                            bused;
2085         u8                              key_buf[16];
2086         u16                             key_type;
2087         u8                              useDK;
2088         u8                              key_index;
2089
2090 }SW_CAM_TABLE,*PSW_CAM_TABLE;
2091 #define   TOTAL_CAM_ENTRY                               32
2092 typedef struct _rate_adaptive
2093 {
2094         u8                              rate_adaptive_disabled;
2095         u8                              ratr_state;
2096         u16                             reserve;
2097
2098         u32                             high_rssi_thresh_for_ra;
2099         u32                             high2low_rssi_thresh_for_ra;
2100         u8                              low2high_rssi_thresh_for_ra40M;
2101         u32                             low_rssi_thresh_for_ra40M;
2102         u8                              low2high_rssi_thresh_for_ra20M;
2103         u32                             low_rssi_thresh_for_ra20M;
2104         u32                             upper_rssi_threshold_ratr;
2105         u32                             middle_rssi_threshold_ratr;
2106         u32                             low_rssi_threshold_ratr;
2107         u32                             low_rssi_threshold_ratr_40M;
2108         u32                             low_rssi_threshold_ratr_20M;
2109         u8                              ping_rssi_enable;
2110         u32                             ping_rssi_ratr;
2111         u32                             ping_rssi_thresh_for_ra;
2112         u32                             last_ratr;
2113         u8                              PreRATRState;
2114
2115 } rate_adaptive, *prate_adaptive;
2116 typedef enum _RATR_TABLE_MODE_8192S{
2117         RATR_INX_WIRELESS_NGB = 0,
2118         RATR_INX_WIRELESS_NG = 1,
2119         RATR_INX_WIRELESS_NB = 2,
2120         RATR_INX_WIRELESS_N = 3,
2121         RATR_INX_WIRELESS_GB = 4,
2122         RATR_INX_WIRELESS_G = 5,
2123         RATR_INX_WIRELESS_B = 6,
2124         RATR_INX_WIRELESS_MC = 7,
2125         RATR_INX_WIRELESS_A = 8,
2126 }RATR_TABLE_MODE_8192S, *PRATR_TABLE_MODE_8192S;
2127
2128 #define NUM_PMKID_CACHE         16
2129 typedef struct _RT_PMKID_LIST
2130 {
2131         u8                                              bUsed;
2132         u8                                              Bssid[6];
2133         u8                                              PMKID[16];
2134         u8                                              SsidBuf[33];
2135         u8*                                             ssid_octet;
2136         u16                                     ssid_length;
2137 } RT_PMKID_LIST, *PRT_PMKID_LIST;
2138
2139 #ifdef CONFIG_CFG_80211
2140 enum {
2141         LIBIPW_CH_PASSIVE_ONLY          = (1 << 0),
2142         LIBIPW_CH_80211H_RULES          = (1 << 1),
2143         LIBIPW_CH_B_ONLY                = (1 << 2),
2144         LIBIPW_CH_NO_IBSS               = (1 << 3),
2145         LIBIPW_CH_UNIFORM_SPREADING     = (1 << 4),
2146         LIBIPW_CH_RADAR_DETECT          = (1 << 5),
2147         LIBIPW_CH_INVALID               = (1 << 6),
2148 };
2149 struct rtllib_channel {
2150         u32 freq;
2151         u8 channel;
2152         u8 flags;
2153         u8 max_power;
2154 };
2155
2156 #define RTLLIB_24GHZ_MIN_CHANNEL 1
2157 #define RTLLIB_24GHZ_MAX_CHANNEL 14
2158 #define RTLLIB_24GHZ_CHANNELS (RTLLIB_24GHZ_MAX_CHANNEL - \
2159                 RTLLIB_24GHZ_MIN_CHANNEL + 1)
2160
2161 struct reg_dmn_pair_mapping {
2162         u16 regDmnEnum;
2163         u16 reg_5ghz_ctl;
2164         u16 reg_2ghz_ctl;
2165 };
2166
2167 struct rtl_regulatory {
2168         char alpha2[2];
2169         u16 country_code;
2170         u16 max_power_level;
2171         u32 tp_scale;
2172         u16 current_rd;
2173         u16 current_rd_ext;
2174         int16_t power_limit;
2175         struct reg_dmn_pair_mapping *regpair;
2176 };
2177
2178 struct ieee80211_bss {
2179         /* Yes, this is a hack */
2180         struct cfg80211_bss cbss;
2181
2182         /* don't want to look up all the time */
2183         size_t ssid_len;
2184         u8 ssid[IEEE80211_MAX_SSID_LEN];
2185
2186         u8 dtim_period;
2187
2188         bool wmm_used;
2189
2190         unsigned long last_probe_resp;
2191
2192 #ifdef CONFIG_MAC80211_MESH
2193         u8 *mesh_id;
2194         size_t mesh_id_len;
2195         u8 *mesh_cfg;
2196 #endif
2197
2198         #define IEEE80211_MAX_SUPP_RATES 32
2199         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
2200         size_t supp_rates_len;
2201
2202         /*
2203          * During assocation, we save an ERP value from a probe response so
2204          * that we can feed ERP info to the driver when handling the
2205          * association completes. these fields probably won't be up-to-date
2206          * otherwise, you probably don't want to use them.
2207          */
2208         bool has_erp_value;
2209         u8 erp_value;
2210 };
2211
2212 /* Parsed Information Elements */
2213 struct ieee802_11_elems {
2214         u8 *ie_start;
2215         size_t total_len;
2216
2217         /* pointers to IEs */
2218         u8 *ssid;
2219         u8 *supp_rates;
2220         u8 *fh_params;
2221         u8 *ds_params;
2222         u8 *cf_params;
2223         struct ieee80211_tim_ie *tim;
2224         u8 *ibss_params;
2225         u8 *challenge;
2226         u8 *wpa;
2227         u8 *rsn;
2228         u8 *erp_info;
2229         u8 *ext_supp_rates;
2230         u8 *wmm_info;
2231         u8 *wmm_param;
2232         struct ieee80211_ht_cap *ht_cap_elem;
2233         struct ieee80211_ht_info *ht_info_elem;
2234         u8 *mesh_config;
2235         u8 *mesh_id;
2236         u8 *peer_link;
2237         u8 *preq;
2238         u8 *prep;
2239         u8 *perr;
2240         u8 *ch_switch_elem;
2241         u8 *country_elem;
2242         u8 *pwr_constr_elem;
2243         u8 *quiet_elem;         /* first quite element */
2244         u8 *timeout_int;
2245
2246         /* length of them, respectively */
2247         u8 ssid_len;
2248         u8 supp_rates_len;
2249         u8 fh_params_len;
2250         u8 ds_params_len;
2251         u8 cf_params_len;
2252         u8 tim_len;
2253         u8 ibss_params_len;
2254         u8 challenge_len;
2255         u8 wpa_len;
2256         u8 rsn_len;
2257         u8 erp_info_len;
2258         u8 ext_supp_rates_len;
2259         u8 wmm_info_len;
2260         u8 wmm_param_len;
2261         u8 mesh_config_len;
2262         u8 mesh_id_len;
2263         u8 peer_link_len;
2264         u8 preq_len;
2265         u8 prep_len;
2266         u8 perr_len;
2267         u8 ch_switch_elem_len;
2268         u8 country_elem_len;
2269         u8 pwr_constr_elem_len;
2270         u8 quiet_elem_len;
2271         u8 num_of_quiet_elem;   /* can be more the one */
2272         u8 timeout_int_len;
2273 };
2274
2275 #endif
2276
2277
2278 typedef struct _RT_INTEL_PROMISCUOUS_MODE_INFO {
2279      bool bPromiscuousOn;
2280      bool bFilterSourceStationFrame;
2281 } RT_INTEL_PROMISCUOUS_MODE_INFO, *PRT_INTEL_PROMISCUOUS_MODE_INFO;
2282
2283
2284 /*************** DRIVER STATUS   *****/
2285 #define STATUS_SCANNING                 0
2286 #define STATUS_SCAN_HW                  1
2287 #define STATUS_SCAN_ABORTING    2
2288 #define STATUS_SETTING_CHAN             3
2289 /*************** DRIVER STATUS   *****/
2290
2291 enum {
2292         NO_USE          = 0,
2293         USED            = 1,
2294         HW_SEC  = 2,
2295         SW_SEC          = 3,
2296 };
2297
2298 enum {
2299         LPS_IS_WAKE = 0,
2300         LPS_IS_SLEEP = 1,
2301         LPS_WAIT_NULL_DATA_SEND =2,
2302 };
2303
2304 struct rtllib_device {
2305         struct pci_dev *pdev;
2306         struct net_device *dev;
2307         struct rtllib_security sec;
2308
2309         bool disable_mgnt_queue;
2310
2311         unsigned long status;
2312         short hwscan_ch_bk;
2313         HT_EXTCHNL_OFFSET chan_offset_bk;
2314         HT_CHANNEL_WIDTH bandwidth_bk;
2315         u8 hwscan_sem_up;
2316 #ifdef CONFIG_CFG_80211
2317         struct wireless_dev wdev;
2318         struct rtl_regulatory regulatory;
2319 #endif
2320         u8      CntAfterLink;
2321
2322         RT_OP_MODE      OpMode;
2323
2324         u8 VersionID;
2325         /* The last AssocReq/Resp IEs */
2326         u8 *assocreq_ies, *assocresp_ies;
2327         size_t assocreq_ies_len, assocresp_ies_len;
2328
2329         bool b_customer_lenovo_id;
2330         bool    bForcedShowRxRate;
2331         bool    bForcedShowRateStill;
2332         u8      SystemQueryDataRateCount;
2333         bool    bForcedBgMode;
2334         bool bUseRAMask;
2335         bool b1x1RecvCombine;
2336         u8 RF_Type;
2337         bool b1SSSupport;
2338
2339         u8 hwsec_active;
2340         bool is_silent_reset;
2341       bool force_mic_error;
2342         bool is_roaming;
2343         bool ieee_up;
2344         bool cannot_notify;
2345         bool bSupportRemoteWakeUp;
2346         RT_PS_MODE      dot11PowerSaveMode;
2347         bool actscanning;
2348         bool FirstIe_InScan;
2349         bool be_scan_inprogress;
2350         bool beinretry;
2351         RT_RF_POWER_STATE               eRFPowerState;
2352         RT_RF_CHANGE_SOURCE     RfOffReason;
2353         bool is_set_key;
2354         bool wx_set_enc;
2355         PRT_HIGH_THROUGHPUT     pHTInfo;
2356         spinlock_t bw_spinlock;
2357
2358         spinlock_t reorder_spinlock;
2359         u8      Regdot11HTOperationalRateSet[16];
2360         u8      Regdot11TxHTOperationalRateSet[16];
2361         u8      dot11HTOperationalRateSet[16];
2362         u8      RegHTSuppRateSet[16];
2363         u8                              HTCurrentOperaRate;
2364         u8                              HTHighestOperaRate;
2365        u8               MinSpaceCfg;
2366         u8              MaxMssDensity;
2367         u8      bTxDisableRateFallBack;
2368         u8      bTxUseDriverAssingedRate;
2369         u8      bTxEnableFwCalcDur;
2370         atomic_t        atm_chnlop;
2371         atomic_t        atm_swbw;
2372
2373         struct list_head                Tx_TS_Admit_List;
2374         struct list_head                Tx_TS_Pending_List;
2375         struct list_head                Tx_TS_Unused_List;
2376         TX_TS_RECORD            TxTsRecord[TOTAL_TS_NUM];
2377         struct list_head                Rx_TS_Admit_List;
2378         struct list_head                Rx_TS_Pending_List;
2379         struct list_head                Rx_TS_Unused_List;
2380         RX_TS_RECORD            RxTsRecord[TOTAL_TS_NUM];
2381         RX_REORDER_ENTRY        RxReorderEntry[128];
2382         struct list_head                RxReorder_Unused_List;
2383         u8                              ForcedPriority;
2384
2385
2386         /* Bookkeeping structures */
2387         struct net_device_stats stats;
2388         struct rtllib_stats ieee_stats;
2389         struct rtllib_softmac_stats softmac_stats;
2390
2391         /* Probe / Beacon management */
2392         struct list_head network_free_list;
2393         struct list_head network_list;
2394 #ifdef RTL8192U
2395         struct list_head network_bssid_free_list;
2396         struct list_head network_bssid_list;
2397 #endif
2398         struct rtllib_network *networks;
2399         int scans;
2400         int scan_age;
2401
2402         int iw_mode; /* operating mode (IW_MODE_*) */
2403         bool bNetPromiscuousMode;
2404         RT_INTEL_PROMISCUOUS_MODE_INFO IntelPromiscuousModeInfo;
2405
2406         struct iw_spy_data spy_data;
2407
2408         spinlock_t lock;
2409         spinlock_t wpax_suitlist_lock;
2410
2411         int tx_headroom; /* Set to size of any additional room needed at front
2412                           * of allocated Tx SKBs */
2413         u32 config;
2414
2415         /* WEP and other encryption related settings at the device level */
2416         int open_wep; /* Set to 1 to allow unencrypted frames */
2417         int auth_mode;
2418         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
2419                                  * WEP key changes */
2420
2421         /* If the host performs {en,de}cryption, then set to 1 */
2422         int host_encrypt;
2423         int host_encrypt_msdu;
2424         int host_decrypt;
2425         /* host performs multicast decryption */
2426         int host_mc_decrypt;
2427
2428         /* host should strip IV and ICV from protected frames */
2429         /* meaningful only when hardware decryption is being used */
2430         int host_strip_iv_icv;
2431
2432         int host_open_frag;
2433         int host_build_iv;
2434         int ieee802_1x; /* is IEEE 802.1X used */
2435
2436         /* WPA data */
2437         bool bHalfNMode;
2438         bool bHalfWirelessN24GMode;
2439         int wpa_enabled;
2440         int drop_unencrypted;
2441         int tkip_countermeasures;
2442         int privacy_invoked;
2443         size_t wpa_ie_len;
2444         u8 *wpa_ie;
2445         size_t wps_ie_len;
2446         u8 *wps_ie;
2447         u8 ap_mac_addr[6];
2448         u16 pairwise_key_type;
2449         u16 group_key_type;
2450         struct list_head crypt_deinit_list;
2451         struct rtllib_crypt_data *crypt[WEP_KEYS];
2452
2453         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
2454         SW_CAM_TABLE swcamtable[TOTAL_CAM_ENTRY];
2455         struct timer_list crypt_deinit_timer;
2456         int crypt_quiesced;
2457
2458         int bcrx_sta_key; /* use individual keys to override default keys even
2459                            * with RX of broad/multicast frames */
2460
2461         RT_PMKID_LIST           PMKIDList[NUM_PMKID_CACHE];
2462
2463         /* Fragmentation structures */
2464         struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
2465         unsigned int frag_next_idx[17];
2466         u16 fts; /* Fragmentation Threshold */
2467 #define DEFAULT_RTS_THRESHOLD 2346U
2468 #define MIN_RTS_THRESHOLD 1
2469 #define MAX_RTS_THRESHOLD 2346U
2470         u16 rts; /* RTS threshold */
2471
2472         /* Association info */
2473         u8 bssid[ETH_ALEN];
2474
2475         /* This stores infos for the current network.
2476          * Either the network we are associated in INFRASTRUCTURE
2477          * or the network that we are creating in MASTER mode.
2478          * ad-hoc is a mixture ;-).
2479          * Note that in infrastructure mode, even when not associated,
2480          * fields bssid and essid may be valid (if wpa_set and essid_set
2481          * are true) as thy carry the value set by the user via iwconfig
2482          */
2483         struct rtllib_network current_network;
2484
2485         enum rtllib_state state;
2486
2487         int short_slot;
2488         int reg_mode;
2489         int mode;       /* A, B, G */
2490         int modulation; /* CCK, OFDM */
2491         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
2492         int abg_true;   /* ABG flag              */
2493
2494         /* used for forcing the ibss workqueue to terminate
2495          * without wait for the syncro scan to terminate
2496          */
2497         short sync_scan_hurryup;
2498         u16 scan_watch_dog;
2499         int perfect_rssi;
2500         int worst_rssi;
2501
2502         u16 prev_seq_ctl;       /* used to drop duplicate frames */
2503
2504         /* map of allowed channels. 0 is dummy */
2505 #ifdef ENABLE_DOT11D
2506         void* pDot11dInfo;
2507         bool bGlobalDomain;
2508 #else
2509         u8 channel_map[MAX_CHANNEL_NUMBER+1];
2510 #endif
2511         u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
2512
2513         u8   IbssStartChnl;
2514         u8   ibss_maxjoin_chal;
2515
2516         int rate;       /* current rate */
2517         int basic_rate;
2518         u32     currentRate;
2519
2520         short active_scan;
2521
2522         /* this contains flags for selectively enable softmac support */
2523         u16 softmac_features;
2524
2525         /* if the sequence control field is not filled by HW */
2526         u16 seq_ctrl[5];
2527
2528         /* association procedure transaction sequence number */
2529         u16 associate_seq;
2530
2531         /* AID for RTXed association responses */
2532         u16 assoc_id;
2533
2534         /* power save mode related*/
2535         u8 ack_tx_to_ieee;
2536         short ps;
2537         short sta_sleep;
2538         int ps_timeout;
2539         int ps_period;
2540         struct tasklet_struct ps_task;
2541         u32 ps_th;
2542         u32 ps_tl;
2543         bool polling;
2544
2545         short raw_tx;
2546         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2547         short queue_stop;
2548         short scanning_continue ;
2549         short proto_started;
2550         short proto_stoppping;
2551
2552         struct semaphore wx_sem;
2553         struct semaphore scan_sem;
2554         struct semaphore ips_sem;
2555
2556         spinlock_t mgmt_tx_lock;
2557         spinlock_t beacon_lock;
2558
2559         short beacon_txing;
2560
2561         short wap_set;
2562         short ssid_set;
2563
2564         /* set on initialization */
2565         u8  qos_support;
2566         unsigned int wmm_acm;
2567
2568         /* for discarding duplicated packets in IBSS */
2569         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
2570
2571         /* for discarding duplicated packets in BSS */
2572         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
2573         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
2574         unsigned long last_packet_time[17];
2575
2576         /* for PS mode */
2577         unsigned long last_rx_ps_time;
2578         bool                    bAwakePktSent;
2579         u8                      LPSDelayCnt;
2580
2581         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
2582         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
2583         int mgmt_queue_head;
2584         int mgmt_queue_tail;
2585 #define RTLLIB_QUEUE_LIMIT 128
2586         u8 AsocRetryCount;
2587         unsigned int hw_header;
2588         struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
2589         struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
2590         struct sk_buff_head  skb_drv_aggQ[MAX_QUEUE_SIZE];
2591         u32     sta_edca_param[4];
2592         bool aggregation;
2593         bool enable_rx_imm_BA;
2594         bool bibsscoordinator;
2595
2596         bool    bdynamic_txpower_enable;
2597
2598         bool bCTSToSelfEnable;
2599         u8      CTSToSelfTH;
2600
2601         u32     fsync_time_interval;
2602         u32     fsync_rate_bitmap;
2603         u8      fsync_rssi_threshold;
2604         bool    bfsync_enable;
2605
2606         u8      fsync_multiple_timeinterval;
2607         u32     fsync_firstdiff_ratethreshold;
2608         u32     fsync_seconddiff_ratethreshold;
2609         Fsync_State                     fsync_state;
2610         bool            bis_any_nonbepkts;
2611         bandwidth_autoswitch bandwidth_auto_switch;
2612         bool FwRWRF;
2613
2614         RT_LINK_DETECT_T        LinkDetectInfo;
2615         bool bIsAggregateFrame;
2616         RT_POWER_SAVE_CONTROL   PowerSaveControl;
2617         u8 amsdu_in_process;
2618
2619         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2620         struct  tx_pending_t tx_pending;
2621
2622         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
2623         struct timer_list associate_timer;
2624
2625         /* used if IEEE_SOFTMAC_BEACONS is set */
2626         struct timer_list beacon_timer;
2627         u8 need_sw_enc;
2628         work_struct_rsl associate_complete_wq;
2629         work_struct_rsl ips_leave_wq;
2630         delayed_work_struct_rsl associate_procedure_wq;
2631         delayed_work_struct_rsl softmac_scan_wq;
2632         delayed_work_struct_rsl softmac_hint11d_wq;
2633         delayed_work_struct_rsl associate_retry_wq;
2634         delayed_work_struct_rsl start_ibss_wq;
2635         delayed_work_struct_rsl hw_wakeup_wq;
2636         delayed_work_struct_rsl hw_sleep_wq;
2637         delayed_work_struct_rsl link_change_wq;
2638         work_struct_rsl wx_sync_scan_wq;
2639
2640         struct workqueue_struct *wq;
2641
2642         /* Callback functions */
2643         void (*set_security)(struct net_device *dev,
2644                              struct rtllib_security *sec);
2645
2646         /* Used to TX data frame by using txb structs.
2647          * this is not used if in the softmac_features
2648          * is set the flag IEEE_SOFTMAC_TX_QUEUE
2649          */
2650         int (*hard_start_xmit)(struct rtllib_txb *txb,
2651                                struct net_device *dev);
2652
2653         int (*reset_port)(struct net_device *dev);
2654         int (*is_queue_full) (struct net_device * dev, int pri);
2655
2656         int (*handle_management) (struct net_device * dev,
2657                                   struct rtllib_network * network, u16 type);
2658         int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
2659
2660         /* Softmac-generated frames (mamagement) are TXed via this
2661          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
2662          * not set. As some cards may have different HW queues that
2663          * one might want to use for data and management frames
2664          * the option to have two callbacks might be useful.
2665          * This fucntion can't sleep.
2666          */
2667         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
2668                                struct net_device *dev);
2669
2670         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
2671          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
2672          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
2673          * then also management frames are sent via this callback.
2674          * This function can't sleep.
2675          */
2676         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
2677                                struct net_device *dev,int rate);
2678
2679         /* stops the HW queue for DATA frames. Useful to avoid
2680          * waste time to TX data frame when we are reassociating
2681          * This function can sleep.
2682          */
2683         void (*data_hard_stop)(struct net_device *dev);
2684
2685         /* OK this is complementar to data_poll_hard_stop */
2686         void (*data_hard_resume)(struct net_device *dev);
2687
2688         /* ask to the driver to retune the radio .
2689          * This function can sleep. the driver should ensure
2690          * the radio has been swithced before return.
2691          */
2692         void (*set_chan)(struct net_device *dev,short ch);
2693
2694         /* These are not used if the ieee stack takes care of
2695          * scanning (IEEE_SOFTMAC_SCAN feature set).
2696          * In this case only the set_chan is used.
2697          *
2698          * The syncro version is similar to the start_scan but
2699          * does not return until all channels has been scanned.
2700          * this is called in user context and should sleep,
2701          * it is called in a work_queue when swithcing to ad-hoc mode
2702          * or in behalf of iwlist scan when the card is associated
2703          * and root user ask for a scan.
2704          * the fucntion stop_scan should stop both the syncro and
2705          * background scanning and can sleep.
2706          * The fucntion start_scan should initiate the background
2707          * scanning and can't sleep.
2708          */
2709         void (*scan_syncro)(struct net_device *dev);
2710         void (*start_scan)(struct net_device *dev);
2711         void (*stop_scan)(struct net_device *dev);
2712
2713         void (*rtllib_start_hw_scan)(struct net_device *dev);
2714         void (*rtllib_stop_hw_scan)(struct net_device *dev);
2715
2716         /* indicate the driver that the link state is changed
2717          * for example it may indicate the card is associated now.
2718          * Driver might be interested in this to apply RX filter
2719          * rules or simply light the LINK led
2720          */
2721         void (*link_change)(struct net_device *dev);
2722
2723         /* these two function indicates to the HW when to start
2724          * and stop to send beacons. This is used when the
2725          * IEEE_SOFTMAC_BEACONS is not set. For now the
2726          * stop_send_bacons is NOT guaranteed to be called only
2727          * after start_send_beacons.
2728          */
2729         void (*start_send_beacons) (struct net_device *dev);
2730         void (*stop_send_beacons) (struct net_device *dev);
2731
2732         /* power save mode related */
2733         void (*sta_wake_up) (struct net_device *dev);
2734         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
2735         short (*ps_is_queue_empty) (struct net_device *dev);
2736         int (*handle_beacon) (struct net_device * dev, struct rtllib_beacon * beacon, struct rtllib_network * network);
2737         int (*handle_assoc_response) (struct net_device * dev, struct rtllib_assoc_response_frame * resp, struct rtllib_network * network);
2738
2739
2740         /* check whether Tx hw resouce available */
2741         short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
2742         short (*get_nic_desc_num)(struct net_device *dev, int queue_index);
2743         void (*SetBWModeHandler)(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset);
2744         bool (*GetNmodeSupportBySecCfg)(struct net_device* dev);
2745         void (*SetWirelessMode)(struct net_device* dev, u8 wireless_mode);
2746         bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device* dev);
2747         u8   (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
2748         void (*HalUsbRxAggrHandler)(struct net_device *dev, bool Value);
2749         void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2750         bool (*SetFwCmdHandler)(struct net_device *dev, FW_CMD_IO_TYPE          FwCmdIO);
2751         void (*UpdateHalRAMaskHandler)(struct net_device* dev, bool bMulticast, u8 macId, u8 MimoPs, u8 WirelessMode, u8 bCurTxBW40MHz, u8 rssi_level);
2752         void (*UpdateBeaconInterruptHandler)(struct net_device* dev, bool start);
2753         void (*UpdateInterruptMaskHandler)(struct net_device* dev, u32 AddMSR, u32 RemoveMSR);
2754         u16  (*rtl_11n_user_show_rates)(struct net_device *dev);
2755         void (*ScanOperationBackupHandler)(struct net_device *dev, u8 Operation);
2756         void (*LedControlHandler)(struct net_device * dev, LED_CTL_MODE LedAction);
2757         void (*SetHwRegHandler)(struct net_device *dev,u8 variable,u8* val);
2758         void (*GetHwRegHandler)(struct net_device *dev,u8 variable,u8* val);
2759
2760         void (*AllowAllDestAddrHandler)(struct net_device *dev, bool bAllowAllDA, bool WriteIntoReg);
2761
2762         void (*rtllib_ips_leave_wq) (struct net_device *dev);
2763         void (*rtllib_ips_leave)(struct net_device *dev);
2764         void (*LeisurePSLeave)(struct net_device *dev);
2765         void (*rtllib_rfkill_poll)(struct net_device *dev);
2766
2767         /* This must be the last item so that it points to the data
2768          * allocated beyond this structure by alloc_rtllib */
2769         u8 priv[0];
2770 };
2771
2772 #define IEEE_A            (1<<0)
2773 #define IEEE_B            (1<<1)
2774 #define IEEE_G            (1<<2)
2775 #define IEEE_N_24G                (1<<4)
2776 #define IEEE_N_5G                 (1<<5)
2777 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
2778
2779 /* Generate a 802.11 header */
2780
2781 /* Uses the channel change callback directly
2782  * instead of [start/stop] scan callbacks
2783  */
2784 #define IEEE_SOFTMAC_SCAN (1<<2)
2785
2786 /* Perform authentication and association handshake */
2787 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
2788
2789 /* Generate probe requests */
2790 #define IEEE_SOFTMAC_PROBERQ (1<<4)
2791
2792 /* Generate respones to probe requests */
2793 #define IEEE_SOFTMAC_PROBERS (1<<5)
2794
2795 /* The ieee802.11 stack will manages the netif queue
2796  * wake/stop for the driver, taking care of 802.11
2797  * fragmentation. See softmac.c for details. */
2798 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2799
2800 /* Uses only the softmac_data_hard_start_xmit
2801  * even for TX management frames.
2802  */
2803 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
2804
2805 /* Generate beacons.  The stack will enqueue beacons
2806  * to the card
2807  */
2808 #define IEEE_SOFTMAC_BEACONS (1<<6)
2809
2810
2811 static inline void *rtllib_priv(struct net_device *dev)
2812 {
2813         return ((struct rtllib_device *)netdev_priv(dev))->priv;
2814 }
2815
2816 extern inline int rtllib_is_empty_essid(const char *essid, int essid_len)
2817 {
2818         /* Single white space is for Linksys APs */
2819         if (essid_len == 1 && essid[0] == ' ')
2820                 return 1;
2821
2822         /* Otherwise, if the entire essid is 0, we assume it is hidden */
2823         while (essid_len) {
2824                 essid_len--;
2825                 if (essid[essid_len] != '\0')
2826                         return 0;
2827         }
2828
2829         return 1;
2830 }
2831
2832 extern inline int rtllib_is_valid_mode(struct rtllib_device *ieee, int mode)
2833 {
2834         /*
2835          * It is possible for both access points and our device to support
2836          * combinations of modes, so as long as there is one valid combination
2837          * of ap/device supported modes, then return success
2838          *
2839          */
2840         if ((mode & IEEE_A) &&
2841             (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2842             (ieee->freq_band & RTLLIB_52GHZ_BAND))
2843                 return 1;
2844
2845         if ((mode & IEEE_G) &&
2846             (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2847             (ieee->freq_band & RTLLIB_24GHZ_BAND))
2848                 return 1;
2849
2850         if ((mode & IEEE_B) &&
2851             (ieee->modulation & RTLLIB_CCK_MODULATION) &&
2852             (ieee->freq_band & RTLLIB_24GHZ_BAND))
2853                 return 1;
2854
2855         return 0;
2856 }
2857
2858 extern inline int rtllib_get_hdrlen(u16 fc)
2859 {
2860         int hdrlen = RTLLIB_3ADDR_LEN;
2861
2862         switch (WLAN_FC_GET_TYPE(fc)) {
2863         case RTLLIB_FTYPE_DATA:
2864                 if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
2865                         hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
2866                 if (RTLLIB_QOS_HAS_SEQ(fc))
2867                         hdrlen += 2; /* QOS ctrl*/
2868                 break;
2869         case RTLLIB_FTYPE_CTL:
2870                 switch (WLAN_FC_GET_STYPE(fc)) {
2871                 case RTLLIB_STYPE_CTS:
2872                 case RTLLIB_STYPE_ACK:
2873                         hdrlen = RTLLIB_1ADDR_LEN;
2874                         break;
2875                 default:
2876                         hdrlen = RTLLIB_2ADDR_LEN;
2877                         break;
2878                 }
2879                 break;
2880         }
2881
2882         return hdrlen;
2883 }
2884
2885 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
2886 {
2887         switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
2888         case RTLLIB_1ADDR_LEN:
2889                 return ((struct rtllib_hdr_1addr *)hdr)->payload;
2890         case RTLLIB_2ADDR_LEN:
2891                 return ((struct rtllib_hdr_2addr *)hdr)->payload;
2892         case RTLLIB_3ADDR_LEN:
2893                 return ((struct rtllib_hdr_3addr *)hdr)->payload;
2894         case RTLLIB_4ADDR_LEN:
2895                 return ((struct rtllib_hdr_4addr *)hdr)->payload;
2896         }
2897         return NULL;
2898 }
2899
2900 static inline int rtllib_is_ofdm_rate(u8 rate)
2901 {
2902         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2903         case RTLLIB_OFDM_RATE_6MB:
2904         case RTLLIB_OFDM_RATE_9MB:
2905         case RTLLIB_OFDM_RATE_12MB:
2906         case RTLLIB_OFDM_RATE_18MB:
2907         case RTLLIB_OFDM_RATE_24MB:
2908         case RTLLIB_OFDM_RATE_36MB:
2909         case RTLLIB_OFDM_RATE_48MB:
2910         case RTLLIB_OFDM_RATE_54MB:
2911                 return 1;
2912         }
2913         return 0;
2914 }
2915
2916 static inline int rtllib_is_cck_rate(u8 rate)
2917 {
2918         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2919         case RTLLIB_CCK_RATE_1MB:
2920         case RTLLIB_CCK_RATE_2MB:
2921         case RTLLIB_CCK_RATE_5MB:
2922         case RTLLIB_CCK_RATE_11MB:
2923                 return 1;
2924         }
2925         return 0;
2926 }
2927
2928
2929 /* rtllib.c */
2930 extern void free_rtllib(struct net_device *dev);
2931 extern struct net_device *alloc_rtllib(int sizeof_priv);
2932
2933 extern int rtllib_set_encryption(struct rtllib_device *ieee);
2934
2935 /* rtllib_tx.c */
2936
2937 extern int rtllib_encrypt_fragment(
2938         struct rtllib_device *ieee,
2939         struct sk_buff *frag,
2940         int hdr_len);
2941
2942 extern int rtllib_xmit(struct sk_buff *skb,  struct net_device *dev);
2943 extern int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev);
2944 extern void rtllib_txb_free(struct rtllib_txb *);
2945
2946 /* rtllib_rx.c */
2947 extern int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
2948                         struct rtllib_rx_stats *rx_stats);
2949 extern void rtllib_rx_mgt(struct rtllib_device *ieee,
2950                              struct sk_buff *skb,
2951                              struct rtllib_rx_stats *stats);
2952 extern void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2953                            struct sk_buff *skb);
2954 extern int IsLegalChannel( struct rtllib_device *rtllib, u8 channel);
2955
2956 /* rtllib_wx.c */
2957 extern int rtllib_wx_get_scan(struct rtllib_device *ieee,
2958                                  struct iw_request_info *info,
2959                                  union iwreq_data *wrqu, char *key);
2960 extern int rtllib_wx_set_encode(struct rtllib_device *ieee,
2961                                    struct iw_request_info *info,
2962                                    union iwreq_data *wrqu, char *key);
2963 extern int rtllib_wx_get_encode(struct rtllib_device *ieee,
2964                                    struct iw_request_info *info,
2965                                    union iwreq_data *wrqu, char *key);
2966 #if WIRELESS_EXT >= 18
2967 extern int rtllib_wx_get_encode_ext(struct rtllib_device *ieee,
2968                             struct iw_request_info *info,
2969                             union iwreq_data* wrqu, char *extra);
2970 extern int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
2971                             struct iw_request_info *info,
2972                             union iwreq_data* wrqu, char *extra);
2973 #endif
2974 extern int rtllib_wx_set_auth(struct rtllib_device *ieee,
2975                                struct iw_request_info *info,
2976                                struct iw_param *data, char *extra);
2977 extern int rtllib_wx_set_mlme(struct rtllib_device *ieee,
2978                                struct iw_request_info *info,
2979                                union iwreq_data *wrqu, char *extra);
2980 extern int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
2981
2982 /* rtllib_softmac.c */
2983 extern short rtllib_is_54g(struct rtllib_network *net);
2984 extern short rtllib_is_shortslot(struct rtllib_network net);
2985 extern int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
2986                         struct rtllib_rx_stats *rx_stats, u16 type,
2987                         u16 stype);
2988 extern void rtllib_softmac_new_net(struct rtllib_device *ieee, struct rtllib_network *net);
2989
2990 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
2991 extern void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
2992
2993 extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2994 extern void notify_wx_assoc_event(struct rtllib_device *ieee);
2995 extern void rtllib_softmac_check_all_nets(struct rtllib_device *ieee);
2996 extern void rtllib_start_bss(struct rtllib_device *ieee);
2997 extern void rtllib_start_master_bss(struct rtllib_device *ieee);
2998 extern void rtllib_start_ibss(struct rtllib_device *ieee);
2999 extern void rtllib_softmac_init(struct rtllib_device *ieee);
3000 extern void rtllib_softmac_free(struct rtllib_device *ieee);
3001 extern void rtllib_associate_abort(struct rtllib_device *ieee);
3002 extern void rtllib_disassociate(struct rtllib_device *ieee);
3003 extern void rtllib_stop_scan(struct rtllib_device *ieee);
3004 extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
3005 extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
3006 extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
3007 extern inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee);
3008 extern u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee);
3009 extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
3010 extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
3011 extern void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
3012 extern void rtllib_check_all_nets(struct rtllib_device *ieee);
3013 extern void rtllib_start_protocol(struct rtllib_device *ieee);
3014 extern void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
3015
3016 extern void rtllib_EnableNetMonitorMode(struct net_device* dev, bool bInitState);
3017 extern void rtllib_DisableNetMonitorMode(struct net_device* dev, bool bInitState);
3018 extern void rtllib_EnableIntelPromiscuousMode(struct net_device* dev, bool bInitState);
3019 extern void rtllib_DisableIntelPromiscuousMode(struct net_device* dev, bool bInitState);
3020 extern void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh);
3021
3022 extern void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag, u8 shutdown);
3023 extern void rtllib_softmac_start_protocol(struct rtllib_device *ieee,u8 mesh_flag);
3024
3025 extern void rtllib_reset_queue(struct rtllib_device *ieee);
3026 extern void rtllib_wake_queue(struct rtllib_device *ieee);
3027 extern void rtllib_stop_queue(struct rtllib_device *ieee);
3028 extern void rtllib_wake_all_queues(struct rtllib_device *ieee);
3029 extern void rtllib_stop_all_queues(struct rtllib_device *ieee);
3030 extern struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
3031 extern void rtllib_start_send_beacons(struct rtllib_device *ieee);
3032 extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
3033 extern int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p, u8 is_mesh);
3034
3035 extern void notify_wx_assoc_event(struct rtllib_device *ieee);
3036 extern void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
3037
3038 extern void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
3039 extern u16 rtllib_query_seqnum(struct rtllib_device*ieee, struct sk_buff* skb, u8* dst);
3040 extern u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
3041
3042 /* rtllib_crypt_ccmp&tkip&wep.c */
3043 extern void rtllib_tkip_null(void);
3044 extern void rtllib_wep_null(void);
3045 extern void rtllib_ccmp_null(void);
3046
3047 /* rtllib_softmac_wx.c */
3048
3049 extern int rtllib_wx_get_wap(struct rtllib_device *ieee,
3050                             struct iw_request_info *info,
3051                             union iwreq_data *wrqu, char *ext);
3052
3053 extern int rtllib_wx_set_wap(struct rtllib_device *ieee,
3054                          struct iw_request_info *info,
3055                          union iwreq_data *awrq,
3056                          char *extra);
3057
3058 extern int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
3059
3060 extern int rtllib_wx_set_rate(struct rtllib_device *ieee,
3061                              struct iw_request_info *info,
3062                              union iwreq_data *wrqu, char *extra);
3063
3064 extern int rtllib_wx_get_rate(struct rtllib_device *ieee,
3065                              struct iw_request_info *info,
3066                              union iwreq_data *wrqu, char *extra);
3067
3068 extern int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
3069                              union iwreq_data *wrqu, char *b);
3070
3071 extern int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
3072                              union iwreq_data *wrqu, char *b);
3073
3074 extern int rtllib_wx_set_essid(struct rtllib_device *ieee,
3075                               struct iw_request_info *a,
3076                               union iwreq_data *wrqu, char *extra);
3077
3078 extern int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
3079                              union iwreq_data *wrqu, char *b);
3080
3081 extern int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
3082                              union iwreq_data *wrqu, char *b);
3083
3084 extern int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
3085                              union iwreq_data *wrqu, char *b);
3086 extern void rtllib_wx_sync_scan_wq(void *data);
3087
3088 extern int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
3089                                struct iw_request_info *info,
3090                                union iwreq_data *wrqu, char *extra);
3091
3092 extern int rtllib_wx_get_name(struct rtllib_device *ieee,
3093                              struct iw_request_info *info,
3094                              union iwreq_data *wrqu, char *extra);
3095
3096 extern int rtllib_wx_set_power(struct rtllib_device *ieee,
3097                                  struct iw_request_info *info,
3098                                  union iwreq_data *wrqu, char *extra);
3099
3100 extern int rtllib_wx_get_power(struct rtllib_device *ieee,
3101                                  struct iw_request_info *info,
3102                                  union iwreq_data *wrqu, char *extra);
3103
3104 extern int rtllib_wx_set_rts(struct rtllib_device *ieee,
3105                              struct iw_request_info *info,
3106                              union iwreq_data *wrqu, char *extra);
3107
3108 extern int rtllib_wx_get_rts(struct rtllib_device *ieee,
3109                              struct iw_request_info *info,
3110                              union iwreq_data *wrqu, char *extra);
3111 #define MAX_RECEIVE_BUFFER_SIZE 9100
3112 extern void HTDebugHTCapability(u8* CapIE, u8* TitleString );
3113 extern void HTDebugHTInfo(u8*  InfoIE, u8* TitleString);
3114
3115 void HTSetConnectBwMode(struct rtllib_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
3116 extern void HTUpdateDefaultSetting(struct rtllib_device* ieee);
3117 extern void HTConstructCapabilityElement(struct rtllib_device* ieee, u8* posHTCap, u8* len, u8 isEncrypt,bool bAssoc);
3118 extern void HTConstructInfoElement(struct rtllib_device* ieee, u8* posHTInfo, u8* len, u8 isEncrypt);
3119 extern void HTConstructRT2RTAggElement(struct rtllib_device* ieee, u8* posRT2RTAgg, u8* len);
3120 extern void HTOnAssocRsp(struct rtllib_device *ieee);
3121 extern void HTInitializeHTInfo(struct rtllib_device* ieee);
3122 extern void HTInitializeBssDesc(PBSS_HT pBssHT);
3123 extern void HTResetSelfAndSavePeerSetting(struct rtllib_device* ieee, struct rtllib_network * pNetwork);
3124 extern void HTUpdateSelfAndPeerSetting(struct rtllib_device* ieee,   struct rtllib_network * pNetwork);
3125 extern u8 HTGetHighestMCSRate(struct rtllib_device* ieee, u8* pMCSRateSet, u8* pMCSFilter);
3126 extern u8 MCS_FILTER_ALL[];
3127 extern u16 MCS_DATA_RATE[2][2][77] ;
3128 extern u8 HTCCheck(struct rtllib_device* ieee, u8*   pFrame);
3129 extern void HTResetIOTSetting(PRT_HIGH_THROUGHPUT  pHTInfo);
3130 extern bool IsHTHalfNmodeAPs(struct rtllib_device* ieee);
3131 extern u16 HTHalfMcsToDataRate(struct rtllib_device* ieee,  u8      nMcsRate);
3132 extern u16 HTMcsToDataRate( struct rtllib_device* ieee, u8 nMcsRate);
3133 extern u16  TxCountToDataRate( struct rtllib_device* ieee, u8 nDataRate);
3134 extern int rtllib_rx_ADDBAReq( struct rtllib_device* ieee, struct sk_buff *skb);
3135 extern int rtllib_rx_ADDBARsp( struct rtllib_device* ieee, struct sk_buff *skb);
3136 extern int rtllib_rx_DELBA(struct rtllib_device* ieee,struct sk_buff *skb);
3137 extern void TsInitAddBA( struct rtllib_device* ieee, PTX_TS_RECORD   pTS, u8 Policy, u8 bOverwritePending);
3138 extern void TsInitDelBA( struct rtllib_device* ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect);
3139 extern void BaSetupTimeOut(unsigned long data);
3140 extern void TxBaInactTimeout(unsigned long data);
3141 extern void RxBaInactTimeout(unsigned long data);
3142 extern void ResetBaEntry( PBA_RECORD pBA);
3143 extern bool GetTs(
3144         struct rtllib_device*        ieee,
3145         PTS_COMMON_INFO                 *ppTS,
3146         u8*                             Addr,
3147         u8                              TID,
3148         TR_SELECT                       TxRxSelect,
3149         bool                            bAddNewTs
3150         );
3151 extern void TSInitialize(struct rtllib_device *ieee);
3152 extern  void TsStartAddBaProcess(struct rtllib_device* ieee, PTX_TS_RECORD   pTxTS);
3153 extern void RemovePeerTS(struct rtllib_device* ieee, u8* Addr);
3154 extern void RemoveAllTS(struct rtllib_device* ieee);
3155 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
3156
3157 extern const long rtllib_wlan_frequencies[];
3158
3159 extern inline void rtllib_increment_scans(struct rtllib_device *ieee)
3160 {
3161         ieee->scans++;
3162 }
3163
3164 extern inline int rtllib_get_scans(struct rtllib_device *ieee)
3165 {
3166         return ieee->scans;
3167 }
3168
3169 static inline const char *escape_essid(const char *essid, u8 essid_len) {
3170         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
3171         const char *s = essid;
3172         char *d = escaped;
3173
3174         if (rtllib_is_empty_essid(essid, essid_len)) {
3175                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
3176                 return escaped;
3177         }
3178
3179         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
3180         while (essid_len--) {
3181                 if (*s == '\0') {
3182                         *d++ = '\\';
3183                         *d++ = '0';
3184                         s++;
3185                 } else {
3186                         *d++ = *s++;
3187                 }
3188         }
3189         *d = '\0';
3190         return escaped;
3191 }
3192
3193 #define CONVERT_RATE(_ieee, _MGN_RATE)  (_MGN_RATE<MGN_MCS0)?(_MGN_RATE):(HTMcsToDataRate(_ieee, (u8)_MGN_RATE))
3194
3195 /* fun with the built-in rtllib stack... */
3196 int rtllib_init(void);
3197 void rtllib_exit(void);
3198 int rtllib_crypto_init(void);
3199 void rtllib_crypto_deinit(void);
3200 int rtllib_crypto_tkip_init(void);
3201 void rtllib_crypto_tkip_exit(void);
3202 int rtllib_crypto_ccmp_init(void);
3203 void rtllib_crypto_ccmp_exit(void);
3204 int rtllib_crypto_wep_init(void);
3205 void rtllib_crypto_wep_exit(void);
3206
3207 void rtllib_MgntDisconnectIBSS(struct rtllib_device* rtllib);
3208 void rtllib_MlmeDisassociateRequest(struct rtllib_device* rtllib, u8* asSta,u8  asRsn);
3209 void rtllib_MgntDisconnectAP(struct rtllib_device* rtllib,      u8 asRsn);
3210 bool rtllib_MgntDisconnect(struct rtllib_device* rtllib,u8 asRsn);
3211
3212
3213 /* For the function is more related to hardware setting, it's better to use the
3214  * ieee handler to refer to it.
3215  */
3216 extern void rtllib_update_active_chan_map(struct rtllib_device *ieee);
3217 extern void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, PRX_TS_RECORD pTS);
3218 extern int rtllib_data_xmit(struct sk_buff *skb, struct net_device *dev);
3219 extern int rtllib_parse_info_param(struct rtllib_device *ieee,
3220                 struct rtllib_info_element *info_element,
3221                 u16 length,
3222                 struct rtllib_network *network,
3223                 struct rtllib_rx_stats *stats);
3224
3225 void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb** prxbIndicateArray,u8  index);
3226 #if defined(RTL8192U) || defined(RTL8192SU) || defined(RTL8192SE)
3227 extern void IbssAgeFunction(struct rtllib_device *ieee);
3228 extern struct sta_info *GetStaInfo(struct rtllib_device *ieee, u8 *addr);
3229 extern void DelStaInfoList(struct rtllib_device *ieee);
3230 extern void DelStaInfo(struct rtllib_device *ieee, u8 *addr);
3231 #endif
3232 extern u8 HTFilterMCSRate( struct rtllib_device* ieee, u8* pSupportMCS, u8* pOperateMCS);
3233 extern void HTUseDefaultSetting(struct rtllib_device* ieee);
3234 #define RT_ASOC_RETRY_LIMIT     5
3235 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
3236 extern void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p);
3237 #ifndef ENABLE_LOCK_DEBUG
3238 #define SPIN_LOCK_IEEE(plock) spin_lock_irqsave((plock), flags)
3239 #define SPIN_UNLOCK_IEEE(plock) spin_unlock_irqrestore((plock), flags)
3240 #define SPIN_LOCK_IEEE_REORDER(plock) spin_lock_irqsave((plock), flags)
3241 #define SPIN_UNLOCK_IEEE_REORDER(plock) spin_unlock_irqrestore((plock), flags)
3242 #define SPIN_LOCK_IEEE_WPAX(plock) spin_lock_irqsave((plock), flags)
3243 #define SPIN_UNLOCK_IEEE_WPAX(plock) spin_unlock_irqrestore((plock), flags)
3244 #define SPIN_LOCK_IEEE_MGNTTX(plock) spin_lock_irqsave((plock), flags)
3245 #define SPIN_UNLOCK_IEEE_MGNTTX(plock) spin_unlock_irqrestore((plock), flags)
3246 #define SPIN_LOCK_IEEE_BCN(plock) spin_lock_irqsave((plock), flags)
3247 #define SPIN_UNLOCK_IEEE_BCN(plock) spin_unlock_irqrestore((plock), flags)
3248 #define SPIN_LOCK_MSH_STAINFO(plock) spin_lock_irqsave((plock), flags)
3249 #define SPIN_UNLOCK_MSH_STAINFO(plock) spin_unlock_irqrestore((plock), flags)
3250 #define SPIN_LOCK_MSH_PREQ(plock) spin_lock_irqsave((plock), flags)
3251 #define SPIN_UNLOCK_MSH_PREQ(plock) spin_unlock_irqrestore((plock), flags)
3252 #define SPIN_LOCK_MSH_QUEUE(plock) spin_lock_irqsave((plock), flags)
3253 #define SPIN_UNLOCK_MSH_QUEUE(plock) spin_unlock_irqrestore((plock), flags)
3254 #define SPIN_LOCK_PRIV_RFPS(plock) spin_lock_irqsave((plock), flags)
3255 #define SPIN_UNLOCK_PRIV_RFPS(plock) spin_unlock_irqrestore((plock), flags)
3256 #define SPIN_LOCK_PRIV_IRQTH(plock) spin_lock_irqsave((plock), flags)
3257 #define SPIN_UNLOCK_PRIV_IRQTH(plock) spin_unlock_irqrestore((plock), flags)
3258 #define SPIN_LOCK_PRIV_TX(plock) spin_lock_irqsave((plock), flags)
3259 #define SPIN_UNLOCK_PRIV_TX(plock) spin_unlock_irqrestore((plock), flags)
3260 #define SPIN_LOCK_PRIV_D3(plock) spin_lock_irqsave((plock), flags)
3261 #define SPIN_UNLOCK_PRIV_D3(plock) spin_unlock_irqrestore((plock), flags)
3262 #define SPIN_LOCK_PRIV_RF(plock) spin_lock_irqsave((plock), flags)
3263 #define SPIN_UNLOCK_PRIV_RF(plock) spin_unlock_irqrestore((plock), flags)
3264 #define SPIN_LOCK_PRIV_PS(plock) spin_lock_irqsave((plock), flags)
3265 #define SPIN_UNLOCK_PRIV_PS(plock) spin_unlock_irqrestore((plock), flags)
3266 #define SEM_DOWN_IEEE_WX(psem) down(psem)
3267 #define SEM_UP_IEEE_WX(psem) up(psem)
3268 #define SEM_DOWN_IEEE_SCAN(psem) down(psem)
3269 #define SEM_UP_IEEE_SCAN(psem) up(psem)
3270 #define SEM_DOWN_IEEE_IPS(psem) down(psem)
3271 #define SEM_UP_IEEE_IPS(psem) up(psem)
3272 #define SEM_DOWN_PRIV_WX(psem) down(psem)
3273 #define SEM_UP_PRIV_WX(psem) up(psem)
3274 #define SEM_DOWN_PRIV_RF(psem) down(psem)
3275 #define SEM_UP_PRIV_RF(psem) up(psem)
3276 #define MUTEX_LOCK_PRIV(pmutex) mutex_lock(pmutex)
3277 #define MUTEX_UNLOCK_PRIV(pmutex) mutex_unlock(pmutex)
3278 #endif
3279 static inline void dump_buf(u8 *buf, u32 len)
3280 {
3281         u32 i;
3282         printk("-----------------Len %d----------------\n", len);
3283         for (i=0; i<len; i++)
3284                 printk("%2.2x-", *(buf+i));
3285         printk("\n");
3286 }
3287 #endif /* RTLLIB_H */