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