]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8192e/rtllib.h
staging: rtl8192e: Remove ifdefs that depend on ENABLE_DOT11D
[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         u16 CountryIeLen;
1745         u8 CountryIeBuf[MAX_IE_LEN];
1746         BSS_HT  bssht;
1747         bool broadcom_cap_exist;
1748         bool realtek_cap_exit;
1749         bool marvell_cap_exist;
1750         bool ralink_cap_exist;
1751         bool atheros_cap_exist;
1752         bool cisco_cap_exist;
1753         bool airgo_cap_exist;
1754         bool unknown_cap_exist;
1755         bool    berp_info_valid;
1756         bool buseprotection;
1757         bool bIsNetgear854T;
1758         u8 SignalStrength;
1759         u8 RSSI;
1760         struct list_head list;
1761 };
1762
1763 #if 1
1764 enum rtllib_state {
1765
1766         /* the card is not linked at all */
1767         RTLLIB_NOLINK = 0,
1768
1769         /* RTLLIB_ASSOCIATING* are for BSS client mode
1770          * the driver shall not perform RX filtering unless
1771          * the state is LINKED.
1772          * The driver shall just check for the state LINKED and
1773          * defaults to NOLINK for ALL the other states (including
1774          * LINKED_SCANNING)
1775          */
1776
1777         /* the association procedure will start (wq scheduling)*/
1778         RTLLIB_ASSOCIATING,
1779         RTLLIB_ASSOCIATING_RETRY,
1780
1781         /* the association procedure is sending AUTH request*/
1782         RTLLIB_ASSOCIATING_AUTHENTICATING,
1783
1784         /* the association procedure has successfully authentcated
1785          * and is sending association request
1786          */
1787         RTLLIB_ASSOCIATING_AUTHENTICATED,
1788
1789         /* the link is ok. the card associated to a BSS or linked
1790          * to a ibss cell or acting as an AP and creating the bss
1791          */
1792         RTLLIB_LINKED,
1793
1794         /* same as LINKED, but the driver shall apply RX filter
1795          * rules as we are in NO_LINK mode. As the card is still
1796          * logically linked, but it is doing a syncro site survey
1797          * then it will be back to LINKED state.
1798          */
1799         RTLLIB_LINKED_SCANNING,
1800 };
1801 #else
1802 enum rtllib_state {
1803         RTLLIB_UNINITIALIZED = 0,
1804         RTLLIB_INITIALIZED,
1805         RTLLIB_ASSOCIATING,
1806         RTLLIB_ASSOCIATED,
1807         RTLLIB_AUTHENTICATING,
1808         RTLLIB_AUTHENTICATED,
1809         RTLLIB_SHUTDOWN
1810 };
1811 #endif
1812
1813 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1814 #define DEFAULT_FTS 2346
1815
1816 #define CFG_RTLLIB_RESERVE_FCS (1<<0)
1817 #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1818 #define CFG_RTLLIB_RTS (1<<2)
1819
1820 #define RTLLIB_24GHZ_MIN_CHANNEL 1
1821 #define RTLLIB_24GHZ_MAX_CHANNEL 14
1822 #define RTLLIB_24GHZ_CHANNELS (RTLLIB_24GHZ_MAX_CHANNEL - \
1823                                   RTLLIB_24GHZ_MIN_CHANNEL + 1)
1824
1825 #define RTLLIB_52GHZ_MIN_CHANNEL 34
1826 #define RTLLIB_52GHZ_MAX_CHANNEL 165
1827 #define RTLLIB_52GHZ_CHANNELS (RTLLIB_52GHZ_MAX_CHANNEL - \
1828                                   RTLLIB_52GHZ_MIN_CHANNEL + 1)
1829 #ifndef eqMacAddr
1830 #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 )
1831 #endif
1832 typedef struct tx_pending_t{
1833         int frag;
1834         struct rtllib_txb *txb;
1835 }tx_pending_t;
1836
1837 typedef struct _bandwidth_autoswitch
1838 {
1839         long threshold_20Mhzto40Mhz;
1840         long    threshold_40Mhzto20Mhz;
1841         bool bforced_tx20Mhz;
1842         bool bautoswitch_enable;
1843 }bandwidth_autoswitch,*pbandwidth_autoswitch;
1844
1845
1846
1847 #define REORDER_WIN_SIZE        128
1848 #define REORDER_ENTRY_NUM       128
1849 typedef struct _RX_REORDER_ENTRY
1850 {
1851         struct list_head        List;
1852         u16                     SeqNum;
1853         struct rtllib_rxb* prxb;
1854 } RX_REORDER_ENTRY, *PRX_REORDER_ENTRY;
1855 typedef enum _Fsync_State{
1856         Default_Fsync,
1857         HW_Fsync,
1858         SW_Fsync
1859 }Fsync_State;
1860
1861 typedef enum _RT_PS_MODE
1862 {
1863         eActive,
1864         eMaxPs,
1865         eFastPs,
1866         eAutoPs,
1867 }RT_PS_MODE;
1868
1869 typedef enum _IPS_CALLBACK_FUNCION
1870 {
1871         IPS_CALLBACK_NONE = 0,
1872         IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1873         IPS_CALLBACK_JOIN_REQUEST = 2,
1874 }IPS_CALLBACK_FUNCION;
1875
1876 typedef enum _RT_JOIN_ACTION{
1877         RT_JOIN_INFRA   = 1,
1878         RT_JOIN_IBSS  = 2,
1879         RT_START_IBSS = 3,
1880         RT_NO_ACTION  = 4,
1881 }RT_JOIN_ACTION;
1882
1883 typedef struct _IbssParms{
1884         u16   atimWin;
1885 }IbssParms, *PIbssParms;
1886 #define MAX_NUM_RATES   264
1887
1888 typedef enum _RT_RF_POWER_STATE
1889 {
1890         eRfOn,
1891         eRfSleep,
1892         eRfOff
1893 }RT_RF_POWER_STATE;
1894
1895 #define MAX_SUPPORT_WOL_PATTERN_NUM             8
1896
1897 #define MAX_WOL_BIT_MASK_SIZE           16
1898 #define MAX_WOL_PATTERN_SIZE            128
1899
1900 typedef enum _WOLPATTERN_TYPE
1901 {
1902         eNetBIOS = 0,
1903         eIPv4IPv6ARP,
1904         eIPv4IPv6TCPSYN,
1905         eMACIDOnly,
1906         eNoDefined,
1907 }WOLPATTERN_TYPE;
1908
1909 typedef struct _RT_PM_WOL_PATTERN_INFO
1910 {
1911         u32     PatternId;
1912         u32     Mask[4];
1913         u16     CrcRemainder;
1914         u8      WFMIndex;
1915         WOLPATTERN_TYPE PatternType;
1916 }RT_PM_WOL_PATTERN_INFO, *PRT_PM_WOL_PATTERN_INFO;
1917
1918 typedef struct _RT_POWER_SAVE_CONTROL
1919 {
1920
1921         bool                            bInactivePs;
1922         bool                            bIPSModeBackup;
1923         bool                            bHaltAdapterClkRQ;
1924         bool                            bSwRfProcessing;
1925         RT_RF_POWER_STATE       eInactivePowerState;
1926         work_struct_rsl         InactivePsWorkItem;
1927         struct timer_list       InactivePsTimer;
1928
1929         IPS_CALLBACK_FUNCION    ReturnPoint;
1930
1931         bool                            bTmpBssDesc;
1932         RT_JOIN_ACTION          tmpJoinAction;
1933         struct rtllib_network tmpBssDesc;
1934
1935         bool                            bTmpScanOnly;
1936         bool                            bTmpActiveScan;
1937         bool                            bTmpFilterHiddenAP;
1938         bool                            bTmpUpdateParms;
1939         u8                              tmpSsidBuf[33];
1940         OCTET_STRING                    tmpSsid2Scan;
1941         bool                            bTmpSsid2Scan;
1942         u8                              tmpNetworkType;
1943         u8                              tmpChannelNumber;
1944         u16                             tmpBcnPeriod;
1945         u8                              tmpDtimPeriod;
1946         u16                             tmpmCap;
1947         OCTET_STRING                    tmpSuppRateSet;
1948         u8                              tmpSuppRateBuf[MAX_NUM_RATES];
1949         bool                            bTmpSuppRate;
1950         IbssParms                               tmpIbpm;
1951         bool                            bTmpIbpm;
1952
1953         bool                            bLeisurePs;
1954         u32                             PowerProfile;
1955         u8                              LpsIdleCount;
1956         u8                              RegMaxLPSAwakeIntvl;
1957         u8                              LPSAwakeIntvl;
1958
1959         u32                             CurPsLevel;
1960         u32                             RegRfPsLevel;
1961
1962         bool                            bFwCtrlLPS;
1963         u8                              FWCtrlPSMode;
1964
1965         bool                            LinkReqInIPSRFOffPgs;
1966         bool                            BufConnectinfoBefore;
1967
1968
1969         bool                            bGpioRfSw;
1970
1971         u8                              RegAMDPciASPM;
1972
1973         u8                              oWLANMode;
1974         RT_PM_WOL_PATTERN_INFO          PmWoLPatternInfo[MAX_SUPPORT_WOL_PATTERN_NUM];
1975
1976 }RT_POWER_SAVE_CONTROL,*PRT_POWER_SAVE_CONTROL;
1977
1978 typedef u32 RT_RF_CHANGE_SOURCE;
1979 #define RF_CHANGE_BY_SW BIT31
1980 #define RF_CHANGE_BY_HW BIT30
1981 #define RF_CHANGE_BY_PS BIT29
1982 #define RF_CHANGE_BY_IPS BIT28
1983 #define RF_CHANGE_BY_INIT       0
1984
1985 typedef enum
1986 {
1987         COUNTRY_CODE_FCC = 0,
1988         COUNTRY_CODE_IC = 1,
1989         COUNTRY_CODE_ETSI = 2,
1990         COUNTRY_CODE_SPAIN = 3,
1991         COUNTRY_CODE_FRANCE = 4,
1992         COUNTRY_CODE_MKK = 5,
1993         COUNTRY_CODE_MKK1 = 6,
1994         COUNTRY_CODE_ISRAEL = 7,
1995         COUNTRY_CODE_TELEC = 8,
1996         COUNTRY_CODE_MIC = 9,
1997         COUNTRY_CODE_GLOBAL_DOMAIN = 10,
1998         COUNTRY_CODE_WORLD_WIDE_13 = 11,
1999         COUNTRY_CODE_TELEC_NETGEAR = 12,
2000         COUNTRY_CODE_MAX
2001 }country_code_type_t;
2002
2003 typedef enum _SCAN_OPERATION_BACKUP_OPT{
2004         SCAN_OPT_BACKUP=0,
2005         SCAN_OPT_RESTORE,
2006         SCAN_OPT_MAX
2007 }SCAN_OPERATION_BACKUP_OPT;
2008
2009 typedef enum _FW_CMD_IO_TYPE{
2010         FW_CMD_DIG_ENABLE = 0,
2011         FW_CMD_DIG_DISABLE = 1,
2012         FW_CMD_DIG_HALT = 2,
2013         FW_CMD_DIG_RESUME = 3,
2014         FW_CMD_HIGH_PWR_ENABLE = 4,
2015         FW_CMD_HIGH_PWR_DISABLE = 5,
2016         FW_CMD_RA_RESET = 6,
2017         FW_CMD_RA_ACTIVE= 7,
2018         FW_CMD_RA_REFRESH_N= 8,
2019         FW_CMD_RA_REFRESH_BG= 9,
2020         FW_CMD_RA_INIT= 10,
2021         FW_CMD_IQK_ENABLE = 11,
2022         FW_CMD_TXPWR_TRACK_ENABLE = 12,
2023         FW_CMD_TXPWR_TRACK_DISABLE = 13,
2024         FW_CMD_TXPWR_TRACK_THERMAL = 14,
2025         FW_CMD_PAUSE_DM_BY_SCAN = 15,
2026         FW_CMD_RESUME_DM_BY_SCAN = 16,
2027         FW_CMD_RA_REFRESH_N_COMB = 17,
2028         FW_CMD_RA_REFRESH_BG_COMB = 18,
2029         FW_CMD_ANTENNA_SW_ENABLE = 19,
2030         FW_CMD_ANTENNA_SW_DISABLE = 20,
2031         FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
2032         FW_CMD_LPS_ENTER = 22,
2033         FW_CMD_LPS_LEAVE = 23,
2034         FW_CMD_DIG_MODE_SS = 24,
2035         FW_CMD_DIG_MODE_FA = 25,
2036         FW_CMD_ADD_A2_ENTRY = 26,
2037         FW_CMD_CTRL_DM_BY_DRIVER = 27,
2038         FW_CMD_CTRL_DM_BY_DRIVER_NEW = 28,
2039         FW_CMD_PAPE_CONTROL = 29,
2040         FW_CMD_CHAN_SET = 30,
2041 }FW_CMD_IO_TYPE,*PFW_CMD_IO_TYPE;
2042
2043 #define RT_MAX_LD_SLOT_NUM      10
2044 typedef struct _RT_LINK_DETECT_T{
2045
2046         u32                             NumRecvBcnInPeriod;
2047         u32                             NumRecvDataInPeriod;
2048
2049         u32                             RxBcnNum[RT_MAX_LD_SLOT_NUM];
2050         u32                             RxDataNum[RT_MAX_LD_SLOT_NUM];
2051         u16                             SlotNum;
2052         u16                             SlotIndex;
2053
2054         u32                             NumTxOkInPeriod;
2055         u32                             NumRxOkInPeriod;
2056         u32                             NumRxUnicastOkInPeriod;
2057         bool                            bBusyTraffic;
2058         bool                            bHigherBusyTraffic;
2059         bool                            bHigherBusyRxTraffic;
2060         u8                              IdleCount;
2061         u32                             NumTxUnicastOkInPeriod;
2062         u32                             LastNumTxUnicast;
2063         u32                             LastNumRxUnicast;
2064 }RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
2065
2066 typedef struct _SW_CAM_TABLE{
2067
2068         u8                              macaddr[6];
2069         bool                            bused;
2070         u8                              key_buf[16];
2071         u16                             key_type;
2072         u8                              useDK;
2073         u8                              key_index;
2074
2075 }SW_CAM_TABLE,*PSW_CAM_TABLE;
2076 #define   TOTAL_CAM_ENTRY                               32
2077 typedef struct _rate_adaptive
2078 {
2079         u8                              rate_adaptive_disabled;
2080         u8                              ratr_state;
2081         u16                             reserve;
2082
2083         u32                             high_rssi_thresh_for_ra;
2084         u32                             high2low_rssi_thresh_for_ra;
2085         u8                              low2high_rssi_thresh_for_ra40M;
2086         u32                             low_rssi_thresh_for_ra40M;
2087         u8                              low2high_rssi_thresh_for_ra20M;
2088         u32                             low_rssi_thresh_for_ra20M;
2089         u32                             upper_rssi_threshold_ratr;
2090         u32                             middle_rssi_threshold_ratr;
2091         u32                             low_rssi_threshold_ratr;
2092         u32                             low_rssi_threshold_ratr_40M;
2093         u32                             low_rssi_threshold_ratr_20M;
2094         u8                              ping_rssi_enable;
2095         u32                             ping_rssi_ratr;
2096         u32                             ping_rssi_thresh_for_ra;
2097         u32                             last_ratr;
2098         u8                              PreRATRState;
2099
2100 } rate_adaptive, *prate_adaptive;
2101 typedef enum _RATR_TABLE_MODE_8192S{
2102         RATR_INX_WIRELESS_NGB = 0,
2103         RATR_INX_WIRELESS_NG = 1,
2104         RATR_INX_WIRELESS_NB = 2,
2105         RATR_INX_WIRELESS_N = 3,
2106         RATR_INX_WIRELESS_GB = 4,
2107         RATR_INX_WIRELESS_G = 5,
2108         RATR_INX_WIRELESS_B = 6,
2109         RATR_INX_WIRELESS_MC = 7,
2110         RATR_INX_WIRELESS_A = 8,
2111 }RATR_TABLE_MODE_8192S, *PRATR_TABLE_MODE_8192S;
2112
2113 #define NUM_PMKID_CACHE         16
2114 typedef struct _RT_PMKID_LIST
2115 {
2116         u8                                              bUsed;
2117         u8                                              Bssid[6];
2118         u8                                              PMKID[16];
2119         u8                                              SsidBuf[33];
2120         u8*                                             ssid_octet;
2121         u16                                     ssid_length;
2122 } RT_PMKID_LIST, *PRT_PMKID_LIST;
2123
2124 #ifdef CONFIG_CFG_80211
2125 enum {
2126         LIBIPW_CH_PASSIVE_ONLY          = (1 << 0),
2127         LIBIPW_CH_80211H_RULES          = (1 << 1),
2128         LIBIPW_CH_B_ONLY                = (1 << 2),
2129         LIBIPW_CH_NO_IBSS               = (1 << 3),
2130         LIBIPW_CH_UNIFORM_SPREADING     = (1 << 4),
2131         LIBIPW_CH_RADAR_DETECT          = (1 << 5),
2132         LIBIPW_CH_INVALID               = (1 << 6),
2133 };
2134 struct rtllib_channel {
2135         u32 freq;
2136         u8 channel;
2137         u8 flags;
2138         u8 max_power;
2139 };
2140
2141 #define RTLLIB_24GHZ_MIN_CHANNEL 1
2142 #define RTLLIB_24GHZ_MAX_CHANNEL 14
2143 #define RTLLIB_24GHZ_CHANNELS (RTLLIB_24GHZ_MAX_CHANNEL - \
2144                 RTLLIB_24GHZ_MIN_CHANNEL + 1)
2145
2146 struct reg_dmn_pair_mapping {
2147         u16 regDmnEnum;
2148         u16 reg_5ghz_ctl;
2149         u16 reg_2ghz_ctl;
2150 };
2151
2152 struct rtl_regulatory {
2153         char alpha2[2];
2154         u16 country_code;
2155         u16 max_power_level;
2156         u32 tp_scale;
2157         u16 current_rd;
2158         u16 current_rd_ext;
2159         int16_t power_limit;
2160         struct reg_dmn_pair_mapping *regpair;
2161 };
2162
2163 struct ieee80211_bss {
2164         /* Yes, this is a hack */
2165         struct cfg80211_bss cbss;
2166
2167         /* don't want to look up all the time */
2168         size_t ssid_len;
2169         u8 ssid[IEEE80211_MAX_SSID_LEN];
2170
2171         u8 dtim_period;
2172
2173         bool wmm_used;
2174
2175         unsigned long last_probe_resp;
2176
2177 #ifdef CONFIG_MAC80211_MESH
2178         u8 *mesh_id;
2179         size_t mesh_id_len;
2180         u8 *mesh_cfg;
2181 #endif
2182
2183         #define IEEE80211_MAX_SUPP_RATES 32
2184         u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
2185         size_t supp_rates_len;
2186
2187         /*
2188          * During assocation, we save an ERP value from a probe response so
2189          * that we can feed ERP info to the driver when handling the
2190          * association completes. these fields probably won't be up-to-date
2191          * otherwise, you probably don't want to use them.
2192          */
2193         bool has_erp_value;
2194         u8 erp_value;
2195 };
2196
2197 /* Parsed Information Elements */
2198 struct ieee802_11_elems {
2199         u8 *ie_start;
2200         size_t total_len;
2201
2202         /* pointers to IEs */
2203         u8 *ssid;
2204         u8 *supp_rates;
2205         u8 *fh_params;
2206         u8 *ds_params;
2207         u8 *cf_params;
2208         struct ieee80211_tim_ie *tim;
2209         u8 *ibss_params;
2210         u8 *challenge;
2211         u8 *wpa;
2212         u8 *rsn;
2213         u8 *erp_info;
2214         u8 *ext_supp_rates;
2215         u8 *wmm_info;
2216         u8 *wmm_param;
2217         struct ieee80211_ht_cap *ht_cap_elem;
2218         struct ieee80211_ht_info *ht_info_elem;
2219         u8 *mesh_config;
2220         u8 *mesh_id;
2221         u8 *peer_link;
2222         u8 *preq;
2223         u8 *prep;
2224         u8 *perr;
2225         u8 *ch_switch_elem;
2226         u8 *country_elem;
2227         u8 *pwr_constr_elem;
2228         u8 *quiet_elem;         /* first quite element */
2229         u8 *timeout_int;
2230
2231         /* length of them, respectively */
2232         u8 ssid_len;
2233         u8 supp_rates_len;
2234         u8 fh_params_len;
2235         u8 ds_params_len;
2236         u8 cf_params_len;
2237         u8 tim_len;
2238         u8 ibss_params_len;
2239         u8 challenge_len;
2240         u8 wpa_len;
2241         u8 rsn_len;
2242         u8 erp_info_len;
2243         u8 ext_supp_rates_len;
2244         u8 wmm_info_len;
2245         u8 wmm_param_len;
2246         u8 mesh_config_len;
2247         u8 mesh_id_len;
2248         u8 peer_link_len;
2249         u8 preq_len;
2250         u8 prep_len;
2251         u8 perr_len;
2252         u8 ch_switch_elem_len;
2253         u8 country_elem_len;
2254         u8 pwr_constr_elem_len;
2255         u8 quiet_elem_len;
2256         u8 num_of_quiet_elem;   /* can be more the one */
2257         u8 timeout_int_len;
2258 };
2259
2260 #endif
2261
2262
2263 typedef struct _RT_INTEL_PROMISCUOUS_MODE_INFO {
2264      bool bPromiscuousOn;
2265      bool bFilterSourceStationFrame;
2266 } RT_INTEL_PROMISCUOUS_MODE_INFO, *PRT_INTEL_PROMISCUOUS_MODE_INFO;
2267
2268
2269 /*************** DRIVER STATUS   *****/
2270 #define STATUS_SCANNING                 0
2271 #define STATUS_SCAN_HW                  1
2272 #define STATUS_SCAN_ABORTING    2
2273 #define STATUS_SETTING_CHAN             3
2274 /*************** DRIVER STATUS   *****/
2275
2276 enum {
2277         NO_USE          = 0,
2278         USED            = 1,
2279         HW_SEC  = 2,
2280         SW_SEC          = 3,
2281 };
2282
2283 enum {
2284         LPS_IS_WAKE = 0,
2285         LPS_IS_SLEEP = 1,
2286         LPS_WAIT_NULL_DATA_SEND =2,
2287 };
2288
2289 struct rtllib_device {
2290         struct pci_dev *pdev;
2291         struct net_device *dev;
2292         struct rtllib_security sec;
2293
2294         bool disable_mgnt_queue;
2295
2296         unsigned long status;
2297         short hwscan_ch_bk;
2298         HT_EXTCHNL_OFFSET chan_offset_bk;
2299         HT_CHANNEL_WIDTH bandwidth_bk;
2300         u8 hwscan_sem_up;
2301 #ifdef CONFIG_CFG_80211
2302         struct wireless_dev wdev;
2303         struct rtl_regulatory regulatory;
2304 #endif
2305         u8      CntAfterLink;
2306
2307         RT_OP_MODE      OpMode;
2308
2309         u8 VersionID;
2310         /* The last AssocReq/Resp IEs */
2311         u8 *assocreq_ies, *assocresp_ies;
2312         size_t assocreq_ies_len, assocresp_ies_len;
2313
2314         bool b_customer_lenovo_id;
2315         bool    bForcedShowRxRate;
2316         bool    bForcedShowRateStill;
2317         u8      SystemQueryDataRateCount;
2318         bool    bForcedBgMode;
2319         bool bUseRAMask;
2320         bool b1x1RecvCombine;
2321         u8 RF_Type;
2322         bool b1SSSupport;
2323
2324         u8 hwsec_active;
2325         bool is_silent_reset;
2326       bool force_mic_error;
2327         bool is_roaming;
2328         bool ieee_up;
2329         bool cannot_notify;
2330         bool bSupportRemoteWakeUp;
2331         RT_PS_MODE      dot11PowerSaveMode;
2332         bool actscanning;
2333         bool FirstIe_InScan;
2334         bool be_scan_inprogress;
2335         bool beinretry;
2336         RT_RF_POWER_STATE               eRFPowerState;
2337         RT_RF_CHANGE_SOURCE     RfOffReason;
2338         bool is_set_key;
2339         bool wx_set_enc;
2340         PRT_HIGH_THROUGHPUT     pHTInfo;
2341         spinlock_t bw_spinlock;
2342
2343         spinlock_t reorder_spinlock;
2344         u8      Regdot11HTOperationalRateSet[16];
2345         u8      Regdot11TxHTOperationalRateSet[16];
2346         u8      dot11HTOperationalRateSet[16];
2347         u8      RegHTSuppRateSet[16];
2348         u8                              HTCurrentOperaRate;
2349         u8                              HTHighestOperaRate;
2350        u8               MinSpaceCfg;
2351         u8              MaxMssDensity;
2352         u8      bTxDisableRateFallBack;
2353         u8      bTxUseDriverAssingedRate;
2354         u8      bTxEnableFwCalcDur;
2355         atomic_t        atm_chnlop;
2356         atomic_t        atm_swbw;
2357
2358         struct list_head                Tx_TS_Admit_List;
2359         struct list_head                Tx_TS_Pending_List;
2360         struct list_head                Tx_TS_Unused_List;
2361         TX_TS_RECORD            TxTsRecord[TOTAL_TS_NUM];
2362         struct list_head                Rx_TS_Admit_List;
2363         struct list_head                Rx_TS_Pending_List;
2364         struct list_head                Rx_TS_Unused_List;
2365         RX_TS_RECORD            RxTsRecord[TOTAL_TS_NUM];
2366         RX_REORDER_ENTRY        RxReorderEntry[128];
2367         struct list_head                RxReorder_Unused_List;
2368         u8                              ForcedPriority;
2369
2370
2371         /* Bookkeeping structures */
2372         struct net_device_stats stats;
2373         struct rtllib_stats ieee_stats;
2374         struct rtllib_softmac_stats softmac_stats;
2375
2376         /* Probe / Beacon management */
2377         struct list_head network_free_list;
2378         struct list_head network_list;
2379         struct rtllib_network *networks;
2380         int scans;
2381         int scan_age;
2382
2383         int iw_mode; /* operating mode (IW_MODE_*) */
2384         bool bNetPromiscuousMode;
2385         RT_INTEL_PROMISCUOUS_MODE_INFO IntelPromiscuousModeInfo;
2386
2387         struct iw_spy_data spy_data;
2388
2389         spinlock_t lock;
2390         spinlock_t wpax_suitlist_lock;
2391
2392         int tx_headroom; /* Set to size of any additional room needed at front
2393                           * of allocated Tx SKBs */
2394         u32 config;
2395
2396         /* WEP and other encryption related settings at the device level */
2397         int open_wep; /* Set to 1 to allow unencrypted frames */
2398         int auth_mode;
2399         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
2400                                  * WEP key changes */
2401
2402         /* If the host performs {en,de}cryption, then set to 1 */
2403         int host_encrypt;
2404         int host_encrypt_msdu;
2405         int host_decrypt;
2406         /* host performs multicast decryption */
2407         int host_mc_decrypt;
2408
2409         /* host should strip IV and ICV from protected frames */
2410         /* meaningful only when hardware decryption is being used */
2411         int host_strip_iv_icv;
2412
2413         int host_open_frag;
2414         int host_build_iv;
2415         int ieee802_1x; /* is IEEE 802.1X used */
2416
2417         /* WPA data */
2418         bool bHalfNMode;
2419         bool bHalfWirelessN24GMode;
2420         int wpa_enabled;
2421         int drop_unencrypted;
2422         int tkip_countermeasures;
2423         int privacy_invoked;
2424         size_t wpa_ie_len;
2425         u8 *wpa_ie;
2426         size_t wps_ie_len;
2427         u8 *wps_ie;
2428         u8 ap_mac_addr[6];
2429         u16 pairwise_key_type;
2430         u16 group_key_type;
2431         struct list_head crypt_deinit_list;
2432         struct rtllib_crypt_data *crypt[WEP_KEYS];
2433
2434         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
2435         SW_CAM_TABLE swcamtable[TOTAL_CAM_ENTRY];
2436         struct timer_list crypt_deinit_timer;
2437         int crypt_quiesced;
2438
2439         int bcrx_sta_key; /* use individual keys to override default keys even
2440                            * with RX of broad/multicast frames */
2441
2442         RT_PMKID_LIST           PMKIDList[NUM_PMKID_CACHE];
2443
2444         /* Fragmentation structures */
2445         struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
2446         unsigned int frag_next_idx[17];
2447         u16 fts; /* Fragmentation Threshold */
2448 #define DEFAULT_RTS_THRESHOLD 2346U
2449 #define MIN_RTS_THRESHOLD 1
2450 #define MAX_RTS_THRESHOLD 2346U
2451         u16 rts; /* RTS threshold */
2452
2453         /* Association info */
2454         u8 bssid[ETH_ALEN];
2455
2456         /* This stores infos for the current network.
2457          * Either the network we are associated in INFRASTRUCTURE
2458          * or the network that we are creating in MASTER mode.
2459          * ad-hoc is a mixture ;-).
2460          * Note that in infrastructure mode, even when not associated,
2461          * fields bssid and essid may be valid (if wpa_set and essid_set
2462          * are true) as thy carry the value set by the user via iwconfig
2463          */
2464         struct rtllib_network current_network;
2465
2466         enum rtllib_state state;
2467
2468         int short_slot;
2469         int reg_mode;
2470         int mode;       /* A, B, G */
2471         int modulation; /* CCK, OFDM */
2472         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
2473         int abg_true;   /* ABG flag              */
2474
2475         /* used for forcing the ibss workqueue to terminate
2476          * without wait for the syncro scan to terminate
2477          */
2478         short sync_scan_hurryup;
2479         u16 scan_watch_dog;
2480         int perfect_rssi;
2481         int worst_rssi;
2482
2483         u16 prev_seq_ctl;       /* used to drop duplicate frames */
2484
2485         /* map of allowed channels. 0 is dummy */
2486         void* pDot11dInfo;
2487         bool bGlobalDomain;
2488         u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
2489
2490         u8   IbssStartChnl;
2491         u8   ibss_maxjoin_chal;
2492
2493         int rate;       /* current rate */
2494         int basic_rate;
2495         u32     currentRate;
2496
2497         short active_scan;
2498
2499         /* this contains flags for selectively enable softmac support */
2500         u16 softmac_features;
2501
2502         /* if the sequence control field is not filled by HW */
2503         u16 seq_ctrl[5];
2504
2505         /* association procedure transaction sequence number */
2506         u16 associate_seq;
2507
2508         /* AID for RTXed association responses */
2509         u16 assoc_id;
2510
2511         /* power save mode related*/
2512         u8 ack_tx_to_ieee;
2513         short ps;
2514         short sta_sleep;
2515         int ps_timeout;
2516         int ps_period;
2517         struct tasklet_struct ps_task;
2518         u32 ps_th;
2519         u32 ps_tl;
2520         bool polling;
2521
2522         short raw_tx;
2523         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2524         short queue_stop;
2525         short scanning_continue ;
2526         short proto_started;
2527         short proto_stoppping;
2528
2529         struct semaphore wx_sem;
2530         struct semaphore scan_sem;
2531         struct semaphore ips_sem;
2532
2533         spinlock_t mgmt_tx_lock;
2534         spinlock_t beacon_lock;
2535
2536         short beacon_txing;
2537
2538         short wap_set;
2539         short ssid_set;
2540
2541         /* set on initialization */
2542         u8  qos_support;
2543         unsigned int wmm_acm;
2544
2545         /* for discarding duplicated packets in IBSS */
2546         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
2547
2548         /* for discarding duplicated packets in BSS */
2549         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
2550         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
2551         unsigned long last_packet_time[17];
2552
2553         /* for PS mode */
2554         unsigned long last_rx_ps_time;
2555         bool                    bAwakePktSent;
2556         u8                      LPSDelayCnt;
2557
2558         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
2559         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
2560         int mgmt_queue_head;
2561         int mgmt_queue_tail;
2562 #define RTLLIB_QUEUE_LIMIT 128
2563         u8 AsocRetryCount;
2564         unsigned int hw_header;
2565         struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
2566         struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
2567         struct sk_buff_head  skb_drv_aggQ[MAX_QUEUE_SIZE];
2568         u32     sta_edca_param[4];
2569         bool aggregation;
2570         bool enable_rx_imm_BA;
2571         bool bibsscoordinator;
2572
2573         bool    bdynamic_txpower_enable;
2574
2575         bool bCTSToSelfEnable;
2576         u8      CTSToSelfTH;
2577
2578         u32     fsync_time_interval;
2579         u32     fsync_rate_bitmap;
2580         u8      fsync_rssi_threshold;
2581         bool    bfsync_enable;
2582
2583         u8      fsync_multiple_timeinterval;
2584         u32     fsync_firstdiff_ratethreshold;
2585         u32     fsync_seconddiff_ratethreshold;
2586         Fsync_State                     fsync_state;
2587         bool            bis_any_nonbepkts;
2588         bandwidth_autoswitch bandwidth_auto_switch;
2589         bool FwRWRF;
2590
2591         RT_LINK_DETECT_T        LinkDetectInfo;
2592         bool bIsAggregateFrame;
2593         RT_POWER_SAVE_CONTROL   PowerSaveControl;
2594         u8 amsdu_in_process;
2595
2596         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2597         struct  tx_pending_t tx_pending;
2598
2599         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
2600         struct timer_list associate_timer;
2601
2602         /* used if IEEE_SOFTMAC_BEACONS is set */
2603         struct timer_list beacon_timer;
2604         u8 need_sw_enc;
2605         work_struct_rsl associate_complete_wq;
2606         work_struct_rsl ips_leave_wq;
2607         delayed_work_struct_rsl associate_procedure_wq;
2608         delayed_work_struct_rsl softmac_scan_wq;
2609         delayed_work_struct_rsl softmac_hint11d_wq;
2610         delayed_work_struct_rsl associate_retry_wq;
2611         delayed_work_struct_rsl start_ibss_wq;
2612         delayed_work_struct_rsl hw_wakeup_wq;
2613         delayed_work_struct_rsl hw_sleep_wq;
2614         delayed_work_struct_rsl link_change_wq;
2615         work_struct_rsl wx_sync_scan_wq;
2616
2617         struct workqueue_struct *wq;
2618
2619         /* Callback functions */
2620         void (*set_security)(struct net_device *dev,
2621                              struct rtllib_security *sec);
2622
2623         /* Used to TX data frame by using txb structs.
2624          * this is not used if in the softmac_features
2625          * is set the flag IEEE_SOFTMAC_TX_QUEUE
2626          */
2627         int (*hard_start_xmit)(struct rtllib_txb *txb,
2628                                struct net_device *dev);
2629
2630         int (*reset_port)(struct net_device *dev);
2631         int (*is_queue_full) (struct net_device * dev, int pri);
2632
2633         int (*handle_management) (struct net_device * dev,
2634                                   struct rtllib_network * network, u16 type);
2635         int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
2636
2637         /* Softmac-generated frames (mamagement) are TXed via this
2638          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
2639          * not set. As some cards may have different HW queues that
2640          * one might want to use for data and management frames
2641          * the option to have two callbacks might be useful.
2642          * This fucntion can't sleep.
2643          */
2644         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
2645                                struct net_device *dev);
2646
2647         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
2648          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
2649          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
2650          * then also management frames are sent via this callback.
2651          * This function can't sleep.
2652          */
2653         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
2654                                struct net_device *dev,int rate);
2655
2656         /* stops the HW queue for DATA frames. Useful to avoid
2657          * waste time to TX data frame when we are reassociating
2658          * This function can sleep.
2659          */
2660         void (*data_hard_stop)(struct net_device *dev);
2661
2662         /* OK this is complementar to data_poll_hard_stop */
2663         void (*data_hard_resume)(struct net_device *dev);
2664
2665         /* ask to the driver to retune the radio .
2666          * This function can sleep. the driver should ensure
2667          * the radio has been swithced before return.
2668          */
2669         void (*set_chan)(struct net_device *dev,short ch);
2670
2671         /* These are not used if the ieee stack takes care of
2672          * scanning (IEEE_SOFTMAC_SCAN feature set).
2673          * In this case only the set_chan is used.
2674          *
2675          * The syncro version is similar to the start_scan but
2676          * does not return until all channels has been scanned.
2677          * this is called in user context and should sleep,
2678          * it is called in a work_queue when swithcing to ad-hoc mode
2679          * or in behalf of iwlist scan when the card is associated
2680          * and root user ask for a scan.
2681          * the fucntion stop_scan should stop both the syncro and
2682          * background scanning and can sleep.
2683          * The fucntion start_scan should initiate the background
2684          * scanning and can't sleep.
2685          */
2686         void (*scan_syncro)(struct net_device *dev);
2687         void (*start_scan)(struct net_device *dev);
2688         void (*stop_scan)(struct net_device *dev);
2689
2690         void (*rtllib_start_hw_scan)(struct net_device *dev);
2691         void (*rtllib_stop_hw_scan)(struct net_device *dev);
2692
2693         /* indicate the driver that the link state is changed
2694          * for example it may indicate the card is associated now.
2695          * Driver might be interested in this to apply RX filter
2696          * rules or simply light the LINK led
2697          */
2698         void (*link_change)(struct net_device *dev);
2699
2700         /* these two function indicates to the HW when to start
2701          * and stop to send beacons. This is used when the
2702          * IEEE_SOFTMAC_BEACONS is not set. For now the
2703          * stop_send_bacons is NOT guaranteed to be called only
2704          * after start_send_beacons.
2705          */
2706         void (*start_send_beacons) (struct net_device *dev);
2707         void (*stop_send_beacons) (struct net_device *dev);
2708
2709         /* power save mode related */
2710         void (*sta_wake_up) (struct net_device *dev);
2711         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
2712         short (*ps_is_queue_empty) (struct net_device *dev);
2713         int (*handle_beacon) (struct net_device * dev, struct rtllib_beacon * beacon, struct rtllib_network * network);
2714         int (*handle_assoc_response) (struct net_device * dev, struct rtllib_assoc_response_frame * resp, struct rtllib_network * network);
2715
2716
2717         /* check whether Tx hw resouce available */
2718         short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
2719         short (*get_nic_desc_num)(struct net_device *dev, int queue_index);
2720         void (*SetBWModeHandler)(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset);
2721         bool (*GetNmodeSupportBySecCfg)(struct net_device* dev);
2722         void (*SetWirelessMode)(struct net_device* dev, u8 wireless_mode);
2723         bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device* dev);
2724         u8   (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
2725         void (*HalUsbRxAggrHandler)(struct net_device *dev, bool Value);
2726         void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2727         bool (*SetFwCmdHandler)(struct net_device *dev, FW_CMD_IO_TYPE          FwCmdIO);
2728         void (*UpdateHalRAMaskHandler)(struct net_device* dev, bool bMulticast, u8 macId, u8 MimoPs, u8 WirelessMode, u8 bCurTxBW40MHz, u8 rssi_level);
2729         void (*UpdateBeaconInterruptHandler)(struct net_device* dev, bool start);
2730         void (*UpdateInterruptMaskHandler)(struct net_device* dev, u32 AddMSR, u32 RemoveMSR);
2731         u16  (*rtl_11n_user_show_rates)(struct net_device *dev);
2732         void (*ScanOperationBackupHandler)(struct net_device *dev, u8 Operation);
2733         void (*LedControlHandler)(struct net_device * dev, LED_CTL_MODE LedAction);
2734         void (*SetHwRegHandler)(struct net_device *dev,u8 variable,u8* val);
2735         void (*GetHwRegHandler)(struct net_device *dev,u8 variable,u8* val);
2736
2737         void (*AllowAllDestAddrHandler)(struct net_device *dev, bool bAllowAllDA, bool WriteIntoReg);
2738
2739         void (*rtllib_ips_leave_wq) (struct net_device *dev);
2740         void (*rtllib_ips_leave)(struct net_device *dev);
2741         void (*LeisurePSLeave)(struct net_device *dev);
2742         void (*rtllib_rfkill_poll)(struct net_device *dev);
2743
2744         /* This must be the last item so that it points to the data
2745          * allocated beyond this structure by alloc_rtllib */
2746         u8 priv[0];
2747 };
2748
2749 #define IEEE_A            (1<<0)
2750 #define IEEE_B            (1<<1)
2751 #define IEEE_G            (1<<2)
2752 #define IEEE_N_24G                (1<<4)
2753 #define IEEE_N_5G                 (1<<5)
2754 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
2755
2756 /* Generate a 802.11 header */
2757
2758 /* Uses the channel change callback directly
2759  * instead of [start/stop] scan callbacks
2760  */
2761 #define IEEE_SOFTMAC_SCAN (1<<2)
2762
2763 /* Perform authentication and association handshake */
2764 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
2765
2766 /* Generate probe requests */
2767 #define IEEE_SOFTMAC_PROBERQ (1<<4)
2768
2769 /* Generate respones to probe requests */
2770 #define IEEE_SOFTMAC_PROBERS (1<<5)
2771
2772 /* The ieee802.11 stack will manages the netif queue
2773  * wake/stop for the driver, taking care of 802.11
2774  * fragmentation. See softmac.c for details. */
2775 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2776
2777 /* Uses only the softmac_data_hard_start_xmit
2778  * even for TX management frames.
2779  */
2780 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
2781
2782 /* Generate beacons.  The stack will enqueue beacons
2783  * to the card
2784  */
2785 #define IEEE_SOFTMAC_BEACONS (1<<6)
2786
2787
2788 static inline void *rtllib_priv(struct net_device *dev)
2789 {
2790         return ((struct rtllib_device *)netdev_priv(dev))->priv;
2791 }
2792
2793 extern inline int rtllib_is_empty_essid(const char *essid, int essid_len)
2794 {
2795         /* Single white space is for Linksys APs */
2796         if (essid_len == 1 && essid[0] == ' ')
2797                 return 1;
2798
2799         /* Otherwise, if the entire essid is 0, we assume it is hidden */
2800         while (essid_len) {
2801                 essid_len--;
2802                 if (essid[essid_len] != '\0')
2803                         return 0;
2804         }
2805
2806         return 1;
2807 }
2808
2809 extern inline int rtllib_is_valid_mode(struct rtllib_device *ieee, int mode)
2810 {
2811         /*
2812          * It is possible for both access points and our device to support
2813          * combinations of modes, so as long as there is one valid combination
2814          * of ap/device supported modes, then return success
2815          *
2816          */
2817         if ((mode & IEEE_A) &&
2818             (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2819             (ieee->freq_band & RTLLIB_52GHZ_BAND))
2820                 return 1;
2821
2822         if ((mode & IEEE_G) &&
2823             (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2824             (ieee->freq_band & RTLLIB_24GHZ_BAND))
2825                 return 1;
2826
2827         if ((mode & IEEE_B) &&
2828             (ieee->modulation & RTLLIB_CCK_MODULATION) &&
2829             (ieee->freq_band & RTLLIB_24GHZ_BAND))
2830                 return 1;
2831
2832         return 0;
2833 }
2834
2835 extern inline int rtllib_get_hdrlen(u16 fc)
2836 {
2837         int hdrlen = RTLLIB_3ADDR_LEN;
2838
2839         switch (WLAN_FC_GET_TYPE(fc)) {
2840         case RTLLIB_FTYPE_DATA:
2841                 if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
2842                         hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
2843                 if (RTLLIB_QOS_HAS_SEQ(fc))
2844                         hdrlen += 2; /* QOS ctrl*/
2845                 break;
2846         case RTLLIB_FTYPE_CTL:
2847                 switch (WLAN_FC_GET_STYPE(fc)) {
2848                 case RTLLIB_STYPE_CTS:
2849                 case RTLLIB_STYPE_ACK:
2850                         hdrlen = RTLLIB_1ADDR_LEN;
2851                         break;
2852                 default:
2853                         hdrlen = RTLLIB_2ADDR_LEN;
2854                         break;
2855                 }
2856                 break;
2857         }
2858
2859         return hdrlen;
2860 }
2861
2862 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
2863 {
2864         switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
2865         case RTLLIB_1ADDR_LEN:
2866                 return ((struct rtllib_hdr_1addr *)hdr)->payload;
2867         case RTLLIB_2ADDR_LEN:
2868                 return ((struct rtllib_hdr_2addr *)hdr)->payload;
2869         case RTLLIB_3ADDR_LEN:
2870                 return ((struct rtllib_hdr_3addr *)hdr)->payload;
2871         case RTLLIB_4ADDR_LEN:
2872                 return ((struct rtllib_hdr_4addr *)hdr)->payload;
2873         }
2874         return NULL;
2875 }
2876
2877 static inline int rtllib_is_ofdm_rate(u8 rate)
2878 {
2879         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2880         case RTLLIB_OFDM_RATE_6MB:
2881         case RTLLIB_OFDM_RATE_9MB:
2882         case RTLLIB_OFDM_RATE_12MB:
2883         case RTLLIB_OFDM_RATE_18MB:
2884         case RTLLIB_OFDM_RATE_24MB:
2885         case RTLLIB_OFDM_RATE_36MB:
2886         case RTLLIB_OFDM_RATE_48MB:
2887         case RTLLIB_OFDM_RATE_54MB:
2888                 return 1;
2889         }
2890         return 0;
2891 }
2892
2893 static inline int rtllib_is_cck_rate(u8 rate)
2894 {
2895         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2896         case RTLLIB_CCK_RATE_1MB:
2897         case RTLLIB_CCK_RATE_2MB:
2898         case RTLLIB_CCK_RATE_5MB:
2899         case RTLLIB_CCK_RATE_11MB:
2900                 return 1;
2901         }
2902         return 0;
2903 }
2904
2905
2906 /* rtllib.c */
2907 extern void free_rtllib(struct net_device *dev);
2908 extern struct net_device *alloc_rtllib(int sizeof_priv);
2909
2910 extern int rtllib_set_encryption(struct rtllib_device *ieee);
2911
2912 /* rtllib_tx.c */
2913
2914 extern int rtllib_encrypt_fragment(
2915         struct rtllib_device *ieee,
2916         struct sk_buff *frag,
2917         int hdr_len);
2918
2919 extern int rtllib_xmit(struct sk_buff *skb,  struct net_device *dev);
2920 extern int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev);
2921 extern void rtllib_txb_free(struct rtllib_txb *);
2922
2923 /* rtllib_rx.c */
2924 extern int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
2925                         struct rtllib_rx_stats *rx_stats);
2926 extern void rtllib_rx_mgt(struct rtllib_device *ieee,
2927                              struct sk_buff *skb,
2928                              struct rtllib_rx_stats *stats);
2929 extern void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2930                            struct sk_buff *skb);
2931 extern int IsLegalChannel( struct rtllib_device *rtllib, u8 channel);
2932
2933 /* rtllib_wx.c */
2934 extern int rtllib_wx_get_scan(struct rtllib_device *ieee,
2935                                  struct iw_request_info *info,
2936                                  union iwreq_data *wrqu, char *key);
2937 extern int rtllib_wx_set_encode(struct rtllib_device *ieee,
2938                                    struct iw_request_info *info,
2939                                    union iwreq_data *wrqu, char *key);
2940 extern int rtllib_wx_get_encode(struct rtllib_device *ieee,
2941                                    struct iw_request_info *info,
2942                                    union iwreq_data *wrqu, char *key);
2943 #if WIRELESS_EXT >= 18
2944 extern int rtllib_wx_get_encode_ext(struct rtllib_device *ieee,
2945                             struct iw_request_info *info,
2946                             union iwreq_data* wrqu, char *extra);
2947 extern int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
2948                             struct iw_request_info *info,
2949                             union iwreq_data* wrqu, char *extra);
2950 #endif
2951 extern int rtllib_wx_set_auth(struct rtllib_device *ieee,
2952                                struct iw_request_info *info,
2953                                struct iw_param *data, char *extra);
2954 extern int rtllib_wx_set_mlme(struct rtllib_device *ieee,
2955                                struct iw_request_info *info,
2956                                union iwreq_data *wrqu, char *extra);
2957 extern int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
2958
2959 /* rtllib_softmac.c */
2960 extern short rtllib_is_54g(struct rtllib_network *net);
2961 extern short rtllib_is_shortslot(struct rtllib_network net);
2962 extern int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
2963                         struct rtllib_rx_stats *rx_stats, u16 type,
2964                         u16 stype);
2965 extern void rtllib_softmac_new_net(struct rtllib_device *ieee, struct rtllib_network *net);
2966
2967 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
2968 extern void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
2969
2970 extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2971 extern void notify_wx_assoc_event(struct rtllib_device *ieee);
2972 extern void rtllib_softmac_check_all_nets(struct rtllib_device *ieee);
2973 extern void rtllib_start_bss(struct rtllib_device *ieee);
2974 extern void rtllib_start_master_bss(struct rtllib_device *ieee);
2975 extern void rtllib_start_ibss(struct rtllib_device *ieee);
2976 extern void rtllib_softmac_init(struct rtllib_device *ieee);
2977 extern void rtllib_softmac_free(struct rtllib_device *ieee);
2978 extern void rtllib_associate_abort(struct rtllib_device *ieee);
2979 extern void rtllib_disassociate(struct rtllib_device *ieee);
2980 extern void rtllib_stop_scan(struct rtllib_device *ieee);
2981 extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
2982 extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
2983 extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2984 extern inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee);
2985 extern u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee);
2986 extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
2987 extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
2988 extern void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
2989 extern void rtllib_check_all_nets(struct rtllib_device *ieee);
2990 extern void rtllib_start_protocol(struct rtllib_device *ieee);
2991 extern void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
2992
2993 extern void rtllib_EnableNetMonitorMode(struct net_device* dev, bool bInitState);
2994 extern void rtllib_DisableNetMonitorMode(struct net_device* dev, bool bInitState);
2995 extern void rtllib_EnableIntelPromiscuousMode(struct net_device* dev, bool bInitState);
2996 extern void rtllib_DisableIntelPromiscuousMode(struct net_device* dev, bool bInitState);
2997 extern void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh);
2998
2999 extern void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag, u8 shutdown);
3000 extern void rtllib_softmac_start_protocol(struct rtllib_device *ieee,u8 mesh_flag);
3001
3002 extern void rtllib_reset_queue(struct rtllib_device *ieee);
3003 extern void rtllib_wake_queue(struct rtllib_device *ieee);
3004 extern void rtllib_stop_queue(struct rtllib_device *ieee);
3005 extern void rtllib_wake_all_queues(struct rtllib_device *ieee);
3006 extern void rtllib_stop_all_queues(struct rtllib_device *ieee);
3007 extern struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
3008 extern void rtllib_start_send_beacons(struct rtllib_device *ieee);
3009 extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
3010 extern int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p, u8 is_mesh);
3011
3012 extern void notify_wx_assoc_event(struct rtllib_device *ieee);
3013 extern void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
3014
3015 extern void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
3016 extern u16 rtllib_query_seqnum(struct rtllib_device*ieee, struct sk_buff* skb, u8* dst);
3017 extern u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
3018
3019 /* rtllib_crypt_ccmp&tkip&wep.c */
3020 extern void rtllib_tkip_null(void);
3021 extern void rtllib_wep_null(void);
3022 extern void rtllib_ccmp_null(void);
3023
3024 /* rtllib_softmac_wx.c */
3025
3026 extern int rtllib_wx_get_wap(struct rtllib_device *ieee,
3027                             struct iw_request_info *info,
3028                             union iwreq_data *wrqu, char *ext);
3029
3030 extern int rtllib_wx_set_wap(struct rtllib_device *ieee,
3031                          struct iw_request_info *info,
3032                          union iwreq_data *awrq,
3033                          char *extra);
3034
3035 extern int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
3036
3037 extern int rtllib_wx_set_rate(struct rtllib_device *ieee,
3038                              struct iw_request_info *info,
3039                              union iwreq_data *wrqu, char *extra);
3040
3041 extern int rtllib_wx_get_rate(struct rtllib_device *ieee,
3042                              struct iw_request_info *info,
3043                              union iwreq_data *wrqu, char *extra);
3044
3045 extern int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
3046                              union iwreq_data *wrqu, char *b);
3047
3048 extern int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
3049                              union iwreq_data *wrqu, char *b);
3050
3051 extern int rtllib_wx_set_essid(struct rtllib_device *ieee,
3052                               struct iw_request_info *a,
3053                               union iwreq_data *wrqu, char *extra);
3054
3055 extern int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
3056                              union iwreq_data *wrqu, char *b);
3057
3058 extern int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
3059                              union iwreq_data *wrqu, char *b);
3060
3061 extern int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
3062                              union iwreq_data *wrqu, char *b);
3063 extern void rtllib_wx_sync_scan_wq(void *data);
3064
3065 extern int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
3066                                struct iw_request_info *info,
3067                                union iwreq_data *wrqu, char *extra);
3068
3069 extern int rtllib_wx_get_name(struct rtllib_device *ieee,
3070                              struct iw_request_info *info,
3071                              union iwreq_data *wrqu, char *extra);
3072
3073 extern int rtllib_wx_set_power(struct rtllib_device *ieee,
3074                                  struct iw_request_info *info,
3075                                  union iwreq_data *wrqu, char *extra);
3076
3077 extern int rtllib_wx_get_power(struct rtllib_device *ieee,
3078                                  struct iw_request_info *info,
3079                                  union iwreq_data *wrqu, char *extra);
3080
3081 extern int rtllib_wx_set_rts(struct rtllib_device *ieee,
3082                              struct iw_request_info *info,
3083                              union iwreq_data *wrqu, char *extra);
3084
3085 extern int rtllib_wx_get_rts(struct rtllib_device *ieee,
3086                              struct iw_request_info *info,
3087                              union iwreq_data *wrqu, char *extra);
3088 #define MAX_RECEIVE_BUFFER_SIZE 9100
3089 extern void HTDebugHTCapability(u8* CapIE, u8* TitleString );
3090 extern void HTDebugHTInfo(u8*  InfoIE, u8* TitleString);
3091
3092 void HTSetConnectBwMode(struct rtllib_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
3093 extern void HTUpdateDefaultSetting(struct rtllib_device* ieee);
3094 extern void HTConstructCapabilityElement(struct rtllib_device* ieee, u8* posHTCap, u8* len, u8 isEncrypt,bool bAssoc);
3095 extern void HTConstructInfoElement(struct rtllib_device* ieee, u8* posHTInfo, u8* len, u8 isEncrypt);
3096 extern void HTConstructRT2RTAggElement(struct rtllib_device* ieee, u8* posRT2RTAgg, u8* len);
3097 extern void HTOnAssocRsp(struct rtllib_device *ieee);
3098 extern void HTInitializeHTInfo(struct rtllib_device* ieee);
3099 extern void HTInitializeBssDesc(PBSS_HT pBssHT);
3100 extern void HTResetSelfAndSavePeerSetting(struct rtllib_device* ieee, struct rtllib_network * pNetwork);
3101 extern void HTUpdateSelfAndPeerSetting(struct rtllib_device* ieee,   struct rtllib_network * pNetwork);
3102 extern u8 HTGetHighestMCSRate(struct rtllib_device* ieee, u8* pMCSRateSet, u8* pMCSFilter);
3103 extern u8 MCS_FILTER_ALL[];
3104 extern u16 MCS_DATA_RATE[2][2][77] ;
3105 extern u8 HTCCheck(struct rtllib_device* ieee, u8*   pFrame);
3106 extern void HTResetIOTSetting(PRT_HIGH_THROUGHPUT  pHTInfo);
3107 extern bool IsHTHalfNmodeAPs(struct rtllib_device* ieee);
3108 extern u16 HTHalfMcsToDataRate(struct rtllib_device* ieee,  u8      nMcsRate);
3109 extern u16 HTMcsToDataRate( struct rtllib_device* ieee, u8 nMcsRate);
3110 extern u16  TxCountToDataRate( struct rtllib_device* ieee, u8 nDataRate);
3111 extern int rtllib_rx_ADDBAReq( struct rtllib_device* ieee, struct sk_buff *skb);
3112 extern int rtllib_rx_ADDBARsp( struct rtllib_device* ieee, struct sk_buff *skb);
3113 extern int rtllib_rx_DELBA(struct rtllib_device* ieee,struct sk_buff *skb);
3114 extern void TsInitAddBA( struct rtllib_device* ieee, PTX_TS_RECORD   pTS, u8 Policy, u8 bOverwritePending);
3115 extern void TsInitDelBA( struct rtllib_device* ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect);
3116 extern void BaSetupTimeOut(unsigned long data);
3117 extern void TxBaInactTimeout(unsigned long data);
3118 extern void RxBaInactTimeout(unsigned long data);
3119 extern void ResetBaEntry( PBA_RECORD pBA);
3120 extern bool GetTs(
3121         struct rtllib_device*        ieee,
3122         PTS_COMMON_INFO                 *ppTS,
3123         u8*                             Addr,
3124         u8                              TID,
3125         TR_SELECT                       TxRxSelect,
3126         bool                            bAddNewTs
3127         );
3128 extern void TSInitialize(struct rtllib_device *ieee);
3129 extern  void TsStartAddBaProcess(struct rtllib_device* ieee, PTX_TS_RECORD   pTxTS);
3130 extern void RemovePeerTS(struct rtllib_device* ieee, u8* Addr);
3131 extern void RemoveAllTS(struct rtllib_device* ieee);
3132 void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
3133
3134 extern const long rtllib_wlan_frequencies[];
3135
3136 extern inline void rtllib_increment_scans(struct rtllib_device *ieee)
3137 {
3138         ieee->scans++;
3139 }
3140
3141 extern inline int rtllib_get_scans(struct rtllib_device *ieee)
3142 {
3143         return ieee->scans;
3144 }
3145
3146 static inline const char *escape_essid(const char *essid, u8 essid_len) {
3147         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
3148         const char *s = essid;
3149         char *d = escaped;
3150
3151         if (rtllib_is_empty_essid(essid, essid_len)) {
3152                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
3153                 return escaped;
3154         }
3155
3156         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
3157         while (essid_len--) {
3158                 if (*s == '\0') {
3159                         *d++ = '\\';
3160                         *d++ = '0';
3161                         s++;
3162                 } else {
3163                         *d++ = *s++;
3164                 }
3165         }
3166         *d = '\0';
3167         return escaped;
3168 }
3169
3170 #define CONVERT_RATE(_ieee, _MGN_RATE)  (_MGN_RATE<MGN_MCS0)?(_MGN_RATE):(HTMcsToDataRate(_ieee, (u8)_MGN_RATE))
3171
3172 /* fun with the built-in rtllib stack... */
3173 int rtllib_init(void);
3174 void rtllib_exit(void);
3175 int rtllib_crypto_init(void);
3176 void rtllib_crypto_deinit(void);
3177 int rtllib_crypto_tkip_init(void);
3178 void rtllib_crypto_tkip_exit(void);
3179 int rtllib_crypto_ccmp_init(void);
3180 void rtllib_crypto_ccmp_exit(void);
3181 int rtllib_crypto_wep_init(void);
3182 void rtllib_crypto_wep_exit(void);
3183
3184 void rtllib_MgntDisconnectIBSS(struct rtllib_device* rtllib);
3185 void rtllib_MlmeDisassociateRequest(struct rtllib_device* rtllib, u8* asSta,u8  asRsn);
3186 void rtllib_MgntDisconnectAP(struct rtllib_device* rtllib,      u8 asRsn);
3187 bool rtllib_MgntDisconnect(struct rtllib_device* rtllib,u8 asRsn);
3188
3189
3190 /* For the function is more related to hardware setting, it's better to use the
3191  * ieee handler to refer to it.
3192  */
3193 extern void rtllib_update_active_chan_map(struct rtllib_device *ieee);
3194 extern void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, PRX_TS_RECORD pTS);
3195 extern int rtllib_data_xmit(struct sk_buff *skb, struct net_device *dev);
3196 extern int rtllib_parse_info_param(struct rtllib_device *ieee,
3197                 struct rtllib_info_element *info_element,
3198                 u16 length,
3199                 struct rtllib_network *network,
3200                 struct rtllib_rx_stats *stats);
3201
3202 void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb** prxbIndicateArray,u8  index);
3203 extern u8 HTFilterMCSRate( struct rtllib_device* ieee, u8* pSupportMCS, u8* pOperateMCS);
3204 extern void HTUseDefaultSetting(struct rtllib_device* ieee);
3205 #define RT_ASOC_RETRY_LIMIT     5
3206 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
3207 extern void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p);
3208 #ifndef ENABLE_LOCK_DEBUG
3209 #define SPIN_LOCK_IEEE(plock) spin_lock_irqsave((plock), flags)
3210 #define SPIN_UNLOCK_IEEE(plock) spin_unlock_irqrestore((plock), flags)
3211 #define SPIN_LOCK_IEEE_REORDER(plock) spin_lock_irqsave((plock), flags)
3212 #define SPIN_UNLOCK_IEEE_REORDER(plock) spin_unlock_irqrestore((plock), flags)
3213 #define SPIN_LOCK_IEEE_WPAX(plock) spin_lock_irqsave((plock), flags)
3214 #define SPIN_UNLOCK_IEEE_WPAX(plock) spin_unlock_irqrestore((plock), flags)
3215 #define SPIN_LOCK_IEEE_MGNTTX(plock) spin_lock_irqsave((plock), flags)
3216 #define SPIN_UNLOCK_IEEE_MGNTTX(plock) spin_unlock_irqrestore((plock), flags)
3217 #define SPIN_LOCK_IEEE_BCN(plock) spin_lock_irqsave((plock), flags)
3218 #define SPIN_UNLOCK_IEEE_BCN(plock) spin_unlock_irqrestore((plock), flags)
3219 #define SPIN_LOCK_MSH_STAINFO(plock) spin_lock_irqsave((plock), flags)
3220 #define SPIN_UNLOCK_MSH_STAINFO(plock) spin_unlock_irqrestore((plock), flags)
3221 #define SPIN_LOCK_MSH_PREQ(plock) spin_lock_irqsave((plock), flags)
3222 #define SPIN_UNLOCK_MSH_PREQ(plock) spin_unlock_irqrestore((plock), flags)
3223 #define SPIN_LOCK_MSH_QUEUE(plock) spin_lock_irqsave((plock), flags)
3224 #define SPIN_UNLOCK_MSH_QUEUE(plock) spin_unlock_irqrestore((plock), flags)
3225 #define SPIN_LOCK_PRIV_RFPS(plock) spin_lock_irqsave((plock), flags)
3226 #define SPIN_UNLOCK_PRIV_RFPS(plock) spin_unlock_irqrestore((plock), flags)
3227 #define SPIN_LOCK_PRIV_IRQTH(plock) spin_lock_irqsave((plock), flags)
3228 #define SPIN_UNLOCK_PRIV_IRQTH(plock) spin_unlock_irqrestore((plock), flags)
3229 #define SPIN_LOCK_PRIV_TX(plock) spin_lock_irqsave((plock), flags)
3230 #define SPIN_UNLOCK_PRIV_TX(plock) spin_unlock_irqrestore((plock), flags)
3231 #define SPIN_LOCK_PRIV_D3(plock) spin_lock_irqsave((plock), flags)
3232 #define SPIN_UNLOCK_PRIV_D3(plock) spin_unlock_irqrestore((plock), flags)
3233 #define SPIN_LOCK_PRIV_RF(plock) spin_lock_irqsave((plock), flags)
3234 #define SPIN_UNLOCK_PRIV_RF(plock) spin_unlock_irqrestore((plock), flags)
3235 #define SPIN_LOCK_PRIV_PS(plock) spin_lock_irqsave((plock), flags)
3236 #define SPIN_UNLOCK_PRIV_PS(plock) spin_unlock_irqrestore((plock), flags)
3237 #define SEM_DOWN_IEEE_WX(psem) down(psem)
3238 #define SEM_UP_IEEE_WX(psem) up(psem)
3239 #define SEM_DOWN_IEEE_SCAN(psem) down(psem)
3240 #define SEM_UP_IEEE_SCAN(psem) up(psem)
3241 #define SEM_DOWN_IEEE_IPS(psem) down(psem)
3242 #define SEM_UP_IEEE_IPS(psem) up(psem)
3243 #define SEM_DOWN_PRIV_WX(psem) down(psem)
3244 #define SEM_UP_PRIV_WX(psem) up(psem)
3245 #define SEM_DOWN_PRIV_RF(psem) down(psem)
3246 #define SEM_UP_PRIV_RF(psem) up(psem)
3247 #define MUTEX_LOCK_PRIV(pmutex) mutex_lock(pmutex)
3248 #define MUTEX_UNLOCK_PRIV(pmutex) mutex_unlock(pmutex)
3249 #endif
3250 static inline void dump_buf(u8 *buf, u32 len)
3251 {
3252         u32 i;
3253         printk("-----------------Len %d----------------\n", len);
3254         for (i=0; i<len; i++)
3255                 printk("%2.2x-", *(buf+i));
3256         printk("\n");
3257 }
3258 #endif /* RTLLIB_H */