xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/core/rtw_ap.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2019 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_AP_C_
16 
17 #include <drv_types.h>
18 
19 #ifdef CONFIG_AP_MODE
20 
21 extern unsigned char	RTW_WPA_OUI[];
22 extern unsigned char	WMM_OUI[];
23 extern unsigned char	WPS_OUI[];
24 extern unsigned char	P2P_OUI[];
25 extern unsigned char	WFD_OUI[];
26 
init_mlme_ap_info(_adapter * padapter)27 void init_mlme_ap_info(_adapter *padapter)
28 {
29 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
30 
31 	_rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
32 	/* pmlmeext->bstart_bss = _FALSE; */
33 }
34 
free_mlme_ap_info(_adapter * padapter)35 void free_mlme_ap_info(_adapter *padapter)
36 {
37 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
38 
39 	stop_ap_mode(padapter);
40 	_rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
41 
42 }
43 
44 /*
45 * Set TIM IE
46 * return length of total TIM IE
47 */
rtw_set_tim_ie(u8 dtim_cnt,u8 dtim_period,const u8 * tim_bmp,u8 tim_bmp_len,u8 * tim_ie)48 u8 rtw_set_tim_ie(u8 dtim_cnt, u8 dtim_period
49 	, const u8 *tim_bmp, u8 tim_bmp_len, u8 *tim_ie)
50 {
51 	u8 *p = tim_ie;
52 	u8 i, n1, n2;
53 	u8 bmp_len;
54 
55 	if (rtw_bmp_not_empty(tim_bmp, tim_bmp_len)) {
56 		/* find the first nonzero octet in tim_bitmap */
57 		for (i = 0; i < tim_bmp_len; i++)
58 			if (tim_bmp[i])
59 				break;
60 		n1 = i & 0xFE;
61 
62 		/* find the last nonzero octet in tim_bitmap, except octet 0 */
63 		for (i = tim_bmp_len - 1; i > 0; i--)
64 			if (tim_bmp[i])
65 				break;
66 		n2 = i;
67 		bmp_len = n2 - n1 + 1;
68 	} else {
69 		n1 = n2 = 0;
70 		bmp_len = 1;
71 	}
72 
73 	*p++ = WLAN_EID_TIM;
74 	*p++ = 2 + 1 + bmp_len;
75 	*p++ = dtim_cnt;
76 	*p++ = dtim_period;
77 	*p++ = (rtw_bmp_is_set(tim_bmp, tim_bmp_len, 0) ? BIT0 : 0) | n1;
78 	_rtw_memcpy(p, tim_bmp + n1, bmp_len);
79 
80 #if 0
81 	RTW_INFO("n1:%u, n2:%u, bmp_offset:%u, bmp_len:%u\n", n1, n2, n1 / 2, bmp_len);
82 	RTW_INFO_DUMP("tim_ie: ", tim_ie + 2, 2 + 1 + bmp_len);
83 #endif
84 	return 2 + 2 + 1 + bmp_len;
85 }
86 
update_BCNTIM(_adapter * padapter)87 static void update_BCNTIM(_adapter *padapter)
88 {
89 	struct sta_priv *pstapriv = &padapter->stapriv;
90 	struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
91 	struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
92 	WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
93 	unsigned char *pie = pnetwork_mlmeext->IEs;
94 
95 #if 0
96 
97 
98 	/* update TIM IE */
99 	/* if(rtw_tim_map_anyone_be_set(padapter, pstapriv->tim_bitmap)) */
100 #endif
101 	if (_TRUE) {
102 		u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
103 		uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
104 
105 		p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
106 		if (p != NULL && tim_ielen > 0) {
107 			tim_ielen += 2;
108 
109 			premainder_ie = p + tim_ielen;
110 
111 			tim_ie_offset = (sint)(p - pie);
112 
113 			remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
114 
115 			/*append TIM IE from dst_ie offset*/
116 			dst_ie = p;
117 		} else {
118 			tim_ielen = 0;
119 
120 			/*calculate head_len*/
121 			offset = _FIXED_IE_LENGTH_;
122 
123 			/* get ssid_ie len */
124 			p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
125 			if (p != NULL)
126 				offset += tmp_len + 2;
127 
128 			/*get supported rates len*/
129 			p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
130 			if (p !=  NULL)
131 				offset += tmp_len + 2;
132 
133 			/*DS Parameter Set IE, len=3*/
134 			offset += 3;
135 
136 			premainder_ie = pie + offset;
137 
138 			remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
139 
140 			/*append TIM IE from offset*/
141 			dst_ie = pie + offset;
142 
143 		}
144 
145 		if (remainder_ielen > 0) {
146 			pbackup_remainder_ie = rtw_malloc(remainder_ielen);
147 			if (pbackup_remainder_ie && premainder_ie)
148 				_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
149 		}
150 
151 		/* append TIM IE */
152 		dst_ie += rtw_set_tim_ie(0, 1, pstapriv->tim_bitmap, pstapriv->aid_bmp_len, dst_ie);
153 
154 		/*copy remainder IE*/
155 		if (pbackup_remainder_ie) {
156 			_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
157 
158 			rtw_mfree(pbackup_remainder_ie, remainder_ielen);
159 		}
160 
161 		offset = (uint)(dst_ie - pie);
162 		pnetwork_mlmeext->IELength = offset + remainder_ielen;
163 
164 	}
165 }
166 
rtw_add_bcn_ie(_adapter * padapter,WLAN_BSSID_EX * pnetwork,u8 index,u8 * data,u8 len)167 void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
168 {
169 	PNDIS_802_11_VARIABLE_IEs	pIE;
170 	u8	bmatch = _FALSE;
171 	u8	*pie = pnetwork->IEs;
172 	u8	*p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
173 	u32	i, offset, ielen = 0, ie_offset, remainder_ielen = 0;
174 
175 	/* Search element id (index) exits or not */
176 	for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
177 		pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
178 
179 		if (pIE->ElementID > index)
180 			break;
181 		else if (pIE->ElementID == index) { /* already exist the same IE */
182 			p = (u8 *)pIE;
183 			ielen = pIE->Length;
184 			bmatch = _TRUE;
185 			break;
186 		}
187 
188 		p = (u8 *)pIE;
189 		ielen = pIE->Length;
190 		i += (pIE->Length + 2);
191 	}
192 
193 	/* Backup remainder IE */
194 	if (p != NULL && ielen > 0) {
195 		ielen += 2;
196 
197 		premainder_ie = p + ielen;
198 
199 		ie_offset = (sint)(p - pie);
200 
201 		remainder_ielen = pnetwork->IELength - ie_offset - ielen;
202 
203 		if (bmatch)
204 			dst_ie = p;
205 		else
206 			dst_ie = (p + ielen);
207 	}
208 
209 	if (dst_ie == NULL)
210 		return;
211 
212 	if (remainder_ielen > 0) {
213 		pbackup_remainder_ie = rtw_malloc(remainder_ielen);
214 		if (pbackup_remainder_ie && premainder_ie)
215 			_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
216 	}
217 
218 	*dst_ie++ = index;
219 	*dst_ie++ = len;
220 
221 	_rtw_memcpy(dst_ie, data, len);
222 	dst_ie += len;
223 
224 	/* Append remainder IE */
225 	if (pbackup_remainder_ie) {
226 		_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
227 
228 		rtw_mfree(pbackup_remainder_ie, remainder_ielen);
229 	}
230 
231 	offset = (uint)(dst_ie - pie);
232 	pnetwork->IELength = offset + remainder_ielen;
233 }
234 
rtw_remove_bcn_ie(_adapter * padapter,WLAN_BSSID_EX * pnetwork,u8 index)235 void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
236 {
237 	u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
238 	uint offset, ielen, ie_offset, remainder_ielen = 0;
239 	u8	*pie = pnetwork->IEs;
240 
241 	p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
242 	if (p != NULL && ielen > 0) {
243 		ielen += 2;
244 
245 		premainder_ie = p + ielen;
246 
247 		ie_offset = (sint)(p - pie);
248 
249 		remainder_ielen = pnetwork->IELength - ie_offset - ielen;
250 
251 		dst_ie = p;
252 	} else
253 		return;
254 
255 	if (remainder_ielen > 0) {
256 		pbackup_remainder_ie = rtw_malloc(remainder_ielen);
257 		if (pbackup_remainder_ie && premainder_ie)
258 			_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
259 	}
260 
261 	/* copy remainder IE */
262 	if (pbackup_remainder_ie) {
263 		_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
264 
265 		rtw_mfree(pbackup_remainder_ie, remainder_ielen);
266 	}
267 
268 	offset = (uint)(dst_ie - pie);
269 	pnetwork->IELength = offset + remainder_ielen;
270 }
271 
rtw_remove_bcn_ie_ex(_adapter * padapter,WLAN_BSSID_EX * pnetwork,u8 index,u8 * pindex_ex,u8 index_ex_len)272 void rtw_remove_bcn_ie_ex(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8* pindex_ex, u8 index_ex_len)
273 {
274 	u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
275 	uint offset, ielen, ie_offset, remainder_ielen = 0;
276 	u8	*pie = pnetwork->IEs;
277 
278 	p = rtw_get_ie_ex(pie + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, index, pindex_ex, index_ex_len, NULL, &ielen);
279 	if (p != NULL && ielen > 0) {
280 		premainder_ie = p + ielen;
281 
282 		ie_offset = (sint)(p - pie);
283 
284 		remainder_ielen = pnetwork->IELength - ie_offset - ielen;
285 
286 		dst_ie = p;
287 	} else
288 		return;
289 
290 	if (remainder_ielen > 0) {
291 		pbackup_remainder_ie = rtw_malloc(remainder_ielen);
292 		if (pbackup_remainder_ie && premainder_ie)
293 			_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
294 	}
295 
296 	/* copy remainder IE */
297 	if (pbackup_remainder_ie) {
298 		_rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
299 
300 		rtw_mfree(pbackup_remainder_ie, remainder_ielen);
301 	}
302 
303 	offset = (uint)(dst_ie - pie);
304 	pnetwork->IELength = offset + remainder_ielen;
305 }
306 
307 u8 chk_sta_is_alive(struct sta_info *psta);
chk_sta_is_alive(struct sta_info * psta)308 u8 chk_sta_is_alive(struct sta_info *psta)
309 {
310 	u8 ret = _FALSE;
311 #ifdef DBG_EXPIRATION_CHK
312 	RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
313 		 , MAC_ARG(psta->phl_sta->mac_addr)
314 		 , 0 /* TODO: psta->phl_sta->hal_sta->rssi_stat.rssi */
315 		 /* , STA_RX_PKTS_ARG(psta) */
316 		 , STA_RX_PKTS_DIFF_ARG(psta)
317 		 , psta->expire_to
318 		 , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
319 		 , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
320 		 , psta->sleepq_len
321 		);
322 #endif
323 
324 	/* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
325 	if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts)) {
326 #if 0
327 		if (psta->state & WIFI_SLEEP_STATE)
328 			ret = _TRUE;
329 #endif
330 	} else
331 		ret = _TRUE;
332 
333 #ifdef CONFIG_RTW_MESH
334 	if (MLME_IS_MESH(psta->padapter)) {
335 		u8 bcn_alive, hwmp_alive;
336 
337 		hwmp_alive = (psta->sta_stats.rx_hwmp_pkts !=
338 			      psta->sta_stats.last_rx_hwmp_pkts);
339 		bcn_alive = (psta->sta_stats.rx_beacon_pkts !=
340 			     psta->sta_stats.last_rx_beacon_pkts);
341 		/* The reference for nexthop_lookup */
342 		psta->alive = ret || hwmp_alive || bcn_alive;
343 		/* The reference for expire_timeout_chk */
344 		/* Exclude bcn_alive to avoid a misjudge condition
345 		   that a peer unexpectedly leave and restart quickly*/
346 		ret = ret || hwmp_alive;
347 	}
348 #endif
349 
350 	sta_update_last_rx_pkts(psta);
351 
352 	return ret;
353 }
354 
355 /**
356  * issue_aka_chk_frame - issue active keep alive check frame
357  *	aka = active keep alive
358  */
359 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
issue_aka_chk_frame(_adapter * adapter,struct sta_info * psta)360 static int issue_aka_chk_frame(_adapter *adapter, struct sta_info *psta)
361 {
362 	int ret = _FAIL;
363 	u8 *target_addr = psta->phl_sta->mac_addr;
364 
365 	if (MLME_IS_AP(adapter)) {
366 		/* issue null data to check sta alive */
367 		if (psta->state & WIFI_SLEEP_STATE)
368 			ret = issue_nulldata(adapter, target_addr, 0, 1, 50);
369 		else
370 			ret = issue_nulldata(adapter, target_addr, 0, 3, 50);
371 	}
372 
373 #ifdef CONFIG_RTW_MESH
374 	if (MLME_IS_MESH(adapter)) {
375 		struct rtw_mesh_path *mpath;
376 
377 		rtw_rcu_read_lock();
378 		mpath = rtw_mesh_path_lookup(adapter, target_addr);
379 		if (!mpath) {
380 			mpath = rtw_mesh_path_add(adapter, target_addr);
381 			if (IS_ERR(mpath)) {
382 				rtw_rcu_read_unlock();
383 				RTW_ERR(FUNC_ADPT_FMT" rtw_mesh_path_add for "MAC_FMT" fail.\n",
384 					FUNC_ADPT_ARG(adapter), MAC_ARG(target_addr));
385 				return _FAIL;
386 			}
387 		}
388 		if (mpath->flags & RTW_MESH_PATH_ACTIVE)
389 			ret = _SUCCESS;
390 		else {
391 			u8 flags = RTW_PREQ_Q_F_START | RTW_PREQ_Q_F_PEER_AKA;
392 			/* issue PREQ to check peer alive */
393 			rtw_mesh_queue_preq(mpath, flags);
394 			ret = _FALSE;
395 		}
396 		rtw_rcu_read_unlock();
397 	}
398 #endif
399 	return ret;
400 }
401 #endif
402 
expire_timeout_chk(_adapter * padapter)403 void	expire_timeout_chk(_adapter *padapter)
404 {
405 	_list	*phead, *plist;
406 	u8 updated = _FALSE;
407 	struct sta_info *psta = NULL;
408 	struct sta_priv *pstapriv = &padapter->stapriv;
409 	u8 chk_alive_num = 0;
410 	char chk_alive_list[NUM_STA];
411 	int i;
412 	int stainfo_offset;
413 	u8 flush_num = 0;
414 	char flush_list[NUM_STA]={0};
415 
416 #ifdef CONFIG_RTW_MESH
417 	if (MLME_IS_MESH(padapter)
418 		&& check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)
419 	) {
420 		struct rtw_mesh_cfg *mcfg = &padapter->mesh_cfg;
421 
422 		rtw_mesh_path_expire(padapter);
423 
424 		/* TBD: up layer timeout mechanism */
425 		/* if (!mcfg->plink_timeout)
426 			return; */
427 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
428 		return;
429 #endif
430 	}
431 #endif
432 
433 #ifdef CONFIG_RTW_WDS
434 	rtw_wds_path_expire(padapter);
435 #endif
436 
437 	_rtw_spinlock_bh(&pstapriv->auth_list_lock);
438 
439 	phead = &pstapriv->auth_list;
440 	plist = get_next(phead);
441 
442 	/* check auth_queue */
443 #ifdef DBG_EXPIRATION_CHK
444 	if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
445 		RTW_INFO(FUNC_ADPT_FMT" auth_list, cnt:%u\n"
446 			, FUNC_ADPT_ARG(padapter), pstapriv->auth_list_cnt);
447 	}
448 #endif
449 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
450 		psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
451 
452 		plist = get_next(plist);
453 
454 
455 #ifdef CONFIG_ATMEL_RC_PATCH
456 		if (_rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->phl_sta->mac_addr), ETH_ALEN) == _TRUE)
457 			continue;
458 		if (psta->flag_atmel_rc)
459 			continue;
460 #endif
461 		if (psta->expire_to > 0) {
462 			psta->expire_to--;
463 			if (psta->expire_to == 0) {
464 				stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
465 				if (stainfo_offset_valid(stainfo_offset))
466 					flush_list[flush_num++] = stainfo_offset;
467 				else
468 					rtw_warn_on(1);
469 			}
470 		}
471 
472 	}
473 
474 	_rtw_spinunlock_bh(&pstapriv->auth_list_lock);
475 	for (i = 0; i < flush_num; i++) {
476 		psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
477 		RTW_INFO(FUNC_ADPT_FMT" auth expire "MAC_FMT"\n"
478 			, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr));
479 		rtw_free_stainfo(padapter, psta);
480 		psta = NULL;
481 	}
482 
483 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
484 
485 	phead = &pstapriv->asoc_list;
486 	plist = get_next(phead);
487 
488 	/* check asoc_queue */
489 #ifdef DBG_EXPIRATION_CHK
490 	if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
491 		RTW_INFO(FUNC_ADPT_FMT" asoc_list, cnt:%u\n"
492 			, FUNC_ADPT_ARG(padapter), pstapriv->asoc_list_cnt);
493 	}
494 #endif
495 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
496 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
497 		plist = get_next(plist);
498 #ifdef CONFIG_ATMEL_RC_PATCH
499 		RTW_INFO("%s:%d  psta=%p, %02x,%02x||%02x,%02x  \n\n", __func__,  __LINE__,
500 			psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->phl_sta->mac_addr[0], psta->phl_sta->mac_addr[5]);
501 		if (_rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->phl_sta->mac_addr), ETH_ALEN) == _TRUE)
502 			continue;
503 		if (psta->flag_atmel_rc)
504 			continue;
505 		RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
506 #endif
507 #ifdef CONFIG_AUTO_AP_MODE
508 		if (psta->isrc)
509 			continue;
510 #endif
511 		if (chk_sta_is_alive(psta) || !psta->expire_to) {
512 			psta->expire_to = pstapriv->expire_to;
513 			psta->keep_alive_trycnt = 0;
514 			#if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
515 			psta->under_exist_checking = 0;
516 			#endif
517 		} else
518 			psta->expire_to--;
519 
520 #if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
521 		if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
522 			/* check sta by delba(addba) for 11n STA */
523 			/* ToDo: use CCX report to check for all STAs */
524 			/* RTW_INFO("asoc check by DELBA/ADDBA! (pstapriv->expire_to=%d s)(psta->expire_to=%d s), [%02x, %d]\n", pstapriv->expire_to*2, psta->expire_to*2, psta->htpriv.agg_enable_bitmap, psta->under_exist_checking); */
525 
526 			if (psta->expire_to <= (pstapriv->expire_to - 50)) {
527 				RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
528 				psta->under_exist_checking = 0;
529 				psta->expire_to = 0;
530 			} else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
531 				RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
532 				psta->under_exist_checking = 1;
533 				/* tear down TX AMPDU */
534 				send_delba(padapter, 1, psta->phl_sta->mac_addr);/*  */ /* originator */
535 				psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
536 				psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
537 			}
538 		}
539 #endif /* !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT) */
540 
541 		if (psta->expire_to <= 0) {
542 			struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
543 
544 			if (padapter->registrypriv.wifi_spec == 1) {
545 				psta->expire_to = pstapriv->expire_to;
546 				continue;
547 			}
548 
549 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
550 #ifdef CONFIG_80211N_HT
551 
552 #define KEEP_ALIVE_TRYCNT (3)
553 
554 			if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
555 				if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
556 					psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
557 				else
558 					psta->keep_alive_trycnt = 0;
559 
560 			} else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
561 				psta->keep_alive_trycnt = 0;
562 			if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
563 				uint priority = 1; /* test using BK */
564 				u8 issued = 0;
565 
566 				/* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
567 				issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
568 
569 				if (0 == issued) {
570 					if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
571 						psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
572 
573 						if (psta->state & WIFI_SLEEP_STATE)
574 							psta->expire_to = 2; /* 2x2=4 sec */
575 						else
576 							psta->expire_to = 1; /* 2 sec */
577 
578 						psta->state |= WIFI_STA_ALIVE_CHK_STATE;
579 
580 						/* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
581 
582 						RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
583 
584 						issue_addba_req(padapter, psta->phl_sta->mac_addr, (u8)priority);
585 
586 						_set_timer(&psta->addba_retry_timer, ADDBA_TO);
587 
588 						psta->keep_alive_trycnt++;
589 
590 						continue;
591 					}
592 				}
593 			}
594 			if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
595 				psta->keep_alive_trycnt = 0;
596 				psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
597 				RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
598 			}
599 
600 #endif /* CONFIG_80211N_HT */
601 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK	 */
602 			if (psta->state & WIFI_SLEEP_STATE) {
603 				if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
604 					/* to check if alive by another methods if staion is at ps mode.					 */
605 					psta->expire_to = pstapriv->expire_to;
606 					psta->state |= WIFI_STA_ALIVE_CHK_STATE;
607 
608 					/* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->phl_sta->mac_addr)); */
609 
610 					/* to update bcn with tim_bitmap for this station */
611 					rtw_tim_map_set(padapter, pstapriv->tim_bitmap, psta->phl_sta->aid);
612 					rtw_update_beacon(padapter, _TIM_IE_, NULL, _TRUE, 0);
613 
614 					if (!pmlmeext->active_keep_alive_check)
615 						continue;
616 				}
617 			}
618 
619 			{
620 				int stainfo_offset;
621 
622 				stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
623 				if (stainfo_offset_valid(stainfo_offset))
624 					chk_alive_list[chk_alive_num++] = stainfo_offset;
625 				continue;
626 			}
627 		} else {
628 			/* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
629 			if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
630 			    && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
631 			   ) {
632 				RTW_INFO(FUNC_ADPT_FMT" sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n"
633 					, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr)
634 					, psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
635 				wakeup_sta_to_xmit(padapter, psta);
636 			}
637 		}
638 	}
639 
640 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
641 
642 	if (chk_alive_num) {
643 #if defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK)
644 		u8 backup_ch = 0, backup_bw = 0, backup_offset = 0;
645 		u8 union_ch = 0, union_bw = 0, union_offset = 0;
646 		u8 switch_channel_by_drv = _TRUE;
647 		struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
648 #endif
649 		char del_asoc_list[NUM_STA];
650 
651 		_rtw_memset(del_asoc_list, NUM_STA, NUM_STA);
652 
653 		#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
654 		if (pmlmeext->active_keep_alive_check) {
655 
656 			if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
657 				|| pmlmeext->chandef.chan != union_ch)
658 				switch_channel_by_drv = _FALSE;
659 
660 			/* switch to correct channel of current network  before issue keep-alive frames */
661 			if (switch_channel_by_drv == _TRUE && rtw_get_oper_ch(padapter) != pmlmeext->chandef.chan) {
662 				backup_ch = rtw_get_oper_ch(padapter);
663 				backup_bw = rtw_get_oper_bw(padapter);
664 				backup_offset = rtw_get_oper_choffset(padapter);
665 				set_channel_bwmode(padapter, union_ch, union_offset, union_bw, _FALSE);
666 			}
667 		}
668 		#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
669 
670 		/* check loop */
671 		for (i = 0; i < chk_alive_num; i++) {
672 			#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
673 			int ret = _FAIL;
674 			#endif
675 
676 			psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
677 
678 			#ifdef CONFIG_ATMEL_RC_PATCH
679 			if (_rtw_memcmp(pstapriv->atmel_rc_pattern, psta->phl_sta->mac_addr, ETH_ALEN) == _TRUE)
680 				continue;
681 			if (psta->flag_atmel_rc)
682 				continue;
683 			#endif
684 
685 			if (!(psta->state & WIFI_ASOC_STATE))
686 				continue;
687 
688 			#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
689 			if (pmlmeext->active_keep_alive_check) {
690 				/* issue active keep alive frame to check */
691 				ret = issue_aka_chk_frame(padapter, psta);
692 
693 				psta->keep_alive_trycnt++;
694 				if (ret == _SUCCESS) {
695 					RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" is alive\n"
696 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr));
697 					psta->expire_to = pstapriv->expire_to;
698 					psta->keep_alive_trycnt = 0;
699 					continue;
700 				} else if (psta->keep_alive_trycnt <= 3) {
701 					RTW_INFO(FUNC_ADPT_FMT" asoc check, "MAC_FMT" keep_alive_trycnt=%d\n"
702 						, FUNC_ADPT_ARG(padapter) , MAC_ARG(psta->phl_sta->mac_addr), psta->keep_alive_trycnt);
703 					psta->expire_to = 1;
704 					continue;
705 				}
706 			}
707 			#endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
708 
709 			psta->keep_alive_trycnt = 0;
710 			del_asoc_list[i] = chk_alive_list[i];
711 			_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
712 			if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
713 				rtw_list_delete(&psta->asoc_list);
714 				pstapriv->asoc_list_cnt--;
715 				#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
716 				if (psta->tbtx_enable)
717 					pstapriv->tbtx_asoc_list_cnt--;
718 				#endif
719 				STA_SET_MESH_PLINK(psta, NULL);
720 			}
721 			_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
722 		}
723 
724 		/* delete loop */
725 		for (i = 0; i < chk_alive_num; i++) {
726 			u8 sta_addr[ETH_ALEN];
727 
728 			if (del_asoc_list[i] >= NUM_STA)
729 				continue;
730 
731 			psta = rtw_get_stainfo_by_offset(pstapriv, del_asoc_list[i]);
732 			_rtw_memcpy(sta_addr, psta->phl_sta->mac_addr, ETH_ALEN);
733 
734 			RTW_INFO(FUNC_ADPT_FMT" asoc expire "MAC_FMT", state=0x%x\n"
735 				, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->phl_sta->mac_addr), psta->state);
736 			updated |= ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _FALSE, _FALSE);
737 			#ifdef CONFIG_RTW_MESH
738 			if (MLME_IS_MESH(padapter))
739 				rtw_mesh_expire_peer(padapter, sta_addr);
740 			#endif
741 		}
742 
743 		#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
744 		if (pmlmeext->active_keep_alive_check) {
745 			/* back to the original operation channel */
746 			if (switch_channel_by_drv == _TRUE && backup_ch > 0)
747 				set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw, _FALSE);
748 		}
749 		#endif
750 	}
751 
752 	associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
753 }
754 
755 #ifdef CONFIG_BMC_TX_RATE_SELECT
rtw_ap_find_mini_tx_rate(_adapter * adapter)756 u8 rtw_ap_find_mini_tx_rate(_adapter *adapter)
757 {
758 	_list	*phead, *plist;
759 	u8 mini_tx_rate = DESC_RATEVHTSS4MCS9, sta_tx_rate;
760 	struct sta_info *psta = NULL;
761 	struct sta_priv *pstapriv = &adapter->stapriv;
762 
763 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
764 	phead = &pstapriv->asoc_list;
765 	plist = get_next(phead);
766 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
767 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
768 		plist = get_next(plist);
769 
770 		sta_tx_rate = psta->phl_sta->ra_info.curr_tx_rate & 0x7F;
771 		if (sta_tx_rate < mini_tx_rate)
772 			mini_tx_rate = sta_tx_rate;
773 	}
774 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
775 
776 	return mini_tx_rate;
777 }
778 
rtw_ap_find_bmc_rate(_adapter * adapter,u8 tx_rate)779 u8 rtw_ap_find_bmc_rate(_adapter *adapter, u8 tx_rate)
780 {
781 	u8 tx_ini_rate = DESC_RATE6M;
782 
783 	switch (tx_rate) {
784 	case DESC_RATEVHTSS3MCS9:
785 	case DESC_RATEVHTSS3MCS8:
786 	case DESC_RATEVHTSS3MCS7:
787 	case DESC_RATEVHTSS3MCS6:
788 	case DESC_RATEVHTSS3MCS5:
789 	case DESC_RATEVHTSS3MCS4:
790 	case DESC_RATEVHTSS3MCS3:
791 	case DESC_RATEVHTSS2MCS9:
792 	case DESC_RATEVHTSS2MCS8:
793 	case DESC_RATEVHTSS2MCS7:
794 	case DESC_RATEVHTSS2MCS6:
795 	case DESC_RATEVHTSS2MCS5:
796 	case DESC_RATEVHTSS2MCS4:
797 	case DESC_RATEVHTSS2MCS3:
798 	case DESC_RATEVHTSS1MCS9:
799 	case DESC_RATEVHTSS1MCS8:
800 	case DESC_RATEVHTSS1MCS7:
801 	case DESC_RATEVHTSS1MCS6:
802 	case DESC_RATEVHTSS1MCS5:
803 	case DESC_RATEVHTSS1MCS4:
804 	case DESC_RATEVHTSS1MCS3:
805 	case DESC_RATEMCS15:
806 	case DESC_RATEMCS14:
807 	case DESC_RATEMCS13:
808 	case DESC_RATEMCS12:
809 	case DESC_RATEMCS11:
810 	case DESC_RATEMCS7:
811 	case DESC_RATEMCS6:
812 	case DESC_RATEMCS5:
813 	case DESC_RATEMCS4:
814 	case DESC_RATEMCS3:
815 	case DESC_RATE54M:
816 	case DESC_RATE48M:
817 	case DESC_RATE36M:
818 	case DESC_RATE24M:
819 		tx_ini_rate = DESC_RATE24M;
820 		break;
821 	case DESC_RATEVHTSS3MCS2:
822 	case DESC_RATEVHTSS3MCS1:
823 	case DESC_RATEVHTSS2MCS2:
824 	case DESC_RATEVHTSS2MCS1:
825 	case DESC_RATEVHTSS1MCS2:
826 	case DESC_RATEVHTSS1MCS1:
827 	case DESC_RATEMCS10:
828 	case DESC_RATEMCS9:
829 	case DESC_RATEMCS2:
830 	case DESC_RATEMCS1:
831 	case DESC_RATE18M:
832 	case DESC_RATE12M:
833 		tx_ini_rate = DESC_RATE12M;
834 		break;
835 	case DESC_RATEVHTSS3MCS0:
836 	case DESC_RATEVHTSS2MCS0:
837 	case DESC_RATEVHTSS1MCS0:
838 	case DESC_RATEMCS8:
839 	case DESC_RATEMCS0:
840 	case DESC_RATE9M:
841 	case DESC_RATE6M:
842 		tx_ini_rate = DESC_RATE6M;
843 		break;
844 	case DESC_RATE11M:
845 	case DESC_RATE5_5M:
846 	case DESC_RATE2M:
847 	case DESC_RATE1M:
848 		tx_ini_rate = DESC_RATE1M;
849 		break;
850 	default:
851 		tx_ini_rate = DESC_RATE6M;
852 		break;
853 	}
854 
855 	if (WIFI_ROLE_IS_ON_5G(adapter))
856 		if (tx_ini_rate < DESC_RATE6M)
857 			tx_ini_rate = DESC_RATE6M;
858 
859 	return tx_ini_rate;
860 }
861 
rtw_update_bmc_sta_tx_rate(_adapter * adapter)862 void rtw_update_bmc_sta_tx_rate(_adapter *adapter)
863 {
864 	struct sta_info *psta = NULL;
865 	u8 tx_rate;
866 
867 	psta = rtw_get_bcmc_stainfo(adapter);
868 	if (psta == NULL) {
869 		RTW_ERR(ADPT_FMT "could not get bmc_sta !!\n", ADPT_ARG(adapter));
870 		return;
871 	}
872 
873 	if (adapter->bmc_tx_rate != MGN_UNKNOWN) {
874 		psta->init_rate = adapter->bmc_tx_rate;
875 		goto _exit;
876 	}
877 
878 	if (adapter->stapriv.asoc_sta_count <= 2)
879 		goto _exit;
880 
881 	tx_rate = rtw_ap_find_mini_tx_rate(adapter);
882 	#ifdef CONFIG_BMC_TX_LOW_RATE
883 	tx_rate = rtw_ap_find_bmc_rate(adapter, tx_rate);
884 	#endif
885 
886 	psta->init_rate = hwrate_to_mrate(tx_rate);
887 
888 _exit:
889 	RTW_INFO(ADPT_FMT" BMC Tx rate - %s\n", ADPT_ARG(adapter), MGN_RATE_STR(psta->init_rate));
890 }
891 #endif
892 
rtw_init_bmc_sta_tx_rate(_adapter * padapter,struct sta_info * psta)893 void rtw_init_bmc_sta_tx_rate(_adapter *padapter, struct sta_info *psta)
894 {
895 /* ToDo: need API to query hal_sta->ra_info.ramask */
896 #if 0
897 #ifdef CONFIG_BMC_TX_LOW_RATE
898 	struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
899 #endif
900 	u8 rate_idx = 0;
901 	u8 brate_table[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M,
902 		MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
903 
904 	if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
905 		return;
906 
907 	if (padapter->bmc_tx_rate != MGN_UNKNOWN)
908 		psta->init_rate = padapter->bmc_tx_rate;
909 	else {
910 		#ifdef CONFIG_BMC_TX_LOW_RATE
911 		if (IsEnableHWOFDM(pmlmeext->cur_wireless_mode) && (psta->phl_sta->ra_info.ramask && 0xFF0))
912 			rate_idx = get_lowest_rate_idx_ex(psta->phl_sta->ra_info.ramask, 4); /*from basic rate*/
913 		else
914 			rate_idx = get_lowest_rate_idx(psta->phl_sta->ra_info.ramask); /*from basic rate*/
915 		#else
916 		rate_idx = get_highest_rate_idx(psta->phl_sta->ra_info.ramask); /*from basic rate*/
917 		#endif
918 		if (rate_idx < 12)
919 			psta->init_rate = brate_table[rate_idx];
920 		else
921 			psta->init_rate = MGN_1M;
922 	}
923 #endif
924 	RTW_INFO(ADPT_FMT" BMC Init Tx rate - %s\n", ADPT_ARG(padapter), MGN_RATE_STR(psta->init_rate));
925 }
926 
927 #if defined(CONFIG_80211N_HT) && defined(CONFIG_BEAMFORMING)
update_sta_info_apmode_ht_bf_cap(_adapter * padapter,struct sta_info * psta)928 void update_sta_info_apmode_ht_bf_cap(_adapter *padapter, struct sta_info *psta)
929 {
930 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
931 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
932 	struct ht_priv	*phtpriv_sta = &psta->htpriv;
933 
934 	u8 cur_beamform_cap = 0;
935 
936 	/*Config Tx beamforming setting*/
937 	if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
938 		GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
939 		SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
940 		/*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
941 		SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
942 	}
943 
944 	if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
945 		GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
946 		SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
947 		/*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
948 		SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
949 	}
950 	if (cur_beamform_cap)
951 		RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->phl_sta->aid, cur_beamform_cap);
952 
953 	phtpriv_sta->beamform_cap = cur_beamform_cap;
954 }
955 #endif /*CONFIG_80211N_HT && CONFIG_BEAMFORMING*/
956 
957 /* notes:
958  * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode  */
update_sta_info_apmode(_adapter * padapter,struct sta_info * psta)959 void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
960 {
961 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
962 	struct security_priv *psecuritypriv = &padapter->securitypriv;
963 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
964 	struct rtw_wifi_role_t *wrole = padapter->phl_role;
965 	struct protocol_cap_t *proto_role_cap = &(wrole->proto_role_cap);
966 #ifdef CONFIG_80211N_HT
967 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
968 	struct ht_priv	*phtpriv_sta = &psta->htpriv;
969 #endif /* CONFIG_80211N_HT */
970 	u8	cur_ldpc_cap = 0, cur_stbc_cap = 0;
971 	/* set intf_tag to if1 */
972 	/* psta->intf_tag = 0; */
973 
974 	RTW_INFO("%s\n", __FUNCTION__);
975 
976 	/*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
977 
978 	if (!MLME_IS_MESH(padapter) && psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
979 		psta->ieee8021x_blocked = _TRUE;
980 	else
981 		psta->ieee8021x_blocked = _FALSE;
982 
983 
984 	/* update sta's cap */
985 
986 	psta->phl_sta->chandef.chan = pmlmeext->chandef.chan;
987 	psta->phl_sta->chandef.band = (psta->phl_sta->chandef.chan > 14) ? BAND_ON_5G : BAND_ON_24G;
988 
989 	/* ERP */
990 	VCS_update(padapter, psta);
991 #ifdef CONFIG_80211N_HT
992 	/* HT related cap */
993 	if (phtpriv_sta->ht_option) {
994 		/* check if sta supports rx ampdu */
995 		phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
996 
997 		phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
998 
999 		/* bwmode */
1000 		if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
1001 			psta->phl_sta->chandef.bw = CHANNEL_WIDTH_40;
1002 		else
1003 			psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
1004 
1005 		if (phtpriv_sta->op_present
1006 			&& !GET_HT_OP_ELE_STA_CHL_WIDTH(phtpriv_sta->ht_op))
1007 			psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
1008 
1009 		if (psta->ht_40mhz_intolerant)
1010 			psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
1011 
1012 		if (pmlmeext->chandef.bw < psta->phl_sta->chandef.bw)
1013 			psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
1014 
1015 		phtpriv_sta->ch_offset = pmlmeext->chandef.offset;
1016 
1017 
1018 		/* check if sta support s Short GI 20M */
1019 		if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
1020 			phtpriv_sta->sgi_20m = _TRUE;
1021 
1022 		/* check if sta support s Short GI 40M */
1023 		if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
1024 			if (psta->phl_sta->chandef.bw == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
1025 				phtpriv_sta->sgi_40m = _TRUE;
1026 			else
1027 				phtpriv_sta->sgi_40m = _FALSE;
1028 		}
1029 
1030 		psta->qos_option = _TRUE;
1031 
1032 		/* B0 Config LDPC Coding Capability */
1033 		if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
1034 		    GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
1035 			SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
1036 			RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->phl_sta->aid);
1037 		}
1038 
1039 		/* B7 B8 B9 Config STBC setting */
1040 		if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
1041 		    GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
1042 			SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
1043 			RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->phl_sta->aid);
1044 		}
1045 
1046 		psta->phl_sta->asoc_cap.stbc_ht_tx =
1047 			GET_HT_CAP_ELE_TX_STBC((u8 *)(&phtpriv_sta->ht_cap));
1048 		psta->phl_sta->asoc_cap.stbc_ht_rx =
1049 			proto_role_cap->stbc_ht_tx ?
1050 			GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap)) : 0;
1051 
1052 		#ifdef CONFIG_BEAMFORMING
1053 		update_sta_info_apmode_ht_bf_cap(padapter, psta);
1054 		#endif
1055 	} else {
1056 		phtpriv_sta->ampdu_enable = _FALSE;
1057 
1058 		phtpriv_sta->sgi_20m = _FALSE;
1059 		phtpriv_sta->sgi_40m = _FALSE;
1060 		psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
1061 		phtpriv_sta->ch_offset = CHAN_OFFSET_NO_EXT;
1062 	}
1063 
1064 	phtpriv_sta->ldpc_cap = cur_ldpc_cap;
1065 	phtpriv_sta->stbc_cap = cur_stbc_cap;
1066 
1067 	/* Rx AMPDU */
1068 	send_delba(padapter, 0, psta->phl_sta->mac_addr);/* recipient */
1069 
1070 	/* TX AMPDU */
1071 	send_delba(padapter, 1, psta->phl_sta->mac_addr);/*  */ /* originator */
1072 	phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
1073 	phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
1074 #endif /* CONFIG_80211N_HT */
1075 
1076 #ifdef CONFIG_80211AC_VHT
1077 	update_sta_vht_info_apmode(padapter, psta);
1078 #endif
1079 
1080 #ifdef CONFIG_80211AX_HE
1081 	update_sta_he_info_apmode(padapter, psta);
1082 #endif
1083 
1084 	psta->phl_sta->chandef.offset = (psta->phl_sta->chandef.bw > CHANNEL_WIDTH_20) ?
1085 		pmlmeext->chandef.offset : CHAN_OFFSET_NO_EXT;
1086 
1087 	/* ToDo: need API to inform hal_sta->ra_info.is_support_sgi */
1088 	/* psta->phl_sta->ra_info.is_support_sgi = query_ra_short_GI(psta, rtw_get_tx_bw_mode(padapter, psta)); */
1089 	update_ldpc_stbc_cap(psta);
1090 
1091 	/* todo: init other variables */
1092 
1093 	_rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
1094 
1095 	_rtw_spinlock_bh(&psta->lock);
1096 
1097 	/* Check encryption */
1098 	if (!MLME_IS_MESH(padapter) && psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
1099 		psta->state |= WIFI_UNDER_KEY_HANDSHAKE;
1100 
1101 	psta->state |= WIFI_ASOC_STATE;
1102 
1103 	_rtw_spinunlock_bh(&psta->lock);
1104 }
1105 
update_ap_info(_adapter * padapter,struct sta_info * psta)1106 static void update_ap_info(_adapter *padapter, struct sta_info *psta)
1107 {
1108 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1109 	WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
1110 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
1111 #ifdef CONFIG_80211N_HT
1112 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
1113 #endif /* CONFIG_80211N_HT */
1114 
1115 #ifdef CONFIG_RTW_MESH
1116 	if (MLME_IS_MESH(padapter))
1117 		psta->qos_option = 1;
1118 #endif
1119 
1120 	psta->phl_sta->wmode = pmlmeext->cur_wireless_mode;
1121 
1122 	psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
1123 	_rtw_memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
1124 
1125 #ifdef CONFIG_80211N_HT
1126 	/* HT related cap */
1127 	if (phtpriv_ap->ht_option) {
1128 		/* check if sta supports rx ampdu */
1129 		/* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
1130 
1131 		/* check if sta support s Short GI 20M */
1132 		if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
1133 			phtpriv_ap->sgi_20m = _TRUE;
1134 		/* check if sta support s Short GI 40M */
1135 		if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
1136 			phtpriv_ap->sgi_40m = _TRUE;
1137 
1138 		psta->qos_option = _TRUE;
1139 	} else {
1140 		phtpriv_ap->ampdu_enable = _FALSE;
1141 
1142 		phtpriv_ap->sgi_20m = _FALSE;
1143 		phtpriv_ap->sgi_40m = _FALSE;
1144 	}
1145 
1146 	psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
1147 	phtpriv_ap->ch_offset = pmlmeext->chandef.offset;
1148 
1149 	phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
1150 	phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
1151 
1152 	_rtw_memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
1153 
1154 #ifdef CONFIG_80211AC_VHT
1155 	_rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
1156 
1157 #ifdef CONFIG_80211AX_HE
1158 	_rtw_memcpy(&psta->hepriv, &pmlmepriv->hepriv, sizeof(struct he_priv));
1159 #endif /* CONFIG_80211AX_HE */
1160 
1161 #endif /* CONFIG_80211AC_VHT */
1162 
1163 #endif /* CONFIG_80211N_HT */
1164 
1165 	_rtw_spinlock_bh(&psta->lock);
1166 	psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
1167 	psta->state |= WIFI_ASOC_STATE;
1168 	_rtw_spinunlock_bh(&psta->lock);
1169 
1170 	rtw_init_bmc_sta_tx_rate(padapter, psta);
1171 }
1172 
rtw_ap_set_edca(_adapter * padapter,enum rtw_ac ac,u32 parm)1173 void rtw_ap_set_edca(_adapter *padapter, enum rtw_ac ac, u32 parm)
1174 {
1175 	struct sta_priv *pstapriv = &padapter->stapriv;
1176 	struct sta_info *psta = rtw_get_stainfo(pstapriv, padapter->phl_role->mac_addr);
1177 
1178 	if (psta && psta->phl_sta) {
1179 		psta->phl_sta->asoc_cap.edca[ac].ac = ac;
1180 		psta->phl_sta->asoc_cap.edca[ac].param = parm;
1181 	}
1182 	rtw_hw_set_edca(padapter, ac, parm);
1183 }
1184 
rtw_set_hw_wmm_param(_adapter * padapter)1185 static void rtw_set_hw_wmm_param(_adapter *padapter)
1186 {
1187 	u8	AIFS, ECWMin, ECWMax, aSifsTime;
1188 	u8	acm_mask;
1189 	u16	TXOP;
1190 	u32	acParm, i;
1191 	u32	edca[4], inx[4];
1192 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1193 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1194 	struct xmit_priv		*pxmitpriv = &padapter->xmitpriv;
1195 	struct registry_priv	*pregpriv = &padapter->registrypriv;
1196 
1197 	acm_mask = 0;
1198 #ifdef CONFIG_80211N_HT
1199 	if (pregpriv->ht_enable &&
1200 		(WIFI_ROLE_IS_ON_5G(padapter) ||
1201 	    (pmlmeext->cur_wireless_mode & WLAN_MD_11N)))
1202 		aSifsTime = 16;
1203 	else
1204 #endif /* CONFIG_80211N_HT */
1205 		aSifsTime = 10;
1206 
1207 	if (pmlmeinfo->WMM_enable == 0) {
1208 		padapter->mlmepriv.acm_mask = 0;
1209 
1210 		AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
1211 
1212 		if (pmlmeext->cur_wireless_mode & (WLAN_MD_11G | WLAN_MD_11A)) {
1213 			ECWMin = 4;
1214 			ECWMax = 10;
1215 		} else if (pmlmeext->cur_wireless_mode & WLAN_MD_11B) {
1216 			ECWMin = 5;
1217 			ECWMax = 10;
1218 		} else {
1219 			ECWMin = 4;
1220 			ECWMax = 10;
1221 		}
1222 
1223 		TXOP = 0;
1224 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1225 		rtw_ap_set_edca(padapter, 0, acParm);
1226 		rtw_ap_set_edca(padapter, 1, acParm);
1227 		rtw_ap_set_edca(padapter, 2, acParm);
1228 
1229 		ECWMin = 2;
1230 		ECWMax = 3;
1231 		TXOP = 0x2f;
1232 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1233 		rtw_ap_set_edca(padapter, 3, acParm);
1234 
1235 	} else {
1236 		edca[0] = edca[1] = edca[2] = edca[3] = 0;
1237 
1238 		/*TODO:*/
1239 		acm_mask = 0;
1240 		padapter->mlmepriv.acm_mask = acm_mask;
1241 
1242 #if 0
1243 		/* BK */
1244 		/* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
1245 #endif
1246 		AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
1247 		ECWMin = 4;
1248 		ECWMax = 10;
1249 		TXOP = 0;
1250 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1251 		rtw_ap_set_edca(padapter, 1, acParm);
1252 		edca[XMIT_BK_QUEUE] = acParm;
1253 		RTW_INFO("WMM(BK): %x\n", acParm);
1254 
1255 		/* BE */
1256 		AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
1257 		ECWMin = 4;
1258 		ECWMax = 6;
1259 		TXOP = 0;
1260 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1261 		rtw_ap_set_edca(padapter, 0, acParm);
1262 		edca[XMIT_BE_QUEUE] = acParm;
1263 		RTW_INFO("WMM(BE): %x\n", acParm);
1264 
1265 		/* VI */
1266 		AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1267 		ECWMin = 3;
1268 		ECWMax = 4;
1269 		TXOP = 94;
1270 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1271 		rtw_ap_set_edca(padapter, 2, acParm);
1272 		edca[XMIT_VI_QUEUE] = acParm;
1273 		RTW_INFO("WMM(VI): %x\n", acParm);
1274 
1275 		/* VO */
1276 		AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1277 		ECWMin = 2;
1278 		ECWMax = 3;
1279 		TXOP = 47;
1280 		acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1281 		rtw_ap_set_edca(padapter, 3, acParm);
1282 		edca[XMIT_VO_QUEUE] = acParm;
1283 		RTW_INFO("WMM(VO): %x\n", acParm);
1284 
1285 
1286 		if (padapter->registrypriv.acm_method == 1)
1287 			rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
1288 		else
1289 			padapter->mlmepriv.acm_mask = acm_mask;
1290 
1291 		inx[0] = 0;
1292 		inx[1] = 1;
1293 		inx[2] = 2;
1294 		inx[3] = 3;
1295 
1296 		if (pregpriv->wifi_spec == 1) {
1297 			u32	j, tmp, change_inx = _FALSE;
1298 
1299 			/* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
1300 			for (i = 0 ; i < 4 ; i++) {
1301 				for (j = i + 1 ; j < 4 ; j++) {
1302 					/* compare CW and AIFS */
1303 					if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
1304 						change_inx = _TRUE;
1305 					else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
1306 						/* compare TXOP */
1307 						if ((edca[j] >> 16) > (edca[i] >> 16))
1308 							change_inx = _TRUE;
1309 					}
1310 
1311 					if (change_inx) {
1312 						tmp = edca[i];
1313 						edca[i] = edca[j];
1314 						edca[j] = tmp;
1315 
1316 						tmp = inx[i];
1317 						inx[i] = inx[j];
1318 						inx[j] = tmp;
1319 
1320 						change_inx = _FALSE;
1321 					}
1322 				}
1323 			}
1324 		}
1325 
1326 		for (i = 0 ; i < 4 ; i++) {
1327 			pxmitpriv->wmm_para_seq[i] = inx[i];
1328 			RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
1329 		}
1330 
1331 	}
1332 
1333 }
1334 #ifdef CONFIG_80211N_HT
update_hw_ht_param(_adapter * padapter)1335 static void update_hw_ht_param(_adapter *padapter)
1336 {
1337 	unsigned char		max_AMPDU_len;
1338 	unsigned char		min_MPDU_spacing;
1339 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
1340 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1341 
1342 	RTW_INFO("%s\n", __FUNCTION__);
1343 
1344 
1345 	/* handle A-MPDU parameter field */
1346 	/*
1347 		AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
1348 		AMPDU_para [4:2]:Min MPDU Start Spacing
1349 	*/
1350 	max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
1351 
1352 	min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
1353 
1354 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
1355 
1356 	rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
1357 
1358 	/*  */
1359 	/* Config SM Power Save setting */
1360 	/*  */
1361 	pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
1362 	if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
1363 #if 0
1364 		u8 i;
1365 		/* update the MCS rates */
1366 		for (i = 0; i < 16; i++)
1367 			pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
1368 #endif
1369 		RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
1370 	}
1371 
1372 	/*  */
1373 	/* Config current HT Protection mode. */
1374 	/*  */
1375 	/* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
1376 
1377 }
1378 #endif /* CONFIG_80211N_HT */
rtw_ap_check_scan(_adapter * padapter)1379 static void rtw_ap_check_scan(_adapter *padapter)
1380 {
1381 	_list		*plist, *phead;
1382 	u32	delta_time, lifetime;
1383 	struct	wlan_network	*pnetwork = NULL;
1384 	WLAN_BSSID_EX *pbss = NULL;
1385 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1386 	_queue	*queue	= &(pmlmepriv->scanned_queue);
1387 	u8 do_scan = _FALSE;
1388 	u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
1389 
1390 	lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
1391 
1392 	_rtw_spinlock_bh(&(pmlmepriv->scanned_queue.lock));
1393 	phead = get_list_head(queue);
1394 	if (rtw_end_of_queue_search(phead, get_next(phead)) == _TRUE)
1395 		if (padapter->registrypriv.wifi_spec) {
1396 			do_scan = _TRUE;
1397 			reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
1398 		}
1399 	_rtw_spinunlock_bh(&(pmlmepriv->scanned_queue.lock));
1400 
1401 #if defined(CONFIG_RTW_ACS) && defined(WKARD_ACS)
1402 	if (padapter->registrypriv.acs_auto_scan) {
1403 		do_scan = _TRUE;
1404 		reason |= RTW_AUTO_SCAN_REASON_ACS;
1405 		rtw_acs_start(padapter);
1406 	}
1407 #endif/*CONFIG_RTW_ACS*/
1408 
1409 	if (_TRUE == do_scan) {
1410 		RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
1411 		rtw_drv_scan_by_self(padapter, reason);
1412 		rtw_scan_abort(padapter, 0);
1413 	}
1414 
1415 #if defined(CONFIG_RTW_ACS) && defined(WKARD_ACS)
1416 	if (padapter->registrypriv.acs_auto_scan)
1417 		rtw_acs_stop(padapter);
1418 #endif
1419 
1420 	_rtw_spinlock_bh(&(pmlmepriv->scanned_queue.lock));
1421 
1422 	phead = get_list_head(queue);
1423 	plist = get_next(phead);
1424 
1425 	while (1) {
1426 
1427 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
1428 			break;
1429 
1430 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
1431 
1432 		if (rtw_chset_search_ch(adapter_to_chset(padapter), pnetwork->network.Configuration.DSConfig) >= 0
1433 		    && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == _TRUE
1434 		    && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))) {
1435 			delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
1436 
1437 			if (delta_time < lifetime) {
1438 
1439 				uint ie_len = 0;
1440 				u8 *pbuf = NULL;
1441 				u8 *ie = NULL;
1442 
1443 				pbss = &pnetwork->network;
1444 				ie = pbss->IEs;
1445 
1446 				/*check if HT CAP INFO IE exists or not*/
1447 				pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
1448 				if (pbuf == NULL) {
1449 					/* HT CAP INFO IE don't exist, it is b/g mode bss.*/
1450 
1451 					if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc))
1452 						ATOMIC_SET(&pmlmepriv->olbc, _TRUE);
1453 
1454 					if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc_ht))
1455 						ATOMIC_SET(&pmlmepriv->olbc_ht, _TRUE);
1456 
1457 					if (padapter->registrypriv.wifi_spec)
1458 						RTW_INFO("%s: %s is a/b/g ap\n", __func__, pnetwork->network.Ssid.Ssid);
1459 				}
1460 			}
1461 		}
1462 
1463 		plist = get_next(plist);
1464 
1465 	}
1466 
1467 	_rtw_spinunlock_bh(&(pmlmepriv->scanned_queue.lock));
1468 #ifdef CONFIG_80211N_HT
1469 	pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
1470 #endif
1471 }
1472 
rtw_start_bss_hdl_after_chbw_decided(_adapter * adapter)1473 void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
1474 {
1475 	WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
1476 	struct sta_info *sta = NULL;
1477 
1478 	/* update cur_wireless_mode */
1479 	update_wireless_mode(adapter);
1480 
1481 	/* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
1482 	UpdateBrateTbl(adapter, pnetwork->SupportedRates);
1483 	rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
1484 
1485 	/* update capability after cur_wireless_mode updated */
1486 	update_capinfo(adapter, rtw_get_capability(pnetwork));
1487 
1488 	/* update AP's sta info */
1489 	sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
1490 	if (!sta) {
1491 		RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
1492 		rtw_warn_on(1);
1493 		return;
1494 	}
1495 
1496 	update_ap_info(adapter, sta);
1497 }
1498 
_rtw_iface_undersurvey_chk(const char * func,_adapter * adapter)1499 static void _rtw_iface_undersurvey_chk(const char *func, _adapter *adapter)
1500 {
1501 	int i;
1502 	_adapter *iface;
1503 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
1504 	struct mlme_priv *pmlmepriv;
1505 
1506 	for (i = 0; i < dvobj->iface_nums; i++) {
1507 		iface = dvobj->padapters[i];
1508 		if ((iface) && rtw_is_adapter_up(iface)) {
1509 			pmlmepriv = &iface->mlmepriv;
1510 			if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY))
1511 				RTW_ERR("%s ("ADPT_FMT") under survey\n", func, ADPT_ARG(iface));
1512 		}
1513 	}
1514 }
1515 
rtw_core_ap_swch_start(_adapter * padapter,struct createbss_parm * parm)1516 void rtw_core_ap_swch_start(_adapter *padapter, struct createbss_parm *parm)
1517 {
1518 	struct dvobj_priv *pdvobj = padapter->dvobj;
1519 	int i;
1520 	u8 ht_option = 0;
1521 	RTW_INFO("%s\n", __func__);
1522 
1523 	if (!IS_CH_WAITING(adapter_to_rfctl(padapter)))
1524 		parm->do_rfk = _TRUE;
1525 
1526 	if (parm->ch_to_set != 0) {
1527 		set_channel_bwmode(padapter, parm->ch_to_set, parm->offset_to_set, parm->bw_to_set, parm->do_rfk);
1528 		rtw_phl_mr_dump_cur_chandef(adapter_to_dvobj(padapter)->phl, padapter->phl_role);
1529 	}
1530 
1531 #if defined(CONFIG_IOCTL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
1532 	for (i = 0; i < pdvobj->iface_nums; i++) {
1533 		if (!(parm->ifbmp_ch_changed & BIT(i)) || !pdvobj->padapters[i])
1534 			continue;
1535 
1536 		#ifdef CONFIG_80211N_HT
1537 		ht_option = pdvobj->padapters[i]->mlmepriv.htpriv.ht_option;
1538 		#endif
1539 
1540 		rtw_cfg80211_ch_switch_notify(pdvobj->padapters[i]
1541 			, pdvobj->padapters[i]->mlmeextpriv.chandef.chan
1542 			, pdvobj->padapters[i]->mlmeextpriv.chandef.bw
1543 			, pdvobj->padapters[i]->mlmeextpriv.chandef.offset
1544 			, ht_option, 0);
1545 
1546 	}
1547 #endif /* defined(CONFIG_IOCTL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) */
1548 	rtw_rfctl_update_op_mode(adapter_to_rfctl(padapter), parm->ifbmp, 1);
1549 }
1550 
rtw_core_ap_start(_adapter * padapter,struct createbss_parm * parm)1551 void rtw_core_ap_start(_adapter *padapter, struct createbss_parm *parm)
1552 {
1553 #define DUMP_ADAPTERS_STATUS 0
1554 		struct dvobj_priv *pdvobj = padapter->dvobj;
1555 		int i;
1556 		RTW_INFO("%s\n", __func__);
1557 		if (DUMP_ADAPTERS_STATUS) {
1558 			RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
1559 			dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
1560 		}
1561 
1562 		for (i = 0; i < pdvobj->iface_nums; i++) {
1563 			struct mlme_priv *mlme;
1564 
1565 			if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
1566 				continue;
1567 
1568 			/* update beacon content only if bstart_bss is _TRUE */
1569 			if (pdvobj->padapters[i]->mlmeextpriv.bstart_bss != _TRUE)
1570 				continue;
1571 
1572 			mlme = &(pdvobj->padapters[i]->mlmepriv);
1573 
1574 			#ifdef CONFIG_80211N_HT
1575 			if ((ATOMIC_READ(&mlme->olbc) == _TRUE) || (ATOMIC_READ(&mlme->olbc_ht) == _TRUE)) {
1576 				/* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
1577 				mlme->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
1578 				mlme->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
1579 				rtw_update_beacon(pdvobj->padapters[i], _HT_ADD_INFO_IE_, NULL, _FALSE, 0);
1580             }
1581 			#endif
1582 
1583 			rtw_update_beacon(pdvobj->padapters[i], _TIM_IE_, NULL, _FALSE, 0);
1584 		}
1585 
1586 		/* after chanctx_add & before send bcn */
1587 #ifndef CONFIG_AP_CMD_DISPR
1588 		rtw_hw_start_bss_network(padapter);
1589 #endif
1590 
1591 		rtw_scan_abort(padapter, 0);
1592 
1593 		_rtw_iface_undersurvey_chk(__func__, padapter);
1594 		/* send beacon */
1595 		rtw_hal_set_hwreg(padapter, HW_VAR_RESUME_BCN, NULL);
1596 		{
1597 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_PCI_BCN_POLLING) || defined(CONFIG_HWSIM)
1598 
1599 		for (i = 0; i < pdvobj->iface_nums; i++) {
1600 			if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
1601 				continue;
1602 
1603 			if (send_beacon(pdvobj->padapters[i]) == _FAIL)
1604 				RTW_INFO(ADPT_FMT" issue_beacon, fail!\n", ADPT_ARG(pdvobj->padapters[i]));
1605 			}
1606 #endif
1607 		}
1608 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
1609 		if (MLME_IS_AP(padapter) && padapter->tbtx_capability == _TRUE) {
1610 			_set_timer(&pmlmeext->tbtx_token_dispatch_timer, 1);
1611 			RTW_INFO("Start token dispatch\n");
1612 		}
1613 #endif
1614 }
1615 
start_bss_network(_adapter * padapter,struct createbss_parm * parm)1616 void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
1617 {
1618 #define DUMP_ADAPTERS_STATUS 0
1619 	u8 mlme_act = MLME_ACTION_UNKNOWN;
1620 	u16 bcn_interval;
1621 	u32	acparm;
1622 	struct registry_priv	*pregpriv = &padapter->registrypriv;
1623 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1624 	struct security_priv *psecuritypriv = &(padapter->securitypriv);
1625 	WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
1626 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
1627 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1628 	WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
1629 	struct dvobj_priv *pdvobj = padapter->dvobj;
1630 	s16 req_ch = REQ_CH_NONE, req_bw = REQ_BW_NONE, req_offset = REQ_OFFSET_NONE;
1631 	struct rtw_chan_def chdef_to_set = {0};
1632 	u8 do_rfk = _FALSE;
1633 	int i;
1634 	u8 ifbmp_ch_changed = 0;
1635 #ifdef CONFIG_MCC_MODE
1636 	struct rtw_phl_com_t *phl_com = GET_PHL_COM(pdvobj);
1637 	u8 mcc_sup = phl_com->dev_cap.mcc_sup;
1638 #endif
1639 	if (parm->req_ch != 0) {
1640 		/* bypass other setting, go checking ch, bw, offset */
1641 		mlme_act = MLME_OPCH_SWITCH;
1642 		req_ch = parm->req_ch;
1643 		req_bw = parm->req_bw;
1644 		req_offset = parm->req_offset;
1645 		goto chbw_decision;
1646 	} else {
1647 		/* request comes from upper layer */
1648 		if (MLME_IS_AP(padapter))
1649 			mlme_act = MLME_AP_STARTED;
1650 		else if (MLME_IS_MESH(padapter))
1651 			mlme_act = MLME_MESH_STARTED;
1652 		else
1653 			rtw_warn_on(1);
1654 		req_ch = 0;
1655 		_rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
1656 	}
1657 
1658 	bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
1659 	pmlmeinfo->bcn_interval = bcn_interval;
1660 
1661 	/* check if there is wps ie, */
1662 	/* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
1663 	/* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
1664 	if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
1665 		pmlmeext->bstart_bss = _TRUE;
1666 
1667 	/* todo: update wmm, ht cap */
1668 	/* pmlmeinfo->WMM_enable; */
1669 	/* pmlmeinfo->HT_enable; */
1670 	if (pmlmepriv->qospriv.qos_option)
1671 		pmlmeinfo->WMM_enable = _TRUE;
1672 #ifdef CONFIG_80211N_HT
1673 	if (pmlmepriv->htpriv.ht_option) {
1674 		pmlmeinfo->WMM_enable = _TRUE;
1675 		pmlmeinfo->HT_enable = _TRUE;
1676 		/* pmlmeinfo->HT_info_enable = _TRUE; */
1677 		/* pmlmeinfo->HT_caps_enable = _TRUE; */
1678 
1679 		update_hw_ht_param(padapter);
1680 	} else
1681 		pmlmeinfo->HT_enable = _FALSE;
1682 #endif /* #CONFIG_80211N_HT */
1683 
1684 #ifdef CONFIG_80211AC_VHT
1685 	if (pmlmepriv->vhtpriv.vht_option) {
1686 		pmlmeinfo->VHT_enable = _TRUE;
1687 		update_hw_vht_param(padapter);
1688 	} else
1689 		pmlmeinfo->VHT_enable = _FALSE;
1690 #endif /* CONFIG_80211AC_VHT */
1691 
1692 #ifdef CONFIG_80211AX_HE
1693 	if (pmlmepriv->hepriv.he_option) {
1694 		pmlmeinfo->HE_enable = _TRUE;
1695 		update_hw_he_param(padapter);
1696 	} else
1697 		pmlmeinfo->HE_enable = _FALSE;
1698 #endif /* CONFIG_80211AX_HE */
1699 
1700 	if (pmlmepriv->cur_network.join_res != _TRUE) { /* setting only at  first time */
1701 		/* WEP Key will be set before this function, do not clear CAM. */
1702 		if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
1703 			&& !MLME_IS_MESH(padapter) /* mesh group key is set before this function */
1704 		)
1705 			flush_all_cam_entry(padapter, PHL_CMD_DIRECTLY, 0);	/* clear CAM */
1706 	}
1707 
1708 #ifdef CONFIG_RTW_MULTI_AP
1709 	rtw_map_config_monitor(padapter, mlme_act);
1710 #endif
1711 
1712 chbw_decision:
1713 	ifbmp_ch_changed = rtw_ap_chbw_decision(padapter, parm->ifbmp, parm->excl_ifbmp
1714 						, req_ch, req_bw, req_offset, &chdef_to_set);
1715 
1716 	for (i = 0; i < pdvobj->iface_nums; i++) {
1717 		if (!(parm->ifbmp & BIT(i)) || !pdvobj->padapters[i])
1718 			continue;
1719 
1720 		/* let pnetwork_mlme == pnetwork_mlmeext */
1721 		_rtw_memcpy(&(pdvobj->padapters[i]->mlmepriv.cur_network.network)
1722 			, &(pdvobj->padapters[i]->mlmeextpriv.mlmext_info.network)
1723 			, pdvobj->padapters[i]->mlmeextpriv.mlmext_info.network.Length);
1724 
1725 		rtw_start_bss_hdl_after_chbw_decided(pdvobj->padapters[i]);
1726 
1727 		/* Set EDCA param reg after update cur_wireless_mode & update_capinfo */
1728 		if (pregpriv->wifi_spec == 1)
1729 			rtw_set_hw_wmm_param(pdvobj->padapters[i]);
1730 	}
1731 
1732 #if defined(CONFIG_DFS_MASTER)
1733 	rtw_dfs_rd_en_decision(padapter, mlme_act, parm->excl_ifbmp);
1734 #endif
1735 
1736 	{
1737 		u8 phl_uch = pmlmeext->chandef.chan;
1738 		enum channel_width phl_ubw = pmlmeext->chandef.bw;
1739 		enum chan_offset phl_uoffset = pmlmeext->chandef.offset;
1740 		bool is_chctx_add = false;
1741 		struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1742 
1743 		is_chctx_add = rtw_phl_chanctx_add(dvobj->phl, padapter->phl_role,
1744 		&phl_uch, &phl_ubw, &phl_uoffset);
1745 
1746 		rtw_hw_update_chan_def(padapter);
1747 		rtw_mi_update_union_chan_inf(padapter, phl_uch, phl_uoffset, phl_ubw);
1748 
1749 		RTW_INFO("%s => chctx_add:%s\n", __func__, (is_chctx_add) ? "Y" : "N");
1750 		RTW_INFO("Core - CH:%d, BW:%d OFF:%d\n", chdef_to_set.chan, chdef_to_set.bw, chdef_to_set.offset);
1751 		RTW_INFO("PHL- CH:%d, BW:%d OFF:%d\n",phl_uch, phl_ubw, phl_uoffset);
1752 	}
1753 
1754 
1755 	parm->ifbmp_ch_changed = ifbmp_ch_changed;
1756 	parm->ch_to_set = chdef_to_set.chan;
1757 	parm->offset_to_set = chdef_to_set.offset;
1758 	parm->bw_to_set = chdef_to_set.bw;
1759 	parm->do_rfk = do_rfk;
1760 
1761 }
1762 
rtw_check_beacon_data(_adapter * padapter,u8 * pbuf,int len)1763 int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf,  int len)
1764 {
1765 	int ret = _SUCCESS;
1766 	u8 *p;
1767 	u8 *pHT_caps_ie = NULL;
1768 	u8 *pHT_info_ie = NULL;
1769 	u16 cap, ht_cap = _FALSE;
1770 	uint ie_len = 0;
1771 	int group_cipher, pairwise_cipher, gmcs;
1772 	u32 akm;
1773 	u8 mfp_opt = MFP_NO;
1774 	u8	channel, network_type;
1775 	u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
1776 	u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
1777 	u8 WIFI_ALLIANCE_OUI[] = {0x50, 0x6f, 0x9a};
1778 	HT_CAP_AMPDU_DENSITY best_ampdu_density = 0;
1779 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
1780 	struct security_priv *psecuritypriv = &padapter->securitypriv;
1781 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1782 	WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
1783 	u8 *ie = pbss_network->IEs;
1784 	u8 vht_cap = _FALSE;
1785 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
1786 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
1787 	struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
1788 	u8 rf_num = 0;
1789 	int ret_rm;
1790 	/* SSID */
1791 	/* Supported rates */
1792 	/* DS Params */
1793 	/* WLAN_EID_COUNTRY */
1794 	/* ERP Information element */
1795 	/* Extended supported rates */
1796 	/* WPA/WPA2 */
1797 	/* Radio Resource Management */
1798 	/* Wi-Fi Wireless Multimedia Extensions */
1799 	/* ht_capab, ht_oper */
1800 	/* WPS IE */
1801 
1802 	RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
1803 
1804 	if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
1805 		return _FAIL;
1806 
1807 
1808 	if (len > MAX_IE_SZ)
1809 		return _FAIL;
1810 
1811 	pbss_network->IELength = len;
1812 
1813 	_rtw_memset(ie, 0, MAX_IE_SZ);
1814 
1815 	_rtw_memcpy(ie, pbuf, pbss_network->IELength);
1816 
1817 
1818 	if (pbss_network->InfrastructureMode != Ndis802_11APMode
1819 		&& pbss_network->InfrastructureMode != Ndis802_11_mesh
1820 	) {
1821 		rtw_warn_on(1);
1822 		return _FAIL;
1823 	}
1824 
1825 
1826 	rtw_ap_check_scan(padapter);
1827 
1828 
1829 	pbss_network->PhyInfo.rssi= 0;
1830 
1831 	_rtw_memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
1832 
1833 	/* beacon interval */
1834 	p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8;	 */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1835 	/* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
1836 	pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
1837 
1838 	/* capability */
1839 	p = rtw_get_capability_from_ie(ie);
1840 	cap = RTW_GET_LE16(p);
1841 
1842 	/* SSID */
1843 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1844 	if (p && ie_len > 0) {
1845 		_rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
1846 		_rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
1847 		pbss_network->Ssid.SsidLength = ie_len;
1848 	}
1849 
1850 #ifdef CONFIG_RTW_MESH
1851 	/* Mesh ID */
1852 	if (MLME_IS_MESH(padapter)) {
1853 		p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, WLAN_EID_MESH_ID, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1854 		if (p && ie_len > 0) {
1855 			_rtw_memset(&pbss_network->mesh_id, 0, sizeof(NDIS_802_11_SSID));
1856 			_rtw_memcpy(pbss_network->mesh_id.Ssid, (p + 2), ie_len);
1857 			pbss_network->mesh_id.SsidLength = ie_len;
1858 		}
1859 	}
1860 #endif
1861 
1862 	/* Parsing extended capabilities IE */
1863 	rtw_parse_ext_cap_ie(pmlmepriv->ext_capab_ie_data, &(pmlmepriv->ext_capab_ie_len), ie \
1864 		, pbss_network->IELength, _BEACON_IE_OFFSET_);
1865 
1866 	/* chnnel */
1867 	channel = 0;
1868 	pbss_network->Configuration.Length = 0;
1869 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1870 	if (p && ie_len > 0)
1871 		channel = *(p + 2);
1872 
1873 	pbss_network->Configuration.DSConfig = channel;
1874 
1875 	/*	support rate ie & ext support ie & IElen & SupportedRates	*/
1876 	network_type = rtw_update_rate_bymode(pbss_network, pregistrypriv->wireless_mode);
1877 
1878 	/* parsing ERP_IE */
1879 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1880 	if (p && ie_len > 0)  {
1881 		if(padapter->registrypriv.wireless_mode == WLAN_MD_11B) {
1882 
1883 			pbss_network->IELength = pbss_network->IELength - *(p+1) - 2;
1884 			ret_rm = rtw_ies_remove_ie(ie , &len, _BEACON_IE_OFFSET_, _ERPINFO_IE_,NULL,0);
1885 			RTW_DBG("%s, remove_ie of ERP_IE=%d\n", __FUNCTION__, ret_rm);
1886 		} else
1887 			ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
1888 
1889 	}
1890 
1891 	/* update privacy/security */
1892 	if (cap & BIT(4))
1893 		pbss_network->Privacy = 1;
1894 	else
1895 		pbss_network->Privacy = 0;
1896 
1897 	psecuritypriv->wpa_psk = 0;
1898 
1899 	/* wpa2 */
1900 	akm = 0;
1901 	gmcs = 0;
1902 	group_cipher = 0;
1903 	pairwise_cipher = 0;
1904 	psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1905 	psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1906 	psecuritypriv->akmp = 0;
1907 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1908 	if (p && ie_len > 0) {
1909 		if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, &gmcs, &akm, &mfp_opt, NULL) == _SUCCESS) {
1910 			psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1911 			psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
1912 			psecuritypriv->dot8021xalg = 1;/* psk,  todo:802.1x */
1913 			psecuritypriv->wpa_psk |= BIT(1);
1914 
1915 			psecuritypriv->wpa2_group_cipher = group_cipher;
1916 			psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
1917 			psecuritypriv->akmp = akm;
1918 
1919 #ifdef CONFIG_IOCTL_CFG80211
1920 			/**
1921 			 * Kernel < v5.x, the auth_type set as
1922 			 * NL80211_AUTHTYPE_AUTOMATIC in
1923 			 * cfg80211_rtw_start_ap(). if the AKM SAE in the RSN
1924 			 * IE, we have to update the auth_type for SAE in
1925 			 * rtw_check_beacon_data()
1926 			 */
1927 			if (CHECK_BIT(WLAN_AKM_TYPE_SAE, akm)) {
1928 				RTW_INFO("%s: Auth type as SAE\n", __func__);
1929 				psecuritypriv->auth_type = MLME_AUTHTYPE_SAE;
1930 				psecuritypriv->auth_alg = WLAN_AUTH_SAE;
1931 			}
1932 #endif /* CONFIG_IOCTL_CFG80211 */
1933 #if 0
1934 			switch (group_cipher) {
1935 			case WPA_CIPHER_NONE:
1936 				psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1937 				break;
1938 			case WPA_CIPHER_WEP40:
1939 				psecuritypriv->wpa2_group_cipher = _WEP40_;
1940 				break;
1941 			case WPA_CIPHER_TKIP:
1942 				psecuritypriv->wpa2_group_cipher = _TKIP_;
1943 				break;
1944 			case WPA_CIPHER_CCMP:
1945 				psecuritypriv->wpa2_group_cipher = _AES_;
1946 				break;
1947 			case WPA_CIPHER_WEP104:
1948 				psecuritypriv->wpa2_group_cipher = _WEP104_;
1949 				break;
1950 			}
1951 
1952 			switch (pairwise_cipher) {
1953 			case WPA_CIPHER_NONE:
1954 				psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1955 				break;
1956 			case WPA_CIPHER_WEP40:
1957 				psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
1958 				break;
1959 			case WPA_CIPHER_TKIP:
1960 				psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
1961 				break;
1962 			case WPA_CIPHER_CCMP:
1963 				psecuritypriv->wpa2_pairwise_cipher = _AES_;
1964 				break;
1965 			case WPA_CIPHER_WEP104:
1966 				psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
1967 				break;
1968 			}
1969 #endif
1970 		}
1971 
1972 	}
1973 
1974 	/* wpa */
1975 	ie_len = 0;
1976 	group_cipher = 0;
1977 	pairwise_cipher = 0;
1978 	psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1979 	psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1980 	for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1981 		p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
1982 		if ((p) && (_rtw_memcmp(p + 2, OUI1, 4))) {
1983 			if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1984 				psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1985 				psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
1986 				psecuritypriv->dot8021xalg = 1;/* psk,  todo:802.1x */
1987 
1988 				psecuritypriv->wpa_psk |= BIT(0);
1989 
1990 				psecuritypriv->wpa_group_cipher = group_cipher;
1991 				psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
1992 
1993 #if 0
1994 				switch (group_cipher) {
1995 				case WPA_CIPHER_NONE:
1996 					psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1997 					break;
1998 				case WPA_CIPHER_WEP40:
1999 					psecuritypriv->wpa_group_cipher = _WEP40_;
2000 					break;
2001 				case WPA_CIPHER_TKIP:
2002 					psecuritypriv->wpa_group_cipher = _TKIP_;
2003 					break;
2004 				case WPA_CIPHER_CCMP:
2005 					psecuritypriv->wpa_group_cipher = _AES_;
2006 					break;
2007 				case WPA_CIPHER_WEP104:
2008 					psecuritypriv->wpa_group_cipher = _WEP104_;
2009 					break;
2010 				}
2011 
2012 				switch (pairwise_cipher) {
2013 				case WPA_CIPHER_NONE:
2014 					psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
2015 					break;
2016 				case WPA_CIPHER_WEP40:
2017 					psecuritypriv->wpa_pairwise_cipher = _WEP40_;
2018 					break;
2019 				case WPA_CIPHER_TKIP:
2020 					psecuritypriv->wpa_pairwise_cipher = _TKIP_;
2021 					break;
2022 				case WPA_CIPHER_CCMP:
2023 					psecuritypriv->wpa_pairwise_cipher = _AES_;
2024 					break;
2025 				case WPA_CIPHER_WEP104:
2026 					psecuritypriv->wpa_pairwise_cipher = _WEP104_;
2027 					break;
2028 				}
2029 #endif
2030 			}
2031 
2032 			break;
2033 
2034 		}
2035 
2036 		if ((p == NULL) || (ie_len == 0))
2037 			break;
2038 
2039 	}
2040 
2041 	if (mfp_opt == MFP_INVALID) {
2042 		RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
2043 		return _FAIL;
2044 	}
2045 	psecuritypriv->mfp_opt = mfp_opt;
2046 
2047 	/* RRM */
2048 	rm_update_cap(pbuf, padapter, len, _BEACON_IE_OFFSET_);
2049 
2050 	/* wmm */
2051 	ie_len = 0;
2052 	pmlmepriv->qospriv.qos_option = 0;
2053 #ifdef CONFIG_RTW_MESH
2054 	if (MLME_IS_MESH(padapter))
2055 		pmlmepriv->qospriv.qos_option = 1;
2056 #endif
2057 	if (pregistrypriv->wmm_enable) {
2058 		for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
2059 			p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
2060 			if ((p) && _rtw_memcmp(p + 2, WMM_PARA_IE, 6)) {
2061 				pmlmepriv->qospriv.qos_option = 1;
2062 
2063 				*(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
2064 
2065 				/* disable all ACM bits since the WMM admission control is not supported */
2066 				*(p + 10) &= ~BIT(4); /* BE */
2067 				*(p + 14) &= ~BIT(4); /* BK */
2068 				*(p + 18) &= ~BIT(4); /* VI */
2069 				*(p + 22) &= ~BIT(4); /* VO */
2070 
2071 				WMM_param_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
2072 
2073 				break;
2074 			}
2075 
2076 			if ((p == NULL) || (ie_len == 0))
2077 				break;
2078 		}
2079 	}
2080 #ifdef CONFIG_80211N_HT
2081 	if(padapter->registrypriv.ht_enable &&
2082 		is_supported_ht(padapter->registrypriv.wireless_mode)) {
2083 		/* parsing HT_CAP_IE */
2084 		p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2085 		if (p && ie_len > 0) {
2086 			HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
2087 			struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
2088 
2089 			if (0) {
2090 				RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
2091 				dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
2092 			}
2093 
2094 			pHT_caps_ie = p;
2095 
2096 			ht_cap = _TRUE;
2097 			network_type |= WLAN_MD_11N;
2098 
2099 			rtw_ht_use_default_setting(padapter);
2100 
2101 			/* Update HT Capabilities Info field */
2102 			if (pmlmepriv->htpriv.sgi_20m == _FALSE)
2103 				pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_20);
2104 
2105 			if (pmlmepriv->htpriv.sgi_40m == _FALSE)
2106 				pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_40);
2107 
2108 			if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
2109 				pht_cap->cap_info &= ~(IEEE80211_HT_CAP_LDPC_CODING);
2110 
2111 			if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
2112 				pht_cap->cap_info &= ~(IEEE80211_HT_CAP_TX_STBC);
2113 
2114 			if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
2115 				pht_cap->cap_info &= ~(IEEE80211_HT_CAP_RX_STBC_3R);
2116 
2117 			/* Update A-MPDU Parameters field */
2118 			pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
2119 
2120 			if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
2121 				(psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) {
2122 				rtw_hal_get_def_var(padapter, HW_VAR_BEST_AMPDU_DENSITY, &best_ampdu_density);
2123 				pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (best_ampdu_density << 2));
2124 			} else
2125 				pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
2126 
2127 			rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
2128 			pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set  Max Rx AMPDU size  to 64K */
2129 
2130 			_rtw_memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
2131 
2132 			/* Update Supported MCS Set field */
2133 			{
2134 				u8 rx_nss = 0;
2135 				int i;
2136 
2137 				rx_nss = get_phy_rx_nss(padapter);
2138 
2139 				/* RX MCS Bitmask */
2140 				switch (rx_nss) {
2141 				case 1:
2142 					set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
2143 					break;
2144 				case 2:
2145 					set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
2146 					break;
2147 				case 3:
2148 					set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
2149 					break;
2150 				case 4:
2151 					set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_4R);
2152 					break;
2153 				default:
2154 					RTW_WARN("rf_type:%d or rx_nss:%u is not expected\n",
2155 						GET_HAL_RFPATH(adapter_to_dvobj(padapter)), rx_nss);
2156 				}
2157 				for (i = 0; i < 10; i++)
2158 					*(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
2159 			}
2160 
2161 #ifdef CONFIG_BEAMFORMING
2162 			/* Use registry value to enable HT Beamforming. */
2163 			/* ToDo: use configure file to set these capability. */
2164 			pht_cap->tx_BF_cap_info = 0;
2165 
2166 			/* HT Beamformer */
2167 			if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
2168 				/* Transmit NDP Capable */
2169 				SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
2170 				/* Explicit Compressed Steering Capable */
2171 				SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
2172 				/* Compressed Steering Number Antennas */
2173 				SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
2174 				rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
2175 				if (rf_num > 3)
2176 					rf_num = 3;
2177 				SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
2178 			}
2179 
2180 			/* HT Beamformee */
2181 			if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
2182 				/* Receive NDP Capable */
2183 				SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
2184 				/* Explicit Compressed Beamforming Feedback Capable */
2185 				SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
2186 				rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
2187 				if (rf_num > 3)
2188 					rf_num = 3;
2189 				SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
2190 			}
2191 #endif /* CONFIG_BEAMFORMING */
2192 
2193 			_rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
2194 
2195 			if (0) {
2196 				RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
2197 				dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
2198 			}
2199 		}
2200 
2201 		/* parsing HT_INFO_IE */
2202 		p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2203 		if (p && ie_len > 0) {
2204 			pHT_info_ie = p;
2205 			if (channel == 0)
2206 				pbss_network->Configuration.DSConfig = GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2);
2207 			else if (channel != GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2)) {
2208 				RTW_INFO(FUNC_ADPT_FMT" ch inconsistent, DSSS:%u, HT primary:%u\n"
2209 					, FUNC_ADPT_ARG(padapter), channel, GET_HT_OP_ELE_PRI_CHL(pHT_info_ie + 2));
2210 			}
2211 		}
2212 	}
2213 #endif /* CONFIG_80211N_HT */
2214 	pmlmepriv->cur_network.network_type = network_type;
2215 
2216 #ifdef CONFIG_80211N_HT
2217 	pmlmepriv->htpriv.ht_option = _FALSE;
2218 
2219 	if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
2220 	    (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
2221 		/* todo: */
2222 		/* ht_cap = _FALSE; */
2223 	}
2224 
2225 	/* ht_cap	 */
2226 	if (padapter->registrypriv.ht_enable &&
2227 		is_supported_ht(padapter->registrypriv.wireless_mode) && ht_cap == _TRUE) {
2228 
2229 		pmlmepriv->htpriv.ht_option = _TRUE;
2230 		pmlmepriv->qospriv.qos_option = 1;
2231 
2232 		pmlmepriv->htpriv.ampdu_enable = pregistrypriv->ampdu_enable ? _TRUE : _FALSE;
2233 
2234 		HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
2235 
2236 		HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
2237 	}
2238 #endif
2239 
2240 #ifdef CONFIG_80211AC_VHT
2241 	pmlmepriv->vhtpriv.upper_layer_setting = _FALSE;
2242 	pmlmepriv->vhtpriv.vht_option = _FALSE;
2243 
2244 	if (pmlmepriv->htpriv.ht_option == _TRUE
2245 		&& pbss_network->Configuration.DSConfig > 14
2246 		&& REGSTY_IS_11AC_ENABLE(pregistrypriv)
2247 		&& is_supported_vht(pregistrypriv->wireless_mode)
2248 		&& RFCTL_REG_EN_11AC(rfctl)
2249 	) {
2250 		/* Parsing VHT_CAP_IE */
2251 		p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability,
2252 			&ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2253 		if (p && ie_len > 0)
2254 			vht_cap = _TRUE;
2255 		else
2256 			RTW_INFO(FUNC_ADPT_FMT" No vht_capability_ie from hostapd/wpa_supplicant\n", FUNC_ADPT_ARG(padapter));
2257 
2258 		/* Update VHT related IEs */
2259 		if (vht_cap == _TRUE) {
2260 			RTW_INFO(FUNC_ADPT_FMT" VHT IEs is configured by hostapd/wpa_supplicant\n", FUNC_ADPT_ARG(padapter));
2261 			pmlmepriv->vhtpriv.upper_layer_setting = _TRUE;
2262 			pmlmepriv->vhtpriv.vht_option = _TRUE;
2263 
2264 			rtw_check_for_vht20(padapter, ie + _BEACON_IE_OFFSET_,
2265 					pbss_network->IELength - _BEACON_IE_OFFSET_);
2266 			rtw_check_vht_ies(padapter, pbss_network);
2267 		} else if (REGSTY_IS_11AC_AUTO(pregistrypriv)) {
2268 			rtw_vht_ies_detach(padapter, pbss_network);
2269 			rtw_vht_ies_attach(padapter, pbss_network);
2270 		}
2271 	}
2272 
2273 	if (pmlmepriv->vhtpriv.vht_option == _FALSE)
2274 		rtw_vht_ies_detach(padapter, pbss_network);
2275 #endif /* CONFIG_80211AC_VHT */
2276 
2277 #ifdef CONFIG_80211AX_HE
2278 	pmlmepriv->hepriv.he_option = _FALSE;
2279 
2280 	/* An HE STA is also a VHT STA if operating in the 5 GHz band */
2281 	/* An HE STA is also a HT STA in the 2GHz band */
2282 	if (REGSTY_IS_11AX_ENABLE(pregistrypriv)
2283 		&& is_supported_he(pregistrypriv->wireless_mode)
2284 		&& RFCTL_REG_EN_11AX(rfctl)
2285 		&& ((channel > 14 && pmlmepriv->vhtpriv.vht_option == _TRUE) ||
2286 		    (channel <= 14 && pmlmepriv->htpriv.ht_option == _TRUE))
2287 	) {
2288 		u8 he_cap = _FALSE;
2289 		u8 he_cap_eid_ext = WLAN_EID_EXTENSION_HE_CAPABILITY;
2290 
2291 		p = rtw_get_ie_ex(ie + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_,
2292 			WLAN_EID_EXTENSION, &he_cap_eid_ext, 1, NULL, &ie_len);
2293 		if (p && ie_len > 0)
2294 			he_cap = _TRUE;
2295 
2296 		/* If He capability is in beacon IE, enable he_option */
2297 		pmlmepriv->hepriv.he_option = he_cap;
2298 		rtw_he_use_default_setting(padapter);
2299 		if (REGSTY_IS_11AX_AUTO(pregistrypriv)) {
2300 			rtw_he_ies_detach(padapter, pbss_network);
2301 			rtw_he_ies_attach(padapter, pbss_network);
2302 		}
2303 	}
2304 	if (pmlmepriv->hepriv.he_option == _FALSE)
2305 		rtw_he_ies_detach(padapter, pbss_network);
2306 #endif
2307 
2308 #ifdef CONFIG_80211N_HT
2309 	if(padapter->registrypriv.ht_enable &&
2310 					is_supported_ht(padapter->registrypriv.wireless_mode) &&
2311 		pbss_network->Configuration.DSConfig <= 14 /*&& padapter->registrypriv.wifi_spec == 1*/) {
2312 
2313 	#ifdef CONFIG_RTW_WNM
2314 		rtw_wnm_add_btm_ext_cap(pmlmepriv->ext_capab_ie_data,
2315 				&(pmlmepriv->ext_capab_ie_len));
2316 	#endif
2317 	#ifdef CONFIG_RTW_MBO
2318 		rtw_mbo_add_internw_ext_cap(pmlmepriv->ext_capab_ie_data,
2319 				&(pmlmepriv->ext_capab_ie_len));
2320 	#endif
2321 		rtw_add_ext_cap_info(pmlmepriv->ext_capab_ie_data, &(pmlmepriv->ext_capab_ie_len), BSS_COEXT);
2322 		rtw_update_ext_cap_ie(pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len, pbss_network->IEs, \
2323 			&(pbss_network->IELength), _BEACON_IE_OFFSET_);
2324 	}
2325 #endif /* CONFIG_80211N_HT */
2326 
2327 #ifdef CONFIG_RTW_80211K
2328 	padapter->rmpriv.enable = _FALSE;
2329 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_RMEnabledCapability, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2330 	if (p && ie_len) {
2331 		RTW_INFO("[%s]Get EID_RMEnabledCapability, len = %d\n", __func__, ie_len);
2332 		padapter->rmpriv.enable = _TRUE;
2333 		_rtw_memcpy(padapter->rmpriv.rm_en_cap_def, p + 2, ie_len);
2334 	}
2335 #endif /* CONFIG_RTW_80211K */
2336 
2337 #ifdef CONFIG_RTW_MBO
2338 	ie_len = 0;
2339 	pmlmepriv->mbopriv.enable = _FALSE;
2340 	for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
2341 		p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
2342 		if ((p) && (_rtw_memcmp(p + 2, WIFI_ALLIANCE_OUI, 3)) && (*(p+5) == MBO_OUI_TYPE)) {
2343 			/* find MBO-OCE information element */
2344 			pmlmepriv->mbopriv.enable = _TRUE;
2345 			rtw_mbo_ie_handler(padapter, &pmlmepriv->mbopriv, p + 6, ie_len - 4);
2346 			break;
2347 		}
2348 		if ((p == NULL) || (ie_len == 0))
2349 			break;
2350 	}
2351 #endif /* CONFIG_RTW_MBO */
2352 
2353 	pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
2354 
2355 	rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
2356 		, &pmlmepriv->ori_chandef.chan, (u8 *)&pmlmepriv->ori_chandef.bw, (u8 *)&pmlmepriv->ori_chandef.offset, 1, 1);
2357 	rtw_warn_on(pmlmepriv->ori_chandef.chan == 0);
2358 
2359 	ret = rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
2360 	{
2361 		int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
2362 
2363 		if (sk_band)
2364 			RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
2365 	}
2366 
2367 	if (ret) {
2368 		rtw_indicate_connect(padapter);
2369 		pmlmepriv->cur_network.join_res = _TRUE;/* for check if already set beacon */
2370 	}
2371 
2372 	return ret;
2373 
2374 }
2375 
2376 #if CONFIG_RTW_MACADDR_ACL
rtw_macaddr_acl_init(_adapter * adapter,u8 period)2377 void rtw_macaddr_acl_init(_adapter *adapter, u8 period)
2378 {
2379 	struct sta_priv *stapriv = &adapter->stapriv;
2380 	struct wlan_acl_pool *acl;
2381 	_queue *acl_node_q;
2382 	int i;
2383 
2384 	if (period >= RTW_ACL_PERIOD_NUM) {
2385 		rtw_warn_on(1);
2386 		return;
2387 	}
2388 
2389 	acl = &stapriv->acl_list[period];
2390 	acl_node_q = &acl->acl_node_q;
2391 
2392 	_rtw_spinlock_init(&(acl_node_q->lock));
2393 
2394 	_rtw_spinlock_bh(&(acl_node_q->lock));
2395 	_rtw_init_listhead(&(acl_node_q->queue));
2396 	acl->num = 0;
2397 	acl->mode = RTW_ACL_MODE_DISABLED;
2398 	for (i = 0; i < NUM_ACL; i++) {
2399 		_rtw_init_listhead(&acl->aclnode[i].list);
2400 		acl->aclnode[i].valid = _FALSE;
2401 	}
2402 	_rtw_spinunlock_bh(&(acl_node_q->lock));
2403 }
2404 
_rtw_macaddr_acl_deinit(_adapter * adapter,u8 period,bool clear_only)2405 static void _rtw_macaddr_acl_deinit(_adapter *adapter, u8 period, bool clear_only)
2406 {
2407 	struct sta_priv *stapriv = &adapter->stapriv;
2408 	struct wlan_acl_pool *acl;
2409 	_queue *acl_node_q;
2410 	_list *head, *list;
2411 	struct rtw_wlan_acl_node *acl_node;
2412 
2413 	if (period >= RTW_ACL_PERIOD_NUM) {
2414 		rtw_warn_on(1);
2415 		return;
2416 	}
2417 
2418 	acl = &stapriv->acl_list[period];
2419 	acl_node_q = &acl->acl_node_q;
2420 
2421 	_rtw_spinlock_bh(&(acl_node_q->lock));
2422 	head = get_list_head(acl_node_q);
2423 	list = get_next(head);
2424 	while (rtw_end_of_queue_search(head, list) == _FALSE) {
2425 		acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2426 		list = get_next(list);
2427 
2428 		if (acl_node->valid == _TRUE) {
2429 			acl_node->valid = _FALSE;
2430 			rtw_list_delete(&acl_node->list);
2431 			acl->num--;
2432 		}
2433 	}
2434 	_rtw_spinunlock_bh(&(acl_node_q->lock));
2435 
2436 	if (!clear_only)
2437 		_rtw_spinlock_free(&(acl_node_q->lock));
2438 
2439 	rtw_warn_on(acl->num);
2440 	acl->mode = RTW_ACL_MODE_DISABLED;
2441 }
2442 
rtw_macaddr_acl_deinit(_adapter * adapter,u8 period)2443 void rtw_macaddr_acl_deinit(_adapter *adapter, u8 period)
2444 {
2445 	_rtw_macaddr_acl_deinit(adapter, period, 0);
2446 }
2447 
rtw_macaddr_acl_clear(_adapter * adapter,u8 period)2448 void rtw_macaddr_acl_clear(_adapter *adapter, u8 period)
2449 {
2450 	_rtw_macaddr_acl_deinit(adapter, period, 1);
2451 }
2452 
rtw_set_macaddr_acl(_adapter * adapter,u8 period,int mode)2453 void rtw_set_macaddr_acl(_adapter *adapter, u8 period, int mode)
2454 {
2455 	struct sta_priv *stapriv = &adapter->stapriv;
2456 	struct wlan_acl_pool *acl;
2457 
2458 	if (period >= RTW_ACL_PERIOD_NUM) {
2459 		rtw_warn_on(1);
2460 		return;
2461 	}
2462 
2463 	acl = &stapriv->acl_list[period];
2464 
2465 	RTW_INFO(FUNC_ADPT_FMT" p=%u, mode=%d\n"
2466 		, FUNC_ADPT_ARG(adapter), period, mode);
2467 
2468 	acl->mode = mode;
2469 }
2470 
rtw_acl_add_sta(_adapter * adapter,u8 period,const u8 * addr)2471 int rtw_acl_add_sta(_adapter *adapter, u8 period, const u8 *addr)
2472 {
2473 	_list *list, *head;
2474 	u8 existed = 0;
2475 	int i = -1, ret = 0;
2476 	struct rtw_wlan_acl_node *acl_node;
2477 	struct sta_priv *stapriv = &adapter->stapriv;
2478 	struct wlan_acl_pool *acl;
2479 	_queue *acl_node_q;
2480 
2481 	if (period >= RTW_ACL_PERIOD_NUM) {
2482 		rtw_warn_on(1);
2483 		ret = -1;
2484 		goto exit;
2485 	}
2486 
2487 	acl = &stapriv->acl_list[period];
2488 	acl_node_q = &acl->acl_node_q;
2489 
2490 	_rtw_spinlock_bh(&(acl_node_q->lock));
2491 
2492 	head = get_list_head(acl_node_q);
2493 	list = get_next(head);
2494 
2495 	/* search for existed entry */
2496 	while (rtw_end_of_queue_search(head, list) == _FALSE) {
2497 		acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2498 		list = get_next(list);
2499 
2500 		if (_rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2501 			if (acl_node->valid == _TRUE) {
2502 				existed = 1;
2503 				break;
2504 			}
2505 		}
2506 	}
2507 	if (existed)
2508 		goto release_lock;
2509 
2510 	if (acl->num >= NUM_ACL)
2511 		goto release_lock;
2512 
2513 	/* find empty one and use */
2514 	for (i = 0; i < NUM_ACL; i++) {
2515 
2516 		acl_node = &acl->aclnode[i];
2517 		if (acl_node->valid == _FALSE) {
2518 
2519 			_rtw_init_listhead(&acl_node->list);
2520 			_rtw_memcpy(acl_node->addr, addr, ETH_ALEN);
2521 			acl_node->valid = _TRUE;
2522 
2523 			rtw_list_insert_tail(&acl_node->list, get_list_head(acl_node_q));
2524 			acl->num++;
2525 			break;
2526 		}
2527 	}
2528 
2529 release_lock:
2530 	_rtw_spinunlock_bh(&(acl_node_q->lock));
2531 
2532 	if (!existed && (i < 0 || i >= NUM_ACL))
2533 		ret = -1;
2534 
2535 	RTW_INFO(FUNC_ADPT_FMT" p=%u "MAC_FMT" %s (acl_num=%d)\n"
2536 		 , FUNC_ADPT_ARG(adapter), period, MAC_ARG(addr)
2537 		, (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
2538 		 , acl->num);
2539 exit:
2540 	return ret;
2541 }
2542 
rtw_acl_remove_sta(_adapter * adapter,u8 period,const u8 * addr)2543 int rtw_acl_remove_sta(_adapter *adapter, u8 period, const u8 *addr)
2544 {
2545 	_list *list, *head;
2546 	int ret = 0;
2547 	struct rtw_wlan_acl_node *acl_node;
2548 	struct sta_priv *stapriv = &adapter->stapriv;
2549 	struct wlan_acl_pool *acl;
2550 	_queue	*acl_node_q;
2551 	u8 is_baddr = is_broadcast_mac_addr(addr);
2552 	u8 match = 0;
2553 
2554 	if (period >= RTW_ACL_PERIOD_NUM) {
2555 		rtw_warn_on(1);
2556 		goto exit;
2557 	}
2558 
2559 	acl = &stapriv->acl_list[period];
2560 	acl_node_q = &acl->acl_node_q;
2561 
2562 	_rtw_spinlock_bh(&(acl_node_q->lock));
2563 
2564 	head = get_list_head(acl_node_q);
2565 	list = get_next(head);
2566 
2567 	while (rtw_end_of_queue_search(head, list) == _FALSE) {
2568 		acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2569 		list = get_next(list);
2570 
2571 		if (is_baddr || _rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2572 			if (acl_node->valid == _TRUE) {
2573 				acl_node->valid = _FALSE;
2574 				rtw_list_delete(&acl_node->list);
2575 				acl->num--;
2576 				match = 1;
2577 			}
2578 		}
2579 	}
2580 
2581 	_rtw_spinunlock_bh(&(acl_node_q->lock));
2582 
2583 	RTW_INFO(FUNC_ADPT_FMT" p=%u "MAC_FMT" %s (acl_num=%d)\n"
2584 		 , FUNC_ADPT_ARG(adapter), period, MAC_ARG(addr)
2585 		 , is_baddr ? "clear all" : (match ? "match" : "no found")
2586 		 , acl->num);
2587 
2588 exit:
2589 	return ret;
2590 }
2591 #endif /* CONFIG_RTW_MACADDR_ACL */
2592 #ifdef CONFIG_CMD_DISP
rtw_ap_set_sta_key(_adapter * adapter,const u8 * addr,u8 alg,const u8 * key,u8 keyid,u8 gk)2593 u8 rtw_ap_set_sta_key(_adapter *adapter, const u8 *addr, u8 alg, const u8 *key, u8 keyid, u8 gk)
2594 {
2595 	struct set_stakey_parm param;
2596 	u8	res = _SUCCESS;
2597 
2598 	_rtw_memcpy(param.addr, addr, ETH_ALEN);
2599 	param.algorithm = alg;
2600 	param.keyid = keyid;
2601 	if (!!(alg & _SEC_TYPE_256_))
2602 		_rtw_memcpy(param.key, key, 32);
2603 	else
2604 		_rtw_memcpy(param.key, key, 16);
2605 	param.gk = gk;
2606 
2607 	set_stakey_hdl(adapter, &param, PHL_CMD_NO_WAIT, 0);
2608 exit:
2609 	return res;
2610 }
2611 
rtw_ap_set_pairwise_key(_adapter * padapter,struct sta_info * psta)2612 u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
2613 {
2614 	return rtw_ap_set_sta_key(padapter
2615 		, psta->phl_sta->mac_addr
2616 		, psta->dot118021XPrivacy
2617 		, psta->dot118021x_UncstKey.skey
2618 		, 0
2619 		, 0
2620 	);
2621 }
2622 
rtw_ap_set_key(_adapter * padapter,u8 * key,u8 alg,int keyid,u8 set_tx)2623 static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
2624 {
2625 	u8 keylen;
2626 	struct setkey_parm setkeyparm;
2627 	int res = _SUCCESS;
2628 
2629 	/* RTW_INFO("%s\n", __FUNCTION__); */
2630 
2631 	_rtw_memset(&setkeyparm, 0, sizeof(struct setkey_parm));
2632 
2633 	setkeyparm.keyid = (u8)keyid;
2634 	if (is_wep_enc(alg))
2635 		padapter->securitypriv.key_mask |= BIT(setkeyparm.keyid);
2636 
2637 	setkeyparm.algorithm = alg;
2638 
2639 	setkeyparm.set_tx = set_tx;
2640 
2641 	switch (alg) {
2642 	case _WEP40_:
2643 		keylen = 5;
2644 		break;
2645 	case _WEP104_:
2646 		keylen = 13;
2647 		break;
2648 	case _GCMP_256_:
2649 	case _CCMP_256_:
2650 		keylen = 32;
2651 		break;
2652 	case _TKIP_:
2653 	case _TKIP_WTMIC_:
2654 	case _AES_:
2655 	case _GCMP_:
2656 	#ifdef CONFIG_IEEE80211W
2657 	case _BIP_CMAC_128_:
2658 	#endif
2659 	default:
2660 		keylen = 16;
2661 	}
2662 
2663 	_rtw_memcpy(&(setkeyparm.key[0]), key, keylen);
2664 	setkey_hdl(padapter, &setkeyparm, PHL_CMD_NO_WAIT, 0);
2665 
2666 exit:
2667 	return res;
2668 }
2669 #else /* CONFIG_FSM */
rtw_ap_set_sta_key(_adapter * adapter,const u8 * addr,u8 alg,const u8 * key,u8 keyid,u8 gk)2670 u8 rtw_ap_set_sta_key(_adapter *adapter, const u8 *addr, u8 alg, const u8 *key, u8 keyid, u8 gk)
2671 {
2672 	struct cmd_priv *cmdpriv = &adapter_to_dvobj(adapter)->cmdpriv;
2673 	struct cmd_obj *cmd;
2674 	struct set_stakey_parm *param;
2675 	u8	res = _SUCCESS;
2676 
2677 	cmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2678 	if (cmd == NULL) {
2679 		res = _FAIL;
2680 		goto exit;
2681 	}
2682 	cmd->padapter = adapter;
2683 
2684 	param = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
2685 	if (param == NULL) {
2686 		rtw_mfree((u8 *) cmd, sizeof(struct cmd_obj));
2687 		res = _FAIL;
2688 		goto exit;
2689 	}
2690 
2691 	init_h2fwcmd_w_parm_no_rsp(cmd, param, CMD_SET_STAKEY);
2692 
2693 	_rtw_memcpy(param->addr, addr, ETH_ALEN);
2694 	param->algorithm = alg;
2695 	param->keyid = keyid;
2696 	if (!!(alg & _SEC_TYPE_256_))
2697 		_rtw_memcpy(param->key, key, 32);
2698 	else
2699 		_rtw_memcpy(param->key, key, 16);
2700 	param->gk = gk;
2701 
2702 	res = rtw_enqueue_cmd(cmdpriv, cmd);
2703 
2704 exit:
2705 	return res;
2706 }
2707 
rtw_ap_set_pairwise_key(_adapter * padapter,struct sta_info * psta)2708 u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
2709 {
2710 	return rtw_ap_set_sta_key(padapter
2711 		, psta->phl_sta->mac_addr
2712 		, psta->dot118021XPrivacy
2713 		, psta->dot118021x_UncstKey.skey
2714 		, 0
2715 		, 0
2716 	);
2717 }
2718 
rtw_ap_set_key(_adapter * padapter,u8 * key,u8 alg,int keyid,u8 set_tx)2719 static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
2720 {
2721 	u8 keylen;
2722 	struct cmd_obj *pcmd;
2723 	struct setkey_parm *psetkeyparm;
2724 	struct cmd_priv	*pcmdpriv = &(adapter_to_dvobj(padapter)->cmdpriv);
2725 	int res = _SUCCESS;
2726 
2727 	/* RTW_INFO("%s\n", __FUNCTION__); */
2728 
2729 	pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2730 	if (pcmd == NULL) {
2731 		res = _FAIL;
2732 		goto exit;
2733 	}
2734 	pcmd->padapter = padapter;
2735 
2736 	psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
2737 	if (psetkeyparm == NULL) {
2738 		rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
2739 		res = _FAIL;
2740 		goto exit;
2741 	}
2742 
2743 	_rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
2744 
2745 	psetkeyparm->keyid = (u8)keyid;
2746 	if (is_wep_enc(alg))
2747 		padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
2748 
2749 	psetkeyparm->algorithm = alg;
2750 
2751 	psetkeyparm->set_tx = set_tx;
2752 
2753 	switch (alg) {
2754 	case _WEP40_:
2755 		keylen = 5;
2756 		break;
2757 	case _WEP104_:
2758 		keylen = 13;
2759 		break;
2760 	case _GCMP_256_:
2761 	case _CCMP_256_:
2762 		keylen = 32;
2763 		break;
2764 	case _TKIP_:
2765 	case _TKIP_WTMIC_:
2766 	case _AES_:
2767 	case _GCMP_:
2768 	#ifdef CONFIG_IEEE80211W
2769 	case _BIP_CMAC_128_:
2770 	#endif
2771 	default:
2772 		keylen = 16;
2773 	}
2774 
2775 	_rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
2776 
2777 	pcmd->cmdcode = CMD_SET_KEY; /*_SetKey_CMD_*/
2778 	pcmd->parmbuf = (u8 *)psetkeyparm;
2779 	pcmd->cmdsz = (sizeof(struct setkey_parm));
2780 	pcmd->rsp = NULL;
2781 	pcmd->rspsz = 0;
2782 
2783 
2784 	_rtw_init_listhead(&pcmd->list);
2785 
2786 	res = rtw_enqueue_cmd(pcmdpriv, pcmd);
2787 
2788 exit:
2789 
2790 	return res;
2791 }
2792 #endif
rtw_ap_set_group_key(_adapter * padapter,u8 * key,u8 alg,int keyid)2793 int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
2794 {
2795 	RTW_INFO("%s\n", __FUNCTION__);
2796 
2797 	return rtw_ap_set_key(padapter, key, alg, keyid, 1);
2798 }
2799 
rtw_ap_set_wep_key(_adapter * padapter,u8 * key,u8 keylen,int keyid,u8 set_tx)2800 int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
2801 {
2802 	u8 alg;
2803 
2804 	switch (keylen) {
2805 	case 5:
2806 		alg = _WEP40_;
2807 		break;
2808 	case 13:
2809 		alg = _WEP104_;
2810 		break;
2811 	default:
2812 		alg = _NO_PRIVACY_;
2813 	}
2814 
2815 	RTW_INFO("%s\n", __FUNCTION__);
2816 
2817 	return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
2818 }
2819 
rtw_ap_bmc_frames_hdl(_adapter * padapter)2820 u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
2821 {
2822 #define HIQ_XMIT_COUNTS (6)
2823 	struct sta_info *psta_bmc;
2824 	_list	*xmitframe_plist, *xmitframe_phead;
2825 	struct xmit_frame *pxmitframe = NULL;
2826 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2827 	struct sta_priv  *pstapriv = &padapter->stapriv;
2828 	bool update_tim = _FALSE;
2829 
2830 
2831 	if (padapter->registrypriv.wifi_spec != 1)
2832 		return H2C_SUCCESS;
2833 
2834 
2835 	psta_bmc = rtw_get_bcmc_stainfo(padapter);
2836 	if (!psta_bmc)
2837 		return H2C_SUCCESS;
2838 
2839 
2840 	_rtw_spinlock_bh(&pxmitpriv->lock);
2841 
2842 	if ((rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, 0)) && (psta_bmc->sleepq_len > 0)) {
2843 		int tx_counts = 0;
2844 
2845 		_update_beacon(padapter, _TIM_IE_, NULL, _FALSE, 0, "update TIM with TIB=1");
2846 
2847 		RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
2848 
2849 		xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2850 		xmitframe_plist = get_next(xmitframe_phead);
2851 
2852 		while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
2853 			pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2854 
2855 			xmitframe_plist = get_next(xmitframe_plist);
2856 
2857 			rtw_list_delete(&pxmitframe->list);
2858 
2859 			psta_bmc->sleepq_len--;
2860 			tx_counts++;
2861 
2862 			if (psta_bmc->sleepq_len > 0)
2863 				pxmitframe->attrib.mdata = 1;
2864 			else
2865 				pxmitframe->attrib.mdata = 0;
2866 
2867 			if (tx_counts == HIQ_XMIT_COUNTS)
2868 				pxmitframe->attrib.mdata = 0;
2869 
2870 			pxmitframe->attrib.triggered = 1;
2871 
2872 			if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
2873 				pxmitframe->attrib.qsel = rtw_hal_get_qsel(padapter,QSLT_HIGH_ID);/*HIQ*/
2874 
2875 			rtw_intf_xmitframe_enqueue(padapter, pxmitframe);
2876 
2877 			if (tx_counts == HIQ_XMIT_COUNTS)
2878 				break;
2879 
2880 		}
2881 
2882 	} else {
2883 		if (psta_bmc->sleepq_len == 0) {
2884 
2885 			/*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
2886 
2887 			if (rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, 0))
2888 				update_tim = _TRUE;
2889 
2890 			rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, 0);
2891 			rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, 0);
2892 
2893 			if (update_tim == _TRUE) {
2894 				RTW_INFO("clear TIB\n");
2895 				_update_beacon(padapter, _TIM_IE_, NULL, _TRUE, 0, "bmc sleepq and HIQ empty");
2896 			}
2897 		}
2898 	}
2899 
2900 	_rtw_spinunlock_bh(&pxmitpriv->lock);
2901 
2902 #if 0
2903 	/* HIQ Check */
2904 	rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2905 
2906 	while (_FALSE == empty && rtw_get_passing_time_ms(start) < 3000) {
2907 		rtw_msleep_os(100);
2908 		rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2909 	}
2910 
2911 
2912 	printk("check if hiq empty=%d\n", empty);
2913 #endif
2914 
2915 	return H2C_SUCCESS;
2916 }
2917 
2918 #ifdef CONFIG_NATIVEAP_MLME
2919 
associated_stainfo_update(_adapter * padapter,struct sta_info * psta,u32 sta_info_type)2920 static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
2921 {
2922 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2923 
2924 	RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->phl_sta->mac_addr), sta_info_type);
2925 #ifdef CONFIG_80211N_HT
2926 	if (sta_info_type & STA_INFO_UPDATE_BW) {
2927 
2928 		if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
2929 			if (pmlmepriv->sw_to_20mhz) {
2930 				psta->phl_sta->chandef.bw = CHANNEL_WIDTH_20;
2931 				/*psta->htpriv.ch_offset = CHAN_OFFSET_NO_EXT;*/
2932 				psta->htpriv.sgi_40m = _FALSE;
2933 			} else {
2934 				/*TODO: Switch back to 40MHZ?80MHZ*/
2935 			}
2936 		}
2937 	}
2938 #endif /* CONFIG_80211N_HT */
2939 	/*
2940 		if (sta_info_type & STA_INFO_UPDATE_RATE) {
2941 
2942 		}
2943 	*/
2944 
2945 	if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
2946 		VCS_update(padapter, psta);
2947 
2948 	/*
2949 		if (sta_info_type & STA_INFO_UPDATE_CAP) {
2950 
2951 		}
2952 
2953 		if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
2954 
2955 		}
2956 
2957 		if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
2958 
2959 		}
2960 	*/
2961 
2962 }
2963 
update_bcn_erpinfo_ie(_adapter * padapter)2964 static void update_bcn_erpinfo_ie(_adapter *padapter)
2965 {
2966 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2967 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
2968 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2969 	WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2970 	unsigned char *p, *ie = pnetwork->IEs;
2971 	u32 len = 0;
2972 
2973 	RTW_INFO("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
2974 
2975 	if (!pmlmeinfo->ERP_enable)
2976 		return;
2977 
2978 	/* parsing ERP_IE */
2979 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2980 	if (p && len > 0) {
2981 		PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
2982 
2983 		if (pmlmepriv->num_sta_non_erp == 1)
2984 			pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
2985 		else
2986 			pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
2987 
2988 		if (pmlmepriv->num_sta_no_short_preamble > 0)
2989 			pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
2990 		else
2991 			pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
2992 
2993 		ERP_IE_handler(padapter, pIE);
2994 	}
2995 
2996 }
2997 
update_bcn_htcap_ie(_adapter * padapter)2998 static void update_bcn_htcap_ie(_adapter *padapter)
2999 {
3000 	RTW_INFO("%s\n", __FUNCTION__);
3001 
3002 }
3003 
update_bcn_htinfo_ie(_adapter * padapter)3004 static void update_bcn_htinfo_ie(_adapter *padapter)
3005 {
3006 #ifdef CONFIG_80211N_HT
3007 	/*
3008 	u8 beacon_updated = _FALSE;
3009 	u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
3010 	*/
3011 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3012 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
3013 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
3014 	WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
3015 	unsigned char *p, *ie = pnetwork->IEs;
3016 	u32 len = 0;
3017 
3018 	if (pmlmepriv->htpriv.ht_option == _FALSE)
3019 		return;
3020 
3021 	if (pmlmeinfo->HT_info_enable != 1)
3022 		return;
3023 
3024 
3025 	RTW_INFO("%s current operation mode=0x%X\n",
3026 		 __FUNCTION__, pmlmepriv->ht_op_mode);
3027 
3028 	RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
3029 		pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, ATOMIC_READ(&pmlmepriv->olbc));
3030 
3031 	/*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
3032 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
3033 	if (p && len > 0) {
3034 		struct HT_info_element *pht_info = NULL;
3035 
3036 		pht_info = (struct HT_info_element *)(p + 2);
3037 
3038 		/* for STA Channel Width/Secondary Channel Offset*/
3039 		if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->chandef.chan <= 14)) {
3040 			if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req == _TRUE)
3041 			    || (pmlmepriv->ht_intolerant_ch_reported == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc) == _TRUE)) {
3042 				SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
3043 				SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
3044 
3045 				pmlmepriv->sw_to_20mhz = 1;
3046 				/*
3047 				sta_info_update_type |= STA_INFO_UPDATE_BW;
3048 				beacon_updated = _TRUE;
3049 				*/
3050 
3051 				RTW_INFO("%s:switching to 20Mhz\n", __FUNCTION__);
3052 
3053 				/*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
3054 			}
3055 		} else {
3056 
3057 			if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == _FALSE)
3058 			    && (pmlmepriv->ht_intolerant_ch_reported == _FALSE) && (ATOMIC_READ(&pmlmepriv->olbc) == _FALSE)) {
3059 
3060 				if (pmlmeext->chandef.bw >= CHANNEL_WIDTH_40) {
3061 
3062 					SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
3063 
3064 					SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
3065 						(pmlmeext->chandef.offset == CHAN_OFFSET_UPPER) ?
3066 						HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
3067 
3068 					pmlmepriv->sw_to_20mhz = 0;
3069 					/*
3070 					sta_info_update_type |= STA_INFO_UPDATE_BW;
3071 					beacon_updated = _TRUE;
3072 					*/
3073 
3074 					RTW_INFO("%s:switching back to 40Mhz\n", __FUNCTION__);
3075 				}
3076 			}
3077 		}
3078 
3079 		/* to update  ht_op_mode*/
3080 		*(u16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
3081 
3082 	}
3083 
3084 	/*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
3085 #endif /* CONFIG_80211N_HT */
3086 }
3087 
update_bcn_rsn_ie(_adapter * padapter)3088 static void update_bcn_rsn_ie(_adapter *padapter)
3089 {
3090 	RTW_INFO("%s\n", __FUNCTION__);
3091 
3092 }
3093 
update_bcn_wpa_ie(_adapter * padapter)3094 static void update_bcn_wpa_ie(_adapter *padapter)
3095 {
3096 	RTW_INFO("%s\n", __FUNCTION__);
3097 
3098 }
3099 
update_bcn_wmm_ie(_adapter * padapter)3100 static void update_bcn_wmm_ie(_adapter *padapter)
3101 {
3102 	RTW_INFO("%s\n", __FUNCTION__);
3103 
3104 }
3105 
update_bcn_wps_ie(_adapter * padapter)3106 static void update_bcn_wps_ie(_adapter *padapter)
3107 {
3108 	u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
3109 	uint wps_ielen = 0, wps_offset, remainder_ielen;
3110 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3111 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
3112 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
3113 	WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
3114 	unsigned char *ie = pnetwork->IEs;
3115 	u32 ielen = pnetwork->IELength;
3116 
3117 
3118 	RTW_INFO("%s\n", __FUNCTION__);
3119 
3120 	pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
3121 
3122 	if (pwps_ie == NULL || wps_ielen == 0)
3123 		return;
3124 
3125 	pwps_ie_src = pmlmepriv->wps_beacon_ie;
3126 	if (pwps_ie_src == NULL)
3127 		return;
3128 
3129 	wps_offset = (uint)(pwps_ie - ie);
3130 
3131 	premainder_ie = pwps_ie + wps_ielen;
3132 
3133 	remainder_ielen = ielen - wps_offset - wps_ielen;
3134 
3135 	if (remainder_ielen > 0) {
3136 		pbackup_remainder_ie = rtw_malloc(remainder_ielen);
3137 		if (pbackup_remainder_ie)
3138 			_rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
3139 	}
3140 
3141 	wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
3142 	if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
3143 		_rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
3144 		pwps_ie += (wps_ielen + 2);
3145 
3146 		if (pbackup_remainder_ie)
3147 			_rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
3148 
3149 		/* update IELength */
3150 		pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
3151 	}
3152 
3153 	if (pbackup_remainder_ie)
3154 		rtw_mfree(pbackup_remainder_ie, remainder_ielen);
3155 
3156 	/* deal with the case without set_tx_beacon_cmd() in rtw_update_beacon() */
3157 #if defined(CONFIG_INTERRUPT_BASED_TXBCN) || defined(CONFIG_PCI_HCI)
3158 	if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
3159 		u8 sr = 0;
3160 		rtw_get_wps_attr_content(pwps_ie_src,  wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
3161 
3162 		if (sr) {
3163 			set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
3164 			RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
3165 		} else {
3166 			clr_fwstate(pmlmepriv, WIFI_UNDER_WPS);
3167 			RTW_INFO("%s, clr WIFI_UNDER_WPS\n", __func__);
3168 		}
3169 	}
3170 #endif
3171 }
3172 
update_bcn_p2p_ie(_adapter * padapter)3173 static void update_bcn_p2p_ie(_adapter *padapter)
3174 {
3175 
3176 }
3177 
update_csa_ie(_adapter * padapter)3178 static u8 update_csa_ie(_adapter *padapter)
3179 {
3180 	u8 update = _FALSE;
3181 #ifdef CONFIG_ECSA_PHL
3182 	struct core_ecsa_info *ecsa_info = &(padapter->ecsa_info);
3183 	struct rtw_phl_ecsa_param *ecsa_param = &(ecsa_info->phl_ecsa_param);
3184 	struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3185 	struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3186 	WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
3187 	u8 csa_data[CSA_IE_LEN] = {0};
3188 	u8 csa_ch = ecsa_param->new_chan_def.chan;
3189 	u8 csa_count = ecsa_param->count;
3190 	u8 *ies = pnetwork->IEs + _BEACON_IE_OFFSET_;
3191 	sint ies_len = pnetwork->IELength - _BEACON_IE_OFFSET_;
3192 	u8 *csa_ie;
3193 	sint csa_ie_len;
3194 
3195 	if (!CHK_ECSA_STATE(padapter, ECSA_ST_SW_START))
3196 		return update;
3197 
3198 	csa_ie = rtw_get_ie(ies, WLAN_EID_CHANNEL_SWITCH, &csa_ie_len, ies_len);
3199 
3200 	if (csa_ie == NULL) {
3201 		if (csa_count > 0) {
3202 			/* add new CSA IE */
3203 			RTW_INFO("CSA : "FUNC_ADPT_FMT" ch=%u, count=%u, add CSA IE\n",
3204 				FUNC_ADPT_ARG(padapter), csa_ch, csa_count);
3205 
3206 			csa_data[CSA_SWITCH_MODE] = ecsa_param->mode;
3207 			csa_data[CSA_NEW_CH] = csa_ch;
3208 			csa_data[CSA_SWITCH_COUNT] = csa_count;
3209 			rtw_add_bcn_ie(padapter, pnetwork, WLAN_EID_CHANNEL_SWITCH, csa_data, CSA_IE_LEN);
3210 			update = _TRUE;
3211 		} else if (csa_ch > 0) {
3212 			/* count = 0, means switching channel immediately */
3213 			RTW_INFO("CSA : "FUNC_ADPT_FMT" ch=%d, count=0, switch channel immediately\n",
3214 				FUNC_ADPT_ARG(padapter), csa_ch);
3215 			SET_ECSA_STATE(padapter, ECSA_ST_SW_DONE);
3216 		}
3217 	} else if (csa_ie && csa_ie_len == CSA_IE_LEN) {
3218 		if (csa_count > 0) {
3219 			/* update CSA IE */
3220 			#ifdef DBG_CSA
3221 			RTW_INFO("CSA : "FUNC_ADPT_FMT" ch=%u, count=%u, update CSA IE\n",
3222 				FUNC_ADPT_ARG(padapter), csa_ch, csa_count);
3223 			#endif
3224 
3225 			csa_ie[2 + CSA_SWITCH_COUNT] = csa_count;
3226 		} else {
3227 			/* remove CSA IE */
3228 			RTW_INFO("CSA : "FUNC_ADPT_FMT" ch=%u, count=%u, remove CSA IE\n",
3229 				FUNC_ADPT_ARG(padapter), csa_ch, csa_count);
3230 
3231 			rtw_remove_bcn_ie(padapter, pnetwork, WLAN_EID_CHANNEL_SWITCH);
3232 			SET_ECSA_STATE(padapter, ECSA_ST_SW_DONE);
3233 		}
3234 		update = _TRUE;
3235 	} else {
3236 		RTW_ERR("CSA : "FUNC_ADPT_FMT" unexpected case\n", FUNC_ADPT_ARG(padapter));
3237 	}
3238 
3239 	if (ecsa_param->count > 0)
3240 		ecsa_param->count--;
3241 
3242 #endif /* CONFIG_ECSA_PHL */
3243 	return update;
3244 }
3245 
update_bcn_vendor_spec_ie(_adapter * padapter,u8 * oui)3246 static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
3247 {
3248 	RTW_INFO("%s\n", __FUNCTION__);
3249 
3250 	if (_rtw_memcmp(RTW_WPA_OUI, oui, 4))
3251 		update_bcn_wpa_ie(padapter);
3252 	else if (_rtw_memcmp(WMM_OUI, oui, 4))
3253 		update_bcn_wmm_ie(padapter);
3254 	else if (_rtw_memcmp(WPS_OUI, oui, 4))
3255 		update_bcn_wps_ie(padapter);
3256 	else if (_rtw_memcmp(P2P_OUI, oui, 4))
3257 		update_bcn_p2p_ie(padapter);
3258 	else
3259 		RTW_INFO("unknown OUI type!\n");
3260 
3261 
3262 }
3263 
_update_beacon(_adapter * padapter,u8 ie_id,u8 * oui,u8 tx,u8 flags,const char * tag)3264 void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, u8 flags, const char *tag)
3265 {
3266 	struct mlme_priv *pmlmepriv;
3267 	struct mlme_ext_priv *pmlmeext;
3268 	bool updated = 1; /* treat as upadated by default */
3269 
3270 	if (!padapter)
3271 		return;
3272 
3273 	pmlmepriv = &(padapter->mlmepriv);
3274 	pmlmeext = &(padapter->mlmeextpriv);
3275 
3276 	if (pmlmeext->bstart_bss == _FALSE)
3277 		return;
3278 
3279 	_rtw_spinlock_bh(&pmlmepriv->bcn_update_lock);
3280 
3281 	switch (ie_id) {
3282 	case _TIM_IE_:
3283 		update_BCNTIM(padapter);
3284 		break;
3285 
3286 	case _ERPINFO_IE_:
3287 		update_bcn_erpinfo_ie(padapter);
3288 		break;
3289 
3290 	case _HT_CAPABILITY_IE_:
3291 		update_bcn_htcap_ie(padapter);
3292 		break;
3293 
3294 	case _RSN_IE_2_:
3295 		update_bcn_rsn_ie(padapter);
3296 		break;
3297 
3298 	case _HT_ADD_INFO_IE_:
3299 		update_bcn_htinfo_ie(padapter);
3300 		break;
3301 
3302 #ifdef CONFIG_RTW_MESH
3303 	case WLAN_EID_MESH_CONFIG:
3304 		updated = rtw_mesh_update_bss_peering_status(padapter, &(pmlmeext->mlmext_info.network));
3305 		updated |= rtw_mesh_update_bss_formation_info(padapter, &(pmlmeext->mlmext_info.network));
3306 		updated |= rtw_mesh_update_bss_forwarding_state(padapter, &(pmlmeext->mlmext_info.network));
3307 		break;
3308 #endif
3309 	case WLAN_EID_CHANNEL_SWITCH:
3310 		updated = update_csa_ie(padapter);
3311 		break;
3312 
3313 	case _VENDOR_SPECIFIC_IE_:
3314 		update_bcn_vendor_spec_ie(padapter, oui);
3315 		break;
3316 
3317 	case 0xFF:
3318 	default:
3319 		break;
3320 	}
3321 
3322 	if (updated)
3323 		pmlmepriv->update_bcn = _TRUE;
3324 
3325 	_rtw_spinunlock_bh(&pmlmepriv->bcn_update_lock);
3326 
3327 #ifndef CONFIG_INTERRUPT_BASED_TXBCN
3328 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) || defined(CONFIG_PCI_BCN_POLLING)
3329 	if (tx && updated) {
3330 		/* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
3331 		if (0)
3332 			RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
3333 		if(flags == RTW_CMDF_WAIT_ACK)
3334 			set_tx_beacon_cmd(padapter, RTW_CMDF_WAIT_ACK);
3335 		else
3336 			set_tx_beacon_cmd(padapter, 0);
3337 	}
3338 #else
3339 	{
3340 		/* PCI will issue beacon when BCN interrupt occurs.		 */
3341 	}
3342 #endif
3343 #endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
3344 }
3345 
3346 #ifdef CONFIG_80211N_HT
3347 
rtw_process_public_act_bsscoex(_adapter * padapter,u8 * pframe,uint frame_len)3348 void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
3349 {
3350 	struct sta_info *psta;
3351 	struct sta_priv *pstapriv = &padapter->stapriv;
3352 	u8 beacon_updated = _FALSE;
3353 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3354 	u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
3355 	uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
3356 	u8 category, action;
3357 
3358 	psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
3359 	if (psta == NULL)
3360 		return;
3361 
3362 
3363 	category = frame_body[0];
3364 	action = frame_body[1];
3365 
3366 	if (frame_body_len > 0) {
3367 		if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
3368 			u8 ie_data = frame_body[4];
3369 
3370 			if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
3371 				if (psta->ht_40mhz_intolerant == 0) {
3372 					psta->ht_40mhz_intolerant = 1;
3373 					pmlmepriv->num_sta_40mhz_intolerant++;
3374 					beacon_updated = _TRUE;
3375 				}
3376 			} else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ)	{
3377 				if (pmlmepriv->ht_20mhz_width_req == _FALSE) {
3378 					pmlmepriv->ht_20mhz_width_req = _TRUE;
3379 					beacon_updated = _TRUE;
3380 				}
3381 			} else
3382 				beacon_updated = _FALSE;
3383 		}
3384 	}
3385 
3386 	if (frame_body_len > 8) {
3387 		/* if EID_BSSIntolerantChlReport ie exists */
3388 		if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
3389 			/*todo:*/
3390 			if (pmlmepriv->ht_intolerant_ch_reported == _FALSE) {
3391 				pmlmepriv->ht_intolerant_ch_reported = _TRUE;
3392 				beacon_updated = _TRUE;
3393 			}
3394 		}
3395 	}
3396 
3397 	if (beacon_updated) {
3398 
3399 		rtw_update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE, 0);
3400 
3401 		associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
3402 	}
3403 
3404 
3405 
3406 }
3407 
rtw_process_ht_action_smps(_adapter * padapter,u8 * ta,u8 ctrl_field)3408 void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
3409 {
3410 	u8 e_field, m_field;
3411 	struct sta_info *psta;
3412 	struct sta_priv *pstapriv = &padapter->stapriv;
3413 
3414 	psta = rtw_get_stainfo(pstapriv, ta);
3415 	if (psta == NULL)
3416 		return;
3417 
3418 	e_field = (ctrl_field & BIT(0)) ? 1 : 0; /*SM Power Save Enabled*/
3419 	m_field = (ctrl_field & BIT(1)) ? 1 : 0; /*SM Mode, 0:static SMPS, 1:dynamic SMPS*/
3420 
3421 	if (e_field) {
3422 		if (m_field) { /*mode*/
3423 			psta->htpriv.smps_cap = WLAN_HT_CAP_SM_PS_DYNAMIC;
3424 			RTW_ERR("Don't support dynamic SMPS\n");
3425 		}
3426 		else
3427 			psta->htpriv.smps_cap = WLAN_HT_CAP_SM_PS_STATIC;
3428 	} else {
3429 		/*disable*/
3430 		psta->htpriv.smps_cap = WLAN_HT_CAP_SM_PS_DISABLED;
3431 	}
3432 
3433 	if (psta->htpriv.smps_cap != WLAN_HT_CAP_SM_PS_DYNAMIC)
3434 		rtw_ssmps_wk_cmd(padapter, psta, e_field, 1);
3435 }
3436 
3437 /*
3438 op_mode
3439 Set to 0 (HT pure) under the followign conditions
3440 	- all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
3441 	- all STAs in the BSS are 20 MHz HT in 20 MHz BSS
3442 Set to 1 (HT non-member protection) if there may be non-HT STAs
3443 	in both the primary and the secondary channel
3444 Set to 2 if only HT STAs are associated in BSS,
3445 	however and at least one 20 MHz HT STA is associated
3446 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
3447 	(currently non-GF HT station is considered as non-HT STA also)
3448 */
rtw_ht_operation_update(_adapter * padapter)3449 int rtw_ht_operation_update(_adapter *padapter)
3450 {
3451 	u16 cur_op_mode, new_op_mode;
3452 	int op_mode_changes = 0;
3453 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3454 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
3455 
3456 	if (pmlmepriv->htpriv.ht_option == _FALSE)
3457 		return 0;
3458 
3459 	/*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
3460 		return 0;*/
3461 
3462 	RTW_INFO("%s current operation mode=0x%X\n",
3463 		 __FUNCTION__, pmlmepriv->ht_op_mode);
3464 
3465 	if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
3466 	    && pmlmepriv->num_sta_ht_no_gf) {
3467 		pmlmepriv->ht_op_mode |=
3468 			HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
3469 		op_mode_changes++;
3470 	} else if ((pmlmepriv->ht_op_mode &
3471 		    HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
3472 		   pmlmepriv->num_sta_ht_no_gf == 0) {
3473 		pmlmepriv->ht_op_mode &=
3474 			~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
3475 		op_mode_changes++;
3476 	}
3477 
3478 	if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
3479 	    (pmlmepriv->num_sta_no_ht || ATOMIC_READ(&pmlmepriv->olbc_ht))) {
3480 		pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
3481 		op_mode_changes++;
3482 	} else if ((pmlmepriv->ht_op_mode &
3483 		    HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
3484 		   (pmlmepriv->num_sta_no_ht == 0 && !ATOMIC_READ(&pmlmepriv->olbc_ht))) {
3485 		pmlmepriv->ht_op_mode &=
3486 			~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
3487 		op_mode_changes++;
3488 	}
3489 
3490 	/* Note: currently we switch to the MIXED op mode if HT non-greenfield
3491 	 * station is associated. Probably it's a theoretical case, since
3492 	 * it looks like all known HT STAs support greenfield.
3493 	 */
3494 	new_op_mode = 0;
3495 	if (pmlmepriv->num_sta_no_ht /*||
3496 	    (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
3497 		new_op_mode = OP_MODE_MIXED;
3498 	else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
3499 		 && pmlmepriv->num_sta_ht_20mhz)
3500 		new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
3501 	else if (ATOMIC_READ(&pmlmepriv->olbc_ht))
3502 		new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
3503 	else
3504 		new_op_mode = OP_MODE_PURE;
3505 
3506 	cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3507 	if (cur_op_mode != new_op_mode) {
3508 		pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3509 		pmlmepriv->ht_op_mode |= new_op_mode;
3510 		op_mode_changes++;
3511 	}
3512 
3513 	RTW_INFO("%s new operation mode=0x%X changes=%d\n",
3514 		 __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
3515 
3516 	return op_mode_changes;
3517 
3518 }
3519 
3520 #endif /* CONFIG_80211N_HT */
3521 
associated_clients_update(_adapter * padapter,u8 updated,u32 sta_info_type)3522 void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
3523 {
3524 	/* update associcated stations cap. */
3525 	if (updated == _TRUE) {
3526 		_list	*phead, *plist;
3527 		struct sta_info *psta = NULL;
3528 		struct sta_priv *pstapriv = &padapter->stapriv;
3529 
3530 		_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
3531 
3532 		phead = &pstapriv->asoc_list;
3533 		plist = get_next(phead);
3534 
3535 		/* check asoc_queue */
3536 		while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3537 			psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3538 
3539 			plist = get_next(plist);
3540 
3541 			associated_stainfo_update(padapter, psta, sta_info_type);
3542 		}
3543 
3544 		_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
3545 
3546 	}
3547 
3548 }
3549 
3550 /* called > TSR LEVEL for USB or SDIO Interface*/
bss_cap_update_on_sta_join(_adapter * padapter,struct sta_info * psta)3551 void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
3552 {
3553 	u8 beacon_updated = _FALSE;
3554 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3555 	struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3556 
3557 
3558 #if 0
3559 	if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
3560 	    !psta->no_short_preamble_set) {
3561 		psta->no_short_preamble_set = 1;
3562 		pmlmepriv->num_sta_no_short_preamble++;
3563 		if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3564 		    (pmlmepriv->num_sta_no_short_preamble == 1))
3565 			ieee802_11_set_beacons(hapd->iface);
3566 	}
3567 #endif
3568 
3569 
3570 	if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
3571 		if (!psta->no_short_preamble_set) {
3572 			psta->no_short_preamble_set = 1;
3573 
3574 			pmlmepriv->num_sta_no_short_preamble++;
3575 
3576 			if ((pmlmeext->cur_wireless_mode > WLAN_MD_11B) &&
3577 			    (pmlmepriv->num_sta_no_short_preamble == 1))
3578 				beacon_updated = _TRUE;
3579 		}
3580 	} else {
3581 		if (psta->no_short_preamble_set) {
3582 			psta->no_short_preamble_set = 0;
3583 
3584 			pmlmepriv->num_sta_no_short_preamble--;
3585 
3586 			if ((pmlmeext->cur_wireless_mode > WLAN_MD_11B) &&
3587 			    (pmlmepriv->num_sta_no_short_preamble == 0))
3588 				beacon_updated = _TRUE;
3589 		}
3590 	}
3591 
3592 #if 0
3593 	if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
3594 		psta->nonerp_set = 1;
3595 		pmlmepriv->num_sta_non_erp++;
3596 		if (pmlmepriv->num_sta_non_erp == 1)
3597 			ieee802_11_set_beacons(hapd->iface);
3598 	}
3599 #endif
3600 
3601 	if (psta->flags & WLAN_STA_NONERP) {
3602 		if (!psta->nonerp_set) {
3603 			psta->nonerp_set = 1;
3604 
3605 			pmlmepriv->num_sta_non_erp++;
3606 
3607 			if (pmlmepriv->num_sta_non_erp == 1) {
3608 				beacon_updated = _TRUE;
3609 				rtw_update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE, 0);
3610 			}
3611 		}
3612 
3613 	} else {
3614 		if (psta->nonerp_set) {
3615 			psta->nonerp_set = 0;
3616 
3617 			pmlmepriv->num_sta_non_erp--;
3618 
3619 			if (pmlmepriv->num_sta_non_erp == 0) {
3620 				beacon_updated = _TRUE;
3621 				rtw_update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE, 0);
3622 			}
3623 		}
3624 
3625 	}
3626 
3627 
3628 #if 0
3629 	if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
3630 	    !psta->no_short_slot_time_set) {
3631 		psta->no_short_slot_time_set = 1;
3632 		pmlmepriv->num_sta_no_short_slot_time++;
3633 		if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3634 		    (pmlmepriv->num_sta_no_short_slot_time == 1))
3635 			ieee802_11_set_beacons(hapd->iface);
3636 	}
3637 #endif
3638 
3639 	if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
3640 		if (!psta->no_short_slot_time_set) {
3641 			psta->no_short_slot_time_set = 1;
3642 
3643 			pmlmepriv->num_sta_no_short_slot_time++;
3644 
3645 			if ((pmlmeext->cur_wireless_mode > WLAN_MD_11B) &&
3646 			    (pmlmepriv->num_sta_no_short_slot_time == 1))
3647 				beacon_updated = _TRUE;
3648 		}
3649 	} else {
3650 		if (psta->no_short_slot_time_set) {
3651 			psta->no_short_slot_time_set = 0;
3652 
3653 			pmlmepriv->num_sta_no_short_slot_time--;
3654 
3655 			if ((pmlmeext->cur_wireless_mode > WLAN_MD_11B) &&
3656 			    (pmlmepriv->num_sta_no_short_slot_time == 0))
3657 				beacon_updated = _TRUE;
3658 		}
3659 	}
3660 
3661 #ifdef CONFIG_80211N_HT
3662 	if(padapter->registrypriv.ht_enable &&
3663 		is_supported_ht(padapter->registrypriv.wireless_mode)) {
3664 		if (psta->flags & WLAN_STA_HT) {
3665 			u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
3666 
3667 			RTW_INFO("HT: STA " MAC_FMT " HT Capabilities Info: 0x%04x\n",
3668 				MAC_ARG(psta->phl_sta->mac_addr), ht_capab);
3669 
3670 			if (psta->no_ht_set) {
3671 				psta->no_ht_set = 0;
3672 				pmlmepriv->num_sta_no_ht--;
3673 			}
3674 
3675 			if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
3676 				if (!psta->no_ht_gf_set) {
3677 					psta->no_ht_gf_set = 1;
3678 					pmlmepriv->num_sta_ht_no_gf++;
3679 				}
3680 				RTW_INFO("%s STA " MAC_FMT " - no "
3681 					 "greenfield, num of non-gf stations %d\n",
3682 					 __FUNCTION__, MAC_ARG(psta->phl_sta->mac_addr),
3683 					 pmlmepriv->num_sta_ht_no_gf);
3684 			}
3685 
3686 			if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
3687 				if (!psta->ht_20mhz_set) {
3688 					psta->ht_20mhz_set = 1;
3689 					pmlmepriv->num_sta_ht_20mhz++;
3690 				}
3691 				RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
3692 					 "num of 20MHz HT STAs %d\n",
3693 					 __FUNCTION__, MAC_ARG(psta->phl_sta->mac_addr),
3694 					 pmlmepriv->num_sta_ht_20mhz);
3695 			}
3696 
3697 			if (((ht_capab & RTW_IEEE80211_HT_CAP_40MHZ_INTOLERANT) != 0) &&
3698 				(psta->ht_40mhz_intolerant == 0)) {
3699 				psta->ht_40mhz_intolerant = 1;
3700 				pmlmepriv->num_sta_40mhz_intolerant++;
3701 				RTW_INFO("%s STA " MAC_FMT " - 40MHZ_INTOLERANT, ",
3702 					   __FUNCTION__, MAC_ARG(psta->phl_sta->mac_addr));
3703 			}
3704 
3705 		} else {
3706 			if (!psta->no_ht_set) {
3707 				psta->no_ht_set = 1;
3708 				pmlmepriv->num_sta_no_ht++;
3709 			}
3710 			if (pmlmepriv->htpriv.ht_option == _TRUE) {
3711 				RTW_INFO("%s STA " MAC_FMT
3712 					 " - no HT, num of non-HT stations %d\n",
3713 					 __FUNCTION__, MAC_ARG(psta->phl_sta->mac_addr),
3714 					 pmlmepriv->num_sta_no_ht);
3715 			}
3716 		}
3717 
3718 		if (rtw_ht_operation_update(padapter) > 0) {
3719 			rtw_update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE, 0);
3720 			rtw_update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE, 0);
3721 			beacon_updated = _TRUE;
3722 		}
3723 	}
3724 #endif /* CONFIG_80211N_HT */
3725 
3726 #ifdef CONFIG_RTW_MESH
3727 	if (MLME_IS_MESH(padapter)) {
3728 		struct sta_priv *pstapriv = &padapter->stapriv;
3729 
3730 		rtw_update_beacon(padapter, WLAN_EID_MESH_CONFIG, NULL, _FALSE, 0);
3731 		if (pstapriv->asoc_list_cnt == 1)
3732 			_set_timer(&padapter->mesh_atlm_param_req_timer, 0);
3733 		beacon_updated = _TRUE;
3734 	}
3735 #endif
3736 
3737 	if (beacon_updated)
3738 		rtw_update_beacon(padapter, 0xFF, NULL, _TRUE, 0);
3739 
3740 	/* update associcated stations cap. */
3741 	associated_clients_update(padapter,  beacon_updated, STA_INFO_UPDATE_ALL);
3742 
3743 	RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3744 
3745 }
3746 
bss_cap_update_on_sta_leave(_adapter * padapter,struct sta_info * psta)3747 u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
3748 {
3749 	u8 beacon_updated = _FALSE;
3750 	struct sta_priv *pstapriv = &padapter->stapriv;
3751 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3752 	struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3753 
3754 	if (!psta)
3755 		return beacon_updated;
3756 
3757 	if (rtw_tim_map_is_set(padapter, pstapriv->tim_bitmap, psta->phl_sta->aid)) {
3758 		rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->phl_sta->aid);
3759 		beacon_updated = _TRUE;
3760 		rtw_update_beacon(padapter, _TIM_IE_, NULL, _FALSE, 0);
3761 	}
3762 
3763 	if (psta->no_short_preamble_set) {
3764 		psta->no_short_preamble_set = 0;
3765 		pmlmepriv->num_sta_no_short_preamble--;
3766 		if (pmlmeext->cur_wireless_mode > WLAN_MD_11B
3767 		    && pmlmepriv->num_sta_no_short_preamble == 0)
3768 			beacon_updated = _TRUE;
3769 	}
3770 
3771 	if (psta->nonerp_set) {
3772 		psta->nonerp_set = 0;
3773 		pmlmepriv->num_sta_non_erp--;
3774 		if (pmlmepriv->num_sta_non_erp == 0) {
3775 			beacon_updated = _TRUE;
3776 			rtw_update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE, 0);
3777 		}
3778 	}
3779 
3780 	if (psta->no_short_slot_time_set) {
3781 		psta->no_short_slot_time_set = 0;
3782 		pmlmepriv->num_sta_no_short_slot_time--;
3783 		if (pmlmeext->cur_wireless_mode > WLAN_MD_11B
3784 		    && pmlmepriv->num_sta_no_short_slot_time == 0)
3785 			beacon_updated = _TRUE;
3786 	}
3787 
3788 #ifdef CONFIG_80211N_HT
3789 	if (psta->no_ht_gf_set) {
3790 		psta->no_ht_gf_set = 0;
3791 		pmlmepriv->num_sta_ht_no_gf--;
3792 	}
3793 
3794 	if (psta->no_ht_set) {
3795 		psta->no_ht_set = 0;
3796 		pmlmepriv->num_sta_no_ht--;
3797 	}
3798 
3799 	if (psta->ht_20mhz_set) {
3800 		psta->ht_20mhz_set = 0;
3801 		pmlmepriv->num_sta_ht_20mhz--;
3802 	}
3803 
3804 	if (psta->ht_40mhz_intolerant) {
3805 		psta->ht_40mhz_intolerant = 0;
3806 		if (pmlmepriv->num_sta_40mhz_intolerant > 0)
3807 			pmlmepriv->num_sta_40mhz_intolerant--;
3808 		else
3809 			rtw_warn_on(1);
3810 	}
3811 
3812 	if (rtw_ht_operation_update(padapter) > 0) {
3813 		rtw_update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE, 0);
3814 		rtw_update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE, 0);
3815 	}
3816 #endif /* CONFIG_80211N_HT */
3817 
3818 #ifdef CONFIG_RTW_MESH
3819 	if (MLME_IS_MESH(padapter)) {
3820 		rtw_update_beacon(padapter, WLAN_EID_MESH_CONFIG, NULL, _FALSE, 0);
3821 		if (pstapriv->asoc_list_cnt == 0)
3822 			_cancel_timer_ex(&padapter->mesh_atlm_param_req_timer);
3823 		beacon_updated = _TRUE;
3824 	}
3825 #endif
3826 
3827 	if (beacon_updated == _TRUE)
3828 		rtw_update_beacon(padapter, 0xFF, NULL, _TRUE, 0);
3829 
3830 #if 0
3831 	/* update associated stations cap. */
3832 	associated_clients_update(padapter,  beacon_updated, STA_INFO_UPDATE_ALL); /* move it to avoid deadlock */
3833 #endif
3834 
3835 	RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3836 
3837 	return beacon_updated;
3838 
3839 }
3840 
ap_free_sta(_adapter * padapter,struct sta_info * psta,bool active,u16 reason,bool enqueue,u8 disassoc)3841 u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue, u8 disassoc)
3842 {
3843 	u8 beacon_updated = _FALSE;
3844 
3845 	if (!psta)
3846 		return beacon_updated;
3847 
3848 	RTW_INFO("%s sta "MAC_FMT"\n", __func__, MAC_ARG(psta->phl_sta->mac_addr));
3849 
3850 	if (active == _TRUE) {
3851 #ifdef CONFIG_80211N_HT
3852 		/* tear down Rx AMPDU */
3853 		send_delba(padapter, 0, psta->phl_sta->mac_addr);/* recipient */
3854 
3855 		/* tear down TX AMPDU */
3856 		send_delba(padapter, 1, psta->phl_sta->mac_addr);/*  */ /* originator */
3857 
3858 #endif /* CONFIG_80211N_HT */
3859 
3860 		if (!MLME_IS_MESH(padapter)) {
3861 			if (disassoc == _TRUE)
3862 				issue_disassoc(padapter, psta->phl_sta->mac_addr, reason);
3863 			else
3864 				issue_deauth(padapter, psta->phl_sta->mac_addr, reason);
3865 		}
3866 	}
3867 
3868 #ifdef CONFIG_RTW_MESH
3869 	if (MLME_IS_MESH(padapter))
3870 		rtw_mesh_path_flush_by_nexthop(psta);
3871 #endif
3872 
3873 #ifdef CONFIG_80211N_HT
3874 	psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
3875 	psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
3876 #endif
3877 
3878 	/* clear cam entry / key */
3879 	rtw_clearstakey_cmd(padapter, psta, enqueue);
3880 
3881 
3882 	_rtw_spinlock_bh(&psta->lock);
3883 	psta->state &= ~(WIFI_ASOC_STATE | WIFI_UNDER_KEY_HANDSHAKE);
3884 
3885 #ifdef CONFIG_IOCTL_CFG80211
3886 	if ((psta->auth_len != 0) && (psta->pauth_frame != NULL)) {
3887 		rtw_mfree(psta->pauth_frame, psta->auth_len);
3888 		psta->pauth_frame = NULL;
3889 		psta->auth_len = 0;
3890 	}
3891 
3892 	if (psta->passoc_req && psta->assoc_req_len > 0) {
3893 		rtw_mfree(psta->passoc_req, psta->assoc_req_len);
3894 		psta->passoc_req = NULL;
3895 		psta->assoc_req_len = 0;
3896 	}
3897 #endif /* CONFIG_IOCTL_CFG80211 */
3898 	_rtw_spinunlock_bh(&psta->lock);
3899 
3900 	if (!MLME_IS_MESH(padapter)) {
3901 		#ifdef CONFIG_RTW_WDS
3902 		rtw_wds_path_flush_by_nexthop(psta);
3903 		#endif
3904 
3905 #ifdef CONFIG_IOCTL_CFG80211
3906 		#ifdef COMPAT_KERNEL_RELEASE
3907 		rtw_cfg80211_indicate_sta_disassoc(padapter, psta->phl_sta->mac_addr, reason);
3908 		#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
3909 		rtw_cfg80211_indicate_sta_disassoc(padapter, psta->phl_sta->mac_addr, reason);
3910 		#else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3911 		/* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
3912 		#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3913 #else
3914 		rtw_indicate_sta_disassoc_event(padapter, psta);
3915 #endif
3916 	}
3917 
3918 	beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
3919 
3920 	report_del_sta_event(padapter, psta->phl_sta->mac_addr, reason, enqueue, _FALSE);
3921 
3922 	return beacon_updated;
3923 
3924 }
3925 
rtw_ap_inform_ch_switch(_adapter * padapter,u8 new_ch,u8 ch_offset)3926 int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
3927 {
3928 	_list	*phead, *plist;
3929 	int ret = 0;
3930 	struct sta_info *psta = NULL;
3931 	struct sta_priv *pstapriv = &padapter->stapriv;
3932 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3933 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
3934 	u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3935 
3936 	if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
3937 		return ret;
3938 
3939 	RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
3940 		 FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
3941 
3942 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
3943 	phead = &pstapriv->asoc_list;
3944 	plist = get_next(phead);
3945 
3946 	/* for each sta in asoc_queue */
3947 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3948 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3949 		plist = get_next(plist);
3950 
3951 		issue_action_spct_ch_switch(padapter, psta->phl_sta->mac_addr, new_ch, ch_offset);
3952 		psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
3953 	}
3954 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
3955 
3956 	issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
3957 
3958 	return ret;
3959 }
3960 
rtw_sta_flush(_adapter * padapter,bool enqueue)3961 int rtw_sta_flush(_adapter *padapter, bool enqueue)
3962 {
3963 	_list	*phead, *plist;
3964 	int ret = 0;
3965 	struct sta_info *psta = NULL;
3966 	struct sta_priv *pstapriv = &padapter->stapriv;
3967 	u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3968 	u8 flush_num = 0;
3969 	char flush_list[NUM_STA];
3970 	int i;
3971 
3972 	if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
3973 		return ret;
3974 
3975 	/* pick sta from sta asoc_queue */
3976 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
3977 	phead = &pstapriv->asoc_list;
3978 	plist = get_next(phead);
3979 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3980 		int stainfo_offset;
3981 
3982 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3983 		plist = get_next(plist);
3984 
3985 		rtw_list_delete(&psta->asoc_list);
3986 		pstapriv->asoc_list_cnt--;
3987 		#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
3988 		if (psta->tbtx_enable)
3989 			pstapriv->tbtx_asoc_list_cnt--;
3990 		#endif
3991 		STA_SET_MESH_PLINK(psta, NULL);
3992 
3993 		stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
3994 		if (stainfo_offset_valid(stainfo_offset))
3995 			flush_list[flush_num++] = stainfo_offset;
3996 		else
3997 			rtw_warn_on(1);
3998 	}
3999 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
4000 
4001 	RTW_INFO(FUNC_NDEV_FMT" flush_num:%d\n", FUNC_NDEV_ARG(padapter->pnetdev), flush_num);
4002 
4003 	/* call ap_free_sta() for each sta picked */
4004 	for (i = 0; i < flush_num; i++) {
4005 		u8 sta_addr[ETH_ALEN];
4006 
4007 		psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
4008 		if (psta != NULL) {
4009 			_rtw_memcpy(sta_addr, psta->phl_sta->mac_addr, ETH_ALEN);
4010 			ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, enqueue, _FALSE);
4011 		}
4012 		#ifdef CONFIG_RTW_MESH
4013 		if (MLME_IS_MESH(padapter))
4014 			rtw_mesh_expire_peer(padapter, sta_addr);
4015 		#endif
4016 	}
4017 
4018 	if (!MLME_IS_MESH(padapter))
4019 		issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
4020 
4021 	associated_clients_update(padapter, _TRUE, STA_INFO_UPDATE_ALL);
4022 
4023 	return ret;
4024 }
4025 
4026 /* called > TSR LEVEL for USB or SDIO Interface*/
sta_info_update(_adapter * padapter,struct sta_info * psta)4027 void sta_info_update(_adapter *padapter, struct sta_info *psta)
4028 {
4029 	int flags = psta->flags;
4030 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4031 
4032 
4033 	/* update wmm cap. */
4034 	if (WLAN_STA_WME & flags)
4035 		psta->qos_option = 1;
4036 	else
4037 		psta->qos_option = 0;
4038 
4039 	if (pmlmepriv->qospriv.qos_option == 0)
4040 		psta->qos_option = 0;
4041 
4042 
4043 #ifdef CONFIG_80211N_HT
4044 	/* update 802.11n ht cap. */
4045 	if (WLAN_STA_HT & flags) {
4046 		psta->htpriv.ht_option = _TRUE;
4047 		psta->qos_option = 1;
4048 
4049 		psta->htpriv.smps_cap = (psta->htpriv.ht_cap.cap_info & IEEE80211_HT_CAP_SM_PS) >> 2;
4050 	} else
4051 		psta->htpriv.ht_option = _FALSE;
4052 
4053 	if (pmlmepriv->htpriv.ht_option == _FALSE)
4054 		psta->htpriv.ht_option = _FALSE;
4055 #endif
4056 
4057 #ifdef CONFIG_80211AC_VHT
4058 	/* update 802.11AC vht cap. */
4059 	if (WLAN_STA_VHT & flags)
4060 		psta->vhtpriv.vht_option = _TRUE;
4061 	else
4062 		psta->vhtpriv.vht_option = _FALSE;
4063 
4064 	if (pmlmepriv->vhtpriv.vht_option == _FALSE)
4065 		psta->vhtpriv.vht_option = _FALSE;
4066 #endif
4067 
4068 #ifdef CONFIG_80211AX_HE
4069 	/* update 802.11AX he cap. */
4070 	if (WLAN_STA_HE & flags)
4071 		psta->hepriv.he_option = _TRUE;
4072 	else
4073 		psta->hepriv.he_option = _FALSE;
4074 
4075 	if (pmlmepriv->hepriv.he_option == _FALSE)
4076 		psta->hepriv.he_option = _FALSE;
4077 #endif
4078 
4079 	update_sta_info_apmode(padapter, psta);
4080 }
4081 
4082 /* restore hw setting from sw data structures */
rtw_ap_restore_network(_adapter * padapter)4083 void rtw_ap_restore_network(_adapter *padapter)
4084 {
4085 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
4086 	struct sta_priv *pstapriv = &padapter->stapriv;
4087 	struct sta_info *psta;
4088 	struct security_priv *psecuritypriv = &(padapter->securitypriv);
4089 	_list	*phead, *plist;
4090 	u8 chk_alive_num = 0;
4091 	char chk_alive_list[NUM_STA];
4092 	int i;
4093 
4094 	rtw_setopmode_cmd(padapter
4095 		, MLME_IS_AP(padapter) ? Ndis802_11APMode : Ndis802_11_mesh
4096 		, RTW_CMDF_DIRECTLY
4097 	);
4098 
4099 	set_channel_bwmode(padapter,
4100 			pmlmeext->chandef.chan,
4101 			pmlmeext->chandef.offset,
4102 			pmlmeext->chandef.bw,
4103 			_FALSE);
4104 
4105 	rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
4106 
4107 	if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
4108 	    (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
4109 		/* restore group key, WEP keys is restored in ips_leave() */
4110 		rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, _FALSE);
4111 	}
4112 
4113 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
4114 
4115 	phead = &pstapriv->asoc_list;
4116 	plist = get_next(phead);
4117 
4118 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4119 		int stainfo_offset;
4120 
4121 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
4122 		plist = get_next(plist);
4123 
4124 		stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
4125 		if (stainfo_offset_valid(stainfo_offset))
4126 			chk_alive_list[chk_alive_num++] = stainfo_offset;
4127 	}
4128 
4129 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
4130 
4131 	for (i = 0; i < chk_alive_num; i++) {
4132 		psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
4133 
4134 		if (psta == NULL){
4135 			RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
4136 		} else if (psta->state & WIFI_ASOC_STATE) {
4137 			rtw_sta_media_status_rpt(padapter, psta, 1);
4138 			/*
4139 			rtw_phl_cmd_change_stainfo(adapter_to_dvobj(adapter)->phl,
4140 						   sta->phl_sta,
4141 						   STA_CHG_RAMASK,
4142 						   NULL,
4143 						   0,
4144 						   PHL_CMD_DIRECTLY,
4145 						   0);
4146 			*/
4147 			/* pairwise key */
4148 			/* per sta pairwise key and settings */
4149 			if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
4150 			    (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
4151 				rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _FALSE);
4152 		}
4153 	}
4154 
4155 }
4156 
start_ap_mode(_adapter * padapter)4157 void start_ap_mode(_adapter *padapter)
4158 {
4159 	int i;
4160 	struct sta_info *psta = NULL;
4161 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4162 	struct sta_priv *pstapriv = &padapter->stapriv;
4163 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4164 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
4165 #ifdef CONFIG_CONCURRENT_MODE
4166 	struct security_priv *psecuritypriv = &padapter->securitypriv;
4167 #endif
4168 
4169 	pmlmepriv->update_bcn = _FALSE;
4170 
4171 	/*init_mlme_ap_info(padapter);*/
4172 
4173 	pmlmeext->bstart_bss = _FALSE;
4174 
4175 	pmlmepriv->num_sta_non_erp = 0;
4176 
4177 	pmlmepriv->num_sta_no_short_slot_time = 0;
4178 
4179 	pmlmepriv->num_sta_no_short_preamble = 0;
4180 
4181 	pmlmepriv->num_sta_ht_no_gf = 0;
4182 #ifdef CONFIG_80211N_HT
4183 	pmlmepriv->num_sta_no_ht = 0;
4184 #endif /* CONFIG_80211N_HT */
4185 	pmlmeinfo->HT_info_enable = 0;
4186 	pmlmeinfo->HT_caps_enable = 0;
4187 	pmlmeinfo->HT_enable = 0;
4188 
4189 	pmlmepriv->num_sta_ht_20mhz = 0;
4190 	pmlmepriv->num_sta_40mhz_intolerant = 0;
4191 	ATOMIC_SET(&pmlmepriv->olbc, _FALSE);
4192 	ATOMIC_SET(&pmlmepriv->olbc_ht, _FALSE);
4193 
4194 #ifdef CONFIG_80211N_HT
4195 	pmlmepriv->ht_20mhz_width_req = _FALSE;
4196 	pmlmepriv->ht_intolerant_ch_reported = _FALSE;
4197 	pmlmepriv->ht_op_mode = 0;
4198 	pmlmepriv->sw_to_20mhz = 0;
4199 #endif
4200 
4201 	_rtw_memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
4202 	pmlmepriv->ext_capab_ie_len = 0;
4203 
4204 #ifdef CONFIG_CONCURRENT_MODE
4205 	psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
4206 #endif
4207 
4208 	for (i = 0 ;  i < pstapriv->max_aid; i++)
4209 		pstapriv->sta_aid[i] = NULL;
4210 
4211 #ifdef CONFIG_RTW_WDS
4212 	if (MLME_IS_AP(padapter))
4213 		rtw_wds_pathtbl_init(padapter);
4214 #endif
4215 
4216 	if (rtw_mi_get_ap_num(padapter))
4217 		RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
4218 }
4219 
stop_ap_mode(_adapter * padapter)4220 void stop_ap_mode(_adapter *padapter)
4221 {
4222 	u8 self_action = MLME_ACTION_UNKNOWN;
4223 	struct sta_info *psta = NULL;
4224 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4225 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4226 	int chanctx_num = 0;
4227 	struct rtw_chan_def chan_def = {0};
4228 
4229 	RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
4230 
4231 	if (MLME_IS_AP(padapter))
4232 		self_action = MLME_AP_STOPPED;
4233 	else if (MLME_IS_MESH(padapter))
4234 		self_action = MLME_MESH_STOPPED;
4235 	else
4236 		rtw_warn_on(1);
4237 
4238 	pmlmepriv->update_bcn = _FALSE;
4239 	/*pmlmeext->bstart_bss = _FALSE;*/
4240 	padapter->netif_up = _FALSE;
4241 	/* _rtw_spinlock_free(&pmlmepriv->bcn_update_lock); */
4242 
4243 	/* reset and init security priv , this can refine with rtw_reset_securitypriv */
4244 	_rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
4245 	padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
4246 	padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
4247 
4248 #ifdef CONFIG_DFS_MASTER
4249 	rtw_dfs_rd_en_decision(padapter, self_action, 0);
4250 #endif
4251 
4252 	rtw_rfctl_update_op_mode(adapter_to_rfctl(padapter), BIT(padapter->iface_id), 0);
4253 
4254 	/* free scan queue */
4255 	rtw_free_network_queue(padapter, _TRUE);
4256 
4257 #if CONFIG_RTW_MACADDR_ACL
4258 	rtw_macaddr_acl_clear(padapter, RTW_ACL_PERIOD_BSS);
4259 #endif
4260 
4261 	rtw_sta_flush(padapter, _TRUE);
4262 
4263 	/* free_assoc_sta_resources	 */
4264 	rtw_free_all_stainfo(padapter);
4265 
4266 #ifdef CONFIG_RTW_WDS
4267 	adapter_set_use_wds(padapter, 0);
4268 #endif
4269 #ifdef CONFIG_RTW_MULTI_AP
4270 	padapter->multi_ap = 0;
4271 #endif
4272 	rtw_free_mlme_priv_ie_data(pmlmepriv);
4273 
4274 	pmlmeext->bstart_bss = _FALSE;
4275 
4276 	rtw_hal_rcr_set_chk_bssid(padapter, self_action);
4277 #ifdef CONFIG_RTW_MULTI_AP
4278 	rtw_map_config_monitor(padapter, self_action);
4279 #endif
4280 #if 0
4281 	chanctx_num = rtw_phl_chanctx_del(adapter_to_dvobj(padapter)->phl,
4282 						padapter->phl_role, &chan_def);
4283 
4284 	if (chanctx_num && chan_def.chan != 0) {
4285 		set_channel_bwmode(padapter, chan_def.chan, chan_def.offset, chan_def.bw, _FALSE);
4286 		rtw_mi_update_union_chan_inf(padapter, chan_def.chan, chan_def.offset, chan_def.bw);
4287 	}
4288 #endif
4289 
4290 #ifdef CONFIG_RTW_WDS
4291 	if (MLME_IS_AP(padapter))
4292 		rtw_wds_pathtbl_unregister(padapter);
4293 #endif
4294 }
4295 
4296 #endif /* CONFIG_NATIVEAP_MLME */
4297 
rtw_ap_update_clients_rainfo(struct _ADAPTER * a,enum phl_cmd_type flag)4298 void rtw_ap_update_clients_rainfo(struct _ADAPTER *a, enum phl_cmd_type flag)
4299 {
4300 	struct dvobj_priv *d = adapter_to_dvobj(a);
4301 	struct mlme_ext_priv *pmlmeext = &(a->mlmeextpriv);
4302 	struct sta_priv *pstapriv = &a->stapriv;
4303 	struct sta_info *psta;
4304 	const struct sta_info *ap_self_psta = rtw_get_stainfo(pstapriv, a->phl_role->mac_addr);
4305 	_list *plist, *phead;
4306 	u8 i;
4307 
4308 	/* update RA mask of all clients */
4309 	_rtw_spinlock_bh(&pstapriv->sta_hash_lock);
4310 	for (i = 0; i < NUM_STA; i++) {
4311 		phead = &(pstapriv->sta_hash[i]);
4312 		plist = get_next(phead);
4313 
4314 		while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4315 			psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
4316 			plist = get_next(plist);
4317 
4318 			/* no need to update RA info of ap self */
4319 			if (psta && psta != ap_self_psta) {
4320 				psta->phl_sta->chandef.bw = pmlmeext->chandef.bw;
4321 				rtw_phl_cmd_change_stainfo(GET_PHL_INFO(d),
4322 							psta->phl_sta,
4323 							STA_CHG_RAMASK,
4324 							NULL,
4325 							0,
4326 							flag,
4327 							0);
4328 			}
4329 		}
4330 	}
4331 	_rtw_spinunlock_bh(&pstapriv->sta_hash_lock);
4332 }
4333 
rtw_ap_update_bss_chbw(_adapter * adapter,WLAN_BSSID_EX * bss,u8 ch,u8 bw,u8 offset)4334 void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
4335 {
4336 #define UPDATE_VHT_CAP 1
4337 #define UPDATE_HT_CAP 1
4338 #ifdef CONFIG_80211AC_VHT
4339 	struct vht_priv *vhtpriv = &adapter->mlmepriv.vhtpriv;
4340 #endif
4341 #ifdef CONFIG_80211AX_HE
4342 	struct he_priv *hepriv = &adapter->mlmepriv.hepriv;
4343 #endif
4344 	{
4345 		u8 *p;
4346 		int ie_len;
4347 		u8 old_ch = bss->Configuration.DSConfig;
4348 		bool change_band = _FALSE;
4349 
4350 		if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
4351 			change_band = _TRUE;
4352 
4353 		/* update channel in IE */
4354 		p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
4355 		if (p && ie_len > 0)
4356 			*(p + 2) = ch;
4357 
4358 		bss->Configuration.DSConfig = ch;
4359 
4360 		/* band is changed, update ERP, support rate, ext support rate IE */
4361 		if (change_band == _TRUE)
4362 			change_band_update_ie(adapter, bss, ch);
4363 	}
4364 
4365 #ifdef CONFIG_80211AX_HE
4366 	if (hepriv->he_option == _TRUE) {
4367 		/* CONFIG_80211AX_HE_TODO */
4368 	}
4369 #endif
4370 
4371 #ifdef CONFIG_80211AC_VHT
4372 	if (vhtpriv->vht_option == _TRUE) {
4373 		u8 *vht_cap_ie, *vht_op_ie;
4374 		int vht_cap_ielen, vht_op_ielen;
4375 		u8	center_freq;
4376 
4377 		vht_cap_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTCapability, &vht_cap_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
4378 		vht_op_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_VHTOperation, &vht_op_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
4379 		center_freq = rtw_phl_get_center_ch(ch, bw, offset);
4380 
4381 		/* update vht cap ie */
4382 		if (vht_cap_ie && vht_cap_ielen) {
4383 			#if UPDATE_VHT_CAP
4384 			/* if ((bw == CHANNEL_WIDTH_160 || bw == CHANNEL_WIDTH_80_80) && pvhtpriv->sgi_160m)
4385 				SET_VHT_CAPABILITY_ELE_SHORT_GI160M(pvht_cap_ie + 2, 1);
4386 			else */
4387 				SET_VHT_CAPABILITY_ELE_SHORT_GI160M(vht_cap_ie + 2, 0);
4388 
4389 			if (bw >= CHANNEL_WIDTH_80 && vhtpriv->sgi_80m)
4390 				SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 1);
4391 			else
4392 				SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 0);
4393 			#endif
4394 		}
4395 
4396 		/* update vht op ie */
4397 		if (vht_op_ie && vht_op_ielen) {
4398 			if (bw < CHANNEL_WIDTH_80) {
4399 				RTW_INFO(FUNC_ADPT_FMT" update VHT 20/40M\n", FUNC_ADPT_ARG(adapter));
4400 				SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
4401 				SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
4402 				SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
4403 			} else if (bw == CHANNEL_WIDTH_80) {
4404 				RTW_INFO(FUNC_ADPT_FMT" update VHT 80M, center_freq = %u\n", FUNC_ADPT_ARG(adapter), center_freq);
4405 				SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 1);
4406 				SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, center_freq);
4407 				SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
4408 			} else {
4409 				RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
4410 				rtw_warn_on(1);
4411 			}
4412 		}
4413 	}
4414 #endif /* CONFIG_80211AC_VHT */
4415 #ifdef CONFIG_80211N_HT
4416 	{
4417 		struct ht_priv	*htpriv = &adapter->mlmepriv.htpriv;
4418 		u8 *ht_cap_ie, *ht_op_ie;
4419 		int ht_cap_ielen, ht_op_ielen;
4420 
4421 		ht_cap_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTCapability, &ht_cap_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
4422 		ht_op_ie = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), EID_HTInfo, &ht_op_ielen, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
4423 
4424 		/* update ht cap ie */
4425 		if (ht_cap_ie && ht_cap_ielen) {
4426 			#if UPDATE_HT_CAP
4427 			if (bw >= CHANNEL_WIDTH_40)
4428 				SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
4429 			else
4430 				SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
4431 
4432 			if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
4433 				SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
4434 			else
4435 				SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
4436 
4437 			if (htpriv->sgi_20m)
4438 				SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
4439 			else
4440 				SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
4441 			#endif
4442 		}
4443 
4444 		/* update ht op ie */
4445 		if (ht_op_ie && ht_op_ielen) {
4446 			SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
4447 			switch (offset) {
4448 			case CHAN_OFFSET_UPPER:
4449 				SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, IEEE80211_SCA);
4450 				break;
4451 			case CHAN_OFFSET_LOWER:
4452 				SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, IEEE80211_SCB);
4453 				break;
4454 			case CHAN_OFFSET_NO_EXT:
4455 			default:
4456 				break;
4457 				SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, IEEE80211_SCN);
4458 			}
4459 
4460 			if (bw >= CHANNEL_WIDTH_40)
4461 				SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
4462 			else
4463 				SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
4464 		}
4465 	}
4466 #endif /* CONFIG_80211N_HT */
4467 }
4468 
rtw_ap_update_chbw_by_ifbmp(struct dvobj_priv * dvobj,u8 ifbmp,u8 cur_ie_ch[],u8 cur_ie_bw[],u8 cur_ie_offset[],u8 dec_ch[],u8 dec_bw[],u8 dec_offset[],const char * caller)4469 static u8 rtw_ap_update_chbw_by_ifbmp(struct dvobj_priv *dvobj, u8 ifbmp
4470 	, u8 cur_ie_ch[], u8 cur_ie_bw[], u8 cur_ie_offset[]
4471 	, u8 dec_ch[], u8 dec_bw[], u8 dec_offset[]
4472 	, const char *caller)
4473 {
4474 	_adapter *iface;
4475 	struct mlme_ext_priv *mlmeext;
4476 	WLAN_BSSID_EX *network;
4477 	u8 ifbmp_ch_changed = 0;
4478 	int i;
4479 
4480 	for (i = 0; i < dvobj->iface_nums; i++) {
4481 		if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4482 			continue;
4483 
4484 		iface = dvobj->padapters[i];
4485 		mlmeext = &(iface->mlmeextpriv);
4486 
4487 		if (MLME_IS_ASOC(iface)) {
4488 			RTW_INFO(FUNC_ADPT_FMT" %u,%u,%u => %u,%u,%u%s\n", caller, ADPT_ARG(iface)
4489 				, mlmeext->chandef.chan, mlmeext->chandef.bw, mlmeext->chandef.offset
4490 				, dec_ch[i], dec_bw[i], dec_offset[i]
4491 				, MLME_IS_OPCH_SW(iface) ? " OPCH_SW" : "");
4492 		} else {
4493 			RTW_INFO(FUNC_ADPT_FMT" %u,%u,%u => %u,%u,%u%s\n", caller, ADPT_ARG(iface)
4494 				, cur_ie_ch[i], cur_ie_bw[i], cur_ie_offset[i]
4495 				, dec_ch[i], dec_bw[i], dec_offset[i]
4496 				, MLME_IS_OPCH_SW(iface) ? " OPCH_SW" : "");
4497 		}
4498 	}
4499 
4500 	for (i = 0; i < dvobj->iface_nums; i++) {
4501 		if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4502 			continue;
4503 
4504 		iface = dvobj->padapters[i];
4505 		mlmeext = &(iface->mlmeextpriv);
4506 		network = &(mlmeext->mlmext_info.network);
4507 
4508 		/* ch setting differs from mlmeext.network IE */
4509 		if (cur_ie_ch[i] != dec_ch[i]
4510 			|| cur_ie_bw[i] != dec_bw[i]
4511 			|| cur_ie_offset[i] != dec_offset[i])
4512 			ifbmp_ch_changed |= BIT(i);
4513 
4514 		/* ch setting differs from existing one */
4515 		if (MLME_IS_ASOC(iface)
4516 			&& (mlmeext->chandef.chan != dec_ch[i]
4517 				|| mlmeext->chandef.bw != dec_bw[i]
4518 				|| mlmeext->chandef.offset != dec_offset[i])
4519 		) {
4520 			if (rtw_linked_check(iface) == _TRUE) {
4521 				#ifdef CONFIG_SPCT_CH_SWITCH
4522 				if (1)
4523 					rtw_ap_inform_ch_switch(iface, dec_ch[i], dec_offset[i]);
4524 				else
4525 				#endif
4526 				#ifdef CONFIG_ECSA_PHL
4527 				if (CHK_ECSA_STATE(iface, ECSA_ST_NONE))
4528 				#endif
4529 					rtw_sta_flush(iface, _FALSE);
4530 			}
4531 		}
4532 
4533 		mlmeext->chandef.chan = dec_ch[i];
4534 		mlmeext->chandef.bw = dec_bw[i];
4535 		mlmeext->chandef.offset = dec_offset[i];
4536 
4537 		rtw_ap_update_bss_chbw(iface, network, dec_ch[i], dec_bw[i], dec_offset[i]);
4538 	}
4539 
4540 	return ifbmp_ch_changed;
4541 }
4542 
rtw_ap_ch_specific_chk(_adapter * adapter,u8 ch,u8 * bw,u8 * offset,const char * caller)4543 static u8 rtw_ap_ch_specific_chk(_adapter *adapter, u8 ch, u8 *bw, u8 *offset, const char *caller)
4544 {
4545 	struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
4546 	RT_CHANNEL_INFO *chset = adapter_to_chset(adapter);
4547 	int ch_idx;
4548 	u8 ret = _SUCCESS;
4549 
4550 	ch_idx = rtw_chset_search_ch(chset, ch);
4551 	if (ch_idx < 0) {
4552 		RTW_WARN("%s ch:%u doesn't fit in chplan\n", caller, ch);
4553 		ret = _FAIL;
4554 		goto exit;
4555 	}
4556 	if (chset[ch_idx].flags & RTW_CHF_NO_IR) {
4557 		RTW_WARN("%s ch:%u is passive\n", caller, ch);
4558 		ret = _FAIL;
4559 		goto exit;
4560 	}
4561 
4562 	rtw_adjust_chbw(adapter, ch, bw, offset);
4563 
4564 	if (!rtw_get_offset_by_chbw(ch, *bw, offset)) {
4565 		RTW_WARN("%s %u,%u has no valid offset\n", caller, ch, *bw);
4566 		ret = _FAIL;
4567 		goto exit;
4568 	}
4569 
4570 	while (!rtw_chset_is_chbw_valid(chset, ch, *bw, *offset, 0, 0)
4571 		|| (rtw_rfctl_dfs_domain_unknown(rfctl) && rtw_chset_is_dfs_chbw(chset, ch, *bw, *offset))
4572 	) {
4573 		if (*bw > CHANNEL_WIDTH_20)
4574 			(*bw)--;
4575 		if (*bw == CHANNEL_WIDTH_20) {
4576 			*offset = CHAN_OFFSET_NO_EXT;
4577 			break;
4578 		}
4579 	}
4580 
4581 
4582 	if (rtw_rfctl_dfs_domain_unknown(rfctl) && rtw_chset_is_dfs_chbw(chset, ch, *bw, *offset)) {
4583 		RTW_WARN("%s DFS channel %u can't be used\n", caller, ch);
4584 		ret = _FAIL;
4585 		goto exit;
4586 	}
4587 
4588 exit:
4589 	return ret;
4590 }
4591 
rtw_ap_choose_chbw(_adapter * adapter,u8 sel_ch,u8 max_bw,u8 cur_ch,u8 * ch,u8 * bw,u8 * offset,bool by_int_info,u8 mesh_only,const char * caller)4592 static bool rtw_ap_choose_chbw(_adapter *adapter, u8 sel_ch, u8 max_bw, u8 cur_ch
4593 	, u8 *ch, u8 *bw, u8 *offset, bool by_int_info, u8 mesh_only, const char *caller)
4594 {
4595 	struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
4596 	bool ch_avail = _FALSE;
4597 
4598 #if defined(CONFIG_DFS_MASTER)
4599 	if (!rtw_rfctl_dfs_domain_unknown(rfctl)) {
4600 		if (rfctl->radar_detected
4601 			&& rfctl->dbg_dfs_choose_dfs_ch_first
4602 		) {
4603 			ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
4604 						, ch, bw, offset
4605 						, RTW_CHF_DFS, 0
4606 						, cur_ch, by_int_info, mesh_only);
4607 			if (ch_avail == _TRUE) {
4608 				RTW_INFO("%s choose 5G DFS channel for debug\n", caller);
4609 				goto exit;
4610 			}
4611 		}
4612 
4613 		if (rfctl->radar_detected
4614 			&& (rfctl->dfs_ch_sel_e_flags || rfctl->dfs_ch_sel_d_flags)
4615 		) {
4616 			ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
4617 						, ch, bw, offset
4618 						, rfctl->dfs_ch_sel_e_flags, rfctl->dfs_ch_sel_d_flags
4619 						, cur_ch, by_int_info, mesh_only);
4620 			if (ch_avail == _TRUE) {
4621 				RTW_INFO("%s choose with dfs_ch_sel_ e_flags:0x%02x d_flags:0x%02x for debug\n"
4622 					, caller, rfctl->dfs_ch_sel_e_flags, rfctl->dfs_ch_sel_d_flags);
4623 				goto exit;
4624 			}
4625 		}
4626 
4627 		ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
4628 					, ch, bw, offset
4629 					, 0, 0
4630 					, cur_ch, by_int_info, mesh_only);
4631 	} else
4632 #endif /* defined(CONFIG_DFS_MASTER) */
4633 	{
4634 		ch_avail = rtw_choose_shortest_waiting_ch(rfctl, sel_ch, max_bw
4635 					, ch, bw, offset
4636 					, 0, RTW_CHF_DFS
4637 					, cur_ch, by_int_info, mesh_only);
4638 	}
4639 #if defined(CONFIG_DFS_MASTER)
4640 exit:
4641 #endif
4642 	if (ch_avail == _FALSE)
4643 		RTW_WARN("%s no available channel\n", caller);
4644 
4645 	return ch_avail;
4646 }
4647 
rtw_ap_chbw_decision(_adapter * adapter,u8 ifbmp,u8 excl_ifbmp,s16 req_ch,s8 req_bw,s8 req_offset,struct rtw_chan_def * chdef)4648 u8 rtw_ap_chbw_decision(_adapter *adapter, u8 ifbmp, u8 excl_ifbmp
4649 	, s16 req_ch, s8 req_bw, s8 req_offset, struct rtw_chan_def *chdef)
4650 {
4651 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
4652 	RT_CHANNEL_INFO *chset = adapter_to_chset(adapter);
4653 	struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
4654 	bool ch_avail = _FALSE;
4655 	u8 cur_ie_ch[CONFIG_IFACE_NUMBER] = {0};
4656 	u8 cur_ie_bw[CONFIG_IFACE_NUMBER] = {0};
4657 	u8 cur_ie_offset[CONFIG_IFACE_NUMBER] = {0};
4658 	u8 dec_ch[CONFIG_IFACE_NUMBER] = {0};
4659 	u8 dec_bw[CONFIG_IFACE_NUMBER] = {0};
4660 	u8 dec_offset[CONFIG_IFACE_NUMBER] = {0};
4661 	u8 u_ch = 0, u_bw = 0, u_offset = 0;
4662 	struct mlme_ext_priv *mlmeext;
4663 	WLAN_BSSID_EX *network;
4664 	struct mi_state mstate;
4665 	struct mi_state mstate_others;
4666 	bool set_u_ch = _FALSE;
4667 	u8 ifbmp_others = 0xFF & ~ifbmp & ~excl_ifbmp;
4668 	u8 ifbmp_ch_changed = 0;
4669 	bool ifbmp_all_mesh = 0;
4670 	_adapter *iface;
4671 	int i;
4672 #ifdef CONFIG_MCC_MODE
4673 	struct rtw_phl_com_t *phl_com = GET_PHL_COM(dvobj);
4674 	u8 mcc_sup = phl_com->dev_cap.mcc_sup;
4675 #endif
4676 #ifdef CONFIG_RTW_MESH
4677 	for (i = 0; i < dvobj->iface_nums; i++)
4678 		if ((ifbmp & BIT(i)) && dvobj->padapters)
4679 			if (!MLME_IS_MESH(dvobj->padapters[i]))
4680 				break;
4681 	ifbmp_all_mesh = i >= dvobj->iface_nums ? 1 : 0;
4682 #endif
4683 
4684 	RTW_INFO("%s ifbmp:0x%02x excl_ifbmp:0x%02x req:%d,%d,%d\n", __func__
4685 		, ifbmp, excl_ifbmp, req_ch, req_bw, req_offset);
4686 	rtw_mi_status_by_ifbmp(dvobj, ifbmp, &mstate);
4687 	rtw_mi_status_by_ifbmp(dvobj, ifbmp_others, &mstate_others);
4688 	RTW_INFO("%s others ld_sta_num:%u, lg_sta_num:%u, ap_num:%u, mesh_num:%u\n"
4689 		, __func__, MSTATE_STA_LD_NUM(&mstate_others), MSTATE_STA_LG_NUM(&mstate_others)
4690 		, MSTATE_AP_NUM(&mstate_others), MSTATE_MESH_NUM(&mstate_others));
4691 
4692 	for (i = 0; i < dvobj->iface_nums; i++) {
4693 		if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4694 			continue;
4695 		iface = dvobj->padapters[i];
4696 		mlmeext = &(iface->mlmeextpriv);
4697 		network = &(mlmeext->mlmext_info.network);
4698 
4699 		/* get current IE channel settings */
4700 		rtw_ies_get_chbw(BSS_EX_TLV_IES(network), BSS_EX_TLV_IES_LEN(network)
4701 			, &cur_ie_ch[i], &cur_ie_bw[i], &cur_ie_offset[i], 1, 1);
4702 
4703 		/* prepare temporary channel setting decision */
4704 		if (req_ch == 0) {
4705 			/* request comes from upper layer, use cur_ie values */
4706 			dec_ch[i] = cur_ie_ch[i];
4707 			dec_bw[i] = cur_ie_bw[i];
4708 			dec_offset[i] = cur_ie_offset[i];
4709 		} else {
4710 			/* use chbw of cur_ie updated with specifying req as temporary decision */
4711 			dec_ch[i] = (req_ch <= REQ_CH_NONE) ? cur_ie_ch[i] : req_ch;
4712 			if (req_bw <= REQ_BW_NONE) {
4713 				if (req_bw == REQ_BW_ORI)
4714 					dec_bw[i] = iface->mlmepriv.ori_chandef.bw;
4715 				else
4716 					dec_bw[i] = cur_ie_bw[i];
4717 			} else
4718 				dec_bw[i] = req_bw;
4719 			dec_offset[i] = (req_offset <= REQ_OFFSET_NONE) ? cur_ie_offset[i] : req_offset;
4720 		}
4721 	}
4722 
4723 	if (MSTATE_STA_LD_NUM(&mstate_others) || MSTATE_STA_LG_NUM(&mstate_others)
4724 		|| MSTATE_AP_NUM(&mstate_others) || MSTATE_MESH_NUM(&mstate_others)
4725 	) {
4726 		/* has linked/linking STA or has AP/Mesh mode */
4727 		rtw_warn_on(!rtw_mi_get_ch_setting_union_by_ifbmp(dvobj, ifbmp_others, &u_ch, &u_bw, &u_offset));
4728 		RTW_INFO("%s others union:%u,%u,%u\n", __func__, u_ch, u_bw, u_offset);
4729 	}
4730 
4731 #ifdef CONFIG_MCC_MODE
4732 	if (mcc_sup && req_ch == 0) {
4733 		/* will disable MCC in ap starter prepare after v10 merge */
4734 		if (rtw_hw_mcc_chk_inprogress(adapter)) {
4735 			u8 if_id = adapter->iface_id;
4736 
4737 			mlmeext = &(adapter->mlmeextpriv);
4738 			/* check channel settings are the same */
4739 			if (cur_ie_ch[if_id] == mlmeext->chandef.chan
4740 				&& cur_ie_bw[if_id] == mlmeext->chandef.bw
4741 				&& cur_ie_offset[if_id] == mlmeext->chandef.offset) {
4742 
4743 				RTW_INFO(FUNC_ADPT_FMT"req ch settings are the same as current ch setting, go to exit\n"
4744 					, FUNC_ADPT_ARG(adapter));
4745 				goto exit;
4746 			} else {
4747 				RTW_WARN(FUNC_ADPT_FMT"request channel settings are different from current channel setting(%d,%d,%d,%d,%d,%d), restart MCC\n"
4748 					, FUNC_ADPT_ARG(adapter)
4749 					, cur_ie_ch[if_id], cur_ie_bw[if_id], cur_ie_offset[if_id]
4750 					, mlmeext->chandef.chan, mlmeext->chandef.bw, mlmeext->chandef.offset);
4751 				#if 0
4752 				rtw_hal_set_mcc_setting_disconnect(adapter);
4753 				#endif
4754 			}
4755 		}
4756 	}
4757 #endif /* CONFIG_MCC_MODE */
4758 
4759 	if (MSTATE_STA_LG_NUM(&mstate_others) && !MSTATE_STA_LD_NUM(&mstate_others)) {
4760 		/* has linking STA but no linked STA */
4761 
4762 		for (i = 0; i < dvobj->iface_nums; i++) {
4763 			if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4764 				continue;
4765 			iface = dvobj->padapters[i];
4766 
4767 			rtw_adjust_chbw(iface, dec_ch[i], &dec_bw[i], &dec_offset[i]);
4768 			#ifdef CONFIG_RTW_MESH
4769 			if (MLME_IS_MESH(iface))
4770 				rtw_mesh_adjust_chbw(dec_ch[i], &dec_bw[i], &dec_offset[i]);
4771 			#endif
4772 
4773 			if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch[i], dec_bw[i], dec_offset[i])) {
4774 				rtw_chset_sync_chbw(chset
4775 					, &dec_ch[i], &dec_bw[i], &dec_offset[i]
4776 					, &u_ch, &u_bw, &u_offset, 1, 0);
4777 				set_u_ch = _TRUE;
4778 			} else {
4779 				#ifdef CONFIG_MCC_MODE
4780 				if (mcc_sup) {
4781 					mlmeext = &(iface->mlmeextpriv);
4782 					mlmeext->chandef.chan = chdef->chan= dec_ch[i];
4783 					mlmeext->chandef.bw = chdef->bw= dec_bw[i];
4784 					mlmeext->chandef.offset = chdef->offset= dec_offset[i];
4785 
4786 					RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(iface)
4787 						 , chdef->chan, chdef->bw, chdef->offset);
4788 					goto exit;
4789 				}
4790 				#endif /* CONFIG_MCC_MODE */
4791 				/* set this for possible ch change when join down*/
4792 				set_fwstate(&iface->mlmepriv, WIFI_OP_CH_SWITCHING);
4793 			}
4794 		}
4795 
4796 	} else if (MSTATE_STA_LD_NUM(&mstate_others)
4797 		|| MSTATE_AP_NUM(&mstate_others) || MSTATE_MESH_NUM(&mstate_others)
4798 	) {
4799 		/* has linked STA mode or AP/Mesh mode */
4800 
4801 		for (i = 0; i < dvobj->iface_nums; i++) {
4802 			if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4803 				continue;
4804 			iface = dvobj->padapters[i];
4805 			#ifdef CONFIG_MCC_MODE
4806 			if (mcc_sup) {
4807 				if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch[i], dec_bw[i], dec_offset[i])) {
4808 					mlmeext = &(iface->mlmeextpriv);
4809 					mlmeext->chandef.chan = chdef->chan = dec_ch[i] = cur_ie_ch[i];
4810 					mlmeext->chandef.bw = chdef->bw = dec_bw[i] = cur_ie_bw[i];
4811 					mlmeext->chandef.offset = chdef->offset = dec_offset[i] = cur_ie_offset[i];
4812 					RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(iface)
4813 						 , chdef->chan, chdef->bw, chdef->offset);
4814 					goto exit;
4815 				}
4816 			}
4817 			#endif /* CONFIG_MCC_MODE */
4818 
4819 			rtw_adjust_chbw(iface, u_ch, &dec_bw[i], &dec_offset[i]);
4820 			#ifdef CONFIG_RTW_MESH
4821 			if (MLME_IS_MESH(iface))
4822 				rtw_mesh_adjust_chbw(u_ch, &dec_bw[i], &dec_offset[i]);
4823 			#endif
4824 
4825 			if (req_ch == 0 && dec_bw[i] > u_bw
4826 				&& rtw_chset_is_dfs_chbw(chset, u_ch, u_bw, u_offset)
4827 			) {
4828 				/* request comes from upper layer, prevent from additional channel waiting */
4829 				dec_bw[i] = u_bw;
4830 				if (dec_bw[i] == CHANNEL_WIDTH_20)
4831 					dec_offset[i] = CHAN_OFFSET_NO_EXT;
4832 			}
4833 
4834 			/* follow */
4835 			rtw_chset_sync_chbw(chset
4836 				, &dec_ch[i], &dec_bw[i], &dec_offset[i]
4837 				, &u_ch, &u_bw, &u_offset, 1, 0);
4838 		}
4839 
4840 		set_u_ch = _TRUE;
4841 
4842 	} else {
4843 		/* autonomous decision */
4844 		u8 ori_ch = 0;
4845 		u8 max_bw;
4846 		bool by_int_info;
4847 
4848 		if (req_ch <= REQ_CH_NONE) /* channel is not specified */
4849 			goto choose_chbw;
4850 
4851 		/* get tmp dec union of ifbmp */
4852 		for (i = 0; i < dvobj->iface_nums; i++) {
4853 			if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4854 				continue;
4855 			if (u_ch == 0) {
4856 				u_ch = dec_ch[i];
4857 				u_bw = dec_bw[i];
4858 				u_offset = dec_offset[i];
4859 				rtw_adjust_chbw(adapter, u_ch, &u_bw, &u_offset);
4860 				rtw_get_offset_by_chbw(u_ch, u_bw, &u_offset);
4861 			} else {
4862 				u8 tmp_ch = dec_ch[i];
4863 				u8 tmp_bw = dec_bw[i];
4864 				u8 tmp_offset = dec_offset[i];
4865 
4866 				rtw_adjust_chbw(adapter, tmp_ch, &tmp_bw, &tmp_offset);
4867 				rtw_get_offset_by_chbw(tmp_ch, tmp_bw, &tmp_offset);
4868 
4869 				rtw_warn_on(!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, tmp_ch, tmp_bw, tmp_offset));
4870 				rtw_sync_chbw(&tmp_ch, &tmp_bw, &tmp_offset, &u_ch, &u_bw, &u_offset);
4871 			}
4872 		}
4873 
4874 		#ifdef CONFIG_RTW_MESH
4875 		/* if ifbmp are all mesh, apply bw restriction */
4876 		if (ifbmp_all_mesh)
4877 			rtw_mesh_adjust_chbw(u_ch, &u_bw, &u_offset);
4878 		#endif
4879 
4880 		RTW_INFO("%s ifbmp:0x%02x tmp union:%u,%u,%u\n", __func__, ifbmp, u_ch, u_bw, u_offset);
4881 
4882 		/* check if tmp dec union is usable */
4883 		if (rtw_ap_ch_specific_chk(adapter, u_ch, &u_bw, &u_offset, __func__) == _FAIL) {
4884 			/* channel can't be used */
4885 			if (req_ch > 0) {
4886 				/* specific channel and not from IE => don't change channel setting */
4887 				goto exit;
4888 			}
4889 			goto choose_chbw;
4890 		} else if (rtw_chset_is_chbw_non_ocp(chset, u_ch, u_bw, u_offset)) {
4891 			RTW_WARN("%s DFS channel %u,%u under non ocp\n", __func__, u_ch, u_bw);
4892 			if (req_ch > 0 && req_bw > REQ_BW_NONE) {
4893 				/* change_chbw with specific channel and specific bw, goto update_bss_chbw directly */
4894 				goto update_bss_chbw;
4895 			}
4896 		} else
4897 			goto update_bss_chbw;
4898 
4899 choose_chbw:
4900 		by_int_info = req_ch == REQ_CH_INT_INFO ? 1 : 0;
4901 		req_ch = req_ch > 0 ? req_ch : 0;
4902 		max_bw = req_bw > REQ_BW_NONE ? req_bw : CHANNEL_WIDTH_20;
4903 		for (i = 0; i < dvobj->iface_nums; i++) {
4904 			if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4905 				continue;
4906 			iface = dvobj->padapters[i];
4907 			mlmeext = &(iface->mlmeextpriv);
4908 
4909 			if (req_bw <= REQ_BW_NONE) {
4910 				if (req_bw == REQ_BW_ORI) {
4911 					if (max_bw < iface->mlmepriv.ori_chandef.bw)
4912 						max_bw = iface->mlmepriv.ori_chandef.bw;
4913 				} else {
4914 					if (max_bw < cur_ie_bw[i])
4915 						max_bw = cur_ie_bw[i];
4916 				}
4917 			}
4918 
4919 			if (MSTATE_AP_NUM(&mstate) || MSTATE_MESH_NUM(&mstate)) {
4920 				if (ori_ch == 0)
4921 					ori_ch = mlmeext->chandef.chan;
4922 				else if (ori_ch != mlmeext->chandef.chan)
4923 					rtw_warn_on(1);
4924 			} else {
4925 				if (ori_ch == 0)
4926 					ori_ch = cur_ie_ch[i];
4927 				else if (ori_ch != cur_ie_ch[i])
4928 					rtw_warn_on(1);
4929 			}
4930 		}
4931 
4932 		ch_avail = rtw_ap_choose_chbw(adapter, req_ch, max_bw
4933 			, ori_ch, &u_ch, &u_bw, &u_offset, by_int_info, ifbmp_all_mesh, __func__);
4934 		if (ch_avail == _FALSE)
4935 			goto exit;
4936 
4937 update_bss_chbw:
4938 		for (i = 0; i < dvobj->iface_nums; i++) {
4939 			if (!(ifbmp & BIT(i)) || !dvobj->padapters[i])
4940 				continue;
4941 			iface = dvobj->padapters[i];
4942 
4943 			dec_ch[i] = u_ch;
4944 			if (dec_bw[i] > u_bw)
4945 				dec_bw[i] = u_bw;
4946 			if (dec_bw[i] == CHANNEL_WIDTH_20)
4947 				dec_offset[i] = CHAN_OFFSET_NO_EXT;
4948 			else
4949 				dec_offset[i] = u_offset;
4950 
4951 			#ifdef CONFIG_RTW_MESH
4952 			if (MLME_IS_MESH(iface))
4953 				rtw_mesh_adjust_chbw(dec_ch[i], &dec_bw[i], &dec_offset[i]);
4954 			#endif
4955 		}
4956 
4957 		set_u_ch = _TRUE;
4958 	}
4959 
4960 	ifbmp_ch_changed = rtw_ap_update_chbw_by_ifbmp(dvobj, ifbmp
4961 							, cur_ie_ch, cur_ie_bw, cur_ie_offset
4962 							, dec_ch, dec_bw, dec_offset
4963 							, __func__);
4964 
4965 	if (u_ch != 0)
4966 		RTW_INFO("%s union:%u,%u,%u\n", __func__, u_ch, u_bw, u_offset);
4967 
4968 	if (rtw_mi_check_fwstate(adapter, WIFI_UNDER_SURVEY)) {
4969 		/* scanning, leave ch setting to scan state machine */
4970 		set_u_ch = _FALSE;
4971 	}
4972 
4973 	if (set_u_ch == _TRUE) {
4974 		chdef->chan= u_ch;
4975 		chdef->bw = u_bw;
4976 		chdef->offset= u_offset;
4977 	}
4978 exit:
4979 	return ifbmp_ch_changed;
4980 }
4981 
rtw_ap_sta_states_check(_adapter * adapter)4982 u8 rtw_ap_sta_states_check(_adapter *adapter)
4983 {
4984 	struct sta_info *psta;
4985 	struct sta_priv *pstapriv = &adapter->stapriv;
4986 	_list *plist, *phead;
4987 	u8 rst = _FALSE;
4988 
4989 	if (!MLME_IS_AP(adapter) && !MLME_IS_MESH(adapter))
4990 		return _FALSE;
4991 
4992 	if (pstapriv->auth_list_cnt !=0)
4993 		return _TRUE;
4994 
4995 	_rtw_spinlock_bh(&pstapriv->asoc_list_lock);
4996 	phead = &pstapriv->asoc_list;
4997 	plist = get_next(phead);
4998 	while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4999 
5000 		psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
5001 		plist = get_next(plist);
5002 
5003 		if (!(psta->state & WIFI_ASOC_STATE)) {
5004 			RTW_INFO(ADPT_FMT"- SoftAP/Mesh - sta under linking, its state = 0x%x\n", ADPT_ARG(adapter), psta->state);
5005 			rst = _TRUE;
5006 			break;
5007 		} else if (psta->state & WIFI_UNDER_KEY_HANDSHAKE) {
5008 			RTW_INFO(ADPT_FMT"- SoftAP/Mesh - sta under key handshaking, its state = 0x%x\n", ADPT_ARG(adapter), psta->state);
5009 			rst = _TRUE;
5010 			break;
5011 		}
5012 	}
5013 	_rtw_spinunlock_bh(&pstapriv->asoc_list_lock);
5014 	return rst;
5015 }
5016 
rtw_ap_parse_sta_capability(_adapter * adapter,struct sta_info * sta,u8 * cap)5017 void rtw_ap_parse_sta_capability(_adapter *adapter, struct sta_info *sta, u8 *cap)
5018 {
5019 	sta->capability = RTW_GET_LE16(cap);
5020 	if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
5021 		sta->flags |= WLAN_STA_SHORT_PREAMBLE;
5022 	else
5023 		sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
5024 }
5025 
rtw_ap_parse_sta_supported_rates(_adapter * adapter,struct sta_info * sta,u8 * tlv_ies,u16 tlv_ies_len)5026 u16 rtw_ap_parse_sta_supported_rates(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
5027 {
5028 	u8 rate_set[12];
5029 	u8 rate_num;
5030 	int i;
5031 	u16 status = _STATS_SUCCESSFUL_;
5032 
5033 	rtw_ies_get_supported_rate(tlv_ies, tlv_ies_len, rate_set, &rate_num);
5034 	if (rate_num == 0) {
5035 		RTW_INFO(FUNC_ADPT_FMT" sta "MAC_FMT" with no supported rate\n"
5036 			, FUNC_ADPT_ARG(adapter), MAC_ARG(sta->phl_sta->mac_addr));
5037 		status = _STATS_FAILURE_;
5038 		goto exit;
5039 	}
5040 
5041 	_rtw_memcpy(sta->bssrateset, rate_set, rate_num);
5042 	sta->bssratelen = rate_num;
5043 
5044 	if (MLME_IS_AP(adapter)) {
5045 		/* this function force only CCK rates to be bassic rate... */
5046 		UpdateBrateTblForSoftAP(sta->bssrateset, sta->bssratelen);
5047 	}
5048 
5049 	/* if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) */ /* ? */
5050 	sta->flags |= WLAN_STA_NONERP;
5051 	for (i = 0; i < sta->bssratelen; i++) {
5052 		if ((sta->bssrateset[i] & 0x7f) > 22) {
5053 			sta->flags &= ~WLAN_STA_NONERP;
5054 			break;
5055 		}
5056 	}
5057 
5058 exit:
5059 	return status;
5060 }
5061 
rtw_ap_parse_sta_security_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)5062 u16 rtw_ap_parse_sta_security_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
5063 {
5064 	struct security_priv *sec = &adapter->securitypriv;
5065 	u8 *wpa_ie;
5066 	int wpa_ie_len;
5067 	int group_cipher = 0, pairwise_cipher = 0, gmcs = 0;
5068 	u32 akm = 0;
5069 	u8 mfp_opt = MFP_NO;
5070 	u8 spp_opt = 0;
5071 	u16 status = _STATS_SUCCESSFUL_;
5072 
5073 	sta->dot8021xalg = 0;
5074 	sta->wpa_psk = 0;
5075 	sta->wpa_group_cipher = 0;
5076 	sta->wpa2_group_cipher = 0;
5077 	sta->wpa_pairwise_cipher = 0;
5078 	sta->wpa2_pairwise_cipher = 0;
5079 	sta->akm_suite_type = 0;
5080 	_rtw_memset(sta->wpa_ie, 0, sizeof(sta->wpa_ie));
5081 
5082 	if ((sec->wpa_psk & BIT(1)) && elems->rsn_ie) {
5083 		wpa_ie = elems->rsn_ie;
5084 		wpa_ie_len = elems->rsn_ie_len;
5085 
5086 		if (rtw_parse_wpa2_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, &gmcs, &akm, &mfp_opt, &spp_opt) == _SUCCESS) {
5087 			sta->dot8021xalg = 1;/* psk, todo:802.1x */
5088 			sta->wpa_psk |= BIT(1);
5089 
5090 			/* RSN optional field absent; the validation is already checked in rtw_rsne_info_parse() */
5091 			if (!group_cipher) {
5092 				RTW_INFO("STA lacks WPA2 Group Suite Cipher --> Default\n");
5093 				group_cipher = sec->wpa2_group_cipher;
5094 			}
5095 			if (!pairwise_cipher) {
5096 				RTW_INFO("STA lacks WPA2 Pairwise Suite Cipher --> Default\n");
5097 				pairwise_cipher = sec->wpa2_pairwise_cipher;
5098 			}
5099 			if (!akm) {
5100 				RTW_INFO("STA lacks WPA2 AKM Cipher --> Default\n");
5101 				akm = sec->akmp;
5102 			}
5103 
5104 			sta->wpa2_group_cipher = group_cipher & sec->wpa2_group_cipher;
5105 			sta->wpa2_pairwise_cipher = pairwise_cipher & sec->wpa2_pairwise_cipher;
5106 			sta->akm_suite_type = akm;
5107 
5108 			if (MLME_IS_AP(adapter) && (CHECK_BIT(WLAN_AKM_TYPE_SAE, akm)) && (MFP_NO == mfp_opt)) {
5109 				status = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
5110 				goto exit;
5111 			}
5112 
5113 			/* RSN optional field exists but no match */
5114 			if (!sta->wpa2_group_cipher) {
5115 				status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
5116 				goto exit;
5117 			}
5118 			if (!sta->wpa2_pairwise_cipher) {
5119 				status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
5120 				goto exit;
5121 			}
5122 			if (MLME_IS_AP(adapter) && (!CHECK_BIT(sec->akmp, akm))) {
5123 				status = WLAN_STATUS_AKMP_NOT_VALID;
5124 				goto exit;
5125 			}
5126 		}
5127 		else {
5128 			status = WLAN_STATUS_INVALID_IE;
5129 			goto exit;
5130 		}
5131 	}
5132 	else if ((sec->wpa_psk & BIT(0)) && elems->wpa_ie) {
5133 		wpa_ie = elems->wpa_ie;
5134 		wpa_ie_len = elems->wpa_ie_len;
5135 
5136 		if (rtw_parse_wpa_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
5137 			sta->dot8021xalg = 1;/* psk, todo:802.1x */
5138 			sta->wpa_psk |= BIT(0);
5139 
5140 			sta->wpa_group_cipher = group_cipher & sec->wpa_group_cipher;
5141 			sta->wpa_pairwise_cipher = pairwise_cipher & sec->wpa_pairwise_cipher;
5142 
5143 			if (!sta->wpa_group_cipher) {
5144 				status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
5145 				goto exit;
5146 			}
5147 
5148 			if (!sta->wpa_pairwise_cipher) {
5149 				status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
5150 				goto exit;
5151 			}
5152 		} else {
5153 			status = WLAN_STATUS_INVALID_IE;
5154 			goto exit;
5155 		}
5156 
5157 	} else {
5158 		wpa_ie = NULL;
5159 		wpa_ie_len = 0;
5160 	}
5161 
5162 	if (sec->dot11PrivacyAlgrthm != _NO_PRIVACY_) {
5163 		/*check if amsdu is allowed */
5164 		if (rtw_check_amsdu_disable(adapter->registrypriv.amsdu_mode, spp_opt) == _TRUE)
5165 			sta->flags |= WLAN_STA_AMSDU_DISABLE;
5166 	}
5167 	if ((sec->mfp_opt == MFP_REQUIRED && mfp_opt < MFP_OPTIONAL)
5168 		|| (mfp_opt == MFP_REQUIRED && sec->mfp_opt < MFP_OPTIONAL)
5169 	) {
5170 		status = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
5171 		goto exit;
5172 	}
5173 
5174 #ifdef CONFIG_RTW_MESH
5175 	if (MLME_IS_MESH(adapter)) {
5176 		/* MFP is mandatory for secure mesh */
5177 		if (adapter->mesh_info.mesh_auth_id)
5178 			sta->flags |= WLAN_STA_MFP;
5179 	} else
5180 #endif
5181 	if (sec->mfp_opt >= MFP_OPTIONAL && mfp_opt >= MFP_OPTIONAL)
5182 		sta->flags |= WLAN_STA_MFP;
5183 
5184 #ifdef CONFIG_IEEE80211W
5185 	if ((sta->flags & WLAN_STA_MFP)
5186 		&& (sec->mfp_opt >= MFP_OPTIONAL && mfp_opt >= MFP_OPTIONAL)
5187 		&& security_type_bip_to_gmcs(sec->dot11wCipher) != gmcs
5188 	) {
5189 		status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
5190 		goto exit;
5191 	}
5192 #endif
5193 
5194 #ifdef CONFIG_IOCTL_CFG80211
5195 	if (MLME_IS_AP(adapter) &&
5196 		(sec->auth_type == MLME_AUTHTYPE_SAE) &&
5197 		(CHECK_BIT(WLAN_AKM_TYPE_SAE, sta->akm_suite_type)) &&
5198 		(WLAN_AUTH_OPEN == sta->authalg)) {
5199 		/* WPA3-SAE, PMK caching */
5200 		if (rtw_cached_pmkid(adapter, sta->phl_sta->mac_addr) == -1) {
5201 			RTW_INFO("SAE: No PMKSA cache entry found\n");
5202 			status = WLAN_STATUS_INVALID_PMKID;
5203 			goto exit;
5204 		} else {
5205 			RTW_INFO("SAE: PMKSA cache entry found\n");
5206 		}
5207 	}
5208 #endif /* CONFIG_IOCTL_CFG80211 */
5209 
5210 	if (!MLME_IS_AP(adapter))
5211 		goto exit;
5212 
5213 	sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
5214 	/* if (hapd->conf->wps_state && wpa_ie == NULL) { */ /* todo: to check ap if supporting WPS */
5215 	if (wpa_ie == NULL) {
5216 		if (elems->wps_ie) {
5217 			RTW_INFO("STA included WPS IE in "
5218 				 "(Re)Association Request - assume WPS is "
5219 				 "used\n");
5220 			sta->flags |= WLAN_STA_WPS;
5221 			/* wpabuf_free(sta->wps_ie); */
5222 			/* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
5223 			/*				elems.wps_ie_len - 4); */
5224 		} else {
5225 			RTW_INFO("STA did not include WPA/RSN IE "
5226 				 "in (Re)Association Request - possible WPS "
5227 				 "use\n");
5228 			sta->flags |= WLAN_STA_MAYBE_WPS;
5229 		}
5230 
5231 		/* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
5232 		/* that the selected registrar of AP is _FLASE */
5233 		if ((sec->wpa_psk > 0)
5234 			&& (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))
5235 		) {
5236 			struct mlme_priv *mlme = &adapter->mlmepriv;
5237 
5238 			if (mlme->wps_beacon_ie) {
5239 				u8 selected_registrar = 0;
5240 
5241 				rtw_get_wps_attr_content(mlme->wps_beacon_ie, mlme->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
5242 
5243 				if (!selected_registrar) {
5244 					RTW_INFO("selected_registrar is _FALSE , or AP is not ready to do WPS\n");
5245 					status = _STATS_UNABLE_HANDLE_STA_;
5246 					goto exit;
5247 				}
5248 			}
5249 		}
5250 
5251 	} else {
5252 		int copy_len;
5253 
5254 		if (sec->wpa_psk == 0) {
5255 			RTW_INFO("STA " MAC_FMT
5256 				": WPA/RSN IE in association request, but AP don't support WPA/RSN\n",
5257 				MAC_ARG(sta->phl_sta->mac_addr));
5258 			status = WLAN_STATUS_INVALID_IE;
5259 			goto exit;
5260 		}
5261 
5262 		if (elems->wps_ie) {
5263 			RTW_INFO("STA included WPS IE in "
5264 				 "(Re)Association Request - WPS is "
5265 				 "used\n");
5266 			sta->flags |= WLAN_STA_WPS;
5267 			copy_len = 0;
5268 		} else
5269 			copy_len = ((wpa_ie_len + 2) > sizeof(sta->wpa_ie)) ? (sizeof(sta->wpa_ie)) : (wpa_ie_len + 2);
5270 
5271 		if (copy_len > 0)
5272 			_rtw_memcpy(sta->wpa_ie, wpa_ie - 2, copy_len);
5273 	}
5274 
5275 exit:
5276 	return status;
5277 }
5278 
rtw_ap_parse_sta_wmm_ie(_adapter * adapter,struct sta_info * sta,u8 * tlv_ies,u16 tlv_ies_len)5279 void rtw_ap_parse_sta_wmm_ie(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
5280 {
5281 	struct mlme_priv *mlme = &adapter->mlmepriv;
5282 	unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
5283 	u8 *p;
5284 
5285 	sta->flags &= ~WLAN_STA_WME;
5286 	sta->qos_option = 0;
5287 	sta->qos_info = 0;
5288 	sta->has_legacy_ac = _TRUE;
5289 	sta->uapsd_vo = 0;
5290 	sta->uapsd_vi = 0;
5291 	sta->uapsd_be = 0;
5292 	sta->uapsd_bk = 0;
5293 
5294 	if (!mlme->qospriv.qos_option)
5295 		goto exit;
5296 
5297 #ifdef CONFIG_RTW_MESH
5298 	if (MLME_IS_MESH(adapter)) {
5299 		/* QoS is mandatory in mesh */
5300 		sta->flags |= WLAN_STA_WME;
5301 	}
5302 #endif
5303 
5304 	p = rtw_get_ie_ex(tlv_ies, tlv_ies_len, WLAN_EID_VENDOR_SPECIFIC, WMM_IE, 6, NULL, NULL);
5305 	if (!p)
5306 		goto exit;
5307 
5308 	sta->flags |= WLAN_STA_WME;
5309 	sta->qos_option = 1;
5310 	sta->qos_info = *(p + 8);
5311 	sta->max_sp_len = (sta->qos_info >> 5) & 0x3;
5312 
5313 	if ((sta->qos_info & 0xf) != 0xf)
5314 		sta->has_legacy_ac = _TRUE;
5315 	else
5316 		sta->has_legacy_ac = _FALSE;
5317 
5318 	if (sta->qos_info & 0xf) {
5319 		if (sta->qos_info & BIT(0))
5320 			sta->uapsd_vo = BIT(0) | BIT(1);
5321 		else
5322 			sta->uapsd_vo = 0;
5323 
5324 		if (sta->qos_info & BIT(1))
5325 			sta->uapsd_vi = BIT(0) | BIT(1);
5326 		else
5327 			sta->uapsd_vi = 0;
5328 
5329 		if (sta->qos_info & BIT(2))
5330 			sta->uapsd_bk = BIT(0) | BIT(1);
5331 		else
5332 			sta->uapsd_bk = 0;
5333 
5334 		if (sta->qos_info & BIT(3))
5335 			sta->uapsd_be = BIT(0) | BIT(1);
5336 		else
5337 			sta->uapsd_be = 0;
5338 	}
5339 
5340 exit:
5341 	return;
5342 }
5343 
rtw_ap_parse_sta_ht_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)5344 void rtw_ap_parse_sta_ht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
5345 {
5346 	struct mlme_priv *mlme = &adapter->mlmepriv;
5347 
5348 	sta->flags &= ~WLAN_STA_HT;
5349 
5350 #ifdef CONFIG_80211N_HT
5351 	if (mlme->htpriv.ht_option == _FALSE)
5352 		goto exit;
5353 
5354 	/* save HT capabilities in the sta object */
5355 	_rtw_memset(&sta->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
5356 	if (elems->ht_capabilities && elems->ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
5357 		sta->flags |= WLAN_STA_HT;
5358 		sta->flags |= WLAN_STA_WME;
5359 		_rtw_memcpy(&sta->htpriv.ht_cap, elems->ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
5360 
5361 		if (elems->ht_operation && elems->ht_operation_len == HT_OP_IE_LEN) {
5362 			_rtw_memcpy(sta->htpriv.ht_op, elems->ht_operation, HT_OP_IE_LEN);
5363 			sta->htpriv.op_present = 1;
5364 		}
5365 	}
5366 exit:
5367 #endif
5368 
5369 	return;
5370 }
5371 
rtw_ap_parse_sta_vht_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)5372 void rtw_ap_parse_sta_vht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
5373 {
5374 	struct mlme_priv *mlme = &adapter->mlmepriv;
5375 
5376 	sta->flags &= ~WLAN_STA_VHT;
5377 
5378 #ifdef CONFIG_80211AC_VHT
5379 	if (mlme->vhtpriv.vht_option == _FALSE)
5380 		goto exit;
5381 
5382 	_rtw_memset(&sta->vhtpriv, 0, sizeof(struct vht_priv));
5383 	if (elems->vht_capabilities && elems->vht_capabilities_len == VHT_CAP_IE_LEN) {
5384 		sta->flags |= WLAN_STA_VHT;
5385 		_rtw_memcpy(sta->vhtpriv.vht_cap, elems->vht_capabilities, VHT_CAP_IE_LEN);
5386 
5387 		if (elems->vht_operation && elems->vht_operation_len== VHT_OP_IE_LEN) {
5388 			_rtw_memcpy(sta->vhtpriv.vht_op, elems->vht_operation, VHT_OP_IE_LEN);
5389 			sta->vhtpriv.op_present = 1;
5390 		}
5391 
5392 		if (elems->vht_op_mode_notify && elems->vht_op_mode_notify_len == 1) {
5393 			_rtw_memcpy(&sta->vhtpriv.vht_op_mode_notify, elems->vht_op_mode_notify, 1);
5394 			sta->vhtpriv.notify_present = 1;
5395 		}
5396 	}
5397 exit:
5398 #endif
5399 
5400 	return;
5401 }
5402 
rtw_ap_parse_sta_he_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)5403 void rtw_ap_parse_sta_he_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
5404 {
5405 	struct mlme_priv *mlme = &adapter->mlmepriv;
5406 
5407 	sta->flags &= ~WLAN_STA_HE;
5408 
5409 #ifdef CONFIG_80211AX_HE
5410 	if (mlme->hepriv.he_option == _FALSE)
5411 		goto exit;
5412 
5413 	_rtw_memset(&sta->hepriv, 0, sizeof(struct he_priv));
5414 	if (elems->he_capabilities && (elems->he_capabilities_len <= HE_CAP_ELE_MAX_LEN)) {
5415 		sta->flags |= WLAN_STA_HE;
5416 		_rtw_memcpy(sta->hepriv.he_cap, elems->he_capabilities, elems->he_capabilities_len);
5417 
5418 		if (elems->he_operation && (elems->he_operation_len <= HE_OPER_ELE_MAX_LEN)) {
5419 			_rtw_memcpy(sta->hepriv.he_op, elems->he_operation, elems->he_operation_len);
5420 			sta->hepriv.op_present = 1;
5421 		}
5422 
5423 #if 0
5424 		if (elems->vht_op_mode_notify && elems->vht_op_mode_notify_len == 1) {
5425 			_rtw_memcpy(&sta->vhtpriv.vht_op_mode_notify, elems->vht_op_mode_notify, 1);
5426 			sta->vhtpriv.notify_present = 1;
5427 		}
5428 #endif
5429 	}
5430 exit:
5431 #endif
5432 
5433 	return;
5434 }
5435 
rtw_ap_parse_sta_multi_ap_ie(_adapter * adapter,struct sta_info * sta,u8 * ies,int ies_len)5436 void rtw_ap_parse_sta_multi_ap_ie(_adapter *adapter, struct sta_info *sta, u8 *ies, int ies_len)
5437 {
5438 	sta->flags &= ~WLAN_STA_MULTI_AP;
5439 
5440 #ifdef CONFIG_RTW_MULTI_AP
5441 	if (adapter->multi_ap
5442 		&& (rtw_get_multi_ap_ie_ext(ies, ies_len) & MULTI_AP_BACKHAUL_STA)
5443 	) {
5444 		if (adapter->multi_ap & MULTI_AP_BACKHAUL_BSS) /* with backhaul bss, enable WDS */
5445 			sta->flags |= WLAN_STA_MULTI_AP | WLAN_STA_WDS;
5446 		else if (adapter->multi_ap & MULTI_AP_FRONTHAUL_BSS) /* fronthaul bss only */
5447 			sta->flags |= WLAN_STA_MULTI_AP;
5448 	}
5449 #endif
5450 }
5451 
5452 #if CONFIG_RTW_AP_DATA_BMC_TO_UC
rtw_ap_data_bmc_to_uc(_adapter * adapter,const u8 * da,const u8 * sa,const u8 * ori_ta,u16 os_qid,_list * b2u_list)5453 static bool rtw_ap_data_bmc_to_uc(_adapter *adapter
5454 	, const u8 *da, const u8 *sa, const u8 *ori_ta
5455 	, u16 os_qid, _list *b2u_list)
5456 {
5457 	struct sta_priv *stapriv = &adapter->stapriv;
5458 	struct xmit_priv *xmitpriv = &adapter->xmitpriv;
5459 	_list *head, *list;
5460 	struct sta_info *sta;
5461 	char b2u_sta_id[NUM_STA];
5462 	u8 b2u_sta_num = 0;
5463 	bool bmc_need = _FALSE;
5464 	int i;
5465 
5466 	 _rtw_spinlock_bh(&stapriv->asoc_list_lock);
5467 	head = &stapriv->asoc_list;
5468 	list = get_next(head);
5469 
5470 	while ((rtw_end_of_queue_search(head, list)) == _FALSE) {
5471 		int stainfo_offset;
5472 
5473 		sta = LIST_CONTAINOR(list, struct sta_info, asoc_list);
5474 		list = get_next(list);
5475 
5476 		stainfo_offset = rtw_stainfo_offset(stapriv, sta);
5477 		if (stainfo_offset_valid(stainfo_offset))
5478 			b2u_sta_id[b2u_sta_num++] = stainfo_offset;
5479 	}
5480 	_rtw_spinunlock_bh(&stapriv->asoc_list_lock);
5481 
5482 	if (!b2u_sta_num)
5483 		goto exit;
5484 
5485 	for (i = 0; i < b2u_sta_num; i++) {
5486 		struct xmit_frame *b2uframe = NULL;
5487 		struct pkt_attrib *attrib;
5488 
5489 		sta = rtw_get_stainfo_by_offset(stapriv, b2u_sta_id[i]);
5490 		if (!(sta->state & WIFI_ASOC_STATE)
5491 			|| _rtw_memcmp(sta->phl_sta->mac_addr, sa, ETH_ALEN) == _TRUE
5492 			|| (ori_ta && _rtw_memcmp(sta->phl_sta->mac_addr, ori_ta, ETH_ALEN) == _TRUE)
5493 			|| is_broadcast_mac_addr(sta->phl_sta->mac_addr)
5494 			|| is_zero_mac_addr(sta->phl_sta->mac_addr))
5495 			continue;
5496 
5497 		if (core_tx_alloc_xmitframe(adapter, &b2uframe, os_qid) == FAIL) {
5498 			bmc_need = _TRUE;
5499 			break;
5500 		}
5501 
5502 		attrib = &b2uframe->attrib;
5503 
5504 		_rtw_memcpy(attrib->ra, sta->phl_sta->mac_addr, ETH_ALEN);
5505 		_rtw_memcpy(attrib->ta, adapter_mac_addr(adapter), ETH_ALEN);
5506 		#ifdef CONFIG_RTW_WDS
5507 		if (adapter_use_wds(adapter) && (sta->flags & WLAN_STA_WDS)) {
5508 			_rtw_memcpy(attrib->dst, da, ETH_ALEN);
5509 			attrib->wds = 1;
5510 		} else
5511 		#endif
5512 			_rtw_memcpy(attrib->dst, attrib->ra, ETH_ALEN);
5513 		_rtw_memcpy(attrib->src, sa, ETH_ALEN);
5514 
5515 		rtw_list_insert_tail(&b2uframe->list, b2u_list);
5516 	}
5517 
5518 exit:
5519 	return bmc_need;
5520 }
5521 
dump_ap_b2u_flags(void * sel,_adapter * adapter)5522 void dump_ap_b2u_flags(void *sel, _adapter *adapter)
5523 {
5524 	RTW_PRINT_SEL(sel, "%4s %4s\n", "src", "fwd");
5525 	RTW_PRINT_SEL(sel, "0x%02x 0x%02x\n", adapter->b2u_flags_ap_src, adapter->b2u_flags_ap_fwd);
5526 }
5527 #endif /* CONFIG_RTW_AP_DATA_BMC_TO_UC */
5528 
rtw_ap_nexthop_resolve(_adapter * adapter,struct xmit_frame * xframe)5529 static int rtw_ap_nexthop_resolve(_adapter *adapter, struct xmit_frame *xframe)
5530 {
5531 	struct pkt_attrib *attrib = &xframe->attrib;
5532 	int ret = _SUCCESS;
5533 
5534 #ifdef CONFIG_RTW_WDS
5535 	if (adapter_use_wds(adapter)) {
5536 		if (rtw_wds_nexthop_lookup(adapter, attrib->dst, attrib->ra) == 0) {
5537 			if (_rtw_memcmp(attrib->dst, attrib->ra, ETH_ALEN) == _FALSE)
5538 				attrib->wds = 1;
5539 		} else {
5540 			ret = _FAIL;
5541 		}
5542 	} else
5543 #endif
5544 		_rtw_memcpy(attrib->ra, attrib->dst, ETH_ALEN);
5545 
5546 	return ret;
5547 }
5548 
5549 #ifdef CONFIG_RTW_WDS
rtw_ap_data_flood_for_unknown_da(_adapter * adapter,const u8 * da,const u8 * sa,const u8 * ori_ta,u16 os_qid,_list * f_list)5550 static void rtw_ap_data_flood_for_unknown_da(_adapter *adapter, const u8 *da,
5551 					     const u8 *sa, const u8 *ori_ta,
5552 					     u16 os_qid, _list *f_list)
5553 {
5554 	struct sta_priv *stapriv = &adapter->stapriv;
5555 	struct xmit_priv *xmitpriv = &adapter->xmitpriv;
5556 	_list *head, *list;
5557 	struct sta_info *sta;
5558 	char sta_id[NUM_STA];
5559 	u8 sta_num = 0;
5560 	int i;
5561 
5562 	_rtw_spinlock_bh(&stapriv->asoc_list_lock);
5563 	head = &stapriv->asoc_list;
5564 	list = get_next(head);
5565 
5566 	while ((rtw_end_of_queue_search(head, list)) == _FALSE) {
5567 		int stainfo_offset;
5568 
5569 		sta = LIST_CONTAINOR(list, struct sta_info, asoc_list);
5570 		list = get_next(list);
5571 
5572 		stainfo_offset = rtw_stainfo_offset(stapriv, sta);
5573 		if (stainfo_offset_valid(stainfo_offset))
5574 			sta_id[sta_num++] = stainfo_offset;
5575 	}
5576 
5577 	_rtw_spinunlock_bh(&stapriv->asoc_list_lock);
5578 
5579 	if (!sta_num)
5580 		goto exit;
5581 
5582 	for (i = 0; i < sta_num; i++) {
5583 		struct xmit_frame *frame;
5584 		struct pkt_attrib *attrib;
5585 
5586 		sta = rtw_get_stainfo_by_offset(stapriv, sta_id[i]);
5587 		if (!(sta->state & WIFI_ASOC_STATE)
5588 		    || !(sta->flags & WLAN_STA_WDS)
5589 		    || _rtw_memcmp(sta->phl_sta->mac_addr, sa, ETH_ALEN) == _TRUE
5590 		    || (ori_ta && _rtw_memcmp(sta->phl_sta->mac_addr, ori_ta, ETH_ALEN) == _TRUE)
5591 		    || is_broadcast_mac_addr(sta->phl_sta->mac_addr)
5592 		    || is_zero_mac_addr(sta->phl_sta->mac_addr))
5593 			continue;
5594 
5595 		if (core_tx_alloc_xmitframe(adapter, &frame, os_qid) == FAIL)
5596 			break;
5597 
5598 		attrib = &frame->attrib;
5599 
5600 		_rtw_memcpy(attrib->ra, sta->phl_sta->mac_addr, ETH_ALEN);
5601 		_rtw_memcpy(attrib->ta, adapter_mac_addr(adapter), ETH_ALEN);
5602 		_rtw_memcpy(attrib->dst, da, ETH_ALEN);
5603 		_rtw_memcpy(attrib->src, sa, ETH_ALEN);
5604 		attrib->wds = 1;
5605 
5606 		rtw_list_insert_tail(&frame->list, f_list);
5607 	}
5608 
5609 exit:
5610 	return;
5611 }
5612 #endif /* CONFIG_RTW_WDS */
5613 
rtw_ap_addr_resolve(_adapter * adapter,u16 os_qid,struct xmit_frame * xframe,struct sk_buff * pkt,_list * f_list)5614 int rtw_ap_addr_resolve(_adapter *adapter, u16 os_qid, struct xmit_frame *xframe,
5615 			struct sk_buff *pkt, _list *f_list)
5616 {
5617 	struct pkt_file pktfile;
5618 	struct ethhdr etherhdr;
5619 	struct pkt_attrib *attrib;
5620 	u8 is_da_mcast;
5621 
5622 	int res = _SUCCESS;
5623 
5624 	_rtw_open_pktfile(pkt, &pktfile);
5625 	if (_rtw_pktfile_read(&pktfile, (u8 *)&etherhdr, ETH_HLEN) != ETH_HLEN) {
5626 		res = _FAIL;
5627 		goto exit;
5628 	}
5629 
5630 	xframe->pkt = pkt;
5631 #if defined(CONFIG_RTW_WDS) || CONFIG_RTW_AP_DATA_BMC_TO_UC
5632 	_rtw_init_listhead(f_list);
5633 #endif
5634 
5635 	is_da_mcast = IS_MCAST(etherhdr.h_dest);
5636 	if (is_da_mcast) {
5637 		#if CONFIG_RTW_AP_DATA_BMC_TO_UC
5638 		if (rtw_ap_src_b2u_policy_chk(adapter->b2u_flags_ap_src, etherhdr.h_dest)
5639 		    && adapter->registrypriv.wifi_spec == 0
5640 		    && adapter->xmitpriv.free_xmitframe_cnt > (NR_XMITFRAME / 4)) {
5641 			if (rtw_ap_data_bmc_to_uc(adapter, etherhdr.h_dest,
5642 						  etherhdr.h_source, NULL,
5643 						  os_qid, f_list) == 0) {
5644 				res = RTW_ORI_NO_NEED;
5645 				goto exit;
5646 			}
5647 		}
5648 		#endif
5649 	}
5650 
5651 	attrib = &xframe->attrib;
5652 
5653 	_rtw_memcpy(attrib->dst, etherhdr.h_dest, ETH_ALEN);
5654 	_rtw_memcpy(attrib->src, etherhdr.h_source, ETH_ALEN);
5655 	_rtw_memcpy(attrib->ta, adapter_mac_addr(adapter), ETH_ALEN);
5656 
5657 	if (is_da_mcast) {
5658 		_rtw_memcpy(attrib->ra, attrib->dst, ETH_ALEN);
5659 	} else {
5660 		res = rtw_ap_nexthop_resolve(adapter, xframe);
5661 		#ifdef CONFIG_RTW_WDS
5662 		if (res != _SUCCESS) {
5663 			/* unknown DA, flood frame to every WDS STA */
5664 			rtw_ap_data_flood_for_unknown_da(adapter, etherhdr.h_dest,
5665 							 etherhdr.h_source, NULL,
5666 							 os_qid, f_list);
5667 			res = RTW_ORI_NO_NEED;
5668 		}
5669 		#endif
5670 	}
5671 
5672 exit:
5673 	return res;
5674 }
5675 
rtw_ap_rx_data_validate_hdr(_adapter * adapter,union recv_frame * rframe,struct sta_info ** sta)5676 int rtw_ap_rx_data_validate_hdr(_adapter *adapter, union recv_frame *rframe, struct sta_info **sta)
5677 {
5678 	struct sta_priv *stapriv = &adapter->stapriv;
5679 	struct rx_pkt_attrib *rattrib = &rframe->u.hdr.attrib;
5680 	u8 *whdr = get_recvframe_data(rframe);
5681 	u8 is_ra_bmc = 0;
5682 	sint ret = _FAIL;
5683 
5684 	if (!(MLME_STATE(adapter) & WIFI_ASOC_STATE))
5685 		goto exit;
5686 
5687 	switch (rattrib->to_fr_ds) {
5688 	case 2:
5689 		if (IS_MCAST(GetAddr1Ptr(whdr)))
5690 			goto exit;
5691 		_rtw_memcpy(rattrib->ra, GetAddr1Ptr(whdr), ETH_ALEN);
5692 		_rtw_memcpy(rattrib->ta, get_addr2_ptr(whdr), ETH_ALEN);
5693 		_rtw_memcpy(rattrib->dst, GetAddr3Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
5694 		_rtw_memcpy(rattrib->src, get_addr2_ptr(whdr), ETH_ALEN);
5695 		_rtw_memcpy(rattrib->bssid, GetAddr1Ptr(whdr), ETH_ALEN);
5696 		break;
5697 	case 3:
5698 		is_ra_bmc = IS_MCAST(GetAddr1Ptr(whdr)) ? 1 : 0;
5699 		_rtw_memcpy(rattrib->ra, GetAddr1Ptr(whdr), ETH_ALEN);
5700 		_rtw_memcpy(rattrib->ta, get_addr2_ptr(whdr), ETH_ALEN);
5701 		_rtw_memcpy(rattrib->dst, GetAddr3Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
5702 		_rtw_memcpy(rattrib->src, GetAddr4Ptr(whdr), ETH_ALEN); /* may change after checking AMSDU subframe header */
5703 		if (!is_ra_bmc)
5704 			_rtw_memcpy(rattrib->bssid, GetAddr1Ptr(whdr), ETH_ALEN);
5705 		break;
5706 	default:
5707 		ret = RTW_RX_HANDLED; /* don't count for drop */
5708 		goto exit;
5709 	}
5710 
5711 	*sta = rtw_get_stainfo(stapriv, rattrib->ta);
5712 	if (*sta == NULL) {
5713 		if (!is_ra_bmc && !IS_RADAR_DETECTED(adapter_to_rfctl(adapter))) {
5714 			#ifndef CONFIG_CUSTOMER_ALIBABA_GENERAL
5715 			RTW_INFO(FUNC_ADPT_FMT" issue_deauth to "MAC_FMT" with reason(7), unknown TA\n"
5716 				, FUNC_ADPT_ARG(adapter), MAC_ARG(rattrib->ta));
5717 			issue_deauth(adapter, rattrib->ta, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5718 			#endif
5719 		}
5720 		ret = RTW_RX_HANDLED;
5721 		goto exit;
5722 	}
5723 
5724 #ifdef CONFIG_RTW_WDS_AUTO_EN
5725 	if (rattrib->to_fr_ds == 3 && !(sta->flags & WLAN_STA_WDS))
5726 		sta->flags |= WLAN_STA_WDS;
5727 #endif
5728 
5729 	process_pwrbit_data(adapter, rframe, *sta);
5730 
5731 	if ((get_frame_sub_type(whdr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE)
5732 		process_wmmps_data(adapter, rframe, *sta);
5733 
5734 	if (get_frame_sub_type(whdr) & BIT(6)) {
5735 		/* No data, will not indicate to upper layer, temporily count it here */
5736 		count_rx_stats(adapter, rframe, *sta);
5737 		ret = RTW_RX_HANDLED;
5738 		goto exit;
5739 	}
5740 
5741 	ret = _SUCCESS;
5742 
5743 exit:
5744 	return ret;
5745 }
5746 
rtw_ap_rx_msdu_act_check(union recv_frame * rframe,const u8 * da,const u8 * sa,u8 * msdu,enum rtw_rx_llc_hdl llc_hdl,struct xmit_frame ** fwd_frame,_list * f_list)5747 int rtw_ap_rx_msdu_act_check(union recv_frame *rframe
5748 	, const u8 *da, const u8 *sa
5749 	, u8 *msdu, enum rtw_rx_llc_hdl llc_hdl
5750 	, struct xmit_frame **fwd_frame, _list *f_list)
5751 {
5752 	_adapter *adapter = rframe->u.hdr.adapter;
5753 	struct rx_pkt_attrib *rattrib = &rframe->u.hdr.attrib;
5754 	struct rtw_wds_path *wpath;
5755 	u8 is_da_bmc = IS_MCAST(da);
5756 	u8 is_da_self = !is_da_bmc && _rtw_memcmp(da, adapter_mac_addr(adapter), ETH_ALEN);
5757 	u8 is_da_peer = 0;
5758 	int in_wds_tbl = 0;
5759 	u16 os_qid;
5760 	struct xmit_frame *xframe;
5761 	struct pkt_attrib *xattrib;
5762 	u8 fwd_ra[ETH_ALEN] = {0};
5763 	int act = 0;
5764 
5765 #ifdef CONFIG_RTW_WDS
5766 	/* update/create wds info for SA, RA */
5767 	if (adapter_use_wds(adapter)
5768 		&& (rframe->u.hdr.psta->state & WIFI_ASOC_STATE)
5769 		&& _rtw_memcmp(sa, rframe->u.hdr.psta->phl_sta->mac_addr, ETH_ALEN) == _FALSE
5770 	) {
5771 		rtw_rcu_read_lock();
5772 		wpath = rtw_wds_path_lookup(adapter, sa);
5773 		if (!wpath)
5774 			rtw_wds_path_add(adapter, sa, rframe->u.hdr.psta);
5775 		else {
5776 			rtw_wds_path_assign_nexthop(wpath, rframe->u.hdr.psta);
5777 			wpath->last_update = rtw_get_current_time();
5778 		}
5779 		rtw_rcu_read_unlock();
5780 	}
5781 #endif
5782 
5783 	/* SA is self, need no further process */
5784 	if (_rtw_memcmp(sa, adapter_mac_addr(adapter), ETH_ALEN) == _TRUE)
5785 		goto exit;
5786 
5787 	if (is_da_bmc) {
5788 		/* DA is bmc addr */
5789 		act |= RTW_RX_MSDU_ACT_INDICATE;
5790 		#if 0 /* TODO: ap_isolate */
5791 		if (adapter->mlmepriv.ap_isolate)
5792 			goto exit;
5793 		#endif
5794 		goto fwd_chk;
5795 
5796 	}
5797 
5798 	if (is_da_self) {
5799 		/* DA is self, indicate */
5800 		act |= RTW_RX_MSDU_ACT_INDICATE;
5801 		goto exit;
5802 	}
5803 
5804 	/* DA is not self */
5805 #ifdef CONFIG_RTW_WDS
5806 	if (adapter_use_wds(adapter))
5807 		in_wds_tbl = rtw_wds_nexthop_lookup(adapter, da, fwd_ra) == 0;
5808 #endif
5809 	if (!in_wds_tbl)
5810 		is_da_peer = rtw_get_stainfo(&adapter->stapriv, da) ? 1 : 0;
5811 
5812 	if (in_wds_tbl || is_da_peer) {
5813 		/* DA is known (peer or can be forwarded by peer) */
5814 		#if 0 /* TODO: ap_isolate */
5815 		if (adapter->mlmepriv.ap_isolate) {
5816 			#if defined(DBG_RX_DROP_FRAME)
5817 			RTW_INFO("DBG_RX_DROP_FRAME "FUNC_ADPT_FMT" DA("MAC_FMT") through peer, ap_isolate\n"
5818 				, FUNC_ADPT_ARG(adapter), MAC_ARG(da));
5819 			#endif
5820 			goto exit;
5821 		}
5822 		#endif
5823 		goto fwd_chk;
5824 	}
5825 
5826 	/* DA is unknown*/
5827 	act |= RTW_RX_MSDU_ACT_INDICATE;
5828 	#if 0 /* TODO: ap_isolate */
5829 	if (adapter->mlmepriv.ap_isolate) {
5830 		/*
5831 		* unknown DA and ap_isolate, indicate only
5832 		* (bridge will not forward packets to originating port)
5833 		*/
5834 		goto exit;
5835 	}
5836 	#endif
5837 
5838 fwd_chk:
5839 
5840 	if (adapter->stapriv.asoc_list_cnt <= 1)
5841 		goto exit;
5842 
5843 	os_qid = rtw_os_recv_select_queue(msdu, llc_hdl);
5844 
5845 #if defined(CONFIG_RTW_WDS) || CONFIG_RTW_AP_DATA_BMC_TO_UC
5846 	_rtw_init_listhead(f_list);
5847 #endif
5848 
5849 #if CONFIG_RTW_AP_DATA_BMC_TO_UC
5850 	if (is_da_bmc) {
5851 		if (rtw_ap_fwd_b2u_policy_chk(adapter->b2u_flags_ap_fwd, da, rattrib->to_fr_ds == 3 && !IS_MCAST(rattrib->ra))
5852 			&& adapter->registrypriv.wifi_spec == 0
5853 			&& adapter->xmitpriv.free_xmitframe_cnt > (NR_XMITFRAME / 4)
5854 		) {
5855 			if (rtw_ap_data_bmc_to_uc(adapter
5856 				, da, sa, rframe->u.hdr.psta->phl_sta->mac_addr
5857 				, os_qid, f_list) == 0
5858 			) {
5859 				if (!rtw_is_list_empty(f_list))
5860 					goto set_act_fwd;
5861 				else
5862 					goto exit;
5863 			}
5864 		}
5865 	} else
5866 #endif
5867 #ifdef CONFIG_RTW_WDS
5868 	if (adapter_use_wds(adapter) && !in_wds_tbl && !is_da_peer) {
5869 		/* unknown DA, flood frame to every WDS STA except receiving one */
5870 		rtw_ap_data_flood_for_unknown_da(adapter
5871 			, da, sa, rframe->u.hdr.psta->phl_sta->mac_addr
5872 			, os_qid, f_list);
5873 		if (!rtw_is_list_empty(f_list))
5874 			goto set_act_fwd;
5875 		else
5876 			goto exit;
5877 	} else
5878 #endif
5879 	;
5880 
5881 	if (core_tx_alloc_xmitframe(adapter, &xframe, os_qid) == FAIL) {
5882 		#ifdef DBG_TX_DROP_FRAME
5883 		RTW_INFO("DBG_TX_DROP_FRAME "FUNC_ADPT_FMT" core_tx_alloc_xmitframe fail\n"
5884 			, FUNC_ADPT_ARG(adapter));
5885 		#endif
5886 		goto exit;
5887 	}
5888 
5889 	xattrib = &xframe->attrib;
5890 
5891 	_rtw_memcpy(xattrib->dst, da, ETH_ALEN);
5892 	_rtw_memcpy(xattrib->src, sa, ETH_ALEN);
5893 	_rtw_memcpy(xattrib->ta, adapter_mac_addr(adapter), ETH_ALEN);
5894 
5895 	#ifdef CONFIG_RTW_WDS
5896 	if (in_wds_tbl && _rtw_memcmp(da, fwd_ra, ETH_ALEN) == _FALSE) {
5897 		_rtw_memcpy(xattrib->ra, fwd_ra, ETH_ALEN);
5898 		xattrib->wds = 1;
5899 	} else
5900 	#endif
5901 		_rtw_memcpy(xattrib->ra, da, ETH_ALEN);
5902 
5903 	*fwd_frame = xframe;
5904 
5905 #if defined(CONFIG_RTW_WDS) || CONFIG_RTW_AP_DATA_BMC_TO_UC
5906 set_act_fwd:
5907 #endif
5908 	act |= RTW_RX_MSDU_ACT_FORWARD;
5909 
5910 exit:
5911 	return act;
5912 }
5913 
5914 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
rtw_issue_action_token_req(_adapter * padapter,struct sta_info * pstat)5915 void rtw_issue_action_token_req(_adapter *padapter, struct sta_info *pstat)
5916 {
5917 	/* Token Request Format
5918 	 	Category code :		1 Byte
5919 		Action code : 		1 Byte
5920 		Element field: 		4 Bytes, the duration of data transmission requested for the station.
5921 	*/
5922 
5923 	u8 val = 0x0;
5924 	u8 category = RTW_WLAN_CATEGORY_TBTX;
5925 	u32 tbtx_duration = TBTX_TX_DURATION*1000;
5926 	u8 *pframe;
5927 	unsigned short *fctrl;
5928 	struct xmit_frame		*pmgntframe;
5929 	struct pkt_attrib		*pattrib;
5930 	struct rtw_ieee80211_hdr	*pwlanhdr;
5931 	struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5932 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5933 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5934 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
5935 	WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
5936 
5937 
5938 	if (rtw_rfctl_is_tx_blocked_by_ch_waiting(adapter_to_rfctl(padapter)))
5939 		return;
5940 
5941 	RTW_DBG("%s: %6ph\n", __FUNCTION__, pstat->phl_sta->mac_addr);
5942 	pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5943 	if (pmgntframe == NULL)
5944 		return;
5945 
5946 	/* update attribute */
5947 	pattrib = &pmgntframe->attrib;
5948 	update_mgnt_tx_rate(padapter, IEEE80211_OFDM_RATE_24MB); // issue action request using OFDM rate? 20190320 Bruce add
5949 	update_mgntframe_attrib(padapter, pattrib);
5950 
5951 	_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5952 
5953 	pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5954 	pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5955 
5956 	fctrl = &(pwlanhdr->frame_ctl);
5957 	*(fctrl) = 0;
5958 
5959 	_rtw_memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->phl_sta->mac_addr, ETH_ALEN);
5960 	_rtw_memcpy((void *)get_addr2_ptr(pwlanhdr), adapter_mac_addr(padapter), ETH_ALEN);
5961 	_rtw_memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5962 
5963 
5964 	SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5965 	pmlmeext->mgnt_seq++;
5966 	set_frame_sub_type(pframe, WIFI_ACTION);
5967 
5968 	pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5969 	pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5970 
5971 	pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
5972 	pframe = rtw_set_fixed_ie(pframe, 1, &(val), &(pattrib->pktlen));
5973 	pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(tbtx_duration), &(pattrib->pktlen));
5974 
5975 	pattrib->last_txcmdsz = pattrib->pktlen;
5976 	padapter->stapriv.last_token_holder = pstat;
5977 	dump_mgntframe(padapter, pmgntframe);
5978 
5979 }
5980 #endif	/* CONFIG_RTW_TOKEN_BASED_XMIT */
5981 
rtw_ap_set_sta_wmode(_adapter * padapter,struct sta_info * sta)5982 void rtw_ap_set_sta_wmode(_adapter *padapter, struct sta_info *sta)
5983 {
5984 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5985 	WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
5986 	enum wlan_mode network_type = WLAN_MD_INVALID;
5987 
5988 #ifdef CONFIG_80211AX_HE
5989 	if (sta->hepriv.he_option == _TRUE)
5990 		network_type = WLAN_MD_11AX;
5991 #endif
5992 #ifdef CONFIG_80211AC_VHT
5993 	if (network_type == WLAN_MD_INVALID) {
5994 		if (sta->vhtpriv.vht_option == _TRUE)
5995 			network_type = WLAN_MD_11AC;
5996 	}
5997 #endif
5998 #ifdef CONFIG_80211N_HT
5999 	if (network_type == WLAN_MD_INVALID) {
6000 		if (sta->htpriv.ht_option == _TRUE)
6001 			network_type =  WLAN_MD_11N;
6002 	}
6003 #endif
6004 
6005 	if (pcur_network->Configuration.DSConfig > 14)
6006 		network_type |= WLAN_MD_11A;
6007 	else {
6008 		if ((cckratesonly_included(sta->bssrateset, sta->bssratelen)) == _TRUE)
6009 			network_type |= WLAN_MD_11B;
6010 		else if ((cckrates_included(sta->bssrateset, sta->bssratelen)) == _TRUE)
6011 			network_type |= WLAN_MD_11BG;
6012 		else
6013 			network_type |= WLAN_MD_11G;
6014 	}
6015 
6016 	sta->phl_sta->wmode = network_type;
6017 }
6018 
6019 #if defined(CONFIG_RTW_ACS) && defined(WKARD_ACS)
rtw_acs_start(_adapter * padapter)6020 void rtw_acs_start(_adapter *padapter)
6021 {
6022 	RTW_INFO(FUNC_ADPT_FMT" not support\n", FUNC_ADPT_ARG(padapter));
6023 }
6024 
rtw_acs_stop(_adapter * padapter)6025 void rtw_acs_stop(_adapter *padapter)
6026 {
6027 	RTW_INFO(FUNC_ADPT_FMT" not support\n", FUNC_ADPT_ARG(padapter));
6028 }
6029 #endif /* defined(CONFIG_RTW_ACS) && defined(WKARD_ACS) */
6030 
6031 #ifdef CONFIG_AP_CMD_DISPR
6032 
_ap_start_swch_start_notify(struct _ADAPTER * padapter)6033 static enum rtw_phl_status _ap_start_swch_start_notify(struct _ADAPTER *padapter)
6034 {
6035 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6036 	struct rtw_wifi_role_t *role = padapter->phl_role;
6037 	enum rtw_phl_status status;
6038 	struct phl_msg msg = {0};
6039 	struct phl_msg_attribute attr = {0};
6040 
6041 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_START);
6042 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_SWCH_START);
6043 
6044 	msg.band_idx = padapter->phl_role->hw_band;
6045 	msg.rsvd[0] = (u8*)role;
6046 
6047 	status = rtw_phl_send_msg_to_dispr(GET_PHL_INFO(d),
6048 					       &msg, &attr, NULL);
6049 
6050 	return status;
6051 }
6052 
_ap_start_swch_done_notify_cb(void * priv,struct phl_msg * msg)6053 static void _ap_start_swch_done_notify_cb(void *priv, struct phl_msg *msg)
6054 {
6055 	struct _ADAPTER *a = (struct _ADAPTER *)priv;
6056 
6057 
6058 	RTW_DBG(FUNC_ADPT_FMT ": ap_start_cmd_state=%u\n",
6059 		FUNC_ADPT_ARG(a), a->ap_start_cmd_state);
6060 
6061 	if (msg->inbuf) {
6062 		rtw_vmfree(msg->inbuf, msg->inlen);
6063 		msg->inbuf = NULL;
6064 	}
6065 }
6066 
6067 static enum rtw_phl_status
_ap_start_swch_done_notify(struct _ADAPTER * a,struct rtw_chan_def * chandef)6068 _ap_start_swch_done_notify(struct _ADAPTER *a, struct rtw_chan_def *chandef)
6069 {
6070 	struct dvobj_priv *d = adapter_to_dvobj(a);
6071 	struct phl_msg msg = {0};
6072 	struct phl_msg_attribute attr = {0};
6073 	u8 *info = NULL;
6074 	enum rtw_phl_status status;
6075 
6076 
6077 	info = rtw_vmalloc(sizeof(struct rtw_chan_def));
6078 	if (!info) {
6079 		RTW_ERR(FUNC_ADPT_FMT ": Allocate msg hub buffer fail!\n",
6080 			FUNC_ADPT_ARG(a));
6081 		return RTW_PHL_STATUS_RESOURCE;
6082 	}
6083 	_rtw_memcpy(info, chandef, sizeof(struct rtw_chan_def));
6084 
6085 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_START);
6086 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_SWCH_DONE);
6087 	msg.band_idx = a->phl_role->hw_band;
6088 	msg.inbuf = info;
6089 	msg.inlen = sizeof(struct rtw_chan_def);
6090 
6091 	attr.completion.completion = _ap_start_swch_done_notify_cb;
6092 	attr.completion.priv = a;
6093 
6094 	status = rtw_phl_send_msg_to_dispr(GET_PHL_INFO(d),
6095 					       &msg, &attr, NULL);
6096 	if (status != RTW_PHL_STATUS_SUCCESS) {
6097 		rtw_vmfree(info, sizeof(struct rtw_chan_def));
6098 		RTW_ERR(FUNC_ADPT_FMT ": send_msg_to_dispr fail(0x%x)!\n",
6099 			FUNC_ADPT_ARG(a), status);
6100 	}
6101 
6102 	return status;
6103 }
6104 
_ap_start_end_notify_cb(void * priv,struct phl_msg * msg)6105 static void _ap_start_end_notify_cb(void *priv, struct phl_msg *msg)
6106 {
6107 
6108 	if (msg->inbuf) {
6109 		rtw_vmfree(msg->inbuf, msg->inlen);
6110 		msg->inbuf = NULL;
6111 	}
6112 }
6113 
6114 static enum rtw_phl_status
_ap_start_end_notify(struct _ADAPTER * padapter,bool success,bool abort)6115 _ap_start_end_notify(struct _ADAPTER *padapter, bool success, bool abort)
6116 {
6117 	struct rtw_wifi_role_t *role = padapter->phl_role;
6118 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6119 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6120 	struct phl_msg msg = {0};
6121 	struct phl_msg_attribute attr = {0};
6122 	u8 *info = NULL;
6123 
6124 	RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_AP_START\n", FUNC_ADPT_ARG(padapter));
6125 
6126 	info = rtw_vmalloc(sizeof(u8));
6127 	if (info == NULL) {
6128 		RTW_ERR("%s: alloc buffer failed!\n", __func__);
6129 		return RTW_PHL_STATUS_RESOURCE;
6130 	}
6131 
6132 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_START);
6133 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_AP_START_END);
6134 	if (success) {
6135 		*info = RTW_PHL_STATUS_SUCCESS;
6136 	} else {
6137 		*info = RTW_PHL_STATUS_FAILURE;
6138 	}
6139 
6140 	msg.inbuf = info;
6141 	msg.inlen = 1;
6142 	msg.band_idx = role->hw_band;
6143 	msg.rsvd[0] = (u8*)role;
6144 
6145 	if(abort)
6146 		attr.opt = MSG_OPT_SEND_IN_ABORT;
6147 	attr.completion.completion = _ap_start_end_notify_cb;
6148 	attr.completion.priv = padapter;
6149 
6150 
6151 	status = rtw_phl_send_msg_to_dispr(GET_PHL_INFO(d),
6152 					       &msg, &attr, NULL);
6153 	if (status != RTW_PHL_STATUS_SUCCESS) {
6154 		rtw_vmfree(info, sizeof(u8));
6155 		RTW_ERR(FUNC_ADPT_FMT ": send_msg_to_dispr fail(0x%x)!\n",
6156 			FUNC_ADPT_ARG(padapter), status);
6157 	}
6158 
6159 	return status;
6160 }
6161 
ap_free_cmdobj(struct cmd_obj * pcmd)6162 static void ap_free_cmdobj(struct cmd_obj *pcmd)
6163 {
6164 	struct _ADAPTER *padapter = pcmd->padapter;
6165 
6166 	if (!pcmd)
6167 		return;
6168 
6169 
6170 	if (pcmd->sctx) {
6171 		if (pcmd->res == H2C_SUCCESS)
6172 			rtw_sctx_done(&pcmd->sctx);
6173 		else
6174 			rtw_sctx_done_err(&pcmd->sctx, RTW_SCTX_DONE_CMD_ERROR);
6175 	}
6176 
6177 	rtw_free_cmd_obj(pcmd);
6178 
6179 	return;
6180 }
6181 
_ap_start_cmd_done(struct cmd_obj * pcmd)6182 static void _ap_start_cmd_done(struct cmd_obj *pcmd)
6183 {
6184 	struct _ADAPTER *padapter = pcmd->padapter;
6185 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6186 	struct rtw_wifi_role_t *role = padapter->phl_role;
6187 	enum rtw_phl_status status;
6188 
6189 	RTW_INFO("%s: +\n", __func__);
6190 
6191 	if (!padapter->ap_start_cmd_token){
6192 		RTW_ERR("%s : token is NULL!\n", __func__);
6193 		return;
6194 	}
6195 
6196 	status = rtw_phl_free_cmd_token(GET_PHL_INFO(d),
6197 					role->hw_band, &padapter->ap_start_cmd_token);
6198 
6199 	padapter->ap_start_cmd_token = 0;
6200 	padapter->ap_start_cmd_state = 0;
6201 
6202 	if (status != RTW_PHL_STATUS_SUCCESS)
6203 		RTW_ERR(FUNC_ADPT_FMT ": free_cmd_token fail(0x%x)!\n",
6204 			FUNC_ADPT_ARG(padapter), status);
6205 
6206 	ap_free_cmdobj(pcmd);
6207 
6208 	RTW_INFO("%s: -\n", __func__);
6209 }
6210 
rtw_free_bcn_entry(struct _ADAPTER * padapter)6211 enum rtw_phl_status rtw_free_bcn_entry(struct _ADAPTER *padapter){
6212 
6213 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6214 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6215 
6216 #ifdef RTW_PHL_BCN
6217 	status = rtw_phl_free_bcn_entry(d->phl, padapter->phl_role);
6218 	if (status != RTW_PHL_STATUS_SUCCESS) {
6219 		RTW_INFO("%s - phl_free_bcn_entry failed\n", __func__);
6220 	}
6221 #endif
6222 
6223 	return status;
6224 }
6225 
_ap_start_req_acquired(void * dispr,void * priv)6226 static enum phl_mdl_ret_code _ap_start_req_acquired(void *dispr, void *priv)
6227 {
6228 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6229 	struct _ADAPTER *padapter = pcmd->padapter;
6230 	struct createbss_parm *parm = (struct createbss_parm *)pcmd->parmbuf;
6231 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
6232 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
6233 	struct rtw_wifi_role_t *role = padapter->phl_role;
6234 	struct rtw_phl_com_t *phl_com = role->phl_com;
6235 	struct phl_info_t *phl_info = phl_com->phl_priv;
6236 	struct phl_msg msg = {0};
6237 	struct phl_msg_attribute attr = {0};
6238 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6239 
6240 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6241 
6242 	if ((parm->req_ch == 0 && pmlmeinfo->state == WIFI_FW_AP_STATE)
6243 		|| parm->req_ch != 0
6244 	){
6245 		start_bss_network(padapter, parm);
6246 	}
6247 
6248 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_START);
6249 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_AP_START_PREPARE);
6250 	msg.band_idx = role->hw_band;
6251 
6252 	status = rtw_phl_send_msg_to_dispr(phl_info,
6253 	                                    &msg,
6254 	                                    &attr,
6255 	                                    NULL);
6256 	if (status != RTW_PHL_STATUS_SUCCESS) {
6257 		return MDL_RET_FAIL;
6258 	} else {
6259 		SET_STATUS_FLAG(padapter->ap_start_cmd_state, CMD_APSTART_ACQUIRE);
6260 		return MDL_RET_SUCCESS;
6261 	}
6262 }
6263 
_ap_start_req_abort(void * dispr,void * priv)6264 static enum phl_mdl_ret_code _ap_start_req_abort(void *dispr, void *priv)
6265 {
6266 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6267 	struct _ADAPTER *padapter = pcmd->padapter;
6268 	enum rtw_phl_status status = RTW_PHL_STATUS_FAILURE;
6269 
6270 	if (TEST_STATUS_FLAG(padapter->ap_start_cmd_state, CMD_APSTART_ACQUIRE)) {
6271 		status = _ap_start_end_notify(padapter, false, true);
6272 	}
6273 
6274 	padapter->ap_start_cmd_state = 0;
6275 	RTW_INFO("%s\n", __func__);
6276 	return MDL_RET_SUCCESS;
6277 }
6278 
_ap_start_req_ev_hdlr(void * dispr,void * priv,struct phl_msg * msg)6279 static enum phl_mdl_ret_code _ap_start_req_ev_hdlr(void *dispr, void *priv, struct phl_msg* msg)
6280 {
6281 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6282 	struct _ADAPTER *padapter = pcmd->padapter;
6283 	struct createbss_parm *parm = (struct createbss_parm *)pcmd->parmbuf;
6284 	struct rtw_wifi_role_t *wifi_role = padapter->phl_role;
6285 	struct rtw_phl_com_t *phl_com = wifi_role->phl_com;
6286 	void *d = phlcom_to_drvpriv(phl_com);
6287 	struct phl_msg nextmsg = {0};
6288 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6289 
6290 	RTW_DBG(FUNC_ADPT_FMT ": + msg_id=0x%08x\n",
6291 		FUNC_ADPT_ARG(padapter), msg->msg_id);
6292 
6293 	if (MSG_MDL_ID_FIELD(msg->msg_id) != PHL_FG_MDL_AP_START) {
6294 		RTW_INFO(FUNC_ADPT_FMT ": Message is not from ap start module, "
6295 			 "skip msg_id=0x%08x\n", FUNC_ADPT_ARG(padapter), msg->msg_id);
6296 		RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6297 		return MDL_RET_IGNORE;
6298 	}
6299 
6300 	if (IS_MSG_FAIL(msg->msg_id)) {
6301 		RTW_WARN(FUNC_ADPT_FMT ": cmd dispatcher notify cmd failure on "
6302 			 "msg_id=0x%08x\n", FUNC_ADPT_ARG(padapter), msg->msg_id);
6303 	}
6304 
6305 	SET_MSG_MDL_ID_FIELD(nextmsg.msg_id, PHL_FG_MDL_AP_START);
6306 	nextmsg.band_idx = wifi_role->hw_band;
6307 
6308 	switch(MSG_EVT_ID_FIELD(msg->msg_id)) {
6309 		case MSG_EVT_AP_START_PREPARE:
6310 		{
6311 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_AP_START_PREPARE\n", FUNC_ADPT_ARG(padapter));
6312 			status = _ap_start_swch_start_notify(padapter);
6313 			if(status != RTW_PHL_STATUS_SUCCESS)
6314 				RTW_ERR("%s :: [MSG_EVT_AP_START_PREPARE] rtw_phl_send_msg_to_dispr failed\n", __func__);
6315 			break;
6316 		}
6317 		case MSG_EVT_SWCH_START:
6318 		{
6319 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_SWCH_START\n", FUNC_ADPT_ARG(padapter));
6320 			rtw_core_ap_swch_start(padapter, parm);
6321 			status = _ap_start_swch_done_notify(padapter, &wifi_role->chandef);
6322 			if(status != RTW_PHL_STATUS_SUCCESS)
6323 				RTW_ERR("%s :: [SWCH_START] rtw_phl_send_msg_to_dispr failed\n", __func__);
6324 			break;
6325 		}
6326 
6327 		case MSG_EVT_SWCH_DONE:
6328 		{
6329 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_SWCH_DONE\n", FUNC_ADPT_ARG(padapter));
6330 			status = rtw_phl_ap_started(adapter_to_dvobj(padapter)->phl, padapter->phl_role);
6331 			if(status != RTW_PHL_STATUS_SUCCESS)
6332 				RTW_ERR("%s :: [MSG_EVT_SWCH_DONE] rtw_phl_send_msg_to_dispr failed\n", __func__);
6333 			break;
6334 		}
6335 		case MSG_EVT_AP_START:
6336 		{
6337 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_AP_START\n", FUNC_ADPT_ARG(padapter));
6338 			rtw_core_ap_start(padapter, parm); /* send beacon */
6339 			status = _ap_start_end_notify(padapter, true, false);
6340 			break;
6341 		}
6342 
6343 		case MSG_EVT_AP_START_END:
6344 		{
6345 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_AP_START_END\n", FUNC_ADPT_ARG(padapter));
6346 			if (msg->inbuf == NULL) {
6347 				RTW_WARN("[MSG_EVT_AP_START_END] Msg info buffer NULL!\n");
6348 				break;
6349 			}
6350 
6351 			if (*(msg->inbuf) == RTW_PHL_STATUS_FAILURE){
6352 				RTW_WARN("[MSG_EVT_AP_START_END] Msg_inbuf is FAIL!\n");
6353 				stop_ap_hdl(padapter);
6354 			}
6355 
6356 			_ap_start_cmd_done(pcmd);
6357 			break;
6358 		}
6359 
6360 		default:
6361 			/* unknown state */
6362 		break;
6363 	}
6364 
6365 
6366 	if (status != RTW_PHL_STATUS_SUCCESS) {
6367 		/* Trigger stop AP flow when start AP failure */
6368 		stop_ap_hdl(padapter);
6369 		_ap_start_cmd_done(pcmd);
6370 	}
6371 
6372 	return MDL_RET_SUCCESS;
6373 }
6374 
_ap_start_req_set_info(void * dispr,void * priv,struct phl_module_op_info * info)6375 static enum phl_mdl_ret_code _ap_start_req_set_info(void *dispr, void *priv, struct phl_module_op_info* info)
6376 {
6377 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6378 	struct _ADAPTER *padapter = pcmd->padapter;
6379 
6380 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6381 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6382 
6383 	return MDL_RET_IGNORE;
6384 }
6385 
_ap_start_req_query_info(void * dispr,void * priv,struct phl_module_op_info * info)6386 static enum phl_mdl_ret_code _ap_start_req_query_info(void *dispr, void *priv, struct phl_module_op_info* info)
6387 {
6388 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6389 	struct _ADAPTER *padapter = pcmd->padapter;
6390 	enum phl_mdl_ret_code ret = MDL_RET_IGNORE;
6391 
6392 
6393 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6394 
6395 	switch (info->op_code) {
6396 	case FG_REQ_OP_GET_ROLE:
6397 		info->outbuf = (u8*)padapter->phl_role;
6398 		ret = MDL_RET_SUCCESS;
6399 		break;
6400 
6401 	default:
6402 		break;
6403 	}
6404 
6405 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6406 	return ret;
6407 }
6408 
rtw_cmd_ap_start_req_init(struct cmd_obj * pcmd,struct phl_cmd_token_req * fgreq)6409 static void rtw_cmd_ap_start_req_init(struct cmd_obj *pcmd, struct phl_cmd_token_req *fgreq)
6410 {
6411 	struct _ADAPTER *padapter = pcmd->padapter;
6412 	u8 res = _SUCCESS;
6413 
6414     /* Fill foreground command request */
6415     fgreq->module_id= PHL_FG_MDL_AP_START;
6416     fgreq->priv = pcmd;
6417     fgreq->role = padapter->phl_role;
6418 
6419     fgreq->acquired = _ap_start_req_acquired;
6420     fgreq->abort = _ap_start_req_abort;
6421     fgreq->msg_hdlr = _ap_start_req_ev_hdlr;
6422     fgreq->set_info = _ap_start_req_set_info;
6423     fgreq->query_info = _ap_start_req_query_info;
6424 
6425 	padapter->ap_start_cmd_state = 0;
6426 	padapter->ap_start_cmd_token = 0;
6427 
6428 	RTW_INFO("%s\n", __func__);
6429 }
6430 
rtw_ap_start_cmd(struct cmd_obj * pcmd)6431 enum rtw_phl_status rtw_ap_start_cmd(struct cmd_obj *pcmd)
6432 {
6433 	struct _ADAPTER *padapter = pcmd->padapter;
6434 	struct phl_cmd_token_req fgreq={0};
6435 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6436 	enum rtw_phl_status status;
6437 	struct rtw_wifi_role_t *role = padapter->phl_role;
6438 
6439 	rtw_cmd_ap_start_req_init(pcmd, &fgreq);
6440 
6441 	RTW_DBG(FUNC_ADPT_FMT ": \n", FUNC_ADPT_ARG(padapter));
6442 
6443 	/* cmd_dispatcher would copy whole phl_cmd_token_req */
6444 	status = rtw_phl_add_cmd_token_req(d->phl, role->hw_band, &fgreq, &padapter->ap_start_cmd_token);
6445 	if((status != RTW_PHL_STATUS_SUCCESS) &&
6446 	   (status != RTW_PHL_STATUS_PENDING))
6447 		goto error;
6448 
6449 	status = RTW_PHL_STATUS_SUCCESS;
6450 
6451 error:
6452 	return status;
6453 
6454 }
6455 
_ap_stop_cmd_done(struct cmd_obj * pcmd)6456 static void _ap_stop_cmd_done(struct cmd_obj *pcmd)
6457 {
6458 	struct _ADAPTER *padapter = pcmd->padapter;
6459 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6460 	struct rtw_wifi_role_t *role = padapter->phl_role;
6461 	enum rtw_phl_status status;
6462 
6463 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6464 
6465 	if (!padapter->ap_stop_cmd_token){
6466 		RTW_ERR("%s : token is NULL!\n", __func__);
6467 		return;
6468 	}
6469 
6470 	status = rtw_phl_free_cmd_token(GET_PHL_INFO(d),
6471 					role->hw_band, &padapter->ap_stop_cmd_token);
6472 
6473 	padapter->ap_stop_cmd_token = 0;
6474 	padapter->ap_stop_cmd_state = 0;
6475 	if (status != RTW_PHL_STATUS_SUCCESS)
6476 		RTW_ERR(FUNC_ADPT_FMT ": free_cmd_token fail(0x%x)!\n",
6477 			FUNC_ADPT_ARG(padapter), status);
6478 
6479 	ap_free_cmdobj(pcmd);
6480 
6481 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6482 }
6483 
_ap_stop_ap_stop_notify(struct _ADAPTER * adapter)6484 static enum rtw_phl_status _ap_stop_ap_stop_notify(struct _ADAPTER *adapter)
6485 {
6486 	struct dvobj_priv *d = adapter_to_dvobj(adapter);
6487 	struct rtw_wifi_role_t *role = adapter->phl_role;
6488 	enum rtw_phl_status status;
6489 	struct phl_msg msg = {0};
6490 	struct phl_msg_attribute attr = {0};
6491 
6492 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_STOP);
6493 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_AP_STOP);
6494 
6495 	msg.band_idx = adapter->phl_role->hw_band;
6496 	msg.rsvd[0] = (u8*)role;
6497 
6498 	status = rtw_phl_send_msg_to_dispr(GET_PHL_INFO(d),
6499 					       &msg, &attr, NULL);
6500 
6501 	if (status != RTW_PHL_STATUS_SUCCESS) {
6502 		RTW_ERR(FUNC_ADPT_FMT ": send_msg_to_dispr fail(0x%x)!\n", FUNC_ADPT_ARG(adapter), status);
6503 	}
6504 	return status;
6505 }
6506 
_ap_stop_abort_notify_cb(void * priv,struct phl_msg * msg)6507 static void _ap_stop_abort_notify_cb(void *priv, struct phl_msg *msg)
6508 {
6509 	_adapter *padapter = (_adapter *)priv;
6510 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6511 	struct _ADAPTER *adapter = (struct _ADAPTER *)priv;
6512 	enum rtw_phl_status phl_status = RTW_PHL_STATUS_SUCCESS;
6513 	struct rtw_chan_def chan_def = {0};
6514 	u8 chctx_num = 0;
6515 
6516 #ifdef RTW_PHL_BCN
6517 	phl_status = rtw_phl_free_bcn_entry(d->phl, adapter->phl_role);
6518 	if (phl_status != RTW_PHL_STATUS_SUCCESS) {
6519 		RTW_INFO("%s - phl_free_bcn_entry failed\n", __func__);
6520 	}
6521 #endif
6522 }
6523 
_ap_stop_abort_notify(struct _ADAPTER * adapter,bool abort)6524 static enum rtw_phl_status _ap_stop_abort_notify(struct _ADAPTER *adapter, bool abort)
6525 {
6526 	struct dvobj_priv *d = adapter_to_dvobj(adapter);
6527 	struct rtw_wifi_role_t *role = adapter->phl_role;
6528 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6529 	struct phl_msg msg = {0};
6530 	struct phl_msg_attribute attr = {0};
6531 
6532 	SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_FG_MDL_AP_STOP);
6533 	SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_AP_STOP);
6534 	msg.band_idx = role->hw_band;
6535 	msg.rsvd[0] = (u8*)role;
6536 
6537 	if(abort)
6538 		attr.opt = MSG_OPT_SEND_IN_ABORT;
6539 	attr.completion.completion = _ap_stop_abort_notify_cb;
6540 	attr.completion.priv = adapter;
6541 
6542 	status = rtw_phl_send_msg_to_dispr(d->phl,
6543 	                            		&msg,
6544 	                                	&attr,
6545 	                            		NULL);
6546 	if (status != RTW_PHL_STATUS_SUCCESS) {
6547 		RTW_INFO("[%s] Abort send msg fail!\n", __func__);
6548 	}
6549 
6550 	return status;
6551 }
6552 
_ap_stop_req_acquired(void * dispr,void * priv)6553 static enum phl_mdl_ret_code _ap_stop_req_acquired(void *dispr, void *priv)
6554 {
6555 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6556 	struct _ADAPTER *padapter = pcmd->padapter;
6557 	struct rtw_wifi_role_t *role = padapter->phl_role;
6558 	struct rtw_phl_com_t *phl_com = role->phl_com;
6559 	struct phl_info_t *phl_info = phl_com->phl_priv;
6560 	struct phl_msg msg = {0};
6561 
6562 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6563 
6564 	SET_STATUS_FLAG(padapter->ap_stop_cmd_state, CMD_APSTOP_ACQUIRE);
6565 
6566 	rtw_phl_ap_stop(adapter_to_dvobj(padapter)->phl, role);
6567 
6568 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6569 
6570 	return MDL_RET_SUCCESS;
6571 
6572 }
6573 
_ap_stop_req_abort(void * dispr,void * priv)6574 static enum phl_mdl_ret_code _ap_stop_req_abort(void *dispr, void *priv)
6575 {
6576 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6577 	struct _ADAPTER *padapter = pcmd->padapter;
6578 
6579 	if(TEST_STATUS_FLAG(padapter->ap_stop_cmd_state, CMD_APSTOP_STARTED)){
6580 		/* case1: MSG_EVT_AP_STOP has been processed*/
6581 	}
6582 	else if(TEST_STATUS_FLAG(padapter->ap_stop_cmd_state, CMD_APSTOP_ACQUIRE)){
6583 		/* case2: MSG_EVT_AP_STOP in msgQ
6584 		   case3: MSG_EVT_AP_STOP doesn't back to msg_hdlr yet */
6585 		if (RTW_PHL_STATUS_SUCCESS != _ap_stop_abort_notify(padapter, true)) {
6586 			/* do not execute core_mr_handle because do not know if the I/O operation is acceptable */
6587 			//core_mr_delete_chctx(adapter, &chctx_num, &chan_def);
6588 		}
6589 	}
6590 	else{
6591 		/* apstop token stay in tokenOpQ */
6592 	}
6593 
6594 	padapter->ap_stop_cmd_state = 0;
6595 	RTW_INFO("%s\n", __func__);
6596 	return MDL_RET_SUCCESS;
6597 }
6598 
_ap_stop_req_ev_hdlr(void * dispr,void * priv,struct phl_msg * msg)6599 static enum phl_mdl_ret_code _ap_stop_req_ev_hdlr(void *dispr, void *priv, struct phl_msg* msg)
6600 {
6601 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6602 	struct _ADAPTER *padapter = pcmd->padapter;
6603 	struct rtw_wifi_role_t *wifi_role = padapter->phl_role;
6604 	struct rtw_phl_com_t *phl_com = wifi_role->phl_com;
6605 	struct phl_info_t *phl_info = phl_com->phl_priv;
6606 	void *d = phlcom_to_drvpriv(phl_com);
6607 	struct phl_msg nextmsg = {0};
6608 	enum rtw_phl_status status = RTW_PHL_STATUS_SUCCESS;
6609 
6610 	RTW_DBG(FUNC_ADPT_FMT ": + msg_id=0x%08x\n",
6611 		FUNC_ADPT_ARG(padapter), msg->msg_id);
6612 
6613 	if (MSG_MDL_ID_FIELD(msg->msg_id) != PHL_FG_MDL_AP_STOP) {
6614 		RTW_INFO(FUNC_ADPT_FMT ": Message is not from ap stop module, "
6615 			 "skip msg_id=0x%08x\n", FUNC_ADPT_ARG(padapter), msg->msg_id);
6616 		RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6617 		return MDL_RET_IGNORE;
6618 	}
6619 
6620 	if (IS_MSG_FAIL(msg->msg_id)) {
6621 		RTW_WARN(FUNC_ADPT_FMT ": cmd dispatcher notify cmd failure on "
6622 			 "msg_id=0x%08x\n", FUNC_ADPT_ARG(padapter), msg->msg_id);
6623 	}
6624 
6625 	SET_MSG_MDL_ID_FIELD(nextmsg.msg_id, PHL_FG_MDL_AP_STOP);
6626 	nextmsg.band_idx = wifi_role->hw_band;
6627 
6628 	switch(MSG_EVT_ID_FIELD(msg->msg_id)) {
6629 		case MSG_EVT_AP_STOP_PREPARE:
6630 		{
6631 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_AP_STOP_PREPARE\n", FUNC_ADPT_ARG(padapter));
6632 			status = _ap_stop_ap_stop_notify(padapter);
6633 			if (status != RTW_PHL_STATUS_SUCCESS) {
6634 				RTW_ERR("%s :: [MSG_EVT_AP_STOP_PREPARE] ap_stop_notify fail\n", __func__);
6635 				_ap_stop_cmd_done(pcmd);
6636 			}
6637 			break;
6638 		}
6639 		case MSG_EVT_AP_STOP:
6640 		{
6641 			RTW_DBG(FUNC_ADPT_FMT ": MSG_EVT_SWCH_START\n", FUNC_ADPT_ARG(padapter));
6642 			stop_ap_hdl(padapter);
6643 			rtw_phl_ap_stop_resume_hdlr(phl_info, wifi_role);
6644 			_ap_stop_cmd_done(pcmd);
6645 			break;
6646 		}
6647 		default:
6648 			/* unknown state */
6649 		break;
6650 	}
6651 
6652 	return MDL_RET_SUCCESS;
6653 }
6654 
_ap_stop_req_set_info(void * dispr,void * priv,struct phl_module_op_info * info)6655 static enum phl_mdl_ret_code _ap_stop_req_set_info(void *dispr, void *priv, struct phl_module_op_info* info)
6656 {
6657 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6658 	struct _ADAPTER *padapter = pcmd->padapter;
6659 
6660 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6661 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(padapter));
6662 
6663 	return MDL_RET_IGNORE;
6664 }
6665 
_ap_stop_req_query_info(void * dispr,void * priv,struct phl_module_op_info * info)6666 static enum phl_mdl_ret_code _ap_stop_req_query_info(void *dispr, void *priv, struct phl_module_op_info* info)
6667 {
6668 	struct cmd_obj *pcmd = (struct cmd_obj *)priv;
6669 	struct _ADAPTER *a = pcmd->padapter;
6670 	enum phl_mdl_ret_code ret = MDL_RET_IGNORE;
6671 
6672 
6673 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(a));
6674 
6675 	switch (info->op_code) {
6676 	case FG_REQ_OP_GET_ROLE:
6677 		info->outbuf = (u8*)a->phl_role;
6678 		ret = MDL_RET_SUCCESS;
6679 		break;
6680 
6681 	default:
6682 		break;
6683 	}
6684 
6685 	RTW_DBG(FUNC_ADPT_FMT ": -\n", FUNC_ADPT_ARG(a));
6686 	return ret;
6687 }
6688 
rtw_cmd_ap_stop_req_init(struct cmd_obj * pcmd,struct phl_cmd_token_req * fgreq)6689 static void rtw_cmd_ap_stop_req_init(struct cmd_obj *pcmd, struct phl_cmd_token_req *fgreq)
6690 {
6691 	struct _ADAPTER *padapter = pcmd->padapter;
6692 
6693 	RTW_DBG(FUNC_ADPT_FMT ": \n", FUNC_ADPT_ARG(padapter));
6694 	/* Fill foreground command request */
6695 	fgreq->module_id= PHL_FG_MDL_AP_STOP;
6696 	fgreq->priv = pcmd;
6697 	fgreq->role = padapter->phl_role;
6698 
6699 	fgreq->acquired = _ap_stop_req_acquired;
6700 	fgreq->abort = _ap_stop_req_abort;
6701 	fgreq->msg_hdlr = _ap_stop_req_ev_hdlr;
6702 	fgreq->set_info = _ap_stop_req_set_info;
6703 	fgreq->query_info = _ap_stop_req_query_info;
6704 
6705 	padapter->ap_stop_cmd_state = 0;
6706 	padapter->ap_stop_cmd_token = 0;
6707 }
6708 
rtw_ap_stop_cmd(struct cmd_obj * pcmd)6709 enum rtw_phl_status rtw_ap_stop_cmd(struct cmd_obj *pcmd)
6710 {
6711 	struct _ADAPTER *padapter = pcmd->padapter;
6712 	struct phl_cmd_token_req fgreq={0};
6713 	struct dvobj_priv *d = adapter_to_dvobj(padapter);
6714 	enum rtw_phl_status pstatus;
6715 	struct rtw_wifi_role_t *role = padapter->phl_role;
6716 
6717 	RTW_DBG(FUNC_ADPT_FMT ": +\n", FUNC_ADPT_ARG(padapter));
6718 
6719 	rtw_cmd_ap_stop_req_init(pcmd, &fgreq);
6720 
6721 	/* cmd_dispatcher would copy whole phl_cmd_token_req */
6722 	pstatus = rtw_phl_add_cmd_token_req(d->phl, role->hw_band, &fgreq, &padapter->ap_stop_cmd_token);
6723 	if((pstatus != RTW_PHL_STATUS_SUCCESS) &&
6724 	   (pstatus != RTW_PHL_STATUS_PENDING))
6725 		goto error;
6726 
6727 	pstatus = RTW_PHL_STATUS_SUCCESS;
6728 
6729 error:
6730 	return pstatus;
6731 
6732 }
6733 
6734 #endif
6735 #endif	/* CONFIG_AP_MODE */
6736