]> Git Repo - J-linux.git/blob - drivers/staging/rtl8192e/rtllib.h
Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[J-linux.git] / drivers / staging / rtl8192e / rtllib.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Merged with mainline rtllib.h in Aug 2004.  Original ieee802_11
4  * remains copyright by the original authors
5  *
6  * Portions of the merged code are based on Host AP (software wireless
7  * LAN access point) driver for Intersil Prism2/2.5/3.
8  *
9  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
10  * <[email protected]>
11  * Copyright (c) 2002-2003, Jouni Malinen <[email protected]>
12  *
13  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
14  * <[email protected]>
15  * Copyright (c) 2004, Intel Corporation
16  *
17  * Modified for Realtek's wi-fi cards by Andrea Merello
18  * <[email protected]>
19  */
20 #ifndef RTLLIB_H
21 #define RTLLIB_H
22 #include <linux/if_ether.h> /* ETH_ALEN */
23 #include <linux/kernel.h>   /* ARRAY_SIZE */
24 #include <linux/module.h>
25 #include <linux/interrupt.h>
26 #include <linux/jiffies.h>
27 #include <linux/timer.h>
28 #include <linux/sched.h>
29 #include <linux/mutex.h>
30
31 #include <linux/delay.h>
32 #include <linux/wireless.h>
33
34 #include "rtllib_debug.h"
35 #include "rtl819x_HT.h"
36 #include "rtl819x_BA.h"
37 #include "rtl819x_TS.h"
38
39 #include <linux/netdevice.h>
40 #include <linux/if_arp.h> /* ARPHRD_ETHER */
41 #include <net/lib80211.h>
42
43 #define MAX_PRECMD_CNT 16
44 #define MAX_RFDEPENDCMD_CNT 16
45 #define MAX_POSTCMD_CNT 16
46
47 #ifndef WIRELESS_SPY
48 #define WIRELESS_SPY
49 #endif
50 #include <net/iw_handler.h>
51
52 #ifndef IW_MODE_MONITOR
53 #define IW_MODE_MONITOR 6
54 #endif
55
56 #ifndef IWEVCUSTOM
57 #define IWEVCUSTOM 0x8c02
58 #endif
59
60 #ifndef IW_CUSTOM_MAX
61 /* Max number of char in custom event - use multiple of them if needed */
62 #define IW_CUSTOM_MAX   256     /* In bytes */
63 #endif
64
65 #define container_of_dwork_rsl(x, y, z)                         \
66         container_of(to_delayed_work(x), y, z)
67
68 static inline void *netdev_priv_rsl(struct net_device *dev)
69 {
70         return netdev_priv(dev);
71 }
72
73 #define KEY_TYPE_NA             0x0
74 #define KEY_TYPE_WEP40          0x1
75 #define KEY_TYPE_TKIP           0x2
76 #define KEY_TYPE_CCMP           0x4
77 #define KEY_TYPE_WEP104         0x5
78 /* added for rtl819x tx procedure */
79 #define MAX_QUEUE_SIZE          0x10
80
81 #define BK_QUEUE                               0
82 #define BE_QUEUE                               1
83 #define VI_QUEUE                               2
84 #define VO_QUEUE                               3
85 #define HCCA_QUEUE                           4
86 #define TXCMD_QUEUE                         5
87 #define MGNT_QUEUE                           6
88 #define HIGH_QUEUE                           7
89 #define BEACON_QUEUE                       8
90
91 #ifndef IW_MODE_MESH
92 #define IW_MODE_MESH                    7
93 #endif
94
95 #define IE_CISCO_FLAG_POSITION          0x08
96 #define SUPPORT_CKIP_MIC                        0x08
97 #define SUPPORT_CKIP_PK                 0x10
98 #define RT_RF_OFF_LEVL_HALT_NIC         BIT3
99 #define RT_IN_PS_LEVEL(psc, _PS_FLAG)           \
100         ((psc->CurPsLevel & _PS_FLAG) ? true : false)
101 #define RT_CLEAR_PS_LEVEL(psc, _PS_FLAG)        \
102         (psc->CurPsLevel &= (~(_PS_FLAG)))
103
104 /* defined for skb cb field */
105 /* At most 28 byte */
106 struct cb_desc {
107         /* Tx Desc Related flags (8-9) */
108         u8 bLastIniPkt:1;
109         u8 bCmdOrInit:1;
110         u8 bFirstSeg:1;
111         u8 bLastSeg:1;
112         u8 bEncrypt:1;
113         u8 tx_dis_rate_fallback:1;
114         u8 tx_use_drv_assinged_rate:1;
115         u8 bHwSec:1;
116
117         u8 nStuckCount;
118
119         /* Tx Firmware Related flags (10-11)*/
120         u8 bCTSEnable:1;
121         u8 bRTSEnable:1;
122         u8 bUseShortGI:1;
123         u8 bUseShortPreamble:1;
124         u8 bTxEnableFwCalcDur:1;
125         u8 bAMPDUEnable:1;
126         u8 bRTSSTBC:1;
127         u8 RTSSC:1;
128
129         u8 bRTSBW:1;
130         u8 bPacketBW:1;
131         u8 bRTSUseShortPreamble:1;
132         u8 bRTSUseShortGI:1;
133         u8 bMulticast:1;
134         u8 bBroadcast:1;
135         u8 drv_agg_enable:1;
136         u8 reserved2:1;
137
138         /* Tx Desc related element(12-19) */
139         u8 rata_index;
140         u8 queue_index;
141         u16 txbuf_size;
142         u8 RATRIndex;
143         u8 bAMSDU:1;
144         u8 bFromAggrQ:1;
145         u8 reserved6:6;
146         u8 macId;
147         u8 priority;
148
149         /* Tx firmware related element(20-27) */
150         u8 data_rate;
151         u8 rts_rate;
152         u8 ampdu_factor;
153         u8 ampdu_density;
154         u8 DrvAggrNum;
155         u8 bdhcp;
156         u16 pkt_size;
157         u8 bIsSpecialDataFrame;
158
159         u8 bBTTxPacket;
160         u8 bIsBTProbRsp;
161 };
162
163 enum sw_chnl_cmd_id {
164         CmdID_End,
165         CmdID_SetTxPowerLevel,
166         CmdID_BBRegWrite10,
167         CmdID_WritePortUlong,
168         CmdID_WritePortUshort,
169         CmdID_WritePortUchar,
170         CmdID_RF_WriteReg,
171 };
172
173 struct sw_chnl_cmd {
174         enum sw_chnl_cmd_id CmdID;
175         u32                     Para1;
176         u32                     Para2;
177         u32                     msDelay;
178 } __packed;
179
180 /*--------------------------Define -------------------------------------------*/
181 #define MGN_1M            0x02
182 #define MGN_2M            0x04
183 #define MGN_5_5M                0x0b
184 #define MGN_11M          0x16
185
186 #define MGN_6M            0x0c
187 #define MGN_9M            0x12
188 #define MGN_12M          0x18
189 #define MGN_18M          0x24
190 #define MGN_24M          0x30
191 #define MGN_36M          0x48
192 #define MGN_48M          0x60
193 #define MGN_54M          0x6c
194
195 #define MGN_MCS0                0x80
196 #define MGN_MCS1                0x81
197 #define MGN_MCS2                0x82
198 #define MGN_MCS3                0x83
199 #define MGN_MCS4                0x84
200 #define MGN_MCS5                0x85
201 #define MGN_MCS6                0x86
202 #define MGN_MCS7                0x87
203 #define MGN_MCS8                0x88
204 #define MGN_MCS9                0x89
205 #define MGN_MCS10              0x8a
206 #define MGN_MCS11              0x8b
207 #define MGN_MCS12              0x8c
208 #define MGN_MCS13              0x8d
209 #define MGN_MCS14              0x8e
210 #define MGN_MCS15              0x8f
211
212 enum hw_variables {
213         HW_VAR_ETHER_ADDR,
214         HW_VAR_MULTICAST_REG,
215         HW_VAR_BASIC_RATE,
216         HW_VAR_BSSID,
217         HW_VAR_MEDIA_STATUS,
218         HW_VAR_SECURITY_CONF,
219         HW_VAR_BEACON_INTERVAL,
220         HW_VAR_ATIM_WINDOW,
221         HW_VAR_LISTEN_INTERVAL,
222         HW_VAR_CS_COUNTER,
223         HW_VAR_DEFAULTKEY0,
224         HW_VAR_DEFAULTKEY1,
225         HW_VAR_DEFAULTKEY2,
226         HW_VAR_DEFAULTKEY3,
227         HW_VAR_SIFS,
228         HW_VAR_DIFS,
229         HW_VAR_EIFS,
230         HW_VAR_SLOT_TIME,
231         HW_VAR_ACK_PREAMBLE,
232         HW_VAR_CW_CONFIG,
233         HW_VAR_CW_VALUES,
234         HW_VAR_RATE_FALLBACK_CONTROL,
235         HW_VAR_CONTENTION_WINDOW,
236         HW_VAR_RETRY_COUNT,
237         HW_VAR_TR_SWITCH,
238         HW_VAR_COMMAND,
239         HW_VAR_WPA_CONFIG,
240         HW_VAR_AMPDU_MIN_SPACE,
241         HW_VAR_SHORTGI_DENSITY,
242         HW_VAR_AMPDU_FACTOR,
243         HW_VAR_MCS_RATE_AVAILABLE,
244         HW_VAR_AC_PARAM,
245         HW_VAR_ACM_CTRL,
246         HW_VAR_DIS_Req_Qsize,
247         HW_VAR_CCX_CHNL_LOAD,
248         HW_VAR_CCX_NOISE_HISTOGRAM,
249         HW_VAR_CCX_CLM_NHM,
250         HW_VAR_TxOPLimit,
251         HW_VAR_TURBO_MODE,
252         HW_VAR_RF_STATE,
253         HW_VAR_RF_OFF_BY_HW,
254         HW_VAR_BUS_SPEED,
255         HW_VAR_SET_DEV_POWER,
256
257         HW_VAR_RCR,
258         HW_VAR_RATR_0,
259         HW_VAR_RRSR,
260         HW_VAR_CPU_RST,
261         HW_VAR_CECHK_BSSID,
262         HW_VAR_LBK_MODE,
263         HW_VAR_AES_11N_FIX,
264         HW_VAR_USB_RX_AGGR,
265         HW_VAR_USER_CONTROL_TURBO_MODE,
266         HW_VAR_RETRY_LIMIT,
267         HW_VAR_INIT_TX_RATE,
268         HW_VAR_TX_RATE_REG,
269         HW_VAR_EFUSE_USAGE,
270         HW_VAR_EFUSE_BYTES,
271         HW_VAR_AUTOLOAD_STATUS,
272         HW_VAR_RF_2R_DISABLE,
273         HW_VAR_SET_RPWM,
274         HW_VAR_H2C_FW_PWRMODE,
275         HW_VAR_H2C_FW_JOINBSSRPT,
276         HW_VAR_1X1_RECV_COMBINE,
277         HW_VAR_STOP_SEND_BEACON,
278         HW_VAR_TSF_TIMER,
279         HW_VAR_IO_CMD,
280
281         HW_VAR_RF_RECOVERY,
282         HW_VAR_H2C_FW_UPDATE_GTK,
283         HW_VAR_WF_MASK,
284         HW_VAR_WF_CRC,
285         HW_VAR_WF_IS_MAC_ADDR,
286         HW_VAR_H2C_FW_OFFLOAD,
287         HW_VAR_RESET_WFCRC,
288
289         HW_VAR_HANDLE_FW_C2H,
290         HW_VAR_DL_FW_RSVD_PAGE,
291         HW_VAR_AID,
292         HW_VAR_HW_SEQ_ENABLE,
293         HW_VAR_CORRECT_TSF,
294         HW_VAR_BCN_VALID,
295         HW_VAR_FWLPS_RF_ON,
296         HW_VAR_DUAL_TSF_RST,
297         HW_VAR_SWITCH_EPHY_WoWLAN,
298         HW_VAR_INT_MIGRATION,
299         HW_VAR_INT_AC,
300         HW_VAR_RF_TIMING,
301 };
302
303 enum rt_op_mode {
304         RT_OP_MODE_AP,
305         RT_OP_MODE_INFRASTRUCTURE,
306         RT_OP_MODE_IBSS,
307         RT_OP_MODE_NO_LINK,
308 };
309
310 #define aSifsTime                                               \
311          (((priv->rtllib->current_network.mode == IEEE_A)       \
312         || (priv->rtllib->current_network.mode == IEEE_N_24G)   \
313         || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10)
314
315 #define MGMT_QUEUE_NUM 5
316
317 #define MAX_IE_LEN  0xff
318
319 #define msleep_interruptible_rsl  msleep_interruptible
320
321 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
322  * 6.2.1.1.2.
323  *
324  * The figure in section 7.1.2 suggests a body size of up to 2312
325  * bytes is allowed, which is a bit confusing, I suspect this
326  * represents the 2304 bytes of real data, plus a possible 8 bytes of
327  * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
328  */
329 #define RTLLIB_1ADDR_LEN 10
330 #define RTLLIB_2ADDR_LEN 16
331 #define RTLLIB_3ADDR_LEN 24
332 #define RTLLIB_4ADDR_LEN 30
333 #define RTLLIB_FCS_LEN    4
334
335 #define RTLLIB_SKBBUFFER_SIZE 2500
336
337 #define MIN_FRAG_THRESHOLD     256U
338 #define MAX_FRAG_THRESHOLD     2346U
339
340 /* Frame control field constants */
341 #define RTLLIB_FCTL_FTYPE               0x000c
342 #define RTLLIB_FCTL_STYPE               0x00f0
343 #define RTLLIB_FCTL_FRAMETYPE   0x00fc
344 #define RTLLIB_FCTL_TODS                0x0100
345 #define RTLLIB_FCTL_FROMDS              0x0200
346 #define RTLLIB_FCTL_DSTODS              0x0300
347 #define RTLLIB_FCTL_MOREFRAGS   0x0400
348 #define RTLLIB_FCTL_RETRY               0x0800
349 #define RTLLIB_FCTL_PM          0x1000
350 #define RTLLIB_FCTL_MOREDATA            0x2000
351 #define RTLLIB_FCTL_WEP         0x4000
352 #define RTLLIB_FCTL_ORDER               0x8000
353
354 #define RTLLIB_FTYPE_MGMT               0x0000
355 #define RTLLIB_FTYPE_CTL                0x0004
356 #define RTLLIB_FTYPE_DATA               0x0008
357
358 /* management */
359 #define RTLLIB_STYPE_ASSOC_REQ  0x0000
360 #define RTLLIB_STYPE_ASSOC_RESP         0x0010
361 #define RTLLIB_STYPE_REASSOC_REQ        0x0020
362 #define RTLLIB_STYPE_REASSOC_RESP       0x0030
363 #define RTLLIB_STYPE_PROBE_REQ  0x0040
364 #define RTLLIB_STYPE_PROBE_RESP 0x0050
365 #define RTLLIB_STYPE_BEACON             0x0080
366 #define RTLLIB_STYPE_ATIM               0x0090
367 #define RTLLIB_STYPE_DISASSOC   0x00A0
368 #define RTLLIB_STYPE_AUTH               0x00B0
369 #define RTLLIB_STYPE_DEAUTH             0x00C0
370 #define RTLLIB_STYPE_MANAGE_ACT 0x00D0
371
372 /* control */
373 #define RTLLIB_STYPE_PSPOLL             0x00A0
374 #define RTLLIB_STYPE_RTS                0x00B0
375 #define RTLLIB_STYPE_CTS                0x00C0
376 #define RTLLIB_STYPE_ACK                0x00D0
377
378 /* data */
379 #define RTLLIB_STYPE_DATA               0x0000
380 #define RTLLIB_STYPE_DATA_CFACK 0x0010
381 #define RTLLIB_STYPE_DATA_CFPOLL        0x0020
382 #define RTLLIB_STYPE_DATA_CFACKPOLL     0x0030
383 #define RTLLIB_STYPE_NULLFUNC   0x0040
384 #define RTLLIB_STYPE_QOS_DATA   0x0080
385 #define RTLLIB_STYPE_QOS_NULL   0x00C0
386
387 #define RTLLIB_SCTL_FRAG                0x000F
388 #define RTLLIB_SCTL_SEQ         0xFFF0
389
390 /* QOS control */
391 #define RTLLIB_QCTL_TID       0x000F
392
393 #define FC_QOS_BIT                                      BIT7
394 #define IsDataFrame(pdu)        (((pdu[0] & 0x0C) == 0x08) ? true : false)
395 #define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
396 #define IsQoSDataFrame(pframe)                  \
397         ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==  \
398         (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
399 #define Frame_Order(pframe)     (*(u16 *)pframe&RTLLIB_FCTL_ORDER)
400 #define SN_LESS(a, b)           (((a-b)&0x800) != 0)
401 #define SN_EQUAL(a, b)  (a == b)
402 #define MAX_DEV_ADDR_SIZE 8
403
404 enum act_category {
405         ACT_CAT_QOS = 1,
406         ACT_CAT_DLS = 2,
407         ACT_CAT_BA  = 3,
408         ACT_CAT_HT  = 7,
409         ACT_CAT_WMM = 17,
410 };
411
412 enum ba_action {
413         ACT_ADDBAREQ = 0,
414         ACT_ADDBARSP = 1,
415         ACT_DELBA    = 2,
416 };
417
418 enum init_gain_op_type {
419         IG_Backup = 0,
420         IG_Restore,
421         IG_Max
422 };
423
424 enum led_ctl_mode {
425         LED_CTL_POWER_ON = 1,
426         LED_CTL_LINK = 2,
427         LED_CTL_NO_LINK = 3,
428         LED_CTL_TX = 4,
429         LED_CTL_RX = 5,
430         LED_CTL_SITE_SURVEY = 6,
431         LED_CTL_POWER_OFF = 7,
432         LED_CTL_START_TO_LINK = 8,
433 };
434
435 enum wireless_mode {
436         WIRELESS_MODE_UNKNOWN = 0x00,
437         WIRELESS_MODE_A = 0x01,
438         WIRELESS_MODE_B = 0x02,
439         WIRELESS_MODE_G = 0x04,
440         WIRELESS_MODE_AUTO = 0x08,
441         WIRELESS_MODE_N_24G = 0x10,
442         WIRELESS_MODE_N_5G = 0x20
443 };
444
445 #ifndef ETH_P_PAE
446 #define ETH_P_PAE       0x888E          /* Port Access Entity (IEEE 802.1X) */
447 #define ETH_P_IP        0x0800          /* Internet Protocol packet     */
448 #define ETH_P_ARP       0x0806          /* Address Resolution packet    */
449 #endif /* ETH_P_PAE */
450
451 #ifndef ETH_P_80211_RAW
452 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
453 #endif
454
455 /* IEEE 802.11 defines */
456
457 #define P80211_OUI_LEN 3
458
459 struct rtllib_snap_hdr {
460         u8    dsap;   /* always 0xAA */
461         u8    ssap;   /* always 0xAA */
462         u8    ctrl;   /* always 0x03 */
463         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
464
465 } __packed;
466
467 enum _REG_PREAMBLE_MODE {
468         PREAMBLE_LONG = 1,
469         PREAMBLE_AUTO = 2,
470         PREAMBLE_SHORT = 3,
471 };
472
473 #define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
474
475 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
476 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
477 #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
478
479 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
480 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
481 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & RTLLIB_SCTL_SEQ) >> 4)
482
483 /* Authentication algorithms */
484 #define WLAN_AUTH_OPEN 0
485 #define WLAN_AUTH_SHARED_KEY 1
486 #define WLAN_AUTH_LEAP 128
487
488 #define WLAN_CAPABILITY_ESS (1<<0)
489 #define WLAN_CAPABILITY_IBSS (1<<1)
490 #define WLAN_CAPABILITY_PRIVACY (1<<4)
491 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
492 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
493
494 #define RTLLIB_STATMASK_SIGNAL (1<<0)
495 #define RTLLIB_STATMASK_RSSI (1<<1)
496 #define RTLLIB_STATMASK_NOISE (1<<2)
497 #define RTLLIB_STATMASK_WEMASK 0x7
498
499 #define RTLLIB_CCK_MODULATION    (1<<0)
500 #define RTLLIB_OFDM_MODULATION   (1<<1)
501
502 #define RTLLIB_24GHZ_BAND     (1<<0)
503 #define RTLLIB_52GHZ_BAND     (1<<1)
504
505 #define RTLLIB_CCK_RATE_LEN             4
506 #define RTLLIB_CCK_RATE_1MB                     0x02
507 #define RTLLIB_CCK_RATE_2MB                     0x04
508 #define RTLLIB_CCK_RATE_5MB                     0x0B
509 #define RTLLIB_CCK_RATE_11MB                    0x16
510 #define RTLLIB_OFDM_RATE_LEN            8
511 #define RTLLIB_OFDM_RATE_6MB                    0x0C
512 #define RTLLIB_OFDM_RATE_9MB                    0x12
513 #define RTLLIB_OFDM_RATE_12MB           0x18
514 #define RTLLIB_OFDM_RATE_18MB           0x24
515 #define RTLLIB_OFDM_RATE_24MB           0x30
516 #define RTLLIB_OFDM_RATE_36MB           0x48
517 #define RTLLIB_OFDM_RATE_48MB           0x60
518 #define RTLLIB_OFDM_RATE_54MB           0x6C
519 #define RTLLIB_BASIC_RATE_MASK          0x80
520
521 /* this is stolen and modified from the madwifi driver*/
522 #define RTLLIB_FC0_TYPE_MASK            0x0c
523 #define RTLLIB_FC0_TYPE_DATA            0x08
524 #define RTLLIB_FC0_SUBTYPE_MASK 0xB0
525 #define RTLLIB_FC0_SUBTYPE_QOS  0x80
526
527 #define RTLLIB_QOS_HAS_SEQ(fc) \
528         (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
529          (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
530
531 /* this is stolen from ipw2200 driver */
532 #define IEEE_IBSS_MAC_HASH_SIZE 31
533 struct ieee_ibss_seq {
534         u8 mac[ETH_ALEN];
535         u16 seq_num[17];
536         u16 frag_num[17];
537         unsigned long packet_time[17];
538         struct list_head list;
539 };
540
541 /* NOTE: This data is for statistical purposes; not all hardware provides this
542  *       information for frames received.  Not setting these will not cause
543  *       any adverse affects.
544  */
545 struct rtllib_rx_stats {
546         u64 mac_time;
547         s8  rssi;
548         u8  signal;
549         u8  noise;
550         u16 rate; /* in 100 kbps */
551         u8  received_channel;
552         u8  control;
553         u8  mask;
554         u8  freq;
555         u16 len;
556         u64 tsf;
557         u32 beacon_time;
558         u8  nic_type;
559         u16 Length;
560         u8  SignalQuality;
561         s32 RecvSignalPower;
562         s8  RxPower;
563         u8  SignalStrength;
564         u16 bHwError:1;
565         u16 bCRC:1;
566         u16 bICV:1;
567         u16 bShortPreamble:1;
568         u16 Antenna:1;
569         u16 Decrypted:1;
570         u16 Wakeup:1;
571         u16 Reserved0:1;
572         u8  AGC;
573         u32 TimeStampLow;
574         u32 TimeStampHigh;
575         bool bShift;
576         bool bIsQosData;
577
578         u8    RxDrvInfoSize;
579         u8    RxBufShift;
580         bool  bIsAMPDU;
581         bool  bFirstMPDU;
582         bool  bContainHTC;
583         bool  RxIs40MHzPacket;
584         u32   RxPWDBAll;
585         u8    RxMIMOSignalStrength[4];
586         s8    RxMIMOSignalQuality[2];
587         bool  bPacketMatchBSSID;
588         bool  bIsCCK;
589         bool  bPacketToSelf;
590         u16    packetlength;
591         u16    fraglength;
592         u16    fragoffset;
593         u16    ntotalfrag;
594         bool   bPacketBeacon;
595         bool   bToSelfBA;
596         u16    Seq_Num;
597 };
598
599 /* IEEE 802.11 requires that STA supports concurrent reception of at least
600  * three fragmented frames. This define can be increased to support more
601  * concurrent frames, but it should be noted that each entry can consume about
602  * 2 kB of RAM and increasing cache size will slow down frame reassembly.
603  */
604 #define RTLLIB_FRAG_CACHE_LEN 4
605
606 struct rtllib_frag_entry {
607         unsigned long first_frag_time;
608         unsigned int seq;
609         unsigned int last_frag;
610         struct sk_buff *skb;
611         u8 src_addr[ETH_ALEN];
612         u8 dst_addr[ETH_ALEN];
613 };
614
615 struct rtllib_device;
616
617 #define SEC_ACTIVE_KEY    (1<<4)
618 #define SEC_AUTH_MODE     (1<<5)
619 #define SEC_UNICAST_GROUP (1<<6)
620 #define SEC_LEVEL        (1<<7)
621 #define SEC_ENABLED       (1<<8)
622
623 #define SEC_LEVEL_0      0 /* None */
624 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
625 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
626 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
627 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
628
629 #define SEC_ALG_NONE            0
630 #define SEC_ALG_WEP             1
631 #define SEC_ALG_TKIP            2
632 #define SEC_ALG_CCMP            4
633
634 #define WEP_KEY_LEN             13
635 #define SCM_KEY_LEN             32
636
637 struct rtllib_security {
638         u16 active_key:2,
639             enabled:1,
640             auth_mode:2,
641             auth_algo:4,
642             unicast_uses_group:1,
643             encrypt:1;
644         u8 key_sizes[NUM_WEP_KEYS];
645         u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN];
646         u8 level;
647         u16 flags;
648 } __packed;
649
650 /* 802.11 data frame from AP
651  *       ,-------------------------------------------------------------------.
652  * Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
653  *       |------|------|---------|---------|---------|------|---------|------|
654  * Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
655  *       |      | tion | (BSSID) |         |         | ence |  data   |      |
656  *       `-------------------------------------------------------------------'
657  * Total: 28-2340 bytes
658  */
659
660 /* Management Frame Information Element Types */
661 enum rtllib_mfie {
662         MFIE_TYPE_SSID = 0,
663         MFIE_TYPE_RATES = 1,
664         MFIE_TYPE_FH_SET = 2,
665         MFIE_TYPE_DS_SET = 3,
666         MFIE_TYPE_CF_SET = 4,
667         MFIE_TYPE_TIM = 5,
668         MFIE_TYPE_IBSS_SET = 6,
669         MFIE_TYPE_COUNTRY = 7,
670         MFIE_TYPE_HOP_PARAMS = 8,
671         MFIE_TYPE_HOP_TABLE = 9,
672         MFIE_TYPE_REQUEST = 10,
673         MFIE_TYPE_CHALLENGE = 16,
674         MFIE_TYPE_POWER_CONSTRAINT = 32,
675         MFIE_TYPE_POWER_CAPABILITY = 33,
676         MFIE_TYPE_TPC_REQUEST = 34,
677         MFIE_TYPE_TPC_REPORT = 35,
678         MFIE_TYPE_SUPP_CHANNELS = 36,
679         MFIE_TYPE_CSA = 37,
680         MFIE_TYPE_MEASURE_REQUEST = 38,
681         MFIE_TYPE_MEASURE_REPORT = 39,
682         MFIE_TYPE_QUIET = 40,
683         MFIE_TYPE_IBSS_DFS = 41,
684         MFIE_TYPE_ERP = 42,
685         MFIE_TYPE_HT_CAP = 45,
686         MFIE_TYPE_RSN = 48,
687         MFIE_TYPE_RATES_EX = 50,
688         MFIE_TYPE_HT_INFO = 61,
689         MFIE_TYPE_AIRONET = 133,
690         MFIE_TYPE_GENERIC = 221,
691         MFIE_TYPE_QOS_PARAMETER = 222,
692 };
693
694 /* Minimal header; can be used for passing 802.11 frames with sufficient
695  * information to determine what type of underlying data type is actually
696  * stored in the data.
697  */
698 struct rtllib_pspoll_hdr {
699         __le16 frame_ctl;
700         __le16 aid;
701         u8 bssid[ETH_ALEN];
702         u8 ta[ETH_ALEN];
703 } __packed;
704
705 struct rtllib_hdr {
706         __le16 frame_ctl;
707         __le16 duration_id;
708         u8 payload[];
709 } __packed;
710
711 struct rtllib_hdr_1addr {
712         __le16 frame_ctl;
713         __le16 duration_id;
714         u8 addr1[ETH_ALEN];
715         u8 payload[];
716 } __packed;
717
718 struct rtllib_hdr_2addr {
719         __le16 frame_ctl;
720         __le16 duration_id;
721         u8 addr1[ETH_ALEN];
722         u8 addr2[ETH_ALEN];
723         u8 payload[];
724 } __packed;
725
726 struct rtllib_hdr_3addr {
727         __le16 frame_ctl;
728         __le16 duration_id;
729         u8 addr1[ETH_ALEN];
730         u8 addr2[ETH_ALEN];
731         u8 addr3[ETH_ALEN];
732         __le16 seq_ctl;
733         u8 payload[];
734 } __packed;
735
736 struct rtllib_hdr_4addr {
737         __le16 frame_ctl;
738         __le16 duration_id;
739         u8 addr1[ETH_ALEN];
740         u8 addr2[ETH_ALEN];
741         u8 addr3[ETH_ALEN];
742         __le16 seq_ctl;
743         u8 addr4[ETH_ALEN];
744         u8 payload[];
745 } __packed;
746
747 struct rtllib_hdr_3addrqos {
748         __le16 frame_ctl;
749         __le16 duration_id;
750         u8 addr1[ETH_ALEN];
751         u8 addr2[ETH_ALEN];
752         u8 addr3[ETH_ALEN];
753         __le16 seq_ctl;
754         __le16 qos_ctl;
755         u8 payload[];
756 } __packed;
757
758 struct rtllib_hdr_4addrqos {
759         __le16 frame_ctl;
760         __le16 duration_id;
761         u8 addr1[ETH_ALEN];
762         u8 addr2[ETH_ALEN];
763         u8 addr3[ETH_ALEN];
764         __le16 seq_ctl;
765         u8 addr4[ETH_ALEN];
766         __le16 qos_ctl;
767         u8 payload[];
768 } __packed;
769
770 struct rtllib_info_element {
771         u8 id;
772         u8 len;
773         u8 data[];
774 } __packed;
775
776 struct rtllib_authentication {
777         struct rtllib_hdr_3addr header;
778         __le16 algorithm;
779         __le16 transaction;
780         __le16 status;
781         /*challenge*/
782         struct rtllib_info_element info_element[];
783 } __packed;
784
785 struct rtllib_disauth {
786         struct rtllib_hdr_3addr header;
787         __le16 reason;
788 } __packed;
789
790 struct rtllib_disassoc {
791         struct rtllib_hdr_3addr header;
792         __le16 reason;
793 } __packed;
794
795 struct rtllib_probe_request {
796         struct rtllib_hdr_3addr header;
797         /* SSID, supported rates */
798         struct rtllib_info_element info_element[];
799 } __packed;
800
801 struct rtllib_probe_response {
802         struct rtllib_hdr_3addr header;
803         u32 time_stamp[2];
804         __le16 beacon_interval;
805         __le16 capability;
806         /* SSID, supported rates, FH params, DS params,
807          * CF params, IBSS params, TIM (if beacon), RSN
808          */
809         struct rtllib_info_element info_element[];
810 } __packed;
811
812 /* Alias beacon for probe_response */
813 #define rtllib_beacon rtllib_probe_response
814
815 struct rtllib_assoc_request_frame {
816         struct rtllib_hdr_3addr header;
817         __le16 capability;
818         __le16 listen_interval;
819         /* SSID, supported rates, RSN */
820         struct rtllib_info_element info_element[];
821 } __packed;
822
823 struct rtllib_assoc_response_frame {
824         struct rtllib_hdr_3addr header;
825         __le16 capability;
826         __le16 status;
827         __le16 aid;
828         struct rtllib_info_element info_element[]; /* supported rates */
829 } __packed;
830
831 struct rtllib_txb {
832         u8 nr_frags;
833         u8 encrypted;
834         u8 queue_index;
835         u8 rts_included;
836         u16 reserved;
837         __le16 frag_size;
838         __le16 payload_size;
839         struct sk_buff *fragments[];
840 };
841
842 #define MAX_SUBFRAME_COUNT                64
843 struct rtllib_rxb {
844         u8 nr_subframes;
845         struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
846         u8 dst[ETH_ALEN];
847         u8 src[ETH_ALEN];
848 } __packed;
849
850 union frameqos {
851         u16 shortdata;
852         u8  chardata[2];
853         struct {
854                 u16 tid:4;
855                 u16 eosp:1;
856                 u16 ack_policy:2;
857                 u16 reserved:1;
858                 u16 txop:8;
859         } field;
860 };
861
862 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
863  * only use 8, and then use extended rates for the remaining supported
864  * rates.  Other APs, however, stick all of their supported rates on the
865  * main rates information element...
866  */
867 #define MAX_RATES_LENGTH                  ((u8)12)
868 #define MAX_RATES_EX_LENGTH            ((u8)16)
869 #define MAX_NETWORK_COUNT                 96
870
871 #define MAX_CHANNEL_NUMBER               161
872 #define RTLLIB_SOFTMAC_SCAN_TIME           100
873 #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
874
875 #define MAX_WPA_IE_LEN 64
876 #define MAX_WZC_IE_LEN 256
877
878 #define NETWORK_EMPTY_ESSID (1<<0)
879 #define NETWORK_HAS_OFDM    (1<<1)
880 #define NETWORK_HAS_CCK     (1<<2)
881
882 /* QoS structure */
883 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
884 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
885 #define NETWORK_HAS_QOS_MASK        (NETWORK_HAS_QOS_PARAMETERS | \
886                                          NETWORK_HAS_QOS_INFORMATION)
887 /* 802.11h */
888 #define NETWORK_HAS_ERP_VALUE      (1<<10)
889
890 #define QOS_QUEUE_NUM              4
891 #define QOS_OUI_LEN                  3
892 #define QOS_OUI_TYPE                2
893 #define QOS_ELEMENT_ID            221
894 #define QOS_OUI_INFO_SUB_TYPE      0
895 #define QOS_OUI_PARAM_SUB_TYPE    1
896 #define QOS_VERSION_1              1
897
898 struct rtllib_qos_information_element {
899         u8 elementID;
900         u8 length;
901         u8 qui[QOS_OUI_LEN];
902         u8 qui_type;
903         u8 qui_subtype;
904         u8 version;
905         u8 ac_info;
906 } __packed;
907
908 struct rtllib_qos_ac_parameter {
909         u8 aci_aifsn;
910         u8 ecw_min_max;
911         __le16 tx_op_limit;
912 } __packed;
913
914 struct rtllib_qos_parameter_info {
915         struct rtllib_qos_information_element info_element;
916         u8 reserved;
917         struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
918 } __packed;
919
920 struct rtllib_qos_parameters {
921         __le16 cw_min[QOS_QUEUE_NUM];
922         __le16 cw_max[QOS_QUEUE_NUM];
923         u8 aifs[QOS_QUEUE_NUM];
924         u8 flag[QOS_QUEUE_NUM];
925         __le16 tx_op_limit[QOS_QUEUE_NUM];
926 } __packed;
927
928 struct rtllib_qos_data {
929         struct rtllib_qos_parameters parameters;
930         unsigned int wmm_acm;
931         int active;
932         int supported;
933         u8 param_count;
934         u8 old_param_count;
935 };
936
937 struct rtllib_tim_parameters {
938         u8 tim_count;
939         u8 tim_period;
940 } __packed;
941
942 struct rtllib_wmm_ac_param {
943         u8 ac_aci_acm_aifsn;
944         u8 ac_ecwmin_ecwmax;
945         u16 ac_txop_limit;
946 };
947
948 enum eap_type {
949         EAP_PACKET = 0,
950         EAPOL_START,
951         EAPOL_LOGOFF,
952         EAPOL_KEY,
953         EAPOL_ENCAP_ASF_ALERT
954 };
955
956 static const char * const eap_types[] = {
957         [EAP_PACKET]            = "EAP-Packet",
958         [EAPOL_START]           = "EAPOL-Start",
959         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
960         [EAPOL_KEY]             = "EAPOL-Key",
961         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
962 };
963
964 static inline const char *eap_get_type(int type)
965 {
966         return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" :
967                  eap_types[type];
968 }
969
970 static inline u8 Frame_QoSTID(u8 *buf)
971 {
972         struct rtllib_hdr_3addr *hdr;
973         u16 fc;
974
975         hdr = (struct rtllib_hdr_3addr *)buf;
976         fc = le16_to_cpu(hdr->frame_ctl);
977         return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) &&
978                     (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
979 }
980
981 struct eapol {
982         u8 snap[6];
983         u16 ethertype;
984         u8 version;
985         u8 type;
986         u16 length;
987 } __packed;
988
989 struct rtllib_softmac_stats {
990         unsigned int rx_ass_ok;
991         unsigned int rx_ass_err;
992         unsigned int rx_probe_rq;
993         unsigned int tx_probe_rs;
994         unsigned int tx_beacons;
995         unsigned int rx_auth_rq;
996         unsigned int rx_auth_rs_ok;
997         unsigned int rx_auth_rs_err;
998         unsigned int tx_auth_rq;
999         unsigned int no_auth_rs;
1000         unsigned int no_ass_rs;
1001         unsigned int tx_ass_rq;
1002         unsigned int rx_ass_rq;
1003         unsigned int tx_probe_rq;
1004         unsigned int reassoc;
1005         unsigned int swtxstop;
1006         unsigned int swtxawake;
1007         unsigned char CurrentShowTxate;
1008         unsigned char last_packet_rate;
1009         unsigned int txretrycount;
1010 };
1011
1012 /* These are the data types that can make up management packets
1013  *
1014  * u16 auth_algorithm;
1015  * u16 auth_sequence;
1016  * u16 beacon_interval;
1017  * u16 capability;
1018  * u8 current_ap[ETH_ALEN];
1019  * u16 listen_interval;
1020  * struct {
1021  *   u16 association_id:14, reserved:2;
1022  * } __packed;
1023  * u32 time_stamp[2];
1024  * u16 reason;
1025  * u16 status;
1026  */
1027
1028 #define RTLLIB_DEFAULT_TX_ESSID "Penguin"
1029 #define RTLLIB_DEFAULT_BASIC_RATE 2
1030
1031 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1032 #define MAX_SP_Len  (WMM_all_frame << 4)
1033 #define RTLLIB_QOS_TID 0x0f
1034 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1035
1036 #define RTLLIB_DTIM_MBCAST 4
1037 #define RTLLIB_DTIM_UCAST 2
1038 #define RTLLIB_DTIM_VALID 1
1039 #define RTLLIB_DTIM_INVALID 0
1040
1041 #define RTLLIB_PS_DISABLED 0
1042 #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
1043 #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
1044
1045 #define WME_AC_BK   0x00
1046 #define WME_AC_BE   0x01
1047 #define WME_AC_VI   0x02
1048 #define WME_AC_VO   0x03
1049 #define WME_AC_PRAM_LEN 16
1050
1051 #define MAX_RECEIVE_BUFFER_SIZE 9100
1052
1053 #define UP2AC(up) (                \
1054         ((up) < 1) ? WME_AC_BE : \
1055         ((up) < 3) ? WME_AC_BK : \
1056         ((up) < 4) ? WME_AC_BE : \
1057         ((up) < 6) ? WME_AC_VI : \
1058         WME_AC_VO)
1059
1060 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
1061 #define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address
1062                                          * plus ether type
1063                                          */
1064
1065 enum erp_t {
1066         ERP_NonERPpresent       = 0x01,
1067         ERP_UseProtection       = 0x02,
1068         ERP_BarkerPreambleMode = 0x04,
1069 };
1070
1071 struct rtllib_network {
1072         /* These entries are used to identify a unique network */
1073         u8 bssid[ETH_ALEN];
1074         u8 channel;
1075         /* Ensure null-terminated for any debug msgs */
1076         u8 ssid[IW_ESSID_MAX_SIZE + 1];
1077         u8 ssid_len;
1078         u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
1079         u8 hidden_ssid_len;
1080         struct rtllib_qos_data qos_data;
1081
1082         bool    bWithAironetIE;
1083         bool    bCkipSupported;
1084         bool    bCcxRmEnable;
1085         u8      CcxRmState[2];
1086         bool    bMBssidValid;
1087         u8      MBssidMask;
1088         u8      MBssid[ETH_ALEN];
1089         bool    bWithCcxVerNum;
1090         u8      BssCcxVerNumber;
1091         /* These are network statistics */
1092         struct rtllib_rx_stats stats;
1093         u16 capability;
1094         u8  rates[MAX_RATES_LENGTH];
1095         u8  rates_len;
1096         u8  rates_ex[MAX_RATES_EX_LENGTH];
1097         u8  rates_ex_len;
1098         unsigned long last_scanned;
1099         u8  mode;
1100         u32 flags;
1101         u32 time_stamp[2];
1102         u16 beacon_interval;
1103         u16 listen_interval;
1104         u16 atim_window;
1105         u8  erp_value;
1106         u8  wpa_ie[MAX_WPA_IE_LEN];
1107         size_t wpa_ie_len;
1108         u8  rsn_ie[MAX_WPA_IE_LEN];
1109         size_t rsn_ie_len;
1110         u8  wzc_ie[MAX_WZC_IE_LEN];
1111         size_t wzc_ie_len;
1112
1113         struct rtllib_tim_parameters tim;
1114         u8  dtim_period;
1115         u8  dtim_data;
1116         u64 last_dtim_sta_time;
1117
1118         u8 wmm_info;
1119         struct rtllib_wmm_ac_param wmm_param[4];
1120         u8 Turbo_Enable;
1121         u16 CountryIeLen;
1122         u8 CountryIeBuf[MAX_IE_LEN];
1123         struct bss_ht bssht;
1124         bool broadcom_cap_exist;
1125         bool realtek_cap_exit;
1126         bool marvell_cap_exist;
1127         bool ralink_cap_exist;
1128         bool atheros_cap_exist;
1129         bool cisco_cap_exist;
1130         bool airgo_cap_exist;
1131         bool unknown_cap_exist;
1132         bool    berp_info_valid;
1133         bool buseprotection;
1134         u8 SignalStrength;
1135         u8 RSSI;
1136         struct list_head list;
1137 };
1138
1139 enum rtllib_state {
1140
1141         /* the card is not linked at all */
1142         RTLLIB_NOLINK = 0,
1143
1144         /* RTLLIB_ASSOCIATING* are for BSS client mode
1145          * the driver shall not perform RX filtering unless
1146          * the state is LINKED.
1147          * The driver shall just check for the state LINKED and
1148          * defaults to NOLINK for ALL the other states (including
1149          * LINKED_SCANNING)
1150          */
1151
1152         /* the association procedure will start (wq scheduling)*/
1153         RTLLIB_ASSOCIATING,
1154         RTLLIB_ASSOCIATING_RETRY,
1155
1156         /* the association procedure is sending AUTH request*/
1157         RTLLIB_ASSOCIATING_AUTHENTICATING,
1158
1159         /* the association procedure has successfully authenticated
1160          * and is sending association request
1161          */
1162         RTLLIB_ASSOCIATING_AUTHENTICATED,
1163
1164         /* the link is ok. the card associated to a BSS or linked
1165          * to a ibss cell or acting as an AP and creating the bss
1166          */
1167         RTLLIB_LINKED,
1168
1169         /* same as LINKED, but the driver shall apply RX filter
1170          * rules as we are in NO_LINK mode. As the card is still
1171          * logically linked, but it is doing a syncro site survey
1172          * then it will be back to LINKED state.
1173          */
1174         RTLLIB_LINKED_SCANNING,
1175 };
1176
1177 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1178 #define DEFAULT_FTS 2346
1179
1180 #define CFG_RTLLIB_RESERVE_FCS (1<<0)
1181 #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1182
1183 struct tx_pending {
1184         int frag;
1185         struct rtllib_txb *txb;
1186 };
1187
1188 struct bandwidth_autoswitch {
1189         long threshold_20Mhzto40Mhz;
1190         long    threshold_40Mhzto20Mhz;
1191         bool bforced_tx20Mhz;
1192         bool bautoswitch_enable;
1193 };
1194
1195 #define REORDER_WIN_SIZE        128
1196 #define REORDER_ENTRY_NUM       128
1197 struct rx_reorder_entry {
1198         struct list_head        List;
1199         u16                     SeqNum;
1200         struct rtllib_rxb *prxb;
1201 };
1202
1203 enum fsync_state {
1204         Default_Fsync,
1205         HW_Fsync,
1206         SW_Fsync
1207 };
1208
1209 enum rt_ps_mode {
1210         eActive,
1211         eMaxPs,
1212         eFastPs,
1213         eAutoPs,
1214 };
1215
1216 enum ips_callback_function {
1217         IPS_CALLBACK_NONE = 0,
1218         IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1219         IPS_CALLBACK_JOIN_REQUEST = 2,
1220 };
1221
1222 enum rt_rf_power_state {
1223         rf_on,
1224         rf_sleep,
1225         rf_off
1226 };
1227
1228 struct rt_pwr_save_ctrl {
1229         bool                            bSwRfProcessing;
1230         enum rt_rf_power_state eInactivePowerState;
1231         enum ips_callback_function ReturnPoint;
1232
1233         bool                            bLeisurePs;
1234         u8                              LpsIdleCount;
1235         u8                              reg_max_lps_awake_intvl;
1236         u8                              LPSAwakeIntvl;
1237
1238         u32                             CurPsLevel;
1239 };
1240
1241 #define RT_RF_CHANGE_SOURCE u32
1242
1243 #define RF_CHANGE_BY_SW BIT31
1244 #define RF_CHANGE_BY_HW BIT30
1245 #define RF_CHANGE_BY_PS BIT29
1246 #define RF_CHANGE_BY_IPS BIT28
1247 #define RF_CHANGE_BY_INIT       0
1248
1249 enum country_code_type {
1250         COUNTRY_CODE_FCC = 0,
1251         COUNTRY_CODE_IC = 1,
1252         COUNTRY_CODE_ETSI = 2,
1253         COUNTRY_CODE_SPAIN = 3,
1254         COUNTRY_CODE_FRANCE = 4,
1255         COUNTRY_CODE_MKK = 5,
1256         COUNTRY_CODE_MKK1 = 6,
1257         COUNTRY_CODE_ISRAEL = 7,
1258         COUNTRY_CODE_TELEC = 8,
1259         COUNTRY_CODE_MIC = 9,
1260         COUNTRY_CODE_GLOBAL_DOMAIN = 10,
1261         COUNTRY_CODE_WORLD_WIDE_13 = 11,
1262         COUNTRY_CODE_TELEC_NETGEAR = 12,
1263         COUNTRY_CODE_MAX
1264 };
1265
1266 enum scan_op_backup_opt {
1267         SCAN_OPT_BACKUP = 0,
1268         SCAN_OPT_RESTORE,
1269         SCAN_OPT_MAX
1270 };
1271
1272 enum fw_cmd_io_type {
1273         FW_CMD_DIG_ENABLE = 0,
1274         FW_CMD_DIG_DISABLE = 1,
1275         FW_CMD_DIG_HALT = 2,
1276         FW_CMD_DIG_RESUME = 3,
1277         FW_CMD_HIGH_PWR_ENABLE = 4,
1278         FW_CMD_HIGH_PWR_DISABLE = 5,
1279         FW_CMD_RA_RESET = 6,
1280         FW_CMD_RA_ACTIVE = 7,
1281         FW_CMD_RA_REFRESH_N = 8,
1282         FW_CMD_RA_REFRESH_BG = 9,
1283         FW_CMD_RA_INIT = 10,
1284         FW_CMD_IQK_ENABLE = 11,
1285         FW_CMD_TXPWR_TRACK_ENABLE = 12,
1286         FW_CMD_TXPWR_TRACK_DISABLE = 13,
1287         FW_CMD_TXPWR_TRACK_THERMAL = 14,
1288         FW_CMD_PAUSE_DM_BY_SCAN = 15,
1289         FW_CMD_RESUME_DM_BY_SCAN = 16,
1290         FW_CMD_RA_REFRESH_N_COMB = 17,
1291         FW_CMD_RA_REFRESH_BG_COMB = 18,
1292         FW_CMD_ANTENNA_SW_ENABLE = 19,
1293         FW_CMD_ANTENNA_SW_DISABLE = 20,
1294         FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
1295         FW_CMD_LPS_ENTER = 22,
1296         FW_CMD_LPS_LEAVE = 23,
1297 };
1298
1299 #define RT_MAX_LD_SLOT_NUM      10
1300 struct rt_link_detect {
1301
1302         u32                             NumRecvBcnInPeriod;
1303         u32                             NumRecvDataInPeriod;
1304
1305         u32                             RxBcnNum[RT_MAX_LD_SLOT_NUM];
1306         u32                             RxDataNum[RT_MAX_LD_SLOT_NUM];
1307         u16                             SlotNum;
1308         u16                             SlotIndex;
1309
1310         u32                             NumTxOkInPeriod;
1311         u32                             NumRxOkInPeriod;
1312         u32                             NumRxUnicastOkInPeriod;
1313         bool                            bBusyTraffic;
1314         bool                            bHigherBusyTraffic;
1315         bool                            bHigherBusyRxTraffic;
1316 };
1317
1318 struct sw_cam_table {
1319
1320         u8                              macaddr[ETH_ALEN];
1321         bool                            bused;
1322         u8                              key_buf[16];
1323         u16                             key_type;
1324         u8                              useDK;
1325         u8                              key_index;
1326
1327 };
1328
1329 #define   TOTAL_CAM_ENTRY                               32
1330 struct rate_adaptive {
1331         u8                              rate_adaptive_disabled;
1332         u8                              ratr_state;
1333         u16                             reserve;
1334
1335         u32                             high_rssi_thresh_for_ra;
1336         u32                             high2low_rssi_thresh_for_ra;
1337         u8                              low2high_rssi_thresh_for_ra40M;
1338         u32                             low_rssi_thresh_for_ra40M;
1339         u8                              low2high_rssi_thresh_for_ra20M;
1340         u32                             low_rssi_thresh_for_ra20M;
1341         u32                             upper_rssi_threshold_ratr;
1342         u32                             middle_rssi_threshold_ratr;
1343         u32                             low_rssi_threshold_ratr;
1344         u32                             low_rssi_threshold_ratr_40M;
1345         u32                             low_rssi_threshold_ratr_20M;
1346         u8                              ping_rssi_enable;
1347         u32                             ping_rssi_ratr;
1348         u32                             ping_rssi_thresh_for_ra;
1349         u32                             last_ratr;
1350         u8                              PreRATRState;
1351
1352 };
1353
1354 #define NUM_PMKID_CACHE         16
1355 struct rt_pmkid_list {
1356         u8 Bssid[ETH_ALEN];
1357         u8 PMKID[16];
1358         u8 SsidBuf[33];
1359         u8 bUsed;
1360 };
1361
1362 struct rt_intel_promisc_mode {
1363         bool promiscuous_on;
1364         bool fltr_src_sta_frame;
1365 };
1366
1367 /*************** DRIVER STATUS   *****/
1368 #define STATUS_SCANNING                 0
1369 /*************** DRIVER STATUS   *****/
1370
1371 enum {
1372         LPS_IS_WAKE = 0,
1373         LPS_IS_SLEEP = 1,
1374         LPS_WAIT_NULL_DATA_SEND = 2,
1375 };
1376
1377 struct rtllib_device {
1378         struct pci_dev *pdev;
1379         struct net_device *dev;
1380         struct rtllib_security sec;
1381
1382         bool disable_mgnt_queue;
1383
1384         unsigned long status;
1385         u8      CntAfterLink;
1386
1387         enum rt_op_mode OpMode;
1388
1389         /* The last AssocReq/Resp IEs */
1390         u8 *assocreq_ies, *assocresp_ies;
1391         size_t assocreq_ies_len, assocresp_ies_len;
1392
1393         bool    bForcedBgMode;
1394
1395         u8 hwsec_active;
1396         bool is_silent_reset;
1397         bool is_roaming;
1398         bool ieee_up;
1399         bool cannot_notify;
1400         bool bSupportRemoteWakeUp;
1401         bool actscanning;
1402         bool FirstIe_InScan;
1403         bool be_scan_inprogress;
1404         bool beinretry;
1405         enum rt_rf_power_state rf_power_state;
1406         RT_RF_CHANGE_SOURCE rf_off_reason;
1407         bool is_set_key;
1408         bool wx_set_enc;
1409         struct rt_hi_throughput *ht_info;
1410
1411         spinlock_t reorder_spinlock;
1412         u8      reg_dot11ht_oper_rate_set[16];
1413         u8      reg_dot11tx_ht_oper_rate_set[16];
1414         u8      dot11ht_oper_rate_set[16];
1415         u8      reg_ht_supp_rate_set[16];
1416         u8      HTCurrentOperaRate;
1417         u8      HTHighestOperaRate;
1418         u8      tx_dis_rate_fallback;
1419         u8      tx_use_drv_assinged_rate;
1420         u8      bTxEnableFwCalcDur;
1421         atomic_t        atm_swbw;
1422
1423         struct list_head                Tx_TS_Admit_List;
1424         struct list_head                Tx_TS_Pending_List;
1425         struct list_head                Tx_TS_Unused_List;
1426         struct tx_ts_record TxTsRecord[TOTAL_TS_NUM];
1427         struct list_head                Rx_TS_Admit_List;
1428         struct list_head                Rx_TS_Pending_List;
1429         struct list_head                Rx_TS_Unused_List;
1430         struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
1431         struct rx_reorder_entry RxReorderEntry[128];
1432         struct list_head                RxReorder_Unused_List;
1433
1434         /* Bookkeeping structures */
1435         struct net_device_stats stats;
1436         struct rtllib_softmac_stats softmac_stats;
1437
1438         /* Probe / Beacon management */
1439         struct list_head network_free_list;
1440         struct list_head network_list;
1441         struct rtllib_network *networks;
1442         int scans;
1443         int scan_age;
1444
1445         int iw_mode; /* operating mode (IW_MODE_*) */
1446         bool net_promiscuous_md;
1447         struct rt_intel_promisc_mode intel_promiscuous_md_info;
1448
1449         spinlock_t lock;
1450         spinlock_t wpax_suitlist_lock;
1451
1452         int tx_headroom; /* Set to size of any additional room needed at front
1453                           * of allocated Tx SKBs
1454                           */
1455         u32 config;
1456
1457         /* WEP and other encryption related settings at the device level */
1458         int open_wep; /* Set to 1 to allow unencrypted frames */
1459         int auth_mode;
1460         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1461                                  * WEP key changes
1462                                  */
1463
1464         /* If the host performs {en,de}cryption, then set to 1 */
1465         int host_encrypt;
1466         int host_decrypt;
1467
1468         int ieee802_1x; /* is IEEE 802.1X used */
1469
1470         /* WPA data */
1471         bool bHalfWirelessN24GMode;
1472         int wpa_enabled;
1473         int drop_unencrypted;
1474         int tkip_countermeasures;
1475         int privacy_invoked;
1476         size_t wpa_ie_len;
1477         u8 *wpa_ie;
1478         size_t wps_ie_len;
1479         u8 *wps_ie;
1480         u8 ap_mac_addr[ETH_ALEN];
1481         u16 pairwise_key_type;
1482         u16 group_key_type;
1483
1484         struct lib80211_crypt_info crypt_info;
1485
1486         struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY];
1487
1488         struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
1489
1490         /* Fragmentation structures */
1491         struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
1492         unsigned int frag_next_idx[17];
1493         u16 fts; /* Fragmentation Threshold */
1494 #define DEFAULT_RTS_THRESHOLD 2346U
1495 #define MIN_RTS_THRESHOLD 1
1496 #define MAX_RTS_THRESHOLD 2346U
1497         u16 rts; /* RTS threshold */
1498
1499         /* Association info */
1500         u8 bssid[ETH_ALEN];
1501
1502         /* This stores infos for the current network.
1503          * Either the network we are associated in INFRASTRUCTURE
1504          * or the network that we are creating in MASTER mode.
1505          * ad-hoc is a mixture ;-).
1506          * Note that in infrastructure mode, even when not associated,
1507          * fields bssid and essid may be valid (if wpa_set and essid_set
1508          * are true) as thy carry the value set by the user via iwconfig
1509          */
1510         struct rtllib_network current_network;
1511
1512         enum rtllib_state state;
1513
1514         int short_slot;
1515         int mode;       /* A, B, G */
1516         int modulation; /* CCK, OFDM */
1517
1518         /* used for forcing the ibss workqueue to terminate
1519          * without wait for the syncro scan to terminate
1520          */
1521         short sync_scan_hurryup;
1522         u16 scan_watch_dog;
1523
1524         /* map of allowed channels. 0 is dummy */
1525         void *dot11d_info;
1526         bool global_domain;
1527         u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
1528
1529         u8   bss_start_channel;
1530         u8   ibss_maxjoin_chal;
1531
1532         int rate;       /* current rate */
1533         int basic_rate;
1534
1535         short active_scan;
1536
1537         /* this contains flags for selectively enable softmac support */
1538         u16 softmac_features;
1539
1540         /* if the sequence control field is not filled by HW */
1541         u16 seq_ctrl[5];
1542
1543         /* association procedure transaction sequence number */
1544         u16 associate_seq;
1545
1546         /* AID for RTXed association responses */
1547         u16 assoc_id;
1548
1549         /* power save mode related*/
1550         u8 ack_tx_to_ieee;
1551         short ps;
1552         short sta_sleep;
1553         int ps_timeout;
1554         int ps_period;
1555         struct work_struct ps_task;
1556         u64 ps_time;
1557         bool polling;
1558
1559         short raw_tx;
1560         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1561         short queue_stop;
1562         short scanning_continue;
1563         short proto_started;
1564         short proto_stoppping;
1565
1566         struct mutex wx_mutex;
1567         struct mutex scan_mutex;
1568         struct mutex ips_mutex;
1569
1570         spinlock_t mgmt_tx_lock;
1571         spinlock_t beacon_lock;
1572
1573         short beacon_txing;
1574
1575         short wap_set;
1576         short ssid_set;
1577
1578         /* set on initialization */
1579         unsigned int wmm_acm;
1580
1581         /* for discarding duplicated packets in IBSS */
1582         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1583
1584         /* for discarding duplicated packets in BSS */
1585         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1586         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1587         unsigned long last_packet_time[17];
1588
1589         /* for PS mode */
1590         unsigned long last_rx_ps_time;
1591         bool                    bAwakePktSent;
1592         u8                      LPSDelayCnt;
1593
1594         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1595         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1596         int mgmt_queue_head;
1597         int mgmt_queue_tail;
1598         u8 AsocRetryCount;
1599         struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
1600
1601         bool    bdynamic_txpower_enable;
1602
1603         bool bCTSToSelfEnable;
1604
1605         u32     fsync_time_interval;
1606         u32     fsync_rate_bitmap;
1607         u8      fsync_rssi_threshold;
1608         bool    bfsync_enable;
1609
1610         u8      fsync_multiple_timeinterval;
1611         u32     fsync_firstdiff_ratethreshold;
1612         u32     fsync_seconddiff_ratethreshold;
1613         enum fsync_state fsync_state;
1614         bool            bis_any_nonbepkts;
1615         struct bandwidth_autoswitch bandwidth_auto_switch;
1616         bool FwRWRF;
1617
1618         struct rt_link_detect link_detect_info;
1619         bool bIsAggregateFrame;
1620         struct rt_pwr_save_ctrl pwr_save_ctrl;
1621
1622         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1623         struct tx_pending tx_pending;
1624
1625         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1626         struct timer_list associate_timer;
1627
1628         /* used if IEEE_SOFTMAC_BEACONS is set */
1629         struct timer_list beacon_timer;
1630         u8 need_sw_enc;
1631         struct work_struct associate_complete_wq;
1632         struct work_struct ips_leave_wq;
1633         struct delayed_work associate_procedure_wq;
1634         struct delayed_work softmac_scan_wq;
1635         struct delayed_work associate_retry_wq;
1636         struct delayed_work start_ibss_wq;
1637         struct delayed_work hw_wakeup_wq;
1638         struct delayed_work hw_sleep_wq;
1639         struct delayed_work link_change_wq;
1640         struct work_struct wx_sync_scan_wq;
1641
1642         union {
1643                 struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
1644                 struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
1645                 struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
1646                 struct {
1647                         struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT];
1648                         struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT];
1649                         struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1650                 };
1651         };
1652
1653         /* Callback functions */
1654         void (*set_security)(struct net_device *dev,
1655                              struct rtllib_security *sec);
1656
1657         /* Used to TX data frame by using txb structs.
1658          * this is not used if in the softmac_features
1659          * is set the flag IEEE_SOFTMAC_TX_QUEUE
1660          */
1661         int (*hard_start_xmit)(struct rtllib_txb *txb,
1662                                struct net_device *dev);
1663
1664         int (*reset_port)(struct net_device *dev);
1665
1666         /* Softmac-generated frames (management) are TXed via this
1667          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1668          * not set. As some cards may have different HW queues that
1669          * one might want to use for data and management frames
1670          * the option to have two callbacks might be useful.
1671          * This function can't sleep.
1672          */
1673         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1674                                struct net_device *dev);
1675
1676         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1677          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1678          * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1679          * then also management frames are sent via this callback.
1680          * This function can't sleep.
1681          */
1682         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1683                                struct net_device *dev, int rate);
1684
1685         /* stops the HW queue for DATA frames. Useful to avoid
1686          * waste time to TX data frame when we are reassociating
1687          * This function can sleep.
1688          */
1689         void (*data_hard_stop)(struct net_device *dev);
1690
1691         /* OK this is complementing to data_poll_hard_stop */
1692         void (*data_hard_resume)(struct net_device *dev);
1693
1694         /* ask to the driver to retune the radio.
1695          * This function can sleep. the driver should ensure
1696          * the radio has been switched before return.
1697          */
1698         void (*set_chan)(struct net_device *dev, short ch);
1699
1700         void (*rtllib_start_hw_scan)(struct net_device *dev);
1701         void (*rtllib_stop_hw_scan)(struct net_device *dev);
1702
1703         /* indicate the driver that the link state is changed
1704          * for example it may indicate the card is associated now.
1705          * Driver might be interested in this to apply RX filter
1706          * rules or simply light the LINK led
1707          */
1708         void (*link_change)(struct net_device *dev);
1709
1710         /* these two function indicates to the HW when to start
1711          * and stop to send beacons. This is used when the
1712          * IEEE_SOFTMAC_BEACONS is not set. For now the
1713          * stop_send_bacons is NOT guaranteed to be called only
1714          * after start_send_beacons.
1715          */
1716         void (*start_send_beacons)(struct net_device *dev);
1717         void (*stop_send_beacons)(struct net_device *dev);
1718
1719         /* power save mode related */
1720         void (*sta_wake_up)(struct net_device *dev);
1721         void (*enter_sleep_state)(struct net_device *dev, u64 time);
1722         short (*ps_is_queue_empty)(struct net_device *dev);
1723         int (*handle_beacon)(struct net_device *dev,
1724                              struct rtllib_beacon *beacon,
1725                              struct rtllib_network *network);
1726         int (*handle_assoc_response)(struct net_device *dev,
1727                                      struct rtllib_assoc_response_frame *resp,
1728                                      struct rtllib_network *network);
1729
1730         /* check whether Tx hw resource available */
1731         short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
1732         void (*SetBWModeHandler)(struct net_device *dev,
1733                                  enum ht_channel_width bandwidth,
1734                                  enum ht_extchnl_offset Offset);
1735         bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
1736         void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
1737         bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
1738         u8   (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
1739         void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
1740         bool (*SetFwCmdHandler)(struct net_device *dev,
1741                                 enum fw_cmd_io_type FwCmdIO);
1742         void (*UpdateBeaconInterruptHandler)(struct net_device *dev,
1743                                              bool start);
1744         void (*ScanOperationBackupHandler)(struct net_device *dev,
1745                                            u8 Operation);
1746         void (*LedControlHandler)(struct net_device *dev,
1747                                   enum led_ctl_mode LedAction);
1748         void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
1749
1750         void (*AllowAllDestAddrHandler)(struct net_device *dev,
1751                                         bool bAllowAllDA, bool WriteIntoReg);
1752
1753         void (*rtllib_ips_leave_wq)(struct net_device *dev);
1754         void (*rtllib_ips_leave)(struct net_device *dev);
1755         void (*LeisurePSLeave)(struct net_device *dev);
1756
1757         /* This must be the last item so that it points to the data
1758          * allocated beyond this structure by alloc_rtllib
1759          */
1760         u8 priv[];
1761 };
1762
1763 #define IEEE_A      (1<<0)
1764 #define IEEE_B      (1<<1)
1765 #define IEEE_G      (1<<2)
1766 #define IEEE_N_24G                (1<<4)
1767 #define IEEE_N_5G                 (1<<5)
1768 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1769
1770 /* Generate a 802.11 header */
1771
1772 /* Uses the channel change callback directly
1773  * instead of [start/stop] scan callbacks
1774  */
1775 #define IEEE_SOFTMAC_SCAN (1<<2)
1776
1777 /* Perform authentication and association handshake */
1778 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1779
1780 /* Generate probe requests */
1781 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1782
1783 /* Generate response to probe requests */
1784 #define IEEE_SOFTMAC_PROBERS (1<<5)
1785
1786 /* The ieee802.11 stack will manage the netif queue
1787  * wake/stop for the driver, taking care of 802.11
1788  * fragmentation. See softmac.c for details.
1789  */
1790 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1791
1792 /* Uses only the softmac_data_hard_start_xmit
1793  * even for TX management frames.
1794  */
1795 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1796
1797 /* Generate beacons.  The stack will enqueue beacons
1798  * to the card
1799  */
1800 #define IEEE_SOFTMAC_BEACONS (1<<6)
1801
1802 static inline void *rtllib_priv(struct net_device *dev)
1803 {
1804         return ((struct rtllib_device *)netdev_priv(dev))->priv;
1805 }
1806
1807 static inline int rtllib_is_empty_essid(const char *essid, int essid_len)
1808 {
1809         /* Single white space is for Linksys APs */
1810         if (essid_len == 1 && essid[0] == ' ')
1811                 return 1;
1812
1813         /* Otherwise, if the entire essid is 0, we assume it is hidden */
1814         while (essid_len) {
1815                 essid_len--;
1816                 if (essid[essid_len] != '\0')
1817                         return 0;
1818         }
1819
1820         return 1;
1821 }
1822
1823 static inline int rtllib_get_hdrlen(u16 fc)
1824 {
1825         int hdrlen = RTLLIB_3ADDR_LEN;
1826
1827         switch (WLAN_FC_GET_TYPE(fc)) {
1828         case RTLLIB_FTYPE_DATA:
1829                 if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
1830                         hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
1831                 if (RTLLIB_QOS_HAS_SEQ(fc))
1832                         hdrlen += 2; /* QOS ctrl*/
1833                 break;
1834         case RTLLIB_FTYPE_CTL:
1835                 switch (WLAN_FC_GET_STYPE(fc)) {
1836                 case RTLLIB_STYPE_CTS:
1837                 case RTLLIB_STYPE_ACK:
1838                         hdrlen = RTLLIB_1ADDR_LEN;
1839                         break;
1840                 default:
1841                         hdrlen = RTLLIB_2ADDR_LEN;
1842                         break;
1843                 }
1844                 break;
1845         }
1846
1847         return hdrlen;
1848 }
1849
1850 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
1851 {
1852         switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
1853         case RTLLIB_1ADDR_LEN:
1854                 return ((struct rtllib_hdr_1addr *)hdr)->payload;
1855         case RTLLIB_2ADDR_LEN:
1856                 return ((struct rtllib_hdr_2addr *)hdr)->payload;
1857         case RTLLIB_3ADDR_LEN:
1858                 return ((struct rtllib_hdr_3addr *)hdr)->payload;
1859         case RTLLIB_4ADDR_LEN:
1860                 return ((struct rtllib_hdr_4addr *)hdr)->payload;
1861         }
1862         return NULL;
1863 }
1864
1865 static inline int rtllib_is_ofdm_rate(u8 rate)
1866 {
1867         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1868         case RTLLIB_OFDM_RATE_6MB:
1869         case RTLLIB_OFDM_RATE_9MB:
1870         case RTLLIB_OFDM_RATE_12MB:
1871         case RTLLIB_OFDM_RATE_18MB:
1872         case RTLLIB_OFDM_RATE_24MB:
1873         case RTLLIB_OFDM_RATE_36MB:
1874         case RTLLIB_OFDM_RATE_48MB:
1875         case RTLLIB_OFDM_RATE_54MB:
1876                 return 1;
1877         }
1878         return 0;
1879 }
1880
1881 static inline int rtllib_is_cck_rate(u8 rate)
1882 {
1883         switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1884         case RTLLIB_CCK_RATE_1MB:
1885         case RTLLIB_CCK_RATE_2MB:
1886         case RTLLIB_CCK_RATE_5MB:
1887         case RTLLIB_CCK_RATE_11MB:
1888                 return 1;
1889         }
1890         return 0;
1891 }
1892
1893 /* rtllib.c */
1894 void free_rtllib(struct net_device *dev);
1895 struct net_device *alloc_rtllib(int sizeof_priv);
1896
1897 /* rtllib_tx.c */
1898
1899 int rtllib_encrypt_fragment(struct rtllib_device *ieee,
1900                             struct sk_buff *frag,
1901                             int hdr_len);
1902
1903 netdev_tx_t rtllib_xmit(struct sk_buff *skb,  struct net_device *dev);
1904 void rtllib_txb_free(struct rtllib_txb *txb);
1905
1906 /* rtllib_rx.c */
1907 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1908               struct rtllib_rx_stats *rx_stats);
1909 void rtllib_rx_probe_rq(struct rtllib_device *ieee,
1910                         struct sk_buff *skb);
1911 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
1912
1913 /* rtllib_wx.c */
1914 int rtllib_wx_get_scan(struct rtllib_device *ieee,
1915                        struct iw_request_info *info,
1916                        union iwreq_data *wrqu, char *key);
1917 int rtllib_wx_set_encode(struct rtllib_device *ieee,
1918                          struct iw_request_info *info,
1919                          union iwreq_data *wrqu, char *key);
1920 int rtllib_wx_get_encode(struct rtllib_device *ieee,
1921                          struct iw_request_info *info,
1922                          union iwreq_data *wrqu, char *key);
1923 int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
1924                              struct iw_request_info *info,
1925                              union iwreq_data *wrqu, char *extra);
1926 int rtllib_wx_set_auth(struct rtllib_device *ieee,
1927                        struct iw_request_info *info,
1928                        struct iw_param *data, char *extra);
1929 int rtllib_wx_set_mlme(struct rtllib_device *ieee,
1930                        struct iw_request_info *info,
1931                        union iwreq_data *wrqu, char *extra);
1932 int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
1933
1934 /* rtllib_softmac.c */
1935 int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
1936                             struct rtllib_rx_stats *rx_stats, u16 type,
1937                             u16 stype);
1938 void rtllib_softmac_new_net(struct rtllib_device *ieee,
1939                             struct rtllib_network *net);
1940
1941 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
1942 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
1943
1944 void rtllib_start_ibss(struct rtllib_device *ieee);
1945 int rtllib_softmac_init(struct rtllib_device *ieee);
1946 void rtllib_softmac_free(struct rtllib_device *ieee);
1947 void rtllib_disassociate(struct rtllib_device *ieee);
1948 void rtllib_stop_scan(struct rtllib_device *ieee);
1949 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
1950 void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
1951 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
1952 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
1953 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
1954 void rtllib_start_protocol(struct rtllib_device *ieee);
1955 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
1956
1957 void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState);
1958 void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState);
1959 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState);
1960 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
1961                                         bool bInitState);
1962 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
1963                                   u8 mesh_flag, u8 shutdown);
1964 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag);
1965
1966 void rtllib_reset_queue(struct rtllib_device *ieee);
1967 void rtllib_wake_all_queues(struct rtllib_device *ieee);
1968 void rtllib_stop_all_queues(struct rtllib_device *ieee);
1969 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
1970 void rtllib_start_send_beacons(struct rtllib_device *ieee);
1971 void rtllib_stop_send_beacons(struct rtllib_device *ieee);
1972
1973 void notify_wx_assoc_event(struct rtllib_device *ieee);
1974 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
1975
1976 void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
1977 u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
1978
1979 /* rtllib_softmac_wx.c */
1980
1981 int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info,
1982                       union iwreq_data *wrqu, char *ext);
1983
1984 int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info,
1985                       union iwreq_data *awrq, char *extra);
1986
1987 int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,
1988                         union iwreq_data *wrqu, char *b);
1989
1990 int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info,
1991                        union iwreq_data *wrqu, char *extra);
1992
1993 int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info,
1994                        union iwreq_data *wrqu, char *extra);
1995
1996 int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
1997                        union iwreq_data *wrqu, char *b);
1998
1999 int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
2000                        union iwreq_data *wrqu, char *b);
2001
2002 int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2003                         union iwreq_data *wrqu, char *extra);
2004
2005 int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2006                        union iwreq_data *wrqu, char *b);
2007
2008 int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2009                        union iwreq_data *wrqu, char *b);
2010
2011 int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2012                        union iwreq_data *wrqu, char *b);
2013 void rtllib_wx_sync_scan_wq(void *data);
2014
2015 int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
2016                         struct iw_request_info *info,
2017                         union iwreq_data *wrqu, char *extra);
2018
2019 int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info,
2020                        union iwreq_data *wrqu, char *extra);
2021
2022 int rtllib_wx_set_power(struct rtllib_device *ieee,
2023                         struct iw_request_info *info,
2024                         union iwreq_data *wrqu, char *extra);
2025
2026 int rtllib_wx_get_power(struct rtllib_device *ieee,
2027                         struct iw_request_info *info,
2028                         union iwreq_data *wrqu, char *extra);
2029
2030 int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2031                       union iwreq_data *wrqu, char *extra);
2032
2033 int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2034                       union iwreq_data *wrqu, char *extra);
2035 #define MAX_RECEIVE_BUFFER_SIZE 9100
2036
2037 void HTSetConnectBwMode(struct rtllib_device *ieee,
2038                         enum ht_channel_width bandwidth,
2039                         enum ht_extchnl_offset Offset);
2040 void HTUpdateDefaultSetting(struct rtllib_device *ieee);
2041 void HTConstructCapabilityElement(struct rtllib_device *ieee,
2042                                   u8 *posHTCap, u8 *len,
2043                                   u8 isEncrypt, bool bAssoc);
2044 void HTConstructInfoElement(struct rtllib_device *ieee,
2045                             u8 *posHTInfo, u8 *len, u8 isEncrypt);
2046 void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
2047                                 u8 *posRT2RTAgg, u8 *len);
2048 void HTOnAssocRsp(struct rtllib_device *ieee);
2049 void HTInitializeHTInfo(struct rtllib_device *ieee);
2050 void HTInitializeBssDesc(struct bss_ht *pBssHT);
2051 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
2052                                    struct rtllib_network *pNetwork);
2053 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
2054                                      struct rtllib_network *pNetwork);
2055 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
2056                        u8 *pMCSFilter);
2057 extern u8 MCS_FILTER_ALL[];
2058 extern u16 MCS_DATA_RATE[2][2][77];
2059 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
2060 void HTResetIOTSetting(struct rt_hi_throughput *ht_info);
2061 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
2062 u16  TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
2063 int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
2064 int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
2065 int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
2066 void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
2067                  u8 Policy, u8 bOverwritePending);
2068 void TsInitDelBA(struct rtllib_device *ieee,
2069                  struct ts_common_info *pTsCommonInfo,
2070                  enum tr_select TxRxSelect);
2071 void BaSetupTimeOut(struct timer_list *t);
2072 void TxBaInactTimeout(struct timer_list *t);
2073 void RxBaInactTimeout(struct timer_list *t);
2074 void ResetBaEntry(struct ba_record *pBA);
2075 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr,
2076            u8 TID, enum tr_select TxRxSelect, bool bAddNewTs);
2077 void TSInitialize(struct rtllib_device *ieee);
2078 void TsStartAddBaProcess(struct rtllib_device *ieee,
2079                          struct tx_ts_record *pTxTS);
2080 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2081 void RemoveAllTS(struct rtllib_device *ieee);
2082
2083 extern const long rtllib_wlan_frequencies[];
2084
2085 static inline const char *escape_essid(const char *essid, u8 essid_len)
2086 {
2087         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2088
2089         if (rtllib_is_empty_essid(essid, essid_len)) {
2090                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2091                 return escaped;
2092         }
2093
2094         snprintf(escaped, sizeof(escaped), "%*pE", essid_len, essid);
2095         return escaped;
2096 }
2097
2098 /* fun with the built-in rtllib stack... */
2099 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
2100
2101 /* For the function is more related to hardware setting, it's better to use the
2102  * ieee handler to refer to it.
2103  */
2104 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
2105                                  struct rx_ts_record *pTS);
2106 int rtllib_parse_info_param(struct rtllib_device *ieee,
2107                             struct rtllib_info_element *info_element,
2108                             u16 length,
2109                             struct rtllib_network *network,
2110                             struct rtllib_rx_stats *stats);
2111
2112 void rtllib_indicate_packets(struct rtllib_device *ieee,
2113                              struct rtllib_rxb **prxbIndicateArray, u8  index);
2114 void HTUseDefaultSetting(struct rtllib_device *ieee);
2115 #define RT_ASOC_RETRY_LIMIT     5
2116 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
2117
2118 #endif /* RTLLIB_H */
This page took 0.152756 seconds and 4 git commands to generate.