1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 ******************************************************************************/
18 #include <osdep_service.h>
19 #include <drv_types.h>
20 #include "linux/ieee80211.h"
23 #include <linux/wireless.h>
25 #if (WIRELESS_EXT < 22)
26 #error "Obsolete pre 2007 wireless extensions are not supported"
30 #ifdef CONFIG_8723AU_AP_MODE
33 #define WLAN_STA_AUTH BIT(0)
34 #define WLAN_STA_ASSOC BIT(1)
35 #define WLAN_STA_PS BIT(2)
36 #define WLAN_STA_TIM BIT(3)
37 #define WLAN_STA_PERM BIT(4)
38 #define WLAN_STA_AUTHORIZED BIT(5)
39 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
40 #define WLAN_STA_SHORT_PREAMBLE BIT(7)
41 #define WLAN_STA_PREAUTH BIT(8)
42 #define WLAN_STA_WME BIT(9)
43 #define WLAN_STA_MFP BIT(10)
44 #define WLAN_STA_HT BIT(11)
45 #define WLAN_STA_WPS BIT(12)
46 #define WLAN_STA_MAYBE_WPS BIT(13)
47 #define WLAN_STA_NONERP BIT(31)
51 #define WPA_CIPHER_NONE BIT(0)
52 #define WPA_CIPHER_WEP40 BIT(1)
53 #define WPA_CIPHER_WEP104 BIT(2)
54 #define WPA_CIPHER_TKIP BIT(3)
55 #define WPA_CIPHER_CCMP BIT(4)
59 #define WPA_SELECTOR_LEN 4
60 extern u8 RTW_WPA_OUI23A_TYPE
[] ;
61 extern u16 RTW_WPA_VERSION23A
;
62 extern u8 WPA_AUTH_KEY_MGMT_NONE23A
[];
63 extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X23A
[];
64 extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X23A
[];
65 extern u8 WPA_CIPHER_SUITE_NONE23A
[];
66 extern u8 WPA_CIPHER_SUITE_WEP4023A
[];
67 extern u8 WPA_CIPHER_SUITE_TKIP23A
[];
68 extern u8 WPA_CIPHER_SUITE_WRAP23A
[];
69 extern u8 WPA_CIPHER_SUITE_CCMP23A
[];
70 extern u8 WPA_CIPHER_SUITE_WEP10423A
[];
73 #define RSN_HEADER_LEN 4
74 #define RSN_SELECTOR_LEN 4
76 extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X23A
[];
77 extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X23A
[];
78 extern u8 RSN_CIPHER_SUITE_NONE23A
[];
79 extern u8 RSN_CIPHER_SUITE_WEP4023A
[];
80 extern u8 RSN_CIPHER_SUITE_TKIP23A
[];
81 extern u8 RSN_CIPHER_SUITE_WRAP23A
[];
82 extern u8 RSN_CIPHER_SUITE_CCMP23A
[];
83 extern u8 RSN_CIPHER_SUITE_WEP10423A
[];
85 enum ratr_table_mode
{
86 RATR_INX_WIRELESS_NGB
= 0, /* BGN 40 Mhz 2SS 1SS */
87 RATR_INX_WIRELESS_NG
= 1, /* GN or N */
88 RATR_INX_WIRELESS_NB
= 2, /* BGN 20 Mhz 2SS 1SS or BN */
89 RATR_INX_WIRELESS_N
= 3,
90 RATR_INX_WIRELESS_GB
= 4,
91 RATR_INX_WIRELESS_G
= 5,
92 RATR_INX_WIRELESS_B
= 6,
93 RATR_INX_WIRELESS_MC
= 7,
94 RATR_INX_WIRELESS_AC_N
= 8,
101 /* tx: cck only , rx: cck only, hw: cck */
102 WIRELESS_11B
= BIT(0),
103 /* tx: ofdm only, rx: ofdm & cck, hw: cck & ofdm */
104 WIRELESS_11G
= BIT(1),
105 /* tx: ofdm only, rx: ofdm only, hw: ofdm only */
106 WIRELESS_11A
= BIT(2),
107 /* tx: MCS only, rx: MCS & cck, hw: MCS & cck */
108 WIRELESS_11_24N
= BIT(3),
109 /* tx: MCS only, rx: MCS & ofdm, hw: ofdm only */
110 WIRELESS_11_5N
= BIT(4),
111 /* WIRELESS_AUTO = BIT(5), */
112 WIRELESS_AC
= BIT(6),
115 /* tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
116 WIRELESS_11BG
= WIRELESS_11B
|WIRELESS_11G
,
117 /* tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
118 WIRELESS_11G_24N
= WIRELESS_11G
| WIRELESS_11_24N
,
119 /* tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
120 WIRELESS_11A_5N
= WIRELESS_11A
| WIRELESS_11_5N
,
121 /* tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
122 WIRELESS_11BG_24N
= WIRELESS_11B
| WIRELESS_11G
| WIRELESS_11_24N
,
123 /* tx: ofdm & MCS, rx: ofdm & MCS, hw: ofdm only */
124 WIRELESS_11AGN
= WIRELESS_11A
| WIRELESS_11G
| WIRELESS_11_24N
|
126 WIRELESS_11ABGN
= WIRELESS_11A
| WIRELESS_11B
| WIRELESS_11G
|
127 WIRELESS_11_24N
| WIRELESS_11_5N
,
130 #define SUPPORTED_24G_NETTYPE_MSK (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N)
131 #define SUPPORTED_5G_NETTYPE_MSK (WIRELESS_11A | WIRELESS_11_5N)
133 #define IsSupported24G(NetType) (NetType & SUPPORTED_24G_NETTYPE_MSK ? true : false)
134 #define IsSupported5G(NetType) (NetType & SUPPORTED_5G_NETTYPE_MSK ? true : false)
136 #define IsEnableHWCCK(NetType) IsSupported24G(NetType)
137 #define IsEnableHWOFDM(NetType) (NetType & (WIRELESS_11G|WIRELESS_11_24N|SUPPORTED_5G_NETTYPE_MSK) ? true : false)
139 #define IsSupportedRxCCK(NetType) IsEnableHWCCK(NetType)
140 #define IsSupportedRxOFDM(NetType) IsEnableHWOFDM(NetType)
141 #define IsSupportedRxMCS(NetType) IsEnableHWOFDM(NetType)
143 #define IsSupportedTxCCK(NetType) (NetType & (WIRELESS_11B) ? true : false)
144 #define IsSupportedTxOFDM(NetType) (NetType & (WIRELESS_11G|WIRELESS_11A) ? true : false)
145 #define IsSupportedTxMCS(NetType) (NetType & (WIRELESS_11_24N|WIRELESS_11_5N) ? true : false)
148 #define MIN_FRAG_THRESHOLD 256U
149 #define MAX_FRAG_THRESHOLD 2346U
154 #define NON_EXPLICIT_ACK 2
157 /* IEEE 802.11 defines */
159 #define P80211_OUI_LEN 3
161 struct ieee80211_snap_hdr
{
162 u8 dsap
; /* always 0xAA */
163 u8 ssap
; /* always 0xAA */
164 u8 ctrl
; /* always 0x03 */
165 u8 oui
[P80211_OUI_LEN
]; /* organizational universal id */
166 } __attribute__ ((packed
));
169 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
171 #define WLAN_REASON_JOIN_WRONG_CHANNEL 65534
172 #define WLAN_REASON_EXPIRATION_CHK 65535
174 #define IEEE80211_CCK_RATE_LEN 4
175 #define IEEE80211_NUM_OFDM_RATESLEN 8
178 #define IEEE80211_CCK_RATE_1MB 0x02
179 #define IEEE80211_CCK_RATE_2MB 0x04
180 #define IEEE80211_CCK_RATE_5MB 0x0B
181 #define IEEE80211_CCK_RATE_11MB 0x16
182 #define IEEE80211_OFDM_RATE_LEN 8
183 #define IEEE80211_OFDM_RATE_6MB 0x0C
184 #define IEEE80211_OFDM_RATE_9MB 0x12
185 #define IEEE80211_OFDM_RATE_12MB 0x18
186 #define IEEE80211_OFDM_RATE_18MB 0x24
187 #define IEEE80211_OFDM_RATE_24MB 0x30
188 #define IEEE80211_OFDM_RATE_36MB 0x48
189 #define IEEE80211_OFDM_RATE_48MB 0x60
190 #define IEEE80211_OFDM_RATE_54MB 0x6C
191 #define IEEE80211_BASIC_RATE_MASK 0x80
193 #define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
194 #define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
195 #define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
196 #define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
197 #define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
198 #define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
199 #define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
200 #define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
201 #define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
202 #define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
203 #define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
204 #define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
206 #define IEEE80211_CCK_RATES_MASK 0x0000000F
207 #define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \
208 IEEE80211_CCK_RATE_2MB_MASK)
209 #define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
210 IEEE80211_CCK_RATE_5MB_MASK | \
211 IEEE80211_CCK_RATE_11MB_MASK)
213 #define IEEE80211_OFDM_RATES_MASK 0x00000FF0
214 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
215 IEEE80211_OFDM_RATE_12MB_MASK | \
216 IEEE80211_OFDM_RATE_24MB_MASK)
217 #define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
218 IEEE80211_OFDM_RATE_9MB_MASK | \
219 IEEE80211_OFDM_RATE_18MB_MASK | \
220 IEEE80211_OFDM_RATE_36MB_MASK | \
221 IEEE80211_OFDM_RATE_48MB_MASK | \
222 IEEE80211_OFDM_RATE_54MB_MASK)
223 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
224 IEEE80211_CCK_DEFAULT_RATES_MASK)
226 #define IEEE80211_NUM_OFDM_RATES 8
227 #define IEEE80211_NUM_CCK_RATES 4
228 #define IEEE80211_OFDM_SHIFT_MASK_A 4
233 /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
234 * only use 8, and then use extended rates for the remaining supported
235 * rates. Other APs, however, stick all of their supported rates on the
236 * main rates information element... */
237 #define MAX_RATES_LENGTH 12
238 #define MAX_RATES_EX_LENGTH 16
239 #define MAX_CHANNEL_NUMBER 161
240 #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
242 #define MAX_WPA_IE_LEN 256
243 #define MAX_WPS_IE_LEN 256
244 #define MAX_P2P_IE_LEN 256
245 #define MAX_WFD_IE_LEN 128
249 -1: authentication fail
254 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
255 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
259 #define WME_OUI_TYPE 2
260 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
261 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
262 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
263 #define WME_VERSION 1
266 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
268 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
270 /* Represent channel details, subset of ieee80211_channel */
271 struct rtw_ieee80211_channel
{
272 /* enum ieee80211_band band; */
273 /* u16 center_freq; */
276 /* int max_antenna_gain; */
278 /* int max_reg_power; */
279 /* bool beacon_found; */
280 /* u32 orig_flags; */
287 /*"center_freq:%u, "*/ \
290 /*"max_antenna_gain:%d\n"*/ \
291 /*"max_power:%d\n"*/ \
292 /*"max_reg_power:%d\n"*/ \
293 /*"beacon_found:%u\n"*/ \
294 /*"orig_flags:0x%08x\n"*/ \
295 /*"orig_mag:%d\n"*/ \
298 #define CHAN_ARG(channel) \
299 /*(channel)->band*/ \
300 /*, (channel)->center_freq*/ \
301 (channel)->hw_value \
303 /*, (channel)->max_antenna_gain*/ \
304 /*, (channel)->max_power*/ \
305 /*, (channel)->max_reg_power*/ \
306 /*, (channel)->beacon_found*/ \
307 /*, (channel)->orig_flags*/ \
308 /*, (channel)->orig_mag*/ \
309 /*, (channel)->orig_mpwr*/ \
311 u8 *rtw_set_ie23a(u8 *pbuf, int index, uint len, const u8 *source, uint *frlen);
313 u8
hal_ch_offset_to_secondary_ch_offset23a(u8 ch_offset
);
314 u8
*rtw_set_ie23a_ch_switch(u8
*buf
, u32
*buf_len
, u8 ch_switch_mode
, u8 new_ch
, u8 ch_switch_cnt
);
315 u8
*rtw_set_ie23a_secondary_ch_offset(u8
*buf
, u32
*buf_len
, u8 secondary_ch_offset
);
317 u8
*rtw_get_ie23a(u8
*pbuf
, int index
, int *len
, int limit
);
318 u8
*rtw_get_ie23a_ex(u8
*in_ie
, uint in_len
, u8 eid
, u8
*oui
, u8 oui_len
, u8
*ie
, uint
*ielen
);
319 int rtw_ies_remove_ie23a(u8
*ies
, uint
*ies_len
, uint offset
, u8 eid
, u8
*oui
, u8 oui_len
);
321 void rtw_set_supported_rate23a(u8
*SupportedRates
, uint mode
);
323 int rtw_parse_wpa_ie23a(const u8
* wpa_ie
, int wpa_ie_len
, int *group_cipher
, int *pairwise_cipher
, int *is_8021x
);
324 int rtw_parse_wpa2_ie23a(const u8
* wpa_ie
, int wpa_ie_len
, int *group_cipher
, int *pairwise_cipher
, int *is_8021x
);
326 const u8
*rtw_get_wps_attr23a(const u8
*wps_ie
, uint wps_ielen
, u16 target_attr_id
,u8
*buf_attr
, u32
*len_attr
);
327 const u8
*rtw_get_wps_attr_content23a(const u8
*wps_ie
, uint wps_ielen
, u16 target_attr_id
,u8
*buf_content
);
329 uint
rtw_get_rateset_len23a(u8
*rateset
);
331 struct registry_priv
;
332 int rtw_generate_ie23a(struct registry_priv
*pregistrypriv
);
335 int rtw_get_bit_value_from_ieee_value23a(u8 val
);
337 int rtw_check_network_type23a(unsigned char *rate
, int ratelen
, int channel
);
339 void rtw_get_bcn_info23a(struct wlan_network
*pnetwork
);
341 u16
rtw_mcs_rate23a(u8 rf_type
, u8 bw_40MHz
, u8 short_GI_20
, u8 short_GI_40
,
342 struct ieee80211_mcs_info
*mcs
);
344 #endif /* IEEE80211_H */