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