1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
3 
4 #define _RTW_AP_C_
5 
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/wifi.h"
9 #include "../include/ieee80211.h"
10 #include "../include/rtl8188e_cmd.h"
11 
init_mlme_ap_info(struct adapter * padapter)12 void init_mlme_ap_info(struct adapter *padapter)
13 {
14 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
15 	struct sta_priv *pstapriv = &padapter->stapriv;
16 	struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
17 
18 	spin_lock_init(&pmlmepriv->bcn_update_lock);
19 
20 	/* for ACL */
21 	rtw_init_queue(&pacl_list->acl_node_q);
22 
23 	start_ap_mode(padapter);
24 }
25 
free_mlme_ap_info(struct adapter * padapter)26 void free_mlme_ap_info(struct adapter *padapter)
27 {
28 	struct sta_info *psta = NULL;
29 	struct sta_priv *pstapriv = &padapter->stapriv;
30 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
31 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
32 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
33 
34 	pmlmepriv->update_bcn = false;
35 	pmlmeext->bstart_bss = false;
36 
37 	rtw_sta_flush(padapter);
38 
39 	pmlmeinfo->state = _HW_STATE_NOLINK_;
40 
41 	/* free_assoc_sta_resources */
42 	rtw_free_all_stainfo(padapter);
43 
44 	/* free bc/mc sta_info */
45 	psta = rtw_get_bcmc_stainfo(padapter);
46 	spin_lock_bh(&pstapriv->sta_hash_lock);
47 	rtw_free_stainfo(padapter, psta);
48 	spin_unlock_bh(&pstapriv->sta_hash_lock);
49 }
50 
update_BCNTIM(struct adapter * padapter)51 static void update_BCNTIM(struct adapter *padapter)
52 {
53 	struct sta_priv *pstapriv = &padapter->stapriv;
54 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
55 	struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
56 	struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
57 	unsigned char *pie = pnetwork_mlmeext->IEs;
58 	u8 *p, *dst_ie, *premainder_ie = NULL;
59 	u8 *pbackup_remainder_ie = NULL;
60 	__le16 tim_bitmap_le;
61 	uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
62 
63 	/* update TIM IE */
64 
65 	p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen,
66 		       pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
67 	if (p && tim_ielen > 0) {
68 		tim_ielen += 2;
69 		premainder_ie = p + tim_ielen;
70 		tim_ie_offset = (int)(p - pie);
71 		remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
72 		/* append TIM IE from dst_ie offset */
73 		dst_ie = p;
74 	} else {
75 		tim_ielen = 0;
76 
77 		/* calculate head_len */
78 		offset = _FIXED_IE_LENGTH_;
79 		offset += pnetwork_mlmeext->Ssid.SsidLength + 2;
80 
81 		/*  get supported rates len */
82 		p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_,
83 			       &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
84 		if (p)
85 			offset += tmp_len + 2;
86 
87 		/* DS Parameter Set IE, len = 3 */
88 		offset += 3;
89 
90 		premainder_ie = pie + offset;
91 
92 		remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
93 
94 		/* append TIM IE from offset */
95 		dst_ie = pie + offset;
96 	}
97 
98 	if (remainder_ielen > 0) {
99 		pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
100 		if (pbackup_remainder_ie && premainder_ie)
101 			memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
102 	}
103 	*dst_ie++ = _TIM_IE_;
104 
105 	if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fc))
106 		tim_ielen = 5;
107 	else
108 		tim_ielen = 4;
109 
110 	*dst_ie++ = tim_ielen;
111 
112 	*dst_ie++ = 0;/* DTIM count */
113 	*dst_ie++ = 1;/* DTIM period */
114 
115 	if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
116 		*dst_ie++ = BIT(0);/* bitmap ctrl */
117 	else
118 		*dst_ie++ = 0;
119 
120 	tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
121 
122 	if (tim_ielen == 4) {
123 		*dst_ie++ = *(u8 *)&tim_bitmap_le;
124 	} else if (tim_ielen == 5) {
125 		memcpy(dst_ie, &tim_bitmap_le, 2);
126 		dst_ie += 2;
127 	}
128 
129 	/* copy remainder IE */
130 	if (pbackup_remainder_ie) {
131 		memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
132 
133 		kfree(pbackup_remainder_ie);
134 	}
135 	offset =  (uint)(dst_ie - pie);
136 	pnetwork_mlmeext->IELength = offset + remainder_ielen;
137 
138 	set_tx_beacon_cmd(padapter);
139 }
140 
chk_sta_is_alive(struct sta_info * psta)141 static u8 chk_sta_is_alive(struct sta_info *psta)
142 {
143 	u8 ret = false;
144 
145 	if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) ==
146 	    (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts))
147 		;
148 	else
149 		ret = true;
150 
151 	sta_update_last_rx_pkts(psta);
152 
153 	return ret;
154 }
155 
expire_timeout_chk(struct adapter * padapter)156 void	expire_timeout_chk(struct adapter *padapter)
157 {
158 	struct list_head *phead, *plist;
159 	u8 updated = 0;
160 	struct sta_info *psta = NULL;
161 	struct sta_priv *pstapriv = &padapter->stapriv;
162 	u8 chk_alive_num = 0;
163 	char chk_alive_list[NUM_STA];
164 	int i;
165 
166 	spin_lock_bh(&pstapriv->auth_list_lock);
167 
168 	phead = &pstapriv->auth_list;
169 	plist = phead->next;
170 
171 	/* check auth_queue */
172 	while (phead != plist) {
173 		psta = container_of(plist, struct sta_info, auth_list);
174 		plist = plist->next;
175 
176 		if (psta->expire_to > 0) {
177 			psta->expire_to--;
178 			if (psta->expire_to == 0) {
179 				list_del_init(&psta->auth_list);
180 				pstapriv->auth_list_cnt--;
181 
182 				spin_unlock_bh(&pstapriv->auth_list_lock);
183 
184 				spin_lock_bh(&pstapriv->sta_hash_lock);
185 				rtw_free_stainfo(padapter, psta);
186 				spin_unlock_bh(&pstapriv->sta_hash_lock);
187 
188 				spin_lock_bh(&pstapriv->auth_list_lock);
189 			}
190 		}
191 	}
192 	spin_unlock_bh(&pstapriv->auth_list_lock);
193 
194 	psta = NULL;
195 
196 	spin_lock_bh(&pstapriv->asoc_list_lock);
197 
198 	phead = &pstapriv->asoc_list;
199 	plist = phead->next;
200 
201 	/* check asoc_queue */
202 	while (phead != plist) {
203 		psta = container_of(plist, struct sta_info, asoc_list);
204 		plist = plist->next;
205 
206 		if (chk_sta_is_alive(psta) || !psta->expire_to) {
207 			psta->expire_to = pstapriv->expire_to;
208 			psta->keep_alive_trycnt = 0;
209 			psta->under_exist_checking = 0;
210 		} else {
211 			psta->expire_to--;
212 		}
213 
214 		if (psta->expire_to <= 0) {
215 			struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
216 
217 			if (padapter->registrypriv.wifi_spec == 1) {
218 				psta->expire_to = pstapriv->expire_to;
219 				continue;
220 			}
221 
222 			if (psta->state & WIFI_SLEEP_STATE) {
223 				if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
224 					/* to check if alive by another methods if station is at ps mode. */
225 					psta->expire_to = pstapriv->expire_to;
226 					psta->state |= WIFI_STA_ALIVE_CHK_STATE;
227 
228 					/* to update bcn with tim_bitmap for this station */
229 					pstapriv->tim_bitmap |= BIT(psta->aid);
230 					update_beacon(padapter, _TIM_IE_, NULL, false);
231 
232 					if (!pmlmeext->active_keep_alive_check)
233 						continue;
234 				}
235 			}
236 			if (pmlmeext->active_keep_alive_check) {
237 				int stainfo_offset;
238 
239 				stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
240 				if (stainfo_offset_valid(stainfo_offset))
241 					chk_alive_list[chk_alive_num++] = stainfo_offset;
242 				continue;
243 			}
244 
245 			list_del_init(&psta->asoc_list);
246 			pstapriv->asoc_list_cnt--;
247 
248 			updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
249 		} else {
250 			/* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
251 			if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) &&
252 			    padapter->xmitpriv.free_xmitframe_cnt < (NR_XMITFRAME / pstapriv->asoc_list_cnt / 2)) {
253 				wakeup_sta_to_xmit(padapter, psta);
254 			}
255 		}
256 	}
257 
258 	spin_unlock_bh(&pstapriv->asoc_list_lock);
259 
260 	if (chk_alive_num) {
261 		u8 backup_oper_channel = 0;
262 		struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
263 		/* switch to correct channel of current network  before issue keep-alive frames */
264 		if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
265 			backup_oper_channel = rtw_get_oper_ch(padapter);
266 			SelectChannel(padapter, pmlmeext->cur_channel);
267 		}
268 
269 		/* issue null data to check sta alive*/
270 		for (i = 0; i < chk_alive_num; i++) {
271 			int ret = _FAIL;
272 
273 			psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
274 
275 			if (psta->state & WIFI_SLEEP_STATE)
276 				ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
277 			else
278 				ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
279 
280 			psta->keep_alive_trycnt++;
281 			if (ret == _SUCCESS) {
282 				psta->expire_to = pstapriv->expire_to;
283 				psta->keep_alive_trycnt = 0;
284 				continue;
285 			} else if (psta->keep_alive_trycnt <= 3) {
286 				psta->expire_to = 1;
287 				continue;
288 			}
289 
290 			psta->keep_alive_trycnt = 0;
291 
292 			spin_lock_bh(&pstapriv->asoc_list_lock);
293 			list_del_init(&psta->asoc_list);
294 			pstapriv->asoc_list_cnt--;
295 			updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
296 			spin_unlock_bh(&pstapriv->asoc_list_lock);
297 		}
298 
299 		if (backup_oper_channel > 0) /* back to the original operation channel */
300 			SelectChannel(padapter, backup_oper_channel);
301 	}
302 
303 	associated_clients_update(padapter, updated);
304 }
305 
add_RATid(struct adapter * padapter,struct sta_info * psta,u8 rssi_level)306 void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
307 {
308 	int i;
309 	u32 init_rate = 0;
310 	unsigned char sta_band = 0, raid, shortGIrate = false;
311 	unsigned char limit;
312 	unsigned int tx_ra_bitmap = 0;
313 	struct ht_priv	*psta_ht = NULL;
314 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
315 	struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
316 
317 	if (psta)
318 		psta_ht = &psta->htpriv;
319 	else
320 		return;
321 
322 	if (!(psta->state & _FW_LINKED))
323 		return;
324 
325 	/* b/g mode ra_bitmap */
326 	for (i = 0; i < sizeof(psta->bssrateset); i++) {
327 		if (psta->bssrateset[i])
328 			tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i] & 0x7f);
329 	}
330 	/* n mode ra_bitmap */
331 	if (psta_ht->ht_option) {
332 		limit = 8; /* 1R */
333 
334 		for (i = 0; i < limit; i++) {
335 			if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
336 				tx_ra_bitmap |= BIT(i + 12);
337 		}
338 
339 		/* max short GI rate */
340 		shortGIrate = psta_ht->sgi;
341 	}
342 
343 	if (pcur_network->Configuration.DSConfig > 14) {
344 		sta_band |= WIRELESS_INVALID;
345 	} else {
346 		if (tx_ra_bitmap & 0xffff000)
347 			sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
348 		else if (tx_ra_bitmap & 0xff0)
349 			sta_band |= WIRELESS_11G | WIRELESS_11B;
350 		else
351 			sta_band |= WIRELESS_11B;
352 	}
353 
354 	psta->wireless_mode = sta_band;
355 
356 	raid = networktype_to_raid(sta_band);
357 	init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f;
358 
359 	if (psta->aid < NUM_STA) {
360 		u8 arg = 0;
361 
362 		arg = psta->mac_id & 0x1f;
363 
364 		arg |= BIT(7);/* support entry 2~31 */
365 
366 		if (shortGIrate)
367 			arg |= BIT(5);
368 
369 		tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
370 
371 		/* bitmap[0:27] = tx_rate_bitmap */
372 		/* bitmap[28:31]= Rate Adaptive id */
373 		/* arg[0:4] = macid */
374 		/* arg[5] = Short GI */
375 		rtl8188e_Add_RateATid(padapter, tx_ra_bitmap, arg, rssi_level);
376 
377 		if (shortGIrate)
378 			init_rate |= BIT(6);
379 
380 		/* set ra_id, init_rate */
381 		psta->raid = raid;
382 		psta->init_rate = init_rate;
383 	}
384 }
385 
update_bmc_sta(struct adapter * padapter)386 void update_bmc_sta(struct adapter *padapter)
387 {
388 	u32 init_rate = 0;
389 	unsigned char	network_type, raid;
390 	int i, supportRateNum = 0;
391 	unsigned int tx_ra_bitmap = 0;
392 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
393 	struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
394 	struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
395 
396 	if (psta) {
397 		psta->aid = 0;/* default set to 0 */
398 		psta->mac_id = psta->aid + 1;
399 
400 		psta->qos_option = 0;
401 		psta->htpriv.ht_option = false;
402 
403 		psta->ieee8021x_blocked = 0;
404 
405 		memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
406 
407 		/* prepare for add_RATid */
408 		supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
409 		network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, 1);
410 
411 		memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
412 		psta->bssratelen = supportRateNum;
413 
414 		/* b/g mode ra_bitmap */
415 		for (i = 0; i < supportRateNum; i++) {
416 			if (psta->bssrateset[i])
417 				tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i] & 0x7f);
418 		}
419 
420 		if (pcur_network->Configuration.DSConfig > 14) {
421 			network_type = WIRELESS_INVALID;
422 		} else {
423 			/* force to b mode */
424 			network_type = WIRELESS_11B;
425 			tx_ra_bitmap = 0xf;
426 		}
427 
428 		raid = networktype_to_raid(network_type);
429 		init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f;
430 
431 		/* ap mode */
432 		rtl8188e_SetHalODMVar(padapter, psta, true);
433 
434 		{
435 			u8 arg = 0;
436 
437 			arg = psta->mac_id & 0x1f;
438 			arg |= BIT(7);
439 			tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
440 
441 			/* bitmap[0:27] = tx_rate_bitmap */
442 			/* bitmap[28:31]= Rate Adaptive id */
443 			/* arg[0:4] = macid */
444 			/* arg[5] = Short GI */
445 			rtl8188e_Add_RateATid(padapter, tx_ra_bitmap, arg, 0);
446 		}
447 		/* set ra_id, init_rate */
448 		psta->raid = raid;
449 		psta->init_rate = init_rate;
450 
451 		rtw_sta_media_status_rpt(padapter, psta, 1);
452 
453 		spin_lock_bh(&psta->lock);
454 		psta->state = _FW_LINKED;
455 		spin_unlock_bh(&psta->lock);
456 	}
457 }
458 
459 /* notes: */
460 /* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
461 /* MAC_ID = AID+1 for sta in ap/adhoc mode */
462 /* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
463 /* MAC_ID = 0 for bssid for sta/ap/adhoc */
464 /* CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
465 
update_sta_info_apmode(struct adapter * padapter,struct sta_info * psta)466 void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta)
467 {
468 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
469 	struct security_priv *psecuritypriv = &padapter->securitypriv;
470 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
471 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
472 	struct ht_priv	*phtpriv_sta = &psta->htpriv;
473 	u16 sta_cap_info;
474 	u16 ap_cap_info;
475 
476 	psta->mac_id = psta->aid + 1;
477 
478 	/* ap mode */
479 	rtl8188e_SetHalODMVar(padapter, psta, true);
480 
481 	if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
482 		psta->ieee8021x_blocked = true;
483 	else
484 		psta->ieee8021x_blocked = false;
485 
486 	/* update sta's cap */
487 
488 	/* ERP */
489 	VCS_update(padapter, psta);
490 	/* HT related cap */
491 	if (phtpriv_sta->ht_option) {
492 		/* check if sta supports rx ampdu */
493 		phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
494 		sta_cap_info = le16_to_cpu(phtpriv_sta->ht_cap.cap_info);
495 		ap_cap_info = le16_to_cpu(phtpriv_ap->ht_cap.cap_info);
496 
497 		/* check if sta support s Short GI */
498 		if ((sta_cap_info & ap_cap_info) &
499 		    (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40))
500 			phtpriv_sta->sgi = true;
501 
502 		/*  bwmode */
503 		if ((sta_cap_info & ap_cap_info) & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
504 			phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
505 			phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
506 		}
507 		psta->qos_option = true;
508 	} else {
509 		phtpriv_sta->ampdu_enable = false;
510 		phtpriv_sta->sgi = false;
511 		phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
512 		phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
513 	}
514 
515 	/* Rx AMPDU */
516 	send_delba(padapter, 0, psta->hwaddr);/*  recipient */
517 
518 	/* TX AMPDU */
519 	send_delba(padapter, 1, psta->hwaddr);/* originator */
520 	phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
521 	phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
522 
523 	/* todo: init other variables */
524 
525 	memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
526 
527 	spin_lock_bh(&psta->lock);
528 	psta->state |= _FW_LINKED;
529 	spin_unlock_bh(&psta->lock);
530 }
531 
update_bcn_erpinfo_ie(struct adapter * padapter)532 static void update_bcn_erpinfo_ie(struct adapter *padapter)
533 {
534 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
535 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
536 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
537 	struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
538 	unsigned char *p, *ie = pnetwork->IEs;
539 	u32 len = 0;
540 
541 	if (!pmlmeinfo->ERP_enable)
542 		return;
543 
544 	/* parsing ERP_IE */
545 	p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len,
546 		       (pnetwork->IELength - _BEACON_IE_OFFSET_));
547 	if (p && len > 0) {
548 		struct ndis_802_11_var_ie *pIE = (struct ndis_802_11_var_ie *)p;
549 
550 		if (pmlmepriv->num_sta_non_erp == 1)
551 			pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
552 		else
553 			pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
554 
555 		if (pmlmepriv->num_sta_no_short_preamble > 0)
556 			pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
557 		else
558 			pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
559 
560 		ERP_IE_handler(padapter, pIE);
561 	}
562 }
563 
update_bcn_wps_ie(struct adapter * padapter)564 static void update_bcn_wps_ie(struct adapter *padapter)
565 {
566 	u8 *pwps_ie = NULL, *pwps_ie_src;
567 	u8 *premainder_ie, *pbackup_remainder_ie = NULL;
568 	uint wps_ielen = 0, wps_offset, remainder_ielen;
569 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
570 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
571 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
572 	struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
573 	unsigned char *ie = pnetwork->IEs;
574 	u32 ielen = pnetwork->IELength;
575 
576 	pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
577 
578 	if (!pwps_ie || wps_ielen == 0)
579 		return;
580 
581 	wps_offset = (uint)(pwps_ie - ie);
582 
583 	premainder_ie = pwps_ie + wps_ielen;
584 
585 	remainder_ielen = ielen - wps_offset - wps_ielen;
586 
587 	if (remainder_ielen > 0) {
588 		pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
589 		if (pbackup_remainder_ie)
590 			memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
591 	}
592 
593 	pwps_ie_src = pmlmepriv->wps_beacon_ie;
594 	if (!pwps_ie_src)
595 		goto exit;
596 
597 	wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
598 	if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
599 		memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
600 		pwps_ie += (wps_ielen + 2);
601 
602 		if (pbackup_remainder_ie)
603 			memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
604 
605 		/* update IELength */
606 		pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
607 	}
608 
609 exit:
610 	kfree(pbackup_remainder_ie);
611 }
612 
update_bcn_vendor_spec_ie(struct adapter * padapter,u8 * oui)613 static void update_bcn_vendor_spec_ie(struct adapter *padapter, u8 *oui)
614 {
615 	if (!memcmp(WPS_OUI, oui, 4))
616 		update_bcn_wps_ie(padapter);
617 }
618 
update_beacon(struct adapter * padapter,u8 ie_id,u8 * oui,u8 tx)619 void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
620 {
621 	struct mlme_priv *pmlmepriv;
622 	struct mlme_ext_priv	*pmlmeext;
623 
624 	if (!padapter)
625 		return;
626 
627 	pmlmepriv = &padapter->mlmepriv;
628 	pmlmeext = &padapter->mlmeextpriv;
629 
630 	if (!pmlmeext->bstart_bss)
631 		return;
632 
633 	spin_lock_bh(&pmlmepriv->bcn_update_lock);
634 
635 	switch (ie_id) {
636 	case _TIM_IE_:
637 		update_BCNTIM(padapter);
638 		break;
639 	case _ERPINFO_IE_:
640 		update_bcn_erpinfo_ie(padapter);
641 		break;
642 	case _VENDOR_SPECIFIC_IE_:
643 		update_bcn_vendor_spec_ie(padapter, oui);
644 		break;
645 	default:
646 		break;
647 	}
648 
649 	pmlmepriv->update_bcn = true;
650 
651 	spin_unlock_bh(&pmlmepriv->bcn_update_lock);
652 
653 	if (tx)
654 		set_tx_beacon_cmd(padapter);
655 }
656 
657 /* op_mode
658  * Set to 0 (HT pure) under the following conditions
659  *	- all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
660  *	- all STAs in the BSS are 20 MHz HT in 20 MHz BSS
661  * Set to 1 (HT non-member protection) if there may be non-HT STAs
662  *	in both the primary and the secondary channel
663  * Set to 2 if only HT STAs are associated in BSS,
664  *	however and at least one 20 MHz HT STA is associated
665  * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
666  *	(currently non-GF HT station is considered as non-HT STA also)
667  */
rtw_ht_operation_update(struct adapter * padapter)668 static int rtw_ht_operation_update(struct adapter *padapter)
669 {
670 	u16 cur_op_mode, new_op_mode;
671 	int op_mode_changes = 0;
672 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
673 	struct ht_priv	*phtpriv_ap = &pmlmepriv->htpriv;
674 
675 	if (pmlmepriv->htpriv.ht_option)
676 		return 0;
677 
678 	if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
679 	    pmlmepriv->num_sta_ht_no_gf) {
680 		pmlmepriv->ht_op_mode |=
681 			HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
682 		op_mode_changes++;
683 	} else if ((pmlmepriv->ht_op_mode &
684 		   HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
685 		   pmlmepriv->num_sta_ht_no_gf == 0) {
686 		pmlmepriv->ht_op_mode &=
687 			~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
688 		op_mode_changes++;
689 	}
690 
691 	if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
692 	    (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
693 		pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
694 		op_mode_changes++;
695 	} else if ((pmlmepriv->ht_op_mode &
696 		    HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
697 		   (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
698 		pmlmepriv->ht_op_mode &=
699 			~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
700 		op_mode_changes++;
701 	}
702 
703 	/* Note: currently we switch to the MIXED op mode if HT non-greenfield
704 	 * station is associated. Probably it's a theoretical case, since
705 	 * it looks like all known HT STAs support greenfield.
706 	 */
707 	new_op_mode = 0;
708 	if (pmlmepriv->num_sta_no_ht ||
709 	    (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
710 		new_op_mode = OP_MODE_MIXED;
711 	else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) &
712 		  IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
713 		 pmlmepriv->num_sta_ht_20mhz)
714 		new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
715 	else if (pmlmepriv->olbc_ht)
716 		new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
717 	else
718 		new_op_mode = OP_MODE_PURE;
719 
720 	cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
721 	if (cur_op_mode != new_op_mode) {
722 		pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
723 		pmlmepriv->ht_op_mode |= new_op_mode;
724 		op_mode_changes++;
725 	}
726 
727 	return op_mode_changes;
728 }
729 
associated_clients_update(struct adapter * padapter,u8 updated)730 void associated_clients_update(struct adapter *padapter, u8 updated)
731 {
732 	/* update associated stations cap. */
733 	if (updated) {
734 		struct list_head *phead, *plist;
735 		struct sta_info *psta = NULL;
736 		struct sta_priv *pstapriv = &padapter->stapriv;
737 
738 		spin_lock_bh(&pstapriv->asoc_list_lock);
739 
740 		phead = &pstapriv->asoc_list;
741 		plist = phead->next;
742 
743 		/* check asoc_queue */
744 		while (phead != plist) {
745 			psta = container_of(plist, struct sta_info, asoc_list);
746 
747 			plist = plist->next;
748 
749 			VCS_update(padapter, psta);
750 		}
751 		spin_unlock_bh(&pstapriv->asoc_list_lock);
752 	}
753 }
754 
755 /* called > TSR LEVEL for USB or SDIO Interface*/
bss_cap_update_on_sta_join(struct adapter * padapter,struct sta_info * psta)756 void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
757 {
758 	u8 beacon_updated = false;
759 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
760 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
761 
762 	if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
763 		if (!psta->no_short_preamble_set) {
764 			psta->no_short_preamble_set = 1;
765 
766 			pmlmepriv->num_sta_no_short_preamble++;
767 
768 			if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
769 			    (pmlmepriv->num_sta_no_short_preamble == 1)) {
770 				beacon_updated = true;
771 				update_beacon(padapter, 0xFF, NULL, true);
772 			}
773 		}
774 	} else {
775 		if (psta->no_short_preamble_set) {
776 			psta->no_short_preamble_set = 0;
777 
778 			pmlmepriv->num_sta_no_short_preamble--;
779 
780 			if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
781 			    (pmlmepriv->num_sta_no_short_preamble == 0)) {
782 				beacon_updated = true;
783 				update_beacon(padapter, 0xFF, NULL, true);
784 			}
785 		}
786 	}
787 
788 	if (psta->flags & WLAN_STA_NONERP) {
789 		if (!psta->nonerp_set) {
790 			psta->nonerp_set = 1;
791 
792 			pmlmepriv->num_sta_non_erp++;
793 
794 			if (pmlmepriv->num_sta_non_erp == 1) {
795 				beacon_updated = true;
796 				update_beacon(padapter, _ERPINFO_IE_, NULL, true);
797 			}
798 		}
799 	} else {
800 		if (psta->nonerp_set) {
801 			psta->nonerp_set = 0;
802 
803 			pmlmepriv->num_sta_non_erp--;
804 
805 			if (pmlmepriv->num_sta_non_erp == 0) {
806 				beacon_updated = true;
807 				update_beacon(padapter, _ERPINFO_IE_, NULL, true);
808 			}
809 		}
810 	}
811 
812 	if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
813 		if (!psta->no_short_slot_time_set) {
814 			psta->no_short_slot_time_set = 1;
815 
816 			pmlmepriv->num_sta_no_short_slot_time++;
817 
818 			if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
819 			    (pmlmepriv->num_sta_no_short_slot_time == 1)) {
820 				beacon_updated = true;
821 				update_beacon(padapter, 0xFF, NULL, true);
822 			}
823 		}
824 	} else {
825 		if (psta->no_short_slot_time_set) {
826 			psta->no_short_slot_time_set = 0;
827 
828 			pmlmepriv->num_sta_no_short_slot_time--;
829 
830 			if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
831 			    (pmlmepriv->num_sta_no_short_slot_time == 0)) {
832 				beacon_updated = true;
833 				update_beacon(padapter, 0xFF, NULL, true);
834 			}
835 		}
836 	}
837 
838 	if (psta->flags & WLAN_STA_HT) {
839 		u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
840 
841 		if (psta->no_ht_set) {
842 			psta->no_ht_set = 0;
843 			pmlmepriv->num_sta_no_ht--;
844 		}
845 
846 		if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
847 			if (!psta->no_ht_gf_set) {
848 				psta->no_ht_gf_set = 1;
849 				pmlmepriv->num_sta_ht_no_gf++;
850 			}
851 		}
852 
853 		if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH_20_40) == 0) {
854 			if (!psta->ht_20mhz_set) {
855 				psta->ht_20mhz_set = 1;
856 				pmlmepriv->num_sta_ht_20mhz++;
857 			}
858 		}
859 	} else {
860 		if (!psta->no_ht_set) {
861 			psta->no_ht_set = 1;
862 			pmlmepriv->num_sta_no_ht++;
863 		}
864 	}
865 
866 	if (rtw_ht_operation_update(padapter) > 0) {
867 		update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
868 		update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
869 	}
870 
871 	/* update associated stations cap. */
872 	associated_clients_update(padapter,  beacon_updated);
873 }
874 
bss_cap_update_on_sta_leave(struct adapter * padapter,struct sta_info * psta)875 u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
876 {
877 	u8 beacon_updated = false;
878 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
879 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
880 
881 	if (!psta)
882 		return beacon_updated;
883 
884 	if (psta->no_short_preamble_set) {
885 		psta->no_short_preamble_set = 0;
886 		pmlmepriv->num_sta_no_short_preamble--;
887 		if (pmlmeext->cur_wireless_mode > WIRELESS_11B &&
888 		    pmlmepriv->num_sta_no_short_preamble == 0) {
889 			beacon_updated = true;
890 			update_beacon(padapter, 0xFF, NULL, true);
891 		}
892 	}
893 
894 	if (psta->nonerp_set) {
895 		psta->nonerp_set = 0;
896 		pmlmepriv->num_sta_non_erp--;
897 		if (pmlmepriv->num_sta_non_erp == 0) {
898 			beacon_updated = true;
899 			update_beacon(padapter, _ERPINFO_IE_, NULL, true);
900 		}
901 	}
902 
903 	if (psta->no_short_slot_time_set) {
904 		psta->no_short_slot_time_set = 0;
905 		pmlmepriv->num_sta_no_short_slot_time--;
906 		if (pmlmeext->cur_wireless_mode > WIRELESS_11B &&
907 		    pmlmepriv->num_sta_no_short_slot_time == 0) {
908 			beacon_updated = true;
909 			update_beacon(padapter, 0xFF, NULL, true);
910 		}
911 	}
912 
913 	if (psta->no_ht_gf_set) {
914 		psta->no_ht_gf_set = 0;
915 		pmlmepriv->num_sta_ht_no_gf--;
916 	}
917 
918 	if (psta->no_ht_set) {
919 		psta->no_ht_set = 0;
920 		pmlmepriv->num_sta_no_ht--;
921 	}
922 
923 	if (psta->ht_20mhz_set) {
924 		psta->ht_20mhz_set = 0;
925 		pmlmepriv->num_sta_ht_20mhz--;
926 	}
927 
928 	if (rtw_ht_operation_update(padapter) > 0) {
929 		update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
930 		update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
931 	}
932 
933 	/* update associated stations cap. */
934 
935 	return beacon_updated;
936 }
937 
rtw_indicate_sta_assoc_event(struct adapter * padapter,struct sta_info * psta)938 void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *psta)
939 {
940 	union iwreq_data wrqu;
941 	struct sta_priv *pstapriv = &padapter->stapriv;
942 
943 	if (!psta)
944 		return;
945 
946 	if (psta->aid > NUM_STA)
947 		return;
948 
949 	if (pstapriv->sta_aid[psta->aid - 1] != psta)
950 		return;
951 
952 	wrqu.addr.sa_family = ARPHRD_ETHER;
953 
954 	memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
955 
956 	wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
957 }
958 
rtw_indicate_sta_disassoc_event(struct adapter * padapter,struct sta_info * psta)959 static void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *psta)
960 {
961 	union iwreq_data wrqu;
962 	struct sta_priv *pstapriv = &padapter->stapriv;
963 
964 	if (!psta)
965 		return;
966 
967 	if (psta->aid > NUM_STA)
968 		return;
969 
970 	if (pstapriv->sta_aid[psta->aid - 1] != psta)
971 		return;
972 
973 	wrqu.addr.sa_family = ARPHRD_ETHER;
974 
975 	memcpy(wrqu.addr.sa_data, psta->hwaddr, ETH_ALEN);
976 
977 	wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
978 }
979 
ap_free_sta(struct adapter * padapter,struct sta_info * psta,bool active,u16 reason)980 u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta,
981 	       bool active, u16 reason)
982 {
983 	u8 beacon_updated = false;
984 	struct sta_priv *pstapriv = &padapter->stapriv;
985 
986 	if (!psta)
987 		return beacon_updated;
988 
989 	/* tear down Rx AMPDU */
990 	send_delba(padapter, 0, psta->hwaddr);/*  recipient */
991 
992 	/* tear down TX AMPDU */
993 	send_delba(padapter, 1, psta->hwaddr);/*  originator */
994 	psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
995 	psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
996 
997 	if (active)
998 		issue_deauth(padapter, psta->hwaddr, reason);
999 
1000 	/* clear cam entry / key */
1001 	rtw_clearstakey_cmd(padapter, (u8 *)psta, (u8)(psta->mac_id + 3), true);
1002 
1003 	spin_lock_bh(&psta->lock);
1004 	psta->state &= ~_FW_LINKED;
1005 	spin_unlock_bh(&psta->lock);
1006 
1007 	rtw_indicate_sta_disassoc_event(padapter, psta);
1008 
1009 	report_del_sta_event(padapter, psta->hwaddr, reason);
1010 
1011 	beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
1012 
1013 	spin_lock_bh(&pstapriv->sta_hash_lock);
1014 	rtw_free_stainfo(padapter, psta);
1015 	spin_unlock_bh(&pstapriv->sta_hash_lock);
1016 
1017 	return beacon_updated;
1018 }
1019 
rtw_sta_flush(struct adapter * padapter)1020 int rtw_sta_flush(struct adapter *padapter)
1021 {
1022 	struct list_head *phead, *plist;
1023 	int ret = 0;
1024 	struct sta_info *psta = NULL;
1025 	struct sta_priv *pstapriv = &padapter->stapriv;
1026 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1027 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
1028 	u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1029 
1030 	if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
1031 		return ret;
1032 
1033 	spin_lock_bh(&pstapriv->asoc_list_lock);
1034 	phead = &pstapriv->asoc_list;
1035 	plist = phead->next;
1036 
1037 	/* free sta asoc_queue */
1038 	while (phead != plist) {
1039 		psta = container_of(plist, struct sta_info, asoc_list);
1040 
1041 		plist = plist->next;
1042 
1043 		list_del_init(&psta->asoc_list);
1044 		pstapriv->asoc_list_cnt--;
1045 
1046 		ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
1047 	}
1048 	spin_unlock_bh(&pstapriv->asoc_list_lock);
1049 
1050 	issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
1051 
1052 	associated_clients_update(padapter, true);
1053 
1054 	return ret;
1055 }
1056 
1057 /* called > TSR LEVEL for USB or SDIO Interface*/
sta_info_update(struct adapter * padapter,struct sta_info * psta)1058 void sta_info_update(struct adapter *padapter, struct sta_info *psta)
1059 {
1060 	int flags = psta->flags;
1061 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1062 
1063 	/* update wmm cap. */
1064 	if (WLAN_STA_WME & flags)
1065 		psta->qos_option = 1;
1066 	else
1067 		psta->qos_option = 0;
1068 
1069 	if (pmlmepriv->qospriv.qos_option == 0)
1070 		psta->qos_option = 0;
1071 
1072 	/* update 802.11n ht cap. */
1073 	if (WLAN_STA_HT & flags) {
1074 		psta->htpriv.ht_option = true;
1075 		psta->qos_option = 1;
1076 	} else {
1077 		psta->htpriv.ht_option = false;
1078 	}
1079 
1080 	if (!pmlmepriv->htpriv.ht_option)
1081 		psta->htpriv.ht_option = false;
1082 
1083 	update_sta_info_apmode(padapter, psta);
1084 }
1085 
start_ap_mode(struct adapter * padapter)1086 void start_ap_mode(struct adapter *padapter)
1087 {
1088 	int i;
1089 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1090 	struct sta_priv *pstapriv = &padapter->stapriv;
1091 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1092 	struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1093 
1094 	pmlmepriv->update_bcn = false;
1095 
1096 	pmlmeext->bstart_bss = false;
1097 
1098 	pmlmepriv->num_sta_non_erp = 0;
1099 
1100 	pmlmepriv->num_sta_no_short_slot_time = 0;
1101 
1102 	pmlmepriv->num_sta_no_short_preamble = 0;
1103 
1104 	pmlmepriv->num_sta_ht_no_gf = 0;
1105 	pmlmepriv->num_sta_no_ht = 0;
1106 	pmlmepriv->num_sta_ht_20mhz = 0;
1107 
1108 	pmlmepriv->olbc = false;
1109 
1110 	pmlmepriv->olbc_ht = false;
1111 
1112 	pmlmepriv->ht_op_mode = 0;
1113 
1114 	for (i = 0; i < NUM_STA; i++)
1115 		pstapriv->sta_aid[i] = NULL;
1116 
1117 	pmlmepriv->wps_beacon_ie = NULL;
1118 	pmlmepriv->wps_probe_resp_ie = NULL;
1119 	pmlmepriv->wps_assoc_resp_ie = NULL;
1120 
1121 	pmlmepriv->p2p_beacon_ie = NULL;
1122 	pmlmepriv->p2p_probe_resp_ie = NULL;
1123 
1124 	/* for ACL */
1125 	INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
1126 	pacl_list->num = 0;
1127 	pacl_list->mode = 0;
1128 	for (i = 0; i < NUM_ACL; i++) {
1129 		INIT_LIST_HEAD(&pacl_list->aclnode[i].list);
1130 		pacl_list->aclnode[i].valid = false;
1131 	}
1132 }
1133 
stop_ap_mode(struct adapter * padapter)1134 void stop_ap_mode(struct adapter *padapter)
1135 {
1136 	struct list_head *phead, *plist;
1137 	struct rtw_wlan_acl_node *paclnode;
1138 	struct sta_info *psta = NULL;
1139 	struct sta_priv *pstapriv = &padapter->stapriv;
1140 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1141 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1142 	struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1143 	struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1144 
1145 	pmlmepriv->update_bcn = false;
1146 	pmlmeext->bstart_bss = false;
1147 
1148 	/* reset and init security priv , this can refine with rtw_reset_securitypriv */
1149 	memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
1150 	padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1151 	padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
1152 
1153 	/* for ACL */
1154 	spin_lock_bh(&pacl_node_q->lock);
1155 	phead = get_list_head(pacl_node_q);
1156 	plist = phead->next;
1157 	while (phead != plist) {
1158 		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1159 		plist = plist->next;
1160 
1161 		if (paclnode->valid) {
1162 			paclnode->valid = false;
1163 
1164 			list_del_init(&paclnode->list);
1165 
1166 			pacl_list->num--;
1167 		}
1168 	}
1169 	spin_unlock_bh(&pacl_node_q->lock);
1170 
1171 	rtw_sta_flush(padapter);
1172 
1173 	/* free_assoc_sta_resources */
1174 	rtw_free_all_stainfo(padapter);
1175 
1176 	psta = rtw_get_bcmc_stainfo(padapter);
1177 	spin_lock_bh(&pstapriv->sta_hash_lock);
1178 	rtw_free_stainfo(padapter, psta);
1179 	spin_unlock_bh(&pstapriv->sta_hash_lock);
1180 
1181 	rtw_init_bcmc_stainfo(padapter);
1182 
1183 	rtw_free_mlme_priv_ie_data(pmlmepriv);
1184 }
1185