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