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