• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  ******************************************************************************/
15 #ifndef __IEEE80211_H
16 #define __IEEE80211_H
17 
18 #include <osdep_service.h>
19 #include <drv_types.h>
20 #include "linux/ieee80211.h"
21 #include "wifi.h"
22 
23 #include <linux/wireless.h>
24 
25 #if (WIRELESS_EXT < 22)
26 #error "Obsolete pre 2007 wireless extensions are not supported"
27 #endif
28 
29 
30 #ifdef CONFIG_8723AU_AP_MODE
31 
32 /* STA flags */
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)
48 
49 #endif
50 
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)
56 
57 
58 
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[];
71 
72 
73 #define RSN_HEADER_LEN 4
74 #define RSN_SELECTOR_LEN 4
75 
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[];
84 
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,
95 };
96 
97 enum NETWORK_TYPE
98 {
99 	WIRELESS_INVALID = 0,
100 	/* Sub-Element */
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),
113 
114 	/* Combination */
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 |
125 				WIRELESS_11_5N,
126 	WIRELESS_11ABGN = WIRELESS_11A | WIRELESS_11B | WIRELESS_11G |
127 				WIRELESS_11_24N | WIRELESS_11_5N,
128 };
129 
130 #define SUPPORTED_24G_NETTYPE_MSK (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N)
131 #define SUPPORTED_5G_NETTYPE_MSK (WIRELESS_11A | WIRELESS_11_5N)
132 
133 #define IsSupported24G(NetType) (NetType & SUPPORTED_24G_NETTYPE_MSK ? true : false)
134 #define IsSupported5G(NetType) (NetType & SUPPORTED_5G_NETTYPE_MSK ? true : false)
135 
136 #define IsEnableHWCCK(NetType) IsSupported24G(NetType)
137 #define IsEnableHWOFDM(NetType) (NetType & (WIRELESS_11G|WIRELESS_11_24N|SUPPORTED_5G_NETTYPE_MSK) ? true : false)
138 
139 #define IsSupportedRxCCK(NetType) IsEnableHWCCK(NetType)
140 #define IsSupportedRxOFDM(NetType) IsEnableHWOFDM(NetType)
141 #define IsSupportedRxMCS(NetType) IsEnableHWOFDM(NetType)
142 
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)
146 
147 
148 #define MIN_FRAG_THRESHOLD     256U
149 #define	MAX_FRAG_THRESHOLD     2346U
150 
151 /* QoS,QOS */
152 #define NORMAL_ACK			0
153 #define NO_ACK				1
154 #define NON_EXPLICIT_ACK		2
155 #define BLOCK_ACK			3
156 
157 /* IEEE 802.11 defines */
158 
159 #define P80211_OUI_LEN 3
160 
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));
167 
168 
169 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
170 
171 #define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
172 #define WLAN_REASON_EXPIRATION_CHK 65535
173 
174 
175 #define IEEE80211_STATMASK_SIGNAL (1<<0)
176 #define IEEE80211_STATMASK_RSSI (1<<1)
177 #define IEEE80211_STATMASK_NOISE (1<<2)
178 #define IEEE80211_STATMASK_RATE (1<<3)
179 #define IEEE80211_STATMASK_WEMASK 0x7
180 
181 
182 #define IEEE80211_CCK_MODULATION    (1<<0)
183 #define IEEE80211_OFDM_MODULATION   (1<<1)
184 
185 #define IEEE80211_24GHZ_BAND     (1<<0)
186 #define IEEE80211_52GHZ_BAND     (1<<1)
187 
188 #define IEEE80211_CCK_RATE_LEN			4
189 #define IEEE80211_NUM_OFDM_RATESLEN	8
190 
191 
192 #define IEEE80211_CCK_RATE_1MB		        0x02
193 #define IEEE80211_CCK_RATE_2MB		        0x04
194 #define IEEE80211_CCK_RATE_5MB		        0x0B
195 #define IEEE80211_CCK_RATE_11MB		        0x16
196 #define IEEE80211_OFDM_RATE_LEN			8
197 #define IEEE80211_OFDM_RATE_6MB		        0x0C
198 #define IEEE80211_OFDM_RATE_9MB		        0x12
199 #define IEEE80211_OFDM_RATE_12MB		0x18
200 #define IEEE80211_OFDM_RATE_18MB		0x24
201 #define IEEE80211_OFDM_RATE_24MB		0x30
202 #define IEEE80211_OFDM_RATE_36MB		0x48
203 #define IEEE80211_OFDM_RATE_48MB		0x60
204 #define IEEE80211_OFDM_RATE_54MB		0x6C
205 #define IEEE80211_BASIC_RATE_MASK		0x80
206 
207 #define IEEE80211_CCK_RATE_1MB_MASK		(1<<0)
208 #define IEEE80211_CCK_RATE_2MB_MASK		(1<<1)
209 #define IEEE80211_CCK_RATE_5MB_MASK		(1<<2)
210 #define IEEE80211_CCK_RATE_11MB_MASK		(1<<3)
211 #define IEEE80211_OFDM_RATE_6MB_MASK		(1<<4)
212 #define IEEE80211_OFDM_RATE_9MB_MASK		(1<<5)
213 #define IEEE80211_OFDM_RATE_12MB_MASK		(1<<6)
214 #define IEEE80211_OFDM_RATE_18MB_MASK		(1<<7)
215 #define IEEE80211_OFDM_RATE_24MB_MASK		(1<<8)
216 #define IEEE80211_OFDM_RATE_36MB_MASK		(1<<9)
217 #define IEEE80211_OFDM_RATE_48MB_MASK		(1<<10)
218 #define IEEE80211_OFDM_RATE_54MB_MASK		(1<<11)
219 
220 #define IEEE80211_CCK_RATES_MASK	        0x0000000F
221 #define IEEE80211_CCK_BASIC_RATES_MASK	(IEEE80211_CCK_RATE_1MB_MASK | \
222 	IEEE80211_CCK_RATE_2MB_MASK)
223 #define IEEE80211_CCK_DEFAULT_RATES_MASK	(IEEE80211_CCK_BASIC_RATES_MASK | \
224 	IEEE80211_CCK_RATE_5MB_MASK | \
225 	IEEE80211_CCK_RATE_11MB_MASK)
226 
227 #define IEEE80211_OFDM_RATES_MASK		0x00000FF0
228 #define IEEE80211_OFDM_BASIC_RATES_MASK	(IEEE80211_OFDM_RATE_6MB_MASK | \
229 	IEEE80211_OFDM_RATE_12MB_MASK | \
230 	IEEE80211_OFDM_RATE_24MB_MASK)
231 #define IEEE80211_OFDM_DEFAULT_RATES_MASK	(IEEE80211_OFDM_BASIC_RATES_MASK | \
232 	IEEE80211_OFDM_RATE_9MB_MASK  | \
233 	IEEE80211_OFDM_RATE_18MB_MASK | \
234 	IEEE80211_OFDM_RATE_36MB_MASK | \
235 	IEEE80211_OFDM_RATE_48MB_MASK | \
236 	IEEE80211_OFDM_RATE_54MB_MASK)
237 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
238 				      IEEE80211_CCK_DEFAULT_RATES_MASK)
239 
240 #define IEEE80211_NUM_OFDM_RATES	    8
241 #define IEEE80211_NUM_CCK_RATES	            4
242 #define IEEE80211_OFDM_SHIFT_MASK_A         4
243 
244 #define WEP_KEYS 4
245 
246 
247 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
248  * only use 8, and then use extended rates for the remaining supported
249  * rates.  Other APs, however, stick all of their supported rates on the
250  * main rates information element... */
251 #define MAX_RATES_LENGTH	12
252 #define MAX_RATES_EX_LENGTH	16
253 #define MAX_CHANNEL_NUMBER	161
254 #define RTW_CH_MAX_2G_CHANNEL	14	/* Max channel in 2G band */
255 
256 #define MAX_WPA_IE_LEN		256
257 #define MAX_WPS_IE_LEN		256
258 #define MAX_P2P_IE_LEN		256
259 #define MAX_WFD_IE_LEN		128
260 
261 /*
262 join_res:
263 -1: authentication fail
264 -2: association fail
265 > 0: TID
266 */
267 
268 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
269 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
270 
271 #define MAXTID	16
272 
273 #define WME_OUI_TYPE 2
274 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
275 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
276 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
277 #define WME_VERSION 1
278 
279 
280 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
281 
282 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
283 
284 /* Represent channel details, subset of ieee80211_channel */
285 struct rtw_ieee80211_channel {
286 	/* enum ieee80211_band band; */
287 	/* u16 center_freq; */
288 	u16 hw_value;
289 	u32 flags;
290 	/* int max_antenna_gain; */
291 	/* int max_power; */
292 	/* int max_reg_power; */
293 	/* bool beacon_found; */
294 	/* u32 orig_flags; */
295 	/* int orig_mag; */
296 	/* int orig_mpwr; */
297 };
298 
299 #define CHAN_FMT \
300 	/*"band:%d, "*/ \
301 	/*"center_freq:%u, "*/ \
302 	"hw_value:%u, " \
303 	"flags:0x%08x" \
304 	/*"max_antenna_gain:%d\n"*/ \
305 	/*"max_power:%d\n"*/ \
306 	/*"max_reg_power:%d\n"*/ \
307 	/*"beacon_found:%u\n"*/ \
308 	/*"orig_flags:0x%08x\n"*/ \
309 	/*"orig_mag:%d\n"*/ \
310 	/*"orig_mpwr:%d\n"*/
311 
312 #define CHAN_ARG(channel) \
313 	/*(channel)->band*/ \
314 	/*, (channel)->center_freq*/ \
315 	(channel)->hw_value \
316 	, (channel)->flags \
317 	/*, (channel)->max_antenna_gain*/ \
318 	/*, (channel)->max_power*/ \
319 	/*, (channel)->max_reg_power*/ \
320 	/*, (channel)->beacon_found*/ \
321 	/*, (channel)->orig_flags*/ \
322 	/*, (channel)->orig_mag*/ \
323 	/*, (channel)->orig_mpwr*/ \
324 
325 u8 *rtw_set_ie23a(u8 *pbuf, int index, uint len, const u8 *source, uint *frlen);
326 
327 u8 hal_ch_offset_to_secondary_ch_offset23a(u8 ch_offset);
328 u8 *rtw_set_ie23a_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode, u8 new_ch, u8 ch_switch_cnt);
329 u8 *rtw_set_ie23a_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset);
330 
331 u8 *rtw_get_ie23a(u8*pbuf, int index, int *len, int limit);
332 u8 *rtw_get_ie23a_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen);
333 int rtw_ies_remove_ie23a(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len);
334 
335 void rtw_set_supported_rate23a(u8 *SupportedRates, uint mode);
336 
337 int rtw_parse_wpa_ie23a(const u8* wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
338 int rtw_parse_wpa2_ie23a(const u8* wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x);
339 
340 const u8 *rtw_get_wps_attr23a(const u8 *wps_ie, uint wps_ielen, u16 target_attr_id ,u8 *buf_attr, u32 *len_attr);
341 const u8 *rtw_get_wps_attr_content23a(const u8 *wps_ie, uint wps_ielen, u16 target_attr_id ,u8 *buf_content);
342 
343 uint	rtw_get_rateset_len23a(u8	*rateset);
344 
345 struct registry_priv;
346 int rtw_generate_ie23a(struct registry_priv *pregistrypriv);
347 
348 
349 int rtw_get_bit_value_from_ieee_value23a(u8 val);
350 
351 int rtw_check_network_type23a(unsigned char *rate, int ratelen, int channel);
352 
353 void rtw_get_bcn_info23a(struct wlan_network *pnetwork);
354 
355 u16 rtw_mcs_rate23a(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40,
356 		    struct ieee80211_mcs_info *mcs);
357 
358 #endif /* IEEE80211_H */
359