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