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