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