staging: r8188eu: remove ETH_ALEN from ieee80211.h
[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_TYPE_LEN            2
15 #define PAYLOAD_TYPE_LEN        1
16
17 #define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
18
19 /* STA flags */
20 #define WLAN_STA_AUTH BIT(0)
21 #define WLAN_STA_ASSOC BIT(1)
22 #define WLAN_STA_PS BIT(2)
23 #define WLAN_STA_TIM BIT(3)
24 #define WLAN_STA_PERM BIT(4)
25 #define WLAN_STA_AUTHORIZED BIT(5)
26 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
27 #define WLAN_STA_SHORT_PREAMBLE BIT(7)
28 #define WLAN_STA_PREAUTH BIT(8)
29 #define WLAN_STA_WME BIT(9)
30 #define WLAN_STA_MFP BIT(10)
31 #define WLAN_STA_HT BIT(11)
32 #define WLAN_STA_WPS BIT(12)
33 #define WLAN_STA_MAYBE_WPS BIT(13)
34 #define WLAN_STA_NONERP BIT(31)
35
36 #define IEEE_CMD_SET_WPA_PARAM                  1
37 #define IEEE_CMD_SET_WPA_IE                             2
38 #define IEEE_CMD_SET_ENCRYPTION                 3
39 #define IEEE_CMD_MLME                                           4
40
41 #define IEEE_PARAM_WPA_ENABLED                          1
42 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
43 #define IEEE_PARAM_DROP_UNENCRYPTED                     3
44 #define IEEE_PARAM_PRIVACY_INVOKED                      4
45 #define IEEE_PARAM_AUTH_ALGS                                    5
46 #define IEEE_PARAM_IEEE_802_1X                          6
47 #define IEEE_PARAM_WPAX_SELECT                          7
48
49 #define AUTH_ALG_OPEN_SYSTEM                    0x1
50 #define AUTH_ALG_SHARED_KEY                     0x2
51 #define AUTH_ALG_LEAP                           0x00000004
52
53 #define IEEE_MLME_STA_DEAUTH                            1
54 #define IEEE_MLME_STA_DISASSOC                  2
55
56 #define IEEE_CRYPT_ERR_UNKNOWN_ALG                      2
57 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR                     3
58 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED                4
59 #define IEEE_CRYPT_ERR_KEY_SET_FAILED                   5
60 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED                6
61 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
62
63 #define IEEE_CRYPT_ALG_NAME_LEN                 16
64
65 #define WPA_CIPHER_NONE         BIT(0)
66 #define WPA_CIPHER_WEP40        BIT(1)
67 #define WPA_CIPHER_WEP104 BIT(2)
68 #define WPA_CIPHER_TKIP         BIT(3)
69 #define WPA_CIPHER_CCMP         BIT(4)
70
71
72 #define WPA_SELECTOR_LEN 4
73 extern u8 RTW_WPA_OUI_TYPE[];
74 extern u16 RTW_WPA_VERSION;
75 extern u8 WPA_AUTH_KEY_MGMT_NONE[];
76 extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[];
77 extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
78 extern u8 WPA_CIPHER_SUITE_NONE[];
79 extern u8 WPA_CIPHER_SUITE_WEP40[];
80 extern u8 WPA_CIPHER_SUITE_TKIP[];
81 extern u8 WPA_CIPHER_SUITE_WRAP[];
82 extern u8 WPA_CIPHER_SUITE_CCMP[];
83 extern u8 WPA_CIPHER_SUITE_WEP104[];
84
85 #define RSN_HEADER_LEN 4
86 #define RSN_SELECTOR_LEN 4
87
88 extern u16 RSN_VERSION_BSD;
89 extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[];
90 extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
91 extern u8 RSN_CIPHER_SUITE_NONE[];
92 extern u8 RSN_CIPHER_SUITE_WEP40[];
93 extern u8 RSN_CIPHER_SUITE_TKIP[];
94 extern u8 RSN_CIPHER_SUITE_WRAP[];
95 extern u8 RSN_CIPHER_SUITE_CCMP[];
96 extern u8 RSN_CIPHER_SUITE_WEP104[];
97
98 enum ratr_table_mode {
99         RATR_INX_WIRELESS_NGB = 0,      /*  BGN 40 Mhz 2SS 1SS */
100         RATR_INX_WIRELESS_NG = 1,       /*  GN or N */
101         RATR_INX_WIRELESS_NB = 2,       /*  BGN 20 Mhz 2SS 1SS  or BN */
102         RATR_INX_WIRELESS_N = 3,
103         RATR_INX_WIRELESS_GB = 4,
104         RATR_INX_WIRELESS_G = 5,
105         RATR_INX_WIRELESS_B = 6,
106         RATR_INX_WIRELESS_MC = 7,
107         RATR_INX_WIRELESS_AC_N = 8,
108 };
109
110 enum NETWORK_TYPE {
111         WIRELESS_INVALID = 0,
112         /* Sub-Element */
113         WIRELESS_11B = BIT(0), /* tx:cck only, rx:cck only, hw: cck */
114         WIRELESS_11G = BIT(1), /* tx:ofdm only, rx:ofdm & cck, hw:cck & ofdm*/
115         WIRELESS_11_24N = BIT(3), /* tx:MCS only, rx:MCS & cck, hw:MCS & cck */
116
117         /* Combination */
118         /*  tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
119         WIRELESS_11BG = (WIRELESS_11B | WIRELESS_11G),
120         /*  tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
121         WIRELESS_11G_24N = (WIRELESS_11G | WIRELESS_11_24N),
122         /*  tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
123         WIRELESS_11BG_24N = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N),
124 };
125
126 #define SUPPORTED_24G_NETTYPE_MSK                               \
127          (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N)
128
129 #define IsSupported24G(NetType)                                 \
130         ((NetType) & SUPPORTED_24G_NETTYPE_MSK ? true : false)
131
132 #define IsEnableHWCCK(NetType)                                  \
133         IsSupported24G(NetType)
134
135 #define IsSupportedRxCCK(NetType) IsEnableHWCCK(NetType)
136
137 #define IsSupportedTxCCK(NetType)                               \
138         ((NetType) & (WIRELESS_11B) ? true : false)
139 #define IsSupportedTxOFDM(NetType)                              \
140         ((NetType) & (WIRELESS_11G) ? true : false)
141 #define IsSupportedTxMCS(NetType)                               \
142         ((NetType) & (WIRELESS_11_24N) ? true : false)
143
144 struct ieee_param {
145         u32 cmd;
146         u8 sta_addr[ETH_ALEN];
147         union {
148                 struct {
149                         u8 name;
150                         u32 value;
151                 } wpa_param;
152                 struct {
153                         u32 len;
154                         u8 reserved[32];
155                         u8 data[];
156                 } wpa_ie;
157                 struct {
158                         int command;
159                         int reason_code;
160                 } mlme;
161                 struct {
162                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
163                         u8 set_tx;
164                         u32 err;
165                         u8 idx;
166                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
167                         u16 key_len;
168                         u8 key[];
169                 } crypt;
170                 struct {
171                         u16 aid;
172                         u16 capability;
173                         int flags;
174                         u8 tx_supp_rates[16];
175                         struct ieee80211_ht_cap ht_cap;
176                 } add_sta;
177                 struct {
178                         u8      reserved[2];/* for set max_num_sta */
179                         u8      buf[];
180                 } bcn_ie;
181         } u;
182 };
183
184 #define IEEE80211_DATA_LEN              2304
185 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
186    6.2.1.1.2.
187
188    The figure in section 7.1.2 suggests a body size of up to 2312
189    bytes is allowed, which is a bit confusing, I suspect this
190    represents the 2304 bytes of real data, plus a possible 8 bytes of
191    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
192
193 #define IEEE80211_HLEN                  30
194 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
195
196 /* this is stolen from ipw2200 driver */
197 #define IEEE_IBSS_MAC_HASH_SIZE 31
198
199 struct rtw_ieee80211_hdr {
200         __le16 frame_ctl;
201         __le16 duration_id;
202         u8 addr1[ETH_ALEN];
203         u8 addr2[ETH_ALEN];
204         u8 addr3[ETH_ALEN];
205         u16 seq_ctl;
206         u8 addr4[ETH_ALEN];
207 } __packed;
208
209 struct rtw_ieee80211_hdr_3addr {
210         __le16 frame_ctl;
211         __le16 duration_id;
212         u8 addr1[ETH_ALEN];
213         u8 addr2[ETH_ALEN];
214         u8 addr3[ETH_ALEN];
215         u16 seq_ctl;
216 } __packed;
217
218 struct rtw_ieee80211_hdr_3addr_qos {
219         __le16 frame_ctl;
220         __le16 duration_id;
221         u8 addr1[ETH_ALEN];
222         u8 addr2[ETH_ALEN];
223         u8 addr3[ETH_ALEN];
224         u16 seq_ctl;
225         u16     qc;
226 }  __packed;
227
228 #define IEEE80211_3ADDR_LEN 24
229 #define IEEE80211_4ADDR_LEN 30
230 #define IEEE80211_FCS_LEN    4
231
232 #define MIN_FRAG_THRESHOLD     256U
233 #define MAX_FRAG_THRESHOLD     2346U
234
235 /* Frame control field constants */
236 #define RTW_IEEE80211_FCTL_VERS         0x0003
237 #define RTW_IEEE80211_FCTL_FTYPE        0x000c
238 #define RTW_IEEE80211_FCTL_STYPE        0x00f0
239 #define RTW_IEEE80211_FCTL_TODS         0x0100
240 #define RTW_IEEE80211_FCTL_FROMDS       0x0200
241 #define RTW_IEEE80211_FCTL_MOREFRAGS    0x0400
242 #define RTW_IEEE80211_FCTL_RETRY        0x0800
243 #define RTW_IEEE80211_FCTL_PM           0x1000
244 #define RTW_IEEE80211_FCTL_MOREDATA     0x2000
245 #define RTW_IEEE80211_FCTL_PROTECTED    0x4000
246 #define RTW_IEEE80211_FCTL_ORDER        0x8000
247 #define RTW_IEEE80211_FCTL_CTL_EXT      0x0f00
248
249 #define RTW_IEEE80211_FTYPE_MGMT        0x0000
250 #define RTW_IEEE80211_FTYPE_CTL         0x0004
251 #define RTW_IEEE80211_FTYPE_DATA        0x0008
252 #define RTW_IEEE80211_FTYPE_EXT         0x000c
253
254 /* management */
255 #define RTW_IEEE80211_STYPE_ASSOC_REQ   0x0000
256 #define RTW_IEEE80211_STYPE_ASSOC_RESP  0x0010
257 #define RTW_IEEE80211_STYPE_REASSOC_REQ 0x0020
258 #define RTW_IEEE80211_STYPE_REASSOC_RESP        0x0030
259 #define RTW_IEEE80211_STYPE_PROBE_REQ   0x0040
260 #define RTW_IEEE80211_STYPE_PROBE_RESP  0x0050
261 #define RTW_IEEE80211_STYPE_BEACON      0x0080
262 #define RTW_IEEE80211_STYPE_ATIM        0x0090
263 #define RTW_IEEE80211_STYPE_DISASSOC    0x00A0
264 #define RTW_IEEE80211_STYPE_AUTH        0x00B0
265 #define RTW_IEEE80211_STYPE_DEAUTH      0x00C0
266 #define RTW_IEEE80211_STYPE_ACTION      0x00D0
267
268 /* control */
269 #define RTW_IEEE80211_STYPE_CTL_EXT     0x0060
270 #define RTW_IEEE80211_STYPE_BACK_REQ    0x0080
271 #define RTW_IEEE80211_STYPE_BACK        0x0090
272 #define RTW_IEEE80211_STYPE_PSPOLL      0x00A0
273 #define RTW_IEEE80211_STYPE_RTS         0x00B0
274 #define RTW_IEEE80211_STYPE_CTS         0x00C0
275 #define RTW_IEEE80211_STYPE_ACK         0x00D0
276 #define RTW_IEEE80211_STYPE_CFEND       0x00E0
277 #define RTW_IEEE80211_STYPE_CFENDACK    0x00F0
278
279 /* data */
280 #define RTW_IEEE80211_STYPE_DATA        0x0000
281 #define RTW_IEEE80211_STYPE_DATA_CFACK  0x0010
282 #define RTW_IEEE80211_STYPE_DATA_CFPOLL 0x0020
283 #define RTW_IEEE80211_STYPE_DATA_CFACKPOLL      0x0030
284 #define RTW_IEEE80211_STYPE_NULLFUNC    0x0040
285 #define RTW_IEEE80211_STYPE_CFACK       0x0050
286 #define RTW_IEEE80211_STYPE_CFPOLL      0x0060
287 #define RTW_IEEE80211_STYPE_CFACKPOLL   0x0070
288 #define RTW_IEEE80211_STYPE_QOS_DATA    0x0080
289 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACK      0x0090
290 #define RTW_IEEE80211_STYPE_QOS_DATA_CFPOLL     0x00A0
291 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACKPOLL  0x00B0
292 #define RTW_IEEE80211_STYPE_QOS_NULLFUNC        0x00C0
293 #define RTW_IEEE80211_STYPE_QOS_CFACK           0x00D0
294 #define RTW_IEEE80211_STYPE_QOS_CFPOLL          0x00E0
295 #define RTW_IEEE80211_STYPE_QOS_CFACKPOLL       0x00F0
296
297 /* sequence control field */
298 #define RTW_IEEE80211_SCTL_FRAG 0x000F
299 #define RTW_IEEE80211_SCTL_SEQ  0xFFF0
300
301 #define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0)
302 #define RTW_ERP_INFO_USE_PROTECTION BIT(1)
303 #define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
304
305 /* QoS, QOS */
306 #define NORMAL_ACK                      0
307 #define NO_ACK                          1
308 #define NON_EXPLICIT_ACK                2
309 #define BLOCK_ACK                       3
310
311 #ifndef ETH_P_PAE
312 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
313 #endif /* ETH_P_PAE */
314
315 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
316
317 #define ETH_P_ECONET    0x0018
318
319 #ifndef ETH_P_80211_RAW
320 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
321 #endif
322
323 /* IEEE 802.11 defines */
324
325 #define P80211_OUI_LEN 3
326
327 struct ieee80211_snap_hdr {
328         u8    dsap;   /* always 0xAA */
329         u8    ssap;   /* always 0xAA */
330         u8    ctrl;   /* always 0x03 */
331         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
332 } __packed;
333
334 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
335
336 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTW_IEEE80211_FCTL_FTYPE)
337 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTW_IEEE80211_FCTL_STYPE)
338
339 #define WLAN_QC_GET_TID(qc) ((qc) & 0x0f)
340
341 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
342 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & RTW_IEEE80211_SCTL_SEQ)
343
344 /* Authentication algorithms */
345 #define WLAN_AUTH_OPEN 0
346 #define WLAN_AUTH_SHARED_KEY 1
347
348 #define WLAN_AUTH_CHALLENGE_LEN 128
349
350 #define WLAN_CAPABILITY_BSS (1<<0)
351 #define WLAN_CAPABILITY_IBSS (1<<1)
352 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
353 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
354 #define WLAN_CAPABILITY_PRIVACY (1<<4)
355 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
356 #define WLAN_CAPABILITY_PBCC (1<<6)
357 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
358 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
359
360 /* Status codes */
361 #define WLAN_STATUS_SUCCESS 0
362 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
363 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
364 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
365 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
366 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
367 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
368 #define WLAN_STATUS_CHALLENGE_FAIL 15
369 #define WLAN_STATUS_AUTH_TIMEOUT 16
370 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
371 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
372 /* 802.11b */
373 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
374 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
375 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
376
377 /* Reason codes */
378 #define WLAN_REASON_UNSPECIFIED 1
379 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
380 #define WLAN_REASON_DEAUTH_LEAVING 3
381 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
382 #define WLAN_REASON_DISASSOC_AP_BUSY 5
383 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
384 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
385 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
386 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
387 #define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
388 #define WLAN_REASON_EXPIRATION_CHK 65535
389
390 /* Information Element IDs */
391 #define WLAN_EID_SSID 0
392 #define WLAN_EID_SUPP_RATES 1
393 #define WLAN_EID_FH_PARAMS 2
394 #define WLAN_EID_DS_PARAMS 3
395 #define WLAN_EID_CF_PARAMS 4
396 #define WLAN_EID_TIM 5
397 #define WLAN_EID_IBSS_PARAMS 6
398 #define WLAN_EID_CHALLENGE 16
399 /* EIDs defined by IEEE 802.11h - START */
400 #define WLAN_EID_PWR_CONSTRAINT 32
401 #define WLAN_EID_PWR_CAPABILITY 33
402 #define WLAN_EID_TPC_REQUEST 34
403 #define WLAN_EID_TPC_REPORT 35
404 #define WLAN_EID_SUPPORTED_CHANNELS 36
405 #define WLAN_EID_CHANNEL_SWITCH 37
406 #define WLAN_EID_MEASURE_REQUEST 38
407 #define WLAN_EID_MEASURE_REPORT 39
408 #define WLAN_EID_QUITE 40
409 #define WLAN_EID_IBSS_DFS 41
410 /* EIDs defined by IEEE 802.11h - END */
411 #define WLAN_EID_ERP_INFO 42
412 #define WLAN_EID_HT_CAP 45
413 #define WLAN_EID_RSN 48
414 #define WLAN_EID_EXT_SUPP_RATES 50
415 #define WLAN_EID_MOBILITY_DOMAIN 54
416 #define WLAN_EID_FAST_BSS_TRANSITION 55
417 #define WLAN_EID_TIMEOUT_INTERVAL 56
418 #define WLAN_EID_RIC_DATA 57
419 #define WLAN_EID_HT_OPERATION 61
420 #define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
421 #define WLAN_EID_20_40_BSS_COEXISTENCE 72
422 #define WLAN_EID_20_40_BSS_INTOLERANT 73
423 #define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
424 #define WLAN_EID_MMIE 76
425 #define WLAN_EID_VENDOR_SPECIFIC 221
426 #define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
427
428 #define IEEE80211_MGMT_HDR_LEN 24
429 #define IEEE80211_DATA_HDR3_LEN 24
430 #define IEEE80211_DATA_HDR4_LEN 30
431
432 #define IEEE80211_STATMASK_SIGNAL (1<<0)
433 #define IEEE80211_STATMASK_RSSI (1<<1)
434 #define IEEE80211_STATMASK_NOISE (1<<2)
435 #define IEEE80211_STATMASK_RATE (1<<3)
436 #define IEEE80211_STATMASK_WEMASK 0x7
437
438 #define IEEE80211_CCK_MODULATION    (1<<0)
439 #define IEEE80211_OFDM_MODULATION   (1<<1)
440
441 #define IEEE80211_24GHZ_BAND     (1<<0)
442 #define IEEE80211_52GHZ_BAND     (1<<1)
443
444 #define IEEE80211_CCK_RATE_LEN                  4
445 #define IEEE80211_NUM_OFDM_RATESLEN     8
446
447 #define IEEE80211_CCK_RATE_1MB                  0x02
448 #define IEEE80211_CCK_RATE_2MB                  0x04
449 #define IEEE80211_CCK_RATE_5MB                  0x0B
450 #define IEEE80211_CCK_RATE_11MB                 0x16
451 #define IEEE80211_OFDM_RATE_LEN                 8
452 #define IEEE80211_OFDM_RATE_6MB                 0x0C
453 #define IEEE80211_OFDM_RATE_9MB                 0x12
454 #define IEEE80211_OFDM_RATE_12MB                0x18
455 #define IEEE80211_OFDM_RATE_18MB                0x24
456 #define IEEE80211_OFDM_RATE_24MB                0x30
457 #define IEEE80211_OFDM_RATE_36MB                0x48
458 #define IEEE80211_OFDM_RATE_48MB                0x60
459 #define IEEE80211_OFDM_RATE_54MB                0x6C
460 #define IEEE80211_BASIC_RATE_MASK               0x80
461
462 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
463 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
464 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
465 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
466 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
467 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
468 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
469 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
470 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
471 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
472 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
473 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
474
475 #define IEEE80211_CCK_RATES_MASK                0x0000000F
476 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
477         IEEE80211_CCK_RATE_2MB_MASK)
478 #define IEEE80211_CCK_DEFAULT_RATES_MASK                                \
479         (IEEE80211_CCK_BASIC_RATES_MASK |                               \
480         IEEE80211_CCK_RATE_5MB_MASK |                                   \
481         IEEE80211_CCK_RATE_11MB_MASK)
482
483 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
484 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
485         IEEE80211_OFDM_RATE_12MB_MASK |                                 \
486         IEEE80211_OFDM_RATE_24MB_MASK)
487 #define IEEE80211_OFDM_DEFAULT_RATES_MASK                               \
488         (IEEE80211_OFDM_BASIC_RATES_MASK |                              \
489         IEEE80211_OFDM_RATE_9MB_MASK  |                                 \
490         IEEE80211_OFDM_RATE_18MB_MASK |                                 \
491         IEEE80211_OFDM_RATE_36MB_MASK |                                 \
492         IEEE80211_OFDM_RATE_48MB_MASK |                                 \
493         IEEE80211_OFDM_RATE_54MB_MASK)
494 #define IEEE80211_DEFAULT_RATES_MASK                                    \
495         (IEEE80211_OFDM_DEFAULT_RATES_MASK |                            \
496          IEEE80211_CCK_DEFAULT_RATES_MASK)
497
498 #define IEEE80211_NUM_OFDM_RATES        8
499 #define IEEE80211_NUM_CCK_RATES         4
500 #define IEEE80211_OFDM_SHIFT_MASK_A     4
501
502 /* IEEE 802.11 requires that STA supports concurrent reception of at least
503  * three fragmented frames. This define can be increased to support more
504  * concurrent frames, but it should be noted that each entry can consume about
505  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
506 #define IEEE80211_FRAG_CACHE_LEN 4
507
508 #define SEC_KEY_1       (1<<0)
509 #define SEC_KEY_2       (1<<1)
510 #define SEC_KEY_3       (1<<2)
511 #define SEC_KEY_4       (1<<3)
512 #define SEC_ACTIVE_KEY  (1<<4)
513 #define SEC_AUTH_MODE   (1<<5)
514 #define SEC_UNICAST_GROUP (1<<6)
515 #define SEC_LEVEL       (1<<7)
516 #define SEC_ENABLED     (1<<8)
517
518 #define SEC_LEVEL_0      0 /* None */
519 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
520 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
521 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
522 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
523
524 #define WEP_KEYS 4
525 #define WEP_KEY_LEN 13
526
527 /*
528
529  802.11 data frame from AP
530
531       ,-------------------------------------------------------------------.
532 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
533       |------|------|---------|---------|---------|------|---------|------|
534 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
535       |      | tion | (BSSID) |  |       | ence |  data   |      |
536       `-------------------------------------------------------------------'
537
538 Total: 28-2340 bytes
539
540 */
541
542 #define BEACON_PROBE_SSID_ID_POSITION 12
543
544 /* Management Frame Information Element Types */
545 #define MFIE_TYPE_SSID          0
546 #define MFIE_TYPE_RATES         1
547 #define MFIE_TYPE_FH_SET        2
548 #define MFIE_TYPE_DS_SET        3
549 #define MFIE_TYPE_CF_SET        4
550 #define MFIE_TYPE_TIM           5
551 #define MFIE_TYPE_IBSS_SET      6
552 #define MFIE_TYPE_CHALLENGE     16
553 #define MFIE_TYPE_ERP           42
554 #define MFIE_TYPE_RSN           48
555 #define MFIE_TYPE_RATES_EX      50
556 #define MFIE_TYPE_GENERIC       221
557
558 /*
559  * These are the data types that can make up management packets
560  *
561         u16 auth_algorithm;
562         u16 auth_sequence;
563         u16 beacon_interval;
564         u16 capability;
565         u8 current_ap[ETH_ALEN];
566         u16 listen_interval;
567         struct {
568                 u16 association_id:14, reserved:2;
569         } __packed;
570         u32 time_stamp[2];
571         u16 reason;
572         u16 status;
573 */
574
575 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
576 #define IEEE80211_DEFAULT_BASIC_RATE 10
577
578 /* SWEEP TABLE ENTRIES NUMBER*/
579 #define MAX_SWEEP_TAB_ENTRIES             42
580 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
581 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
582  * only use 8, and then use extended rates for the remaining supported
583  * rates.  Other APs, however, stick all of their supported rates on the
584  * main rates information element... */
585 #define MAX_RATES_LENGTH                ((u8)12)
586 #define MAX_RATES_EX_LENGTH             ((u8)16)
587 #define MAX_NETWORK_COUNT               128
588 #define MAX_CHANNEL_NUMBER              161
589 #define IEEE80211_SOFTMAC_SCAN_TIME     400
590 /* HZ / 2) */
591 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
592
593 #define CRC_LENGTH               4U
594
595 #define MAX_WPA_IE_LEN (256)
596 #define MAX_WPS_IE_LEN (512)
597 #define MAX_P2P_IE_LEN (256)
598 #define MAX_WFD_IE_LEN (128)
599
600 #define NETWORK_EMPTY_ESSID (1<<0)
601 #define NETWORK_HAS_OFDM    (1<<1)
602 #define NETWORK_HAS_CCK     (1<<2)
603
604 #define IEEE80211_DTIM_MBCAST 4
605 #define IEEE80211_DTIM_UCAST 2
606 #define IEEE80211_DTIM_VALID 1
607 #define IEEE80211_DTIM_INVALID 0
608
609 #define IEEE80211_PS_DISABLED 0
610 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
611 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
612 #define IW_ESSID_MAX_SIZE 32
613 /*
614 join_res:
615 -1: authentication fail
616 -2: association fail
617 > 0: TID
618 */
619
620 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
621 #define DEFAULT_FTS 2346
622
623 static inline int is_multicast_mac_addr(const u8 *addr)
624 {
625         return ((addr[0] != 0xff) && (0x01 & addr[0]));
626 }
627
628 static inline int is_broadcast_mac_addr(const u8 *addr)
629 {
630         return (addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
631                (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff);
632 }
633
634 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
635 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
636
637 #define MAXTID  16
638
639 #define IEEE_A      (1<<0)
640 #define IEEE_B      (1<<1)
641 #define IEEE_G      (1<<2)
642 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
643
644 /* Action category code */
645 enum rtw_ieee80211_category {
646         RTW_WLAN_CATEGORY_SPECTRUM_MGMT = 0,
647         RTW_WLAN_CATEGORY_QOS = 1,
648         RTW_WLAN_CATEGORY_DLS = 2,
649         RTW_WLAN_CATEGORY_BACK = 3,
650         RTW_WLAN_CATEGORY_PUBLIC = 4, /* IEEE 802.11 public action frames */
651         RTW_WLAN_CATEGORY_RADIO_MEASUREMENT  = 5,
652         RTW_WLAN_CATEGORY_FT = 6,
653         RTW_WLAN_CATEGORY_HT = 7,
654         RTW_WLAN_CATEGORY_SA_QUERY = 8,
655         RTW_WLAN_CATEGORY_TDLS = 12,
656         RTW_WLAN_CATEGORY_WMM = 17,
657         RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */
658 };
659
660 /* SPECTRUM_MGMT action code */
661 enum rtw_ieee80211_spectrum_mgmt_actioncode {
662         RTW_WLAN_ACTION_SPCT_MSR_REQ = 0,
663         RTW_WLAN_ACTION_SPCT_MSR_RPRT = 1,
664         RTW_WLAN_ACTION_SPCT_TPC_REQ = 2,
665         RTW_WLAN_ACTION_SPCT_TPC_RPRT = 3,
666         RTW_WLAN_ACTION_SPCT_CHL_SWITCH = 4,
667         RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5,
668 };
669
670 enum _PUBLIC_ACTION {
671         ACT_PUBLIC_BSSCOEXIST = 0, /*  20/40 BSS Coexistence */
672         ACT_PUBLIC_DSE_ENABLE = 1,
673         ACT_PUBLIC_DSE_DEENABLE = 2,
674         ACT_PUBLIC_DSE_REG_LOCATION = 3,
675         ACT_PUBLIC_EXT_CHL_SWITCH = 4,
676         ACT_PUBLIC_DSE_MSR_REQ = 5,
677         ACT_PUBLIC_DSE_MSR_RPRT = 6,
678         ACT_PUBLIC_MP = 7, /*  Measurement Pilot */
679         ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8,
680         ACT_PUBLIC_VENDOR = 9, /*  for WIFI_DIRECT */
681         ACT_PUBLIC_GAS_INITIAL_REQ = 10,
682         ACT_PUBLIC_GAS_INITIAL_RSP = 11,
683         ACT_PUBLIC_GAS_COMEBACK_REQ = 12,
684         ACT_PUBLIC_GAS_COMEBACK_RSP = 13,
685         ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14,
686         ACT_PUBLIC_LOCATION_TRACK = 15,
687         ACT_PUBLIC_MAX
688 };
689
690 /* BACK action code */
691 enum rtw_ieee80211_back_actioncode {
692         RTW_WLAN_ACTION_ADDBA_REQ = 0,
693         RTW_WLAN_ACTION_ADDBA_RESP = 1,
694         RTW_WLAN_ACTION_DELBA = 2,
695 };
696
697 #define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
698                                 * 00:50:F2 */
699 #define WME_OUI_TYPE 2
700 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
701 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
702 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
703 #define WME_VERSION 1
704
705 #define WME_ACTION_CODE_SETUP_REQUEST 0
706 #define WME_ACTION_CODE_SETUP_RESPONSE 1
707 #define WME_ACTION_CODE_TEARDOWN 2
708
709 #define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0
710 #define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1
711 #define WME_SETUP_RESPONSE_STATUS_REFUSED 3
712
713 #define WME_TSPEC_DIRECTION_UPLINK 0
714 #define WME_TSPEC_DIRECTION_DOWNLINK 1
715 #define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3
716
717 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
718
719 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
720
721 /**
722  * enum rtw_ieee80211_channel_flags - channel flags
723  *
724  * Channel flags set by the regulatory control code.
725  *
726  * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled.
727  * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
728  *      on this channel.
729  * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
730  * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
731  * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
732  *      is not permitted.
733  * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
734  *      is not permitted.
735  */
736 enum rtw_ieee80211_channel_flags {
737         RTW_IEEE80211_CHAN_DISABLED      = 1<<0,
738         RTW_IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
739         RTW_IEEE80211_CHAN_NO_IBSS        = 1<<2,
740         RTW_IEEE80211_CHAN_RADAR            = 1<<3,
741         RTW_IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
742         RTW_IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
743 };
744
745 #define RTW_IEEE80211_CHAN_NO_HT40 \
746           (RTW_IEEE80211_CHAN_NO_HT40PLUS | RTW_IEEE80211_CHAN_NO_HT40MINUS)
747
748 /* Represent channel details, subset of ieee80211_channel */
749 struct rtw_ieee80211_channel {
750         u16 hw_value;
751         u32 flags;
752 };
753
754 #define CHAN_FMT \
755         "hw_value:%u, " \
756         "flags:0x%08x" \
757
758 #define CHAN_ARG(channel) \
759         (channel)->hw_value \
760         , (channel)->flags \
761
762 /* Parsed Information Elements */
763 struct rtw_ieee802_11_elems {
764         u8 *ssid;
765         u8 ssid_len;
766         u8 *supp_rates;
767         u8 supp_rates_len;
768         u8 *fh_params;
769         u8 fh_params_len;
770         u8 *ds_params;
771         u8 ds_params_len;
772         u8 *cf_params;
773         u8 cf_params_len;
774         u8 *tim;
775         u8 tim_len;
776         u8 *ibss_params;
777         u8 ibss_params_len;
778         u8 *challenge;
779         u8 challenge_len;
780         u8 *erp_info;
781         u8 erp_info_len;
782         u8 *ext_supp_rates;
783         u8 ext_supp_rates_len;
784         u8 *wpa_ie;
785         u8 wpa_ie_len;
786         u8 *rsn_ie;
787         u8 rsn_ie_len;
788         u8 *wme;
789         u8 wme_len;
790         u8 *wme_tspec;
791         u8 wme_tspec_len;
792         u8 *wps_ie;
793         u8 wps_ie_len;
794         u8 *power_cap;
795         u8 power_cap_len;
796         u8 *supp_channels;
797         u8 supp_channels_len;
798         u8 *mdie;
799         u8 mdie_len;
800         u8 *ftie;
801         u8 ftie_len;
802         u8 *timeout_int;
803         u8 timeout_int_len;
804         u8 *ht_capabilities;
805         u8 ht_capabilities_len;
806         u8 *ht_operation;
807         u8 ht_operation_len;
808         u8 *vendor_ht_cap;
809         u8 vendor_ht_cap_len;
810 };
811
812 enum parse_res {
813         ParseOK = 0,
814         ParseUnknown = 1,
815         ParseFailed = -1
816 };
817
818 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
819                                           struct rtw_ieee802_11_elems *elems,
820                                           int show_errors);
821
822 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len,
823                      unsigned char *source, unsigned int *frlen);
824 u8 *rtw_set_ie(u8 *pbuf, int index, uint len, u8 *source, uint *frlen);
825 u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit);
826
827 void rtw_set_supported_rate(u8 *SupportedRates, uint mode);
828
829 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit);
830 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit);
831 int rtw_get_wpa_cipher_suite(u8 *s);
832 int rtw_get_wpa2_cipher_suite(u8 *s);
833 int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
834 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
835                      int *pairwise_cipher, int *is_8021x);
836 int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
837                       int *pairwise_cipher, int *is_8021x);
838
839 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
840                    u8 *wpa_ie, u16 *wpa_len);
841
842 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
843 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
844 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
845                      u8 *buf_attr, u32 *len_attr);
846 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
847                              u8 *buf_content, uint *len_content);
848
849 /**
850  * for_each_ie - iterate over continuous IEs
851  * @ie:
852  * @buf:
853  * @buf_len:
854  */
855 #define for_each_ie(ie, buf, buf_len) \
856         for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len;        \
857                 ie = (void *)(((u8 *)ie) + *(((u8 *)ie)+1) + 2))
858
859 u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen);
860 u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
861                      u8 *buf_attr, u32 *len_attr);
862 u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
863                              u8 *buf_content, uint *len_content);
864 u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len,
865                              u8 *pdata_attr);
866 void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex,
867                                        u8 attr_id);
868 uint    rtw_get_rateset_len(u8  *rateset);
869
870 struct registry_priv;
871 int rtw_generate_ie(struct registry_priv *pregistrypriv);
872
873 int rtw_get_bit_value_from_ieee_value(u8 val);
874
875 uint    rtw_is_cckrates_included(u8 *rate);
876
877 uint    rtw_is_cckratesonly_included(u8 *rate);
878
879 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
880
881 void rtw_get_bcn_info(struct wlan_network *pnetwork);
882
883 void rtw_macaddr_cfg(u8 *mac_addr);
884
885 u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate);
886
887 #endif /* IEEE80211_H */