staging: r8188eu: Convert header copyright info to SPDX format, part 2
[linux-2.6-microblaze.git] / drivers / staging / r8188eu / include / ieee80211.h
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #ifndef __IEEE80211_H
5 #define __IEEE80211_H
6
7 #include <osdep_service.h>
8 #include <drv_types.h>
9 #include "wifi.h"
10 #include <linux/wireless.h>
11
12 #define MGMT_QUEUE_NUM 5
13
14 #define ETH_ALEN        6
15 #define ETH_TYPE_LEN            2
16 #define PAYLOAD_TYPE_LEN        1
17
18 #ifdef CONFIG_88EU_AP_MODE
19
20 #define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
21
22 /* RTL871X_IOCTL_HOSTAPD ioctl() cmd: */
23 enum {
24         RTL871X_HOSTAPD_FLUSH = 1,
25         RTL871X_HOSTAPD_ADD_STA = 2,
26         RTL871X_HOSTAPD_REMOVE_STA = 3,
27         RTL871X_HOSTAPD_GET_INFO_STA = 4,
28         /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
29         RTL871X_HOSTAPD_GET_WPAIE_STA = 5,
30         RTL871X_SET_ENCRYPTION = 6,
31         RTL871X_GET_ENCRYPTION = 7,
32         RTL871X_HOSTAPD_SET_FLAGS_STA = 8,
33         RTL871X_HOSTAPD_GET_RID = 9,
34         RTL871X_HOSTAPD_SET_RID = 10,
35         RTL871X_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
36         RTL871X_HOSTAPD_SET_GENERIC_ELEMENT = 12,
37         RTL871X_HOSTAPD_MLME = 13,
38         RTL871X_HOSTAPD_SCAN_REQ = 14,
39         RTL871X_HOSTAPD_STA_CLEAR_STATS = 15,
40         RTL871X_HOSTAPD_SET_BEACON = 16,
41         RTL871X_HOSTAPD_SET_WPS_BEACON = 17,
42         RTL871X_HOSTAPD_SET_WPS_PROBE_RESP = 18,
43         RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP = 19,
44         RTL871X_HOSTAPD_SET_HIDDEN_SSID = 20,
45         RTL871X_HOSTAPD_SET_MACADDR_ACL = 21,
46         RTL871X_HOSTAPD_ACL_ADD_STA = 22,
47         RTL871X_HOSTAPD_ACL_REMOVE_STA = 23,
48 };
49
50 /* STA flags */
51 #define WLAN_STA_AUTH BIT(0)
52 #define WLAN_STA_ASSOC BIT(1)
53 #define WLAN_STA_PS BIT(2)
54 #define WLAN_STA_TIM BIT(3)
55 #define WLAN_STA_PERM BIT(4)
56 #define WLAN_STA_AUTHORIZED BIT(5)
57 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
58 #define WLAN_STA_SHORT_PREAMBLE BIT(7)
59 #define WLAN_STA_PREAUTH BIT(8)
60 #define WLAN_STA_WME BIT(9)
61 #define WLAN_STA_MFP BIT(10)
62 #define WLAN_STA_HT BIT(11)
63 #define WLAN_STA_WPS BIT(12)
64 #define WLAN_STA_MAYBE_WPS BIT(13)
65 #define WLAN_STA_NONERP BIT(31)
66
67 #endif
68
69 #define IEEE_CMD_SET_WPA_PARAM                  1
70 #define IEEE_CMD_SET_WPA_IE                             2
71 #define IEEE_CMD_SET_ENCRYPTION                 3
72 #define IEEE_CMD_MLME                                           4
73
74 #define IEEE_PARAM_WPA_ENABLED                          1
75 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
76 #define IEEE_PARAM_DROP_UNENCRYPTED                     3
77 #define IEEE_PARAM_PRIVACY_INVOKED                      4
78 #define IEEE_PARAM_AUTH_ALGS                                    5
79 #define IEEE_PARAM_IEEE_802_1X                          6
80 #define IEEE_PARAM_WPAX_SELECT                          7
81
82 #define AUTH_ALG_OPEN_SYSTEM                    0x1
83 #define AUTH_ALG_SHARED_KEY                     0x2
84 #define AUTH_ALG_LEAP                           0x00000004
85
86 #define IEEE_MLME_STA_DEAUTH                            1
87 #define IEEE_MLME_STA_DISASSOC                  2
88
89 #define IEEE_CRYPT_ERR_UNKNOWN_ALG                      2
90 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR                     3
91 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED                4
92 #define IEEE_CRYPT_ERR_KEY_SET_FAILED                   5
93 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED                6
94 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
95
96 #define IEEE_CRYPT_ALG_NAME_LEN                 16
97
98 #define WPA_CIPHER_NONE         BIT(0)
99 #define WPA_CIPHER_WEP40        BIT(1)
100 #define WPA_CIPHER_WEP104 BIT(2)
101 #define WPA_CIPHER_TKIP         BIT(3)
102 #define WPA_CIPHER_CCMP         BIT(4)
103
104
105 #define WPA_SELECTOR_LEN 4
106 extern u8 RTW_WPA_OUI_TYPE[];
107 extern u16 RTW_WPA_VERSION;
108 extern u8 WPA_AUTH_KEY_MGMT_NONE[];
109 extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[];
110 extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
111 extern u8 WPA_CIPHER_SUITE_NONE[];
112 extern u8 WPA_CIPHER_SUITE_WEP40[];
113 extern u8 WPA_CIPHER_SUITE_TKIP[];
114 extern u8 WPA_CIPHER_SUITE_WRAP[];
115 extern u8 WPA_CIPHER_SUITE_CCMP[];
116 extern u8 WPA_CIPHER_SUITE_WEP104[];
117
118 #define RSN_HEADER_LEN 4
119 #define RSN_SELECTOR_LEN 4
120
121 extern u16 RSN_VERSION_BSD;
122 extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[];
123 extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
124 extern u8 RSN_CIPHER_SUITE_NONE[];
125 extern u8 RSN_CIPHER_SUITE_WEP40[];
126 extern u8 RSN_CIPHER_SUITE_TKIP[];
127 extern u8 RSN_CIPHER_SUITE_WRAP[];
128 extern u8 RSN_CIPHER_SUITE_CCMP[];
129 extern u8 RSN_CIPHER_SUITE_WEP104[];
130
131 enum ratr_table_mode {
132         RATR_INX_WIRELESS_NGB = 0,      /*  BGN 40 Mhz 2SS 1SS */
133         RATR_INX_WIRELESS_NG = 1,       /*  GN or N */
134         RATR_INX_WIRELESS_NB = 2,       /*  BGN 20 Mhz 2SS 1SS  or BN */
135         RATR_INX_WIRELESS_N = 3,
136         RATR_INX_WIRELESS_GB = 4,
137         RATR_INX_WIRELESS_G = 5,
138         RATR_INX_WIRELESS_B = 6,
139         RATR_INX_WIRELESS_MC = 7,
140         RATR_INX_WIRELESS_AC_N = 8,
141 };
142
143 enum NETWORK_TYPE {
144         WIRELESS_INVALID = 0,
145         /* Sub-Element */
146         WIRELESS_11B = BIT(0), /* tx:cck only, rx:cck only, hw: cck */
147         WIRELESS_11G = BIT(1), /* tx:ofdm only, rx:ofdm & cck, hw:cck & ofdm*/
148         WIRELESS_11A = BIT(2), /* tx:ofdm only, rx: ofdm only, hw:ofdm only */
149         WIRELESS_11_24N = BIT(3), /* tx:MCS only, rx:MCS & cck, hw:MCS & cck */
150         WIRELESS_11_5N = BIT(4), /* tx:MCS only, rx:MCS & ofdm, hw:ofdm only */
151         WIRELESS_AC             = BIT(6),
152
153         /* Combination */
154         /*  tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
155         WIRELESS_11BG = (WIRELESS_11B | WIRELESS_11G),
156         /*  tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
157         WIRELESS_11G_24N = (WIRELESS_11G | WIRELESS_11_24N),
158         /*  tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
159         WIRELESS_11A_5N = (WIRELESS_11A | WIRELESS_11_5N),
160         /*  tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
161         WIRELESS_11BG_24N = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N),
162         /*  tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
163         WIRELESS_11AGN = (WIRELESS_11A | WIRELESS_11G | WIRELESS_11_24N |
164                           WIRELESS_11_5N),
165         WIRELESS_11ABGN = (WIRELESS_11A | WIRELESS_11B | WIRELESS_11G |
166                            WIRELESS_11_24N | WIRELESS_11_5N),
167 };
168
169 #define SUPPORTED_24G_NETTYPE_MSK                               \
170          (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N)
171 #define SUPPORTED_5G_NETTYPE_MSK                                \
172          (WIRELESS_11A | WIRELESS_11_5N)
173
174 #define IsSupported24G(NetType)                                 \
175         ((NetType) & SUPPORTED_24G_NETTYPE_MSK ? true : false)
176 #define IsSupported5G(NetType)                                  \
177         ((NetType) & SUPPORTED_5G_NETTYPE_MSK ? true : false)
178
179 #define IsEnableHWCCK(NetType)                                  \
180         IsSupported24G(NetType)
181 #define IsEnableHWOFDM(NetType)                                 \
182         ((NetType) & (WIRELESS_11G | WIRELESS_11_24N |          \
183          SUPPORTED_5G_NETTYPE_MSK) ? true : false)
184
185 #define IsSupportedRxCCK(NetType) IsEnableHWCCK(NetType)
186 #define IsSupportedRxOFDM(NetType) IsEnableHWOFDM(NetType)
187 #define IsSupportedRxMCS(NetType) IsEnableHWOFDM(NetType)
188
189 #define IsSupportedTxCCK(NetType)                               \
190         ((NetType) & (WIRELESS_11B) ? true : false)
191 #define IsSupportedTxOFDM(NetType)                              \
192         ((NetType) & (WIRELESS_11G|WIRELESS_11A) ? true : false)
193 #define IsSupportedTxMCS(NetType)                               \
194         ((NetType) & (WIRELESS_11_24N|WIRELESS_11_5N) ? true : false)
195
196 struct ieee_param {
197         u32 cmd;
198         u8 sta_addr[ETH_ALEN];
199         union {
200                 struct {
201                         u8 name;
202                         u32 value;
203                 } wpa_param;
204                 struct {
205                         u32 len;
206                         u8 reserved[32];
207                         u8 data[0];
208                 } wpa_ie;
209                 struct {
210                         int command;
211                         int reason_code;
212                 } mlme;
213                 struct {
214                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
215                         u8 set_tx;
216                         u32 err;
217                         u8 idx;
218                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
219                         u16 key_len;
220                         u8 key[0];
221                 } crypt;
222 #ifdef CONFIG_88EU_AP_MODE
223                 struct {
224                         u16 aid;
225                         u16 capability;
226                         int flags;
227                         u8 tx_supp_rates[16];
228                         struct ieee80211_ht_cap ht_cap;
229                 } add_sta;
230                 struct {
231                         u8      reserved[2];/* for set max_num_sta */
232                         u8      buf[0];
233                 } bcn_ie;
234 #endif
235
236         } u;
237 };
238
239 #ifdef CONFIG_88EU_AP_MODE
240 struct ieee_param_ex {
241         u32 cmd;
242         u8 sta_addr[ETH_ALEN];
243         u8 data[0];
244 };
245
246 struct sta_data {
247         u16 aid;
248         u16 capability;
249         int flags;
250         u32 sta_set;
251         u8 tx_supp_rates[16];
252         u32 tx_supp_rates_len;
253         struct ieee80211_ht_cap ht_cap;
254         u64     rx_pkts;
255         u64     rx_bytes;
256         u64     rx_drops;
257         u64     tx_pkts;
258         u64     tx_bytes;
259         u64     tx_drops;
260 };
261 #endif
262
263 #define IEEE80211_DATA_LEN              2304
264 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
265    6.2.1.1.2.
266
267    The figure in section 7.1.2 suggests a body size of up to 2312
268    bytes is allowed, which is a bit confusing, I suspect this
269    represents the 2304 bytes of real data, plus a possible 8 bytes of
270    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
271
272 #define IEEE80211_HLEN                  30
273 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
274
275 /* this is stolen from ipw2200 driver */
276 #define IEEE_IBSS_MAC_HASH_SIZE 31
277
278 struct ieee_ibss_seq {
279         u8 mac[ETH_ALEN];
280         u16 seq_num;
281         u16 frag_num;
282         unsigned long packet_time;
283         struct list_head list;
284 };
285
286 struct rtw_ieee80211_hdr {
287         __le16 frame_ctl;
288         __le16 duration_id;
289         u8 addr1[ETH_ALEN];
290         u8 addr2[ETH_ALEN];
291         u8 addr3[ETH_ALEN];
292         u16 seq_ctl;
293         u8 addr4[ETH_ALEN];
294 } __packed;
295
296 struct rtw_ieee80211_hdr_3addr {
297         __le16 frame_ctl;
298         __le16 duration_id;
299         u8 addr1[ETH_ALEN];
300         u8 addr2[ETH_ALEN];
301         u8 addr3[ETH_ALEN];
302         u16 seq_ctl;
303 } __packed;
304
305 struct rtw_ieee80211_hdr_qos {
306         __le16 frame_ctl;
307         __le16 duration_id;
308         u8 addr1[ETH_ALEN];
309         u8 addr2[ETH_ALEN];
310         u8 addr3[ETH_ALEN];
311         u16 seq_ctl;
312         u8 addr4[ETH_ALEN];
313         u16     qc;
314 }  __packed;
315
316 struct rtw_ieee80211_hdr_3addr_qos {
317         __le16 frame_ctl;
318         __le16 duration_id;
319         u8 addr1[ETH_ALEN];
320         u8 addr2[ETH_ALEN];
321         u8 addr3[ETH_ALEN];
322         u16 seq_ctl;
323         u16     qc;
324 }  __packed;
325
326 struct eapol {
327         u8 snap[6];
328         u16 ethertype;
329         u8 version;
330         u8 type;
331         u16 length;
332 } __packed;
333
334 enum eap_type {
335         EAP_PACKET = 0,
336         EAPOL_START,
337         EAPOL_LOGOFF,
338         EAPOL_KEY,
339         EAPOL_ENCAP_ASF_ALERT
340 };
341
342 #define IEEE80211_3ADDR_LEN 24
343 #define IEEE80211_4ADDR_LEN 30
344 #define IEEE80211_FCS_LEN    4
345
346 #define MIN_FRAG_THRESHOLD     256U
347 #define MAX_FRAG_THRESHOLD     2346U
348
349 /* Frame control field constants */
350 #define RTW_IEEE80211_FCTL_VERS         0x0003
351 #define RTW_IEEE80211_FCTL_FTYPE        0x000c
352 #define RTW_IEEE80211_FCTL_STYPE        0x00f0
353 #define RTW_IEEE80211_FCTL_TODS         0x0100
354 #define RTW_IEEE80211_FCTL_FROMDS       0x0200
355 #define RTW_IEEE80211_FCTL_MOREFRAGS    0x0400
356 #define RTW_IEEE80211_FCTL_RETRY        0x0800
357 #define RTW_IEEE80211_FCTL_PM           0x1000
358 #define RTW_IEEE80211_FCTL_MOREDATA     0x2000
359 #define RTW_IEEE80211_FCTL_PROTECTED    0x4000
360 #define RTW_IEEE80211_FCTL_ORDER        0x8000
361 #define RTW_IEEE80211_FCTL_CTL_EXT      0x0f00
362
363 #define RTW_IEEE80211_FTYPE_MGMT        0x0000
364 #define RTW_IEEE80211_FTYPE_CTL         0x0004
365 #define RTW_IEEE80211_FTYPE_DATA        0x0008
366 #define RTW_IEEE80211_FTYPE_EXT         0x000c
367
368 /* management */
369 #define RTW_IEEE80211_STYPE_ASSOC_REQ   0x0000
370 #define RTW_IEEE80211_STYPE_ASSOC_RESP  0x0010
371 #define RTW_IEEE80211_STYPE_REASSOC_REQ 0x0020
372 #define RTW_IEEE80211_STYPE_REASSOC_RESP        0x0030
373 #define RTW_IEEE80211_STYPE_PROBE_REQ   0x0040
374 #define RTW_IEEE80211_STYPE_PROBE_RESP  0x0050
375 #define RTW_IEEE80211_STYPE_BEACON      0x0080
376 #define RTW_IEEE80211_STYPE_ATIM        0x0090
377 #define RTW_IEEE80211_STYPE_DISASSOC    0x00A0
378 #define RTW_IEEE80211_STYPE_AUTH        0x00B0
379 #define RTW_IEEE80211_STYPE_DEAUTH      0x00C0
380 #define RTW_IEEE80211_STYPE_ACTION      0x00D0
381
382 /* control */
383 #define RTW_IEEE80211_STYPE_CTL_EXT     0x0060
384 #define RTW_IEEE80211_STYPE_BACK_REQ    0x0080
385 #define RTW_IEEE80211_STYPE_BACK        0x0090
386 #define RTW_IEEE80211_STYPE_PSPOLL      0x00A0
387 #define RTW_IEEE80211_STYPE_RTS         0x00B0
388 #define RTW_IEEE80211_STYPE_CTS         0x00C0
389 #define RTW_IEEE80211_STYPE_ACK         0x00D0
390 #define RTW_IEEE80211_STYPE_CFEND       0x00E0
391 #define RTW_IEEE80211_STYPE_CFENDACK    0x00F0
392
393 /* data */
394 #define RTW_IEEE80211_STYPE_DATA        0x0000
395 #define RTW_IEEE80211_STYPE_DATA_CFACK  0x0010
396 #define RTW_IEEE80211_STYPE_DATA_CFPOLL 0x0020
397 #define RTW_IEEE80211_STYPE_DATA_CFACKPOLL      0x0030
398 #define RTW_IEEE80211_STYPE_NULLFUNC    0x0040
399 #define RTW_IEEE80211_STYPE_CFACK       0x0050
400 #define RTW_IEEE80211_STYPE_CFPOLL      0x0060
401 #define RTW_IEEE80211_STYPE_CFACKPOLL   0x0070
402 #define RTW_IEEE80211_STYPE_QOS_DATA    0x0080
403 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACK      0x0090
404 #define RTW_IEEE80211_STYPE_QOS_DATA_CFPOLL     0x00A0
405 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACKPOLL  0x00B0
406 #define RTW_IEEE80211_STYPE_QOS_NULLFUNC        0x00C0
407 #define RTW_IEEE80211_STYPE_QOS_CFACK           0x00D0
408 #define RTW_IEEE80211_STYPE_QOS_CFPOLL          0x00E0
409 #define RTW_IEEE80211_STYPE_QOS_CFACKPOLL       0x00F0
410
411 /* sequence control field */
412 #define RTW_IEEE80211_SCTL_FRAG 0x000F
413 #define RTW_IEEE80211_SCTL_SEQ  0xFFF0
414
415 #define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0)
416 #define RTW_ERP_INFO_USE_PROTECTION BIT(1)
417 #define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
418
419 /* QoS, QOS */
420 #define NORMAL_ACK                      0
421 #define NO_ACK                          1
422 #define NON_EXPLICIT_ACK                2
423 #define BLOCK_ACK                       3
424
425 #ifndef ETH_P_PAE
426 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
427 #endif /* ETH_P_PAE */
428
429 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
430
431 #define ETH_P_ECONET    0x0018
432
433 #ifndef ETH_P_80211_RAW
434 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
435 #endif
436
437 /* IEEE 802.11 defines */
438
439 #define P80211_OUI_LEN 3
440
441 struct ieee80211_snap_hdr {
442         u8    dsap;   /* always 0xAA */
443         u8    ssap;   /* always 0xAA */
444         u8    ctrl;   /* always 0x03 */
445         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
446 } __packed;
447
448 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
449
450 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTW_IEEE80211_FCTL_FTYPE)
451 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTW_IEEE80211_FCTL_STYPE)
452
453 #define WLAN_QC_GET_TID(qc) ((qc) & 0x0f)
454
455 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
456 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & RTW_IEEE80211_SCTL_SEQ)
457
458 /* Authentication algorithms */
459 #define WLAN_AUTH_OPEN 0
460 #define WLAN_AUTH_SHARED_KEY 1
461
462 #define WLAN_AUTH_CHALLENGE_LEN 128
463
464 #define WLAN_CAPABILITY_BSS (1<<0)
465 #define WLAN_CAPABILITY_IBSS (1<<1)
466 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
467 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
468 #define WLAN_CAPABILITY_PRIVACY (1<<4)
469 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
470 #define WLAN_CAPABILITY_PBCC (1<<6)
471 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
472 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
473
474 /* Status codes */
475 #define WLAN_STATUS_SUCCESS 0
476 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
477 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
478 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
479 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
480 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
481 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
482 #define WLAN_STATUS_CHALLENGE_FAIL 15
483 #define WLAN_STATUS_AUTH_TIMEOUT 16
484 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
485 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
486 /* 802.11b */
487 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
488 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
489 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
490
491 /* Reason codes */
492 #define WLAN_REASON_UNSPECIFIED 1
493 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
494 #define WLAN_REASON_DEAUTH_LEAVING 3
495 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
496 #define WLAN_REASON_DISASSOC_AP_BUSY 5
497 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
498 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
499 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
500 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
501 #define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
502 #define WLAN_REASON_EXPIRATION_CHK 65535
503
504 /* Information Element IDs */
505 #define WLAN_EID_SSID 0
506 #define WLAN_EID_SUPP_RATES 1
507 #define WLAN_EID_FH_PARAMS 2
508 #define WLAN_EID_DS_PARAMS 3
509 #define WLAN_EID_CF_PARAMS 4
510 #define WLAN_EID_TIM 5
511 #define WLAN_EID_IBSS_PARAMS 6
512 #define WLAN_EID_CHALLENGE 16
513 /* EIDs defined by IEEE 802.11h - START */
514 #define WLAN_EID_PWR_CONSTRAINT 32
515 #define WLAN_EID_PWR_CAPABILITY 33
516 #define WLAN_EID_TPC_REQUEST 34
517 #define WLAN_EID_TPC_REPORT 35
518 #define WLAN_EID_SUPPORTED_CHANNELS 36
519 #define WLAN_EID_CHANNEL_SWITCH 37
520 #define WLAN_EID_MEASURE_REQUEST 38
521 #define WLAN_EID_MEASURE_REPORT 39
522 #define WLAN_EID_QUITE 40
523 #define WLAN_EID_IBSS_DFS 41
524 /* EIDs defined by IEEE 802.11h - END */
525 #define WLAN_EID_ERP_INFO 42
526 #define WLAN_EID_HT_CAP 45
527 #define WLAN_EID_RSN 48
528 #define WLAN_EID_EXT_SUPP_RATES 50
529 #define WLAN_EID_MOBILITY_DOMAIN 54
530 #define WLAN_EID_FAST_BSS_TRANSITION 55
531 #define WLAN_EID_TIMEOUT_INTERVAL 56
532 #define WLAN_EID_RIC_DATA 57
533 #define WLAN_EID_HT_OPERATION 61
534 #define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
535 #define WLAN_EID_20_40_BSS_COEXISTENCE 72
536 #define WLAN_EID_20_40_BSS_INTOLERANT 73
537 #define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
538 #define WLAN_EID_MMIE 76
539 #define WLAN_EID_VENDOR_SPECIFIC 221
540 #define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
541
542 #define IEEE80211_MGMT_HDR_LEN 24
543 #define IEEE80211_DATA_HDR3_LEN 24
544 #define IEEE80211_DATA_HDR4_LEN 30
545
546 #define IEEE80211_STATMASK_SIGNAL (1<<0)
547 #define IEEE80211_STATMASK_RSSI (1<<1)
548 #define IEEE80211_STATMASK_NOISE (1<<2)
549 #define IEEE80211_STATMASK_RATE (1<<3)
550 #define IEEE80211_STATMASK_WEMASK 0x7
551
552 #define IEEE80211_CCK_MODULATION    (1<<0)
553 #define IEEE80211_OFDM_MODULATION   (1<<1)
554
555 #define IEEE80211_24GHZ_BAND     (1<<0)
556 #define IEEE80211_52GHZ_BAND     (1<<1)
557
558 #define IEEE80211_CCK_RATE_LEN                  4
559 #define IEEE80211_NUM_OFDM_RATESLEN     8
560
561 #define IEEE80211_CCK_RATE_1MB                  0x02
562 #define IEEE80211_CCK_RATE_2MB                  0x04
563 #define IEEE80211_CCK_RATE_5MB                  0x0B
564 #define IEEE80211_CCK_RATE_11MB                 0x16
565 #define IEEE80211_OFDM_RATE_LEN                 8
566 #define IEEE80211_OFDM_RATE_6MB                 0x0C
567 #define IEEE80211_OFDM_RATE_9MB                 0x12
568 #define IEEE80211_OFDM_RATE_12MB                0x18
569 #define IEEE80211_OFDM_RATE_18MB                0x24
570 #define IEEE80211_OFDM_RATE_24MB                0x30
571 #define IEEE80211_OFDM_RATE_36MB                0x48
572 #define IEEE80211_OFDM_RATE_48MB                0x60
573 #define IEEE80211_OFDM_RATE_54MB                0x6C
574 #define IEEE80211_BASIC_RATE_MASK               0x80
575
576 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
577 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
578 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
579 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
580 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
581 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
582 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
583 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
584 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
585 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
586 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
587 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
588
589 #define IEEE80211_CCK_RATES_MASK                0x0000000F
590 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
591         IEEE80211_CCK_RATE_2MB_MASK)
592 #define IEEE80211_CCK_DEFAULT_RATES_MASK                                \
593         (IEEE80211_CCK_BASIC_RATES_MASK |                               \
594         IEEE80211_CCK_RATE_5MB_MASK |                                   \
595         IEEE80211_CCK_RATE_11MB_MASK)
596
597 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
598 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
599         IEEE80211_OFDM_RATE_12MB_MASK |                                 \
600         IEEE80211_OFDM_RATE_24MB_MASK)
601 #define IEEE80211_OFDM_DEFAULT_RATES_MASK                               \
602         (IEEE80211_OFDM_BASIC_RATES_MASK |                              \
603         IEEE80211_OFDM_RATE_9MB_MASK  |                                 \
604         IEEE80211_OFDM_RATE_18MB_MASK |                                 \
605         IEEE80211_OFDM_RATE_36MB_MASK |                                 \
606         IEEE80211_OFDM_RATE_48MB_MASK |                                 \
607         IEEE80211_OFDM_RATE_54MB_MASK)
608 #define IEEE80211_DEFAULT_RATES_MASK                                    \
609         (IEEE80211_OFDM_DEFAULT_RATES_MASK |                            \
610          IEEE80211_CCK_DEFAULT_RATES_MASK)
611
612 #define IEEE80211_NUM_OFDM_RATES        8
613 #define IEEE80211_NUM_CCK_RATES         4
614 #define IEEE80211_OFDM_SHIFT_MASK_A     4
615
616 /* NOTE: This data is for statistical purposes; not all hardware provides this
617  *       information for frames received.  Not setting these will not cause
618  *       any adverse affects. */
619 struct ieee80211_rx_stats {
620         /* u32 mac_time[2]; */
621         s8 rssi;
622         u8 signal;
623         u8 noise;
624         u8 received_channel;
625         u16 rate; /* in 100 kbps */
626         /* u8 control; */
627         u8 mask;
628         u8 freq;
629         u16 len;
630 };
631
632 /* IEEE 802.11 requires that STA supports concurrent reception of at least
633  * three fragmented frames. This define can be increased to support more
634  * concurrent frames, but it should be noted that each entry can consume about
635  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
636 #define IEEE80211_FRAG_CACHE_LEN 4
637
638 struct ieee80211_frag_entry {
639         u32 first_frag_time;
640         uint seq;
641         uint last_frag;
642         uint qos;   /* jackson */
643         uint tid;       /* jackson */
644         struct sk_buff *skb;
645         u8 src_addr[ETH_ALEN];
646         u8 dst_addr[ETH_ALEN];
647 };
648
649 struct ieee80211_stats {
650         uint tx_unicast_frames;
651         uint tx_multicast_frames;
652         uint tx_fragments;
653         uint tx_unicast_octets;
654         uint tx_multicast_octets;
655         uint tx_deferred_transmissions;
656         uint tx_single_retry_frames;
657         uint tx_multiple_retry_frames;
658         uint tx_retry_limit_exceeded;
659         uint tx_discards;
660         uint rx_unicast_frames;
661         uint rx_multicast_frames;
662         uint rx_fragments;
663         uint rx_unicast_octets;
664         uint rx_multicast_octets;
665         uint rx_fcs_errors;
666         uint rx_discards_no_buffer;
667         uint tx_discards_wrong_sa;
668         uint rx_discards_undecryptable;
669         uint rx_message_in_msg_fragments;
670         uint rx_message_in_bad_msg_fragments;
671 };
672
673 struct ieee80211_softmac_stats {
674         uint rx_ass_ok;
675         uint rx_ass_err;
676         uint rx_probe_rq;
677         uint tx_probe_rs;
678         uint tx_beacons;
679         uint rx_auth_rq;
680         uint rx_auth_rs_ok;
681         uint rx_auth_rs_err;
682         uint tx_auth_rq;
683         uint no_auth_rs;
684         uint no_ass_rs;
685         uint tx_ass_rq;
686         uint rx_ass_rq;
687         uint tx_probe_rq;
688         uint reassoc;
689         uint swtxstop;
690         uint swtxawake;
691 };
692
693 #define SEC_KEY_1       (1<<0)
694 #define SEC_KEY_2       (1<<1)
695 #define SEC_KEY_3       (1<<2)
696 #define SEC_KEY_4       (1<<3)
697 #define SEC_ACTIVE_KEY  (1<<4)
698 #define SEC_AUTH_MODE   (1<<5)
699 #define SEC_UNICAST_GROUP (1<<6)
700 #define SEC_LEVEL       (1<<7)
701 #define SEC_ENABLED     (1<<8)
702
703 #define SEC_LEVEL_0      0 /* None */
704 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
705 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
706 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
707 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
708
709 #define WEP_KEYS 4
710 #define WEP_KEY_LEN 13
711
712 struct ieee80211_security {
713         u16 active_key:2,
714         enabled:1,
715         auth_mode:2,
716         auth_algo:4,
717         unicast_uses_group:1;
718         u8 key_sizes[WEP_KEYS];
719         u8 keys[WEP_KEYS][WEP_KEY_LEN];
720         u8 level;
721         u16 flags;
722 } __packed;
723
724 /*
725
726  802.11 data frame from AP
727
728       ,-------------------------------------------------------------------.
729 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
730       |------|------|---------|---------|---------|------|---------|------|
731 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
732       |      | tion | (BSSID) |  |       | ence |  data   |      |
733       `-------------------------------------------------------------------'
734
735 Total: 28-2340 bytes
736
737 */
738
739 struct ieee80211_header_data {
740         u16 frame_ctl;
741         u16 duration_id;
742         u8 addr1[6];
743         u8 addr2[6];
744         u8 addr3[6];
745         u16 seq_ctrl;
746 };
747
748 #define BEACON_PROBE_SSID_ID_POSITION 12
749
750 /* Management Frame Information Element Types */
751 #define MFIE_TYPE_SSID          0
752 #define MFIE_TYPE_RATES         1
753 #define MFIE_TYPE_FH_SET        2
754 #define MFIE_TYPE_DS_SET        3
755 #define MFIE_TYPE_CF_SET        4
756 #define MFIE_TYPE_TIM           5
757 #define MFIE_TYPE_IBSS_SET      6
758 #define MFIE_TYPE_CHALLENGE     16
759 #define MFIE_TYPE_ERP           42
760 #define MFIE_TYPE_RSN           48
761 #define MFIE_TYPE_RATES_EX      50
762 #define MFIE_TYPE_GENERIC       221
763
764 struct ieee80211_info_element_hdr {
765         u8 id;
766         u8 len;
767 } __packed;
768
769 struct ieee80211_info_element {
770         u8 id;
771         u8 len;
772         u8 data[0];
773 } __packed;
774
775 /*
776  * These are the data types that can make up management packets
777  *
778         u16 auth_algorithm;
779         u16 auth_sequence;
780         u16 beacon_interval;
781         u16 capability;
782         u8 current_ap[ETH_ALEN];
783         u16 listen_interval;
784         struct {
785                 u16 association_id:14, reserved:2;
786         } __packed;
787         u32 time_stamp[2];
788         u16 reason;
789         u16 status;
790 */
791
792 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
793 #define IEEE80211_DEFAULT_BASIC_RATE 10
794
795 struct ieee80211_authentication {
796         struct ieee80211_header_data header;
797         u16 algorithm;
798         u16 transaction;
799         u16 status;
800         /* struct ieee80211_info_element_hdr info_element; */
801 } __packed;
802
803 struct ieee80211_probe_response {
804         struct ieee80211_header_data header;
805         u32 time_stamp[2];
806         u16 beacon_interval;
807         u16 capability;
808         struct ieee80211_info_element info_element;
809 } __packed;
810
811 struct ieee80211_probe_request {
812         struct ieee80211_header_data header;
813 } __packed;
814
815 struct ieee80211_assoc_request_frame {
816         struct rtw_ieee80211_hdr_3addr header;
817         u16 capability;
818         u16 listen_interval;
819         struct ieee80211_info_element_hdr info_element;
820 } __packed;
821
822 struct ieee80211_assoc_response_frame {
823         struct rtw_ieee80211_hdr_3addr header;
824         u16 capability;
825         u16 status;
826         u16 aid;
827 } __packed;
828
829 struct ieee80211_txb {
830         u8 nr_frags;
831         u8 encrypted;
832         u16 reserved;
833         u16 frag_size;
834         u16 payload_size;
835         struct sk_buff *fragments[0];
836 };
837
838 /* SWEEP TABLE ENTRIES NUMBER*/
839 #define MAX_SWEEP_TAB_ENTRIES             42
840 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
841 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
842  * only use 8, and then use extended rates for the remaining supported
843  * rates.  Other APs, however, stick all of their supported rates on the
844  * main rates information element... */
845 #define MAX_RATES_LENGTH                ((u8)12)
846 #define MAX_RATES_EX_LENGTH             ((u8)16)
847 #define MAX_NETWORK_COUNT               128
848 #define MAX_CHANNEL_NUMBER              161
849 #define IEEE80211_SOFTMAC_SCAN_TIME     400
850 /* HZ / 2) */
851 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
852
853 #define CRC_LENGTH               4U
854
855 #define MAX_WPA_IE_LEN (256)
856 #define MAX_WPS_IE_LEN (512)
857 #define MAX_P2P_IE_LEN (256)
858 #define MAX_WFD_IE_LEN (128)
859
860 #define NETWORK_EMPTY_ESSID (1<<0)
861 #define NETWORK_HAS_OFDM    (1<<1)
862 #define NETWORK_HAS_CCK     (1<<2)
863
864 #define IEEE80211_DTIM_MBCAST 4
865 #define IEEE80211_DTIM_UCAST 2
866 #define IEEE80211_DTIM_VALID 1
867 #define IEEE80211_DTIM_INVALID 0
868
869 #define IEEE80211_PS_DISABLED 0
870 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
871 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
872 #define IW_ESSID_MAX_SIZE 32
873 /*
874 join_res:
875 -1: authentication fail
876 -2: association fail
877 > 0: TID
878 */
879
880 enum ieee80211_state {
881         /* the card is not linked at all */
882         IEEE80211_NOLINK = 0,
883
884         /* IEEE80211_ASSOCIATING* are for BSS client mode
885          * the driver shall not perform RX filtering unless
886          * the state is LINKED.
887          * The driver shall just check for the state LINKED and
888          * defaults to NOLINK for ALL the other states (including
889          * LINKED_SCANNING)
890          */
891
892         /* the association procedure will start (wq scheduling)*/
893         IEEE80211_ASSOCIATING,
894         IEEE80211_ASSOCIATING_RETRY,
895
896         /* the association procedure is sending AUTH request*/
897         IEEE80211_ASSOCIATING_AUTHENTICATING,
898
899         /* the association procedure has successfully authentcated
900          * and is sending association request
901          */
902         IEEE80211_ASSOCIATING_AUTHENTICATED,
903
904         /* the link is ok. the card associated to a BSS or linked
905          * to a ibss cell or acting as an AP and creating the bss
906          */
907         IEEE80211_LINKED,
908
909         /* same as LINKED, but the driver shall apply RX filter
910          * rules as we are in NO_LINK mode. As the card is still
911          * logically linked, but it is doing a syncro site survey
912          * then it will be back to LINKED state.
913          */
914         IEEE80211_LINKED_SCANNING,
915
916 };
917
918 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
919 #define DEFAULT_FTS 2346
920
921 static inline int is_multicast_mac_addr(const u8 *addr)
922 {
923         return ((addr[0] != 0xff) && (0x01 & addr[0]));
924 }
925
926 static inline int is_broadcast_mac_addr(const u8 *addr)
927 {
928         return (addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
929                (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff);
930 }
931
932 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
933 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
934
935 struct tx_pending {
936         int frag;
937         struct ieee80211_txb *txb;
938 };
939
940 #define MAXTID  16
941
942 #define IEEE_A      (1<<0)
943 #define IEEE_B      (1<<1)
944 #define IEEE_G      (1<<2)
945 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
946
947 /* Baron move to ieee80211.c */
948 int ieee80211_is_empty_essid(const char *essid, int essid_len);
949 int ieee80211_get_hdrlen(u16 fc);
950
951 /* Action category code */
952 enum rtw_ieee80211_category {
953         RTW_WLAN_CATEGORY_SPECTRUM_MGMT = 0,
954         RTW_WLAN_CATEGORY_QOS = 1,
955         RTW_WLAN_CATEGORY_DLS = 2,
956         RTW_WLAN_CATEGORY_BACK = 3,
957         RTW_WLAN_CATEGORY_PUBLIC = 4, /* IEEE 802.11 public action frames */
958         RTW_WLAN_CATEGORY_RADIO_MEASUREMENT  = 5,
959         RTW_WLAN_CATEGORY_FT = 6,
960         RTW_WLAN_CATEGORY_HT = 7,
961         RTW_WLAN_CATEGORY_SA_QUERY = 8,
962         RTW_WLAN_CATEGORY_TDLS = 12,
963         RTW_WLAN_CATEGORY_WMM = 17,
964         RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */
965 };
966
967 /* SPECTRUM_MGMT action code */
968 enum rtw_ieee80211_spectrum_mgmt_actioncode {
969         RTW_WLAN_ACTION_SPCT_MSR_REQ = 0,
970         RTW_WLAN_ACTION_SPCT_MSR_RPRT = 1,
971         RTW_WLAN_ACTION_SPCT_TPC_REQ = 2,
972         RTW_WLAN_ACTION_SPCT_TPC_RPRT = 3,
973         RTW_WLAN_ACTION_SPCT_CHL_SWITCH = 4,
974         RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5,
975 };
976
977 enum _PUBLIC_ACTION {
978         ACT_PUBLIC_BSSCOEXIST = 0, /*  20/40 BSS Coexistence */
979         ACT_PUBLIC_DSE_ENABLE = 1,
980         ACT_PUBLIC_DSE_DEENABLE = 2,
981         ACT_PUBLIC_DSE_REG_LOCATION = 3,
982         ACT_PUBLIC_EXT_CHL_SWITCH = 4,
983         ACT_PUBLIC_DSE_MSR_REQ = 5,
984         ACT_PUBLIC_DSE_MSR_RPRT = 6,
985         ACT_PUBLIC_MP = 7, /*  Measurement Pilot */
986         ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8,
987         ACT_PUBLIC_VENDOR = 9, /*  for WIFI_DIRECT */
988         ACT_PUBLIC_GAS_INITIAL_REQ = 10,
989         ACT_PUBLIC_GAS_INITIAL_RSP = 11,
990         ACT_PUBLIC_GAS_COMEBACK_REQ = 12,
991         ACT_PUBLIC_GAS_COMEBACK_RSP = 13,
992         ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14,
993         ACT_PUBLIC_LOCATION_TRACK = 15,
994         ACT_PUBLIC_MAX
995 };
996
997 /* BACK action code */
998 enum rtw_ieee80211_back_actioncode {
999         RTW_WLAN_ACTION_ADDBA_REQ = 0,
1000         RTW_WLAN_ACTION_ADDBA_RESP = 1,
1001         RTW_WLAN_ACTION_DELBA = 2,
1002 };
1003
1004 /* HT features action code */
1005 enum rtw_ieee80211_ht_actioncode {
1006         RTW_WLAN_ACTION_NOTIFY_CH_WIDTH = 0,
1007         RTW_WLAN_ACTION_SM_PS = 1,
1008         RTW_WLAN_ACTION_PSPM = 2,
1009         RTW_WLAN_ACTION_PCO_PHASE = 3,
1010         RTW_WLAN_ACTION_MIMO_CSI_MX = 4,
1011         RTW_WLAN_ACTION_MIMO_NONCP_BF = 5,
1012         RTW_WLAN_ACTION_MIMP_CP_BF = 6,
1013         RTW_WLAN_ACTION_ASEL_INDICATES_FB = 7,
1014         RTW_WLAN_ACTION_HI_INFO_EXCHG = 8,
1015 };
1016
1017 /* BACK (block-ack) parties */
1018 enum rtw_ieee80211_back_parties {
1019         RTW_WLAN_BACK_RECIPIENT = 0,
1020         RTW_WLAN_BACK_INITIATOR = 1,
1021         RTW_WLAN_BACK_TIMER = 2,
1022 };
1023
1024 #define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
1025                                 * 00:50:F2 */
1026 #define WME_OUI_TYPE 2
1027 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
1028 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
1029 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
1030 #define WME_VERSION 1
1031
1032 #define WME_ACTION_CODE_SETUP_REQUEST 0
1033 #define WME_ACTION_CODE_SETUP_RESPONSE 1
1034 #define WME_ACTION_CODE_TEARDOWN 2
1035
1036 #define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0
1037 #define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1
1038 #define WME_SETUP_RESPONSE_STATUS_REFUSED 3
1039
1040 #define WME_TSPEC_DIRECTION_UPLINK 0
1041 #define WME_TSPEC_DIRECTION_DOWNLINK 1
1042 #define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3
1043
1044 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
1045
1046 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
1047
1048 /**
1049  * enum rtw_ieee80211_channel_flags - channel flags
1050  *
1051  * Channel flags set by the regulatory control code.
1052  *
1053  * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled.
1054  * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
1055  *      on this channel.
1056  * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
1057  * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
1058  * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
1059  *      is not permitted.
1060  * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
1061  *      is not permitted.
1062  */
1063 enum rtw_ieee80211_channel_flags {
1064         RTW_IEEE80211_CHAN_DISABLED      = 1<<0,
1065         RTW_IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
1066         RTW_IEEE80211_CHAN_NO_IBSS        = 1<<2,
1067         RTW_IEEE80211_CHAN_RADAR            = 1<<3,
1068         RTW_IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
1069         RTW_IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
1070 };
1071
1072 #define RTW_IEEE80211_CHAN_NO_HT40 \
1073           (RTW_IEEE80211_CHAN_NO_HT40PLUS | RTW_IEEE80211_CHAN_NO_HT40MINUS)
1074
1075 /* Represent channel details, subset of ieee80211_channel */
1076 struct rtw_ieee80211_channel {
1077         u16 hw_value;
1078         u32 flags;
1079 };
1080
1081 #define CHAN_FMT \
1082         "hw_value:%u, " \
1083         "flags:0x%08x" \
1084
1085 #define CHAN_ARG(channel) \
1086         (channel)->hw_value \
1087         , (channel)->flags \
1088
1089 /* Parsed Information Elements */
1090 struct rtw_ieee802_11_elems {
1091         u8 *ssid;
1092         u8 ssid_len;
1093         u8 *supp_rates;
1094         u8 supp_rates_len;
1095         u8 *fh_params;
1096         u8 fh_params_len;
1097         u8 *ds_params;
1098         u8 ds_params_len;
1099         u8 *cf_params;
1100         u8 cf_params_len;
1101         u8 *tim;
1102         u8 tim_len;
1103         u8 *ibss_params;
1104         u8 ibss_params_len;
1105         u8 *challenge;
1106         u8 challenge_len;
1107         u8 *erp_info;
1108         u8 erp_info_len;
1109         u8 *ext_supp_rates;
1110         u8 ext_supp_rates_len;
1111         u8 *wpa_ie;
1112         u8 wpa_ie_len;
1113         u8 *rsn_ie;
1114         u8 rsn_ie_len;
1115         u8 *wme;
1116         u8 wme_len;
1117         u8 *wme_tspec;
1118         u8 wme_tspec_len;
1119         u8 *wps_ie;
1120         u8 wps_ie_len;
1121         u8 *power_cap;
1122         u8 power_cap_len;
1123         u8 *supp_channels;
1124         u8 supp_channels_len;
1125         u8 *mdie;
1126         u8 mdie_len;
1127         u8 *ftie;
1128         u8 ftie_len;
1129         u8 *timeout_int;
1130         u8 timeout_int_len;
1131         u8 *ht_capabilities;
1132         u8 ht_capabilities_len;
1133         u8 *ht_operation;
1134         u8 ht_operation_len;
1135         u8 *vendor_ht_cap;
1136         u8 vendor_ht_cap_len;
1137 };
1138
1139 enum parse_res {
1140         ParseOK = 0,
1141         ParseUnknown = 1,
1142         ParseFailed = -1
1143 };
1144
1145 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
1146                                           struct rtw_ieee802_11_elems *elems,
1147                                           int show_errors);
1148
1149 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len,
1150                      unsigned char *source, unsigned int *frlen);
1151 u8 *rtw_set_ie(u8 *pbuf, int index, uint len, u8 *source, uint *frlen);
1152
1153 enum secondary_ch_offset {
1154         SCN = 0, /* no secondary channel */
1155         SCA = 1, /* secondary channel above */
1156         SCB = 3,  /* secondary channel below */
1157 };
1158 u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset);
1159 u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset);
1160 u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,
1161                          u8 new_ch, u8 ch_switch_cnt);
1162 u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len,
1163                                    u8 secondary_ch_offset);
1164 u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,
1165                                    u8 flags, u16 reason, u16 precedence);
1166
1167 u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit);
1168 u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui,
1169                   u8 oui_len, u8 *ie, uint *ielen);
1170 int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset,
1171                       u8 eid, u8 *oui, u8 oui_len);
1172
1173 void rtw_set_supported_rate(u8 *SupportedRates, uint mode);
1174
1175 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit);
1176 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit);
1177 int rtw_get_wpa_cipher_suite(u8 *s);
1178 int rtw_get_wpa2_cipher_suite(u8 *s);
1179 int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
1180 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
1181                      int *pairwise_cipher, int *is_8021x);
1182 int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
1183                       int *pairwise_cipher, int *is_8021x);
1184
1185 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
1186                    u8 *wpa_ie, u16 *wpa_len);
1187
1188 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
1189 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
1190 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
1191                      u8 *buf_attr, u32 *len_attr);
1192 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
1193                              u8 *buf_content, uint *len_content);
1194
1195 /**
1196  * for_each_ie - iterate over continuous IEs
1197  * @ie:
1198  * @buf:
1199  * @buf_len:
1200  */
1201 #define for_each_ie(ie, buf, buf_len) \
1202         for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len;        \
1203                 ie = (void *)(((u8 *)ie) + *(((u8 *)ie)+1) + 2))
1204
1205 void dump_ies(u8 *buf, u32 buf_len);
1206 void dump_wps_ie(u8 *ie, u32 ie_len);
1207
1208 #ifdef CONFIG_88EU_P2P
1209 void dump_p2p_ie(u8 *ie, u32 ie_len);
1210 u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen);
1211 u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
1212                      u8 *buf_attr, u32 *len_attr);
1213 u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
1214                              u8 *buf_content, uint *len_content);
1215 u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len,
1216                              u8 *pdata_attr);
1217 void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex,
1218                                        u8 attr_id);
1219 #endif
1220
1221 uint    rtw_get_rateset_len(u8  *rateset);
1222
1223 struct registry_priv;
1224 int rtw_generate_ie(struct registry_priv *pregistrypriv);
1225
1226 int rtw_get_bit_value_from_ieee_value(u8 val);
1227
1228 uint    rtw_is_cckrates_included(u8 *rate);
1229
1230 uint    rtw_is_cckratesonly_included(u8 *rate);
1231
1232 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
1233
1234 void rtw_get_bcn_info(struct wlan_network *pnetwork);
1235
1236 void rtw_macaddr_cfg(u8 *mac_addr);
1237
1238 u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40,
1239                  unsigned char *MCS_rate);
1240
1241 int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category,
1242                            u8 *action);
1243 const char *action_public_str(u8 action);
1244
1245 #endif /* IEEE80211_H */