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