xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8822be/include/ieee80211.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef __IEEE80211_H
21 #define __IEEE80211_H
22 
23 
24 #ifndef CONFIG_RTL8711FW
25 
26 	#if defined PLATFORM_OS_XP
27 		#include <ntstrsafe.h>
28 	#endif
29 #else
30 
31 #endif
32 
33 #define MGMT_QUEUE_NUM 5
34 
35 #define ETH_ALEN	6
36 #define ETH_TYPE_LEN		2
37 #define PAYLOAD_TYPE_LEN	1
38 
39 #define NET80211_TU_TO_US	1024		/* unit:us */
40 #define DEFAULT_BCN_INTERVAL 100 /* 100 ms */
41 
42 #ifdef CONFIG_AP_MODE
43 
44 #define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
45 
46 /* RTL871X_IOCTL_HOSTAPD ioctl() cmd: */
47 enum {
48 	RTL871X_HOSTAPD_FLUSH = 1,
49 	RTL871X_HOSTAPD_ADD_STA = 2,
50 	RTL871X_HOSTAPD_REMOVE_STA = 3,
51 	RTL871X_HOSTAPD_GET_INFO_STA = 4,
52 	/* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
53 	RTL871X_HOSTAPD_GET_WPAIE_STA = 5,
54 	RTL871X_SET_ENCRYPTION = 6,
55 	RTL871X_GET_ENCRYPTION = 7,
56 	RTL871X_HOSTAPD_SET_FLAGS_STA = 8,
57 	RTL871X_HOSTAPD_GET_RID = 9,
58 	RTL871X_HOSTAPD_SET_RID = 10,
59 	RTL871X_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
60 	RTL871X_HOSTAPD_SET_GENERIC_ELEMENT = 12,
61 	RTL871X_HOSTAPD_MLME = 13,
62 	RTL871X_HOSTAPD_SCAN_REQ = 14,
63 	RTL871X_HOSTAPD_STA_CLEAR_STATS = 15,
64 	RTL871X_HOSTAPD_SET_BEACON = 16,
65 	RTL871X_HOSTAPD_SET_WPS_BEACON = 17,
66 	RTL871X_HOSTAPD_SET_WPS_PROBE_RESP = 18,
67 	RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP = 19,
68 	RTL871X_HOSTAPD_SET_HIDDEN_SSID = 20,
69 	RTL871X_HOSTAPD_SET_MACADDR_ACL = 21,
70 	RTL871X_HOSTAPD_ACL_ADD_STA = 22,
71 	RTL871X_HOSTAPD_ACL_REMOVE_STA = 23,
72 };
73 
74 /* STA flags */
75 #define WLAN_STA_AUTH BIT(0)
76 #define WLAN_STA_ASSOC BIT(1)
77 #define WLAN_STA_PS BIT(2)
78 #define WLAN_STA_TIM BIT(3)
79 #define WLAN_STA_PERM BIT(4)
80 #define WLAN_STA_AUTHORIZED BIT(5)
81 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
82 #define WLAN_STA_SHORT_PREAMBLE BIT(7)
83 #define WLAN_STA_PREAUTH BIT(8)
84 #define WLAN_STA_WME BIT(9)
85 #define WLAN_STA_MFP BIT(10)
86 #define WLAN_STA_HT BIT(11)
87 #define WLAN_STA_WPS BIT(12)
88 #define WLAN_STA_MAYBE_WPS BIT(13)
89 #define WLAN_STA_VHT BIT(14)
90 #define WLAN_STA_NONERP BIT(31)
91 
92 #endif
93 
94 #define IEEE_CMD_SET_WPA_PARAM			1
95 #define IEEE_CMD_SET_WPA_IE				2
96 #define IEEE_CMD_SET_ENCRYPTION			3
97 #define IEEE_CMD_MLME						4
98 
99 #define IEEE_PARAM_WPA_ENABLED				1
100 #define IEEE_PARAM_TKIP_COUNTERMEASURES		2
101 #define IEEE_PARAM_DROP_UNENCRYPTED			3
102 #define IEEE_PARAM_PRIVACY_INVOKED			4
103 #define IEEE_PARAM_AUTH_ALGS					5
104 #define IEEE_PARAM_IEEE_802_1X				6
105 #define IEEE_PARAM_WPAX_SELECT				7
106 
107 #define AUTH_ALG_OPEN_SYSTEM			0x1
108 #define AUTH_ALG_SHARED_KEY			0x2
109 #define AUTH_ALG_LEAP				0x00000004
110 
111 #define IEEE_MLME_STA_DEAUTH				1
112 #define IEEE_MLME_STA_DISASSOC			2
113 
114 #define IEEE_CRYPT_ERR_UNKNOWN_ALG			2
115 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR			3
116 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED		4
117 #define IEEE_CRYPT_ERR_KEY_SET_FAILED			5
118 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED		6
119 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED		7
120 
121 
122 #define	IEEE_CRYPT_ALG_NAME_LEN			16
123 
124 #define WPA_CIPHER_NONE	BIT(0)
125 #define WPA_CIPHER_WEP40	BIT(1)
126 #define WPA_CIPHER_WEP104 BIT(2)
127 #define WPA_CIPHER_TKIP	BIT(3)
128 #define WPA_CIPHER_CCMP	BIT(4)
129 
130 
131 
132 #define WPA_SELECTOR_LEN 4
133 extern u8 RTW_WPA_OUI_TYPE[] ;
134 extern u16 RTW_WPA_VERSION ;
135 extern u8 WPA_AUTH_KEY_MGMT_NONE[];
136 extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[];
137 extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
138 extern u8 WPA_CIPHER_SUITE_NONE[];
139 extern u8 WPA_CIPHER_SUITE_WEP40[];
140 extern u8 WPA_CIPHER_SUITE_TKIP[];
141 extern u8 WPA_CIPHER_SUITE_WRAP[];
142 extern u8 WPA_CIPHER_SUITE_CCMP[];
143 extern u8 WPA_CIPHER_SUITE_WEP104[];
144 
145 
146 #define RSN_HEADER_LEN 4
147 #define RSN_SELECTOR_LEN 4
148 
149 extern u16 RSN_VERSION_BSD;
150 extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[];
151 extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
152 extern u8 RSN_CIPHER_SUITE_NONE[];
153 extern u8 RSN_CIPHER_SUITE_WEP40[];
154 extern u8 RSN_CIPHER_SUITE_TKIP[];
155 extern u8 RSN_CIPHER_SUITE_WRAP[];
156 extern u8 RSN_CIPHER_SUITE_CCMP[];
157 extern u8 RSN_CIPHER_SUITE_WEP104[];
158 
159 
160 typedef enum _RATEID_IDX_ {
161 	RATEID_IDX_BGN_40M_2SS = 0,
162 	RATEID_IDX_BGN_40M_1SS = 1,
163 	RATEID_IDX_BGN_20M_2SS_BN = 2,
164 	RATEID_IDX_BGN_20M_1SS_BN = 3,
165 	RATEID_IDX_GN_N2SS = 4,
166 	RATEID_IDX_GN_N1SS = 5,
167 	RATEID_IDX_BG = 6,
168 	RATEID_IDX_G = 7,
169 	RATEID_IDX_B = 8,
170 	RATEID_IDX_VHT_2SS = 9,
171 	RATEID_IDX_VHT_1SS = 10,
172 	RATEID_IDX_MIX1 = 11,
173 	RATEID_IDX_MIX2 = 12,
174 	RATEID_IDX_VHT_3SS = 13,
175 	RATEID_IDX_BGN_3SS = 14,
176 } RATEID_IDX, *PRATEID_IDX;
177 
178 typedef enum _RATR_TABLE_MODE {
179 	RATR_INX_WIRELESS_NGB = 0,	/* BGN 40 Mhz 2SS 1SS */
180 	RATR_INX_WIRELESS_NG = 1,		/* GN or N */
181 	RATR_INX_WIRELESS_NB = 2,		/* BGN 20 Mhz 2SS 1SS  or BN */
182 	RATR_INX_WIRELESS_N = 3,
183 	RATR_INX_WIRELESS_GB = 4,
184 	RATR_INX_WIRELESS_G = 5,
185 	RATR_INX_WIRELESS_B = 6,
186 	RATR_INX_WIRELESS_MC = 7,
187 	RATR_INX_WIRELESS_AC_N = 8,
188 } RATR_TABLE_MODE, *PRATR_TABLE_MODE;
189 
190 
191 enum NETWORK_TYPE {
192 	WIRELESS_INVALID = 0,
193 	/* Sub-Element */
194 	WIRELESS_11B = BIT(0), /* tx: cck only , rx: cck only, hw: cck */
195 	WIRELESS_11G = BIT(1), /* tx: ofdm only, rx: ofdm & cck, hw: cck & ofdm */
196 	WIRELESS_11A = BIT(2), /* tx: ofdm only, rx: ofdm only, hw: ofdm only */
197 	WIRELESS_11_24N = BIT(3), /* tx: MCS only, rx: MCS & cck, hw: MCS & cck */
198 	WIRELESS_11_5N = BIT(4), /* tx: MCS only, rx: MCS & ofdm, hw: ofdm only */
199 	WIRELESS_AUTO = BIT(5),
200 	WIRELESS_11AC = BIT(6),
201 
202 	/* Combination */
203 	/* Type for current wireless mode */
204 	WIRELESS_11BG = (WIRELESS_11B | WIRELESS_11G), /* tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
205 	WIRELESS_11G_24N = (WIRELESS_11G | WIRELESS_11_24N), /* tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
206 	WIRELESS_11A_5N = (WIRELESS_11A | WIRELESS_11_5N), /* tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
207 	WIRELESS_11B_24N = (WIRELESS_11B | WIRELESS_11_24N), /* tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
208 	WIRELESS_11BG_24N = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N), /* tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
209 	WIRELESS_11_24AC = (WIRELESS_11G | WIRELESS_11AC),
210 	WIRELESS_11_24BGAC = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11AC),
211 	WIRELESS_11_5AC = (WIRELESS_11A | WIRELESS_11AC),
212 
213 
214 	/* Type for registry default wireless mode */
215 	WIRELESS_11AGN = (WIRELESS_11A | WIRELESS_11G | WIRELESS_11_24N | WIRELESS_11_5N), /* tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
216 	WIRELESS_11ABGN = (WIRELESS_11A | WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N | WIRELESS_11_5N),
217 	WIRELESS_MODE_24G = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N),
218 	WIRELESS_MODE_5G = (WIRELESS_11A | WIRELESS_11_5N | WIRELESS_11AC),
219 	WIRELESS_MODE_MAX = (WIRELESS_11A | WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N | WIRELESS_11_5N | WIRELESS_11AC),
220 };
221 
222 #define SUPPORTED_24G_NETTYPE_MSK WIRELESS_MODE_24G
223 #define SUPPORTED_5G_NETTYPE_MSK WIRELESS_MODE_5G
224 
225 #define IsLegacyOnly(NetType)  ((NetType) == ((NetType) & (WIRELESS_11BG | WIRELESS_11A)))
226 
227 #define IsSupported24G(NetType) ((NetType) & SUPPORTED_24G_NETTYPE_MSK ? _TRUE : _FALSE)
228 #define IsSupported5G(NetType) ((NetType) & SUPPORTED_5G_NETTYPE_MSK ? _TRUE : _FALSE)
229 
230 #define IsEnableHWCCK(NetType) IsSupported24G(NetType)
231 #define IsEnableHWOFDM(NetType) ((NetType) & (WIRELESS_11G | WIRELESS_11_24N | SUPPORTED_5G_NETTYPE_MSK) ? _TRUE : _FALSE)
232 
233 #define IsSupportedRxCCK(NetType) IsEnableHWCCK(NetType)
234 #define IsSupportedRxOFDM(NetType) IsEnableHWOFDM(NetType)
235 #define IsSupportedRxHT(NetType) IsEnableHWOFDM(NetType)
236 
237 #define IsSupportedTxCCK(NetType) ((NetType) & (WIRELESS_11B) ? _TRUE : _FALSE)
238 #define IsSupportedTxOFDM(NetType) ((NetType) & (WIRELESS_11G | WIRELESS_11A) ? _TRUE : _FALSE)
239 #define IsSupportedHT(NetType) ((NetType) & (WIRELESS_11_24N | WIRELESS_11_5N) ? _TRUE : _FALSE)
240 
241 #define IsSupportedVHT(NetType) ((NetType) & (WIRELESS_11AC) ? _TRUE : _FALSE)
242 
243 
244 typedef struct ieee_param {
245 	u32 cmd;
246 	u8 sta_addr[ETH_ALEN];
247 	union {
248 		struct {
249 			u8 name;
250 			u32 value;
251 		} wpa_param;
252 		struct {
253 			u32 len;
254 			u8 reserved[32];
255 			u8 data[0];
256 		} wpa_ie;
257 		struct {
258 			int command;
259 			int reason_code;
260 		} mlme;
261 		struct {
262 			u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
263 			u8 set_tx;
264 			u32 err;
265 			u8 idx;
266 			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
267 			u16 key_len;
268 			u8 key[0];
269 		} crypt;
270 #ifdef CONFIG_AP_MODE
271 		struct {
272 			u16 aid;
273 			u16 capability;
274 			int flags;
275 			u8 tx_supp_rates[16];
276 			struct rtw_ieee80211_ht_cap ht_cap;
277 		} add_sta;
278 		struct {
279 			u8	reserved[2];/* for set max_num_sta */
280 			u8	buf[0];
281 		} bcn_ie;
282 #endif
283 
284 	} u;
285 } ieee_param;
286 
287 #ifdef CONFIG_AP_MODE
288 typedef struct ieee_param_ex {
289 	u32 cmd;
290 	u8 sta_addr[ETH_ALEN];
291 	u8 data[0];
292 } ieee_param_ex;
293 
294 struct sta_data {
295 	u16 aid;
296 	u16 capability;
297 	int flags;
298 	u32 sta_set;
299 	u8 tx_supp_rates[16];
300 	u32 tx_supp_rates_len;
301 	struct rtw_ieee80211_ht_cap ht_cap;
302 	u64	rx_pkts;
303 	u64	rx_bytes;
304 	u64	rx_drops;
305 	u64	tx_pkts;
306 	u64	tx_bytes;
307 	u64	tx_drops;
308 };
309 #endif
310 
311 
312 #if WIRELESS_EXT < 17
313 	#define IW_QUAL_QUAL_INVALID   0x10
314 	#define IW_QUAL_LEVEL_INVALID  0x20
315 	#define IW_QUAL_NOISE_INVALID  0x40
316 	#define IW_QUAL_QUAL_UPDATED   0x1
317 	#define IW_QUAL_LEVEL_UPDATED  0x2
318 	#define IW_QUAL_NOISE_UPDATED  0x4
319 #endif
320 
321 #define IEEE80211_DATA_LEN		2304
322 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
323    6.2.1.1.2.
324 
325    The figure in section 7.1.2 suggests a body size of up to 2312
326    bytes is allowed, which is a bit confusing, I suspect this
327    represents the 2304 bytes of real data, plus a possible 8 bytes of
328    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
329 
330 
331 #define IEEE80211_HLEN			30
332 #define IEEE80211_FRAME_LEN		(IEEE80211_DATA_LEN + IEEE80211_HLEN)
333 
334 
335 /* this is stolen from ipw2200 driver */
336 #define IEEE_IBSS_MAC_HASH_SIZE 31
337 
338 struct ieee_ibss_seq {
339 	u8 mac[ETH_ALEN];
340 	u16 seq_num;
341 	u16 frag_num;
342 	unsigned long packet_time;
343 	_list	list;
344 };
345 
346 #if defined(PLATFORM_LINUX) || defined(CONFIG_RTL8711FW) || defined(PLATFORM_FREEBSD)
347 
348 struct rtw_ieee80211_hdr {
349 	u16 frame_ctl;
350 	u16 duration_id;
351 	u8 addr1[ETH_ALEN];
352 	u8 addr2[ETH_ALEN];
353 	u8 addr3[ETH_ALEN];
354 	u16 seq_ctl;
355 	u8 addr4[ETH_ALEN];
356 } __attribute__((packed));
357 
358 struct rtw_ieee80211_hdr_3addr {
359 	u16 frame_ctl;
360 	u16 duration_id;
361 	u8 addr1[ETH_ALEN];
362 	u8 addr2[ETH_ALEN];
363 	u8 addr3[ETH_ALEN];
364 	u16 seq_ctl;
365 } __attribute__((packed));
366 
367 
368 struct rtw_ieee80211_hdr_qos {
369 	u16 frame_ctl;
370 	u16 duration_id;
371 	u8 addr1[ETH_ALEN];
372 	u8 addr2[ETH_ALEN];
373 	u8 addr3[ETH_ALEN];
374 	u16 seq_ctl;
375 	u8 addr4[ETH_ALEN];
376 	u16	qc;
377 }  __attribute__((packed));
378 
379 struct rtw_ieee80211_hdr_3addr_qos {
380 	u16 frame_ctl;
381 	u16 duration_id;
382 	u8 addr1[ETH_ALEN];
383 	u8 addr2[ETH_ALEN];
384 	u8 addr3[ETH_ALEN];
385 	u16 seq_ctl;
386 	u16     qc;
387 }  __attribute__((packed));
388 
389 struct eapol {
390 	u8 snap[6];
391 	u16 ethertype;
392 	u8 version;
393 	u8 type;
394 	u16 length;
395 } __attribute__((packed));
396 
397 #endif
398 
399 
400 
401 #ifdef PLATFORM_WINDOWS
402 
403 #pragma pack(1)
404 struct rtw_ieee80211_hdr {
405 	u16 frame_ctl;
406 	u16 duration_id;
407 	u8 addr1[ETH_ALEN];
408 	u8 addr2[ETH_ALEN];
409 	u8 addr3[ETH_ALEN];
410 	u16 seq_ctl;
411 	u8 addr4[ETH_ALEN];
412 };
413 
414 struct rtw_ieee80211_hdr_3addr {
415 	u16 frame_ctl;
416 	u16 duration_id;
417 	u8 addr1[ETH_ALEN];
418 	u8 addr2[ETH_ALEN];
419 	u8 addr3[ETH_ALEN];
420 	u16 seq_ctl;
421 };
422 
423 
424 struct rtw_ieee80211_hdr_qos {
425 	struct rtw_ieee80211_hdr wlan_hdr;
426 	u16	qc;
427 };
428 
429 struct rtw_ieee80211_hdr_3addr_qos {
430 	struct  rtw_ieee80211_hdr_3addr wlan_hdr;
431 	u16     qc;
432 };
433 
434 struct eapol {
435 	u8 snap[6];
436 	u16 ethertype;
437 	u8 version;
438 	u8 type;
439 	u16 length;
440 };
441 #pragma pack()
442 
443 #endif
444 
445 
446 
447 enum eap_type {
448 	EAP_PACKET = 0,
449 	EAPOL_START,
450 	EAPOL_LOGOFF,
451 	EAPOL_KEY,
452 	EAPOL_ENCAP_ASF_ALERT
453 };
454 
455 #define IEEE80211_3ADDR_LEN 24
456 #define IEEE80211_4ADDR_LEN 30
457 #define IEEE80211_FCS_LEN    4
458 
459 #define MIN_FRAG_THRESHOLD     256U
460 #define	MAX_FRAG_THRESHOLD     2346U
461 
462 /* Frame control field constants */
463 #define RTW_IEEE80211_FCTL_VERS		0x0003
464 #define RTW_IEEE80211_FCTL_FTYPE		0x000c
465 #define RTW_IEEE80211_FCTL_STYPE		0x00f0
466 #define RTW_IEEE80211_FCTL_TODS		0x0100
467 #define RTW_IEEE80211_FCTL_FROMDS	0x0200
468 #define RTW_IEEE80211_FCTL_MOREFRAGS	0x0400
469 #define RTW_IEEE80211_FCTL_RETRY		0x0800
470 #define RTW_IEEE80211_FCTL_PM		0x1000
471 #define RTW_IEEE80211_FCTL_MOREDATA	0x2000
472 #define RTW_IEEE80211_FCTL_PROTECTED	0x4000
473 #define RTW_IEEE80211_FCTL_ORDER		0x8000
474 #define RTW_IEEE80211_FCTL_CTL_EXT	0x0f00
475 
476 #define RTW_IEEE80211_FTYPE_MGMT		0x0000
477 #define RTW_IEEE80211_FTYPE_CTL		0x0004
478 #define RTW_IEEE80211_FTYPE_DATA		0x0008
479 #define RTW_IEEE80211_FTYPE_EXT		0x000c
480 
481 /* management */
482 #define RTW_IEEE80211_STYPE_ASSOC_REQ	0x0000
483 #define RTW_IEEE80211_STYPE_ASSOC_RESP	0x0010
484 #define RTW_IEEE80211_STYPE_REASSOC_REQ	0x0020
485 #define RTW_IEEE80211_STYPE_REASSOC_RESP	0x0030
486 #define RTW_IEEE80211_STYPE_PROBE_REQ	0x0040
487 #define RTW_IEEE80211_STYPE_PROBE_RESP	0x0050
488 #define RTW_IEEE80211_STYPE_BEACON		0x0080
489 #define RTW_IEEE80211_STYPE_ATIM		0x0090
490 #define RTW_IEEE80211_STYPE_DISASSOC	0x00A0
491 #define RTW_IEEE80211_STYPE_AUTH		0x00B0
492 #define RTW_IEEE80211_STYPE_DEAUTH		0x00C0
493 #define RTW_IEEE80211_STYPE_ACTION		0x00D0
494 
495 /* control */
496 #define RTW_IEEE80211_STYPE_CTL_EXT		0x0060
497 #define RTW_IEEE80211_STYPE_BACK_REQ		0x0080
498 #define RTW_IEEE80211_STYPE_BACK		0x0090
499 #define RTW_IEEE80211_STYPE_PSPOLL		0x00A0
500 #define RTW_IEEE80211_STYPE_RTS		0x00B0
501 #define RTW_IEEE80211_STYPE_CTS		0x00C0
502 #define RTW_IEEE80211_STYPE_ACK		0x00D0
503 #define RTW_IEEE80211_STYPE_CFEND		0x00E0
504 #define RTW_IEEE80211_STYPE_CFENDACK		0x00F0
505 
506 /* data */
507 #define RTW_IEEE80211_STYPE_DATA		0x0000
508 #define RTW_IEEE80211_STYPE_DATA_CFACK	0x0010
509 #define RTW_IEEE80211_STYPE_DATA_CFPOLL	0x0020
510 #define RTW_IEEE80211_STYPE_DATA_CFACKPOLL	0x0030
511 #define RTW_IEEE80211_STYPE_NULLFUNC	0x0040
512 #define RTW_IEEE80211_STYPE_CFACK		0x0050
513 #define RTW_IEEE80211_STYPE_CFPOLL		0x0060
514 #define RTW_IEEE80211_STYPE_CFACKPOLL	0x0070
515 #define RTW_IEEE80211_STYPE_QOS_DATA		0x0080
516 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACK		0x0090
517 #define RTW_IEEE80211_STYPE_QOS_DATA_CFPOLL		0x00A0
518 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACKPOLL	0x00B0
519 #define RTW_IEEE80211_STYPE_QOS_NULLFUNC	0x00C0
520 #define RTW_IEEE80211_STYPE_QOS_CFACK		0x00D0
521 #define RTW_IEEE80211_STYPE_QOS_CFPOLL		0x00E0
522 #define RTW_IEEE80211_STYPE_QOS_CFACKPOLL	0x00F0
523 
524 /* sequence control field */
525 #define RTW_IEEE80211_SCTL_FRAG	0x000F
526 #define RTW_IEEE80211_SCTL_SEQ	0xFFF0
527 
528 
529 #define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0)
530 #define RTW_ERP_INFO_USE_PROTECTION BIT(1)
531 #define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
532 
533 /* QoS,QOS */
534 #define NORMAL_ACK			0
535 #define NO_ACK				1
536 #define NON_EXPLICIT_ACK	2
537 #define BLOCK_ACK			3
538 
539 #ifndef ETH_P_PAE
540 	#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
541 #endif /* ETH_P_PAE */
542 
543 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
544 
545 #define ETH_P_ECONET	0x0018
546 
547 #ifndef ETH_P_80211_RAW
548 	#define ETH_P_80211_RAW (ETH_P_ECONET + 1)
549 #endif
550 
551 /* IEEE 802.11 defines */
552 
553 #define P80211_OUI_LEN 3
554 
555 #if defined(PLATFORM_LINUX) || defined(CONFIG_RTL8711FW) || defined(PLATFORM_FREEBSD)
556 
557 struct ieee80211_snap_hdr {
558 
559 	u8    dsap;   /* always 0xAA */
560 	u8    ssap;   /* always 0xAA */
561 	u8    ctrl;   /* always 0x03 */
562 	u8    oui[P80211_OUI_LEN];    /* organizational universal id */
563 
564 } __attribute__((packed));
565 
566 #endif
567 
568 #ifdef PLATFORM_WINDOWS
569 
570 #pragma pack(1)
571 struct ieee80211_snap_hdr {
572 
573 	u8    dsap;   /* always 0xAA */
574 	u8    ssap;   /* always 0xAA */
575 	u8    ctrl;   /* always 0x03 */
576 	u8    oui[P80211_OUI_LEN];    /* organizational universal id */
577 
578 };
579 #pragma pack()
580 
581 #endif
582 
583 
584 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
585 
586 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTW_IEEE80211_FCTL_FTYPE)
587 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTW_IEEE80211_FCTL_STYPE)
588 
589 #define WLAN_QC_GET_TID(qc) ((qc) & 0x0f)
590 
591 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
592 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & RTW_IEEE80211_SCTL_SEQ)
593 
594 /* Authentication algorithms */
595 #define WLAN_AUTH_OPEN 0
596 #define WLAN_AUTH_SHARED_KEY 1
597 
598 #define WLAN_AUTH_CHALLENGE_LEN 128
599 
600 #define WLAN_CAPABILITY_BSS (1<<0)
601 #define WLAN_CAPABILITY_IBSS (1<<1)
602 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
603 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
604 #define WLAN_CAPABILITY_PRIVACY (1<<4)
605 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
606 #define WLAN_CAPABILITY_PBCC (1<<6)
607 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
608 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
609 
610 /* Status codes */
611 #define WLAN_STATUS_SUCCESS 0
612 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
613 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
614 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
615 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
616 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
617 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
618 #define WLAN_STATUS_CHALLENGE_FAIL 15
619 #define WLAN_STATUS_AUTH_TIMEOUT 16
620 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
621 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
622 /* 802.11b */
623 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
624 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
625 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
626 
627 /* Reason codes */
628 #define WLAN_REASON_UNSPECIFIED 1
629 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
630 #define WLAN_REASON_DEAUTH_LEAVING 3
631 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
632 #define WLAN_REASON_DISASSOC_AP_BUSY 5
633 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
634 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
635 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
636 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
637 #define WLAN_REASON_ACTIVE_ROAM 65533
638 #define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
639 #define WLAN_REASON_EXPIRATION_CHK 65535
640 
641 /* Information Element IDs */
642 #define WLAN_EID_SSID 0
643 #define WLAN_EID_SUPP_RATES 1
644 #define WLAN_EID_FH_PARAMS 2
645 #define WLAN_EID_DS_PARAMS 3
646 #define WLAN_EID_CF_PARAMS 4
647 #define WLAN_EID_TIM 5
648 #define WLAN_EID_IBSS_PARAMS 6
649 #define WLAN_EID_CHALLENGE 16
650 /* EIDs defined by IEEE 802.11h - START */
651 #define WLAN_EID_PWR_CONSTRAINT 32
652 #define WLAN_EID_PWR_CAPABILITY 33
653 #define WLAN_EID_TPC_REQUEST 34
654 #define WLAN_EID_TPC_REPORT 35
655 #define WLAN_EID_SUPPORTED_CHANNELS 36
656 #define WLAN_EID_CHANNEL_SWITCH 37
657 #define WLAN_EID_MEASURE_REQUEST 38
658 #define WLAN_EID_MEASURE_REPORT 39
659 #define WLAN_EID_QUITE 40
660 #define WLAN_EID_IBSS_DFS 41
661 /* EIDs defined by IEEE 802.11h - END */
662 #define WLAN_EID_ERP_INFO 42
663 #define WLAN_EID_HT_CAP 45
664 #define WLAN_EID_RSN 48
665 #define WLAN_EID_EXT_SUPP_RATES 50
666 #define WLAN_EID_MOBILITY_DOMAIN 54
667 #define WLAN_EID_FAST_BSS_TRANSITION 55
668 #define WLAN_EID_TIMEOUT_INTERVAL 56
669 #define WLAN_EID_RIC_DATA 57
670 #define WLAN_EID_HT_OPERATION 61
671 #define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
672 #define WLAN_EID_20_40_BSS_COEXISTENCE 72
673 #define WLAN_EID_20_40_BSS_INTOLERANT 73
674 #define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
675 #define WLAN_EID_MMIE 76
676 #define WLAN_EID_VENDOR_SPECIFIC 221
677 #define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
678 #define WLAN_EID_VHT_CAPABILITY 191
679 #define WLAN_EID_VHT_OPERATION 192
680 #define WLAN_EID_VHT_OP_MODE_NOTIFY 199
681 
682 #define IEEE80211_MGMT_HDR_LEN 24
683 #define IEEE80211_DATA_HDR3_LEN 24
684 #define IEEE80211_DATA_HDR4_LEN 30
685 
686 
687 #define IEEE80211_STATMASK_SIGNAL (1<<0)
688 #define IEEE80211_STATMASK_RSSI (1<<1)
689 #define IEEE80211_STATMASK_NOISE (1<<2)
690 #define IEEE80211_STATMASK_RATE (1<<3)
691 #define IEEE80211_STATMASK_WEMASK 0x7
692 
693 
694 #define IEEE80211_CCK_MODULATION    (1<<0)
695 #define IEEE80211_OFDM_MODULATION   (1<<1)
696 
697 #define IEEE80211_24GHZ_BAND     (1<<0)
698 #define IEEE80211_52GHZ_BAND     (1<<1)
699 
700 #define IEEE80211_CCK_RATE_LEN		4
701 #define IEEE80211_NUM_OFDM_RATESLEN	8
702 
703 
704 #define IEEE80211_CCK_RATE_1MB		        0x02
705 #define IEEE80211_CCK_RATE_2MB		        0x04
706 #define IEEE80211_CCK_RATE_5MB		        0x0B
707 #define IEEE80211_CCK_RATE_11MB		        0x16
708 #define IEEE80211_OFDM_RATE_LEN		8
709 #define IEEE80211_OFDM_RATE_6MB		        0x0C
710 #define IEEE80211_OFDM_RATE_9MB		        0x12
711 #define IEEE80211_OFDM_RATE_12MB		0x18
712 #define IEEE80211_OFDM_RATE_18MB		0x24
713 #define IEEE80211_OFDM_RATE_24MB		0x30
714 #define IEEE80211_OFDM_RATE_36MB		0x48
715 #define IEEE80211_OFDM_RATE_48MB		0x60
716 #define IEEE80211_OFDM_RATE_54MB		0x6C
717 #define IEEE80211_BASIC_RATE_MASK		0x80
718 
719 #define IEEE80211_CCK_RATE_1MB_MASK		(1<<0)
720 #define IEEE80211_CCK_RATE_2MB_MASK		(1<<1)
721 #define IEEE80211_CCK_RATE_5MB_MASK		(1<<2)
722 #define IEEE80211_CCK_RATE_11MB_MASK		(1<<3)
723 #define IEEE80211_OFDM_RATE_6MB_MASK		(1<<4)
724 #define IEEE80211_OFDM_RATE_9MB_MASK		(1<<5)
725 #define IEEE80211_OFDM_RATE_12MB_MASK		(1<<6)
726 #define IEEE80211_OFDM_RATE_18MB_MASK		(1<<7)
727 #define IEEE80211_OFDM_RATE_24MB_MASK		(1<<8)
728 #define IEEE80211_OFDM_RATE_36MB_MASK		(1<<9)
729 #define IEEE80211_OFDM_RATE_48MB_MASK		(1<<10)
730 #define IEEE80211_OFDM_RATE_54MB_MASK		(1<<11)
731 
732 #define IEEE80211_CCK_RATES_MASK	        0x0000000F
733 #define IEEE80211_CCK_BASIC_RATES_MASK	(IEEE80211_CCK_RATE_1MB_MASK | \
734 		IEEE80211_CCK_RATE_2MB_MASK)
735 #define IEEE80211_CCK_DEFAULT_RATES_MASK	(IEEE80211_CCK_BASIC_RATES_MASK | \
736 		IEEE80211_CCK_RATE_5MB_MASK | \
737 		IEEE80211_CCK_RATE_11MB_MASK)
738 
739 #define IEEE80211_OFDM_RATES_MASK		0x00000FF0
740 #define IEEE80211_OFDM_BASIC_RATES_MASK	(IEEE80211_OFDM_RATE_6MB_MASK | \
741 		IEEE80211_OFDM_RATE_12MB_MASK | \
742 		IEEE80211_OFDM_RATE_24MB_MASK)
743 #define IEEE80211_OFDM_DEFAULT_RATES_MASK	(IEEE80211_OFDM_BASIC_RATES_MASK | \
744 		IEEE80211_OFDM_RATE_9MB_MASK  | \
745 		IEEE80211_OFDM_RATE_18MB_MASK | \
746 		IEEE80211_OFDM_RATE_36MB_MASK | \
747 		IEEE80211_OFDM_RATE_48MB_MASK | \
748 		IEEE80211_OFDM_RATE_54MB_MASK)
749 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
750 				      IEEE80211_CCK_DEFAULT_RATES_MASK)
751 
752 #define IEEE80211_NUM_OFDM_RATES	    8
753 #define IEEE80211_NUM_CCK_RATES	            4
754 #define IEEE80211_OFDM_SHIFT_MASK_A         4
755 
756 
757 enum MGN_RATE {
758 	MGN_1M		= 0x02,
759 	MGN_2M		= 0x04,
760 	MGN_5_5M	= 0x0B,
761 	MGN_6M		= 0x0C,
762 	MGN_9M		= 0x12,
763 	MGN_11M	= 0x16,
764 	MGN_12M	= 0x18,
765 	MGN_18M	= 0x24,
766 	MGN_24M	= 0x30,
767 	MGN_36M	= 0x48,
768 	MGN_48M	= 0x60,
769 	MGN_54M	= 0x6C,
770 	MGN_MCS32	= 0x7F,
771 	MGN_MCS0,
772 	MGN_MCS1,
773 	MGN_MCS2,
774 	MGN_MCS3,
775 	MGN_MCS4,
776 	MGN_MCS5,
777 	MGN_MCS6,
778 	MGN_MCS7,
779 	MGN_MCS8,
780 	MGN_MCS9,
781 	MGN_MCS10,
782 	MGN_MCS11,
783 	MGN_MCS12,
784 	MGN_MCS13,
785 	MGN_MCS14,
786 	MGN_MCS15,
787 	MGN_MCS16,
788 	MGN_MCS17,
789 	MGN_MCS18,
790 	MGN_MCS19,
791 	MGN_MCS20,
792 	MGN_MCS21,
793 	MGN_MCS22,
794 	MGN_MCS23,
795 	MGN_MCS24,
796 	MGN_MCS25,
797 	MGN_MCS26,
798 	MGN_MCS27,
799 	MGN_MCS28,
800 	MGN_MCS29,
801 	MGN_MCS30,
802 	MGN_MCS31,
803 	MGN_VHT1SS_MCS0,
804 	MGN_VHT1SS_MCS1,
805 	MGN_VHT1SS_MCS2,
806 	MGN_VHT1SS_MCS3,
807 	MGN_VHT1SS_MCS4,
808 	MGN_VHT1SS_MCS5,
809 	MGN_VHT1SS_MCS6,
810 	MGN_VHT1SS_MCS7,
811 	MGN_VHT1SS_MCS8,
812 	MGN_VHT1SS_MCS9,
813 	MGN_VHT2SS_MCS0,
814 	MGN_VHT2SS_MCS1,
815 	MGN_VHT2SS_MCS2,
816 	MGN_VHT2SS_MCS3,
817 	MGN_VHT2SS_MCS4,
818 	MGN_VHT2SS_MCS5,
819 	MGN_VHT2SS_MCS6,
820 	MGN_VHT2SS_MCS7,
821 	MGN_VHT2SS_MCS8,
822 	MGN_VHT2SS_MCS9,
823 	MGN_VHT3SS_MCS0,
824 	MGN_VHT3SS_MCS1,
825 	MGN_VHT3SS_MCS2,
826 	MGN_VHT3SS_MCS3,
827 	MGN_VHT3SS_MCS4,
828 	MGN_VHT3SS_MCS5,
829 	MGN_VHT3SS_MCS6,
830 	MGN_VHT3SS_MCS7,
831 	MGN_VHT3SS_MCS8,
832 	MGN_VHT3SS_MCS9,
833 	MGN_VHT4SS_MCS0,
834 	MGN_VHT4SS_MCS1,
835 	MGN_VHT4SS_MCS2,
836 	MGN_VHT4SS_MCS3,
837 	MGN_VHT4SS_MCS4,
838 	MGN_VHT4SS_MCS5,
839 	MGN_VHT4SS_MCS6,
840 	MGN_VHT4SS_MCS7,
841 	MGN_VHT4SS_MCS8,
842 	MGN_VHT4SS_MCS9,
843 	MGN_UNKNOWN
844 };
845 
846 #define IS_HT_RATE(_rate)	((_rate) >= MGN_MCS0 && (_rate) <= MGN_MCS31)
847 #define IS_VHT_RATE(_rate)	((_rate) >= MGN_VHT1SS_MCS0 && (_rate) <= MGN_VHT4SS_MCS9)
848 #define IS_CCK_RATE(_rate)	((_rate) == MGN_1M || (_rate) == MGN_2M || (_rate) == MGN_5_5M || (_rate) == MGN_11M)
849 #define IS_OFDM_RATE(_rate)	((_rate) >= MGN_6M && (_rate) <= MGN_54M  && (_rate) != MGN_11M)
850 
851 #define IS_HT1SS_RATE(_rate) ((_rate) >= MGN_MCS0 && (_rate) <= MGN_MCS7)
852 #define IS_HT2SS_RATE(_rate) ((_rate) >= MGN_MCS8 && (_rate) <= MGN_MCS15)
853 #define IS_HT3SS_RATE(_rate) ((_rate) >= MGN_MCS16 && (_rate) <= MGN_MCS23)
854 #define IS_HT4SS_RATE(_rate) ((_rate) >= MGN_MCS24 && (_rate) <= MGN_MCS31)
855 
856 #define IS_VHT1SS_RATE(_rate) ((_rate) >= MGN_VHT1SS_MCS0 && (_rate) <= MGN_VHT1SS_MCS9)
857 #define IS_VHT2SS_RATE(_rate) ((_rate) >= MGN_VHT2SS_MCS0 && (_rate) <= MGN_VHT2SS_MCS9)
858 #define IS_VHT3SS_RATE(_rate) ((_rate) >= MGN_VHT3SS_MCS0 && (_rate) <= MGN_VHT3SS_MCS9)
859 #define IS_VHT4SS_RATE(_rate) ((_rate) >= MGN_VHT4SS_MCS0 && (_rate) <= MGN_VHT4SS_MCS9)
860 
861 #define IS_1T_RATE(_rate)	(IS_CCK_RATE((_rate)) || IS_OFDM_RATE((_rate)) || IS_HT1SS_RATE((_rate)) || IS_VHT1SS_RATE((_rate)))
862 #define IS_2T_RATE(_rate)	(IS_HT2SS_RATE((_rate)) || IS_VHT2SS_RATE((_rate)))
863 #define IS_3T_RATE(_rate)	(IS_HT3SS_RATE((_rate)) || IS_VHT3SS_RATE((_rate)))
864 #define IS_4T_RATE(_rate)	(IS_HT4SS_RATE((_rate)) || IS_VHT4SS_RATE((_rate)))
865 
866 typedef enum _RATE_SECTION {
867 	CCK = 0,
868 	OFDM = 1,
869 	HT_MCS0_MCS7 = 2,
870 	HT_MCS8_MCS15 = 3,
871 	HT_MCS16_MCS23 = 4,
872 	HT_MCS24_MCS31 = 5,
873 	HT_1SS = HT_MCS0_MCS7,
874 	HT_2SS = HT_MCS8_MCS15,
875 	HT_3SS = HT_MCS16_MCS23,
876 	HT_4SS = HT_MCS24_MCS31,
877 	VHT_1SSMCS0_1SSMCS9 = 6,
878 	VHT_2SSMCS0_2SSMCS9 = 7,
879 	VHT_3SSMCS0_3SSMCS9 = 8,
880 	VHT_4SSMCS0_4SSMCS9 = 9,
881 	VHT_1SS = VHT_1SSMCS0_1SSMCS9,
882 	VHT_2SS = VHT_2SSMCS0_2SSMCS9,
883 	VHT_3SS = VHT_3SSMCS0_3SSMCS9,
884 	VHT_4SS = VHT_4SSMCS0_4SSMCS9,
885 	RATE_SECTION_NUM,
886 } RATE_SECTION;
887 
888 const char *rate_section_str(u8 section);
889 
890 #define IS_CCK_RATE_SECTION(section) ((section) == CCK)
891 #define IS_OFDM_RATE_SECTION(section) ((section) == OFDM)
892 #define IS_HT_RATE_SECTION(section) ((section) >= HT_1SS && (section) <= HT_4SS)
893 #define IS_VHT_RATE_SECTION(section) ((section) >= VHT_1SS && (section) <= VHT_4SS)
894 
895 #define IS_1T_RATE_SECTION(section) ((section) == CCK || (section) == OFDM || (section) == HT_1SS || (section) == VHT_1SS)
896 #define IS_2T_RATE_SECTION(section) ((section) == HT_2SS || (section) == VHT_2SS)
897 #define IS_3T_RATE_SECTION(section) ((section) == HT_3SS || (section) == VHT_3SS)
898 #define IS_4T_RATE_SECTION(section) ((section) == HT_4SS || (section) == VHT_4SS)
899 
900 extern u8 mgn_rates_cck[];
901 extern u8 mgn_rates_ofdm[];
902 extern u8 mgn_rates_mcs0_7[];
903 extern u8 mgn_rates_mcs8_15[];
904 extern u8 mgn_rates_mcs16_23[];
905 extern u8 mgn_rates_mcs24_31[];
906 extern u8 mgn_rates_vht1ss[];
907 extern u8 mgn_rates_vht2ss[];
908 extern u8 mgn_rates_vht3ss[];
909 extern u8 mgn_rates_vht4ss[];
910 
911 struct rate_section_ent {
912 	u8 tx_num; /* value of RF_TX_NUM */
913 	u8 rate_num;
914 	u8 *rates;
915 };
916 
917 extern struct rate_section_ent rates_by_sections[];
918 
919 #define rate_section_to_tx_num(section) (rates_by_sections[(section)].tx_num)
920 #define rate_section_rate_num(section) (rates_by_sections[(section)].rate_num)
921 
922 /* NOTE: This data is for statistical purposes; not all hardware provides this
923  *       information for frames received.  Not setting these will not cause
924  *       any adverse affects. */
925 struct ieee80211_rx_stats {
926 	/* u32 mac_time[2]; */
927 	s8 rssi;
928 	u8 signal;
929 	u8 noise;
930 	u8 received_channel;
931 	u16 rate; /* in 100 kbps */
932 	/* u8 control; */
933 	u8 mask;
934 	u8 freq;
935 	u16 len;
936 };
937 
938 /* IEEE 802.11 requires that STA supports concurrent reception of at least
939  * three fragmented frames. This define can be increased to support more
940  * concurrent frames, but it should be noted that each entry can consume about
941  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
942 #define IEEE80211_FRAG_CACHE_LEN 4
943 
944 struct ieee80211_frag_entry {
945 	u32 first_frag_time;
946 	uint seq;
947 	uint last_frag;
948 	uint qos;   /* jackson */
949 	uint tid;	/* jackson */
950 	struct sk_buff *skb;
951 	u8 src_addr[ETH_ALEN];
952 	u8 dst_addr[ETH_ALEN];
953 };
954 
955 #ifndef PLATFORM_FREEBSD /* Baron BSD has already defined */
956 struct ieee80211_stats {
957 	uint tx_unicast_frames;
958 	uint tx_multicast_frames;
959 	uint tx_fragments;
960 	uint tx_unicast_octets;
961 	uint tx_multicast_octets;
962 	uint tx_deferred_transmissions;
963 	uint tx_single_retry_frames;
964 	uint tx_multiple_retry_frames;
965 	uint tx_retry_limit_exceeded;
966 	uint tx_discards;
967 	uint rx_unicast_frames;
968 	uint rx_multicast_frames;
969 	uint rx_fragments;
970 	uint rx_unicast_octets;
971 	uint rx_multicast_octets;
972 	uint rx_fcs_errors;
973 	uint rx_discards_no_buffer;
974 	uint tx_discards_wrong_sa;
975 	uint rx_discards_undecryptable;
976 	uint rx_message_in_msg_fragments;
977 	uint rx_message_in_bad_msg_fragments;
978 };
979 #endif /* PLATFORM_FREEBSD */
980 struct ieee80211_softmac_stats {
981 	uint rx_ass_ok;
982 	uint rx_ass_err;
983 	uint rx_probe_rq;
984 	uint tx_probe_rs;
985 	uint tx_beacons;
986 	uint rx_auth_rq;
987 	uint rx_auth_rs_ok;
988 	uint rx_auth_rs_err;
989 	uint tx_auth_rq;
990 	uint no_auth_rs;
991 	uint no_ass_rs;
992 	uint tx_ass_rq;
993 	uint rx_ass_rq;
994 	uint tx_probe_rq;
995 	uint reassoc;
996 	uint swtxstop;
997 	uint swtxawake;
998 };
999 
1000 #define SEC_KEY_1         (1<<0)
1001 #define SEC_KEY_2         (1<<1)
1002 #define SEC_KEY_3         (1<<2)
1003 #define SEC_KEY_4         (1<<3)
1004 #define SEC_ACTIVE_KEY    (1<<4)
1005 #define SEC_AUTH_MODE     (1<<5)
1006 #define SEC_UNICAST_GROUP (1<<6)
1007 #define SEC_LEVEL         (1<<7)
1008 #define SEC_ENABLED       (1<<8)
1009 
1010 #define SEC_LEVEL_0      0 /* None */
1011 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
1012 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
1013 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
1014 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
1015 
1016 #define WEP_KEYS 4
1017 #define WEP_KEY_LEN 13
1018 
1019 #ifdef CONFIG_IEEE80211W
1020 	#define BIP_MAX_KEYID 5
1021 	#define BIP_AAD_SIZE  20
1022 #endif /* CONFIG_IEEE80211W */
1023 
1024 #if defined(PLATFORM_LINUX) || defined(CONFIG_RTL8711FW)
1025 
1026 struct ieee80211_security {
1027 	u16 active_key:2,
1028 	    enabled:1,
1029 	    auth_mode:2,
1030 	    auth_algo:4,
1031 	    unicast_uses_group:1;
1032 	u8 key_sizes[WEP_KEYS];
1033 	u8 keys[WEP_KEYS][WEP_KEY_LEN];
1034 	u8 level;
1035 	u16 flags;
1036 } __attribute__((packed));
1037 
1038 #endif
1039 
1040 #ifdef PLATFORM_WINDOWS
1041 
1042 #pragma pack(1)
1043 struct ieee80211_security {
1044 	u16 active_key:2,
1045 	    enabled:1,
1046 	    auth_mode:2,
1047 	    auth_algo:4,
1048 	    unicast_uses_group:1;
1049 	u8 key_sizes[WEP_KEYS];
1050 	u8 keys[WEP_KEYS][WEP_KEY_LEN];
1051 	u8 level;
1052 	u16 flags;
1053 } ;
1054 #pragma pack()
1055 
1056 #endif
1057 
1058 /*
1059 
1060  802.11 data frame from AP
1061 
1062       ,-------------------------------------------------------------------.
1063 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
1064       |------|------|---------|---------|---------|------|---------|------|
1065 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
1066       |      | tion | (BSSID) |         |         | ence |  data   |      |
1067       `-------------------------------------------------------------------'
1068 
1069 Total: 28-2340 bytes
1070 
1071 */
1072 
1073 struct ieee80211_header_data {
1074 	u16 frame_ctl;
1075 	u16 duration_id;
1076 	u8 addr1[6];
1077 	u8 addr2[6];
1078 	u8 addr3[6];
1079 	u16 seq_ctrl;
1080 };
1081 
1082 #define BEACON_PROBE_SSID_ID_POSITION 12
1083 
1084 /* Management Frame Information Element Types */
1085 #define MFIE_TYPE_SSID       0
1086 #define MFIE_TYPE_RATES      1
1087 #define MFIE_TYPE_FH_SET     2
1088 #define MFIE_TYPE_DS_SET     3
1089 #define MFIE_TYPE_CF_SET     4
1090 #define MFIE_TYPE_TIM        5
1091 #define MFIE_TYPE_IBSS_SET   6
1092 #define MFIE_TYPE_CHALLENGE  16
1093 #define MFIE_TYPE_ERP        42
1094 #define MFIE_TYPE_RSN	     48
1095 #define MFIE_TYPE_RATES_EX   50
1096 #define MFIE_TYPE_GENERIC    221
1097 
1098 #if defined(PLATFORM_LINUX) || defined(CONFIG_RTL8711FW)
1099 
1100 struct ieee80211_info_element_hdr {
1101 	u8 id;
1102 	u8 len;
1103 } __attribute__((packed));
1104 
1105 struct ieee80211_info_element {
1106 	u8 id;
1107 	u8 len;
1108 	u8 data[0];
1109 } __attribute__((packed));
1110 #endif
1111 
1112 #ifdef PLATFORM_WINDOWS
1113 
1114 #pragma pack(1)
1115 struct ieee80211_info_element_hdr {
1116 	u8 id;
1117 	u8 len;
1118 } ;
1119 
1120 struct ieee80211_info_element {
1121 	u8 id;
1122 	u8 len;
1123 	u8 data[0];
1124 } ;
1125 #pragma pack()
1126 
1127 #endif
1128 
1129 
1130 /*
1131  * These are the data types that can make up management packets
1132  *
1133 	u16 auth_algorithm;
1134 	u16 auth_sequence;
1135 	u16 beacon_interval;
1136 	u16 capability;
1137 	u8 current_ap[ETH_ALEN];
1138 	u16 listen_interval;
1139 	struct {
1140 		u16 association_id:14, reserved:2;
1141 	} __attribute__ ((packed));
1142 	u32 time_stamp[2];
1143 	u16 reason;
1144 	u16 status;
1145 */
1146 
1147 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
1148 #define IEEE80211_DEFAULT_BASIC_RATE 10
1149 
1150 
1151 #if defined(PLATFORM_LINUX) || defined(CONFIG_RTL8711FW)
1152 
1153 
1154 struct ieee80211_authentication {
1155 	struct ieee80211_header_data header;
1156 	u16 algorithm;
1157 	u16 transaction;
1158 	u16 status;
1159 	/* struct ieee80211_info_element_hdr info_element; */
1160 } __attribute__((packed));
1161 
1162 
1163 struct ieee80211_probe_response {
1164 	struct ieee80211_header_data header;
1165 	u32 time_stamp[2];
1166 	u16 beacon_interval;
1167 	u16 capability;
1168 	struct ieee80211_info_element info_element;
1169 } __attribute__((packed));
1170 
1171 struct ieee80211_probe_request {
1172 	struct ieee80211_header_data header;
1173 	/*struct ieee80211_info_element info_element;*/
1174 } __attribute__((packed));
1175 
1176 struct ieee80211_assoc_request_frame {
1177 	struct rtw_ieee80211_hdr_3addr header;
1178 	u16 capability;
1179 	u16 listen_interval;
1180 	/* u8 current_ap[ETH_ALEN]; */
1181 	struct ieee80211_info_element_hdr info_element;
1182 } __attribute__((packed));
1183 
1184 struct ieee80211_assoc_response_frame {
1185 	struct rtw_ieee80211_hdr_3addr header;
1186 	u16 capability;
1187 	u16 status;
1188 	u16 aid;
1189 	/*	struct ieee80211_info_element info_element;  supported rates  */
1190 } __attribute__((packed));
1191 #endif
1192 
1193 
1194 
1195 #ifdef PLATFORM_WINDOWS
1196 
1197 #pragma pack(1)
1198 
1199 struct ieee80211_authentication {
1200 	struct ieee80211_header_data header;
1201 	u16 algorithm;
1202 	u16 transaction;
1203 	u16 status;
1204 	/* struct ieee80211_info_element_hdr info_element; */
1205 } ;
1206 
1207 
1208 struct ieee80211_probe_response {
1209 	struct ieee80211_header_data header;
1210 	u32 time_stamp[2];
1211 	u16 beacon_interval;
1212 	u16 capability;
1213 	struct ieee80211_info_element info_element;
1214 } ;
1215 
1216 struct ieee80211_probe_request {
1217 	struct ieee80211_header_data header;
1218 	/*struct ieee80211_info_element info_element;*/
1219 } ;
1220 
1221 struct ieee80211_assoc_request_frame {
1222 	struct rtw_ieee80211_hdr_3addr header;
1223 	u16 capability;
1224 	u16 listen_interval;
1225 	/* u8 current_ap[ETH_ALEN]; */
1226 	struct ieee80211_info_element_hdr info_element;
1227 } ;
1228 
1229 struct ieee80211_assoc_response_frame {
1230 	struct rtw_ieee80211_hdr_3addr header;
1231 	u16 capability;
1232 	u16 status;
1233 	u16 aid;
1234 	/*	struct ieee80211_info_element info_element;  supported rates  */
1235 };
1236 
1237 #pragma pack()
1238 
1239 #endif
1240 
1241 
1242 
1243 
1244 struct ieee80211_txb {
1245 	u8 nr_frags;
1246 	u8 encrypted;
1247 	u16 reserved;
1248 	u16 frag_size;
1249 	u16 payload_size;
1250 	struct sk_buff *fragments[0];
1251 };
1252 
1253 
1254 /* SWEEP TABLE ENTRIES NUMBER*/
1255 #define MAX_SWEEP_TAB_ENTRIES		  42
1256 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
1257 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
1258  * only use 8, and then use extended rates for the remaining supported
1259  * rates.  Other APs, however, stick all of their supported rates on the
1260  * main rates information element... */
1261 #define MAX_RATES_LENGTH                  ((u8)12)
1262 #define MAX_RATES_EX_LENGTH               ((u8)16)
1263 #define MAX_NETWORK_COUNT                  128
1264 #define MAX_CHANNEL_NUMBER                 161
1265 #define IEEE80211_SOFTMAC_SCAN_TIME	  400
1266 /* (HZ / 2) */
1267 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
1268 
1269 #define CRC_LENGTH                 4U
1270 
1271 #define MAX_WPA_IE_LEN (256)
1272 #define MAX_WPS_IE_LEN (512)
1273 #define MAX_P2P_IE_LEN (256)
1274 #define MAX_WFD_IE_LEN (128)
1275 
1276 #define NETWORK_EMPTY_ESSID (1<<0)
1277 #define NETWORK_HAS_OFDM    (1<<1)
1278 #define NETWORK_HAS_CCK     (1<<2)
1279 
1280 #define IEEE80211_DTIM_MBCAST 4
1281 #define IEEE80211_DTIM_UCAST 2
1282 #define IEEE80211_DTIM_VALID 1
1283 #define IEEE80211_DTIM_INVALID 0
1284 
1285 #define IEEE80211_PS_DISABLED 0
1286 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
1287 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
1288 #define IW_ESSID_MAX_SIZE 32
1289 #if 0
1290 struct ieee80211_network {
1291 	/* These entries are used to identify a unique network */
1292 	u8 bssid[ETH_ALEN];
1293 	u8 channel;
1294 	/* Ensure null-terminated for any debug msgs */
1295 	u8 ssid[IW_ESSID_MAX_SIZE + 1];
1296 	u8 ssid_len;
1297 	u8	rssi;	/* relative signal strength */
1298 	u8	sq;		/* signal quality */
1299 
1300 	/* These are network statistics */
1301 	/* struct ieee80211_rx_stats stats; */
1302 	u16 capability;
1303 	u16	aid;
1304 	u8 rates[MAX_RATES_LENGTH];
1305 	u8 rates_len;
1306 	u8 rates_ex[MAX_RATES_EX_LENGTH];
1307 	u8 rates_ex_len;
1308 
1309 	u8 edca_parmsets[18];
1310 
1311 	u8 mode;
1312 	u8 flags;
1313 	u8 time_stamp[8];
1314 	u16 beacon_interval;
1315 	u16 listen_interval;
1316 	u16 atim_window;
1317 	u8 wpa_ie[MAX_WPA_IE_LEN];
1318 	size_t wpa_ie_len;
1319 	u8 rsn_ie[MAX_WPA_IE_LEN];
1320 	size_t rsn_ie_len;
1321 	u8 country[6];
1322 	u8 dtim_period;
1323 	u8 dtim_data;
1324 	u8 power_constraint;
1325 	u8 qosinfo;
1326 	u8 qbssload[5];
1327 	u8 network_type;
1328 	int join_res;
1329 	unsigned long	last_scanned;
1330 };
1331 #endif
1332 /*
1333 join_res:
1334 -1: authentication fail
1335 -2: association fail
1336 > 0: TID
1337 */
1338 
1339 #ifndef PLATFORM_FREEBSD /* Baron BSD has already defined */
1340 
1341 enum ieee80211_state {
1342 
1343 	/* the card is not linked at all */
1344 	IEEE80211_NOLINK = 0,
1345 
1346 	/* IEEE80211_ASSOCIATING* are for BSS client mode
1347 	 * the driver shall not perform RX filtering unless
1348 	 * the state is LINKED.
1349 	 * The driver shall just check for the state LINKED and
1350 	 * defaults to NOLINK for ALL the other states (including
1351 	 * LINKED_SCANNING)
1352 	 */
1353 
1354 	/* the association procedure will start (wq scheduling)*/
1355 	IEEE80211_ASSOCIATING,
1356 	IEEE80211_ASSOCIATING_RETRY,
1357 
1358 	/* the association procedure is sending AUTH request*/
1359 	IEEE80211_ASSOCIATING_AUTHENTICATING,
1360 
1361 	/* the association procedure has successfully authentcated
1362 	 * and is sending association request
1363 	 */
1364 	IEEE80211_ASSOCIATING_AUTHENTICATED,
1365 
1366 	/* the link is ok. the card associated to a BSS or linked
1367 	 * to a ibss cell or acting as an AP and creating the bss
1368 	 */
1369 	IEEE80211_LINKED,
1370 
1371 	/* same as LINKED, but the driver shall apply RX filter
1372 	 * rules as we are in NO_LINK mode. As the card is still
1373 	 * logically linked, but it is doing a syncro site survey
1374 	 * then it will be back to LINKED state.
1375 	 */
1376 	IEEE80211_LINKED_SCANNING,
1377 
1378 };
1379 #endif /* PLATFORM_FREEBSD */
1380 
1381 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1382 #define DEFAULT_FTS 2346
1383 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
1384 #define MAC_ARG(x) ((u8 *)(x))[0], ((u8 *)(x))[1], ((u8 *)(x))[2], ((u8 *)(x))[3], ((u8 *)(x))[4], ((u8 *)(x))[5]
1385 #define IP_FMT "%d.%d.%d.%d"
1386 #define IP_ARG(x) ((u8 *)(x))[0], ((u8 *)(x))[1], ((u8 *)(x))[2], ((u8 *)(x))[3]
1387 #define PORT_FMT "%u"
1388 #define PORT_ARG(x) ntohs(*((u16 *)(x)))
1389 
1390 #ifdef PLATFORM_FREEBSD /* Baron change func to macro */
1391 #define is_multicast_mac_addr(Addr) ((((Addr[0]) & 0x01) == 0x01) && ((Addr[0]) != 0xff))
1392 #define is_broadcast_mac_addr(Addr) ((((Addr[0]) & 0xff) == 0xff) && (((Addr[1]) & 0xff) == 0xff) && \
1393 	(((Addr[2]) & 0xff) == 0xff) && (((Addr[3]) & 0xff) == 0xff) && (((Addr[4]) & 0xff) == 0xff) && \
1394 				     (((Addr[5]) & 0xff) == 0xff))
1395 #else
is_multicast_mac_addr(const u8 * addr)1396 extern __inline int is_multicast_mac_addr(const u8 *addr)
1397 {
1398 	return (addr[0] != 0xff) && (0x01 & addr[0]);
1399 }
1400 
is_broadcast_mac_addr(const u8 * addr)1401 extern __inline int is_broadcast_mac_addr(const u8 *addr)
1402 {
1403 	return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&   \
1404 		(addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
1405 }
1406 
is_zero_mac_addr(const u8 * addr)1407 extern __inline int is_zero_mac_addr(const u8 *addr)
1408 {
1409 	return ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) &&   \
1410 		(addr[3] == 0x00) && (addr[4] == 0x00) && (addr[5] == 0x00));
1411 }
1412 #endif /* PLATFORM_FREEBSD */
1413 
1414 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
1415 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
1416 
1417 typedef struct tx_pending_t {
1418 	int frag;
1419 	struct ieee80211_txb *txb;
1420 } tx_pending_t;
1421 
1422 
1423 
1424 #define TID_NUM	16
1425 
1426 #define IEEE_A            (1<<0)
1427 #define IEEE_B            (1<<1)
1428 #define IEEE_G            (1<<2)
1429 #define IEEE_MODE_MASK    (IEEE_A | IEEE_B | IEEE_G)
1430 
1431 /* Baron move to ieee80211.c */
1432 int ieee80211_is_empty_essid(const char *essid, int essid_len);
1433 int ieee80211_get_hdrlen(u16 fc);
1434 
1435 #if 0
1436 	/* Action frame categories (IEEE 802.11-2007, 7.3.1.11, Table 7-24) */
1437 	#define WLAN_ACTION_SPECTRUM_MGMT 0
1438 	#define WLAN_ACTION_QOS 1
1439 	#define WLAN_ACTION_DLS 2
1440 	#define WLAN_ACTION_BLOCK_ACK 3
1441 	#define WLAN_ACTION_RADIO_MEASUREMENT 5
1442 	#define WLAN_ACTION_FT 6
1443 	#define WLAN_ACTION_SA_QUERY 8
1444 	#define WLAN_ACTION_WMM 17
1445 #endif
1446 
1447 
1448 /* Action category code */
1449 enum rtw_ieee80211_category {
1450 	RTW_WLAN_CATEGORY_SPECTRUM_MGMT = 0,
1451 	RTW_WLAN_CATEGORY_QOS = 1,
1452 	RTW_WLAN_CATEGORY_DLS = 2,
1453 	RTW_WLAN_CATEGORY_BACK = 3,
1454 	RTW_WLAN_CATEGORY_PUBLIC = 4, /* IEEE 802.11 public action frames */
1455 	RTW_WLAN_CATEGORY_RADIO_MEASUREMENT  = 5,
1456 	RTW_WLAN_CATEGORY_FT = 6,
1457 	RTW_WLAN_CATEGORY_HT = 7,
1458 	RTW_WLAN_CATEGORY_SA_QUERY = 8,
1459 	RTW_WLAN_CATEGORY_UNPROTECTED_WNM = 11, /* add for CONFIG_IEEE80211W, none 11w also can use */
1460 	RTW_WLAN_CATEGORY_TDLS = 12,
1461 	RTW_WLAN_CATEGORY_SELF_PROTECTED = 15, /* add for CONFIG_IEEE80211W, none 11w also can use */
1462 	RTW_WLAN_CATEGORY_WMM = 17,
1463 	RTW_WLAN_CATEGORY_VHT = 21,
1464 	RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */
1465 };
1466 
1467 /* SPECTRUM_MGMT action code */
1468 enum rtw_ieee80211_spectrum_mgmt_actioncode {
1469 	RTW_WLAN_ACTION_SPCT_MSR_REQ = 0,
1470 	RTW_WLAN_ACTION_SPCT_MSR_RPRT = 1,
1471 	RTW_WLAN_ACTION_SPCT_TPC_REQ = 2,
1472 	RTW_WLAN_ACTION_SPCT_TPC_RPRT = 3,
1473 	RTW_WLAN_ACTION_SPCT_CHL_SWITCH = 4,
1474 	RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5,
1475 };
1476 
1477 enum _PUBLIC_ACTION {
1478 	ACT_PUBLIC_BSSCOEXIST = 0, /* 20/40 BSS Coexistence */
1479 	ACT_PUBLIC_DSE_ENABLE = 1,
1480 	ACT_PUBLIC_DSE_DEENABLE = 2,
1481 	ACT_PUBLIC_DSE_REG_LOCATION = 3,
1482 	ACT_PUBLIC_EXT_CHL_SWITCH = 4,
1483 	ACT_PUBLIC_DSE_MSR_REQ = 5,
1484 	ACT_PUBLIC_DSE_MSR_RPRT = 6,
1485 	ACT_PUBLIC_MP = 7, /* Measurement Pilot */
1486 	ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8,
1487 	ACT_PUBLIC_VENDOR = 9, /* for WIFI_DIRECT */
1488 	ACT_PUBLIC_GAS_INITIAL_REQ = 10,
1489 	ACT_PUBLIC_GAS_INITIAL_RSP = 11,
1490 	ACT_PUBLIC_GAS_COMEBACK_REQ = 12,
1491 	ACT_PUBLIC_GAS_COMEBACK_RSP = 13,
1492 	ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14,
1493 	ACT_PUBLIC_LOCATION_TRACK = 15,
1494 	ACT_PUBLIC_MAX
1495 };
1496 
1497 #ifdef CONFIG_TDLS
1498 enum TDLS_ACTION_FIELD {
1499 	TDLS_SETUP_REQUEST = 0,
1500 	TDLS_SETUP_RESPONSE = 1,
1501 	TDLS_SETUP_CONFIRM = 2,
1502 	TDLS_TEARDOWN = 3,
1503 	TDLS_PEER_TRAFFIC_INDICATION = 4,
1504 	TDLS_CHANNEL_SWITCH_REQUEST = 5,
1505 	TDLS_CHANNEL_SWITCH_RESPONSE = 6,
1506 	TDLS_PEER_PSM_REQUEST = 7,
1507 	TDLS_PEER_PSM_RESPONSE = 8,
1508 	TDLS_PEER_TRAFFIC_RESPONSE = 9,
1509 	TDLS_DISCOVERY_REQUEST = 10,
1510 	TDLS_DISCOVERY_RESPONSE = 14,	/* it's used in public action frame */
1511 };
1512 
1513 #define	TUNNELED_PROBE_REQ	15
1514 #define	TUNNELED_PROBE_RSP	16
1515 #endif /* CONFIG_TDLS */
1516 
1517 /* BACK action code */
1518 enum rtw_ieee80211_back_actioncode {
1519 	RTW_WLAN_ACTION_ADDBA_REQ = 0,
1520 	RTW_WLAN_ACTION_ADDBA_RESP = 1,
1521 	RTW_WLAN_ACTION_DELBA = 2,
1522 };
1523 
1524 /* HT features action code */
1525 enum rtw_ieee80211_ht_actioncode {
1526 	RTW_WLAN_ACTION_HT_NOTI_CHNL_WIDTH = 0,
1527 	RTW_WLAN_ACTION_HT_SM_PS = 1,
1528 	RTW_WLAN_ACTION_HT_PSMP = 2,
1529 	RTW_WLAN_ACTION_HT_SET_PCO_PHASE = 3,
1530 	RTW_WLAN_ACTION_HT_CSI = 4,
1531 	RTW_WLAN_ACTION_HT_NON_COMPRESS_BEAMFORMING = 5,
1532 	RTW_WLAN_ACTION_HT_COMPRESS_BEAMFORMING = 6,
1533 	RTW_WLAN_ACTION_HT_ASEL_FEEDBACK = 7,
1534 };
1535 
1536 /* BACK (block-ack) parties */
1537 enum rtw_ieee80211_back_parties {
1538 	RTW_WLAN_BACK_RECIPIENT = 0,
1539 	RTW_WLAN_BACK_INITIATOR = 1,
1540 	RTW_WLAN_BACK_TIMER = 2,
1541 };
1542 
1543 /*20/40 BSS Coexistence element */
1544 #define RTW_WLAN_20_40_BSS_COEX_INFO_REQ            BIT(0)
1545 #define RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL         BIT(1)
1546 #define RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ     BIT(2)
1547 #define RTW_WLAN_20_40_BSS_COEX_OBSS_EXEMPT_REQ     BIT(3)
1548 #define RTW_WLAN_20_40_BSS_COEX_OBSS_EXEMPT_GRNT    BIT(4)
1549 
1550 /* VHT features action code */
1551 enum rtw_ieee80211_vht_actioncode {
1552 	RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING = 0,
1553 	RTW_WLAN_ACTION_VHT_GROUPID_MANAGEMENT = 1,
1554 	RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION = 2,
1555 };
1556 
1557 
1558 #define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
1559 				* 00:50:F2 */
1560 #ifndef PLATFORM_FREEBSD /* Baron BSD has defined */
1561 	#define WME_OUI_TYPE 2
1562 #endif /* PLATFORM_FREEBSD */
1563 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
1564 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
1565 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
1566 #define WME_VERSION 1
1567 
1568 #define WME_ACTION_CODE_SETUP_REQUEST 0
1569 #define WME_ACTION_CODE_SETUP_RESPONSE 1
1570 #define WME_ACTION_CODE_TEARDOWN 2
1571 
1572 #define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0
1573 #define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1
1574 #define WME_SETUP_RESPONSE_STATUS_REFUSED 3
1575 
1576 #define WME_TSPEC_DIRECTION_UPLINK 0
1577 #define WME_TSPEC_DIRECTION_DOWNLINK 1
1578 #define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3
1579 
1580 
1581 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
1582 
1583 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
1584 
1585 /**
1586  * enum rtw_ieee80211_channel_flags - channel flags
1587  *
1588  * Channel flags set by the regulatory control code.
1589  *
1590  * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled.
1591  * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
1592  *      on this channel.
1593  * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
1594  * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
1595  * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
1596  *      is not permitted.
1597  * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
1598  *      is not permitted.
1599  */
1600 enum rtw_ieee80211_channel_flags {
1601 	RTW_IEEE80211_CHAN_DISABLED         = 1 << 0,
1602 	RTW_IEEE80211_CHAN_PASSIVE_SCAN     = 1 << 1,
1603 	RTW_IEEE80211_CHAN_NO_IBSS          = 1 << 2,
1604 	RTW_IEEE80211_CHAN_RADAR            = 1 << 3,
1605 	RTW_IEEE80211_CHAN_NO_HT40PLUS      = 1 << 4,
1606 	RTW_IEEE80211_CHAN_NO_HT40MINUS     = 1 << 5,
1607 };
1608 
1609 #define RTW_IEEE80211_CHAN_NO_HT40 \
1610 	(RTW_IEEE80211_CHAN_NO_HT40PLUS | RTW_IEEE80211_CHAN_NO_HT40MINUS)
1611 
1612 /* Represent channel details, subset of ieee80211_channel */
1613 struct rtw_ieee80211_channel {
1614 	/* enum ieee80211_band band; */
1615 	/* u16 center_freq; */
1616 	u16 hw_value;
1617 	u32 flags;
1618 	/* int max_antenna_gain; */
1619 	/* int max_power; */
1620 	/* int max_reg_power; */
1621 	/* bool beacon_found; */
1622 	/* u32 orig_flags; */
1623 	/* int orig_mag; */
1624 	/* int orig_mpwr; */
1625 };
1626 
1627 #define CHAN_FMT \
1628 	/*"band:%d, "*/ \
1629 	/*"center_freq:%u, "*/ \
1630 	"hw_value:%u, " \
1631 	"flags:0x%08x" \
1632 	/*"max_antenna_gain:%d\n"*/ \
1633 	/*"max_power:%d\n"*/ \
1634 	/*"max_reg_power:%d\n"*/ \
1635 	/*"beacon_found:%u\n"*/ \
1636 	/*"orig_flags:0x%08x\n"*/ \
1637 	/*"orig_mag:%d\n"*/ \
1638 	/*"orig_mpwr:%d\n"*/
1639 
1640 #define CHAN_ARG(channel) \
1641 	/*(channel)->band*/ \
1642 	/*, (channel)->center_freq*/ \
1643 	(channel)->hw_value \
1644 	, (channel)->flags \
1645 	/*, (channel)->max_antenna_gain*/ \
1646 	/*, (channel)->max_power*/ \
1647 	/*, (channel)->max_reg_power*/ \
1648 	/*, (channel)->beacon_found*/ \
1649 	/*, (channel)->orig_flags*/ \
1650 	/*, (channel)->orig_mag*/ \
1651 	/*, (channel)->orig_mpwr*/ \
1652 
1653 	/* Parsed Information Elements */
1654 	struct rtw_ieee802_11_elems {
1655 		u8 *ssid;
1656 		u8 ssid_len;
1657 		u8 *supp_rates;
1658 		u8 supp_rates_len;
1659 		u8 *fh_params;
1660 		u8 fh_params_len;
1661 		u8 *ds_params;
1662 		u8 ds_params_len;
1663 		u8 *cf_params;
1664 		u8 cf_params_len;
1665 		u8 *tim;
1666 		u8 tim_len;
1667 		u8 *ibss_params;
1668 		u8 ibss_params_len;
1669 		u8 *challenge;
1670 		u8 challenge_len;
1671 		u8 *erp_info;
1672 		u8 erp_info_len;
1673 		u8 *ext_supp_rates;
1674 		u8 ext_supp_rates_len;
1675 		u8 *wpa_ie;
1676 		u8 wpa_ie_len;
1677 		u8 *rsn_ie;
1678 		u8 rsn_ie_len;
1679 		u8 *wme;
1680 		u8 wme_len;
1681 		u8 *wme_tspec;
1682 		u8 wme_tspec_len;
1683 		u8 *wps_ie;
1684 		u8 wps_ie_len;
1685 		u8 *power_cap;
1686 		u8 power_cap_len;
1687 		u8 *supp_channels;
1688 		u8 supp_channels_len;
1689 		u8 *mdie;
1690 		u8 mdie_len;
1691 		u8 *ftie;
1692 		u8 ftie_len;
1693 		u8 *timeout_int;
1694 		u8 timeout_int_len;
1695 		u8 *ht_capabilities;
1696 		u8 ht_capabilities_len;
1697 		u8 *ht_operation;
1698 		u8 ht_operation_len;
1699 		u8 *vendor_ht_cap;
1700 		u8 vendor_ht_cap_len;
1701 		u8 *vht_capabilities;
1702 		u8 vht_capabilities_len;
1703 		u8 *vht_operation;
1704 		u8 vht_operation_len;
1705 		u8 *vht_op_mode_notify;
1706 		u8 vht_op_mode_notify_len;
1707 	};
1708 
1709 	typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
1710 
1711 	ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,
1712 					    struct rtw_ieee802_11_elems *elems,
1713 					    int show_errors);
1714 
1715 	u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source, unsigned int *frlen);
1716 	u8 *rtw_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen);
1717 
1718 	enum secondary_ch_offset {
1719 		SCN = 0, /* no secondary channel */
1720 		SCA = 1, /* secondary channel above */
1721 		SCB = 3,  /* secondary channel below */
1722 	};
1723 	u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset);
1724 	u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset);
1725 	u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode, u8 new_ch, u8 ch_switch_cnt);
1726 	u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset);
1727 	u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl, u8 flags, u16 reason, u16 precedence);
1728 
1729 	u8 *rtw_get_ie(u8 *pbuf, sint index, sint *len, sint limit);
1730 	u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen);
1731 	int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len);
1732 
1733 	void rtw_set_supported_rate(u8 *SupportedRates, uint mode) ;
1734 
1735 	unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit);
1736 	unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit);
1737 	int rtw_get_wpa_cipher_suite(u8 *s);
1738 	int rtw_get_wpa2_cipher_suite(u8 *s);
1739 	int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
1740 	int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
1741 	int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
1742 
1743 	int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len);
1744 
1745 	u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
1746 	u8 *rtw_get_wps_ie_from_scan_queue(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen, u8 frame_type);
1747 	u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
1748 	u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_attr, u32 *len_attr);
1749 	u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_content, uint *len_content);
1750 
1751 	/**
1752 	 * for_each_ie - iterate over continuous IEs
1753 	 * @ie:
1754 	 * @buf:
1755 	 * @buf_len:
1756 	 */
1757 #define for_each_ie(ie, buf, buf_len) \
1758 	for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len; ie = (void *)(((u8 *)ie) + *(((u8 *)ie)+1) + 2))
1759 
1760 	void dump_ies(void *sel, u8 *buf, u32 buf_len);
1761 
1762 #ifdef CONFIG_80211N_HT
1763 	void dump_ht_cap_ie_content(void *sel, u8 *buf, u32 buf_len);
1764 #endif
1765 
1766 	void dump_wps_ie(void *sel, u8 *ie, u32 ie_len);
1767 
1768 	void rtw_ies_get_chbw(u8 *ies, int ies_len, u8 *ch, u8 *bw, u8 *offset);
1769 
1770 	void rtw_bss_get_chbw(WLAN_BSSID_EX *bss, u8 *ch, u8 *bw, u8 *offset);
1771 
1772 	bool rtw_is_chbw_grouped(u8 ch_a, u8 bw_a, u8 offset_a
1773 				 , u8 ch_b, u8 bw_b, u8 offset_b);
1774 	void rtw_sync_chbw(u8 *req_ch, u8 *req_bw, u8 *req_offset
1775 			   , u8 *g_ch, u8 *g_bw, u8 *g_offset);
1776 
1777 	u32 rtw_get_p2p_merged_ies_len(u8 *in_ie, u32 in_len);
1778 	int rtw_p2p_merge_ies(u8 *in_ie, u32 in_len, u8 *merge_ie);
1779 	void dump_p2p_ie(void *sel, u8 *ie, u32 ie_len);
1780 	u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen);
1781 	u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_attr, u32 *len_attr);
1782 	u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_content, uint *len_content);
1783 	u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr);
1784 	uint rtw_del_p2p_ie(u8 *ies, uint ies_len_ori, const char *msg);
1785 	uint rtw_del_p2p_attr(u8 *ie, uint ielen_ori, u8 attr_id);
1786 	u8 *rtw_bss_ex_get_p2p_ie(WLAN_BSSID_EX *bss_ex, u8 *p2p_ie, uint *p2p_ielen);
1787 	void rtw_bss_ex_del_p2p_ie(WLAN_BSSID_EX *bss_ex);
1788 	void rtw_bss_ex_del_p2p_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id);
1789 
1790 	void dump_wfd_ie(void *sel, u8 *ie, u32 ie_len);
1791 	u8 *rtw_get_wfd_ie(u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen);
1792 	u8 *rtw_get_wfd_attr(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr);
1793 	u8 *rtw_get_wfd_attr_content(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content);
1794 	uint rtw_del_wfd_ie(u8 *ies, uint ies_len_ori, const char *msg);
1795 	uint rtw_del_wfd_attr(u8 *ie, uint ielen_ori, u8 attr_id);
1796 	u8 *rtw_bss_ex_get_wfd_ie(WLAN_BSSID_EX *bss_ex, u8 *wfd_ie, uint *wfd_ielen);
1797 	void rtw_bss_ex_del_wfd_ie(WLAN_BSSID_EX *bss_ex);
1798 	void rtw_bss_ex_del_wfd_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id);
1799 
1800 	uint	rtw_get_rateset_len(u8	*rateset);
1801 
1802 	struct registry_priv;
1803 	int rtw_generate_ie(struct registry_priv *pregistrypriv);
1804 
1805 	int rtw_get_bit_value_from_ieee_value(u8 val);
1806 
1807 	uint	rtw_is_cckrates_included(u8 *rate);
1808 
1809 	uint	rtw_is_cckratesonly_included(u8 *rate);
1810 
1811 	int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
1812 
1813 	void rtw_get_bcn_info(struct wlan_network *pnetwork);
1814 
1815 	u8 rtw_check_invalid_mac_address(u8 *mac_addr, u8 check_local_bit);
1816 	void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr);
1817 
1818 	u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate);
1819 	u8	rtw_ht_mcsset_to_nss(u8 *supp_mcs_set);
1820 
1821 	int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action);
1822 	const char *action_public_str(u8 action);
1823 
1824 	u8 key_2char2num(u8 hch, u8 lch);
1825 	u8 str_2char2num(u8 hch, u8 lch);
1826 	void macstr2num(u8 *dst, u8 *src);
1827 	u8 convert_ip_addr(u8 hch, u8 mch, u8 lch);
1828 	int wifirate2_ratetbl_inx(unsigned char rate);
1829 
1830 #endif /* IEEE80211_H */
1831