OSDN Git Service

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