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