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