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