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