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