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

Archive Download this file



interactive