xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/core/rtw_wlan_util.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2021 Realtek Corporation.
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 #define _RTW_WLAN_UTIL_C_
16 
17 #include <drv_types.h>
18 
19 unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
20 unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
21 
22 unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
23 unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
24 unsigned char BROADCOM_OUI3[] = {0x00, 0x05, 0xb5};
25 
26 
27 unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
28 unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
29 unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
30 unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
31 unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
32 
33 unsigned char REALTEK_96B_IE[] = {0x00, 0xe0, 0x4c, 0x02, 0x01, 0x20};
34 
35 extern unsigned char RTW_WPA_OUI[];
36 extern unsigned char WPA_TKIP_CIPHER[4];
37 extern unsigned char RSN_TKIP_CIPHER[4];
38 
39 #define R2T_PHY_DELAY	(0)
40 
41 /* #define WAIT_FOR_BCN_TO_MIN	(3000) */
42 #define WAIT_FOR_BCN_TO_MIN	(6000)
43 #define WAIT_FOR_BCN_TO_MAX	(20000)
44 
45 static u8 rtw_basic_rate_cck[4] = {
46 	IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
47 	IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
48 };
49 
50 static u8 rtw_basic_rate_ofdm[3] = {
51 	IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
52 	IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
53 };
54 
55 static u8 rtw_basic_rate_mix[7] = {
56 	IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
57 	IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK,
58 	IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK, IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
59 	IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
60 };
61 
62 extern u8	WIFI_CCKRATES[];
rtw_is_cck_rate(u8 rate)63 bool rtw_is_cck_rate(u8 rate)
64 {
65 	int i;
66 
67 	for (i = 0; i < 4; i++)
68 		if ((WIFI_CCKRATES[i] & 0x7F) == (rate & 0x7F))
69 			return 1;
70 	return 0;
71 }
72 
73 extern u8	WIFI_OFDMRATES[];
rtw_is_ofdm_rate(u8 rate)74 bool rtw_is_ofdm_rate(u8 rate)
75 {
76 	int i;
77 
78 	for (i = 0; i < 8; i++)
79 		if ((WIFI_OFDMRATES[i] & 0x7F) == (rate & 0x7F))
80 			return 1;
81 	return 0;
82 }
83 
84 /* test if rate is defined in rtw_basic_rate_cck */
rtw_is_basic_rate_cck(u8 rate)85 bool rtw_is_basic_rate_cck(u8 rate)
86 {
87 	int i;
88 
89 	for (i = 0; i < 4; i++)
90 		if ((rtw_basic_rate_cck[i] & 0x7F) == (rate & 0x7F))
91 			return 1;
92 	return 0;
93 }
94 
95 /* test if rate is defined in rtw_basic_rate_ofdm */
rtw_is_basic_rate_ofdm(u8 rate)96 bool rtw_is_basic_rate_ofdm(u8 rate)
97 {
98 	int i;
99 
100 	for (i = 0; i < 3; i++)
101 		if ((rtw_basic_rate_ofdm[i] & 0x7F) == (rate & 0x7F))
102 			return 1;
103 	return 0;
104 }
105 
106 /* test if rate is defined in rtw_basic_rate_mix */
rtw_is_basic_rate_mix(u8 rate)107 bool rtw_is_basic_rate_mix(u8 rate)
108 {
109 	int i;
110 
111 	for (i = 0; i < 7; i++)
112 		if ((rtw_basic_rate_mix[i] & 0x7F) == (rate & 0x7F))
113 			return 1;
114 	return 0;
115 }
cckrates_included(unsigned char * rate,int ratelen)116 int cckrates_included(unsigned char *rate, int ratelen)
117 {
118 	int	i;
119 
120 	for (i = 0; i < ratelen; i++) {
121 		if ((((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
122 		    (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
123 			return _TRUE;
124 	}
125 
126 	return _FALSE;
127 
128 }
129 
cckratesonly_included(unsigned char * rate,int ratelen)130 int cckratesonly_included(unsigned char *rate, int ratelen)
131 {
132 	int	i;
133 
134 	for (i = 0; i < ratelen; i++) {
135 		if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
136 		    (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
137 			return _FALSE;
138 	}
139 
140 	return _TRUE;
141 }
142 
rtw_get_sta_rx_nss(_adapter * adapter,struct sta_info * psta)143 s8 rtw_get_sta_rx_nss(_adapter *adapter, struct sta_info *psta)
144 {
145 	s8 nss = 1;
146 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
147 
148 	if (!psta)
149 		return nss;
150 
151 	nss = get_phy_rx_nss(adapter);
152 
153 #ifdef CONFIG_80211N_HT
154 	#ifdef CONFIG_80211AC_VHT
155 	#ifdef CONFIG_80211AX_HE
156 	if (psta->hepriv.he_option)
157 		nss = psta->phl_sta->asoc_cap.nss_tx;
158 	else
159 	#endif /* CONFIG_80211AX_HE */
160 	if (psta->vhtpriv.vht_option)
161 		nss = rtw_min(nss, rtw_vht_mcsmap_to_nss(psta->vhtpriv.vht_mcs_map));
162 	else
163 	#endif /* CONFIG_80211AC_VHT */
164 	if (psta->htpriv.ht_option)
165 		nss = rtw_min(nss, rtw_ht_mcsset_to_nss(psta->htpriv.ht_cap.supp_mcs_set));
166 #endif /*CONFIG_80211N_HT*/
167 	RTW_INFO("%s: %d ss\n", __func__, nss);
168 	return nss;
169 }
170 
rtw_get_sta_tx_nss(_adapter * adapter,struct sta_info * psta)171 s8 rtw_get_sta_tx_nss(_adapter *adapter, struct sta_info *psta)
172 {
173 	s8 nss = 1;
174 
175 	if (!psta)
176 		return nss;
177 
178 	nss = get_phy_tx_nss(adapter);
179 
180 #ifdef CONFIG_80211N_HT
181 	#ifdef CONFIG_80211AC_VHT
182 	#ifdef CONFIG_80211AX_HE
183 	if (psta->hepriv.he_option)
184 		nss = psta->phl_sta->asoc_cap.nss_rx;
185 	else
186 	#endif /* CONFIG_80211AX_HE */
187 	if (psta->vhtpriv.vht_option)
188 		nss = rtw_min(nss, rtw_vht_mcsmap_to_nss(psta->vhtpriv.vht_mcs_map));
189 	else
190 	#endif /* CONFIG_80211AC_VHT */
191 	if (psta->htpriv.ht_option)
192 		nss = rtw_min(nss, rtw_ht_mcsset_to_nss(psta->htpriv.ht_cap.supp_mcs_set));
193 #endif /*CONFIG_80211N_HT*/
194 	RTW_INFO("%s: %d SS\n", __func__, nss);
195 	return nss;
196 }
197 
ratetbl_val_2wifirate(unsigned char rate)198 unsigned char ratetbl_val_2wifirate(unsigned char rate)
199 {
200 	unsigned char val = 0;
201 
202 	switch (rate & 0x7f) {
203 	case 0:
204 		val = IEEE80211_CCK_RATE_1MB;
205 		break;
206 
207 	case 1:
208 		val = IEEE80211_CCK_RATE_2MB;
209 		break;
210 
211 	case 2:
212 		val = IEEE80211_CCK_RATE_5MB;
213 		break;
214 
215 	case 3:
216 		val = IEEE80211_CCK_RATE_11MB;
217 		break;
218 
219 	case 4:
220 		val = IEEE80211_OFDM_RATE_6MB;
221 		break;
222 
223 	case 5:
224 		val = IEEE80211_OFDM_RATE_9MB;
225 		break;
226 
227 	case 6:
228 		val = IEEE80211_OFDM_RATE_12MB;
229 		break;
230 
231 	case 7:
232 		val = IEEE80211_OFDM_RATE_18MB;
233 		break;
234 
235 	case 8:
236 		val = IEEE80211_OFDM_RATE_24MB;
237 		break;
238 
239 	case 9:
240 		val = IEEE80211_OFDM_RATE_36MB;
241 		break;
242 
243 	case 10:
244 		val = IEEE80211_OFDM_RATE_48MB;
245 		break;
246 
247 	case 11:
248 		val = IEEE80211_OFDM_RATE_54MB;
249 		break;
250 
251 	}
252 
253 	return val;
254 
255 }
256 
is_basicrate(_adapter * padapter,unsigned char rate)257 int is_basicrate(_adapter *padapter, unsigned char rate)
258 {
259 	int i;
260 	unsigned char val;
261 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
262 
263 	for (i = 0; i < NumRates; i++) {
264 		val = pmlmeext->basicrate[i];
265 
266 		if ((val != 0xff) && (val != 0xfe)) {
267 			if (rate == ratetbl_val_2wifirate(val))
268 				return _TRUE;
269 		}
270 	}
271 
272 	return _FALSE;
273 }
274 
ratetbl2rateset(_adapter * padapter,unsigned char * rateset)275 unsigned int ratetbl2rateset(_adapter *padapter, unsigned char *rateset)
276 {
277 	int i;
278 	unsigned char rate;
279 	unsigned int	len = 0;
280 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
281 
282 	for (i = 0; i < NumRates; i++) {
283 		rate = pmlmeext->datarate[i];
284 
285 		if (rtw_get_oper_ch(padapter) > 14 && rate < _6M_RATE_) /*5G no support CCK rate*/
286 			continue;
287 
288 		switch (rate) {
289 		case 0xff:
290 			return len;
291 
292 		case 0xfe:
293 			continue;
294 
295 		default:
296 			rate = ratetbl_val_2wifirate(rate);
297 
298 			if (is_basicrate(padapter, rate) == _TRUE)
299 				rate |= IEEE80211_BASIC_RATE_MASK;
300 
301 			rateset[len] = rate;
302 			len++;
303 			break;
304 		}
305 	}
306 	return len;
307 }
308 
get_rate_set(_adapter * padapter,unsigned char * pbssrate,int * bssrate_len)309 void get_rate_set(_adapter *padapter, unsigned char *pbssrate, int *bssrate_len)
310 {
311 	unsigned char supportedrates[NumRates];
312 
313 	_rtw_memset(supportedrates, 0, NumRates);
314 	*bssrate_len = ratetbl2rateset(padapter, supportedrates);
315 	_rtw_memcpy(pbssrate, supportedrates, *bssrate_len);
316 }
317 
set_mcs_rate_by_mask(u8 * mcs_set,u32 mask)318 void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask)
319 {
320 	u8 mcs_rate_1r = (u8)(mask & 0xff);
321 	u8 mcs_rate_2r = (u8)((mask >> 8) & 0xff);
322 	u8 mcs_rate_3r = (u8)((mask >> 16) & 0xff);
323 	u8 mcs_rate_4r = (u8)((mask >> 24) & 0xff);
324 
325 	mcs_set[0] &= mcs_rate_1r;
326 	mcs_set[1] &= mcs_rate_2r;
327 	mcs_set[2] &= mcs_rate_3r;
328 	mcs_set[3] &= mcs_rate_4r;
329 }
330 
UpdateBrateTbl(_adapter * adapter,u8 * mBratesOS)331 void UpdateBrateTbl(
332 	_adapter *adapter,
333 	u8			*mBratesOS
334 )
335 {
336 	u8	i;
337 	u8	rate;
338 
339 	/* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
340 	for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
341 		rate = mBratesOS[i] & 0x7f;
342 		switch (rate) {
343 		case IEEE80211_CCK_RATE_1MB:
344 		case IEEE80211_CCK_RATE_2MB:
345 		case IEEE80211_CCK_RATE_5MB:
346 		case IEEE80211_CCK_RATE_11MB:
347 		case IEEE80211_OFDM_RATE_6MB:
348 		case IEEE80211_OFDM_RATE_12MB:
349 		case IEEE80211_OFDM_RATE_24MB:
350 			mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
351 			break;
352 		}
353 	}
354 
355 }
356 
UpdateBrateTblForSoftAP(u8 * bssrateset,u32 bssratelen)357 void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen)
358 {
359 	u8	i;
360 	u8	rate;
361 
362 	for (i = 0; i < bssratelen; i++) {
363 		rate = bssrateset[i] & 0x7f;
364 		switch (rate) {
365 		case IEEE80211_CCK_RATE_1MB:
366 		case IEEE80211_CCK_RATE_2MB:
367 		case IEEE80211_CCK_RATE_5MB:
368 		case IEEE80211_CCK_RATE_11MB:
369 			bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
370 			break;
371 		}
372 	}
373 
374 }
375 /*rtw_phl_mr_get_chandef(dvobj->phl, adapter->phl_role, &chandef); => mr union chan*/
376 /*rtw_phl_get_cur_hal_chdef(adapter->phl_role, &chandef) => hal chan*/
377 
rtw_get_oper_chdef(_adapter * adapter,struct rtw_chan_def * chandef)378 void rtw_get_oper_chdef(_adapter *adapter, struct rtw_chan_def *chandef)
379 {
380 	if (!adapter->phl_role)
381 		return;
382 
383 	if (rtw_phl_get_cur_hal_chdef(adapter->phl_role, chandef) != RTW_PHL_STATUS_SUCCESS)
384 		RTW_ERR("%s failed\n", __func__);
385 }
386 
rtw_get_oper_band(_adapter * adapter)387 u8 rtw_get_oper_band(_adapter *adapter)
388 {
389 	struct rtw_chan_def cur_chandef = {0};
390 
391 	rtw_get_oper_chdef(adapter, &cur_chandef);
392 	return cur_chandef.band;
393 }
394 
rtw_get_oper_ch(_adapter * adapter)395 u8 rtw_get_oper_ch(_adapter *adapter)
396 {
397 	struct rtw_chan_def cur_chandef = {0};
398 
399 	rtw_get_oper_chdef(adapter, &cur_chandef);
400 	return cur_chandef.chan;
401 }
402 
rtw_get_oper_bw(_adapter * adapter)403 u8 rtw_get_oper_bw(_adapter *adapter)
404 {
405 	struct rtw_chan_def cur_chandef = {0};
406 
407 	rtw_get_oper_chdef(adapter, &cur_chandef);
408 	return cur_chandef.bw;
409 }
410 
rtw_get_oper_choffset(_adapter * adapter)411 u8 rtw_get_oper_choffset(_adapter *adapter)
412 {
413 	struct rtw_chan_def cur_chandef = {0};
414 
415 	rtw_get_oper_chdef(adapter, &cur_chandef);
416 	return cur_chandef.offset;
417 }
418 
rtw_get_on_oper_ch_time(_adapter * adapter)419 inline systime rtw_get_on_oper_ch_time(_adapter *adapter)
420 {
421 	return adapter_to_dvobj(adapter)->on_oper_ch_time;
422 }
423 
rtw_get_on_cur_ch_time(_adapter * adapter)424 inline systime rtw_get_on_cur_ch_time(_adapter *adapter)
425 {
426 	if (adapter->mlmeextpriv.chandef.chan == rtw_get_oper_ch(adapter))
427 		return adapter_to_dvobj(adapter)->on_oper_ch_time;
428 	else
429 		return 0;
430 }
431 
set_channel_bwmode(_adapter * padapter,unsigned char channel,unsigned char channel_offset,unsigned short bwmode,u8 do_rfk)432 void set_channel_bwmode(_adapter *padapter,
433 				unsigned char channel,
434 				unsigned char channel_offset,
435 				unsigned short bwmode,
436 				u8 do_rfk)
437 {
438 	rtw_hw_set_ch_bw(padapter, channel, (enum channel_width)bwmode,
439 		channel_offset, do_rfk);
440 }
441 
get_my_bssid(WLAN_BSSID_EX * pnetwork)442 __inline u8 *get_my_bssid(WLAN_BSSID_EX *pnetwork)
443 {
444 	return pnetwork->MacAddress;
445 }
446 
get_beacon_interval(WLAN_BSSID_EX * bss)447 u16 get_beacon_interval(WLAN_BSSID_EX *bss)
448 {
449 	unsigned short val;
450 	_rtw_memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
451 
452 	return le16_to_cpu(val);
453 
454 }
455 
is_client_associated_to_ap(_adapter * padapter)456 int is_client_associated_to_ap(_adapter *padapter)
457 {
458 	struct mlme_ext_priv	*pmlmeext;
459 	struct mlme_ext_info	*pmlmeinfo;
460 
461 	if (!padapter)
462 		return _FAIL;
463 
464 	pmlmeext = &padapter->mlmeextpriv;
465 	pmlmeinfo = &(pmlmeext->mlmext_info);
466 
467 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
468 		return _TRUE;
469 	else
470 		return _FAIL;
471 }
472 
is_client_associated_to_ibss(_adapter * padapter)473 int is_client_associated_to_ibss(_adapter *padapter)
474 {
475 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
476 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
477 
478 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
479 		return _TRUE;
480 	else
481 		return _FAIL;
482 }
483 
484 /*GEORGIA_TODO_FIXIT*/
485 #define GET_H2CCMD_MSRRPT_PARM_OPMODE(__pH2CCmd) 	LE_BITS_TO_1BYTE(((u8 *)(__pH2CCmd)), 0, 1)
486 #define GET_H2CCMD_MSRRPT_PARM_ROLE(__pH2CCmd)	LE_BITS_TO_1BYTE(((u8 *)(__pH2CCmd)), 4, 4)
487 
is_IBSS_empty(_adapter * padapter)488 int is_IBSS_empty(_adapter *padapter)
489 {
490 /* ToDo */
491 #if 0
492 	int i;
493 	struct macid_ctl_t *macid_ctl = &padapter->dvobj->macid_ctl;
494 
495 	for (i = 0; i < macid_ctl->num; i++) {
496 		if (!rtw_macid_is_used(macid_ctl, i))
497 			continue;
498 		if (!rtw_macid_is_iface_specific(macid_ctl, i, padapter))
499 			continue;
500 		if (!GET_H2CCMD_MSRRPT_PARM_OPMODE(&macid_ctl->h2c_msr[i]))
501 			continue;
502 		if (GET_H2CCMD_MSRRPT_PARM_ROLE(&macid_ctl->h2c_msr[i]) == H2C_MSR_ROLE_ADHOC)
503 			return _FAIL;
504 	}
505 #endif
506 	return _TRUE;
507 }
508 
decide_wait_for_beacon_timeout(unsigned int bcn_interval)509 unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval)
510 {
511 	if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
512 		return WAIT_FOR_BCN_TO_MIN;
513 	else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
514 		return WAIT_FOR_BCN_TO_MAX;
515 	else
516 		return bcn_interval << 2;
517 }
518 
519 #if defined(CONFIG_P2P) && defined(CONFIG_WFD)
rtw_process_wfd_ie(_adapter * adapter,u8 * wfd_ie,u8 wfd_ielen,const char * tag)520 void rtw_process_wfd_ie(_adapter *adapter, u8 *wfd_ie, u8 wfd_ielen, const char *tag)
521 {
522 	struct wifidirect_info *wdinfo = &adapter->wdinfo;
523 
524 	u8 *attr_content;
525 	u32 attr_contentlen = 0;
526 
527 	if (!rtw_hw_chk_wl_func(adapter_to_dvobj(adapter), WL_FUNC_MIRACAST))
528 		return;
529 
530 	RTW_INFO("[%s] Found WFD IE\n", tag);
531 	attr_content = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
532 	if (attr_content && attr_contentlen) {
533 		wdinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
534 		RTW_INFO("[%s] Peer PORT NUM = %d\n", tag, wdinfo->wfd_info->peer_rtsp_ctrlport);
535 	}
536 }
537 
rtw_process_wfd_ies(_adapter * adapter,u8 * ies,u8 ies_len,const char * tag)538 void rtw_process_wfd_ies(_adapter *adapter, u8 *ies, u8 ies_len, const char *tag)
539 {
540 	u8 *wfd_ie;
541 	u32	wfd_ielen;
542 
543 	if (!rtw_hw_chk_wl_func(adapter_to_dvobj(adapter), WL_FUNC_MIRACAST))
544 		return;
545 
546 	wfd_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &wfd_ielen);
547 	while (wfd_ie) {
548 		rtw_process_wfd_ie(adapter, wfd_ie, wfd_ielen, tag);
549 		wfd_ie = rtw_get_wfd_ie(wfd_ie + wfd_ielen, (ies + ies_len) - (wfd_ie + wfd_ielen), NULL, &wfd_ielen);
550 	}
551 }
552 #endif /* defined(CONFIG_P2P) && defined(CONFIG_WFD) */
553 
WMM_param_handler(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)554 int WMM_param_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs	pIE)
555 {
556 	/* struct registry_priv	*pregpriv = &padapter->registrypriv; */
557 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
558 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
559 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
560 
561 	if (pmlmepriv->qospriv.qos_option == 0) {
562 		pmlmeinfo->WMM_enable = 0;
563 		return _FALSE;
564 	}
565 
566 	if (_rtw_memcmp(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element)))
567 		return _FALSE;
568 	else
569 		_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
570 	pmlmeinfo->WMM_enable = 1;
571 	return _TRUE;
572 
573 #if 0
574 	if (pregpriv->wifi_spec == 1) {
575 		if (pmlmeinfo->WMM_enable == 1) {
576 			/* todo: compare the parameter set count & decide wheher to update or not */
577 			return _FAIL;
578 		} else {
579 			pmlmeinfo->WMM_enable = 1;
580 			_rtw_rtw_memcpy(&(pmlmeinfo->WMM_param), (pIE->data + 6), sizeof(struct WMM_para_element));
581 			return _TRUE;
582 		}
583 	} else {
584 		pmlmeinfo->WMM_enable = 0;
585 		return _FAIL;
586 	}
587 #endif
588 
589 }
590 
591 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
rtw_is_tbtx_capabilty(u8 * p,u8 len)592 u8 rtw_is_tbtx_capabilty(u8 *p, u8 len){
593 	int i;
594 	u8 tbtx_cap_ie[8] = {0x00, 0xe0, 0x4c, 0x01, 0x00, 0x00, 0x00, 0x00};
595 
596 	for (i = 0; i < len; i++) {
597 		if (*(p + i) != tbtx_cap_ie[i])
598 			return _FALSE;
599 		else
600 			continue;
601 	}
602 	return _TRUE;
603 }
604 #endif
605 
WMMOnAssocRsp(_adapter * padapter)606 void WMMOnAssocRsp(_adapter *padapter)
607 {
608 	u8	ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
609 	u8	acm_mask;
610 	u16	TXOP;
611 	u32	acParm, i;
612 	u32	edca[4], inx[4];
613 	u8 ac_be = 0;
614 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
615 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
616 	struct xmit_priv		*pxmitpriv = &padapter->xmitpriv;
617 	struct registry_priv	*pregpriv = &padapter->registrypriv;
618 #ifdef CONFIG_WMMPS_STA
619 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
620 	struct qos_priv	*pqospriv = &pmlmepriv->qospriv;
621 #endif /* CONFIG_WMMPS_STA */
622 
623 	acm_mask = 0;
624 
625 	if (WIFI_ROLE_IS_ON_5G(padapter) ||
626 	    (pmlmeext->cur_wireless_mode & WLAN_MD_11N))
627 		aSifsTime = 16;
628 	else
629 		aSifsTime = 10;
630 
631 	if (pmlmeinfo->WMM_enable == 0) {
632 		padapter->mlmepriv.acm_mask = 0;
633 
634 		AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
635 
636 		if (pmlmeext->cur_wireless_mode & (WLAN_MD_11G | WLAN_MD_11A)) {
637 			ECWMin = 4;
638 			ECWMax = 10;
639 		} else if (pmlmeext->cur_wireless_mode & WLAN_MD_11B) {
640 			ECWMin = 5;
641 			ECWMax = 10;
642 		} else {
643 			ECWMin = 4;
644 			ECWMax = 10;
645 		}
646 
647 		TXOP = 0;
648 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
649 		rtw_hw_set_edca(padapter, 0, acParm);
650 		rtw_hw_set_edca(padapter, 1, acParm);
651 		rtw_hw_set_edca(padapter, 2, acParm);
652 
653 		ECWMin = 2;
654 		ECWMax = 3;
655 		TXOP = 0x2f;
656 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
657 		rtw_hw_set_edca(padapter, 3, acParm);
658 	} else {
659 		edca[0] = edca[1] = edca[2] = edca[3] = 0;
660 
661 		for (i = 0; i < 4; i++) {
662 			ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
663 			ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
664 
665 			/* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
666 			AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) * pmlmeinfo->slotTime + aSifsTime;
667 
668 			ECWMin = (pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f);
669 			ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
670 			TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
671 
672 			acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
673 			rtw_hw_set_edca(padapter, ACI, acParm);
674 
675 			switch (ACI) {
676 			case 0x0:
677 				acm_mask |= (ACM ? BIT(1) : 0);
678 				edca[XMIT_BE_QUEUE] = acParm;
679 				break;
680 
681 			case 0x1:
682 				/* acm_mask |= (ACM? BIT(0):0); */
683 				edca[XMIT_BK_QUEUE] = acParm;
684 				break;
685 
686 			case 0x2:
687 				acm_mask |= (ACM ? BIT(2) : 0);
688 				edca[XMIT_VI_QUEUE] = acParm;
689 				break;
690 
691 			case 0x3:
692 				acm_mask |= (ACM ? BIT(3) : 0);
693 				edca[XMIT_VO_QUEUE] = acParm;
694 				break;
695 			}
696 
697 			RTW_INFO("WMM(%x): %x, %x\n", ACI, ACM, acParm);
698 
699 			if (i == ac_be) {
700 				padapter->last_edca = acParm;
701 				acParm = rtw_get_turbo_edca(padapter, AIFS, ECWMin, ECWMax, TXOP);
702 				if (acParm) {
703 					rtw_hw_set_edca(padapter, ACI, acParm);
704 					padapter->last_edca = acParm;
705 				}
706 			}
707 
708 		}
709 
710 		if (padapter->registrypriv.acm_method == 1)
711 			rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
712 		else
713 			padapter->mlmepriv.acm_mask = acm_mask;
714 
715 		inx[0] = 0;
716 		inx[1] = 1;
717 		inx[2] = 2;
718 		inx[3] = 3;
719 
720 		if (pregpriv->wifi_spec == 1) {
721 			u32	j, tmp, change_inx = _FALSE;
722 
723 			/* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
724 			for (i = 0; i < 4; i++) {
725 				for (j = i + 1; j < 4; j++) {
726 					/* compare CW and AIFS */
727 					if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
728 						change_inx = _TRUE;
729 					else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
730 						/* compare TXOP */
731 						if ((edca[j] >> 16) > (edca[i] >> 16))
732 							change_inx = _TRUE;
733 					}
734 
735 					if (change_inx) {
736 						tmp = edca[i];
737 						edca[i] = edca[j];
738 						edca[j] = tmp;
739 
740 						tmp = inx[i];
741 						inx[i] = inx[j];
742 						inx[j] = tmp;
743 
744 						change_inx = _FALSE;
745 					}
746 				}
747 			}
748 		}
749 
750 		for (i = 0; i < 4; i++) {
751 			pxmitpriv->wmm_para_seq[i] = inx[i];
752 			RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
753 		}
754 
755 #ifdef CONFIG_WMMPS_STA
756 		/* if AP supports UAPSD function, driver must set each uapsd TID to coresponding mac register 0x693 */
757 		if (pmlmeinfo->WMM_param.QoS_info & AP_SUPPORTED_UAPSD) {
758 			pqospriv->uapsd_ap_supported = 1;
759 			rtw_hal_set_hwreg(padapter, HW_VAR_UAPSD_TID, NULL);
760 		}
761 #endif /* CONFIG_WMMPS_STA */
762 	}
763 }
764 
bwmode_update_check(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)765 static void bwmode_update_check(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
766 {
767 #ifdef CONFIG_80211N_HT
768 	unsigned char	 new_bwmode;
769 	unsigned char  new_ch_offset;
770 	struct HT_info_element	*pHT_info;
771 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
772 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
773 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
774 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
775 	struct ht_priv			*phtpriv = &pmlmepriv->htpriv;
776 	u8	cbw40_enable = 0;
777 
778 	if (!pIE)
779 		return;
780 
781 	if (phtpriv->ht_option == _FALSE)
782 		return;
783 
784 	if (pmlmeext->chandef.bw >= CHANNEL_WIDTH_80)
785 		return;
786 
787 	if (pIE->Length > sizeof(struct HT_info_element))
788 		return;
789 
790 	pHT_info = (struct HT_info_element *)pIE->data;
791 
792 	if (rtw_hw_chk_bw_cap(adapter_to_dvobj(padapter), BW_CAP_40M)) {
793 		if (pmlmeext->chandef.chan > 14) {
794 			if (REGSTY_IS_BW_5G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
795 				cbw40_enable = 1;
796 		} else {
797 			if (REGSTY_IS_BW_2G_SUPPORT(pregistrypriv, CHANNEL_WIDTH_40))
798 				cbw40_enable = 1;
799 		}
800 	}
801 
802 	if ((pHT_info->infos[0] & BIT(2)) && cbw40_enable) {
803 		new_bwmode = CHANNEL_WIDTH_40;
804 
805 		switch (pHT_info->infos[0] & 0x3) {
806 		case 1:
807 			new_ch_offset = CHAN_OFFSET_UPPER;
808 			break;
809 
810 		case 3:
811 			new_ch_offset = CHAN_OFFSET_LOWER;
812 			break;
813 
814 		default:
815 			new_bwmode = CHANNEL_WIDTH_20;
816 			new_ch_offset = CHAN_OFFSET_NO_EXT;
817 			break;
818 		}
819 	} else {
820 		new_bwmode = CHANNEL_WIDTH_20;
821 		new_ch_offset = CHAN_OFFSET_NO_EXT;
822 	}
823 
824 
825 	if ((new_bwmode != pmlmeext->chandef.bw || new_ch_offset != pmlmeext->chandef.offset)
826 	    && new_bwmode < pmlmeext->chandef.bw
827 	   ) {
828 		pmlmeinfo->bwmode_updated = _TRUE;
829 
830 		pmlmeext->chandef.bw = new_bwmode;
831 		pmlmeext->chandef.offset = new_ch_offset;
832 
833 		/* update HT info also */
834 		HT_info_handler(padapter, pIE);
835 	} else
836 		pmlmeinfo->bwmode_updated = _FALSE;
837 
838 
839 	if (_TRUE == pmlmeinfo->bwmode_updated) {
840 		struct sta_info *psta;
841 		WLAN_BSSID_EX	*cur_network = &(pmlmeinfo->network);
842 		struct sta_priv	*pstapriv = &padapter->stapriv;
843 
844 		/* set_channel_bwmode(padapter, pmlmeext->chandef.chan, pmlmeext->chandef.offset, pmlmeext->chandef.bw); */
845 
846 
847 		/* update ap's stainfo */
848 		psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
849 		if (psta) {
850 			struct ht_priv	*phtpriv_sta = &psta->htpriv;
851 
852 			if (phtpriv_sta->ht_option) {
853 				/* bwmode				 */
854 				psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
855 				phtpriv_sta->ch_offset = pmlmeext->chandef.offset;
856 			} else {
857 				psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
858 				phtpriv_sta->ch_offset = CHAN_OFFSET_NO_EXT;
859 			}
860 
861 			rtw_phl_cmd_change_stainfo(adapter_to_dvobj(padapter)->phl,
862 					   psta->phl_sta,
863 					   STA_CHG_RAMASK,
864 					   NULL,
865 					   0,
866 					   PHL_CMD_NO_WAIT,
867 					   0);
868 		}
869 
870 		/* pmlmeinfo->bwmode_updated = _FALSE; */ /* bwmode_updated done, reset it! */
871 	}
872 #endif /* CONFIG_80211N_HT */
873 }
874 
875 #ifdef ROKU_PRIVATE
Supported_rate_infra_ap(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)876 void Supported_rate_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
877 {
878 	unsigned int	i;
879 	struct mlme_ext_priv		*pmlmeext = &padapter->mlmeextpriv;
880 	struct mlme_ext_info		*pmlmeinfo = &(pmlmeext->mlmext_info);
881 
882 	if (pIE == NULL)
883 		return;
884 
885 	for (i = 0 ; i < pIE->Length; i++)
886 		pmlmeinfo->SupportedRates_infra_ap[i] = (pIE->data[i]);
887 
888 }
889 
Extended_Supported_rate_infra_ap(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)890 void Extended_Supported_rate_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
891 {
892 	unsigned int i, j;
893 	struct mlme_ext_priv		*pmlmeext = &padapter->mlmeextpriv;
894 	struct mlme_ext_info		*pmlmeinfo = &(pmlmeext->mlmext_info);
895 
896 	if (pIE == NULL)
897 		return;
898 
899 	if (pIE->Length > 0) {
900 		for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
901 			if (pmlmeinfo->SupportedRates_infra_ap[i] == 0)
902 				break;
903 		}
904 		for (j = 0; j < pIE->Length; j++)
905 			pmlmeinfo->SupportedRates_infra_ap[i+j] = (pIE->data[j]);
906 	}
907 
908 }
909 
HT_get_ss_from_mcs_set(u8 * mcs_set,u8 * Rx_ss)910 void HT_get_ss_from_mcs_set(u8 *mcs_set, u8 *Rx_ss)
911 {
912 	u8 i, j;
913 	u8 r_ss = 0, t_ss = 0;
914 
915 	for (i = 0; i < 4; i++) {
916 		if ((mcs_set[3-i] & 0xff) != 0x00) {
917 			r_ss = 4-i;
918 			break;
919 		}
920 	}
921 
922 	*Rx_ss = r_ss;
923 }
924 
HT_caps_handler_infra_ap(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)925 void HT_caps_handler_infra_ap(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
926 {
927 	unsigned int	i;
928 	u8	cur_stbc_cap_infra_ap = 0;
929 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
930 	struct ht_priv_infra_ap		*phtpriv = &pmlmepriv->htpriv_infra_ap;
931 
932 	struct mlme_ext_priv		*pmlmeext = &padapter->mlmeextpriv;
933 	struct mlme_ext_info		*pmlmeinfo = &(pmlmeext->mlmext_info);
934 
935 	if (pIE == NULL)
936 		return;
937 
938 	pmlmeinfo->ht_vht_received |= BIT(0);
939 
940 	/*copy MCS_SET*/
941 	for (i = 3; i < 19; i++)
942 		phtpriv->MCS_set_infra_ap[i-3] = (pIE->data[i]);
943 
944 	/*get number of stream from mcs set*/
945 	HT_get_ss_from_mcs_set(phtpriv->MCS_set_infra_ap, &phtpriv->Rx_ss_infra_ap);
946 
947 	phtpriv->rx_highest_data_rate_infra_ap = le16_to_cpu(GET_HT_CAP_ELE_RX_HIGHEST_DATA_RATE(pIE->data));
948 
949 	phtpriv->ldpc_cap_infra_ap = GET_HT_CAP_ELE_LDPC_CAP(pIE->data);
950 
951 	if (GET_HT_CAP_ELE_RX_STBC(pIE->data))
952 		SET_FLAG(cur_stbc_cap_infra_ap, STBC_HT_ENABLE_RX);
953 	if (GET_HT_CAP_ELE_TX_STBC(pIE->data))
954 		SET_FLAG(cur_stbc_cap_infra_ap, STBC_HT_ENABLE_TX);
955 	phtpriv->stbc_cap_infra_ap = cur_stbc_cap_infra_ap;
956 
957 	/*store ap info SGI 20m 40m*/
958 	phtpriv->sgi_20m_infra_ap = GET_HT_CAP_ELE_SHORT_GI20M(pIE->data);
959 	phtpriv->sgi_40m_infra_ap = GET_HT_CAP_ELE_SHORT_GI40M(pIE->data);
960 
961 	/*store ap info for supported channel bandwidth*/
962 	phtpriv->channel_width_infra_ap = GET_HT_CAP_ELE_CHL_WIDTH(pIE->data);
963 }
964 #endif /* ROKU_PRIVATE */
965 
HT_caps_handler(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)966 void HT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
967 {
968 #ifdef CONFIG_80211N_HT
969 	unsigned int i;
970 	u8 max_AMPDU_len, min_MPDU_spacing;
971 	u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0, rx_nss = 0;
972 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
973 	struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
974 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
975 	struct ht_priv *phtpriv = &pmlmepriv->htpriv;
976 	struct sta_info *sta = NULL;
977 	struct rtw_phl_stainfo_t *phl_sta = NULL;
978 	struct rtw_wifi_role_t *wrole = padapter->phl_role;
979 	struct protocol_cap_t *proto_role_cap = &(wrole->proto_role_cap);
980 #ifdef CONFIG_DISABLE_MCS13TO15
981 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
982 #endif
983 
984 	if (pIE == NULL)
985 		return;
986 
987 	if (phtpriv->ht_option == _FALSE)
988 		return;
989 
990 	pmlmeinfo->HT_caps_enable = 1;
991 
992 	for (i = 0; i < (pIE->Length); i++) {
993 		if (i != 2) {
994 			/*	Commented by Albert 2010/07/12 */
995 			/*	Got the endian issue here. */
996 			pmlmeinfo->HT_caps.u.HT_cap[i] &= (pIE->data[i]);
997 		} else {
998 			/* AMPDU Parameters field */
999 
1000 			/* Get MIN of MAX AMPDU Length Exp */
1001 			if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3) > (pIE->data[i] & 0x3))
1002 				max_AMPDU_len = (pIE->data[i] & 0x3);
1003 			else
1004 				max_AMPDU_len = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3);
1005 
1006 			/* Get MAX of MIN MPDU Start Spacing */
1007 			if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) > (pIE->data[i] & 0x1c))
1008 				min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c);
1009 			else
1010 				min_MPDU_spacing = (pIE->data[i] & 0x1c);
1011 
1012 			pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para = max_AMPDU_len | min_MPDU_spacing;
1013 		}
1014 	}
1015 
1016 	/*	Commented by Albert 2010/07/12 */
1017 	/*	Have to handle the endian issue after copying. */
1018 	/*	HT_ext_caps didn't be used yet.	 */
1019 	pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info = le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info);
1020 	pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps = le16_to_cpu(pmlmeinfo->HT_caps.u.HT_cap_element.HT_ext_caps);
1021 
1022 	/* update the MCS set */
1023 	for (i = 0; i < 16; i++)
1024 		pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate[i] &= pmlmeext->default_supported_mcs_set[i];
1025 
1026 	rx_nss = get_phy_rx_nss(padapter);
1027 
1028 	switch (rx_nss) {
1029 	case 1:
1030 		set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_1R);
1031 		break;
1032 	case 2:
1033 		#ifdef CONFIG_DISABLE_MCS13TO15
1034 		if (pmlmeext->chandef.bw == CHANNEL_WIDTH_40 && pregistrypriv->wifi_spec != 1)
1035 			set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R_13TO15_OFF);
1036 		else
1037 		#endif
1038 			set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_2R);
1039 		break;
1040 	case 3:
1041 		set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_3R);
1042 		break;
1043 	case 4:
1044 		set_mcs_rate_by_mask(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_RATE_4R);
1045 		break;
1046 	default:
1047 		RTW_WARN("rf_type:%d or tx_nss:%u is not expected\n", GET_HAL_RFPATH(adapter_to_dvobj(padapter)), rx_nss);
1048 	}
1049 
1050 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1051 		/* Config STBC setting */
1052 		if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAP_ELE_RX_STBC(pIE->data)) {
1053 			SET_FLAG(cur_stbc_cap, STBC_HT_ENABLE_TX);
1054 			RTW_INFO("Enable HT Tx STBC !\n");
1055 		}
1056 		phtpriv->stbc_cap = cur_stbc_cap;
1057 
1058 #ifdef CONFIG_BEAMFORMING
1059 		/* Config Tx beamforming setting */
1060 		if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
1061 		    GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pIE->data)) {
1062 			SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
1063 			/* Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
1064 			SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pIE->data) << 6);
1065 		}
1066 
1067 		if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
1068 		    GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pIE->data)) {
1069 			SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
1070 			/* Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
1071 			SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pIE->data) << 4);
1072 		}
1073 		phtpriv->beamform_cap = cur_beamform_cap;
1074 		if (cur_beamform_cap)
1075 			RTW_INFO("AP HT Beamforming Cap = 0x%02X\n", cur_beamform_cap);
1076 #endif /*CONFIG_BEAMFORMING*/
1077 	} else {
1078 		/*WIFI_STATION_STATEorI_ADHOC_STATE or WIFI_ADHOC_MASTER_STATE*/
1079 		sta = rtw_get_stainfo(&padapter->stapriv, pmlmeinfo->network.MacAddress);
1080 		if (!sta) {
1081 			RTW_ERR(FUNC_ADPT_FMT ": STA(" MAC_FMT ") not found!\n",
1082 				FUNC_ADPT_ARG(padapter), MAC_ARG(pmlmeinfo->network.MacAddress));
1083 			return;
1084 		}
1085 		if (!sta->phl_sta) {
1086 			RTW_ERR(FUNC_ADPT_FMT ": PHL STA(" MAC_FMT ") not exist!\n",
1087 				FUNC_ADPT_ARG(padapter), MAC_ARG(pmlmeinfo->network.MacAddress));
1088 			return;
1089 		}
1090 		phl_sta = sta->phl_sta;
1091 
1092 		/* Config LDPC Coding Capability */
1093 		if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX) && GET_HT_CAP_ELE_LDPC_CAP(pIE->data)) {
1094 			SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
1095 			RTW_INFO("Enable HT Tx LDPC!\n");
1096 			phl_sta->asoc_cap.ht_ldpc = 1;
1097 		}
1098 		phtpriv->ldpc_cap = cur_ldpc_cap;
1099 
1100 		/* Config STBC setting */
1101 		if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAP_ELE_RX_STBC(pIE->data)) {
1102 			SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
1103 			RTW_INFO("Enable HT Tx STBC!\n");
1104 			phl_sta->asoc_cap.stbc_ht_rx =
1105 				proto_role_cap->stbc_ht_tx ? GET_HT_CAP_ELE_RX_STBC(pIE->data) : 0;
1106 		}
1107 		phtpriv->stbc_cap = cur_stbc_cap;
1108 		phl_sta->asoc_cap.stbc_ht_tx = GET_HT_CAP_ELE_TX_STBC(pIE->data);
1109 
1110 #ifdef CONFIG_BEAMFORMING
1111 		/* Config beamforming setting */
1112 		if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
1113 		    GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pIE->data)) {
1114 			SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
1115 			/* Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
1116 			SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pIE->data) << 6);
1117 		}
1118 
1119 		if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
1120 		    GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pIE->data)) {
1121 			SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
1122 			/* Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
1123 			SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pIE->data) << 4);
1124 		}
1125 		phtpriv->beamform_cap = cur_beamform_cap;
1126 		if (cur_beamform_cap)
1127 			RTW_INFO("Client HT Beamforming Cap = 0x%02X\n", cur_beamform_cap);
1128 #endif /*CONFIG_BEAMFORMING*/
1129 	}
1130 
1131 #endif /* CONFIG_80211N_HT */
1132 }
1133 
HT_info_handler(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)1134 void HT_info_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
1135 {
1136 #ifdef CONFIG_80211N_HT
1137 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1138 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1139 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
1140 	struct ht_priv			*phtpriv = &pmlmepriv->htpriv;
1141 
1142 	if (pIE == NULL)
1143 		return;
1144 
1145 	if (phtpriv->ht_option == _FALSE)
1146 		return;
1147 
1148 
1149 	if (pIE->Length > sizeof(struct HT_info_element))
1150 		return;
1151 
1152 	pmlmeinfo->HT_info_enable = 1;
1153 	_rtw_memcpy(&(pmlmeinfo->HT_info), pIE->data, pIE->Length);
1154 #endif /* CONFIG_80211N_HT */
1155 	return;
1156 }
1157 
HTOnAssocRsp(_adapter * padapter)1158 void HTOnAssocRsp(_adapter *padapter)
1159 {
1160 	unsigned char		max_AMPDU_len;
1161 	unsigned char		min_MPDU_spacing;
1162 	/* struct registry_priv	 *pregpriv = &padapter->registrypriv; */
1163 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1164 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1165 
1166 	RTW_INFO("%s\n", __FUNCTION__);
1167 
1168 	if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
1169 		pmlmeinfo->HT_enable = 1;
1170 	else {
1171 		pmlmeinfo->HT_enable = 0;
1172 		/* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
1173 		return;
1174 	}
1175 
1176 	/* handle A-MPDU parameter field */
1177 	/*
1178 		AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
1179 		AMPDU_para [4:2]:Min MPDU Start Spacing
1180 	*/
1181 	max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
1182 
1183 	min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
1184 
1185 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
1186 #ifdef CONFIG_80211N_HT
1187 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
1188 #endif /* CONFIG_80211N_HT */
1189 #if 0 /* move to rtw_update_ht_cap() */
1190 	if ((pregpriv->bw_mode > 0) &&
1191 	    (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & BIT(1)) &&
1192 	    (pmlmeinfo->HT_info.infos[0] & BIT(2))) {
1193 		/* switch to the 40M Hz mode accoring to the AP */
1194 		pmlmeext->cur_bwmode = CHANNEL_WIDTH_40;
1195 		switch ((pmlmeinfo->HT_info.infos[0] & 0x3)) {
1196 		case IEEE80211_SCA:
1197 			pmlmeext->cur_ch_offset = CHAN_OFFSET_UPPER;
1198 			break;
1199 
1200 		case IEEE80211_SCB:
1201 			pmlmeext->cur_ch_offset = CHAN_OFFSET_LOWER;
1202 			break;
1203 
1204 		default:
1205 			pmlmeext->cur_ch_offset = CHAN_OFFSET_NO_EXT;
1206 			break;
1207 		}
1208 	}
1209 #endif
1210 
1211 	/* set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
1212 
1213 #if 0 /* move to rtw_update_ht_cap() */
1214 	/*  */
1215 	/* Config SM Power Save setting */
1216 	/*  */
1217 	pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
1218 	if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
1219 #if 0
1220 		u8 i;
1221 		/* update the MCS rates */
1222 		for (i = 0; i < 16; i++)
1223 			pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
1224 #endif
1225 		RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
1226 	}
1227 
1228 	/*  */
1229 	/* Config current HT Protection mode. */
1230 	/*  */
1231 	pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3;
1232 #endif
1233 
1234 }
1235 
ERP_IE_handler(_adapter * padapter,PNDIS_802_11_VARIABLE_IEs pIE)1236 void ERP_IE_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE)
1237 {
1238 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1239 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1240 
1241 	if (pIE->Length > 1)
1242 		return;
1243 
1244 	pmlmeinfo->ERP_enable = 1;
1245 	_rtw_memcpy(&(pmlmeinfo->ERP_IE), pIE->data, pIE->Length);
1246 }
1247 
VCS_update(_adapter * padapter,struct sta_info * psta)1248 void VCS_update(_adapter *padapter, struct sta_info *psta)
1249 {
1250 	struct registry_priv	*pregpriv = &padapter->registrypriv;
1251 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1252 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1253 
1254 	switch (pregpriv->vrtl_carrier_sense) { /* 0:off 1:on 2:auto */
1255 	case 0: /* off */
1256 		psta->rtsen = 0;
1257 		psta->cts2self = 0;
1258 		break;
1259 
1260 	case 1: /* on */
1261 		if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */
1262 			psta->rtsen = 1;
1263 			psta->cts2self = 0;
1264 		} else {
1265 			psta->rtsen = 0;
1266 			psta->cts2self = 1;
1267 		}
1268 		break;
1269 
1270 	case 2: /* auto */
1271 	default:
1272 		if (((pmlmeinfo->ERP_enable) && (pmlmeinfo->ERP_IE & BIT(1)))
1273 			/*||(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/
1274 		) {
1275 			if (pregpriv->vcs_type == 1) {
1276 				psta->rtsen = 1;
1277 				psta->cts2self = 0;
1278 			} else {
1279 				psta->rtsen = 0;
1280 				psta->cts2self = 1;
1281 			}
1282 		} else {
1283 			psta->rtsen = 0;
1284 			psta->cts2self = 0;
1285 		}
1286 		break;
1287 	}
1288 
1289 	switch (pregpriv->hw_rts_en) { /* 0:disable 1:enable */
1290 	case 0:
1291 		psta->hw_rts_en = 0;
1292 		break;
1293 	case 1:
1294 		psta->hw_rts_en = 1;
1295 		break;
1296 	default:
1297 		RTW_WARN("%s: unexpected value(%d) for hw_rts_en.\n", __func__, pregpriv->hw_rts_en);
1298 		break;
1299 	}
1300 
1301 }
1302 
update_ldpc_stbc_cap(struct sta_info * psta)1303 void	update_ldpc_stbc_cap(struct sta_info *psta)
1304 {
1305 #ifdef CONFIG_80211N_HT
1306 
1307 #ifdef CONFIG_80211AC_VHT
1308 #ifdef CONFIG_80211AX_HE
1309 	/* CONFIG_80211AX_HE_TODO */
1310 #endif /* CONFIG_80211AX_HE */
1311 	if (psta->vhtpriv.vht_option) {
1312 		if (TEST_FLAG(psta->vhtpriv.ldpc_cap, LDPC_VHT_ENABLE_TX))
1313 			psta->phl_sta->asoc_cap.vht_ldpc = 1;
1314 		else
1315 			psta->phl_sta->asoc_cap.vht_ldpc = 0;
1316 	} else
1317 #endif /* CONFIG_80211AC_VHT */
1318 		if (psta->htpriv.ht_option) {
1319 			if (TEST_FLAG(psta->htpriv.ldpc_cap, LDPC_HT_ENABLE_TX))
1320 				psta->phl_sta->asoc_cap.ht_ldpc = 1;
1321 			else
1322 				psta->phl_sta->asoc_cap.ht_ldpc = 0;
1323 		} else {
1324 			psta->phl_sta->asoc_cap.vht_ldpc = 0;
1325 			psta->phl_sta->asoc_cap.ht_ldpc = 0;
1326 		}
1327 
1328 #endif /* CONFIG_80211N_HT */
1329 }
1330 
check_ielen(u8 * start,uint len)1331 int check_ielen(u8 *start, uint len)
1332 {
1333 	int left = len;
1334 	u8 *pos = start;
1335 	u8 id, elen;
1336 
1337 	while (left >= 2) {
1338 		id = *pos++;
1339 		elen = *pos++;
1340 		left -= 2;
1341 
1342 		if (elen > left) {
1343 			RTW_ERR("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
1344 					id, elen, (unsigned long) left);
1345 			return _FALSE;
1346 		}
1347 		if ((id == WLAN_EID_VENDOR_SPECIFIC) && (elen < 3))
1348 				return _FALSE;
1349 
1350 		left -= elen;
1351 		pos += elen;
1352 	}
1353 	if (left)
1354 		return _FALSE;
1355 
1356 	return _TRUE;
1357 }
1358 
validate_beacon_len(u8 * pframe,u32 len)1359 int validate_beacon_len(u8 *pframe, u32 len)
1360 {
1361 	u8 ie_offset = _BEACON_IE_OFFSET_ + sizeof(struct rtw_ieee80211_hdr_3addr);
1362 
1363 	if (len < ie_offset) {
1364 		RTW_ERR("%s: incorrect beacon length(%d)\n", __func__, len);
1365 		rtw_warn_on(1);
1366 		return _FALSE;
1367 	}
1368 
1369 	if (check_ielen(pframe + ie_offset, len - ie_offset) == _FALSE)
1370 		return _FALSE;
1371 
1372 	return _TRUE;
1373 }
1374 
1375 
1376 u8 support_rate_ranges[] = {
1377 	IEEE80211_CCK_RATE_1MB,
1378 	IEEE80211_CCK_RATE_2MB,
1379 	IEEE80211_CCK_RATE_5MB,
1380 	IEEE80211_CCK_RATE_11MB,
1381 	IEEE80211_OFDM_RATE_6MB,
1382 	IEEE80211_OFDM_RATE_9MB,
1383 	IEEE80211_OFDM_RATE_12MB,
1384 	IEEE80211_OFDM_RATE_18MB,
1385 	IEEE80211_PBCC_RATE_22MB,
1386 	IEEE80211_FREAK_RATE_22_5MB,
1387 	IEEE80211_OFDM_RATE_24MB,
1388 	IEEE80211_OFDM_RATE_36MB,
1389 	IEEE80211_OFDM_RATE_48MB,
1390 	IEEE80211_OFDM_RATE_54MB,
1391 };
1392 
match_ranges(u16 EID,u32 value)1393 inline bool match_ranges(u16 EID, u32 value)
1394 {
1395 	int i;
1396 	int nr_range;
1397 
1398 	switch (EID) {
1399 	case _EXT_SUPPORTEDRATES_IE_:
1400 	case _SUPPORTEDRATES_IE_:
1401 		nr_range = sizeof(support_rate_ranges)/sizeof(u8);
1402 		for (i = 0; i < nr_range; i++) {
1403 			/*	clear bit7 before searching.	*/
1404 			value &= ~BIT(7);
1405 			if (value == support_rate_ranges[i])
1406 				return _TRUE;
1407 		}
1408 		break;
1409 	default:
1410 		break;
1411 	};
1412 	return _FALSE;
1413 }
1414 
1415 /*
1416  * rtw_validate_value: validate the IE contain.
1417  *
1418  *	Input :
1419  *		EID : Element ID
1420  *		p	: IE buffer (without EID & length)
1421  *		len	: IE length
1422  *	return:
1423  * 		_TRUE	: All Values are validated.
1424  *		_FALSE	: At least one value is NOT validated.
1425  */
rtw_validate_value(u16 EID,u8 * p,u16 len)1426 bool rtw_validate_value(u16 EID, u8 *p, u16 len)
1427 {
1428 	u8 rate;
1429 	u32 i, nr_val;
1430 
1431 	switch (EID) {
1432 	case _EXT_SUPPORTEDRATES_IE_:
1433 	case _SUPPORTEDRATES_IE_:
1434 		nr_val = len;
1435 		for (i=0; i<nr_val; i++) {
1436 			rate = *(p+i);
1437 			if (match_ranges(EID, rate) == _FALSE)
1438 				return _FALSE;
1439 		}
1440 		break;
1441 	default:
1442 		break;
1443 	};
1444 	return _TRUE;
1445 }
1446 
is_hidden_ssid(char * ssid,int len)1447 bool is_hidden_ssid(char *ssid, int len)
1448 {
1449 	return len == 0 || is_all_null(ssid, len) == _TRUE;
1450 }
1451 
hidden_ssid_ap(WLAN_BSSID_EX * snetwork)1452 inline bool hidden_ssid_ap(WLAN_BSSID_EX *snetwork)
1453 {
1454 	return ((snetwork->Ssid.SsidLength == 0) ||
1455 		is_all_null(snetwork->Ssid.Ssid, snetwork->Ssid.SsidLength) == _TRUE);
1456 }
1457 
1458 /*
1459 	Get SSID if this ilegal frame(probe resp) comes from a hidden SSID AP.
1460 	Update the SSID to the corresponding pnetwork in scan queue.
1461 */
rtw_absorb_ssid_ifneed(_adapter * padapter,WLAN_BSSID_EX * bssid,u8 * pframe)1462 void rtw_absorb_ssid_ifneed(_adapter *padapter, WLAN_BSSID_EX *bssid, u8 *pframe)
1463 {
1464 	struct wlan_network *scanned = NULL;
1465 	WLAN_BSSID_EX	*snetwork;
1466 	u8 ie_offset, *p=NULL, *next_ie=NULL;
1467 	u8 *mac;
1468 	sint ssid_len_ori;
1469 	u32 remain_len = 0;
1470 	u8 backupIE[MAX_IE_SZ];
1471 	u16 subtype;
1472 
1473 	mac = get_addr2_ptr(pframe);
1474 	subtype = get_frame_sub_type(pframe);
1475 
1476 	if (subtype == WIFI_BEACON) {
1477 		bssid->Reserved[0] = BSS_TYPE_BCN;
1478 		ie_offset = _BEACON_IE_OFFSET_;
1479 	} else {
1480 		/* FIXME : more type */
1481 		if (subtype == WIFI_PROBERSP) {
1482 			ie_offset = _PROBERSP_IE_OFFSET_;
1483 			bssid->Reserved[0] = BSS_TYPE_PROB_RSP;
1484 		} else if (subtype == WIFI_PROBEREQ) {
1485 			ie_offset = _PROBEREQ_IE_OFFSET_;
1486 			bssid->Reserved[0] = BSS_TYPE_PROB_REQ;
1487 		} else {
1488 			bssid->Reserved[0] = BSS_TYPE_UNDEF;
1489 			ie_offset = _FIXED_IE_LENGTH_;
1490 		}
1491 	}
1492 
1493 	_rtw_spinlock_bh(&padapter->mlmepriv.scanned_queue.lock);
1494 	scanned = _rtw_find_network(&padapter->mlmepriv.scanned_queue, mac);
1495 	if (!scanned) {
1496 		_rtw_spinunlock_bh(&padapter->mlmepriv.scanned_queue.lock);
1497 		return;
1498 	}
1499 
1500 	snetwork = &(scanned->network);
1501 	/* scan queue records as Hidden SSID && Input frame is NOT Hidden SSID	*/
1502 	if (hidden_ssid_ap(snetwork) && !hidden_ssid_ap(bssid)) {
1503 		p = rtw_get_ie(snetwork->IEs+ie_offset, _SSID_IE_, &ssid_len_ori, snetwork->IELength-ie_offset);
1504 		if (!p) {
1505 			_rtw_spinunlock_bh(&padapter->mlmepriv.scanned_queue.lock);
1506 			return;
1507 		}
1508 		next_ie = p + 2 + ssid_len_ori;
1509 		remain_len = snetwork->IELength - (next_ie - snetwork->IEs);
1510 		scanned->network.Ssid.SsidLength = bssid->Ssid.SsidLength;
1511 		_rtw_memcpy(scanned->network.Ssid.Ssid, bssid->Ssid.Ssid, bssid->Ssid.SsidLength);
1512 
1513 		//update pnetwork->ssid, pnetwork->ssidlen
1514 		_rtw_memcpy(backupIE, next_ie, remain_len);
1515 		*(p+1) = bssid->Ssid.SsidLength;
1516 		_rtw_memcpy(p+2, bssid->Ssid.Ssid, bssid->Ssid.SsidLength);
1517 		_rtw_memcpy(p+2+bssid->Ssid.SsidLength, backupIE, remain_len);
1518 		snetwork->IELength += bssid->Ssid.SsidLength;
1519 	}
1520 	_rtw_spinunlock_bh(&padapter->mlmepriv.scanned_queue.lock);
1521 }
1522 
1523 #ifdef DBG_RX_BCN
rtw_debug_rx_bcn(_adapter * adapter,u8 * pframe,u32 packet_len)1524 void rtw_debug_rx_bcn(_adapter *adapter, u8 *pframe, u32 packet_len)
1525 {
1526 	struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1527 	struct mlme_ext_info *mlmeinfo = &(pmlmeext->mlmext_info);
1528 	u16 sn = ((struct rtw_ieee80211_hdr_3addr *)pframe)->seq_ctl >> 4;
1529 	u64 tsf, tsf_offset;
1530 	u8 dtim_cnt, dtim_period, tim_bmap, tim_pvbit;
1531 
1532 	update_TSF(pmlmeext, pframe, packet_len);
1533 	tsf = pmlmeext->TSFValue;
1534 	tsf_offset = rtw_modular64(pmlmeext->TSFValue, (mlmeinfo->bcn_interval * 1024));
1535 
1536 	/*get TIM IE*/
1537 	/*DTIM Count*/
1538 	dtim_cnt = pmlmeext->tim[0];
1539 	/*DTIM Period*/
1540 	dtim_period = pmlmeext->tim[1];
1541 	/*Bitmap*/
1542 	tim_bmap = pmlmeext->tim[2];
1543 	/*Partial VBitmap AID 0 ~ 7*/
1544 	tim_pvbit = pmlmeext->tim[3];
1545 
1546 	RTW_INFO("[BCN] SN-%d, TSF-%lld(us), offset-%lld, bcn_interval-%d DTIM-%d[%d] bitmap-0x%02x-0x%02x\n",
1547 		sn, tsf, tsf_offset, mlmeinfo->bcn_interval, dtim_period, dtim_cnt, tim_bmap, tim_pvbit);
1548 }
1549 #endif
1550 
1551 /*
1552  * rtw_get_bcn_keys: get beacon keys from recv frame
1553  *
1554  * TODO:
1555  *	WLAN_EID_COUNTRY
1556  *	WLAN_EID_ERP_INFO
1557  *	WLAN_EID_CHANNEL_SWITCH
1558  *	WLAN_EID_PWR_CONSTRAINT
1559  */
_rtw_get_bcn_keys(u8 * cap_info,u32 buf_len,u8 def_ch,_adapter * adapter,struct beacon_keys * recv_beacon)1560 int _rtw_get_bcn_keys(u8 *cap_info, u32 buf_len, u8 def_ch
1561 	, _adapter *adapter
1562 	, struct beacon_keys *recv_beacon)
1563 {
1564 	int left;
1565 	u16 capability;
1566 	unsigned char *pos;
1567 	struct rtw_ieee802_11_elems elems;
1568 
1569 	_rtw_memset(recv_beacon, 0, sizeof(*recv_beacon));
1570 
1571 	/* checking capabilities */
1572 	capability = le16_to_cpu(*(unsigned short *)(cap_info));
1573 
1574 	/* checking IEs */
1575 	left = buf_len - 2;
1576 	pos = cap_info + 2;
1577 	if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed)
1578 		return _FALSE;
1579 
1580 	if (elems.ht_capabilities) {
1581 		if (elems.ht_capabilities_len != 26)
1582 			return _FALSE;
1583 	}
1584 
1585 	if (elems.ht_operation) {
1586 		if (elems.ht_operation_len != 22)
1587 			return _FALSE;
1588 	}
1589 
1590 	if (elems.vht_capabilities) {
1591 		if (elems.vht_capabilities_len != 12)
1592 			return _FALSE;
1593 	}
1594 
1595 	if (elems.vht_operation) {
1596 		if (elems.vht_operation_len != 5)
1597 			return _FALSE;
1598 	}
1599 
1600 	if (rtw_ies_get_supported_rate(pos, left, recv_beacon->rate_set, &recv_beacon->rate_num) == _FAIL)
1601 		return _FALSE;
1602 
1603 	if (cckratesonly_included(recv_beacon->rate_set, recv_beacon->rate_num) == _TRUE)
1604 		recv_beacon->proto_cap |= PROTO_CAP_11B;
1605 	else if (cckrates_included(recv_beacon->rate_set, recv_beacon->rate_num) == _TRUE)
1606 		recv_beacon->proto_cap |= PROTO_CAP_11B | PROTO_CAP_11G;
1607 	else
1608 		recv_beacon->proto_cap |= PROTO_CAP_11G;
1609 
1610 	if (elems.ht_capabilities && elems.ht_operation)
1611 		recv_beacon->proto_cap |= PROTO_CAP_11N;
1612 
1613 	if (elems.vht_capabilities && elems.vht_operation)
1614 		recv_beacon->proto_cap |= PROTO_CAP_11AC;
1615 
1616 	if (elems.he_capabilities && elems.he_operation)
1617 		recv_beacon->proto_cap |= PROTO_CAP_11AX;
1618 
1619 	/* check bw and channel offset */
1620 	rtw_ies_get_chbw(pos, left, &recv_beacon->ch, &recv_beacon->bw, &recv_beacon->offset, 1, 1);
1621 	if (!recv_beacon->ch)
1622 		recv_beacon->ch = def_ch;
1623 
1624 	/* checking SSID */
1625 	if (elems.ssid) {
1626 		if (elems.ssid_len > sizeof(recv_beacon->ssid))
1627 			return _FALSE;
1628 
1629 		_rtw_memcpy(recv_beacon->ssid, elems.ssid, elems.ssid_len);
1630 		recv_beacon->ssid_len = elems.ssid_len;
1631 	}
1632 
1633 	/* checking RSN first */
1634 	if (elems.rsn_ie && elems.rsn_ie_len) {
1635 		recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_RSN;
1636 		rtw_parse_wpa2_ie(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1637 			&recv_beacon->group_cipher, &recv_beacon->pairwise_cipher,
1638 			NULL, &recv_beacon->akm, NULL, NULL);
1639 	}
1640 	/* checking WPA secon */
1641 	else if (elems.wpa_ie && elems.wpa_ie_len) {
1642 		recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_WPA;
1643 		rtw_parse_wpa_ie(elems.wpa_ie - 2, elems.wpa_ie_len + 2,
1644 			&recv_beacon->group_cipher, &recv_beacon->pairwise_cipher,
1645 				 &recv_beacon->akm);
1646 	} else if (capability & BIT(4))
1647 		recv_beacon->encryp_protocol = ENCRYP_PROTOCOL_WEP;
1648 
1649 	if (adapter) {
1650 		struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1651 
1652 		if (elems.tim && elems.tim_len) {
1653 			#ifdef DBG_RX_BCN
1654 			_rtw_memcpy(pmlmeext->tim, elems.tim, 4);
1655 			#endif
1656 			pmlmeext->dtim = elems.tim[1];
1657 		}
1658 
1659 		/* checking RTW TBTX */
1660 		#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
1661 		if (elems.tbtx_cap && elems.tbtx_cap_len) {
1662 			struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1663 
1664 			if (rtw_is_tbtx_capabilty(elems.tbtx_cap, elems.tbtx_cap_len))
1665 				RTW_DBG("AP support TBTX\n");
1666 		}
1667 		#endif
1668 	}
1669 
1670 	return _TRUE;
1671 }
1672 
rtw_get_bcn_keys(_adapter * adapter,u8 * whdr,u32 flen,struct beacon_keys * bcn_keys)1673 int rtw_get_bcn_keys(_adapter *adapter
1674 	, u8 *whdr, u32 flen, struct beacon_keys *bcn_keys)
1675 {
1676 	return _rtw_get_bcn_keys(
1677 		whdr + WLAN_HDR_A3_LEN + 10
1678 		, flen - WLAN_HDR_A3_LEN - 10
1679 		, adapter->mlmeextpriv.chandef.chan, adapter
1680 		, bcn_keys);
1681 }
1682 
rtw_get_bcn_keys_from_bss(WLAN_BSSID_EX * bss,struct beacon_keys * bcn_keys)1683 int rtw_get_bcn_keys_from_bss(WLAN_BSSID_EX *bss, struct beacon_keys *bcn_keys)
1684 {
1685 	return _rtw_get_bcn_keys(
1686 		bss->IEs + 10
1687 		, bss->IELength - 10
1688 		, bss->Configuration.DSConfig, NULL
1689 		, bcn_keys);
1690 }
1691 
rtw_update_bcn_keys_of_network(struct wlan_network * network)1692 int rtw_update_bcn_keys_of_network(struct wlan_network *network)
1693 {
1694 	network->bcn_keys_valid = rtw_get_bcn_keys_from_bss(&network->network, &network->bcn_keys);
1695 	return network->bcn_keys_valid;
1696 }
1697 
rtw_dump_bcn_keys(void * sel,struct beacon_keys * recv_beacon)1698 void rtw_dump_bcn_keys(void *sel, struct beacon_keys *recv_beacon)
1699 {
1700 	u8 ssid[IW_ESSID_MAX_SIZE + 1];
1701 
1702 	_rtw_memcpy(ssid, recv_beacon->ssid, recv_beacon->ssid_len);
1703 	ssid[recv_beacon->ssid_len] = '\0';
1704 
1705 	RTW_PRINT_SEL(sel, "ssid = %s (len = %u)\n", ssid, recv_beacon->ssid_len);
1706 	RTW_PRINT_SEL(sel, "ch = %u,%u,%u\n"
1707 		, recv_beacon->ch, recv_beacon->bw, recv_beacon->offset);
1708 	RTW_PRINT_SEL(sel, "proto_cap = 0x%02x\n", recv_beacon->proto_cap);
1709 	RTW_MAP_DUMP_SEL(sel, "rate_set = "
1710 		, recv_beacon->rate_set, recv_beacon->rate_num);
1711 	RTW_PRINT_SEL(sel, "sec = %d, group = 0x%x, pair = 0x%x, akm = 0x%08x\n"
1712 		, recv_beacon->encryp_protocol, recv_beacon->group_cipher
1713 		, recv_beacon->pairwise_cipher, recv_beacon->akm);
1714 }
1715 
rtw_bcn_key_compare(struct beacon_keys * cur,struct beacon_keys * recv)1716 bool rtw_bcn_key_compare(struct beacon_keys *cur, struct beacon_keys *recv)
1717 {
1718 #define BCNKEY_VERIFY_PROTO_CAP 0
1719 #define BCNKEY_VERIFY_WHOLE_RATE_SET 0
1720 
1721 	struct beacon_keys tmp;
1722 	bool ret = _FALSE;
1723 
1724 	if (!rtw_is_chbw_grouped(cur->ch, cur->bw, cur->offset
1725 			, recv->ch, recv->bw, recv->offset))
1726 		goto exit;
1727 
1728 	_rtw_memcpy(&tmp, cur, sizeof(tmp));
1729 
1730 	/* check fields excluding below */
1731 	tmp.ch = recv->ch;
1732 	tmp.bw = recv->bw;
1733 	tmp.offset = recv->offset;
1734 	if (!BCNKEY_VERIFY_PROTO_CAP)
1735 		tmp.proto_cap = recv->proto_cap;
1736 	if (!BCNKEY_VERIFY_WHOLE_RATE_SET) {
1737 		tmp.rate_num = recv->rate_num;
1738 		_rtw_memcpy(tmp.rate_set, recv->rate_set, 12);
1739 	}
1740 
1741 	if (_rtw_memcmp(&tmp, recv, sizeof(*recv)) == _FALSE)
1742 		goto exit;
1743 
1744 	ret = _TRUE;
1745 
1746 exit:
1747 	return ret;
1748 }
1749 
rtw_check_bcn_info(_adapter * adapter,u8 * pframe,u32 packet_len)1750 int rtw_check_bcn_info(_adapter *adapter, u8 *pframe, u32 packet_len)
1751 {
1752 	u8 *pbssid = GetAddr3Ptr(pframe);
1753 	struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1754 	struct wlan_network *cur_network = &(adapter->mlmepriv.cur_network);
1755 	struct beacon_keys *cur_beacon = &pmlmepriv->cur_beacon_keys;
1756 	struct beacon_keys recv_beacon;
1757 	int ret = 0;
1758 	u8 ifbmp_m = rtw_mi_get_ap_mesh_ifbmp(adapter);
1759 	u8 ifbmp_s = rtw_mi_get_ld_sta_ifbmp(adapter);
1760 	struct dvobj_priv *d = adapter_to_dvobj(adapter);
1761 	struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1762 	struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1763 	u8 ssid_is_hidden = _FALSE;
1764 
1765 	if (is_client_associated_to_ap(adapter) == _FALSE)
1766 		goto exit_success;
1767 
1768 	if (rtw_get_bcn_keys(adapter, pframe, packet_len, &recv_beacon) == _FALSE)
1769 		goto exit_success; /* parsing failed => broken IE */
1770 
1771 #ifdef DBG_RX_BCN
1772 	rtw_debug_rx_bcn(adapter, pframe, packet_len);
1773 #endif
1774 
1775 	ssid_is_hidden = is_hidden_ssid(recv_beacon.ssid, recv_beacon.ssid_len);
1776 
1777 	if (recv_beacon.ssid_len != cur_beacon->ssid_len) {
1778 		pmlmeinfo->illegal_beacon_code |= SSID_LENGTH_CHANGED;
1779 		pmlmeinfo->illegal_beacon_code |= SSID_CHANGED;
1780 		if (!ssid_is_hidden) {
1781 			RTW_WARN("%s: Ignore ssid len change new %d old %d\n",
1782 				 __func__, recv_beacon.ssid_len,
1783 				 cur_beacon->ssid_len);
1784 		}
1785 	} else if ((_rtw_memcmp(recv_beacon.ssid,
1786 				cur_beacon->ssid,
1787 				cur_beacon->ssid_len) == _FALSE)) {
1788 		pmlmeinfo->illegal_beacon_code |= SSID_CHANGED;
1789 		if (!ssid_is_hidden) {
1790 			RTW_INFO_DUMP("[old ssid]: ",
1791 				      cur_beacon->ssid, cur_beacon->ssid_len);
1792 			RTW_INFO_DUMP("[new ssid]: ",
1793 				      recv_beacon.ssid, cur_beacon->ssid_len);
1794 		}
1795 	}
1796 
1797 	/* hidden ssid, replace with current beacon ssid directly */
1798 	if (ssid_is_hidden) {
1799 		_rtw_memcpy(recv_beacon.ssid, cur_beacon->ssid, cur_beacon->ssid_len);
1800 		recv_beacon.ssid_len = cur_beacon->ssid_len;
1801 	}
1802 
1803 #if CONFIG_DFS
1804 	if (check_fwstate(pmlmepriv, WIFI_CSA_UPDATE_BEACON)) {
1805 		u8 u_ch, u_offset, u_bw;
1806 		u8 bcn_ch, bcn_bw, bcn_offset;
1807 		struct sta_info *psta = NULL;
1808 		struct rtw_chan_def mr_chdef = {0};
1809 		struct rtw_chan_def new_chdef = {0};
1810 
1811 		/* get union ch/bw/offset from chan_ctx */
1812 		rtw_phl_mr_get_chandef(d->phl, adapter->phl_role, &mr_chdef);
1813 		u_ch = mr_chdef.chan;
1814 		u_offset = (u8)mr_chdef.offset;
1815 		u_bw = (u8)mr_chdef.bw;
1816 
1817 		#ifdef DBG_CSA
1818 		RTW_INFO("CSA : before update beacon, u_ch=%u, recv_beacon.ch=%u\n", u_ch, recv_beacon.ch);
1819 		#endif
1820 
1821 		if (pmlmepriv->bcn_cnts_after_csa < 5) {
1822 			if (u_ch == recv_beacon.ch)
1823 				pmlmepriv->bcn_cnts_after_csa += 1;
1824 			goto exit_success;
1825 		} else
1826 			pmlmepriv->bcn_cnts_after_csa = 0;
1827 
1828 		_rtw_memcpy(cur_beacon, &recv_beacon, sizeof(recv_beacon));
1829 		clr_fwstate(pmlmepriv, WIFI_CSA_UPDATE_BEACON);
1830 
1831 		bcn_ch = recv_beacon.ch;
1832 		bcn_bw = recv_beacon.bw;
1833 		bcn_offset = recv_beacon.offset;
1834 
1835 		#ifdef DBG_CSA
1836 		RTW_INFO("CSA : after update beacon, recv_beacon.ch=%u, recv_beacon.bw=%u, recv_beacon.offset=%u\n", \
1837 			bcn_ch, bcn_bw, bcn_offset);
1838 		rtw_dump_bcn_keys(RTW_DBGDUMP, &recv_beacon);
1839 		#endif
1840 
1841 		_cancel_timer_nowait(&pmlmeext->csa_timer);
1842 
1843 		/* beacon bw/offset is different from CSA IE */
1844 		if ((bcn_bw > u_bw) ||
1845 			(bcn_offset != u_offset &&
1846 			u_offset != CHAN_OFFSET_NO_EXT &&
1847 			bcn_offset != CHAN_OFFSET_NO_EXT)) {
1848 
1849 			pmlmeext->chandef.bw = bcn_bw;
1850 			pmlmeext->chandef.offset = bcn_offset;
1851 			/* updaet STA mode DSConfig , ap mode will update in rtw_change_bss_chbw_cmd */
1852 			pmlmepriv->cur_network.network.Configuration.DSConfig = bcn_ch;
1853 
1854 			/* update wifi role chandef */
1855 			rtw_hw_update_chan_def(adapter);
1856 
1857 			/* update chanctx */
1858 			if (rtw_phl_mr_upt_chandef(d->phl, adapter->phl_role) == RTW_PHL_STATUS_FAILURE)
1859 				RTW_ERR("CSA : update chanctx fail\n");
1860 
1861 			rtw_phl_mr_get_chandef(d->phl, adapter->phl_role, &new_chdef);
1862 			rtw_mi_update_union_chan_inf(adapter, new_chdef.chan, (u8)new_chdef.offset, (u8)new_chdef.bw);
1863 
1864 			#ifdef CONFIG_AP_MODE
1865 			if (ifbmp_m) {
1866 				rtw_change_bss_chbw_cmd(dvobj_get_primary_adapter(d), 0
1867 					, ifbmp_m, 0, new_chdef.chan, REQ_BW_ORI, REQ_OFFSET_NONE);
1868 			} else
1869 			#endif
1870 			{
1871 				#ifdef CONFIG_DFS_MASTER
1872 				rtw_dfs_rd_en_decision(adapter, MLME_OPCH_SWITCH, ifbmp_s);
1873 				#endif
1874 				rtw_set_chbw_cmd(adapter, new_chdef.chan, (u8)new_chdef.bw, (u8)new_chdef.offset, 0);
1875 			}
1876 			RTW_INFO("CSA : after update bw/offset, new_bw=%d, new_offset=%d \n", \
1877 				(u8)new_chdef.bw, (u8)new_chdef.offset);
1878 		} else {
1879 			RTW_INFO("CSA : u_ch=%d, u_bw=%d, u_offset=%d, recv_beacon.ch=%d, recv_beacon.bw=%d, recv_beacon.offset=%d\n"
1880 			, u_ch, u_bw, u_offset, bcn_ch, bcn_bw, bcn_offset);
1881 		}
1882 
1883 		/* update RA mask */
1884 		psta = rtw_get_stainfo(&adapter->stapriv, get_bssid(&adapter->mlmepriv));
1885 		if (psta) {
1886 			psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
1887 			rtw_phl_cmd_change_stainfo(GET_PHL_INFO(d),
1888 						psta->phl_sta,
1889 						STA_CHG_RAMASK,
1890 						NULL,
1891 						0,
1892 						PHL_CMD_NO_WAIT,
1893 						0);
1894 		}
1895 
1896 		RTW_INFO("CSA : update beacon done, WIFI_CSA_UPDATE_BEACON is clear\n");
1897 	}
1898 #endif /* CONFIG_DFS */
1899 
1900 	if (_rtw_memcmp(&recv_beacon, cur_beacon, sizeof(recv_beacon)) == _FALSE) {
1901 		RTW_INFO(FUNC_ADPT_FMT" new beacon occur!!\n", FUNC_ADPT_ARG(adapter));
1902 		RTW_INFO(FUNC_ADPT_FMT" cur beacon key:\n", FUNC_ADPT_ARG(adapter));
1903 		rtw_dump_bcn_keys(RTW_DBGDUMP, cur_beacon);
1904 		RTW_INFO(FUNC_ADPT_FMT" new beacon key:\n", FUNC_ADPT_ARG(adapter));
1905 		rtw_dump_bcn_keys(RTW_DBGDUMP, &recv_beacon);
1906 
1907 		if (recv_beacon.ch != cur_beacon->ch)
1908 			pmlmeinfo->illegal_beacon_code |= BEACON_CHANNEL_CHANGED;
1909 		if (recv_beacon.encryp_protocol != cur_beacon->encryp_protocol)
1910 			pmlmeinfo->illegal_beacon_code |= ENCRYPT_PROTOCOL_CHANGED;
1911 		if (recv_beacon.pairwise_cipher != cur_beacon->pairwise_cipher)
1912 			pmlmeinfo->illegal_beacon_code |= PAIRWISE_CIPHER_CHANGED;
1913 		if (recv_beacon.group_cipher != cur_beacon->group_cipher)
1914 			pmlmeinfo->illegal_beacon_code |= GROUP_CIPHER_CHANGED;
1915 		if (recv_beacon.akm != cur_beacon->akm)
1916 			pmlmeinfo->illegal_beacon_code |= IS_8021X_CHANGED;
1917 
1918 		if (rtw_bcn_key_compare(cur_beacon, &recv_beacon) == _FALSE)
1919 			goto exit;
1920 
1921 		_rtw_memcpy(cur_beacon, &recv_beacon, sizeof(recv_beacon));
1922 	}
1923 
1924 exit_success:
1925 	ret = 1;
1926 
1927 exit:
1928 	return ret;
1929 }
1930 
update_beacon_info(_adapter * padapter,u8 * pframe,uint pkt_len,struct sta_info * psta)1931 void update_beacon_info(_adapter *padapter, u8 *pframe, uint pkt_len, struct sta_info *psta)
1932 {
1933 	unsigned int i;
1934 	unsigned int len;
1935 	PNDIS_802_11_VARIABLE_IEs	pIE;
1936 
1937 #ifdef CONFIG_TDLS
1938 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
1939 	u8 tdls_prohibited[] = { 0x00, 0x00, 0x00, 0x00, 0x10 }; /* bit(38): TDLS_prohibited */
1940 #endif /* CONFIG_TDLS */
1941 
1942 	len = pkt_len - (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN);
1943 
1944 	for (i = 0; i < len;) {
1945 		pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + (_BEACON_IE_OFFSET_ + WLAN_HDR_A3_LEN) + i);
1946 
1947 		switch (pIE->ElementID) {
1948 		case _VENDOR_SPECIFIC_IE_:
1949 			/* to update WMM paramter set while receiving beacon */
1950 			if (_rtw_memcmp(pIE->data, WMM_PARA_OUI, 6) && pIE->Length == WLAN_WMM_LEN)	/* WMM */
1951 				(WMM_param_handler(padapter, pIE)) ? report_wmm_edca_update(padapter) : 0;
1952 
1953 			break;
1954 
1955 		case _HT_EXTRA_INFO_IE_:	/* HT info */
1956 			/* HT_info_handler(padapter, pIE); */
1957 			bwmode_update_check(padapter, pIE);
1958 			break;
1959 #ifdef CONFIG_80211AC_VHT
1960 		case EID_OpModeNotification:
1961 			rtw_process_vht_op_mode_notify(padapter, pIE->data, psta);
1962 			break;
1963 #endif /* CONFIG_80211AC_VHT */
1964 		case _ERPINFO_IE_:
1965 			ERP_IE_handler(padapter, pIE);
1966 			VCS_update(padapter, psta);
1967 			break;
1968 
1969 #ifdef CONFIG_TDLS
1970 		case WLAN_EID_EXT_CAP:
1971 			if (check_ap_tdls_prohibited(pIE->data, pIE->Length) == _TRUE)
1972 				ptdlsinfo->ap_prohibited = _TRUE;
1973 			if (check_ap_tdls_ch_switching_prohibited(pIE->data, pIE->Length) == _TRUE)
1974 				ptdlsinfo->ch_switch_prohibited = _TRUE;
1975 			break;
1976 #endif /* CONFIG_TDLS */
1977 #ifdef CONFIG_80211AX_HE
1978 		case WLAN_EID_EXTENSION:
1979 			if (pIE->data[0] == WLAN_EID_EXTENSION_HE_OPERATION)
1980 				HE_operation_handler(padapter, pIE);
1981 			else if (pIE->data[0] == WLAN_EID_EXTENSION_HE_MU_EDCA)
1982 				HE_mu_edca_handler(padapter, pIE, _FALSE);
1983 			break;
1984 #endif
1985 		default:
1986 			break;
1987 		}
1988 
1989 		i += (pIE->Length + 2);
1990 	}
1991 }
1992 
1993 #if CONFIG_DFS
process_csa_ie(_adapter * padapter,u8 * ies,uint ies_len)1994 void process_csa_ie(_adapter *padapter, u8 *ies, uint ies_len)
1995 {
1996 #ifdef CONFIG_ECSA_PHL
1997 	struct core_ecsa_info *ecsa_info = &(padapter->ecsa_info);
1998 	struct rtw_phl_ecsa_param *ecsa_param = &(ecsa_info->phl_ecsa_param);
1999 #endif
2000 	struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
2001 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2002 	struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2003 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2004 	unsigned int i, j, countdown;
2005 	PNDIS_802_11_VARIABLE_IEs pIE, sub_pie;
2006 	u8 ch = 0, csa_ch_offset = 0, csa_ch_width = 0, csa_ch_freq_seg0 = 0, csa_ch_freq_seg1 = 0;
2007 	u8 csa_switch_cnt = 0, csa_mode = 0;
2008 	u8 is_csa_running;
2009 
2010 #ifdef DBG_CSA
2011 	u8 *p;
2012 	u32 ie_len = 0;
2013 	p = rtw_get_ie(ies, WLAN_EID_CHANNEL_SWITCH, &ie_len, ies_len);
2014 	if (p && ie_len > 0)
2015 		RTW_INFO("CSA : %s, CH = %u, count = %u\n",__func__, *(p+2+1), *(p+2+2));
2016 #endif
2017 
2018 #ifdef CONFIG_ECSA_PHL
2019 	is_csa_running = rtw_mr_is_ecsa_running(padapter);
2020 #else
2021 	is_csa_running = (rfctl->csa_chandef.chan > 0) ? _TRUE : _FALSE;
2022 #endif
2023 
2024 	/* compare with scheduling CSA to block incoming CSA IE */
2025 	if (is_csa_running || check_fwstate(pmlmepriv, WIFI_CSA_UPDATE_BEACON))
2026 		return;
2027 
2028 	for (i = 0; i + 1 < ies_len;) {
2029 		pIE = (PNDIS_802_11_VARIABLE_IEs)(ies + i);
2030 
2031 		switch (pIE->ElementID) {
2032 		case WLAN_EID_CHANNEL_SWITCH:
2033 			csa_mode = *(pIE->data);
2034 			ch = *(pIE->data + 1);
2035 			csa_switch_cnt = *(pIE->data + 2);
2036 
2037 			RTW_INFO("CSA : mode = %u, ch = %u, switch count = %u\n",
2038 				csa_mode, ch, csa_switch_cnt);
2039 			break;
2040 		case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
2041 			csa_ch_offset = *(pIE->data);
2042 			break;
2043 		case WLAN_EID_WIDE_BANDWIDTH_CHANNEL_SWITCH:
2044 			csa_ch_width = *(pIE->data);
2045 			csa_ch_freq_seg0 = *(pIE->data+1);
2046 			csa_ch_freq_seg1 = *(pIE->data+2);
2047 
2048 			RTW_INFO("CSA : bw:%02x center_freq_0:%u center_freq_1:%u, ch=%u\n"
2049 					, csa_ch_width, csa_ch_freq_seg0, csa_ch_freq_seg1, ch);
2050 			break;
2051 		case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
2052 			for (j=0; j + 1 < pIE->Length;) {
2053 				sub_pie = (PNDIS_802_11_VARIABLE_IEs)(ies + i + j + 2);
2054 				if (sub_pie->ElementID == WLAN_EID_WIDE_BANDWIDTH_CHANNEL_SWITCH) {
2055 					csa_ch_width = *(sub_pie->data);
2056 					csa_ch_freq_seg0 = *(sub_pie->data+1);
2057 					csa_ch_freq_seg1 = *(sub_pie->data+2);
2058 
2059 					RTW_INFO("CSA : sub_IE:%02x IE_length:%02x bw:%02x center_freq_0:%u center_freq_1:%u, ch=%u\n"
2060 						, sub_pie->ElementID, sub_pie->Length, csa_ch_width, csa_ch_freq_seg0, csa_ch_freq_seg1, ch);
2061 				}
2062 				j += (sub_pie->Length + 2);
2063 			}
2064 			break;
2065 		default:
2066 			break;
2067 		}
2068 
2069 		i += (pIE->Length + 2);
2070 	}
2071 
2072 	/* Doesn't support switch bandwidth/offset in the same channel for now */
2073 	if (ch == rtw_mi_get_union_chan(padapter)) {
2074 		RTW_ERR("%s : receive the same channel from CSA IE, so ignore it\n", __func__);
2075 		return;
2076 	}
2077 
2078 	if (ch != 0) {
2079 		#ifdef CONFIG_ECSA_PHL
2080 		ecsa_param->ecsa_type = ECSA_TYPE_STA;
2081 		ecsa_param->mode = csa_mode;
2082 		ecsa_param->count = csa_switch_cnt;
2083 		/* ecsa_param.op_class = rfctl->op_class; */ /* TODO : ECSA */
2084 		ecsa_param->new_chan_def.band = rtw_phl_get_band_type(ch);
2085 		ecsa_param->new_chan_def.chan = ch;
2086 		/* The channel width defined in 802.11 spec */
2087 		ecsa_info->channel_width = csa_ch_width;
2088 		ecsa_param->new_chan_def.offset = csa_ch_offset;
2089 		ecsa_param->new_chan_def.center_freq1 = csa_ch_freq_seg0;
2090 		ecsa_param->new_chan_def.center_freq2 = csa_ch_freq_seg1;
2091 		ecsa_param->flag = 0;
2092 		ecsa_param->delay_start_ms = 0;
2093 
2094 		SET_ECSA_STATE(padapter, ECSA_ST_SW_START);
2095 		rtw_trigger_phl_ecsa_start(padapter);
2096 		#else
2097 		rfctl->csa_mode = csa_mode;
2098 		rfctl->csa_switch_cnt = csa_switch_cnt;
2099 		rfctl->csa_ch_width = csa_ch_width;
2100 
2101 		rfctl->csa_chandef.band = rtw_phl_get_band_type(ch);
2102 		rfctl->csa_chandef.chan = ch;
2103 		rfctl->csa_chandef.offset = csa_ch_offset;
2104 		rfctl->csa_chandef.center_freq1= csa_ch_freq_seg0;
2105 		rfctl->csa_chandef.center_freq2 = csa_ch_freq_seg1;
2106 
2107 		countdown = pmlmeinfo->network.Configuration.BeaconPeriod * (csa_switch_cnt+1); /* ms */
2108 		RTW_INFO("csa: set countdown timer to %d ms\n", countdown);
2109 		_set_timer(&pmlmeext->csa_timer, countdown);
2110 		#endif /* CONFIG_ECSA_PHL */
2111 	}
2112 }
2113 #endif /* CONFIG_DFS */
2114 
2115 #ifdef CONFIG_80211D
rtw_iface_accept_country_ie(_adapter * adapter)2116 bool rtw_iface_accept_country_ie(_adapter *adapter)
2117 {
2118 	struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
2119 
2120 	if (!(BIT(adapter->iface_id) & rfctl->country_ie_slave_en_ifbmp))
2121 		return 0;
2122 	if (!MLME_IS_STA(adapter))
2123 		return 0;
2124 	if (!MLME_IS_GC(adapter)) {
2125 		if (!(rfctl->country_ie_slave_en_role & COUNTRY_IE_SLAVE_EN_ROLE_STA))
2126 			return 0;
2127 	} else {
2128 		if (!(rfctl->country_ie_slave_en_role & COUNTRY_IE_SLAVE_EN_ROLE_GC))
2129 			return 0;
2130 	}
2131 	return 1;
2132 }
2133 
process_country_ie(_adapter * adapter,u8 * ies,uint ies_len)2134 void process_country_ie(_adapter *adapter, u8 *ies, uint ies_len)
2135 {
2136 	struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
2137 
2138 	if (rfctl->regd_src == REGD_SRC_RTK_PRIV
2139 		&& !rtw_rfctl_is_disable_sw_channel_plan(rfctl_to_dvobj(rfctl))
2140 		&& !rfctl->csa_chandef.chan /* don't process country ie when under CSA processing */
2141 	) {
2142 		struct mlme_priv *mlme = &adapter->mlmepriv;
2143 		const u8 *ie = NULL;
2144 		sint ie_len = 0;
2145 
2146 		if (rtw_iface_accept_country_ie(adapter)) {
2147 			ie = rtw_get_ie(ies, WLAN_EID_COUNTRY, &ie_len, ies_len);
2148 			if (ie) {
2149 				if (ie_len < 6) {
2150 					ie = NULL;
2151 					ie_len = 0;
2152 				} else
2153 					ie_len += 2;
2154 			}
2155 		}
2156 
2157 		if (!mlme->recv_country_ie && !ie)
2158 			return;
2159 		if (mlme->recv_country_ie_len == ie_len
2160 			&& _rtw_memcmp(mlme->recv_country_ie, ie, ie_len) == _TRUE)
2161 			return;
2162 
2163 		if (!ie) {
2164 			rtw_buf_free(&mlme->recv_country_ie, &mlme->recv_country_ie_len);
2165 			rtw_apply_recv_country_ie_cmd(adapter, 0, 0, 0, NULL);
2166 		} else {
2167 			char ori_alpha2[2] = {0, 0};
2168 
2169 			if (mlme->recv_country_ie)
2170 				_rtw_memcpy(ori_alpha2, mlme->recv_country_ie + 2, 2);
2171 
2172 			rtw_buf_update(&mlme->recv_country_ie, &mlme->recv_country_ie_len, ie, ie_len);
2173 			/* for now only country code is used */
2174 			if (_rtw_memcmp(ori_alpha2, mlme->recv_country_ie + 2, 2) == _TRUE)
2175 				return;
2176 			RTW_INFO(FUNC_ADPT_FMT" country_ie alpha2 changed\n", FUNC_ADPT_ARG(adapter));
2177 			rtw_apply_recv_country_ie_cmd(adapter, 0
2178 				, mlme->cur_beacon_keys.ch > 14 ? BAND_ON_5G : BAND_ON_24G
2179 				, mlme->cur_beacon_keys.ch, mlme->recv_country_ie);
2180 		}
2181 	}
2182 }
2183 #endif /* CONFIG_80211D */
2184 
parsing_eapol_packet(_adapter * padapter,u8 * key_payload,struct sta_info * psta,u8 trx_type)2185 enum eap_type parsing_eapol_packet(_adapter *padapter, u8 *key_payload, struct sta_info *psta, u8 trx_type)
2186 {
2187 	struct security_priv *psecuritypriv = &(padapter->securitypriv);
2188 	struct ieee802_1x_hdr *hdr;
2189 	struct wpa_eapol_key *key;
2190 	u16 key_info, key_data_length;
2191 	char *trx_msg = trx_type ? "send" : "recv";
2192 	enum eap_type eapol_type;
2193 
2194 	hdr = (struct ieee802_1x_hdr *) key_payload;
2195 
2196 	 /* WPS - eapol start packet */
2197 	if (hdr->type == 1 && hdr->length == 0) {
2198 		RTW_INFO("%s eapol start packet\n", trx_msg);
2199 		return EAPOL_START;
2200 	}
2201 
2202 	if (hdr->type == 0) { /* WPS - eapol packet */
2203 		RTW_INFO("%s eapol packet\n", trx_msg);
2204 		return EAPOL_PACKET;
2205 	}
2206 
2207 	key = (struct wpa_eapol_key *) (hdr + 1);
2208 	key_info = be16_to_cpu(*((u16 *)(key->key_info)));
2209 	key_data_length = be16_to_cpu(*((u16 *)(key->key_data_length)));
2210 
2211 	if (!(key_info & WPA_KEY_INFO_KEY_TYPE)) { /* WPA group key handshake */
2212 		if (key_info & WPA_KEY_INFO_ACK) {
2213 			RTW_PRINT("%s eapol packet - WPA Group Key 1/2\n", trx_msg);
2214 			eapol_type = EAPOL_WPA_GROUP_KEY_1_2;
2215 		} else {
2216 			RTW_PRINT("%s eapol packet - WPA Group Key 2/2\n", trx_msg);
2217 			eapol_type = EAPOL_WPA_GROUP_KEY_2_2;
2218 
2219 			/* WPA key-handshake has completed */
2220 			if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPAPSK)
2221 				psta->state &= (~WIFI_UNDER_KEY_HANDSHAKE);
2222 		}
2223 	} else if (key_info & WPA_KEY_INFO_MIC) {
2224 		if (key_data_length == 0) {
2225 			RTW_PRINT("%s eapol packet 4/4\n", trx_msg);
2226 			eapol_type = EAPOL_4_4;
2227 		} else if (key_info & WPA_KEY_INFO_ACK) {
2228 			RTW_PRINT("%s eapol packet 3/4\n", trx_msg);
2229 			eapol_type = EAPOL_3_4;
2230 		} else {
2231 			RTW_PRINT("%s eapol packet 2/4\n", trx_msg);
2232 			eapol_type = EAPOL_2_4;
2233 		}
2234 	} else {
2235 		RTW_PRINT("%s eapol packet 1/4\n", trx_msg);
2236 		eapol_type = EAPOL_1_4;
2237 	}
2238 
2239 	return eapol_type;
2240 }
2241 
is_ap_in_tkip(_adapter * padapter)2242 unsigned int is_ap_in_tkip(_adapter *padapter)
2243 {
2244 	u32 i;
2245 	PNDIS_802_11_VARIABLE_IEs	pIE;
2246 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2247 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2248 	WLAN_BSSID_EX		*cur_network = &(pmlmeinfo->network);
2249 
2250 	if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
2251 		for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;) {
2252 			pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
2253 
2254 			switch (pIE->ElementID) {
2255 			case _VENDOR_SPECIFIC_IE_:
2256 				if ((_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4)) && (_rtw_memcmp((pIE->data + 12), WPA_TKIP_CIPHER, 4)))
2257 					return _TRUE;
2258 				break;
2259 
2260 			case _RSN_IE_2_:
2261 				if (_rtw_memcmp((pIE->data + 8), RSN_TKIP_CIPHER, 4))
2262 					return _TRUE;
2263 
2264 			default:
2265 				break;
2266 			}
2267 
2268 			i += (pIE->Length + 2);
2269 		}
2270 
2271 		return _FALSE;
2272 	} else
2273 		return _FALSE;
2274 
2275 }
2276 
should_forbid_n_rate(_adapter * padapter)2277 unsigned int should_forbid_n_rate(_adapter *padapter)
2278 {
2279 	u32 i;
2280 	PNDIS_802_11_VARIABLE_IEs	pIE;
2281 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
2282 	WLAN_BSSID_EX  *cur_network = &pmlmepriv->cur_network.network;
2283 
2284 	if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
2285 		for (i = sizeof(NDIS_802_11_FIXED_IEs); i < cur_network->IELength;) {
2286 			pIE = (PNDIS_802_11_VARIABLE_IEs)(cur_network->IEs + i);
2287 
2288 			switch (pIE->ElementID) {
2289 			case _VENDOR_SPECIFIC_IE_:
2290 				if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4) &&
2291 				    ((_rtw_memcmp((pIE->data + 12), WPA_CIPHER_SUITE_CCMP, 4)) ||
2292 				     (_rtw_memcmp((pIE->data + 16), WPA_CIPHER_SUITE_CCMP, 4))))
2293 					return _FALSE;
2294 				break;
2295 
2296 			case _RSN_IE_2_:
2297 				if ((_rtw_memcmp((pIE->data + 8), RSN_CIPHER_SUITE_CCMP, 4))  ||
2298 				    (_rtw_memcmp((pIE->data + 12), RSN_CIPHER_SUITE_CCMP, 4)))
2299 					return _FALSE;
2300 
2301 			default:
2302 				break;
2303 			}
2304 
2305 			i += (pIE->Length + 2);
2306 		}
2307 
2308 		return _TRUE;
2309 	} else
2310 		return _FALSE;
2311 
2312 }
2313 
2314 
is_ap_in_wep(_adapter * padapter)2315 unsigned int is_ap_in_wep(_adapter *padapter)
2316 {
2317 	u32 i;
2318 	PNDIS_802_11_VARIABLE_IEs	pIE;
2319 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2320 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2321 	WLAN_BSSID_EX		*cur_network = &(pmlmeinfo->network);
2322 
2323 	if (rtw_get_capability((WLAN_BSSID_EX *)cur_network) & WLAN_CAPABILITY_PRIVACY) {
2324 		for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pmlmeinfo->network.IELength;) {
2325 			pIE = (PNDIS_802_11_VARIABLE_IEs)(pmlmeinfo->network.IEs + i);
2326 
2327 			switch (pIE->ElementID) {
2328 			case _VENDOR_SPECIFIC_IE_:
2329 				if (_rtw_memcmp(pIE->data, RTW_WPA_OUI, 4))
2330 					return _FALSE;
2331 				break;
2332 
2333 			case _RSN_IE_2_:
2334 				return _FALSE;
2335 
2336 			default:
2337 				break;
2338 			}
2339 
2340 			i += (pIE->Length + 2);
2341 		}
2342 
2343 		return _TRUE;
2344 	} else
2345 		return _FALSE;
2346 
2347 }
2348 
2349 int wifirate2_ratetbl_inx(unsigned char rate);
wifirate2_ratetbl_inx(unsigned char rate)2350 int wifirate2_ratetbl_inx(unsigned char rate)
2351 {
2352 	int	inx = 0;
2353 	rate = rate & 0x7f;
2354 
2355 	switch (rate) {
2356 	case 54*2:
2357 		inx = 11;
2358 		break;
2359 
2360 	case 48*2:
2361 		inx = 10;
2362 		break;
2363 
2364 	case 36*2:
2365 		inx = 9;
2366 		break;
2367 
2368 	case 24*2:
2369 		inx = 8;
2370 		break;
2371 
2372 	case 18*2:
2373 		inx = 7;
2374 		break;
2375 
2376 	case 12*2:
2377 		inx = 6;
2378 		break;
2379 
2380 	case 9*2:
2381 		inx = 5;
2382 		break;
2383 
2384 	case 6*2:
2385 		inx = 4;
2386 		break;
2387 
2388 	case 11*2:
2389 		inx = 3;
2390 		break;
2391 	case 11:
2392 		inx = 2;
2393 		break;
2394 
2395 	case 2*2:
2396 		inx = 1;
2397 		break;
2398 
2399 	case 1*2:
2400 		inx = 0;
2401 		break;
2402 
2403 	}
2404 	return inx;
2405 }
2406 
update_basic_rate(unsigned char * ptn,unsigned int ptn_sz)2407 unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz)
2408 {
2409 	unsigned int i, num_of_rate;
2410 	unsigned int mask = 0;
2411 
2412 	num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
2413 
2414 	for (i = 0; i < num_of_rate; i++) {
2415 		if ((*(ptn + i)) & 0x80)
2416 			mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
2417 	}
2418 	return mask;
2419 }
2420 
update_supported_rate(unsigned char * ptn,unsigned int ptn_sz)2421 unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz)
2422 {
2423 	unsigned int i, num_of_rate;
2424 	unsigned int mask = 0;
2425 
2426 	num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
2427 
2428 	for (i = 0; i < num_of_rate; i++)
2429 		mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
2430 
2431 	return mask;
2432 }
2433 
support_short_GI(_adapter * padapter,struct HT_caps_element * pHT_caps,u8 bwmode)2434 int support_short_GI(_adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode)
2435 {
2436 	unsigned char					bit_offset;
2437 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
2438 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2439 
2440 	if (!(pmlmeinfo->HT_enable))
2441 		return _FAIL;
2442 
2443 	bit_offset = (bwmode & CHANNEL_WIDTH_40) ? 6 : 5;
2444 
2445 	if (pHT_caps->u.HT_cap_element.HT_caps_info & (0x1 << bit_offset))
2446 		return _SUCCESS;
2447 	else
2448 		return _FAIL;
2449 }
2450 
get_highest_rate_idx(u64 mask)2451 unsigned char get_highest_rate_idx(u64 mask)
2452 {
2453 	int i;
2454 	unsigned char rate_idx = 0;
2455 
2456 	for (i = 63; i >= 0; i--) {
2457 		if ((mask >> i) & 0x01) {
2458 			rate_idx = i;
2459 			break;
2460 		}
2461 	}
2462 
2463 	return rate_idx;
2464 }
get_lowest_rate_idx_ex(u64 mask,int start_bit)2465 unsigned char get_lowest_rate_idx_ex(u64 mask, int start_bit)
2466 {
2467 	int i;
2468 	unsigned char rate_idx = 0;
2469 
2470 	for (i = start_bit; i < 64; i++) {
2471 		if ((mask >> i) & 0x01) {
2472 			rate_idx = i;
2473 			break;
2474 		}
2475 	}
2476 
2477 	return rate_idx;
2478 }
2479 
get_highest_bw_cap(u8 bwmode)2480 u8 get_highest_bw_cap(u8 bwmode)
2481 {
2482 	u8 hbw = CHANNEL_WIDTH_20;
2483 
2484 	if (bwmode & BW_CAP_80_80M)
2485 		hbw = CHANNEL_WIDTH_80_80;
2486 	else if (bwmode & BW_CAP_160M)
2487 		hbw = CHANNEL_WIDTH_160;
2488 	else if (bwmode & BW_CAP_80M)
2489 		hbw = CHANNEL_WIDTH_80;
2490 	else if (bwmode & BW_CAP_40M)
2491 		hbw = CHANNEL_WIDTH_40;
2492 	else if (bwmode & BW_CAP_20M)
2493 		hbw = CHANNEL_WIDTH_20;
2494 	else if (bwmode & BW_CAP_10M)
2495 		hbw = CHANNEL_WIDTH_10;
2496 	else if (bwmode & BW_CAP_5M)
2497 		hbw = CHANNEL_WIDTH_5;
2498 
2499 	return hbw;
2500 }
2501 
2502 /* Update RRSR and Rate for USERATE */
update_tx_basic_rate(_adapter * padapter,u8 wirelessmode)2503 void update_tx_basic_rate(_adapter *padapter, u8 wirelessmode)
2504 {
2505 	NDIS_802_11_RATES_EX	supported_rates;
2506 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
2507 
2508 	_rtw_memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
2509 
2510 	/* clear B mod if current channel is in 5G band, avoid tx cck rate in 5G band. */
2511 	if (pmlmeext->chandef.chan > 14)
2512 		wirelessmode &= ~(WLAN_MD_11B);
2513 
2514 	if ((wirelessmode & WLAN_MD_11B) && (wirelessmode == WLAN_MD_11B))
2515 		_rtw_memcpy(supported_rates, rtw_basic_rate_cck, 4);
2516 	else if (wirelessmode & WLAN_MD_11B)
2517 		_rtw_memcpy(supported_rates, rtw_basic_rate_mix, 7);
2518 	else
2519 		_rtw_memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
2520 
2521 	if (wirelessmode & WLAN_MD_11B)
2522 		update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
2523 	else
2524 		update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
2525 
2526 	rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, supported_rates);
2527 }
2528 
check_assoc_AP(u8 * pframe,uint len)2529 unsigned char check_assoc_AP(u8 *pframe, uint len)
2530 {
2531 	unsigned int	i;
2532 	PNDIS_802_11_VARIABLE_IEs	pIE;
2533 
2534 	for (i = sizeof(NDIS_802_11_FIXED_IEs); i < len;) {
2535 		pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
2536 
2537 		switch (pIE->ElementID) {
2538 		case _VENDOR_SPECIFIC_IE_:
2539 			if ((_rtw_memcmp(pIE->data, ARTHEROS_OUI1, 3)) || (_rtw_memcmp(pIE->data, ARTHEROS_OUI2, 3))) {
2540 				RTW_INFO("link to Artheros AP\n");
2541 				return HT_IOT_PEER_ATHEROS;
2542 			} else if ((_rtw_memcmp(pIE->data, BROADCOM_OUI1, 3))
2543 				   || (_rtw_memcmp(pIE->data, BROADCOM_OUI2, 3))
2544 				|| (_rtw_memcmp(pIE->data, BROADCOM_OUI3, 3))) {
2545 				RTW_INFO("link to Broadcom AP\n");
2546 				return HT_IOT_PEER_BROADCOM;
2547 			} else if (_rtw_memcmp(pIE->data, MARVELL_OUI, 3)) {
2548 				RTW_INFO("link to Marvell AP\n");
2549 				return HT_IOT_PEER_MARVELL;
2550 			} else if (_rtw_memcmp(pIE->data, RALINK_OUI, 3)) {
2551 				RTW_INFO("link to Ralink AP\n");
2552 				return HT_IOT_PEER_RALINK;
2553 			} else if (_rtw_memcmp(pIE->data, CISCO_OUI, 3)) {
2554 				RTW_INFO("link to Cisco AP\n");
2555 				return HT_IOT_PEER_CISCO;
2556 			} else if (_rtw_memcmp(pIE->data, REALTEK_OUI, 3)) {
2557 				u32	Vender = HT_IOT_PEER_REALTEK;
2558 
2559 				if (pIE->Length >= 5) {
2560 					if (pIE->data[4] == 1) {
2561 						/* if(pIE->data[5] & RT_HT_CAP_USE_LONG_PREAMBLE) */
2562 						/*	bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_LONG_PREAMBLE; */
2563 
2564 						if (pIE->data[5] & RT_HT_CAP_USE_92SE) {
2565 							/* bssDesc->BssHT.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE; */
2566 							Vender = HT_IOT_PEER_REALTEK_92SE;
2567 						}
2568 					}
2569 
2570 					if (pIE->data[5] & RT_HT_CAP_USE_SOFTAP)
2571 						Vender = HT_IOT_PEER_REALTEK_SOFTAP;
2572 
2573 					if (pIE->data[4] == 2) {
2574 						if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CBV) {
2575 							Vender = HT_IOT_PEER_REALTEK_JAGUAR_CBVAP;
2576 							RTW_INFO("link to Realtek JAGUAR_CBVAP\n");
2577 						}
2578 						if (pIE->data[6] & RT_HT_CAP_USE_JAGUAR_CCV) {
2579 							Vender = HT_IOT_PEER_REALTEK_JAGUAR_CCVAP;
2580 							RTW_INFO("link to Realtek JAGUAR_CCVAP\n");
2581 						}
2582 					}
2583 				}
2584 
2585 				RTW_INFO("link to Realtek AP\n");
2586 				return Vender;
2587 			} else if (_rtw_memcmp(pIE->data, AIRGOCAP_OUI, 3)) {
2588 				RTW_INFO("link to Airgo Cap\n");
2589 				return HT_IOT_PEER_AIRGO;
2590 			} else
2591 				break;
2592 
2593 		default:
2594 			break;
2595 		}
2596 
2597 		i += (pIE->Length + 2);
2598 	}
2599 
2600 	RTW_INFO("link to new AP\n");
2601 	return HT_IOT_PEER_UNKNOWN;
2602 }
2603 
get_assoc_AP_Vendor(char * vendor,u8 assoc_AP_vendor)2604 void get_assoc_AP_Vendor(char *vendor, u8 assoc_AP_vendor)
2605 {
2606 	switch (assoc_AP_vendor) {
2607 
2608 	case HT_IOT_PEER_UNKNOWN:
2609 	sprintf(vendor, "%s", "unknown");
2610 	break;
2611 
2612 	case HT_IOT_PEER_REALTEK:
2613 	case HT_IOT_PEER_REALTEK_92SE:
2614 	case HT_IOT_PEER_REALTEK_SOFTAP:
2615 	case HT_IOT_PEER_REALTEK_JAGUAR_CBVAP:
2616 	case HT_IOT_PEER_REALTEK_JAGUAR_CCVAP:
2617 
2618 	sprintf(vendor, "%s", "Realtek");
2619 	break;
2620 
2621 	case HT_IOT_PEER_BROADCOM:
2622 	sprintf(vendor, "%s", "Broadcom");
2623 	break;
2624 
2625 	case HT_IOT_PEER_MARVELL:
2626 	sprintf(vendor, "%s", "Marvell");
2627 	break;
2628 
2629 	case HT_IOT_PEER_RALINK:
2630 	sprintf(vendor, "%s", "Ralink");
2631 	break;
2632 
2633 	case HT_IOT_PEER_CISCO:
2634 	sprintf(vendor, "%s", "Cisco");
2635 	break;
2636 
2637 	case HT_IOT_PEER_AIRGO:
2638 	sprintf(vendor, "%s", "Airgo");
2639 	break;
2640 
2641 	case HT_IOT_PEER_ATHEROS:
2642 	sprintf(vendor, "%s", "Atheros");
2643 	break;
2644 
2645 	default:
2646 	sprintf(vendor, "%s", "unkown");
2647 	break;
2648 	}
2649 
2650 }
2651 #ifdef CONFIG_RTS_FULL_BW
rtw_parse_sta_vendor_ie_8812(_adapter * adapter,struct sta_info * sta,u8 * tlv_ies,u16 tlv_ies_len)2652 void rtw_parse_sta_vendor_ie_8812(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
2653 {
2654 	unsigned char REALTEK_OUI[] = {0x00,0xe0, 0x4c};
2655 	u8 *p;
2656 
2657 	p = rtw_get_ie_ex(tlv_ies, tlv_ies_len, WLAN_EID_VENDOR_SPECIFIC, REALTEK_OUI, 3, NULL, NULL);
2658 	if (!p)
2659 		goto exit;
2660 	else {
2661 		if(*(p+1) > 6 ) {
2662 
2663 			if(*(p+6) != 2)
2664 				goto exit;
2665 
2666 			if(*(p+8) == RT_HT_CAP_USE_JAGUAR_CBV)
2667 				sta->vendor_8812 = TRUE;
2668 			else if (*(p+8) == RT_HT_CAP_USE_JAGUAR_CCV)
2669 				sta->vendor_8812 = TRUE;
2670 		}
2671 	}
2672 exit:
2673 	return;
2674 }
2675 #endif/*CONFIG_RTS_FULL_BW*/
2676 
2677 #ifdef CONFIG_80211AC_VHT
get_vht_bf_cap(u8 * pframe,uint len,struct vht_bf_cap * bf_cap)2678 void get_vht_bf_cap(u8 *pframe, uint len, struct vht_bf_cap *bf_cap)
2679 {
2680 	unsigned int i;
2681 	PNDIS_802_11_VARIABLE_IEs pIE;
2682 
2683 	for (i = sizeof(NDIS_802_11_FIXED_IEs); i < len;) {
2684 		pIE = (PNDIS_802_11_VARIABLE_IEs)(pframe + i);
2685 
2686 		switch (pIE->ElementID) {
2687 
2688 		case EID_VHTCapability:
2689 			bf_cap->is_mu_bfer = GET_VHT_CAPABILITY_ELE_MU_BFER(pIE->data);
2690 			bf_cap->su_sound_dim = GET_VHT_CAPABILITY_ELE_SU_BFER_SOUND_DIM_NUM(pIE->data);
2691 			break;
2692 		default:
2693 			break;
2694 		}
2695 		i += (pIE->Length + 2);
2696 	}
2697 }
2698 #endif
2699 
update_capinfo(_adapter * adapter,u16 updateCap)2700 void update_capinfo(_adapter *adapter, u16 updateCap)
2701 {
2702 	struct mlme_ext_priv	*pmlmeext = &adapter->mlmeextpriv;
2703 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2704 	BOOLEAN		ShortPreamble;
2705 
2706 	/* Check preamble mode, 2005.01.06, by rcnjko. */
2707 	/* Mark to update preamble value forever, 2008.03.18 by lanhsin */
2708 	/* if( pMgntInfo->RegPreambleMode == PREAMBLE_AUTO ) */
2709 	{
2710 
2711 		if (updateCap & cShortPreamble) {
2712 			/* Short Preamble */
2713 			if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) { /* PREAMBLE_LONG or PREAMBLE_AUTO */
2714 				ShortPreamble = _TRUE;
2715 				pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
2716 				rtw_hal_set_hwreg(adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
2717 			}
2718 		} else {
2719 			/* Long Preamble */
2720 			if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) { /* PREAMBLE_SHORT or PREAMBLE_AUTO */
2721 				ShortPreamble = _FALSE;
2722 				pmlmeinfo->preamble_mode = PREAMBLE_LONG;
2723 				rtw_hal_set_hwreg(adapter, HW_VAR_ACK_PREAMBLE, (u8 *)&ShortPreamble);
2724 			}
2725 		}
2726 	}
2727 
2728 	if (updateCap & cIBSS) {
2729 		/* Filen: See 802.11-2007 p.91 */
2730 		pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
2731 	} else {
2732 		/* Filen: See 802.11-2007 p.90 */
2733 		if (pmlmeext->cur_wireless_mode & (WLAN_MD_11N | WLAN_MD_11A | WLAN_MD_11AC))
2734 			pmlmeinfo->slotTime = SHORT_SLOT_TIME;
2735 		else if (pmlmeext->cur_wireless_mode & (WLAN_MD_11G)) {
2736 			if ((updateCap & cShortSlotTime) /* && (!(pMgntInfo->pHTInfo->RT2RT_HT_Mode & RT_HT_CAP_USE_LONG_PREAMBLE)) */) {
2737 				/* Short Slot Time */
2738 				pmlmeinfo->slotTime = SHORT_SLOT_TIME;
2739 			} else {
2740 				/* Long Slot Time */
2741 				pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
2742 			}
2743 		} else {
2744 			/* B Mode */
2745 			pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
2746 		}
2747 	}
2748 
2749 	rtw_hal_set_hwreg(adapter, HW_VAR_SLOT_TIME, &pmlmeinfo->slotTime);
2750 
2751 }
2752 
2753 /*
2754 * set adapter.mlmeextpriv.mlmext_info.HT_enable
2755 * set adapter.mlmeextpriv.cur_wireless_mode
2756 * set SIFS register
2757 * set mgmt tx rate
2758 */
update_wireless_mode(_adapter * padapter)2759 void update_wireless_mode(_adapter *padapter)
2760 {
2761 	int ratelen, network_type = 0;
2762 	u32 SIFS_Timer;
2763 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
2764 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2765 	WLAN_BSSID_EX		*cur_network = &(pmlmeinfo->network);
2766 	unsigned char			*rate = cur_network->SupportedRates;
2767 #ifdef CONFIG_P2P
2768 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
2769 #endif /* CONFIG_P2P */
2770 
2771 	ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
2772 
2773 	if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
2774 		pmlmeinfo->HT_enable = 1;
2775 
2776 	if (pmlmeext->chandef.chan > 14) {
2777 		if (pmlmeinfo->HE_enable)
2778 			network_type = WLAN_MD_11AX;
2779 		else if (pmlmeinfo->VHT_enable)
2780 			network_type = WLAN_MD_11AC;
2781 		else if (pmlmeinfo->HT_enable)
2782 			network_type = WLAN_MD_11N;
2783 
2784 		network_type |= WLAN_MD_11A;
2785 	} else {
2786 		if (pmlmeinfo->HE_enable)
2787 			network_type = WLAN_MD_11AX;
2788 		else if (pmlmeinfo->VHT_enable)
2789 			network_type = WLAN_MD_11AC;
2790 		else if (pmlmeinfo->HT_enable)
2791 			network_type = WLAN_MD_11N;
2792 
2793 		if ((cckratesonly_included(rate, ratelen)) == _TRUE)
2794 			network_type |= WLAN_MD_11B;
2795 		else if ((cckrates_included(rate, ratelen)) == _TRUE)
2796 			network_type |= WLAN_MD_11BG;
2797 		else
2798 			network_type |= WLAN_MD_11G;
2799 	}
2800 
2801 	pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
2802 	/* RTW_INFO("network_type=%02x, padapter->registrypriv.wireless_mode=%02x\n", network_type, padapter->registrypriv.wireless_mode); */
2803 
2804 	if ((pmlmeext->cur_wireless_mode & WLAN_MD_11B) &&
2805 	    #ifdef CONFIG_P2P
2806 	    !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
2807 	    !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) &&
2808 	    #endif
2809 	    1)
2810 		update_mgnt_tx_rate(padapter, IEEE80211_CCK_RATE_1MB);
2811 	else
2812 		update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_6MB);
2813 }
2814 
update_sta_basic_rate(struct sta_info * psta,u8 wireless_mode)2815 void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode)
2816 {
2817 	if (is_supported_tx_cck(wireless_mode)) {
2818 		/* Only B, B/G, and B/G/N AP could use CCK rate */
2819 		_rtw_memcpy(psta->bssrateset, rtw_basic_rate_cck, 4);
2820 		psta->bssratelen = 4;
2821 	} else {
2822 		_rtw_memcpy(psta->bssrateset, rtw_basic_rate_ofdm, 3);
2823 		psta->bssratelen = 3;
2824 	}
2825 }
2826 
rtw_ies_get_supported_rate(u8 * ies,uint ies_len,u8 * rate_set,u8 * rate_num)2827 int rtw_ies_get_supported_rate(u8 *ies, uint ies_len, u8 *rate_set, u8 *rate_num)
2828 {
2829 	u8 *ie, *p;
2830 	unsigned int ie_len;
2831 	int i, j;
2832 
2833 	struct support_rate_handler support_rate_tbl[] = {
2834 		{IEEE80211_CCK_RATE_1MB, 		_FALSE,		_FALSE},
2835 		{IEEE80211_CCK_RATE_2MB, 		_FALSE,		_FALSE},
2836 		{IEEE80211_CCK_RATE_5MB, 		_FALSE,		_FALSE},
2837 		{IEEE80211_CCK_RATE_11MB,		_FALSE,		_FALSE},
2838 		{IEEE80211_OFDM_RATE_6MB,		_FALSE,		_FALSE},
2839 		{IEEE80211_OFDM_RATE_9MB,		_FALSE,		_FALSE},
2840 		{IEEE80211_OFDM_RATE_12MB,		_FALSE,		_FALSE},
2841 		{IEEE80211_OFDM_RATE_18MB,		_FALSE,		_FALSE},
2842 		{IEEE80211_OFDM_RATE_24MB,		_FALSE,		_FALSE},
2843 		{IEEE80211_OFDM_RATE_36MB,		_FALSE,		_FALSE},
2844 		{IEEE80211_OFDM_RATE_48MB,		_FALSE,		_FALSE},
2845 		{IEEE80211_OFDM_RATE_54MB,		_FALSE,		_FALSE},
2846 	};
2847 
2848 	if (!rate_set || !rate_num)
2849 		return _FALSE;
2850 
2851 	*rate_num = 0;
2852 	ie = rtw_get_ie(ies, _SUPPORTEDRATES_IE_, &ie_len, ies_len);
2853 	if (ie == NULL)
2854 		goto ext_rate;
2855 
2856 	/* get valid supported rates */
2857 	for (i = 0; i < 12; i++) {
2858 		p = ie + 2;
2859 		for (j = 0; j < ie_len; j++) {
2860 			if ((*p & ~BIT(7)) == support_rate_tbl[i].rate){
2861 				support_rate_tbl[i].existence = _TRUE;
2862 				if ((*p) & BIT(7))
2863 					support_rate_tbl[i].basic = _TRUE;
2864 			}
2865 			p++;
2866 		}
2867 	}
2868 
2869 ext_rate:
2870 	ie = rtw_get_ie(ies, _EXT_SUPPORTEDRATES_IE_, &ie_len, ies_len);
2871 	if (ie) {
2872 		/* get valid extended supported rates */
2873 		for (i = 0; i < 12; i++) {
2874 			p = ie + 2;
2875 			for (j = 0; j < ie_len; j++) {
2876 				if ((*p & ~BIT(7)) == support_rate_tbl[i].rate){
2877 					support_rate_tbl[i].existence = _TRUE;
2878 					if ((*p) & BIT(7))
2879 						support_rate_tbl[i].basic = _TRUE;
2880 				}
2881 				p++;
2882 			}
2883 		}
2884 	}
2885 
2886 	for (i = 0; i < 12; i++){
2887 		if (support_rate_tbl[i].existence){
2888 			if (support_rate_tbl[i].basic)
2889 				rate_set[*rate_num] = support_rate_tbl[i].rate | IEEE80211_BASIC_RATE_MASK;
2890 			else
2891 				rate_set[*rate_num] = support_rate_tbl[i].rate;
2892 			*rate_num += 1;
2893 		}
2894 	}
2895 
2896 	if (*rate_num == 0)
2897 		return _FAIL;
2898 
2899 	if (0) {
2900 		int i;
2901 
2902 		for (i = 0; i < *rate_num; i++)
2903 			RTW_INFO("rate:0x%02x\n", *(rate_set + i));
2904 	}
2905 
2906 	return _SUCCESS;
2907 }
2908 
process_addba_req(_adapter * padapter,u8 * paddba_req,u8 * addr)2909 void process_addba_req(_adapter *padapter, u8 *paddba_req, u8 *addr)
2910 {
2911 	struct sta_info *psta;
2912 	u16 tid, start_seq, param;
2913 	struct sta_priv *pstapriv = &padapter->stapriv;
2914 	struct ADDBA_request	*preq = (struct ADDBA_request *)paddba_req;
2915 	u8 size, accept = _FALSE;
2916 
2917 	psta = rtw_get_stainfo(pstapriv, addr);
2918 	if (!psta)
2919 		goto exit;
2920 
2921 	start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
2922 	param = le16_to_cpu(preq->BA_para_set);
2923 	tid = (param >> 2) & 0x0f;
2924 
2925 	accept = rtw_rx_ampdu_is_accept(padapter);
2926 	if (padapter->fix_rx_ampdu_size != RX_AMPDU_SIZE_INVALID)
2927 		size = padapter->fix_rx_ampdu_size;
2928 	else {
2929 		size = rtw_rx_ampdu_size(padapter);
2930 		size = rtw_min(size, rx_ampdu_size_sta_limit(padapter, psta));
2931 	}
2932 
2933 	if (accept == _TRUE)
2934 		rtw_addbarsp_cmd(padapter, addr, tid, preq, 0, size, start_seq);
2935 	else
2936 		rtw_addbarsp_cmd(padapter, addr, tid, preq, 37, size, start_seq);/* reject ADDBA Req */
2937 
2938 exit:
2939 	return;
2940 }
2941 
rtw_process_bar_frame(_adapter * padapter,union recv_frame * precv_frame)2942 void rtw_process_bar_frame(_adapter *padapter, union recv_frame *precv_frame)
2943 {
2944 	struct sta_priv *pstapriv = &padapter->stapriv;
2945 	u8 *pframe = precv_frame->u.hdr.rx_data;
2946 	struct sta_info *psta = NULL;
2947 	struct recv_reorder_ctrl *preorder_ctrl = NULL;
2948 	u8 tid = 0;
2949 	u16 start_seq=0;
2950 
2951 	psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
2952 	if (psta == NULL)
2953 		goto exit;
2954 
2955 	tid = ((cpu_to_le16((*(u16 *)(pframe + 16))) & 0xf000) >> 12);
2956 	preorder_ctrl = &psta->recvreorder_ctrl[tid];
2957 	start_seq = ((cpu_to_le16(*(u16 *)(pframe + 18))) >> 4);
2958 	preorder_ctrl->indicate_seq = start_seq;
2959 
2960 	rtw_phl_rx_bar(padapter->dvobj->phl, psta->phl_sta, tid, start_seq);
2961 	/* for Debug use */
2962 	if (0)
2963 		RTW_INFO(FUNC_ADPT_FMT" tid=%d, start_seq=%d\n", FUNC_ADPT_ARG(padapter),  tid, start_seq);
2964 
2965 exit:
2966 	return;
2967 }
2968 
update_TSF(struct mlme_ext_priv * pmlmeext,u8 * pframe,uint len)2969 void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
2970 {
2971 	u8 *pIE;
2972 	u32 *pbuf;
2973 
2974 	pIE = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
2975 	pbuf = (u32 *)pIE;
2976 
2977 	pmlmeext->TSFValue = le32_to_cpu(*(pbuf + 1));
2978 
2979 	pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
2980 
2981 	pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
2982 }
2983 
2984 #ifdef CONFIG_BCN_RECV_TIME
2985 /*	calculate beacon receiving time
2986 	1.RxBCNTime(CCK_1M) = [192us(preamble)] + [length of beacon(byte)*8us] + [10us]
2987 	2.RxBCNTime(OFDM_6M) = [8us(S) + 8us(L) + 4us(L-SIG)] + [(length of beacon(byte)/3 + 1] *4us] + [10us]
2988 */
_rx_bcn_time_calculate(uint bcn_len,u8 data_rate)2989 inline u16 _rx_bcn_time_calculate(uint bcn_len, u8 data_rate)
2990 {
2991 	u16 rx_bcn_time = 0;/*us*/
2992 
2993 	if (data_rate == DESC_RATE1M)
2994 		rx_bcn_time = 192 + bcn_len * 8 + 10;
2995 	else if(data_rate == DESC_RATE6M)
2996 		rx_bcn_time = 8 + 8 + 4 + (bcn_len /3 + 1) * 4 + 10;
2997 /*
2998 	else
2999 		RTW_ERR("%s invalid data rate(0x%02x)\n", __func__, data_rate);
3000 */
3001 	return rx_bcn_time;
3002 }
rtw_rx_bcn_time_update(_adapter * adapter,uint bcn_len,u8 data_rate)3003 void rtw_rx_bcn_time_update(_adapter *adapter, uint bcn_len, u8 data_rate)
3004 {
3005 	struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
3006 
3007 	pmlmeext->bcn_rx_time = _rx_bcn_time_calculate(bcn_len, data_rate);
3008 }
3009 #endif
3010 
beacon_timing_control(_adapter * padapter)3011 void beacon_timing_control(_adapter *padapter)
3012 {
3013 	rtw_hal_bcn_param_setting(padapter);
3014 }
3015 
rtw_collect_bcn_info(_adapter * adapter)3016 inline void rtw_collect_bcn_info(_adapter *adapter)
3017 {
3018 	struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
3019 
3020 	if (!is_client_associated_to_ap(adapter))
3021 		return;
3022 
3023 	pmlmeext->cur_bcn_cnt = pmlmeext->bcn_cnt - pmlmeext->last_bcn_cnt;
3024 	pmlmeext->last_bcn_cnt = pmlmeext->bcn_cnt;
3025 	/*TODO get offset of bcn's timestamp*/
3026 	/*pmlmeext->bcn_timestamp;*/
3027 }
3028 
rtw_bmp_is_set(const u8 * bmp,u8 bmp_len,u8 id)3029 inline bool rtw_bmp_is_set(const u8 *bmp, u8 bmp_len, u8 id)
3030 {
3031 	if (id / 8 >= bmp_len)
3032 		return 0;
3033 
3034 	return bmp[id / 8] & BIT(id % 8);
3035 }
3036 
rtw_bmp_set(u8 * bmp,u8 bmp_len,u8 id)3037 inline void rtw_bmp_set(u8 *bmp, u8 bmp_len, u8 id)
3038 {
3039 	if (id / 8 < bmp_len)
3040 		bmp[id / 8] |= BIT(id % 8);
3041 }
3042 
rtw_bmp_clear(u8 * bmp,u8 bmp_len,u8 id)3043 inline void rtw_bmp_clear(u8 *bmp, u8 bmp_len, u8 id)
3044 {
3045 	if (id / 8 < bmp_len)
3046 		bmp[id / 8] &= ~BIT(id % 8);
3047 }
3048 
rtw_bmp_not_empty(const u8 * bmp,u8 bmp_len)3049 inline bool rtw_bmp_not_empty(const u8 *bmp, u8 bmp_len)
3050 {
3051 	int i;
3052 
3053 	for (i = 0; i < bmp_len; i++) {
3054 		if (bmp[i])
3055 			return 1;
3056 	}
3057 
3058 	return 0;
3059 }
3060 
rtw_bmp_not_empty_exclude_bit0(const u8 * bmp,u8 bmp_len)3061 inline bool rtw_bmp_not_empty_exclude_bit0(const u8 *bmp, u8 bmp_len)
3062 {
3063 	int i;
3064 
3065 	for (i = 0; i < bmp_len; i++) {
3066 		if (i == 0) {
3067 			if (bmp[i] & 0xFE)
3068 				return 1;
3069 		} else {
3070 			if (bmp[i])
3071 				return 1;
3072 		}
3073 	}
3074 
3075 	return 0;
3076 }
3077 
3078 #ifdef CONFIG_AP_MODE
3079 /* Check the id be set or not in map , if yes , return a none zero value*/
rtw_tim_map_is_set(_adapter * padapter,const u8 * map,u8 id)3080 bool rtw_tim_map_is_set(_adapter *padapter, const u8 *map, u8 id)
3081 {
3082 	return rtw_bmp_is_set(map, padapter->stapriv.aid_bmp_len, id);
3083 }
3084 
3085 /* Set the id into map array*/
rtw_tim_map_set(_adapter * padapter,u8 * map,u8 id)3086 void rtw_tim_map_set(_adapter *padapter, u8 *map, u8 id)
3087 {
3088 	rtw_bmp_set(map, padapter->stapriv.aid_bmp_len, id);
3089 }
3090 
3091 /* Clear the id from map array*/
rtw_tim_map_clear(_adapter * padapter,u8 * map,u8 id)3092 void rtw_tim_map_clear(_adapter *padapter, u8 *map, u8 id)
3093 {
3094 	rtw_bmp_clear(map, padapter->stapriv.aid_bmp_len, id);
3095 }
3096 
3097 /* Check have anyone bit be set , if yes return true*/
rtw_tim_map_anyone_be_set(_adapter * padapter,const u8 * map)3098 bool rtw_tim_map_anyone_be_set(_adapter *padapter, const u8 *map)
3099 {
3100 	return rtw_bmp_not_empty(map, padapter->stapriv.aid_bmp_len);
3101 }
3102 
3103 /* Check have anyone bit be set exclude bit0 , if yes return true*/
rtw_tim_map_anyone_be_set_exclude_aid0(_adapter * padapter,const u8 * map)3104 bool rtw_tim_map_anyone_be_set_exclude_aid0(_adapter *padapter, const u8 *map)
3105 {
3106 	return rtw_bmp_not_empty_exclude_bit0(map, padapter->stapriv.aid_bmp_len);
3107 }
3108 #endif /* CONFIG_AP_MODE */
3109 
dvobj_get_unregisterd_adapter(struct dvobj_priv * dvobj)3110 _adapter *dvobj_get_unregisterd_adapter(struct dvobj_priv *dvobj)
3111 {
3112 	_adapter *adapter = NULL;
3113 	int i;
3114 
3115 	for (i = 0; i < dvobj->iface_nums; i++) {
3116 		if (dvobj->padapters[i]->registered == 0)
3117 			break;
3118 	}
3119 
3120 	if (i < dvobj->iface_nums)
3121 		adapter = dvobj->padapters[i];
3122 
3123 	return adapter;
3124 }
3125 
dvobj_get_adapter_by_addr(struct dvobj_priv * dvobj,u8 * addr)3126 _adapter *dvobj_get_adapter_by_addr(struct dvobj_priv *dvobj, u8 *addr)
3127 {
3128 	_adapter *adapter = NULL;
3129 	int i;
3130 
3131 	for (i = 0; i < dvobj->iface_nums; i++) {
3132 		if (_rtw_memcmp(dvobj->padapters[i]->mac_addr, addr, ETH_ALEN) == _TRUE)
3133 			break;
3134 	}
3135 
3136 	if (i < dvobj->iface_nums)
3137 		adapter = dvobj->padapters[i];
3138 
3139 	return adapter;
3140 }
3141 
rtw_get_he_bitrate(u8 mcs,u8 bw,u8 nss,u8 sgi)3142 static u32 rtw_get_he_bitrate(u8 mcs, u8 bw, u8 nss, u8 sgi)
3143 {
3144 	static const u32 base[4][3][12] = { /*[bw][GI][MCS] */
3145 		/* BW20 */
3146 		{{   8600000,  17200000,  25800000,  34400000, /* GI 0.8u */
3147 		    51600000,  68800000,  77400000,  86000000,
3148 		   103200000, 114700000, 129000000, 143400000,
3149 		},
3150 		{    8100000,  16300000,  24400000,  32500000, /* GI 1.6u */
3151 		    48800000,  65000000,  73100000,  81300000,
3152 		    97500000, 108300000, 121900000, 135400000,
3153 		},
3154 		{    7300000,  14600000,  21900000,  29300000, /* GI 3.2u */
3155 		    43900000,  58500000,  65800000,  73100000,
3156 		    87800000,  97500000, 109700000, 121900000,
3157 		}},
3158 		/* BW40 */
3159 		{{  17200000,  34400000,  51600000,  68800000, /* GI 0.8u */
3160 		   103200000, 137600000, 154900000, 172100000,
3161 		   206500000, 229400000, 258100000, 286800000,
3162 		},
3163 		{   16300000,  32500000,  48800000,  65000000, /* GI 1.6u */
3164 		    97500000, 130000000, 146300000, 162500000,
3165 		   195000000, 216700000, 243800000, 270800000,
3166 		},
3167 		{   14600000,  29300000,  43900000,  58500000, /* GI 3.2u */
3168 		    87800000, 117000000, 131600000, 146300000,
3169 		   175500000, 195000000, 219400000, 243800000,
3170 		}},
3171 		/* BW80 */
3172 		{{  36000000,  72100000, 108100000, 144100000, /* GI 0.8u */
3173 		   216200000, 288200000, 324300000, 360300000,
3174 		   432400000, 480400000, 540400000, 600500000,
3175 		},
3176 		{   34000000,  68100000, 102100000, 136100000, /* GI 1.6u */
3177 		   204200000, 272200000, 306300000, 340300000,
3178 		   408300000, 453700000, 510400000, 567100000,
3179 		},
3180 		{   30600000,  61300000,  91900000, 122500000, /* GI 3.2u */
3181 		   183800000, 245000000, 275600000, 306300000,
3182 		   367500000, 408300000, 459400000, 510400000,
3183 		}},
3184 		/* BW160 and BW80+80 */
3185 		{{  72100000, 144100000, 216200000, 288200000, /* GI 0.8u */
3186 		   432400000, 576500000, 648500000, 720600000,
3187 		   864700000, 960800000,1080900000,1201000000,
3188 		},
3189 		{   68100000, 136100000, 204200000, 272200000, /* GI 1.6u */
3190 		   408300000, 544400000, 612500000, 680600000,
3191 		   816700000, 907400000,1020800000,1134300000,
3192 		},
3193 		{   61300000, 122500000, 183800000, 245000000, /* GI 3.2u */
3194 		   367500000, 490000000, 551300000, 612500000,
3195 		   735000000, 816700000, 918800000,1020800000,
3196 		}}
3197 	};
3198 	u32 bitrate;
3199 	int bw_idx, sgi_idx;
3200 
3201 	if (mcs > 11) {
3202 		RTW_INFO("Invalid mcs = %d\n", mcs);
3203 		return 0;
3204 	}
3205 
3206 	if (nss > 4 || nss < 1) {
3207 		RTW_INFO("Now only support nss = 1, 2, 3, 4\n");
3208 		return 0;
3209 	}
3210 
3211 	switch (bw) {
3212 	case CHANNEL_WIDTH_80_80:
3213 	case CHANNEL_WIDTH_160:
3214 		bw_idx = 3;
3215 		break;
3216 	case CHANNEL_WIDTH_80:
3217 		bw_idx = 2;
3218 		break;
3219 	case CHANNEL_WIDTH_40:
3220 		bw_idx = 1;
3221 		break;
3222 	case CHANNEL_WIDTH_20:
3223 		bw_idx = 0;
3224 		break;
3225 	default:
3226 		RTW_INFO("bw = %d currently not supported\n", bw);
3227 		return 0;
3228 	}
3229 
3230 	/* refer to mdata.rx_gi_ltf */
3231 	switch (sgi) {
3232 	case RTW_GILTF_LGI_4XHE32:
3233 		sgi_idx = 2; /* 3.2 GI */
3234 		break;
3235 	case RTW_GILTF_2XHE16:
3236 	case RTW_GILTF_1XHE16:
3237 		sgi_idx = 1; /* 1.6 GI */
3238 		break;
3239 	case RTW_GILTF_SGI_4XHE08:
3240 	case RTW_GILTF_2XHE08:
3241 	case RTW_GILTF_1XHE08:
3242 		sgi_idx = 0; /* 0.8 GI */
3243 		break;
3244 	default:
3245 		RTW_INFO("gi_ltf = %d currently not supported\n", sgi);
3246 		return 0;
3247 	}
3248 	bitrate = base[bw_idx][sgi_idx][mcs];
3249 	bitrate *= nss;
3250 	return (bitrate/100000);
3251 }
3252 
rtw_get_vht_bitrate(u8 mcs,u8 bw,u8 nss,u8 sgi)3253 static u32 rtw_get_vht_bitrate(u8 mcs, u8 bw, u8 nss, u8 sgi)
3254 {
3255 	static const u32 base[4][10] = {
3256 		{   6500000,
3257 		   13000000,
3258 		   19500000,
3259 		   26000000,
3260 		   39000000,
3261 		   52000000,
3262 		   58500000,
3263 		   65000000,
3264 		   78000000,
3265 		/* not in the spec, but some devices use this: */
3266 		   86500000,
3267 		},
3268 		{  13500000,
3269 		   27000000,
3270 		   40500000,
3271 		   54000000,
3272 		   81000000,
3273 		  108000000,
3274 		  121500000,
3275 		  135000000,
3276 		  162000000,
3277 		  180000000,
3278 		},
3279 		{  29300000,
3280 		   58500000,
3281 		   87800000,
3282 		  117000000,
3283 		  175500000,
3284 		  234000000,
3285 		  263300000,
3286 		  292500000,
3287 		  351000000,
3288 		  390000000,
3289 		},
3290 		{  58500000,
3291 		  117000000,
3292 		  175500000,
3293 		  234000000,
3294 		  351000000,
3295 		  468000000,
3296 		  526500000,
3297 		  585000000,
3298 		  702000000,
3299 		  780000000,
3300 		},
3301 	};
3302 	u32 bitrate;
3303 	int bw_idx;
3304 
3305 	if (mcs > 9) {
3306 		RTW_INFO("Invalid mcs = %d\n", mcs);
3307 		return 0;
3308 	}
3309 
3310 	if (nss > 4 || nss < 1) {
3311 		RTW_INFO("Now only support nss = 1, 2, 3, 4\n");
3312 	}
3313 
3314 	switch (bw) {
3315 	case CHANNEL_WIDTH_160:
3316 		bw_idx = 3;
3317 		break;
3318 	case CHANNEL_WIDTH_80:
3319 		bw_idx = 2;
3320 		break;
3321 	case CHANNEL_WIDTH_40:
3322 		bw_idx = 1;
3323 		break;
3324 	case CHANNEL_WIDTH_20:
3325 		bw_idx = 0;
3326 		break;
3327 	default:
3328 		RTW_INFO("bw = %d currently not supported\n", bw);
3329 		return 0;
3330 	}
3331 
3332 	bitrate = base[bw_idx][mcs];
3333 	bitrate *= nss;
3334 
3335 	if (sgi)
3336 		bitrate = (bitrate / 9) * 10;
3337 
3338 	/* do NOT round down here */
3339 	return (bitrate + 50000) / 100000;
3340 }
3341 
rtw_get_ht_bitrate(u8 mcs,u8 bw,u8 sgi)3342 static u32 rtw_get_ht_bitrate(u8 mcs, u8 bw, u8 sgi)
3343 {
3344 	int modulation, streams, bitrate;
3345 
3346 	/* the formula below does only work for MCS values smaller than 32 */
3347 	if (mcs >= 32) {
3348 		RTW_INFO("Invalid mcs = %d\n", mcs);
3349 		return 0;
3350 	}
3351 
3352 	if (bw > 1) {
3353 		RTW_INFO("Now HT only support bw = 0(20Mhz), 1(40Mhz)\n");
3354 		return 0;
3355 	}
3356 
3357 	modulation = mcs & 7;
3358 	streams = (mcs >> 3) + 1;
3359 
3360 	bitrate = (bw == 1) ? 13500000 : 6500000;
3361 
3362 	if (modulation < 4)
3363 		bitrate *= (modulation + 1);
3364 	else if (modulation == 4)
3365 		bitrate *= (modulation + 2);
3366 	else
3367 		bitrate *= (modulation + 3);
3368 
3369 	bitrate *= streams;
3370 
3371 	if (sgi)
3372 		bitrate = (bitrate / 9) * 10;
3373 
3374 	/* do NOT round down here */
3375 	return (bitrate + 50000) / 100000;
3376 }
3377 
3378 /**
3379  * @bw: 0(20Mhz), 1(40Mhz), 2(80Mhz), 3(160Mhz)
3380  * @data_rate: enum rtw_data_rate;
3381  * @sgi: enum rtw_gi_ltf
3382  * Returns: bitrate in 100kbps
3383  */
rtw_desc_rate_to_bitrate(u8 bw,u16 data_rate,u8 sgi)3384 u32 rtw_desc_rate_to_bitrate(u8 bw, u16 data_rate, u8 sgi)
3385 {
3386 	u32 bitrate;
3387 
3388 	if (data_rate <= DESC_RATE54M){
3389 		u16 ofdm_rate[12] = {10, 20, 55, 110,
3390 			60, 90, 120, 180, 240, 360, 480, 540};
3391 		bitrate = ofdm_rate[data_rate];
3392 	} else if ((RTW_DATA_RATE_MCS0 <= data_rate) &&
3393 		   (data_rate <= RTW_DATA_RATE_MCS31)) {
3394 		u8 mcs = data_rate - RTW_DATA_RATE_MCS0;
3395 		bitrate = rtw_get_ht_bitrate(mcs, bw, sgi);
3396 	} else if ((RTW_DATA_RATE_VHT_NSS1_MCS0 <= data_rate) &&
3397 		   (data_rate <= RTW_DATA_RATE_VHT_NSS4_MCS9)) {
3398 		u8 mcs = (data_rate - RTW_DATA_RATE_VHT_NSS1_MCS0) % 10;
3399 		u8 nss = ((data_rate - RTW_DATA_RATE_VHT_NSS1_MCS0) / 10) + 1;
3400 		bitrate = rtw_get_vht_bitrate(mcs, bw, nss, sgi);
3401 	} else if ((RTW_DATA_RATE_HE_NSS1_MCS0 <= data_rate) &&
3402 		   (data_rate <= RTW_DATA_RATE_HE_NSS4_MCS11)) {
3403 		u8 mcs = (data_rate - RTW_DATA_RATE_HE_NSS1_MCS0) % 12;
3404 		u8 nss = ((data_rate - RTW_DATA_RATE_HE_NSS1_MCS0) / 12) + 1;
3405 		bitrate = rtw_get_he_bitrate(mcs, bw, nss, sgi);
3406 	} else {
3407 		/* 60Ghz ??? */
3408 		bitrate = 1;
3409 	}
3410 
3411 	return bitrate;
3412 }
3413 
rtw_get_current_tx_rate(_adapter * adapter,struct sta_info * psta)3414 u16 rtw_get_current_tx_rate(_adapter *adapter, struct sta_info *psta)
3415 {
3416 	u16 rate_id = 0;
3417 	struct rtw_phl_rainfo ra_info;
3418 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
3419 
3420 	if (!psta)
3421 		return rate_id;
3422 
3423 	if (adapter->fix_rate != NO_FIX_RATE)
3424 		rate_id = GET_FIX_RATE(adapter->fix_rate);
3425 	else {
3426 		rtw_phl_query_rainfo(dvobj->phl, psta->phl_sta, &ra_info);
3427 		rate_id = ra_info.rate; /* enum rtw_data_rate */
3428 	}
3429 
3430 	return rate_id;
3431 }
3432 
rtw_get_current_tx_sgi(_adapter * adapter,struct sta_info * psta)3433 u8 rtw_get_current_tx_sgi(_adapter *adapter, struct sta_info *psta)
3434 {
3435 	u8 curr_tx_sgi = 0;
3436 	struct rtw_phl_rainfo ra_info;
3437 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
3438 
3439 	if (!psta)
3440 		return curr_tx_sgi;
3441 
3442 	if (adapter->fix_rate != NO_FIX_RATE)
3443 		/* fix rate */
3444 		curr_tx_sgi = GET_FIX_RATE_SGI(adapter->fix_rate);
3445 	else {
3446 		rtw_phl_query_rainfo(dvobj->phl, psta->phl_sta, &ra_info);
3447 		curr_tx_sgi = ra_info.gi_ltf;
3448 	}
3449 
3450 	return curr_tx_sgi;
3451 }
3452 
rtw_get_current_rx_info(_adapter * adapter,struct sta_info * psta,u16 * rate,u8 * bw,u8 * gi_ltf)3453 void rtw_get_current_rx_info(_adapter *adapter, struct sta_info *psta,
3454 	u16 *rate, u8 *bw, u8 *gi_ltf)
3455 {
3456 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
3457 
3458 	if (!psta)
3459 		return;
3460 
3461 	rtw_phl_get_rx_stat(dvobj->phl, psta->phl_sta, rate, bw, gi_ltf);
3462 }
3463 
3464 #ifdef CONFIG_RTW_MULTI_AP
rtw_get_ch_utilization(_adapter * adapter)3465 u8 rtw_get_ch_utilization(_adapter *adapter)
3466 {
3467 #if 0 /* FIXME */
3468 	u16 clm = rtw_phydm_clm_ratio(adapter);
3469 	u16 nhm = rtw_phydm_nhm_ratio(adapter);
3470 #else
3471 	u16 clm = 55;
3472 	u16 nhm = 55;
3473 #endif
3474 	u16 ch_util;
3475 
3476 	ch_util = clm / 3 + (2 * (nhm / 3));
3477 	/* For Multi-AP, scaling 0-100 to 0-255 */
3478 	ch_util = 255 * ch_util / 100;
3479 
3480 	return (u8)ch_util;
3481 }
3482 
rtw_ch_util_rpt(_adapter * adapter)3483 void rtw_ch_util_rpt(_adapter *adapter)
3484 {
3485 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
3486 	_adapter *iface;
3487 	int i, j;
3488 	u8 i_rpts = 0;
3489 	u8 *ch_util;
3490 	u8 **bssid;
3491 	u8 threshold = GET_PRIMARY_ADAPTER(adapter)->ch_util_threshold;
3492 	u8 need_rpt = 0;
3493 
3494 	if (threshold == 0)
3495 		return;
3496 
3497 	ch_util = rtw_zmalloc(sizeof(u8) * dvobj->iface_nums);
3498 	if (!ch_util)
3499 		goto err_out;
3500 
3501 	bssid = (u8 **)rtw_zmalloc(sizeof(u8 *) * dvobj->iface_nums);
3502 	if (!bssid)
3503 		goto err_out1;
3504 
3505 	for (j = 0; j < dvobj->iface_nums; j++) {
3506 		*(bssid + j) = (u8 *)rtw_zmalloc(sizeof(u8) * ETH_ALEN);
3507 		if (!(*(bssid + j)))
3508 			goto err_out2;
3509 	}
3510 
3511 	for (i = 0; i < dvobj->iface_nums; i++) {
3512 		iface = dvobj->padapters[i];
3513 		if ((iface) && MLME_IS_AP(iface)) {
3514 			*(ch_util + i_rpts) = rtw_get_ch_utilization(iface);
3515 			_rtw_memcpy(*(bssid + i_rpts), iface->mac_addr, ETH_ALEN);
3516 			if (*(ch_util + i_rpts) > threshold)
3517 				need_rpt = 1;
3518 
3519 			i_rpts++;
3520 		}
3521 	}
3522 
3523 	if (need_rpt)
3524 		rtw_nlrtw_ch_util_rpt(adapter, i_rpts, ch_util, bssid);
3525 
3526 	rtw_mfree(ch_util, sizeof(u8) * dvobj->iface_nums);
3527 	for (i = 0; i < dvobj->iface_nums; i++)
3528 		rtw_mfree(*(bssid + i), ETH_ALEN);
3529 
3530 	rtw_mfree(bssid, sizeof(u8 *) * dvobj->iface_nums);
3531 
3532 	return;
3533 
3534 err_out2:
3535 	for (i = 0; i < j; i++)
3536 		rtw_mfree(*(bssid + i), sizeof(u8) * ETH_ALEN);
3537 	rtw_mfree(bssid, sizeof(sizeof(u8 *) * dvobj->iface_nums));
3538 err_out1:
3539 	rtw_mfree(ch_util, sizeof(u8) * dvobj->iface_nums);
3540 err_out:
3541 	RTW_INFO("[%s] rtw_zmalloc fail\n", __func__);
3542 }
3543 #endif
3544 
3545 #define rtw_efuse_str_out_raw(str, len)		\
3546 	do {					\
3547 		u32 i;				\
3548 		u8 *_pos = str;			\
3549 		for (i = 0; i <= len; i++) {	\
3550 			_RTW_PRINT_SEL(		\
3551 				RTW_DBGDUMP,	\
3552 				"%c",*_pos++);	\
3553 		}				\
3554 	} while(0)
3555 
rtw_efuse_dbg_raw_dump(struct dvobj_priv * pdvobj)3556 void rtw_efuse_dbg_raw_dump(struct dvobj_priv *pdvobj)
3557 {
3558 #ifdef CONFIG_RTW_EFUSE_DBG_DUMP
3559 #define PROC_MSG_LEN   (80*24*4)
3560 	struct phl_info_t *phl_info = \
3561 		(struct phl_info_t *)GET_PHL_INFO(pdvobj);
3562 	struct rtw_proc_cmd proc_cmd;
3563 	u32 proc_cmd_msg_len = PROC_MSG_LEN;
3564 	u8 *proc_cmd_msg = NULL;
3565 	u8 pstr_dump_hw_map_str[] = "dump_hw_map";
3566 	u32 i = 0;
3567 
3568 	if (0 == CONFIG_RTW_EFUSE_DBG_DUMP)
3569 		return;
3570 
3571 	proc_cmd_msg = rtw_zmalloc(proc_cmd_msg_len);
3572 	if (NULL == proc_cmd_msg)
3573 		return;
3574 
3575 	_rtw_memset(&proc_cmd, 0, sizeof(proc_cmd));
3576 	proc_cmd.in_type = RTW_ARG_TYPE_BUF;
3577 	proc_cmd.in_cnt_len = strlen(pstr_dump_hw_map_str);
3578 	proc_cmd.in.buf = pstr_dump_hw_map_str;
3579 
3580 	rtw_phl_proc_cmd(phl_info, RTW_PROC_CMD_EFUSE,
3581 		&proc_cmd, proc_cmd_msg, proc_cmd_msg_len);
3582 
3583 	rtw_efuse_str_out_raw(proc_cmd_msg, proc_cmd_msg_len);
3584 
3585 	if (proc_cmd_msg)
3586 		rtw_mfree(proc_cmd_msg, PROC_MSG_LEN);
3587 #endif
3588 }
3589 
3590