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_ext_priv *pmlmeext = &padapter->mlmeextpriv;
31 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
32
33 _rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
34
35 /* pmlmeext->bstart_bss = _FALSE; */
36
37 }
38
free_mlme_ap_info(_adapter * padapter)39 void free_mlme_ap_info(_adapter *padapter)
40 {
41 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
42
43 stop_ap_mode(padapter);
44 _rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
45
46 }
47
update_BCNTIM(_adapter * padapter)48 static void update_BCNTIM(_adapter *padapter)
49 {
50 struct sta_priv *pstapriv = &padapter->stapriv;
51 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
52 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
53 WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
54 unsigned char *pie = pnetwork_mlmeext->IEs;
55
56 #if 0
57
58
59 /* update TIM IE */
60 /* if(pstapriv->tim_bitmap) */
61 #endif
62 if (_TRUE) {
63 u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
64 u16 tim_bitmap_le;
65 uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
66
67 tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
68
69 p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
70 if (p != NULL && tim_ielen > 0) {
71 tim_ielen += 2;
72
73 premainder_ie = p + tim_ielen;
74
75 tim_ie_offset = (sint)(p - pie);
76
77 remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
78
79 /*append TIM IE from dst_ie offset*/
80 dst_ie = p;
81 } else {
82 tim_ielen = 0;
83
84 /*calculate head_len*/
85 offset = _FIXED_IE_LENGTH_;
86
87 /* get ssid_ie len */
88 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
89 if (p != NULL)
90 offset += tmp_len + 2;
91
92 /*get supported rates len*/
93 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
94 if (p != NULL)
95 offset += tmp_len + 2;
96
97 /*DS Parameter Set IE, len=3*/
98 offset += 3;
99
100 premainder_ie = pie + offset;
101
102 remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
103
104 /*append TIM IE from offset*/
105 dst_ie = pie + offset;
106
107 }
108
109 if (remainder_ielen > 0) {
110 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
111 if (pbackup_remainder_ie && premainder_ie)
112 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
113 }
114
115 *dst_ie++ = _TIM_IE_;
116
117 if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe))
118 tim_ielen = 5;
119 else
120 tim_ielen = 4;
121
122 *dst_ie++ = tim_ielen;
123
124 *dst_ie++ = 0;/*DTIM count*/
125 *dst_ie++ = 1;/*DTIM period*/
126
127 if (pstapriv->tim_bitmap & BIT(0))/*for bc/mc frames*/
128 *dst_ie++ = BIT(0);/*bitmap ctrl */
129 else
130 *dst_ie++ = 0;
131
132 if (tim_ielen == 4) {
133 u8 pvb = 0;
134
135 if (pstapriv->tim_bitmap & 0x00fe)
136 pvb = (u8)tim_bitmap_le;
137 else if (pstapriv->tim_bitmap & 0xff00)
138 pvb = (u8)(tim_bitmap_le >> 8);
139 else
140 pvb = (u8)tim_bitmap_le;
141
142 *dst_ie++ = pvb;
143
144 } else if (tim_ielen == 5) {
145 _rtw_memcpy(dst_ie, &tim_bitmap_le, 2);
146 dst_ie += 2;
147 }
148
149 /*copy remainder IE*/
150 if (pbackup_remainder_ie) {
151 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
152
153 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
154 }
155
156 offset = (uint)(dst_ie - pie);
157 pnetwork_mlmeext->IELength = offset + remainder_ielen;
158
159 }
160 }
161
rtw_add_bcn_ie(_adapter * padapter,WLAN_BSSID_EX * pnetwork,u8 index,u8 * data,u8 len)162 void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
163 {
164 PNDIS_802_11_VARIABLE_IEs pIE;
165 u8 bmatch = _FALSE;
166 u8 *pie = pnetwork->IEs;
167 u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
168 u32 i, offset, ielen, ie_offset, remainder_ielen = 0;
169
170 for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
171 pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
172
173 if (pIE->ElementID > index)
174 break;
175 else if (pIE->ElementID == index) { /* already exist the same IE */
176 p = (u8 *)pIE;
177 ielen = pIE->Length;
178 bmatch = _TRUE;
179 break;
180 }
181
182 p = (u8 *)pIE;
183 ielen = pIE->Length;
184 i += (pIE->Length + 2);
185 }
186
187 if (p != NULL && ielen > 0) {
188 ielen += 2;
189
190 premainder_ie = p + ielen;
191
192 ie_offset = (sint)(p - pie);
193
194 remainder_ielen = pnetwork->IELength - ie_offset - ielen;
195
196 if (bmatch)
197 dst_ie = p;
198 else
199 dst_ie = (p + ielen);
200 }
201
202 if (dst_ie == NULL)
203 return;
204
205 if (remainder_ielen > 0) {
206 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
207 if (pbackup_remainder_ie && premainder_ie)
208 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
209 }
210
211 *dst_ie++ = index;
212 *dst_ie++ = len;
213
214 _rtw_memcpy(dst_ie, data, len);
215 dst_ie += len;
216
217 /* copy remainder IE */
218 if (pbackup_remainder_ie) {
219 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
220
221 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
222 }
223
224 offset = (uint)(dst_ie - pie);
225 pnetwork->IELength = offset + remainder_ielen;
226 }
227
rtw_remove_bcn_ie(_adapter * padapter,WLAN_BSSID_EX * pnetwork,u8 index)228 void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
229 {
230 u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
231 uint offset, ielen, ie_offset, remainder_ielen = 0;
232 u8 *pie = pnetwork->IEs;
233
234 p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
235 if (p != NULL && ielen > 0) {
236 ielen += 2;
237
238 premainder_ie = p + ielen;
239
240 ie_offset = (sint)(p - pie);
241
242 remainder_ielen = pnetwork->IELength - ie_offset - ielen;
243
244 dst_ie = p;
245 } else
246 return;
247
248 if (remainder_ielen > 0) {
249 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
250 if (pbackup_remainder_ie && premainder_ie)
251 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
252 }
253
254 /* copy remainder IE */
255 if (pbackup_remainder_ie) {
256 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
257
258 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
259 }
260
261 offset = (uint)(dst_ie - pie);
262 pnetwork->IELength = offset + remainder_ielen;
263 }
264
265
266 u8 chk_sta_is_alive(struct sta_info *psta);
chk_sta_is_alive(struct sta_info * psta)267 u8 chk_sta_is_alive(struct sta_info *psta)
268 {
269 u8 ret = _FALSE;
270 #ifdef DBG_EXPIRATION_CHK
271 RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
272 , MAC_ARG(psta->cmn.mac_addr)
273 , psta->cmn.rssi_stat.rssi
274 /* , STA_RX_PKTS_ARG(psta) */
275 , STA_RX_PKTS_DIFF_ARG(psta)
276 , psta->expire_to
277 , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
278 , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
279 , psta->sleepq_len
280 );
281 #endif
282
283 /* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
284 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)) {
285 #if 0
286 if (psta->state & WIFI_SLEEP_STATE)
287 ret = _TRUE;
288 #endif
289 } else
290 ret = _TRUE;
291
292 sta_update_last_rx_pkts(psta);
293
294 return ret;
295 }
296
expire_timeout_chk(_adapter * padapter)297 void expire_timeout_chk(_adapter *padapter)
298 {
299 _irqL irqL;
300 _list *phead, *plist;
301 u8 updated = _FALSE;
302 struct sta_info *psta = NULL;
303 struct sta_priv *pstapriv = &padapter->stapriv;
304 u8 chk_alive_num = 0;
305 char chk_alive_list[NUM_STA];
306 int i;
307
308
309 #ifdef CONFIG_MCC_MODE
310 /* then driver may check fail due to not recv client's frame under sitesurvey,
311 * don't expire timeout chk under MCC under sitesurvey */
312
313 if (rtw_hal_mcc_link_status_chk(padapter, __func__) == _FALSE)
314 return;
315 #endif
316
317 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
318
319 phead = &pstapriv->auth_list;
320 plist = get_next(phead);
321
322 /* check auth_queue */
323 #ifdef DBG_EXPIRATION_CHK
324 if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
325 RTW_INFO(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
326 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
327 }
328 #endif
329 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
330 psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
331
332 plist = get_next(plist);
333
334
335 #ifdef CONFIG_ATMEL_RC_PATCH
336 if (_rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->cmn.mac_addr), ETH_ALEN) == _TRUE)
337 continue;
338 if (psta->flag_atmel_rc)
339 continue;
340 #endif
341 if (psta->expire_to > 0) {
342 psta->expire_to--;
343 if (psta->expire_to == 0) {
344 rtw_list_delete(&psta->auth_list);
345 pstapriv->auth_list_cnt--;
346
347 RTW_INFO("auth expire %02X%02X%02X%02X%02X%02X\n",
348 psta->cmn.mac_addr[0], psta->cmn.mac_addr[1], psta->cmn.mac_addr[2],
349 psta->cmn.mac_addr[3], psta->cmn.mac_addr[4], psta->cmn.mac_addr[5]);
350
351 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
352
353 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
354 rtw_free_stainfo(padapter, psta);
355 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
356
357 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
358 }
359 }
360
361 }
362
363 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
364 psta = NULL;
365
366
367 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
368
369 phead = &pstapriv->asoc_list;
370 plist = get_next(phead);
371
372 /* check asoc_queue */
373 #ifdef DBG_EXPIRATION_CHK
374 if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
375 RTW_INFO(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
376 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
377 }
378 #endif
379 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
380 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
381 plist = get_next(plist);
382 #ifdef CONFIG_ATMEL_RC_PATCH
383 RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
384 psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->cmn.mac_addr[0], psta->cmn.mac_addr[5]);
385 if (_rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->cmn.mac_addr), ETH_ALEN) == _TRUE)
386 continue;
387 if (psta->flag_atmel_rc)
388 continue;
389 RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
390 #endif
391 #ifdef CONFIG_AUTO_AP_MODE
392 if (psta->isrc)
393 continue;
394 #endif
395 if (chk_sta_is_alive(psta) || !psta->expire_to) {
396 psta->expire_to = pstapriv->expire_to;
397 psta->keep_alive_trycnt = 0;
398 #ifdef CONFIG_TX_MCAST2UNI
399 psta->under_exist_checking = 0;
400 #endif /* CONFIG_TX_MCAST2UNI */
401 } else
402 psta->expire_to--;
403
404 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
405 #ifdef CONFIG_80211N_HT
406 #ifdef CONFIG_TX_MCAST2UNI
407 if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
408 /* check sta by delba(addba) for 11n STA */
409 /* ToDo: use CCX report to check for all STAs */
410 /* 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); */
411
412 if (psta->expire_to <= (pstapriv->expire_to - 50)) {
413 RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
414 psta->under_exist_checking = 0;
415 psta->expire_to = 0;
416 } else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
417 RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
418 psta->under_exist_checking = 1;
419 /* tear down TX AMPDU */
420 send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
421 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
422 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
423 }
424 }
425 #endif /* CONFIG_TX_MCAST2UNI */
426 #endif /* CONFIG_80211N_HT */
427 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
428
429 if (psta->expire_to <= 0) {
430 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
431
432 if (padapter->registrypriv.wifi_spec == 1) {
433 psta->expire_to = pstapriv->expire_to;
434 continue;
435 }
436
437 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
438 #ifdef CONFIG_80211N_HT
439
440 #define KEEP_ALIVE_TRYCNT (3)
441
442 if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
443 if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
444 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
445 else
446 psta->keep_alive_trycnt = 0;
447
448 } else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
449 psta->keep_alive_trycnt = 0;
450 if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
451 uint priority = 1; /* test using BK */
452 u8 issued = 0;
453
454 /* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
455 issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
456
457 if (0 == issued) {
458 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
459 psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
460
461 if (psta->state & WIFI_SLEEP_STATE)
462 psta->expire_to = 2; /* 2x2=4 sec */
463 else
464 psta->expire_to = 1; /* 2 sec */
465
466 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
467
468 /* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
469
470 RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
471
472 issue_addba_req(padapter, psta->cmn.mac_addr, (u8)priority);
473
474 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
475
476 psta->keep_alive_trycnt++;
477
478 continue;
479 }
480 }
481 }
482 if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
483 psta->keep_alive_trycnt = 0;
484 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
485 RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
486 }
487
488 #endif /* CONFIG_80211N_HT */
489 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
490 if (psta->state & WIFI_SLEEP_STATE) {
491 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
492 /* to check if alive by another methods if staion is at ps mode. */
493 psta->expire_to = pstapriv->expire_to;
494 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
495
496 /* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->cmn.mac_addr)); */
497
498 /* to update bcn with tim_bitmap for this station */
499 pstapriv->tim_bitmap |= BIT(psta->cmn.aid);
500 update_beacon(padapter, _TIM_IE_, NULL, _TRUE);
501
502 if (!pmlmeext->active_keep_alive_check)
503 continue;
504 }
505 }
506 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
507 if (pmlmeext->active_keep_alive_check) {
508 int stainfo_offset;
509
510 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
511 if (stainfo_offset_valid(stainfo_offset))
512 chk_alive_list[chk_alive_num++] = stainfo_offset;
513
514 continue;
515 }
516 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
517 rtw_list_delete(&psta->asoc_list);
518 pstapriv->asoc_list_cnt--;
519 RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->cmn.mac_addr), psta->state);
520 updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
521 } else {
522 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
523 if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
524 && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
525 ) {
526 RTW_INFO("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__
527 , MAC_ARG(psta->cmn.mac_addr)
528 , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
529 wakeup_sta_to_xmit(padapter, psta);
530 }
531 }
532 }
533
534 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
535
536 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
537 if (chk_alive_num) {
538
539 u8 backup_ch = 0, backup_bw = 0, backup_offset = 0;
540 u8 union_ch = 0, union_bw, union_offset;
541 u8 switch_channel = _TRUE;
542 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
543
544 if (!rtw_mi_get_ch_setting_union(padapter, &union_ch, &union_bw, &union_offset)
545 || pmlmeext->cur_channel != union_ch)
546 goto bypass_active_keep_alive;
547
548 #ifdef CONFIG_MCC_MODE
549 if (MCC_EN(padapter)) {
550 /* driver doesn't switch channel under MCC */
551 if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
552 switch_channel = _FALSE;
553 }
554 #endif
555 /* switch to correct channel of current network before issue keep-alive frames */
556 if (switch_channel == _TRUE && rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
557 backup_ch = rtw_get_oper_ch(padapter);
558 backup_bw = rtw_get_oper_bw(padapter);
559 backup_offset = rtw_get_oper_choffset(padapter);
560 set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
561 }
562
563 /* issue null data to check sta alive*/
564 for (i = 0; i < chk_alive_num; i++) {
565 int ret = _FAIL;
566
567 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
568 #ifdef CONFIG_ATMEL_RC_PATCH
569 if (_rtw_memcmp(pstapriv->atmel_rc_pattern, psta->cmn.mac_addr, ETH_ALEN) == _TRUE)
570 continue;
571 if (psta->flag_atmel_rc)
572 continue;
573 #endif
574 if (!(psta->state & _FW_LINKED))
575 continue;
576
577 if (psta->state & WIFI_SLEEP_STATE)
578 ret = issue_nulldata(padapter, psta->cmn.mac_addr, 0, 1, 50);
579 else
580 ret = issue_nulldata(padapter, psta->cmn.mac_addr, 0, 3, 50);
581
582 psta->keep_alive_trycnt++;
583 if (ret == _SUCCESS) {
584 RTW_INFO("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->cmn.mac_addr));
585 psta->expire_to = pstapriv->expire_to;
586 psta->keep_alive_trycnt = 0;
587 continue;
588 } else if (psta->keep_alive_trycnt <= 3) {
589 RTW_INFO("ack check for asoc expire, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
590 psta->expire_to = 1;
591 continue;
592 }
593
594 psta->keep_alive_trycnt = 0;
595 RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->cmn.mac_addr), psta->state);
596 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
597 if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
598 rtw_list_delete(&psta->asoc_list);
599 pstapriv->asoc_list_cnt--;
600 updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
601 }
602 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
603
604 }
605
606 /* back to the original operation channel */
607 if (switch_channel && backup_ch > 0)
608 set_channel_bwmode(padapter, backup_ch, backup_offset, backup_bw);
609
610 bypass_active_keep_alive:
611 ;
612 }
613 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
614
615 associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
616 }
617
rtw_ap_update_sta_ra_info(_adapter * padapter,struct sta_info * psta)618 void rtw_ap_update_sta_ra_info(_adapter *padapter, struct sta_info *psta)
619 {
620 int i;
621 u8 rf_type;
622 unsigned char sta_band = 0;
623 u64 tx_ra_bitmap = 0;
624 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
625 WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
626
627 if (!psta)
628 return;
629
630 if (!(psta->state & _FW_LINKED))
631 return;
632
633 rtw_hal_update_sta_ra_info(padapter, psta);
634 tx_ra_bitmap = psta->cmn.ra_info.ramask;
635
636 if (pcur_network->Configuration.DSConfig > 14) {
637
638 if (tx_ra_bitmap & 0xffff000)
639 sta_band |= WIRELESS_11_5N;
640
641 if (tx_ra_bitmap & 0xff0)
642 sta_band |= WIRELESS_11A;
643
644 /* 5G band */
645 #ifdef CONFIG_80211AC_VHT
646 if (psta->vhtpriv.vht_option)
647 sta_band = WIRELESS_11_5AC;
648 #endif
649 } else {
650 if (tx_ra_bitmap & 0xffff000)
651 sta_band |= WIRELESS_11_24N;
652
653 if (tx_ra_bitmap & 0xff0)
654 sta_band |= WIRELESS_11G;
655
656 if (tx_ra_bitmap & 0x0f)
657 sta_band |= WIRELESS_11B;
658 }
659
660 psta->wireless_mode = sta_band;
661 rtw_hal_update_sta_wset(padapter, psta);
662 RTW_INFO("%s=> mac_id:%d , tx_ra_bitmap:0x%016llx, networkType:0x%02x\n",
663 __FUNCTION__, psta->cmn.mac_id, tx_ra_bitmap, psta->wireless_mode);
664 }
665
666 #ifdef CONFIG_BMC_TX_RATE_SELECT
rtw_ap_find_mini_tx_rate(_adapter * adapter)667 u8 rtw_ap_find_mini_tx_rate(_adapter *adapter)
668 {
669 _irqL irqL;
670 _list *phead, *plist;
671 u8 miini_tx_rate = ODM_RATEVHTSS4MCS9, sta_tx_rate;
672 struct sta_info *psta = NULL;
673 struct sta_priv *pstapriv = &adapter->stapriv;
674
675 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
676 phead = &pstapriv->asoc_list;
677 plist = get_next(phead);
678 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
679 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
680 plist = get_next(plist);
681
682 sta_tx_rate = psta->cmn.ra_info.curr_tx_rate & 0x7F;
683 if (sta_tx_rate < miini_tx_rate)
684 miini_tx_rate = sta_tx_rate;
685 }
686 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
687
688 return miini_tx_rate;
689 }
690
rtw_ap_find_bmc_rate(_adapter * adapter,u8 tx_rate)691 u8 rtw_ap_find_bmc_rate(_adapter *adapter, u8 tx_rate)
692 {
693 PHAL_DATA_TYPE hal_data = GET_HAL_DATA(adapter);
694 u8 tx_ini_rate = ODM_RATE6M;
695
696 switch (tx_rate) {
697 case ODM_RATEVHTSS3MCS9:
698 case ODM_RATEVHTSS3MCS8:
699 case ODM_RATEVHTSS3MCS7:
700 case ODM_RATEVHTSS3MCS6:
701 case ODM_RATEVHTSS3MCS5:
702 case ODM_RATEVHTSS3MCS4:
703 case ODM_RATEVHTSS3MCS3:
704 case ODM_RATEVHTSS2MCS9:
705 case ODM_RATEVHTSS2MCS8:
706 case ODM_RATEVHTSS2MCS7:
707 case ODM_RATEVHTSS2MCS6:
708 case ODM_RATEVHTSS2MCS5:
709 case ODM_RATEVHTSS2MCS4:
710 case ODM_RATEVHTSS2MCS3:
711 case ODM_RATEVHTSS1MCS9:
712 case ODM_RATEVHTSS1MCS8:
713 case ODM_RATEVHTSS1MCS7:
714 case ODM_RATEVHTSS1MCS6:
715 case ODM_RATEVHTSS1MCS5:
716 case ODM_RATEVHTSS1MCS4:
717 case ODM_RATEVHTSS1MCS3:
718 case ODM_RATEMCS15:
719 case ODM_RATEMCS14:
720 case ODM_RATEMCS13:
721 case ODM_RATEMCS12:
722 case ODM_RATEMCS11:
723 case ODM_RATEMCS7:
724 case ODM_RATEMCS6:
725 case ODM_RATEMCS5:
726 case ODM_RATEMCS4:
727 case ODM_RATEMCS3:
728 case ODM_RATE54M:
729 case ODM_RATE48M:
730 case ODM_RATE36M:
731 case ODM_RATE24M:
732 tx_ini_rate = ODM_RATE24M;
733 break;
734 case ODM_RATEVHTSS3MCS2:
735 case ODM_RATEVHTSS3MCS1:
736 case ODM_RATEVHTSS2MCS2:
737 case ODM_RATEVHTSS2MCS1:
738 case ODM_RATEVHTSS1MCS2:
739 case ODM_RATEVHTSS1MCS1:
740 case ODM_RATEMCS10:
741 case ODM_RATEMCS9:
742 case ODM_RATEMCS2:
743 case ODM_RATEMCS1:
744 case ODM_RATE18M:
745 case ODM_RATE12M:
746 tx_ini_rate = ODM_RATE12M;
747 break;
748 case ODM_RATEVHTSS3MCS0:
749 case ODM_RATEVHTSS2MCS0:
750 case ODM_RATEVHTSS1MCS0:
751 case ODM_RATEMCS8:
752 case ODM_RATEMCS0:
753 case ODM_RATE9M:
754 case ODM_RATE6M:
755 tx_ini_rate = ODM_RATE6M;
756 break;
757 case ODM_RATE11M:
758 case ODM_RATE5_5M:
759 case ODM_RATE2M:
760 case ODM_RATE1M:
761 tx_ini_rate = ODM_RATE1M;
762 break;
763 default:
764 tx_ini_rate = ODM_RATE6M;
765 break;
766 }
767
768 if (hal_data->current_band_type == BAND_ON_5G)
769 if (tx_ini_rate < ODM_RATE6M)
770 tx_ini_rate = ODM_RATE6M;
771
772 return tx_ini_rate;
773 }
774
rtw_update_bmc_sta_tx_rate(_adapter * adapter)775 void rtw_update_bmc_sta_tx_rate(_adapter *adapter)
776 {
777 struct sta_info *psta = NULL;
778 u8 tx_rate;
779
780 psta = rtw_get_bcmc_stainfo(adapter);
781 if (psta == NULL) {
782 RTW_ERR(ADPT_FMT "could not get bmc_sta !!\n", ADPT_ARG(adapter));
783 return;
784 }
785
786 if (adapter->bmc_tx_rate != MGN_UNKNOWN) {
787 psta->init_rate = adapter->bmc_tx_rate;
788 goto _exit;
789 }
790
791 if (adapter->stapriv.asoc_sta_count <= 2)
792 goto _exit;
793
794 tx_rate = rtw_ap_find_mini_tx_rate(adapter);
795 #ifdef CONFIG_BMC_TX_LOW_RATE
796 tx_rate = rtw_ap_find_bmc_rate(adapter, tx_rate);
797 #endif
798
799 psta->init_rate = hw_rate_to_m_rate(tx_rate);
800
801 _exit:
802 RTW_INFO(ADPT_FMT" BMC Tx rate - %s\n", ADPT_ARG(adapter), MGN_RATE_STR(psta->init_rate));
803 }
804 #endif
805
rtw_init_bmc_sta_tx_rate(_adapter * padapter,struct sta_info * psta)806 void rtw_init_bmc_sta_tx_rate(_adapter *padapter, struct sta_info *psta)
807 {
808 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
809 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
810 u8 rate_idx = 0;
811 u8 brate_table[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M,
812 MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};
813
814 if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
815 return;
816
817 if (padapter->bmc_tx_rate != MGN_UNKNOWN)
818 psta->init_rate = padapter->bmc_tx_rate;
819 else {
820 #ifdef CONFIG_BMC_TX_LOW_RATE
821 if (IsEnableHWOFDM(pmlmeext->cur_wireless_mode) && (psta->cmn.ra_info.ramask && 0xFF0))
822 rate_idx = get_lowest_rate_idx_ex(psta->cmn.ra_info.ramask, 4); /*from basic rate*/
823 else
824 rate_idx = get_lowest_rate_idx(psta->cmn.ra_info.ramask); /*from basic rate*/
825 #else
826 rate_idx = get_highest_rate_idx(psta->cmn.ra_info.ramask); /*from basic rate*/
827 #endif
828 if (rate_idx < 12)
829 psta->init_rate = brate_table[rate_idx];
830 else
831 psta->init_rate = MGN_1M;
832 }
833
834 RTW_INFO(ADPT_FMT" BMC Init Tx rate - %s\n", ADPT_ARG(padapter), MGN_RATE_STR(psta->init_rate));
835 }
836
update_bmc_sta(_adapter * padapter)837 void update_bmc_sta(_adapter *padapter)
838 {
839 _irqL irqL;
840 unsigned char network_type;
841 int supportRateNum = 0;
842 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
843 WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
844 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
845
846 if (psta) {
847 psta->cmn.aid = 0;/* default set to 0 */
848 psta->qos_option = 0;
849 #ifdef CONFIG_80211N_HT
850 psta->htpriv.ht_option = _FALSE;
851 #endif /* CONFIG_80211N_HT */
852
853 psta->ieee8021x_blocked = 0;
854
855 _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
856
857 /* psta->dot118021XPrivacy = _NO_PRIVACY_; */ /* !!! remove it, because it has been set before this. */
858
859 supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
860 network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, pcur_network->Configuration.DSConfig);
861 if (IsSupportedTxCCK(network_type))
862 network_type = WIRELESS_11B;
863 else if (network_type == WIRELESS_INVALID) { /* error handling */
864 if (pcur_network->Configuration.DSConfig > 14)
865 network_type = WIRELESS_11A;
866 else
867 network_type = WIRELESS_11B;
868 }
869 update_sta_basic_rate(psta, network_type);
870 psta->wireless_mode = network_type;
871
872 rtw_hal_update_sta_ra_info(padapter, psta);
873
874 _enter_critical_bh(&psta->lock, &irqL);
875 psta->state = _FW_LINKED;
876 _exit_critical_bh(&psta->lock, &irqL);
877
878 rtw_sta_media_status_rpt(padapter, psta, 1);
879 rtw_init_bmc_sta_tx_rate(padapter, psta);
880
881 } else
882 RTW_INFO("add_RATid_bmc_sta error!\n");
883
884 }
885
886 #if defined(CONFIG_80211N_HT) && defined(CONFIG_BEAMFORMING)
update_sta_info_apmode_ht_bf_cap(_adapter * padapter,struct sta_info * psta)887 void update_sta_info_apmode_ht_bf_cap(_adapter *padapter, struct sta_info *psta)
888 {
889 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
890 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
891 struct ht_priv *phtpriv_sta = &psta->htpriv;
892
893 u8 cur_beamform_cap = 0;
894
895 /*Config Tx beamforming setting*/
896 if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
897 GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
898 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
899 /*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
900 SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
901 }
902
903 if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
904 GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
905 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
906 /*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
907 SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
908 }
909 if (cur_beamform_cap)
910 RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->cmn.aid, cur_beamform_cap);
911
912 phtpriv_sta->beamform_cap = cur_beamform_cap;
913 psta->cmn.bf_info.ht_beamform_cap = cur_beamform_cap;
914
915 }
916 #endif /*CONFIG_80211N_HT && CONFIG_BEAMFORMING*/
917
918 /* notes:
919 * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
update_sta_info_apmode(_adapter * padapter,struct sta_info * psta)920 void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
921 {
922 _irqL irqL;
923 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
924 struct security_priv *psecuritypriv = &padapter->securitypriv;
925 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
926 #ifdef CONFIG_80211N_HT
927 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
928 struct ht_priv *phtpriv_sta = &psta->htpriv;
929 #endif /* CONFIG_80211N_HT */
930 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0;
931 /* set intf_tag to if1 */
932 /* psta->intf_tag = 0; */
933
934 RTW_INFO("%s\n", __FUNCTION__);
935
936 /*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
937
938 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
939 psta->ieee8021x_blocked = _TRUE;
940 else
941 psta->ieee8021x_blocked = _FALSE;
942
943
944 /* update sta's cap */
945
946 /* ERP */
947 VCS_update(padapter, psta);
948 #ifdef CONFIG_80211N_HT
949 /* HT related cap */
950 if (phtpriv_sta->ht_option) {
951 /* check if sta supports rx ampdu */
952 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
953
954 phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
955
956 /* bwmode */
957 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
958 psta->cmn.bw_mode = CHANNEL_WIDTH_40;
959 else
960 psta->cmn.bw_mode = CHANNEL_WIDTH_20;
961
962 if (psta->ht_40mhz_intolerant)
963 psta->cmn.bw_mode = CHANNEL_WIDTH_20;
964
965 if (pmlmeext->cur_bwmode < psta->cmn.bw_mode)
966 psta->cmn.bw_mode = pmlmeext->cur_bwmode;
967
968 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
969
970
971 /* check if sta support s Short GI 20M */
972 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
973 phtpriv_sta->sgi_20m = _TRUE;
974
975 /* check if sta support s Short GI 40M */
976 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
977 if (psta->cmn.bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
978 phtpriv_sta->sgi_40m = _TRUE;
979 else
980 phtpriv_sta->sgi_40m = _FALSE;
981 }
982
983 psta->qos_option = _TRUE;
984
985 /* B0 Config LDPC Coding Capability */
986 if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
987 GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
988 SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
989 RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->cmn.aid);
990 }
991
992 /* B7 B8 B9 Config STBC setting */
993 if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
994 GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
995 SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
996 RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->cmn.aid);
997 }
998
999 #ifdef CONFIG_BEAMFORMING
1000 update_sta_info_apmode_ht_bf_cap(padapter, psta);
1001 #endif
1002 } else {
1003 phtpriv_sta->ampdu_enable = _FALSE;
1004
1005 phtpriv_sta->sgi_20m = _FALSE;
1006 phtpriv_sta->sgi_40m = _FALSE;
1007 psta->cmn.bw_mode = CHANNEL_WIDTH_20;
1008 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1009 }
1010
1011 phtpriv_sta->ldpc_cap = cur_ldpc_cap;
1012 phtpriv_sta->stbc_cap = cur_stbc_cap;
1013
1014 /* Rx AMPDU */
1015 send_delba(padapter, 0, psta->cmn.mac_addr);/* recipient */
1016
1017 /* TX AMPDU */
1018 send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
1019 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
1020 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
1021 #endif /* CONFIG_80211N_HT */
1022
1023 #ifdef CONFIG_80211AC_VHT
1024 update_sta_vht_info_apmode(padapter, psta);
1025 #endif
1026 psta->cmn.ra_info.is_support_sgi = query_ra_short_GI(psta, rtw_get_tx_bw_mode(padapter, psta));
1027 update_ldpc_stbc_cap(psta);
1028
1029 /* todo: init other variables */
1030
1031 _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
1032
1033
1034 /* add ratid */
1035 /* add_RATid(padapter, psta); */ /* move to ap_sta_info_defer_update() */
1036
1037 /* ap mode */
1038 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
1039
1040 _enter_critical_bh(&psta->lock, &irqL);
1041 psta->state |= _FW_LINKED;
1042 _exit_critical_bh(&psta->lock, &irqL);
1043
1044
1045 }
1046
update_ap_info(_adapter * padapter,struct sta_info * psta)1047 static void update_ap_info(_adapter *padapter, struct sta_info *psta)
1048 {
1049 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1050 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
1051 struct security_priv *psecuritypriv = &padapter->securitypriv;
1052 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1053 #ifdef CONFIG_80211N_HT
1054 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
1055 #endif /* CONFIG_80211N_HT */
1056
1057 psta->wireless_mode = pmlmeext->cur_wireless_mode;
1058
1059 psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
1060 _rtw_memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
1061
1062 #ifdef CONFIG_80211N_HT
1063 /* HT related cap */
1064 if (phtpriv_ap->ht_option) {
1065 /* check if sta supports rx ampdu */
1066 /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
1067
1068 /* check if sta support s Short GI 20M */
1069 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
1070 phtpriv_ap->sgi_20m = _TRUE;
1071 /* check if sta support s Short GI 40M */
1072 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
1073 phtpriv_ap->sgi_40m = _TRUE;
1074
1075 psta->qos_option = _TRUE;
1076 } else {
1077 phtpriv_ap->ampdu_enable = _FALSE;
1078
1079 phtpriv_ap->sgi_20m = _FALSE;
1080 phtpriv_ap->sgi_40m = _FALSE;
1081 }
1082
1083 psta->cmn.bw_mode = pmlmeext->cur_bwmode;
1084 phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
1085
1086 phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
1087 phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
1088
1089 _rtw_memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
1090
1091 #ifdef CONFIG_80211AC_VHT
1092 _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
1093 #endif /* CONFIG_80211AC_VHT */
1094
1095 #endif /* CONFIG_80211N_HT */
1096
1097 psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
1098 }
1099
rtw_set_hw_wmm_param(_adapter * padapter)1100 static void rtw_set_hw_wmm_param(_adapter *padapter)
1101 {
1102 u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
1103 u8 acm_mask;
1104 u16 TXOP;
1105 u32 acParm, i;
1106 u32 edca[4], inx[4];
1107 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1108 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1109 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1110 struct registry_priv *pregpriv = &padapter->registrypriv;
1111
1112 acm_mask = 0;
1113
1114 if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
1115 (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
1116 aSifsTime = 16;
1117 else
1118 aSifsTime = 10;
1119
1120 if (pmlmeinfo->WMM_enable == 0) {
1121 padapter->mlmepriv.acm_mask = 0;
1122
1123 AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
1124
1125 if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
1126 ECWMin = 4;
1127 ECWMax = 10;
1128 } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
1129 ECWMin = 5;
1130 ECWMax = 10;
1131 } else {
1132 ECWMin = 4;
1133 ECWMax = 10;
1134 }
1135
1136 TXOP = 0;
1137 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1138 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
1139 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
1140 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
1141
1142 ECWMin = 2;
1143 ECWMax = 3;
1144 TXOP = 0x2f;
1145 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1146 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
1147
1148 } else {
1149 edca[0] = edca[1] = edca[2] = edca[3] = 0;
1150
1151 /*TODO:*/
1152 acm_mask = 0;
1153 padapter->mlmepriv.acm_mask = acm_mask;
1154
1155 #if 0
1156 /* BK */
1157 /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
1158 #endif
1159 AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
1160 ECWMin = 4;
1161 ECWMax = 10;
1162 TXOP = 0;
1163 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1164 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
1165 edca[XMIT_BK_QUEUE] = acParm;
1166 RTW_INFO("WMM(BK): %x\n", acParm);
1167
1168 /* BE */
1169 AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
1170 ECWMin = 4;
1171 ECWMax = 6;
1172 TXOP = 0;
1173 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1174 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
1175 edca[XMIT_BE_QUEUE] = acParm;
1176 RTW_INFO("WMM(BE): %x\n", acParm);
1177
1178 /* VI */
1179 AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1180 ECWMin = 3;
1181 ECWMax = 4;
1182 TXOP = 94;
1183 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1184 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
1185 edca[XMIT_VI_QUEUE] = acParm;
1186 RTW_INFO("WMM(VI): %x\n", acParm);
1187
1188 /* VO */
1189 AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1190 ECWMin = 2;
1191 ECWMax = 3;
1192 TXOP = 47;
1193 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1194 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
1195 edca[XMIT_VO_QUEUE] = acParm;
1196 RTW_INFO("WMM(VO): %x\n", acParm);
1197
1198
1199 if (padapter->registrypriv.acm_method == 1)
1200 rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
1201 else
1202 padapter->mlmepriv.acm_mask = acm_mask;
1203
1204 inx[0] = 0;
1205 inx[1] = 1;
1206 inx[2] = 2;
1207 inx[3] = 3;
1208
1209 if (pregpriv->wifi_spec == 1) {
1210 u32 j, tmp, change_inx = _FALSE;
1211
1212 /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
1213 for (i = 0 ; i < 4 ; i++) {
1214 for (j = i + 1 ; j < 4 ; j++) {
1215 /* compare CW and AIFS */
1216 if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
1217 change_inx = _TRUE;
1218 else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
1219 /* compare TXOP */
1220 if ((edca[j] >> 16) > (edca[i] >> 16))
1221 change_inx = _TRUE;
1222 }
1223
1224 if (change_inx) {
1225 tmp = edca[i];
1226 edca[i] = edca[j];
1227 edca[j] = tmp;
1228
1229 tmp = inx[i];
1230 inx[i] = inx[j];
1231 inx[j] = tmp;
1232
1233 change_inx = _FALSE;
1234 }
1235 }
1236 }
1237 }
1238
1239 for (i = 0 ; i < 4 ; i++) {
1240 pxmitpriv->wmm_para_seq[i] = inx[i];
1241 RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
1242 }
1243
1244 }
1245
1246 }
1247
update_hw_ht_param(_adapter * padapter)1248 static void update_hw_ht_param(_adapter *padapter)
1249 {
1250 unsigned char max_AMPDU_len;
1251 unsigned char min_MPDU_spacing;
1252 struct registry_priv *pregpriv = &padapter->registrypriv;
1253 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1254 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1255
1256 RTW_INFO("%s\n", __FUNCTION__);
1257
1258
1259 /* handle A-MPDU parameter field */
1260 /*
1261 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
1262 AMPDU_para [4:2]:Min MPDU Start Spacing
1263 */
1264 max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
1265
1266 min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
1267
1268 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
1269
1270 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
1271
1272 /* */
1273 /* Config SM Power Save setting */
1274 /* */
1275 pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
1276 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
1277 #if 0
1278 u8 i;
1279 /* update the MCS rates */
1280 for (i = 0; i < 16; i++)
1281 pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
1282 #endif
1283 RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
1284 }
1285
1286 /* */
1287 /* Config current HT Protection mode. */
1288 /* */
1289 /* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
1290
1291 }
1292
rtw_ap_check_scan(_adapter * padapter)1293 static void rtw_ap_check_scan(_adapter *padapter)
1294 {
1295 _irqL irqL;
1296 _list *plist, *phead;
1297 u32 delta_time, lifetime;
1298 struct wlan_network *pnetwork = NULL;
1299 WLAN_BSSID_EX *pbss = NULL;
1300 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1301 _queue *queue = &(pmlmepriv->scanned_queue);
1302 u8 do_scan = _FALSE;
1303 u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
1304
1305 lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
1306
1307 _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1308 phead = get_list_head(queue);
1309 if (rtw_end_of_queue_search(phead, get_next(phead)) == _TRUE)
1310 if (padapter->registrypriv.wifi_spec) {
1311 do_scan = _TRUE;
1312 reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
1313 }
1314 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1315
1316 #ifdef CONFIG_RTW_ACS
1317 if (padapter->registrypriv.acs_auto_scan) {
1318 do_scan = _TRUE;
1319 reason |= RTW_AUTO_SCAN_REASON_ACS;
1320 rtw_acs_start(padapter);
1321 }
1322 #endif/*CONFIG_RTW_ACS*/
1323
1324 if (_TRUE == do_scan) {
1325 RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
1326 rtw_drv_scan_by_self(padapter, reason);
1327 rtw_scan_wait_completed(padapter);
1328 }
1329
1330 #ifdef CONFIG_RTW_ACS
1331 if (padapter->registrypriv.acs_auto_scan)
1332 rtw_acs_stop(padapter);
1333 #endif
1334
1335 _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1336
1337 phead = get_list_head(queue);
1338 plist = get_next(phead);
1339
1340 while (1) {
1341
1342 if (rtw_end_of_queue_search(phead, plist) == _TRUE)
1343 break;
1344
1345 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
1346
1347 if (rtw_chset_search_ch(adapter_to_chset(padapter), pnetwork->network.Configuration.DSConfig) >= 0
1348 && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == _TRUE
1349 && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))) {
1350 delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
1351
1352 if (delta_time < lifetime) {
1353
1354 uint ie_len = 0;
1355 u8 *pbuf = NULL;
1356 u8 *ie = NULL;
1357
1358 pbss = &pnetwork->network;
1359 ie = pbss->IEs;
1360
1361 /*check if HT CAP INFO IE exists or not*/
1362 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
1363 if (pbuf == NULL) {
1364 /* HT CAP INFO IE don't exist, it is b/g mode bss.*/
1365
1366 if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc))
1367 ATOMIC_SET(&pmlmepriv->olbc, _TRUE);
1368
1369 if (_FALSE == ATOMIC_READ(&pmlmepriv->olbc_ht))
1370 ATOMIC_SET(&pmlmepriv->olbc_ht, _TRUE);
1371
1372 if (padapter->registrypriv.wifi_spec)
1373 RTW_INFO("%s: %s is a/b/g ap\n", __func__, pnetwork->network.Ssid.Ssid);
1374 }
1375 }
1376 }
1377
1378 plist = get_next(plist);
1379
1380 }
1381
1382 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1383
1384 pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
1385
1386 }
1387
rtw_start_bss_hdl_after_chbw_decided(_adapter * adapter)1388 void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
1389 {
1390 WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
1391 struct sta_info *sta = NULL;
1392
1393 /* update cur_wireless_mode */
1394 update_wireless_mode(adapter);
1395
1396 /* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
1397 UpdateBrateTbl(adapter, pnetwork->SupportedRates);
1398 rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
1399
1400 /* update capability after cur_wireless_mode updated */
1401 update_capinfo(adapter, rtw_get_capability(pnetwork));
1402
1403 /* update bc/mc sta_info */
1404 update_bmc_sta(adapter);
1405
1406 /* update AP's sta info */
1407 sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
1408 if (!sta) {
1409 RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
1410 rtw_warn_on(1);
1411 return;
1412 }
1413
1414 update_ap_info(adapter, sta);
1415 }
1416
start_bss_network(_adapter * padapter,struct createbss_parm * parm)1417 void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
1418 {
1419 #define DUMP_ADAPTERS_STATUS 0
1420 u8 self_action = MLME_ACTION_UNKNOWN;
1421 u8 val8;
1422 u16 bcn_interval;
1423 u32 acparm;
1424 struct registry_priv *pregpriv = &padapter->registrypriv;
1425 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1426 struct security_priv *psecuritypriv = &(padapter->securitypriv);
1427 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
1428 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1429 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1430 WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
1431 struct dvobj_priv *pdvobj = padapter->dvobj;
1432 s16 req_ch = -1, req_bw = -1, req_offset = -1;
1433 bool ch_setting_changed = _FALSE;
1434 u8 ch_to_set = 0, bw_to_set, offset_to_set;
1435 u8 doiqk = _FALSE;
1436 /* use for check ch bw offset can be allowed or not */
1437 u8 chbw_allow = _TRUE;
1438
1439 if (MLME_IS_AP(padapter))
1440 self_action = MLME_AP_STARTED;
1441 else if (MLME_IS_MESH(padapter))
1442 self_action = MLME_MESH_STARTED;
1443 else
1444 rtw_warn_on(1);
1445
1446 if (parm->req_ch != 0) {
1447 /* bypass other setting, go checking ch, bw, offset */
1448 req_ch = parm->req_ch;
1449 req_bw = parm->req_bw;
1450 req_offset = parm->req_offset;
1451 goto chbw_decision;
1452 } else {
1453 /* inform this request comes from upper layer */
1454 req_ch = 0;
1455 }
1456
1457 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
1458
1459 /* check if there is wps ie, */
1460 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
1461 /* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
1462 if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
1463 pmlmeext->bstart_bss = _TRUE;
1464
1465 /* todo: update wmm, ht cap */
1466 /* pmlmeinfo->WMM_enable; */
1467 /* pmlmeinfo->HT_enable; */
1468 if (pmlmepriv->qospriv.qos_option)
1469 pmlmeinfo->WMM_enable = _TRUE;
1470 #ifdef CONFIG_80211N_HT
1471 if (pmlmepriv->htpriv.ht_option) {
1472 pmlmeinfo->WMM_enable = _TRUE;
1473 pmlmeinfo->HT_enable = _TRUE;
1474 /* pmlmeinfo->HT_info_enable = _TRUE; */
1475 /* pmlmeinfo->HT_caps_enable = _TRUE; */
1476
1477 update_hw_ht_param(padapter);
1478 }
1479 #endif /* #CONFIG_80211N_HT */
1480
1481 #ifdef CONFIG_80211AC_VHT
1482 if (pmlmepriv->vhtpriv.vht_option) {
1483 pmlmeinfo->VHT_enable = _TRUE;
1484 update_hw_vht_param(padapter);
1485 }
1486 #endif /* CONFIG_80211AC_VHT */
1487
1488 if (pmlmepriv->cur_network.join_res != _TRUE) { /* setting only at first time */
1489 /* WEP Key will be set before this function, do not clear CAM. */
1490 if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
1491 flush_all_cam_entry(padapter); /* clear CAM */
1492 }
1493
1494 /* set MSR to AP_Mode */
1495 Set_MSR(padapter, _HW_STATE_AP_);
1496
1497 /* Set BSSID REG */
1498 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
1499
1500 /* Set EDCA param reg */
1501 #ifdef CONFIG_CONCURRENT_MODE
1502 acparm = 0x005ea42b;
1503 #else
1504 acparm = 0x002F3217; /* VO */
1505 #endif
1506 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
1507 acparm = 0x005E4317; /* VI */
1508 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
1509 /* acparm = 0x00105320; */ /* BE */
1510 acparm = 0x005ea42b;
1511 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
1512 acparm = 0x0000A444; /* BK */
1513 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
1514
1515 /* Set Security */
1516 val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
1517 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
1518
1519 /* Beacon Control related register */
1520 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
1521
1522 chbw_decision:
1523 ch_setting_changed = rtw_ap_chbw_decision(padapter, req_ch, req_bw, req_offset
1524 , &ch_to_set, &bw_to_set, &offset_to_set, &chbw_allow);
1525
1526 /* let pnetwork_mlmeext == pnetwork_mlme. */
1527 _rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
1528
1529 rtw_start_bss_hdl_after_chbw_decided(padapter);
1530
1531 #if defined(CONFIG_DFS_MASTER)
1532 rtw_dfs_master_status_apply(padapter, self_action);
1533 #endif
1534 rtw_hal_rcr_set_chk_bssid(padapter, self_action);
1535
1536 #ifdef CONFIG_MCC_MODE
1537 if (MCC_EN(padapter)) {
1538 /*
1539 * due to check under rtw_ap_chbw_decision
1540 * if under MCC mode, means req channel setting is the same as current channel setting
1541 * if not under MCC mode, mean req channel setting is not the same as current channel setting
1542 */
1543 if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)) {
1544 RTW_INFO(FUNC_ADPT_FMT": req channel setting is the same as current channel setting, go to update BCN\n"
1545 , FUNC_ADPT_ARG(padapter));
1546
1547 goto update_beacon;
1548
1549 }
1550 }
1551
1552 /* issue null data to AP for all interface connecting to AP before switch channel setting for softap */
1553 rtw_hal_mcc_issue_null_data(padapter, chbw_allow, 1);
1554 #endif /* CONFIG_MCC_MODE */
1555
1556 doiqk = _TRUE;
1557 rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
1558
1559 if (ch_to_set != 0) {
1560 set_channel_bwmode(padapter, ch_to_set, offset_to_set, bw_to_set);
1561 rtw_mi_update_union_chan_inf(padapter, ch_to_set, offset_to_set, bw_to_set);
1562 }
1563
1564 doiqk = _FALSE;
1565 rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
1566
1567 #ifdef CONFIG_MCC_MODE
1568 /* after set_channel_bwmode for backup IQK */
1569 rtw_hal_set_mcc_setting_start_bss_network(padapter, chbw_allow);
1570 #endif
1571
1572 if (DUMP_ADAPTERS_STATUS) {
1573 RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
1574 dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
1575 }
1576
1577 update_beacon:
1578 /* update beacon content only if bstart_bss is _TRUE */
1579 if (_TRUE == pmlmeext->bstart_bss) {
1580
1581 _irqL irqL;
1582
1583 if ((ATOMIC_READ(&pmlmepriv->olbc) == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc_ht) == _TRUE)) {
1584 /* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
1585
1586 pmlmepriv->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
1587 pmlmepriv->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
1588 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
1589 }
1590
1591 update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
1592
1593 #ifdef CONFIG_SWTIMER_BASED_TXBCN
1594 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
1595 if (rtw_is_list_empty(&padapter->list)) {
1596 rtw_list_insert_tail(&padapter->list, get_list_head(&pdvobj->ap_if_q));
1597 pdvobj->nr_ap_if++;
1598 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
1599 }
1600 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
1601
1602 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
1603
1604 #endif /*CONFIG_SWTIMER_BASED_TXBCN*/
1605
1606 }
1607
1608 rtw_scan_wait_completed(padapter);
1609
1610 /* send beacon */
1611 if (!rtw_mi_check_fwstate(padapter, _FW_UNDER_SURVEY)) {
1612
1613 /*update_beacon(padapter, _TIM_IE_, NULL, _TRUE);*/
1614
1615 #if !defined(CONFIG_INTERRUPT_BASED_TXBCN)
1616 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1617 #ifdef CONFIG_SWTIMER_BASED_TXBCN
1618 if (pdvobj->nr_ap_if == 1) {
1619 RTW_INFO("start SW BCN TIMER!\n");
1620 _set_timer(&pdvobj->txbcn_timer, bcn_interval);
1621 }
1622 #else
1623 /* other case will tx beacon when bcn interrupt coming in. */
1624 if (send_beacon(padapter) == _FAIL)
1625 RTW_INFO("issue_beacon, fail!\n");
1626 #endif
1627 #endif
1628 #endif /* !defined(CONFIG_INTERRUPT_BASED_TXBCN) */
1629 }
1630
1631 /*Set EDCA param reg after update cur_wireless_mode & update_capinfo*/
1632 if (pregpriv->wifi_spec == 1)
1633 rtw_set_hw_wmm_param(padapter);
1634
1635 /*pmlmeext->bstart_bss = _TRUE;*/
1636 }
1637
rtw_check_beacon_data(_adapter * padapter,u8 * pbuf,int len)1638 int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
1639 {
1640 int ret = _SUCCESS;
1641 u8 *p;
1642 u8 *pHT_caps_ie = NULL;
1643 u8 *pHT_info_ie = NULL;
1644 u16 cap, ht_cap = _FALSE;
1645 uint ie_len = 0;
1646 int group_cipher, pairwise_cipher;
1647 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
1648 int supportRateNum = 0;
1649 u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
1650 u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
1651 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
1652 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1653 struct security_priv *psecuritypriv = &padapter->securitypriv;
1654 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1655 WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
1656 struct sta_priv *pstapriv = &padapter->stapriv;
1657 u8 *ie = pbss_network->IEs;
1658 u8 vht_cap = _FALSE;
1659 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1660 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1661 struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
1662 u8 rf_num = 0;
1663
1664 /* SSID */
1665 /* Supported rates */
1666 /* DS Params */
1667 /* WLAN_EID_COUNTRY */
1668 /* ERP Information element */
1669 /* Extended supported rates */
1670 /* WPA/WPA2 */
1671 /* Wi-Fi Wireless Multimedia Extensions */
1672 /* ht_capab, ht_oper */
1673 /* WPS IE */
1674
1675 RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
1676
1677 if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
1678 return _FAIL;
1679
1680
1681 if (len > MAX_IE_SZ)
1682 return _FAIL;
1683
1684 pbss_network->IELength = len;
1685
1686 _rtw_memset(ie, 0, MAX_IE_SZ);
1687
1688 _rtw_memcpy(ie, pbuf, pbss_network->IELength);
1689
1690
1691 if (pbss_network->InfrastructureMode != Ndis802_11APMode) {
1692 rtw_warn_on(1);
1693 return _FAIL;
1694 }
1695
1696
1697 rtw_ap_check_scan(padapter);
1698
1699
1700 pbss_network->Rssi = 0;
1701
1702 _rtw_memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
1703
1704 /* beacon interval */
1705 p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1706 /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
1707 pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
1708
1709 /* capability */
1710 /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
1711 /* cap = le16_to_cpu(cap); */
1712 cap = RTW_GET_LE16(ie);
1713
1714 /* SSID */
1715 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1716 if (p && ie_len > 0) {
1717 _rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
1718 _rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
1719 pbss_network->Ssid.SsidLength = ie_len;
1720 #ifdef CONFIG_P2P
1721 _rtw_memcpy(padapter->wdinfo.p2p_group_ssid, pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
1722 padapter->wdinfo.p2p_group_ssid_len = pbss_network->Ssid.SsidLength;
1723 #endif
1724 }
1725
1726 /* chnnel */
1727 channel = 0;
1728 pbss_network->Configuration.Length = 0;
1729 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1730 if (p && ie_len > 0)
1731 channel = *(p + 2);
1732
1733 pbss_network->Configuration.DSConfig = channel;
1734
1735
1736 _rtw_memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
1737 /* get supported rates */
1738 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1739 if (p != NULL) {
1740 _rtw_memcpy(supportRate, p + 2, ie_len);
1741 supportRateNum = ie_len;
1742 }
1743
1744 /* get ext_supported rates */
1745 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
1746 if (p != NULL) {
1747 _rtw_memcpy(supportRate + supportRateNum, p + 2, ie_len);
1748 supportRateNum += ie_len;
1749
1750 }
1751
1752 network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
1753
1754 rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
1755
1756
1757 /* parsing ERP_IE */
1758 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1759 if (p && ie_len > 0)
1760 ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
1761
1762 /* update privacy/security */
1763 if (cap & BIT(4))
1764 pbss_network->Privacy = 1;
1765 else
1766 pbss_network->Privacy = 0;
1767
1768 psecuritypriv->wpa_psk = 0;
1769
1770 /* wpa2 */
1771 group_cipher = 0;
1772 pairwise_cipher = 0;
1773 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1774 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1775 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1776 if (p && ie_len > 0) {
1777 if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1778 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1779
1780 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1781 psecuritypriv->wpa_psk |= BIT(1);
1782
1783 psecuritypriv->wpa2_group_cipher = group_cipher;
1784 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
1785 #if 0
1786 switch (group_cipher) {
1787 case WPA_CIPHER_NONE:
1788 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1789 break;
1790 case WPA_CIPHER_WEP40:
1791 psecuritypriv->wpa2_group_cipher = _WEP40_;
1792 break;
1793 case WPA_CIPHER_TKIP:
1794 psecuritypriv->wpa2_group_cipher = _TKIP_;
1795 break;
1796 case WPA_CIPHER_CCMP:
1797 psecuritypriv->wpa2_group_cipher = _AES_;
1798 break;
1799 case WPA_CIPHER_WEP104:
1800 psecuritypriv->wpa2_group_cipher = _WEP104_;
1801 break;
1802 }
1803
1804 switch (pairwise_cipher) {
1805 case WPA_CIPHER_NONE:
1806 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1807 break;
1808 case WPA_CIPHER_WEP40:
1809 psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
1810 break;
1811 case WPA_CIPHER_TKIP:
1812 psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
1813 break;
1814 case WPA_CIPHER_CCMP:
1815 psecuritypriv->wpa2_pairwise_cipher = _AES_;
1816 break;
1817 case WPA_CIPHER_WEP104:
1818 psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
1819 break;
1820 }
1821 #endif
1822 }
1823
1824 }
1825
1826 /* wpa */
1827 ie_len = 0;
1828 group_cipher = 0;
1829 pairwise_cipher = 0;
1830 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1831 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1832 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1833 p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
1834 if ((p) && (_rtw_memcmp(p + 2, OUI1, 4))) {
1835 if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1836 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1837
1838 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1839
1840 psecuritypriv->wpa_psk |= BIT(0);
1841
1842 psecuritypriv->wpa_group_cipher = group_cipher;
1843 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
1844
1845 #if 0
1846 switch (group_cipher) {
1847 case WPA_CIPHER_NONE:
1848 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1849 break;
1850 case WPA_CIPHER_WEP40:
1851 psecuritypriv->wpa_group_cipher = _WEP40_;
1852 break;
1853 case WPA_CIPHER_TKIP:
1854 psecuritypriv->wpa_group_cipher = _TKIP_;
1855 break;
1856 case WPA_CIPHER_CCMP:
1857 psecuritypriv->wpa_group_cipher = _AES_;
1858 break;
1859 case WPA_CIPHER_WEP104:
1860 psecuritypriv->wpa_group_cipher = _WEP104_;
1861 break;
1862 }
1863
1864 switch (pairwise_cipher) {
1865 case WPA_CIPHER_NONE:
1866 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1867 break;
1868 case WPA_CIPHER_WEP40:
1869 psecuritypriv->wpa_pairwise_cipher = _WEP40_;
1870 break;
1871 case WPA_CIPHER_TKIP:
1872 psecuritypriv->wpa_pairwise_cipher = _TKIP_;
1873 break;
1874 case WPA_CIPHER_CCMP:
1875 psecuritypriv->wpa_pairwise_cipher = _AES_;
1876 break;
1877 case WPA_CIPHER_WEP104:
1878 psecuritypriv->wpa_pairwise_cipher = _WEP104_;
1879 break;
1880 }
1881 #endif
1882 }
1883
1884 break;
1885
1886 }
1887
1888 if ((p == NULL) || (ie_len == 0))
1889 break;
1890
1891 }
1892
1893 /* wmm */
1894 ie_len = 0;
1895 pmlmepriv->qospriv.qos_option = 0;
1896 if (pregistrypriv->wmm_enable) {
1897 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1898 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
1899 if ((p) && _rtw_memcmp(p + 2, WMM_PARA_IE, 6)) {
1900 pmlmepriv->qospriv.qos_option = 1;
1901
1902 *(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
1903
1904 /* disable all ACM bits since the WMM admission control is not supported */
1905 *(p + 10) &= ~BIT(4); /* BE */
1906 *(p + 14) &= ~BIT(4); /* BK */
1907 *(p + 18) &= ~BIT(4); /* VI */
1908 *(p + 22) &= ~BIT(4); /* VO */
1909
1910 break;
1911 }
1912
1913 if ((p == NULL) || (ie_len == 0))
1914 break;
1915 }
1916 }
1917 #ifdef CONFIG_80211N_HT
1918 /* parsing HT_CAP_IE */
1919 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1920 if (p && ie_len > 0) {
1921 u8 rf_type = 0;
1922 HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
1923 struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
1924
1925 if (0) {
1926 RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
1927 dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
1928 }
1929
1930 pHT_caps_ie = p;
1931
1932 ht_cap = _TRUE;
1933 network_type |= WIRELESS_11_24N;
1934
1935 rtw_ht_use_default_setting(padapter);
1936
1937 /* Update HT Capabilities Info field */
1938 if (pmlmepriv->htpriv.sgi_20m == _FALSE)
1939 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_20);
1940
1941 if (pmlmepriv->htpriv.sgi_40m == _FALSE)
1942 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_40);
1943
1944 if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
1945 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_LDPC_CODING);
1946
1947 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
1948 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_TX_STBC);
1949
1950 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
1951 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_RX_STBC_3R);
1952
1953 /* Update A-MPDU Parameters field */
1954 pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
1955
1956 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
1957 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
1958 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
1959 else
1960 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
1961
1962 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
1963 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set Max Rx AMPDU size to 64K */
1964
1965 _rtw_memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
1966
1967 /* Update Supported MCS Set field */
1968 {
1969 struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
1970 u8 rx_nss = 0;
1971 int i;
1972
1973 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
1974 rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
1975
1976 /* RX MCS Bitmask */
1977 switch (rx_nss) {
1978 case 1:
1979 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
1980 break;
1981 case 2:
1982 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
1983 break;
1984 case 3:
1985 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
1986 break;
1987 case 4:
1988 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_4R);
1989 break;
1990 default:
1991 RTW_WARN("rf_type:%d or rx_nss:%u is not expected\n", rf_type, hal_spec->rx_nss_num);
1992 }
1993 for (i = 0; i < 10; i++)
1994 *(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
1995 }
1996
1997 #ifdef CONFIG_BEAMFORMING
1998 /* Use registry value to enable HT Beamforming. */
1999 /* ToDo: use configure file to set these capability. */
2000 pht_cap->tx_BF_cap_info = 0;
2001
2002 /* HT Beamformer */
2003 if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
2004 /* Transmit NDP Capable */
2005 SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
2006 /* Explicit Compressed Steering Capable */
2007 SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
2008 /* Compressed Steering Number Antennas */
2009 SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
2010 rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
2011 SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
2012 }
2013
2014 /* HT Beamformee */
2015 if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
2016 /* Receive NDP Capable */
2017 SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
2018 /* Explicit Compressed Beamforming Feedback Capable */
2019 SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
2020 rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
2021 SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
2022 }
2023 #endif /* CONFIG_BEAMFORMING */
2024
2025 _rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
2026
2027 if (0) {
2028 RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
2029 dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
2030 }
2031 }
2032
2033 /* parsing HT_INFO_IE */
2034 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2035 if (p && ie_len > 0)
2036 pHT_info_ie = p;
2037 #endif /* CONFIG_80211N_HT */
2038 switch (network_type) {
2039 case WIRELESS_11B:
2040 pbss_network->NetworkTypeInUse = Ndis802_11DS;
2041 break;
2042 case WIRELESS_11G:
2043 case WIRELESS_11BG:
2044 case WIRELESS_11G_24N:
2045 case WIRELESS_11BG_24N:
2046 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
2047 break;
2048 case WIRELESS_11A:
2049 pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
2050 break;
2051 default:
2052 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
2053 break;
2054 }
2055
2056 pmlmepriv->cur_network.network_type = network_type;
2057
2058 #ifdef CONFIG_80211N_HT
2059 pmlmepriv->htpriv.ht_option = _FALSE;
2060
2061 if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
2062 (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
2063 /* todo: */
2064 /* ht_cap = _FALSE; */
2065 }
2066
2067 /* ht_cap */
2068 if (pregistrypriv->ht_enable && ht_cap == _TRUE) {
2069 pmlmepriv->htpriv.ht_option = _TRUE;
2070 pmlmepriv->qospriv.qos_option = 1;
2071
2072 pmlmepriv->htpriv.ampdu_enable = pregistrypriv->ampdu_enable ? _TRUE : _FALSE;
2073
2074 HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
2075
2076 HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
2077 }
2078 #endif
2079
2080 #ifdef CONFIG_80211AC_VHT
2081
2082 /* Parsing VHT CAP IE */
2083 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
2084 if (p && ie_len > 0)
2085 vht_cap = _TRUE;
2086 /* Parsing VHT OPERATION IE */
2087
2088
2089 pmlmepriv->vhtpriv.vht_option = _FALSE;
2090 /* if channel in 5G band, then add vht ie . */
2091 if ((pbss_network->Configuration.DSConfig > 14)
2092 && (pmlmepriv->htpriv.ht_option == _TRUE)
2093 && REGSTY_IS_11AC_ENABLE(pregistrypriv)
2094 && hal_chk_proto_cap(padapter, PROTO_CAP_11AC)
2095 && (!rfctl->country_ent || COUNTRY_CHPLAN_EN_11AC(rfctl->country_ent))
2096 ) {
2097 if (vht_cap == _TRUE)
2098 pmlmepriv->vhtpriv.vht_option = _TRUE;
2099 else if (REGSTY_IS_11AC_AUTO(pregistrypriv))
2100 rtw_vht_ies_attach(padapter, pbss_network);
2101 }
2102 #endif /* CONFIG_80211AC_VHT */
2103
2104 if(pbss_network->Configuration.DSConfig <= 14 && padapter->registrypriv.wifi_spec == 1) {
2105 uint len = 0;
2106
2107 SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 1);
2108 pmlmepriv->ext_capab_ie_len = 10;
2109 rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
2110 pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
2111 }
2112
2113 pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
2114
2115 rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
2116 , &pmlmepriv->ori_ch, &pmlmepriv->ori_bw, &pmlmepriv->ori_offset);
2117 rtw_warn_on(pmlmepriv->ori_ch == 0);
2118
2119 {
2120 /* alloc sta_info for ap itself */
2121
2122 struct sta_info *sta;
2123
2124 sta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
2125 if (!sta) {
2126 sta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
2127 if (sta == NULL)
2128 return _FAIL;
2129 }
2130 }
2131
2132 rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
2133 {
2134 int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
2135
2136 if (sk_band)
2137 RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
2138 }
2139
2140 rtw_indicate_connect(padapter);
2141
2142 pmlmepriv->cur_network.join_res = _TRUE;/* for check if already set beacon */
2143
2144 /* update bc/mc sta_info */
2145 /* update_bmc_sta(padapter); */
2146
2147 return ret;
2148
2149 }
2150
2151 #if CONFIG_RTW_MACADDR_ACL
rtw_macaddr_acl_init(_adapter * adapter)2152 void rtw_macaddr_acl_init(_adapter *adapter)
2153 {
2154 struct sta_priv *stapriv = &adapter->stapriv;
2155 struct wlan_acl_pool *acl = &stapriv->acl_list;
2156 _queue *acl_node_q = &acl->acl_node_q;
2157 int i;
2158 _irqL irqL;
2159
2160 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2161 _rtw_init_listhead(&(acl_node_q->queue));
2162 acl->num = 0;
2163 acl->mode = RTW_ACL_MODE_DISABLED;
2164 for (i = 0; i < NUM_ACL; i++) {
2165 _rtw_init_listhead(&acl->aclnode[i].list);
2166 acl->aclnode[i].valid = _FALSE;
2167 }
2168 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2169 }
2170
rtw_macaddr_acl_deinit(_adapter * adapter)2171 void rtw_macaddr_acl_deinit(_adapter *adapter)
2172 {
2173 struct sta_priv *stapriv = &adapter->stapriv;
2174 struct wlan_acl_pool *acl = &stapriv->acl_list;
2175 _queue *acl_node_q = &acl->acl_node_q;
2176 _irqL irqL;
2177 _list *head, *list;
2178 struct rtw_wlan_acl_node *acl_node;
2179
2180 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2181 head = get_list_head(acl_node_q);
2182 list = get_next(head);
2183 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2184 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2185 list = get_next(list);
2186
2187 if (acl_node->valid == _TRUE) {
2188 acl_node->valid = _FALSE;
2189 rtw_list_delete(&acl_node->list);
2190 acl->num--;
2191 }
2192 }
2193 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2194
2195 rtw_warn_on(acl->num);
2196 acl->mode = RTW_ACL_MODE_DISABLED;
2197 }
2198
rtw_set_macaddr_acl(_adapter * adapter,int mode)2199 void rtw_set_macaddr_acl(_adapter *adapter, int mode)
2200 {
2201 struct sta_priv *stapriv = &adapter->stapriv;
2202 struct wlan_acl_pool *acl = &stapriv->acl_list;
2203
2204 RTW_INFO(FUNC_ADPT_FMT" mode=%d\n", FUNC_ADPT_ARG(adapter), mode);
2205
2206 acl->mode = mode;
2207
2208 if (mode == RTW_ACL_MODE_DISABLED)
2209 rtw_macaddr_acl_deinit(adapter);
2210 }
2211
rtw_acl_add_sta(_adapter * adapter,const u8 * addr)2212 int rtw_acl_add_sta(_adapter *adapter, const u8 *addr)
2213 {
2214 _irqL irqL;
2215 _list *list, *head;
2216 u8 existed = 0;
2217 int i = -1, ret = 0;
2218 struct rtw_wlan_acl_node *acl_node;
2219 struct sta_priv *stapriv = &adapter->stapriv;
2220 struct wlan_acl_pool *acl = &stapriv->acl_list;
2221 _queue *acl_node_q = &acl->acl_node_q;
2222
2223 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2224
2225 head = get_list_head(acl_node_q);
2226 list = get_next(head);
2227
2228 /* search for existed entry */
2229 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2230 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2231 list = get_next(list);
2232
2233 if (_rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2234 if (acl_node->valid == _TRUE) {
2235 existed = 1;
2236 break;
2237 }
2238 }
2239 }
2240 if (existed)
2241 goto release_lock;
2242
2243 if (acl->num >= NUM_ACL)
2244 goto release_lock;
2245
2246 /* find empty one and use */
2247 for (i = 0; i < NUM_ACL; i++) {
2248
2249 acl_node = &acl->aclnode[i];
2250 if (acl_node->valid == _FALSE) {
2251
2252 _rtw_init_listhead(&acl_node->list);
2253 _rtw_memcpy(acl_node->addr, addr, ETH_ALEN);
2254 acl_node->valid = _TRUE;
2255
2256 rtw_list_insert_tail(&acl_node->list, get_list_head(acl_node_q));
2257 acl->num++;
2258 break;
2259 }
2260 }
2261
2262 release_lock:
2263 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2264
2265 if (!existed && (i < 0 || i >= NUM_ACL))
2266 ret = -1;
2267
2268 RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
2269 , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
2270 , (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
2271 , acl->num);
2272
2273 return ret;
2274 }
2275
rtw_acl_remove_sta(_adapter * adapter,const u8 * addr)2276 int rtw_acl_remove_sta(_adapter *adapter, const u8 *addr)
2277 {
2278 _irqL irqL;
2279 _list *list, *head;
2280 int ret = 0;
2281 struct rtw_wlan_acl_node *acl_node;
2282 struct sta_priv *stapriv = &adapter->stapriv;
2283 struct wlan_acl_pool *acl = &stapriv->acl_list;
2284 _queue *acl_node_q = &acl->acl_node_q;
2285 u8 is_baddr = is_broadcast_mac_addr(addr);
2286 u8 match = 0;
2287
2288 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2289
2290 head = get_list_head(acl_node_q);
2291 list = get_next(head);
2292
2293 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2294 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2295 list = get_next(list);
2296
2297 if (is_baddr || _rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2298 if (acl_node->valid == _TRUE) {
2299 acl_node->valid = _FALSE;
2300 rtw_list_delete(&acl_node->list);
2301 acl->num--;
2302 match = 1;
2303 }
2304 }
2305 }
2306
2307 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2308
2309 RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
2310 , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
2311 , is_baddr ? "clear all" : (match ? "match" : "no found")
2312 , acl->num);
2313
2314 return ret;
2315 }
2316 #endif /* CONFIG_RTW_MACADDR_ACL */
2317
rtw_ap_set_pairwise_key(_adapter * padapter,struct sta_info * psta)2318 u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
2319 {
2320 struct cmd_obj *ph2c;
2321 struct set_stakey_parm *psetstakey_para;
2322 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
2323 u8 res = _SUCCESS;
2324
2325 ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2326 if (ph2c == NULL) {
2327 res = _FAIL;
2328 goto exit;
2329 }
2330
2331 psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
2332 if (psetstakey_para == NULL) {
2333 rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
2334 res = _FAIL;
2335 goto exit;
2336 }
2337
2338 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
2339
2340
2341 psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
2342
2343 _rtw_memcpy(psetstakey_para->addr, psta->cmn.mac_addr, ETH_ALEN);
2344
2345 _rtw_memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
2346
2347
2348 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
2349
2350 exit:
2351
2352 return res;
2353
2354 }
2355
rtw_ap_set_key(_adapter * padapter,u8 * key,u8 alg,int keyid,u8 set_tx)2356 static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
2357 {
2358 u8 keylen;
2359 struct cmd_obj *pcmd;
2360 struct setkey_parm *psetkeyparm;
2361 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
2362 int res = _SUCCESS;
2363
2364 /* RTW_INFO("%s\n", __FUNCTION__); */
2365
2366 pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2367 if (pcmd == NULL) {
2368 res = _FAIL;
2369 goto exit;
2370 }
2371 psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
2372 if (psetkeyparm == NULL) {
2373 rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
2374 res = _FAIL;
2375 goto exit;
2376 }
2377
2378 _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
2379
2380 psetkeyparm->keyid = (u8)keyid;
2381 if (is_wep_enc(alg))
2382 padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
2383
2384 psetkeyparm->algorithm = alg;
2385
2386 psetkeyparm->set_tx = set_tx;
2387
2388 switch (alg) {
2389 case _WEP40_:
2390 keylen = 5;
2391 break;
2392 case _WEP104_:
2393 keylen = 13;
2394 break;
2395 case _TKIP_:
2396 case _TKIP_WTMIC_:
2397 case _AES_:
2398 default:
2399 keylen = 16;
2400 }
2401
2402 _rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
2403
2404 pcmd->cmdcode = _SetKey_CMD_;
2405 pcmd->parmbuf = (u8 *)psetkeyparm;
2406 pcmd->cmdsz = (sizeof(struct setkey_parm));
2407 pcmd->rsp = NULL;
2408 pcmd->rspsz = 0;
2409
2410
2411 _rtw_init_listhead(&pcmd->list);
2412
2413 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
2414
2415 exit:
2416
2417 return res;
2418 }
2419
rtw_ap_set_group_key(_adapter * padapter,u8 * key,u8 alg,int keyid)2420 int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
2421 {
2422 RTW_INFO("%s\n", __FUNCTION__);
2423
2424 return rtw_ap_set_key(padapter, key, alg, keyid, 1);
2425 }
2426
rtw_ap_set_wep_key(_adapter * padapter,u8 * key,u8 keylen,int keyid,u8 set_tx)2427 int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
2428 {
2429 u8 alg;
2430
2431 switch (keylen) {
2432 case 5:
2433 alg = _WEP40_;
2434 break;
2435 case 13:
2436 alg = _WEP104_;
2437 break;
2438 default:
2439 alg = _NO_PRIVACY_;
2440 }
2441
2442 RTW_INFO("%s\n", __FUNCTION__);
2443
2444 return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
2445 }
2446
rtw_ap_bmc_frames_hdl(_adapter * padapter)2447 u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
2448 {
2449 #define HIQ_XMIT_COUNTS (6)
2450 _irqL irqL;
2451 struct sta_info *psta_bmc;
2452 _list *xmitframe_plist, *xmitframe_phead;
2453 struct xmit_frame *pxmitframe = NULL;
2454 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2455 struct sta_priv *pstapriv = &padapter->stapriv;
2456 bool update_tim = _FALSE;
2457
2458
2459 if (padapter->registrypriv.wifi_spec != 1)
2460 return H2C_SUCCESS;
2461
2462
2463 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2464 if (!psta_bmc)
2465 return H2C_SUCCESS;
2466
2467
2468 _enter_critical_bh(&pxmitpriv->lock, &irqL);
2469
2470 if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) {
2471 int tx_counts = 0;
2472
2473 _update_beacon(padapter, _TIM_IE_, NULL, _FALSE, "update TIM with TIB=1");
2474
2475 RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
2476
2477 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2478 xmitframe_plist = get_next(xmitframe_phead);
2479
2480 while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
2481 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2482
2483 xmitframe_plist = get_next(xmitframe_plist);
2484
2485 rtw_list_delete(&pxmitframe->list);
2486
2487 psta_bmc->sleepq_len--;
2488 tx_counts++;
2489
2490 if (psta_bmc->sleepq_len > 0)
2491 pxmitframe->attrib.mdata = 1;
2492 else
2493 pxmitframe->attrib.mdata = 0;
2494
2495 if (tx_counts == HIQ_XMIT_COUNTS)
2496 pxmitframe->attrib.mdata = 0;
2497
2498 pxmitframe->attrib.triggered = 1;
2499
2500 if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
2501 pxmitframe->attrib.qsel = QSLT_HIGH;/*HIQ*/
2502
2503 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2504
2505 if (tx_counts == HIQ_XMIT_COUNTS)
2506 break;
2507
2508 }
2509
2510 } else {
2511 if (psta_bmc->sleepq_len == 0) {
2512
2513 /*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
2514
2515 if (pstapriv->tim_bitmap & BIT(0))
2516 update_tim = _TRUE;
2517
2518 pstapriv->tim_bitmap &= ~BIT(0);
2519 pstapriv->sta_dz_bitmap &= ~BIT(0);
2520
2521 if (update_tim == _TRUE) {
2522 RTW_INFO("clear TIB\n");
2523 _update_beacon(padapter, _TIM_IE_, NULL, _TRUE, "bmc sleepq and HIQ empty");
2524 }
2525 }
2526 }
2527
2528 _exit_critical_bh(&pxmitpriv->lock, &irqL);
2529
2530 #if 0
2531 /* HIQ Check */
2532 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2533
2534 while (_FALSE == empty && rtw_get_passing_time_ms(start) < 3000) {
2535 rtw_msleep_os(100);
2536 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2537 }
2538
2539
2540 printk("check if hiq empty=%d\n", empty);
2541 #endif
2542
2543 return H2C_SUCCESS;
2544 }
2545
2546 #ifdef CONFIG_NATIVEAP_MLME
2547
associated_stainfo_update(_adapter * padapter,struct sta_info * psta,u32 sta_info_type)2548 static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
2549 {
2550 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2551
2552 RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->cmn.mac_addr), sta_info_type);
2553
2554 if (sta_info_type & STA_INFO_UPDATE_BW) {
2555
2556 if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
2557 if (pmlmepriv->sw_to_20mhz) {
2558 psta->cmn.bw_mode = CHANNEL_WIDTH_20;
2559 /*psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;*/
2560 psta->htpriv.sgi_40m = _FALSE;
2561 } else {
2562 /*TODO: Switch back to 40MHZ?80MHZ*/
2563 }
2564 }
2565 }
2566
2567 /*
2568 if (sta_info_type & STA_INFO_UPDATE_RATE) {
2569
2570 }
2571 */
2572
2573 if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
2574 VCS_update(padapter, psta);
2575
2576 /*
2577 if (sta_info_type & STA_INFO_UPDATE_CAP) {
2578
2579 }
2580
2581 if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
2582
2583 }
2584
2585 if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
2586
2587 }
2588 */
2589
2590 }
2591
update_bcn_ext_capab_ie(_adapter * padapter)2592 static void update_bcn_ext_capab_ie(_adapter *padapter)
2593 {
2594 sint ie_len = 0;
2595 unsigned char *pbuf;
2596 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2597 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2598 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2599 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2600 u8 *ie = pnetwork->IEs;
2601 u8 null_extcap_data[8] = {0};
2602
2603 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2604 if (pbuf && ie_len > 0)
2605 rtw_remove_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_);
2606
2607 if ((pmlmepriv->ext_capab_ie_len > 0) &&
2608 (_rtw_memcmp(pmlmepriv->ext_capab_ie_data, null_extcap_data, sizeof(null_extcap_data)) == _FALSE))
2609 rtw_add_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_, pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len);
2610
2611 }
2612
update_bcn_erpinfo_ie(_adapter * padapter)2613 static void update_bcn_erpinfo_ie(_adapter *padapter)
2614 {
2615 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2616 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2617 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2618 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2619 unsigned char *p, *ie = pnetwork->IEs;
2620 u32 len = 0;
2621
2622 RTW_INFO("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
2623
2624 if (!pmlmeinfo->ERP_enable)
2625 return;
2626
2627 /* parsing ERP_IE */
2628 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2629 if (p && len > 0) {
2630 PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
2631
2632 if (pmlmepriv->num_sta_non_erp == 1)
2633 pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
2634 else
2635 pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
2636
2637 if (pmlmepriv->num_sta_no_short_preamble > 0)
2638 pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
2639 else
2640 pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
2641
2642 ERP_IE_handler(padapter, pIE);
2643 }
2644
2645 }
2646
update_bcn_htcap_ie(_adapter * padapter)2647 static void update_bcn_htcap_ie(_adapter *padapter)
2648 {
2649 RTW_INFO("%s\n", __FUNCTION__);
2650
2651 }
2652
update_bcn_htinfo_ie(_adapter * padapter)2653 static void update_bcn_htinfo_ie(_adapter *padapter)
2654 {
2655 /*
2656 u8 beacon_updated = _FALSE;
2657 u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
2658 */
2659 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2660 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2661 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2662 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2663 unsigned char *p, *ie = pnetwork->IEs;
2664 u32 len = 0;
2665
2666 if (pmlmepriv->htpriv.ht_option == _FALSE)
2667 return;
2668
2669 if (pmlmeinfo->HT_info_enable != 1)
2670 return;
2671
2672
2673 RTW_INFO("%s current operation mode=0x%X\n",
2674 __FUNCTION__, pmlmepriv->ht_op_mode);
2675
2676 RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
2677 pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, ATOMIC_READ(&pmlmepriv->olbc));
2678
2679 /*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
2680 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2681 if (p && len > 0) {
2682 struct HT_info_element *pht_info = NULL;
2683
2684 pht_info = (struct HT_info_element *)(p + 2);
2685
2686 /* for STA Channel Width/Secondary Channel Offset*/
2687 if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->cur_channel <= 14)) {
2688 if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req == _TRUE)
2689 || (pmlmepriv->ht_intolerant_ch_reported == _TRUE) || (ATOMIC_READ(&pmlmepriv->olbc) == _TRUE)) {
2690 SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
2691 SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
2692
2693 pmlmepriv->sw_to_20mhz = 1;
2694 /*
2695 sta_info_update_type |= STA_INFO_UPDATE_BW;
2696 beacon_updated = _TRUE;
2697 */
2698
2699 RTW_INFO("%s:switching to 20Mhz\n", __FUNCTION__);
2700
2701 /*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
2702 }
2703 } else {
2704
2705 if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == _FALSE)
2706 && (pmlmepriv->ht_intolerant_ch_reported == _FALSE) && (ATOMIC_READ(&pmlmepriv->olbc) == _FALSE)) {
2707
2708 if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_40) {
2709
2710 SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
2711
2712 SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
2713 (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) ?
2714 HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
2715
2716 pmlmepriv->sw_to_20mhz = 0;
2717 /*
2718 sta_info_update_type |= STA_INFO_UPDATE_BW;
2719 beacon_updated = _TRUE;
2720 */
2721
2722 RTW_INFO("%s:switching back to 40Mhz\n", __FUNCTION__);
2723 }
2724 }
2725 }
2726
2727 /* to update ht_op_mode*/
2728 *(u16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
2729
2730 }
2731
2732 /*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
2733
2734 }
2735
update_bcn_rsn_ie(_adapter * padapter)2736 static void update_bcn_rsn_ie(_adapter *padapter)
2737 {
2738 RTW_INFO("%s\n", __FUNCTION__);
2739
2740 }
2741
update_bcn_wpa_ie(_adapter * padapter)2742 static void update_bcn_wpa_ie(_adapter *padapter)
2743 {
2744 RTW_INFO("%s\n", __FUNCTION__);
2745
2746 }
2747
update_bcn_wmm_ie(_adapter * padapter)2748 static void update_bcn_wmm_ie(_adapter *padapter)
2749 {
2750 RTW_INFO("%s\n", __FUNCTION__);
2751
2752 }
2753
update_bcn_wps_ie(_adapter * padapter)2754 static void update_bcn_wps_ie(_adapter *padapter)
2755 {
2756 u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
2757 uint wps_ielen = 0, wps_offset, remainder_ielen;
2758 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2759 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2760 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2761 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2762 unsigned char *ie = pnetwork->IEs;
2763 u32 ielen = pnetwork->IELength;
2764
2765
2766 RTW_INFO("%s\n", __FUNCTION__);
2767
2768 pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
2769
2770 if (pwps_ie == NULL || wps_ielen == 0)
2771 return;
2772
2773 pwps_ie_src = pmlmepriv->wps_beacon_ie;
2774 if (pwps_ie_src == NULL)
2775 return;
2776
2777 wps_offset = (uint)(pwps_ie - ie);
2778
2779 premainder_ie = pwps_ie + wps_ielen;
2780
2781 remainder_ielen = ielen - wps_offset - wps_ielen;
2782
2783 if (remainder_ielen > 0) {
2784 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
2785 if (pbackup_remainder_ie)
2786 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
2787 }
2788
2789 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
2790 if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
2791 _rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
2792 pwps_ie += (wps_ielen + 2);
2793
2794 if (pbackup_remainder_ie)
2795 _rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
2796
2797 /* update IELength */
2798 pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
2799 }
2800
2801 if (pbackup_remainder_ie)
2802 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
2803
2804 /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
2805 #if defined(CONFIG_INTERRUPT_BASED_TXBCN) || defined(CONFIG_PCI_HCI)
2806 if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
2807 u8 sr = 0;
2808 rtw_get_wps_attr_content(pwps_ie_src, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
2809
2810 if (sr) {
2811 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
2812 RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
2813 } else {
2814 clr_fwstate(pmlmepriv, WIFI_UNDER_WPS);
2815 RTW_INFO("%s, clr WIFI_UNDER_WPS\n", __func__);
2816 }
2817 }
2818 #endif
2819 }
2820
update_bcn_p2p_ie(_adapter * padapter)2821 static void update_bcn_p2p_ie(_adapter *padapter)
2822 {
2823
2824 }
2825
update_bcn_vendor_spec_ie(_adapter * padapter,u8 * oui)2826 static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
2827 {
2828 RTW_INFO("%s\n", __FUNCTION__);
2829
2830 if (_rtw_memcmp(RTW_WPA_OUI, oui, 4))
2831 update_bcn_wpa_ie(padapter);
2832 else if (_rtw_memcmp(WMM_OUI, oui, 4))
2833 update_bcn_wmm_ie(padapter);
2834 else if (_rtw_memcmp(WPS_OUI, oui, 4))
2835 update_bcn_wps_ie(padapter);
2836 else if (_rtw_memcmp(P2P_OUI, oui, 4))
2837 update_bcn_p2p_ie(padapter);
2838 else
2839 RTW_INFO("unknown OUI type!\n");
2840
2841
2842 }
2843
_update_beacon(_adapter * padapter,u8 ie_id,u8 * oui,u8 tx,const char * tag)2844 void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, const char *tag)
2845 {
2846 _irqL irqL;
2847 struct mlme_priv *pmlmepriv;
2848 struct mlme_ext_priv *pmlmeext;
2849
2850 if (!padapter)
2851 return;
2852
2853 pmlmepriv = &(padapter->mlmepriv);
2854 pmlmeext = &(padapter->mlmeextpriv);
2855
2856 if (pmlmeext->bstart_bss == _FALSE)
2857 return;
2858
2859 _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
2860
2861 switch (ie_id) {
2862 case _TIM_IE_:
2863 update_BCNTIM(padapter);
2864 break;
2865
2866 case _ERPINFO_IE_:
2867 update_bcn_erpinfo_ie(padapter);
2868 break;
2869
2870 case _HT_CAPABILITY_IE_:
2871 update_bcn_htcap_ie(padapter);
2872 break;
2873
2874 case _RSN_IE_2_:
2875 update_bcn_rsn_ie(padapter);
2876 break;
2877
2878 case _HT_ADD_INFO_IE_:
2879 update_bcn_htinfo_ie(padapter);
2880 break;
2881
2882 case _EXT_CAP_IE_:
2883 update_bcn_ext_capab_ie(padapter);
2884 break;
2885
2886 case _VENDOR_SPECIFIC_IE_:
2887 update_bcn_vendor_spec_ie(padapter, oui);
2888 break;
2889
2890 case 0xFF:
2891 default:
2892 break;
2893 }
2894
2895 pmlmepriv->update_bcn = _TRUE;
2896
2897 _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
2898
2899 #ifndef CONFIG_INTERRUPT_BASED_TXBCN
2900 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2901 if (tx) {
2902 /* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
2903 if (0)
2904 RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
2905 set_tx_beacon_cmd(padapter);
2906 }
2907 #else
2908 {
2909 /* PCI will issue beacon when BCN interrupt occurs. */
2910 }
2911 #endif
2912 #endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
2913 }
2914
2915 #ifdef CONFIG_80211N_HT
2916
rtw_process_public_act_bsscoex(_adapter * padapter,u8 * pframe,uint frame_len)2917 void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
2918 {
2919 struct sta_info *psta;
2920 struct sta_priv *pstapriv = &padapter->stapriv;
2921 u8 beacon_updated = _FALSE;
2922 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2923 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
2924 uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
2925 u8 category, action;
2926
2927 psta = rtw_get_stainfo(pstapriv, get_addr2_ptr(pframe));
2928 if (psta == NULL)
2929 return;
2930
2931
2932 category = frame_body[0];
2933 action = frame_body[1];
2934
2935 if (frame_body_len > 0) {
2936 if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
2937 u8 ie_data = frame_body[4];
2938
2939 if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
2940 if (psta->ht_40mhz_intolerant == 0) {
2941 psta->ht_40mhz_intolerant = 1;
2942 pmlmepriv->num_sta_40mhz_intolerant++;
2943 beacon_updated = _TRUE;
2944 }
2945 } else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
2946 if (pmlmepriv->ht_20mhz_width_req == _FALSE) {
2947 pmlmepriv->ht_20mhz_width_req = _TRUE;
2948 beacon_updated = _TRUE;
2949 }
2950 } else
2951 beacon_updated = _FALSE;
2952 }
2953 }
2954
2955 if (frame_body_len > 8) {
2956 /* if EID_BSSIntolerantChlReport ie exists */
2957 if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
2958 /*todo:*/
2959 if (pmlmepriv->ht_intolerant_ch_reported == _FALSE) {
2960 pmlmepriv->ht_intolerant_ch_reported = _TRUE;
2961 beacon_updated = _TRUE;
2962 }
2963 }
2964 }
2965
2966 if (beacon_updated) {
2967
2968 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
2969
2970 associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
2971 }
2972
2973
2974
2975 }
2976
rtw_process_ht_action_smps(_adapter * padapter,u8 * ta,u8 ctrl_field)2977 void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
2978 {
2979 u8 e_field, m_field;
2980 struct sta_info *psta;
2981 struct sta_priv *pstapriv = &padapter->stapriv;
2982
2983 psta = rtw_get_stainfo(pstapriv, ta);
2984 if (psta == NULL)
2985 return;
2986
2987 e_field = (ctrl_field & BIT(0)) ? 1 : 0;
2988 m_field = (ctrl_field & BIT(1)) ? 1 : 0;
2989
2990 if (e_field) {
2991
2992 /* enable */
2993 /* 0:static SMPS, 1:dynamic SMPS, 3:SMPS disabled, 2:reserved*/
2994
2995 if (m_field) /*mode*/
2996 psta->htpriv.smps_cap = 1;
2997 else
2998 psta->htpriv.smps_cap = 0;
2999 } else {
3000 /*disable*/
3001 psta->htpriv.smps_cap = 3;
3002 }
3003
3004 rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
3005
3006 }
3007
3008 /*
3009 op_mode
3010 Set to 0 (HT pure) under the followign conditions
3011 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
3012 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
3013 Set to 1 (HT non-member protection) if there may be non-HT STAs
3014 in both the primary and the secondary channel
3015 Set to 2 if only HT STAs are associated in BSS,
3016 however and at least one 20 MHz HT STA is associated
3017 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
3018 (currently non-GF HT station is considered as non-HT STA also)
3019 */
rtw_ht_operation_update(_adapter * padapter)3020 int rtw_ht_operation_update(_adapter *padapter)
3021 {
3022 u16 cur_op_mode, new_op_mode;
3023 int op_mode_changes = 0;
3024 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3025 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
3026
3027 if (pmlmepriv->htpriv.ht_option == _FALSE)
3028 return 0;
3029
3030 /*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
3031 return 0;*/
3032
3033 RTW_INFO("%s current operation mode=0x%X\n",
3034 __FUNCTION__, pmlmepriv->ht_op_mode);
3035
3036 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
3037 && pmlmepriv->num_sta_ht_no_gf) {
3038 pmlmepriv->ht_op_mode |=
3039 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
3040 op_mode_changes++;
3041 } else if ((pmlmepriv->ht_op_mode &
3042 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
3043 pmlmepriv->num_sta_ht_no_gf == 0) {
3044 pmlmepriv->ht_op_mode &=
3045 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
3046 op_mode_changes++;
3047 }
3048
3049 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
3050 (pmlmepriv->num_sta_no_ht || ATOMIC_READ(&pmlmepriv->olbc_ht))) {
3051 pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
3052 op_mode_changes++;
3053 } else if ((pmlmepriv->ht_op_mode &
3054 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
3055 (pmlmepriv->num_sta_no_ht == 0 && !ATOMIC_READ(&pmlmepriv->olbc_ht))) {
3056 pmlmepriv->ht_op_mode &=
3057 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
3058 op_mode_changes++;
3059 }
3060
3061 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
3062 * station is associated. Probably it's a theoretical case, since
3063 * it looks like all known HT STAs support greenfield.
3064 */
3065 new_op_mode = 0;
3066 if (pmlmepriv->num_sta_no_ht /*||
3067 (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
3068 new_op_mode = OP_MODE_MIXED;
3069 else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
3070 && pmlmepriv->num_sta_ht_20mhz)
3071 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
3072 else if (ATOMIC_READ(&pmlmepriv->olbc_ht))
3073 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
3074 else
3075 new_op_mode = OP_MODE_PURE;
3076
3077 cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3078 if (cur_op_mode != new_op_mode) {
3079 pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3080 pmlmepriv->ht_op_mode |= new_op_mode;
3081 op_mode_changes++;
3082 }
3083
3084 RTW_INFO("%s new operation mode=0x%X changes=%d\n",
3085 __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
3086
3087 return op_mode_changes;
3088
3089 }
3090
3091 #endif /* CONFIG_80211N_HT */
3092
associated_clients_update(_adapter * padapter,u8 updated,u32 sta_info_type)3093 void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
3094 {
3095 /* update associcated stations cap. */
3096 if (updated == _TRUE) {
3097 _irqL irqL;
3098 _list *phead, *plist;
3099 struct sta_info *psta = NULL;
3100 struct sta_priv *pstapriv = &padapter->stapriv;
3101
3102 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3103
3104 phead = &pstapriv->asoc_list;
3105 plist = get_next(phead);
3106
3107 /* check asoc_queue */
3108 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3109 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3110
3111 plist = get_next(plist);
3112
3113 associated_stainfo_update(padapter, psta, sta_info_type);
3114 }
3115
3116 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3117
3118 }
3119
3120 }
3121
3122 /* called > TSR LEVEL for USB or SDIO Interface*/
bss_cap_update_on_sta_join(_adapter * padapter,struct sta_info * psta)3123 void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
3124 {
3125 u8 beacon_updated = _FALSE;
3126 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3127 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3128
3129
3130 #if 0
3131 if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
3132 !psta->no_short_preamble_set) {
3133 psta->no_short_preamble_set = 1;
3134 pmlmepriv->num_sta_no_short_preamble++;
3135 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3136 (pmlmepriv->num_sta_no_short_preamble == 1))
3137 ieee802_11_set_beacons(hapd->iface);
3138 }
3139 #endif
3140
3141
3142 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
3143 if (!psta->no_short_preamble_set) {
3144 psta->no_short_preamble_set = 1;
3145
3146 pmlmepriv->num_sta_no_short_preamble++;
3147
3148 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3149 (pmlmepriv->num_sta_no_short_preamble == 1))
3150 beacon_updated = _TRUE;
3151 }
3152 } else {
3153 if (psta->no_short_preamble_set) {
3154 psta->no_short_preamble_set = 0;
3155
3156 pmlmepriv->num_sta_no_short_preamble--;
3157
3158 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3159 (pmlmepriv->num_sta_no_short_preamble == 0))
3160 beacon_updated = _TRUE;
3161 }
3162 }
3163
3164 #if 0
3165 if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
3166 psta->nonerp_set = 1;
3167 pmlmepriv->num_sta_non_erp++;
3168 if (pmlmepriv->num_sta_non_erp == 1)
3169 ieee802_11_set_beacons(hapd->iface);
3170 }
3171 #endif
3172
3173 if (psta->flags & WLAN_STA_NONERP) {
3174 if (!psta->nonerp_set) {
3175 psta->nonerp_set = 1;
3176
3177 pmlmepriv->num_sta_non_erp++;
3178
3179 if (pmlmepriv->num_sta_non_erp == 1) {
3180 beacon_updated = _TRUE;
3181 update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
3182 }
3183 }
3184
3185 } else {
3186 if (psta->nonerp_set) {
3187 psta->nonerp_set = 0;
3188
3189 pmlmepriv->num_sta_non_erp--;
3190
3191 if (pmlmepriv->num_sta_non_erp == 0) {
3192 beacon_updated = _TRUE;
3193 update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
3194 }
3195 }
3196
3197 }
3198
3199
3200 #if 0
3201 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
3202 !psta->no_short_slot_time_set) {
3203 psta->no_short_slot_time_set = 1;
3204 pmlmepriv->num_sta_no_short_slot_time++;
3205 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3206 (pmlmepriv->num_sta_no_short_slot_time == 1))
3207 ieee802_11_set_beacons(hapd->iface);
3208 }
3209 #endif
3210
3211 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
3212 if (!psta->no_short_slot_time_set) {
3213 psta->no_short_slot_time_set = 1;
3214
3215 pmlmepriv->num_sta_no_short_slot_time++;
3216
3217 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3218 (pmlmepriv->num_sta_no_short_slot_time == 1))
3219 beacon_updated = _TRUE;
3220 }
3221 } else {
3222 if (psta->no_short_slot_time_set) {
3223 psta->no_short_slot_time_set = 0;
3224
3225 pmlmepriv->num_sta_no_short_slot_time--;
3226
3227 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3228 (pmlmepriv->num_sta_no_short_slot_time == 0))
3229 beacon_updated = _TRUE;
3230 }
3231 }
3232
3233 #ifdef CONFIG_80211N_HT
3234 if (psta->flags & WLAN_STA_HT) {
3235 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
3236
3237 RTW_INFO("HT: STA " MAC_FMT " HT Capabilities Info: 0x%04x\n",
3238 MAC_ARG(psta->cmn.mac_addr), ht_capab);
3239
3240 if (psta->no_ht_set) {
3241 psta->no_ht_set = 0;
3242 pmlmepriv->num_sta_no_ht--;
3243 }
3244
3245 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
3246 if (!psta->no_ht_gf_set) {
3247 psta->no_ht_gf_set = 1;
3248 pmlmepriv->num_sta_ht_no_gf++;
3249 }
3250 RTW_INFO("%s STA " MAC_FMT " - no "
3251 "greenfield, num of non-gf stations %d\n",
3252 __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
3253 pmlmepriv->num_sta_ht_no_gf);
3254 }
3255
3256 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
3257 if (!psta->ht_20mhz_set) {
3258 psta->ht_20mhz_set = 1;
3259 pmlmepriv->num_sta_ht_20mhz++;
3260 }
3261 RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
3262 "num of 20MHz HT STAs %d\n",
3263 __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
3264 pmlmepriv->num_sta_ht_20mhz);
3265 }
3266
3267 } else {
3268 if (!psta->no_ht_set) {
3269 psta->no_ht_set = 1;
3270 pmlmepriv->num_sta_no_ht++;
3271 }
3272 if (pmlmepriv->htpriv.ht_option == _TRUE) {
3273 RTW_INFO("%s STA " MAC_FMT
3274 " - no HT, num of non-HT stations %d\n",
3275 __FUNCTION__, MAC_ARG(psta->cmn.mac_addr),
3276 pmlmepriv->num_sta_no_ht);
3277 }
3278 }
3279
3280 if (rtw_ht_operation_update(padapter) > 0) {
3281 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
3282 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
3283 beacon_updated = _TRUE;
3284 }
3285 #endif /* CONFIG_80211N_HT */
3286
3287 if (beacon_updated)
3288 update_beacon(padapter, 0xFF, NULL, _TRUE);
3289
3290 /* update associcated stations cap. */
3291 associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL);
3292
3293 RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3294
3295 }
3296
bss_cap_update_on_sta_leave(_adapter * padapter,struct sta_info * psta)3297 u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
3298 {
3299 u8 beacon_updated = _FALSE;
3300 struct sta_priv *pstapriv = &padapter->stapriv;
3301 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3302 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3303
3304 if (!psta)
3305 return beacon_updated;
3306
3307 if (pstapriv->tim_bitmap & BIT(psta->cmn.aid)) {
3308 pstapriv->tim_bitmap &= (~ BIT(psta->cmn.aid));
3309 beacon_updated = _TRUE;
3310 update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
3311 }
3312
3313 if (psta->no_short_preamble_set) {
3314 psta->no_short_preamble_set = 0;
3315 pmlmepriv->num_sta_no_short_preamble--;
3316 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
3317 && pmlmepriv->num_sta_no_short_preamble == 0)
3318 beacon_updated = _TRUE;
3319 }
3320
3321 if (psta->nonerp_set) {
3322 psta->nonerp_set = 0;
3323 pmlmepriv->num_sta_non_erp--;
3324 if (pmlmepriv->num_sta_non_erp == 0) {
3325 beacon_updated = _TRUE;
3326 update_beacon(padapter, _ERPINFO_IE_, NULL, _FALSE);
3327 }
3328 }
3329
3330 if (psta->no_short_slot_time_set) {
3331 psta->no_short_slot_time_set = 0;
3332 pmlmepriv->num_sta_no_short_slot_time--;
3333 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
3334 && pmlmepriv->num_sta_no_short_slot_time == 0)
3335 beacon_updated = _TRUE;
3336 }
3337
3338 #ifdef CONFIG_80211N_HT
3339 if (psta->no_ht_gf_set) {
3340 psta->no_ht_gf_set = 0;
3341 pmlmepriv->num_sta_ht_no_gf--;
3342 }
3343
3344 if (psta->no_ht_set) {
3345 psta->no_ht_set = 0;
3346 pmlmepriv->num_sta_no_ht--;
3347 }
3348
3349 if (psta->ht_20mhz_set) {
3350 psta->ht_20mhz_set = 0;
3351 pmlmepriv->num_sta_ht_20mhz--;
3352 }
3353
3354 if (rtw_ht_operation_update(padapter) > 0) {
3355 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
3356 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
3357 }
3358 #endif /* CONFIG_80211N_HT */
3359
3360 if (beacon_updated == _TRUE)
3361 update_beacon(padapter, 0xFF, NULL, _TRUE);
3362
3363 #if 0
3364 /* update associated stations cap. */
3365 associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL); /* move it to avoid deadlock */
3366 #endif
3367
3368 RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3369
3370 return beacon_updated;
3371
3372 }
3373
ap_free_sta(_adapter * padapter,struct sta_info * psta,bool active,u16 reason,bool enqueue)3374 u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue)
3375 {
3376 _irqL irqL;
3377 u8 beacon_updated = _FALSE;
3378 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3379 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3380 struct sta_priv *pstapriv = &padapter->stapriv;
3381
3382 if (!psta)
3383 return beacon_updated;
3384
3385 if (active == _TRUE) {
3386 #ifdef CONFIG_80211N_HT
3387 /* tear down Rx AMPDU */
3388 send_delba(padapter, 0, psta->cmn.mac_addr);/* recipient */
3389
3390 /* tear down TX AMPDU */
3391 send_delba(padapter, 1, psta->cmn.mac_addr);/* */ /* originator */
3392
3393 #endif /* CONFIG_80211N_HT */
3394
3395 issue_deauth(padapter, psta->cmn.mac_addr, reason);
3396 }
3397
3398 #ifdef CONFIG_BEAMFORMING
3399 beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_LEAVE, psta->cmn.mac_addr, ETH_ALEN, 1);
3400 #endif
3401
3402 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
3403 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
3404
3405 /* clear cam entry / key */
3406 rtw_clearstakey_cmd(padapter, psta, enqueue);
3407
3408
3409 _enter_critical_bh(&psta->lock, &irqL);
3410 psta->state &= ~_FW_LINKED;
3411 _exit_critical_bh(&psta->lock, &irqL);
3412
3413 {
3414 #ifdef CONFIG_IOCTL_CFG80211
3415 #ifdef COMPAT_KERNEL_RELEASE
3416 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->cmn.mac_addr, reason);
3417 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
3418 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->cmn.mac_addr, reason);
3419 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3420 /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
3421 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3422 #else
3423 rtw_indicate_sta_disassoc_event(padapter, psta);
3424 #endif
3425 }
3426
3427 report_del_sta_event(padapter, psta->cmn.mac_addr, reason, enqueue, _FALSE);
3428
3429 beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
3430
3431 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3432 rtw_free_stainfo(padapter, psta);
3433 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3434
3435
3436 return beacon_updated;
3437
3438 }
3439
rtw_ap_inform_ch_switch(_adapter * padapter,u8 new_ch,u8 ch_offset)3440 int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
3441 {
3442 _irqL irqL;
3443 _list *phead, *plist;
3444 int ret = 0;
3445 struct sta_info *psta = NULL;
3446 struct sta_priv *pstapriv = &padapter->stapriv;
3447 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3448 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3449 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3450
3451 if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
3452 return ret;
3453
3454 RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
3455 FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
3456
3457 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3458 phead = &pstapriv->asoc_list;
3459 plist = get_next(phead);
3460
3461 /* for each sta in asoc_queue */
3462 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3463 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3464 plist = get_next(plist);
3465
3466 issue_action_spct_ch_switch(padapter, psta->cmn.mac_addr, new_ch, ch_offset);
3467 psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
3468 }
3469 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3470
3471 issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
3472
3473 return ret;
3474 }
3475
rtw_sta_flush(_adapter * padapter,bool enqueue)3476 int rtw_sta_flush(_adapter *padapter, bool enqueue)
3477 {
3478 _irqL irqL;
3479 _list *phead, *plist;
3480 int ret = 0;
3481 struct sta_info *psta = NULL;
3482 struct sta_priv *pstapriv = &padapter->stapriv;
3483 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3484 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3485 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3486 u8 flush_num = 0;
3487 char flush_list[NUM_STA];
3488 int i;
3489
3490 if (!MLME_IS_AP(padapter) && !MLME_IS_MESH(padapter))
3491 return ret;
3492
3493 RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
3494
3495 /* pick sta from sta asoc_queue */
3496 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3497 phead = &pstapriv->asoc_list;
3498 plist = get_next(phead);
3499 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3500 int stainfo_offset;
3501
3502 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3503 plist = get_next(plist);
3504
3505 rtw_list_delete(&psta->asoc_list);
3506 pstapriv->asoc_list_cnt--;
3507
3508 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
3509 if (stainfo_offset_valid(stainfo_offset))
3510 flush_list[flush_num++] = stainfo_offset;
3511 else
3512 rtw_warn_on(1);
3513 }
3514 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3515
3516 /* call ap_free_sta() for each sta picked */
3517 for (i = 0; i < flush_num; i++) {
3518 psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
3519 ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, enqueue);
3520 }
3521
3522 issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
3523
3524 associated_clients_update(padapter, _TRUE, STA_INFO_UPDATE_ALL);
3525
3526 return ret;
3527 }
3528
3529 /* called > TSR LEVEL for USB or SDIO Interface*/
sta_info_update(_adapter * padapter,struct sta_info * psta)3530 void sta_info_update(_adapter *padapter, struct sta_info *psta)
3531 {
3532 int flags = psta->flags;
3533 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3534
3535
3536 /* update wmm cap. */
3537 if (WLAN_STA_WME & flags)
3538 psta->qos_option = 1;
3539 else
3540 psta->qos_option = 0;
3541
3542 if (pmlmepriv->qospriv.qos_option == 0)
3543 psta->qos_option = 0;
3544
3545
3546 #ifdef CONFIG_80211N_HT
3547 /* update 802.11n ht cap. */
3548 if (WLAN_STA_HT & flags) {
3549 psta->htpriv.ht_option = _TRUE;
3550 psta->qos_option = 1;
3551
3552 psta->htpriv.smps_cap = (psta->htpriv.ht_cap.cap_info & IEEE80211_HT_CAP_SM_PS) >> 2;
3553 } else
3554 psta->htpriv.ht_option = _FALSE;
3555
3556 if (pmlmepriv->htpriv.ht_option == _FALSE)
3557 psta->htpriv.ht_option = _FALSE;
3558 #endif
3559
3560 #ifdef CONFIG_80211AC_VHT
3561 /* update 802.11AC vht cap. */
3562 if (WLAN_STA_VHT & flags)
3563 psta->vhtpriv.vht_option = _TRUE;
3564 else
3565 psta->vhtpriv.vht_option = _FALSE;
3566
3567 if (pmlmepriv->vhtpriv.vht_option == _FALSE)
3568 psta->vhtpriv.vht_option = _FALSE;
3569 #endif
3570
3571 update_sta_info_apmode(padapter, psta);
3572 }
3573
3574 /* called >= TSR LEVEL for USB or SDIO Interface*/
ap_sta_info_defer_update(_adapter * padapter,struct sta_info * psta)3575 void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
3576 {
3577 if (psta->state & _FW_LINKED)
3578 rtw_hal_update_ra_mask(psta); /* DM_RATR_STA_INIT */
3579 }
3580 /* restore hw setting from sw data structures */
rtw_ap_restore_network(_adapter * padapter)3581 void rtw_ap_restore_network(_adapter *padapter)
3582 {
3583 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
3584 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3585 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3586 struct sta_priv *pstapriv = &padapter->stapriv;
3587 struct sta_info *psta;
3588 struct security_priv *psecuritypriv = &(padapter->securitypriv);
3589 _irqL irqL;
3590 _list *phead, *plist;
3591 u8 chk_alive_num = 0;
3592 char chk_alive_list[NUM_STA];
3593 int i;
3594
3595 rtw_setopmode_cmd(padapter, Ndis802_11APMode, _FALSE);
3596
3597 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
3598
3599 rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
3600
3601 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
3602 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
3603 /* restore group key, WEP keys is restored in ips_leave() */
3604 rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, _FALSE);
3605 }
3606
3607 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3608
3609 phead = &pstapriv->asoc_list;
3610 plist = get_next(phead);
3611
3612 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3613 int stainfo_offset;
3614
3615 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3616 plist = get_next(plist);
3617
3618 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
3619 if (stainfo_offset_valid(stainfo_offset))
3620 chk_alive_list[chk_alive_num++] = stainfo_offset;
3621 }
3622
3623 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3624
3625 for (i = 0; i < chk_alive_num; i++) {
3626 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
3627
3628 if (psta == NULL)
3629 RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
3630 else if (psta->state & _FW_LINKED) {
3631 rtw_sta_media_status_rpt(padapter, psta, 1);
3632 Update_RA_Entry(padapter, psta);
3633 /* pairwise key */
3634 /* per sta pairwise key and settings */
3635 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
3636 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
3637 rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _FALSE);
3638 }
3639 }
3640
3641 }
3642
start_ap_mode(_adapter * padapter)3643 void start_ap_mode(_adapter *padapter)
3644 {
3645 int i;
3646 struct sta_info *psta = NULL;
3647 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3648 struct sta_priv *pstapriv = &padapter->stapriv;
3649 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3650 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3651 struct security_priv *psecuritypriv = &padapter->securitypriv;
3652
3653 pmlmepriv->update_bcn = _FALSE;
3654
3655 /*init_mlme_ap_info(padapter);*/
3656
3657 pmlmeext->bstart_bss = _FALSE;
3658
3659 pmlmepriv->num_sta_non_erp = 0;
3660
3661 pmlmepriv->num_sta_no_short_slot_time = 0;
3662
3663 pmlmepriv->num_sta_no_short_preamble = 0;
3664
3665 pmlmepriv->num_sta_ht_no_gf = 0;
3666 #ifdef CONFIG_80211N_HT
3667 pmlmepriv->num_sta_no_ht = 0;
3668 #endif /* CONFIG_80211N_HT */
3669 pmlmeinfo->HT_info_enable = 0;
3670 pmlmeinfo->HT_caps_enable = 0;
3671 pmlmeinfo->HT_enable = 0;
3672
3673 pmlmepriv->num_sta_ht_20mhz = 0;
3674 pmlmepriv->num_sta_40mhz_intolerant = 0;
3675 ATOMIC_SET(&pmlmepriv->olbc, _FALSE);
3676 ATOMIC_SET(&pmlmepriv->olbc_ht, _FALSE);
3677
3678 #ifdef CONFIG_80211N_HT
3679 pmlmepriv->ht_20mhz_width_req = _FALSE;
3680 pmlmepriv->ht_intolerant_ch_reported = _FALSE;
3681 pmlmepriv->ht_op_mode = 0;
3682 pmlmepriv->sw_to_20mhz = 0;
3683 #endif
3684
3685 _rtw_memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
3686 pmlmepriv->ext_capab_ie_len = 0;
3687
3688 #ifdef CONFIG_CONCURRENT_MODE
3689 psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
3690 #endif
3691
3692 for (i = 0 ; i < NUM_STA ; i++)
3693 pstapriv->sta_aid[i] = NULL;
3694
3695 #if CONFIG_RTW_MACADDR_ACL
3696 rtw_macaddr_acl_init(padapter);
3697 #endif
3698
3699 psta = rtw_get_bcmc_stainfo(padapter);
3700 /*_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3701 if (psta)
3702 rtw_free_stainfo(padapter, psta);
3703 /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3704
3705 rtw_init_bcmc_stainfo(padapter);
3706
3707 if (rtw_mi_get_ap_num(padapter))
3708 RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
3709
3710 }
3711
rtw_ap_bcmc_sta_flush(_adapter * padapter)3712 void rtw_ap_bcmc_sta_flush(_adapter *padapter)
3713 {
3714 #ifdef CONFIG_CONCURRENT_MODE
3715 int cam_id = -1;
3716 u8 *addr = adapter_mac_addr(padapter);
3717
3718 cam_id = rtw_iface_bcmc_id_get(padapter);
3719 if (cam_id != INVALID_SEC_MAC_CAM_ID) {
3720 RTW_PRINT("clear group key for "ADPT_FMT" addr:"MAC_FMT", camid:%d\n",
3721 ADPT_ARG(padapter), MAC_ARG(addr), cam_id);
3722 clear_cam_entry(padapter, cam_id);
3723 rtw_camid_free(padapter, cam_id);
3724 rtw_iface_bcmc_id_set(padapter, INVALID_SEC_MAC_CAM_ID); /*init default value*/
3725 }
3726 #else
3727 invalidate_cam_all(padapter);
3728 #endif
3729 }
3730
stop_ap_mode(_adapter * padapter)3731 void stop_ap_mode(_adapter *padapter)
3732 {
3733 u8 self_action = MLME_ACTION_UNKNOWN;
3734 _irqL irqL;
3735 struct sta_info *psta = NULL;
3736 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3737 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3738 struct dvobj_priv *pdvobj = padapter->dvobj;
3739
3740 RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
3741
3742 if (MLME_IS_AP(padapter))
3743 self_action = MLME_AP_STOPPED;
3744 else if (MLME_IS_MESH(padapter))
3745 self_action = MLME_MESH_STOPPED;
3746 else
3747 rtw_warn_on(1);
3748
3749 pmlmepriv->update_bcn = _FALSE;
3750 /*pmlmeext->bstart_bss = _FALSE;*/
3751 padapter->netif_up = _FALSE;
3752 /* _rtw_spinlock_free(&pmlmepriv->bcn_update_lock); */
3753
3754 /* reset and init security priv , this can refine with rtw_reset_securitypriv */
3755 _rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
3756 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
3757 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
3758
3759 #ifdef CONFIG_DFS_MASTER
3760 rtw_dfs_master_status_apply(padapter, self_action);
3761 #endif
3762
3763 /* free scan queue */
3764 rtw_free_network_queue(padapter, _TRUE);
3765
3766 #if CONFIG_RTW_MACADDR_ACL
3767 rtw_macaddr_acl_deinit(padapter);
3768 #endif
3769
3770 rtw_sta_flush(padapter, _TRUE);
3771 rtw_ap_bcmc_sta_flush(padapter);
3772
3773 /* free_assoc_sta_resources */
3774 rtw_free_all_stainfo(padapter);
3775
3776 psta = rtw_get_bcmc_stainfo(padapter);
3777 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3778 rtw_free_stainfo(padapter, psta);
3779 /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3780
3781 rtw_free_mlme_priv_ie_data(pmlmepriv);
3782
3783 #ifdef CONFIG_SWTIMER_BASED_TXBCN
3784 if (pmlmeext->bstart_bss == _TRUE) {
3785 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
3786 pdvobj->nr_ap_if--;
3787 if (pdvobj->nr_ap_if > 0)
3788 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
3789 else
3790 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL;
3791
3792 rtw_list_delete(&padapter->list);
3793 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
3794
3795 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
3796
3797 if (pdvobj->nr_ap_if == 0)
3798 _cancel_timer_ex(&pdvobj->txbcn_timer);
3799 }
3800 #endif
3801
3802 pmlmeext->bstart_bss = _FALSE;
3803
3804 rtw_hal_rcr_set_chk_bssid(padapter, self_action);
3805
3806 #ifdef CONFIG_BT_COEXIST
3807 rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
3808 #endif
3809
3810 }
3811
3812 #endif /* CONFIG_NATIVEAP_MLME */
3813
rtw_ap_update_bss_chbw(_adapter * adapter,WLAN_BSSID_EX * bss,u8 ch,u8 bw,u8 offset)3814 void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
3815 {
3816 #define UPDATE_VHT_CAP 1
3817 #define UPDATE_HT_CAP 1
3818 #ifdef CONFIG_80211AC_VHT
3819 struct vht_priv *vhtpriv = &adapter->mlmepriv.vhtpriv;
3820 #endif
3821 {
3822 u8 *p;
3823 int ie_len;
3824 u8 old_ch = bss->Configuration.DSConfig;
3825 bool change_band = _FALSE;
3826
3827 if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
3828 change_band = _TRUE;
3829
3830 /* update channel in IE */
3831 p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
3832 if (p && ie_len > 0)
3833 *(p + 2) = ch;
3834
3835 bss->Configuration.DSConfig = ch;
3836
3837 /* band is changed, update ERP, support rate, ext support rate IE */
3838 if (change_band == _TRUE)
3839 change_band_update_ie(adapter, bss, ch);
3840 }
3841
3842 #ifdef CONFIG_80211AC_VHT
3843 if (vhtpriv->vht_option == _TRUE) {
3844 u8 *vht_cap_ie, *vht_op_ie;
3845 int vht_cap_ielen, vht_op_ielen;
3846 u8 center_freq;
3847
3848 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)));
3849 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)));
3850 center_freq = rtw_get_center_ch(ch, bw, offset);
3851
3852 /* update vht cap ie */
3853 if (vht_cap_ie && vht_cap_ielen) {
3854 #if UPDATE_VHT_CAP
3855 /* if ((bw == CHANNEL_WIDTH_160 || bw == CHANNEL_WIDTH_80_80) && pvhtpriv->sgi_160m)
3856 SET_VHT_CAPABILITY_ELE_SHORT_GI160M(pvht_cap_ie + 2, 1);
3857 else */
3858 SET_VHT_CAPABILITY_ELE_SHORT_GI160M(vht_cap_ie + 2, 0);
3859
3860 if (bw >= CHANNEL_WIDTH_80 && vhtpriv->sgi_80m)
3861 SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 1);
3862 else
3863 SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 0);
3864 #endif
3865 }
3866
3867 /* update vht op ie */
3868 if (vht_op_ie && vht_op_ielen) {
3869 if (bw < CHANNEL_WIDTH_80) {
3870 SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
3871 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
3872 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
3873 } else if (bw == CHANNEL_WIDTH_80) {
3874 SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 1);
3875 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, center_freq);
3876 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
3877 } else {
3878 RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
3879 rtw_warn_on(1);
3880 }
3881 }
3882 }
3883 #endif /* CONFIG_80211AC_VHT */
3884 #ifdef CONFIG_80211N_HT
3885 {
3886 struct ht_priv *htpriv = &adapter->mlmepriv.htpriv;
3887 u8 *ht_cap_ie, *ht_op_ie;
3888 int ht_cap_ielen, ht_op_ielen;
3889
3890 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)));
3891 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)));
3892
3893 /* update ht cap ie */
3894 if (ht_cap_ie && ht_cap_ielen) {
3895 #if UPDATE_HT_CAP
3896 if (bw >= CHANNEL_WIDTH_40)
3897 SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
3898 else
3899 SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
3900
3901 if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
3902 SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
3903 else
3904 SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
3905
3906 if (htpriv->sgi_20m)
3907 SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
3908 else
3909 SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
3910 #endif
3911 }
3912
3913 /* update ht op ie */
3914 if (ht_op_ie && ht_op_ielen) {
3915 SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
3916 switch (offset) {
3917 case HAL_PRIME_CHNL_OFFSET_LOWER:
3918 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCA);
3919 break;
3920 case HAL_PRIME_CHNL_OFFSET_UPPER:
3921 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCB);
3922 break;
3923 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
3924 default:
3925 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCN);
3926 break;
3927 }
3928
3929 if (bw >= CHANNEL_WIDTH_40)
3930 SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
3931 else
3932 SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
3933 }
3934 }
3935 #endif /* CONFIG_80211N_HT */
3936 }
3937
rtw_ap_chbw_decision(_adapter * adapter,s16 req_ch,s8 req_bw,s8 req_offset,u8 * ch,u8 * bw,u8 * offset,u8 * chbw_allow)3938 bool rtw_ap_chbw_decision(_adapter *adapter, s16 req_ch, s8 req_bw, s8 req_offset
3939 , u8 *ch, u8 *bw, u8 *offset, u8 *chbw_allow)
3940 {
3941 u8 cur_ie_ch, cur_ie_bw, cur_ie_offset;
3942 u8 dec_ch, dec_bw, dec_offset;
3943 u8 u_ch = 0, u_offset, u_bw;
3944 bool changed = _FALSE;
3945 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3946 WLAN_BSSID_EX *network = &(adapter->mlmepriv.cur_network.network);
3947 struct mi_state mstate;
3948 bool set_u_ch = _FALSE, set_dec_ch = _FALSE;
3949
3950 rtw_ies_get_chbw(network->IEs + sizeof(NDIS_802_11_FIXED_IEs)
3951 , network->IELength - sizeof(NDIS_802_11_FIXED_IEs)
3952 , &cur_ie_ch, &cur_ie_bw, &cur_ie_offset);
3953
3954 #ifdef CONFIG_MCC_MODE
3955 if (MCC_EN(adapter)) {
3956 if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC)) {
3957 /* check channel settings are the same */
3958 if (cur_ie_ch == mlmeext->cur_channel
3959 && cur_ie_bw == mlmeext->cur_bwmode
3960 && cur_ie_offset == mlmeext->cur_ch_offset) {
3961
3962
3963 RTW_INFO(FUNC_ADPT_FMT"req ch settings are the same as current ch setting, go to exit\n"
3964 , FUNC_ADPT_ARG(adapter));
3965
3966 *chbw_allow = _FALSE;
3967 goto exit;
3968 } else {
3969 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"
3970 , FUNC_ADPT_ARG(adapter)
3971 , cur_ie_ch, cur_ie_bw, cur_ie_bw
3972 , mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
3973
3974 rtw_hal_set_mcc_setting_disconnect(adapter);
3975 }
3976 }
3977 }
3978 #endif /* CONFIG_MCC_MODE */
3979
3980 /* use chbw of cur_ie updated with specifying req as temporary decision */
3981 dec_ch = (req_ch <= 0) ? cur_ie_ch : req_ch;
3982 dec_bw = (req_bw < 0) ? cur_ie_bw : req_bw;
3983 dec_offset = (req_offset < 0) ? cur_ie_offset : req_offset;
3984
3985 rtw_mi_status_no_self(adapter, &mstate);
3986 RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, lg_sta_num%u, ap_num:%u, mesh_num:%u\n"
3987 , FUNC_ADPT_ARG(adapter), MSTATE_STA_LD_NUM(&mstate), MSTATE_STA_LG_NUM(&mstate)
3988 , MSTATE_AP_NUM(&mstate), MSTATE_MESH_NUM(&mstate));
3989
3990 if (MSTATE_STA_LD_NUM(&mstate) || MSTATE_AP_NUM(&mstate) || MSTATE_MESH_NUM(&mstate)) {
3991 /* has linked STA or AP/Mesh mode, follow */
3992
3993 rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
3994
3995 RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
3996 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
3997
3998 rtw_adjust_chbw(adapter, u_ch, &dec_bw, &dec_offset);
3999 #ifdef CONFIG_MCC_MODE
4000 if (MCC_EN(adapter)) {
4001 if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
4002 mlmeext->cur_channel = *ch = dec_ch;
4003 mlmeext->cur_bwmode = *bw = dec_bw;
4004 mlmeext->cur_ch_offset = *offset = dec_offset;
4005 /* channel bw offset can not be allowed, need MCC */
4006 *chbw_allow = _FALSE;
4007 RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
4008 , *ch, *bw, *offset);
4009 goto exit;
4010 } else
4011 /* channel bw offset can be allowed, not need MCC */
4012 *chbw_allow = _TRUE;
4013 }
4014 #endif /* CONFIG_MCC_MODE */
4015 rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
4016 , &u_ch, &u_bw, &u_offset);
4017
4018 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
4019 , dec_ch, dec_bw, dec_offset);
4020
4021 set_u_ch = _TRUE;
4022 } else if (MSTATE_STA_LG_NUM(&mstate)) {
4023 /* has linking STA */
4024
4025 rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
4026
4027 RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
4028 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
4029
4030 rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
4031
4032 if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
4033
4034 rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
4035 , &u_ch, &u_bw, &u_offset);
4036
4037 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
4038 , dec_ch, dec_bw, dec_offset);
4039
4040 set_u_ch = _TRUE;
4041
4042 /* channel bw offset can be allowed, not need MCC */
4043 *chbw_allow = _TRUE;
4044 } else {
4045 #ifdef CONFIG_MCC_MODE
4046 if (MCC_EN(adapter)) {
4047 mlmeext->cur_channel = *ch = dec_ch;
4048 mlmeext->cur_bwmode = *bw = dec_bw;
4049 mlmeext->cur_ch_offset = *offset = dec_offset;
4050
4051 /* channel bw offset can not be allowed, need MCC */
4052 *chbw_allow = _FALSE;
4053 RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
4054 , *ch, *bw, *offset);
4055 goto exit;
4056 }
4057 #endif /* CONFIG_MCC_MODE */
4058 /* set this for possible ch change when join down*/
4059 set_fwstate(&adapter->mlmepriv, WIFI_OP_CH_SWITCHING);
4060 }
4061 } else {
4062 /* single AP/Mesh mode */
4063
4064 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
4065
4066 /* check temporary decision first */
4067 rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
4068 if (!rtw_get_offset_by_chbw(dec_ch, dec_bw, &dec_offset)) {
4069 if (req_ch == -1 || req_bw == -1)
4070 goto choose_chbw;
4071 RTW_WARN(FUNC_ADPT_FMT" req: %u,%u has no valid offset\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw);
4072 *chbw_allow = _FALSE;
4073 goto exit;
4074 }
4075
4076 if (!rtw_chset_is_chbw_valid(adapter_to_chset(adapter), dec_ch, dec_bw, dec_offset)) {
4077 if (req_ch == -1 || req_bw == -1)
4078 goto choose_chbw;
4079 RTW_WARN(FUNC_ADPT_FMT" req: %u,%u,%u doesn't fit in chplan\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
4080 *chbw_allow = _FALSE;
4081 goto exit;
4082 }
4083
4084 if (rtw_odm_dfs_domain_unknown(adapter) && rtw_is_dfs_chbw(dec_ch, dec_bw, dec_offset)) {
4085 if (req_ch >= 0)
4086 RTW_WARN(FUNC_ADPT_FMT" DFS channel %u,%u,%u can't be used\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
4087 if (req_ch > 0) {
4088 /* specific channel and not from IE => don't change channel setting */
4089 *chbw_allow = _FALSE;
4090 goto exit;
4091 }
4092 goto choose_chbw;
4093 }
4094
4095 if (rtw_chset_is_ch_non_ocp(adapter_to_chset(adapter), dec_ch, dec_bw, dec_offset) == _FALSE)
4096 goto update_bss_chbw;
4097
4098 choose_chbw:
4099 if (req_bw < 0)
4100 req_bw = cur_ie_bw;
4101
4102 #if defined(CONFIG_DFS_MASTER)
4103 if (!rtw_odm_dfs_domain_unknown(adapter)) {
4104 /* choose 5G DFS channel for debug */
4105 if (adapter_to_rfctl(adapter)->dbg_dfs_master_choose_dfs_ch_first
4106 && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_2G | RTW_CHF_NON_DFS) == _TRUE)
4107 RTW_INFO(FUNC_ADPT_FMT" choose 5G DFS channel for debug\n", FUNC_ADPT_ARG(adapter));
4108 else if (adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags
4109 && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags) == _TRUE)
4110 RTW_INFO(FUNC_ADPT_FMT" choose with dfs_ch_sel_d_flags:0x%02x for debug\n", FUNC_ADPT_ARG(adapter), adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags);
4111 else if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, 0) == _FALSE) {
4112 RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
4113 *chbw_allow = _FALSE;
4114 goto exit;
4115 }
4116 } else
4117 #endif /* defined(CONFIG_DFS_MASTER) */
4118 if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_DFS) == _FALSE) {
4119 RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
4120 *chbw_allow = _FALSE;
4121 goto exit;
4122 }
4123
4124 update_bss_chbw:
4125 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
4126 , dec_ch, dec_bw, dec_offset);
4127
4128 /* channel bw offset can be allowed for single AP, not need MCC */
4129 *chbw_allow = _TRUE;
4130 set_dec_ch = _TRUE;
4131 }
4132
4133 if (rtw_mi_check_fwstate(adapter, _FW_UNDER_SURVEY)) {
4134 /* scanning, leave ch setting to scan state machine */
4135 set_u_ch = set_dec_ch = _FALSE;
4136 }
4137
4138 if (mlmeext->cur_channel != dec_ch
4139 || mlmeext->cur_bwmode != dec_bw
4140 || mlmeext->cur_ch_offset != dec_offset)
4141 changed = _TRUE;
4142
4143 if (changed == _TRUE && rtw_linked_check(adapter) == _TRUE) {
4144 #ifdef CONFIG_SPCT_CH_SWITCH
4145 if (1)
4146 rtw_ap_inform_ch_switch(adapter, dec_ch, dec_offset);
4147 else
4148 #endif
4149 rtw_sta_flush(adapter, _FALSE);
4150 }
4151
4152 mlmeext->cur_channel = dec_ch;
4153 mlmeext->cur_bwmode = dec_bw;
4154 mlmeext->cur_ch_offset = dec_offset;
4155
4156 if (u_ch != 0)
4157 RTW_INFO(FUNC_ADPT_FMT" union: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
4158
4159 RTW_INFO(FUNC_ADPT_FMT" dec: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
4160
4161 if (set_u_ch == _TRUE) {
4162 *ch = u_ch;
4163 *bw = u_bw;
4164 *offset = u_offset;
4165 } else if (set_dec_ch == _TRUE) {
4166 *ch = dec_ch;
4167 *bw = dec_bw;
4168 *offset = dec_offset;
4169 }
4170 exit:
4171 return changed;
4172 }
4173
rtw_ap_sta_linking_state_check(_adapter * adapter)4174 u8 rtw_ap_sta_linking_state_check(_adapter *adapter)
4175 {
4176 struct sta_info *psta;
4177 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
4178 struct sta_priv *pstapriv = &adapter->stapriv;
4179 int i;
4180 _list *plist, *phead;
4181 _irqL irqL;
4182 u8 rst = _FALSE;
4183
4184 if (!MLME_IS_AP(adapter) && !MLME_IS_MESH(adapter))
4185 return _FALSE;
4186
4187 if (pstapriv->auth_list_cnt !=0)
4188 return _TRUE;
4189
4190 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
4191 phead = &pstapriv->asoc_list;
4192 plist = get_next(phead);
4193 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4194 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
4195 plist = get_next(plist);
4196 if (!(psta->state &_FW_LINKED)) {
4197 rst = _TRUE;
4198 break;
4199 }
4200 }
4201 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
4202 return rst;
4203 }
4204
4205 /*#define DBG_SWTIMER_BASED_TXBCN*/
4206 #ifdef CONFIG_SWTIMER_BASED_TXBCN
tx_beacon_handlder(struct dvobj_priv * pdvobj)4207 void tx_beacon_handlder(struct dvobj_priv *pdvobj)
4208 {
4209 #define BEACON_EARLY_TIME 20 /* unit:TU*/
4210 _irqL irqL;
4211 _list *plist, *phead;
4212 u32 timestamp[2];
4213 u32 bcn_interval_us; /* unit : usec */
4214 u64 time;
4215 u32 cur_tick, time_offset; /* unit : usec */
4216 u32 inter_bcn_space_us; /* unit : usec */
4217 u32 txbcn_timer_ms; /* unit : ms */
4218 int nr_vap, idx, bcn_idx;
4219 int i;
4220 u8 val8, late = 0;
4221 _adapter *padapter = NULL;
4222
4223 i = 0;
4224
4225 /* get first ap mode interface */
4226 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4227 if (rtw_is_list_empty(&pdvobj->ap_if_q.queue) || (pdvobj->nr_ap_if == 0)) {
4228 RTW_INFO("[%s] ERROR: ap_if_q is empty!or nr_ap = %d\n", __func__, pdvobj->nr_ap_if);
4229 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4230 return;
4231 } else
4232 padapter = LIST_CONTAINOR(get_next(&(pdvobj->ap_if_q.queue)), struct _ADAPTER, list);
4233 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4234
4235 if (NULL == padapter) {
4236 RTW_INFO("[%s] ERROR: no any ap interface!\n", __func__);
4237 return;
4238 }
4239
4240
4241 bcn_interval_us = DEFAULT_BCN_INTERVAL * NET80211_TU_TO_US;
4242 if (0 == bcn_interval_us) {
4243 RTW_INFO("[%s] ERROR: beacon interval = 0\n", __func__);
4244 return;
4245 }
4246
4247 /* read TSF */
4248 timestamp[1] = rtw_read32(padapter, 0x560 + 4);
4249 timestamp[0] = rtw_read32(padapter, 0x560);
4250 while (timestamp[1]) {
4251 time = (0xFFFFFFFF % bcn_interval_us + 1) * timestamp[1] + timestamp[0];
4252 timestamp[0] = (u32)time;
4253 timestamp[1] = (u32)(time >> 32);
4254 }
4255 cur_tick = timestamp[0] % bcn_interval_us;
4256
4257
4258 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4259
4260 nr_vap = (pdvobj->nr_ap_if - 1);
4261 if (nr_vap > 0) {
4262 inter_bcn_space_us = pdvobj->inter_bcn_space * NET80211_TU_TO_US; /* beacon_interval / (nr_vap+1); */
4263 idx = cur_tick / inter_bcn_space_us;
4264 if (idx < nr_vap) /* if (idx < (nr_vap+1))*/
4265 bcn_idx = idx + 1; /* bcn_idx = (idx + 1) % (nr_vap+1);*/
4266 else
4267 bcn_idx = 0;
4268
4269 /* to get padapter based on bcn_idx */
4270 padapter = NULL;
4271 phead = get_list_head(&pdvobj->ap_if_q);
4272 plist = get_next(phead);
4273 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4274 padapter = LIST_CONTAINOR(plist, struct _ADAPTER, list);
4275
4276 plist = get_next(plist);
4277
4278 if (i == bcn_idx)
4279 break;
4280
4281 i++;
4282 }
4283 if ((NULL == padapter) || (i > pdvobj->nr_ap_if)) {
4284 RTW_INFO("[%s] ERROR: nr_ap_if = %d, padapter=%p, bcn_idx=%d, index=%d\n",
4285 __func__, pdvobj->nr_ap_if, padapter, bcn_idx, i);
4286 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4287 return;
4288 }
4289 #ifdef DBG_SWTIMER_BASED_TXBCN
4290 RTW_INFO("BCN_IDX=%d, cur_tick=%d, padapter=%p\n", bcn_idx, cur_tick, padapter);
4291 #endif
4292 if (((idx + 2 == nr_vap + 1) && (idx < nr_vap + 1)) || (0 == bcn_idx)) {
4293 time_offset = bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4294 if ((s32)time_offset < 0)
4295 time_offset += inter_bcn_space_us;
4296
4297 } else {
4298 time_offset = (idx + 2) * inter_bcn_space_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4299 if (time_offset > (inter_bcn_space_us + (inter_bcn_space_us >> 1))) {
4300 time_offset -= inter_bcn_space_us;
4301 late = 1;
4302 }
4303 }
4304 } else
4305 /*#endif*/ { /* MBSSID */
4306 time_offset = 2 * bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4307 if (time_offset > (bcn_interval_us + (bcn_interval_us >> 1))) {
4308 time_offset -= bcn_interval_us;
4309 late = 1;
4310 }
4311 }
4312 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4313
4314 #ifdef DBG_SWTIMER_BASED_TXBCN
4315 RTW_INFO("set sw bcn timer %d us\n", time_offset);
4316 #endif
4317 txbcn_timer_ms = time_offset / NET80211_TU_TO_US;
4318 _set_timer(&pdvobj->txbcn_timer, txbcn_timer_ms);
4319
4320 if (padapter) {
4321 #ifdef CONFIG_BCN_RECOVERY
4322 rtw_ap_bcn_recovery(padapter);
4323 #endif /*CONFIG_BCN_RECOVERY*/
4324
4325 #ifdef CONFIG_BCN_XMIT_PROTECT
4326 rtw_ap_bcn_queue_empty_check(padapter, txbcn_timer_ms);
4327 #endif /*CONFIG_BCN_XMIT_PROTECT*/
4328
4329 #ifdef DBG_SWTIMER_BASED_TXBCN
4330 RTW_INFO("padapter=%p, PORT=%d\n", padapter, padapter->hw_port);
4331 #endif
4332 /* bypass TX BCN queue if op ch is switching/waiting */
4333 if (!check_fwstate(&padapter->mlmepriv, WIFI_OP_CH_SWITCHING)
4334 #ifdef CONFIG_DFS_MASTER
4335 && !IS_CH_WAITING(adapter_to_rfctl(padapter))
4336 #endif
4337 ) {
4338 /*update_beacon(padapter, _TIM_IE_, NULL, _FALSE);*/
4339 /*issue_beacon(padapter, 0);*/
4340 send_beacon(padapter);
4341 }
4342 }
4343
4344 #if 0
4345 /* handle any buffered BC/MC frames*/
4346 /* Don't dynamically change DIS_ATIM due to HW will auto send ACQ after HIQ empty.*/
4347 val8 = *((unsigned char *)priv->beaconbuf + priv->timoffset + 4);
4348 if (val8 & 0x01) {
4349 process_mcast_dzqueue(priv);
4350 priv->pkt_in_dtimQ = 0;
4351 }
4352 #endif
4353
4354 }
4355
tx_beacon_timer_handlder(void * ctx)4356 void tx_beacon_timer_handlder(void *ctx)
4357 {
4358 struct dvobj_priv *pdvobj = (struct dvobj_priv *)ctx;
4359 _adapter *padapter = pdvobj->padapters[0];
4360
4361 if (padapter)
4362 set_tx_beacon_cmd(padapter);
4363 }
4364 #endif
4365
rtw_ap_acdata_control(_adapter * padapter,u8 power_mode)4366 void rtw_ap_acdata_control(_adapter *padapter, u8 power_mode)
4367 {
4368 _irqL irqL;
4369 _list *phead, *plist;
4370 struct sta_info *psta = NULL;
4371 struct sta_priv *pstapriv = &padapter->stapriv;
4372 u8 sta_alive_num = 0, i;
4373 char sta_alive_list[NUM_STA];
4374
4375 #ifdef CONFIG_MCC_MODE
4376 if (MCC_EN(padapter) && rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
4377 /* driver doesn't access macid sleep reg under MCC */
4378 return;
4379 #endif
4380
4381 /*RTW_INFO(FUNC_ADPT_FMT " associated sta num:%d, make macid_%s!!\n",
4382 FUNC_ADPT_ARG(padapter), pstapriv->asoc_list_cnt, power_mode ? "sleep" : "wakeup");*/
4383
4384 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
4385
4386 phead = &pstapriv->asoc_list;
4387 plist = get_next(phead);
4388
4389 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4390 int stainfo_offset;
4391
4392 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
4393 plist = get_next(plist);
4394
4395 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
4396 if (stainfo_offset_valid(stainfo_offset))
4397 sta_alive_list[sta_alive_num++] = stainfo_offset;
4398 }
4399 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
4400
4401 for (i = 0; i < sta_alive_num; i++) {
4402 psta = rtw_get_stainfo_by_offset(pstapriv, sta_alive_list[i]);
4403
4404 if (psta) {
4405 if (power_mode)
4406 rtw_hal_macid_sleep(padapter, psta->cmn.mac_id);
4407 else
4408 rtw_hal_macid_wakeup(padapter, psta->cmn.mac_id);
4409 }
4410 }
4411 }
4412
rtw_ap_parse_sta_capability(_adapter * adapter,struct sta_info * sta,u8 * cap)4413 void rtw_ap_parse_sta_capability(_adapter *adapter, struct sta_info *sta, u8 *cap)
4414 {
4415 sta->capability = RTW_GET_LE16(cap);
4416 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
4417 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
4418 else
4419 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
4420 }
4421
rtw_ap_parse_sta_supported_rates(_adapter * adapter,struct sta_info * sta,u8 * tlv_ies,u16 tlv_ies_len)4422 u16 rtw_ap_parse_sta_supported_rates(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
4423 {
4424 u8 rate_set[16];
4425 u8 rate_num;
4426 int i;
4427 u16 status = _STATS_SUCCESSFUL_;
4428
4429 rtw_ies_get_supported_rate(tlv_ies, tlv_ies_len, rate_set, &rate_num);
4430 if (rate_num == 0) {
4431 RTW_INFO(FUNC_ADPT_FMT" sta "MAC_FMT" with no supported rate\n"
4432 , FUNC_ADPT_ARG(adapter), MAC_ARG(sta->cmn.mac_addr));
4433 status = _STATS_FAILURE_;
4434 goto exit;
4435 }
4436
4437 _rtw_memcpy(sta->bssrateset, rate_set, rate_num);
4438 sta->bssratelen = rate_num;
4439
4440 if (MLME_IS_AP(adapter)) {
4441 /* this function force only CCK rates to be bassic rate... */
4442 UpdateBrateTblForSoftAP(sta->bssrateset, sta->bssratelen);
4443 }
4444
4445 /* if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) */ /* ? */
4446 sta->flags |= WLAN_STA_NONERP;
4447 for (i = 0; i < sta->bssratelen; i++) {
4448 if ((sta->bssrateset[i] & 0x7f) > 22) {
4449 sta->flags &= ~WLAN_STA_NONERP;
4450 break;
4451 }
4452 }
4453
4454 exit:
4455 return status;
4456 }
4457
rtw_ap_parse_sta_security_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)4458 u16 rtw_ap_parse_sta_security_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
4459 {
4460 struct security_priv *sec = &adapter->securitypriv;
4461 u8 *wpa_ie;
4462 int wpa_ie_len;
4463 int group_cipher = 0, pairwise_cipher = 0;
4464 u16 status = _STATS_SUCCESSFUL_;
4465
4466 sta->dot8021xalg = 0;
4467 sta->wpa_psk = 0;
4468 sta->wpa_group_cipher = 0;
4469 sta->wpa2_group_cipher = 0;
4470 sta->wpa_pairwise_cipher = 0;
4471 sta->wpa2_pairwise_cipher = 0;
4472 _rtw_memset(sta->wpa_ie, 0, sizeof(sta->wpa_ie));
4473
4474 if ((sec->wpa_psk & BIT(1)) && elems->rsn_ie) {
4475 wpa_ie = elems->rsn_ie;
4476 wpa_ie_len = elems->rsn_ie_len;
4477
4478 if (rtw_parse_wpa2_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
4479 sta->dot8021xalg = 1;/* psk, todo:802.1x */
4480 sta->wpa_psk |= BIT(1);
4481
4482 sta->wpa2_group_cipher = group_cipher & sec->wpa2_group_cipher;
4483 sta->wpa2_pairwise_cipher = pairwise_cipher & sec->wpa2_pairwise_cipher;
4484
4485 if (!sta->wpa2_group_cipher)
4486 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
4487
4488 if (!sta->wpa2_pairwise_cipher)
4489 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
4490 } else
4491 status = WLAN_STATUS_INVALID_IE;
4492
4493 }
4494 else if ((sec->wpa_psk & BIT(0)) && elems->wpa_ie) {
4495 wpa_ie = elems->wpa_ie;
4496 wpa_ie_len = elems->wpa_ie_len;
4497
4498 if (rtw_parse_wpa_ie(wpa_ie - 2, wpa_ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
4499 sta->dot8021xalg = 1;/* psk, todo:802.1x */
4500 sta->wpa_psk |= BIT(0);
4501
4502 sta->wpa_group_cipher = group_cipher & sec->wpa_group_cipher;
4503 sta->wpa_pairwise_cipher = pairwise_cipher & sec->wpa_pairwise_cipher;
4504
4505 if (!sta->wpa_group_cipher)
4506 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
4507
4508 if (!sta->wpa_pairwise_cipher)
4509 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
4510 } else
4511 status = WLAN_STATUS_INVALID_IE;
4512
4513 } else {
4514 wpa_ie = NULL;
4515 wpa_ie_len = 0;
4516 }
4517
4518 if (status != _STATS_SUCCESSFUL_)
4519 goto exit;
4520
4521 if (!MLME_IS_AP(adapter))
4522 goto exit;
4523
4524 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
4525 /* if (hapd->conf->wps_state && wpa_ie == NULL) { */ /* todo: to check ap if supporting WPS */
4526 if (wpa_ie == NULL) {
4527 if (elems->wps_ie) {
4528 RTW_INFO("STA included WPS IE in "
4529 "(Re)Association Request - assume WPS is "
4530 "used\n");
4531 sta->flags |= WLAN_STA_WPS;
4532 /* wpabuf_free(sta->wps_ie); */
4533 /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
4534 /* elems.wps_ie_len - 4); */
4535 } else {
4536 RTW_INFO("STA did not include WPA/RSN IE "
4537 "in (Re)Association Request - possible WPS "
4538 "use\n");
4539 sta->flags |= WLAN_STA_MAYBE_WPS;
4540 }
4541
4542 /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
4543 /* that the selected registrar of AP is _FLASE */
4544 if ((sec->wpa_psk > 0)
4545 && (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))
4546 ) {
4547 struct mlme_priv *mlme = &adapter->mlmepriv;
4548
4549 if (mlme->wps_beacon_ie) {
4550 u8 selected_registrar = 0;
4551
4552 rtw_get_wps_attr_content(mlme->wps_beacon_ie, mlme->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
4553
4554 if (!selected_registrar) {
4555 RTW_INFO("selected_registrar is _FALSE , or AP is not ready to do WPS\n");
4556 status = _STATS_UNABLE_HANDLE_STA_;
4557 goto exit;
4558 }
4559 }
4560 }
4561
4562 } else {
4563 int copy_len;
4564
4565 if (sec->wpa_psk == 0) {
4566 RTW_INFO("STA " MAC_FMT
4567 ": WPA/RSN IE in association request, but AP don't support WPA/RSN\n",
4568 MAC_ARG(sta->cmn.mac_addr));
4569 status = WLAN_STATUS_INVALID_IE;
4570 goto exit;
4571 }
4572
4573 if (elems->wps_ie) {
4574 RTW_INFO("STA included WPS IE in "
4575 "(Re)Association Request - WPS is "
4576 "used\n");
4577 sta->flags |= WLAN_STA_WPS;
4578 copy_len = 0;
4579 } else
4580 copy_len = ((wpa_ie_len + 2) > sizeof(sta->wpa_ie)) ? (sizeof(sta->wpa_ie)) : (wpa_ie_len + 2);
4581
4582 if (copy_len > 0)
4583 _rtw_memcpy(sta->wpa_ie, wpa_ie - 2, copy_len);
4584 }
4585
4586 exit:
4587 return status;
4588 }
4589
rtw_ap_parse_sta_wmm_ie(_adapter * adapter,struct sta_info * sta,u8 * tlv_ies,u16 tlv_ies_len)4590 void rtw_ap_parse_sta_wmm_ie(_adapter *adapter, struct sta_info *sta, u8 *tlv_ies, u16 tlv_ies_len)
4591 {
4592 struct mlme_priv *mlme = &adapter->mlmepriv;
4593 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
4594 u8 *p;
4595
4596 sta->flags &= ~WLAN_STA_WME;
4597 sta->qos_option = 0;
4598 sta->qos_info = 0;
4599 sta->has_legacy_ac = _TRUE;
4600 sta->uapsd_vo = 0;
4601 sta->uapsd_vi = 0;
4602 sta->uapsd_be = 0;
4603 sta->uapsd_bk = 0;
4604
4605 if (!mlme->qospriv.qos_option)
4606 goto exit;
4607
4608 p = rtw_get_ie_ex(tlv_ies, tlv_ies_len, WLAN_EID_VENDOR_SPECIFIC, WMM_IE, 6, NULL, NULL);
4609 if (!p)
4610 goto exit;
4611
4612 sta->flags |= WLAN_STA_WME;
4613 sta->qos_option = 1;
4614 sta->qos_info = *(p + 8);
4615 sta->max_sp_len = (sta->qos_info >> 5) & 0x3;
4616
4617 if ((sta->qos_info & 0xf) != 0xf)
4618 sta->has_legacy_ac = _TRUE;
4619 else
4620 sta->has_legacy_ac = _FALSE;
4621
4622 if (sta->qos_info & 0xf) {
4623 if (sta->qos_info & BIT(0))
4624 sta->uapsd_vo = BIT(0) | BIT(1);
4625 else
4626 sta->uapsd_vo = 0;
4627
4628 if (sta->qos_info & BIT(1))
4629 sta->uapsd_vi = BIT(0) | BIT(1);
4630 else
4631 sta->uapsd_vi = 0;
4632
4633 if (sta->qos_info & BIT(2))
4634 sta->uapsd_bk = BIT(0) | BIT(1);
4635 else
4636 sta->uapsd_bk = 0;
4637
4638 if (sta->qos_info & BIT(3))
4639 sta->uapsd_be = BIT(0) | BIT(1);
4640 else
4641 sta->uapsd_be = 0;
4642 }
4643
4644 exit:
4645 return;
4646 }
4647
rtw_ap_parse_sta_ht_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)4648 void rtw_ap_parse_sta_ht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
4649 {
4650 struct mlme_priv *mlme = &adapter->mlmepriv;
4651
4652 sta->flags &= ~WLAN_STA_HT;
4653
4654 #ifdef CONFIG_80211N_HT
4655 if (mlme->htpriv.ht_option == _FALSE)
4656 goto exit;
4657
4658 /* save HT capabilities in the sta object */
4659 _rtw_memset(&sta->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
4660 if (elems->ht_capabilities && elems->ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
4661 sta->flags |= WLAN_STA_HT;
4662 sta->flags |= WLAN_STA_WME;
4663 _rtw_memcpy(&sta->htpriv.ht_cap, elems->ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
4664 }
4665 exit:
4666 #endif
4667
4668 return;
4669 }
4670
rtw_ap_parse_sta_vht_ie(_adapter * adapter,struct sta_info * sta,struct rtw_ieee802_11_elems * elems)4671 void rtw_ap_parse_sta_vht_ie(_adapter *adapter, struct sta_info *sta, struct rtw_ieee802_11_elems *elems)
4672 {
4673 struct mlme_priv *mlme = &adapter->mlmepriv;
4674
4675 sta->flags &= ~WLAN_STA_VHT;
4676
4677 #ifdef CONFIG_80211AC_VHT
4678 if (mlme->vhtpriv.vht_option == _FALSE)
4679 goto exit;
4680
4681 _rtw_memset(&sta->vhtpriv, 0, sizeof(struct vht_priv));
4682 if (elems->vht_capabilities && elems->vht_capabilities_len == 12) {
4683 sta->flags |= WLAN_STA_VHT;
4684 _rtw_memcpy(sta->vhtpriv.vht_cap, elems->vht_capabilities, 12);
4685
4686 if (elems->vht_op_mode_notify && elems->vht_op_mode_notify_len == 1)
4687 _rtw_memcpy(&sta->vhtpriv.vht_op_mode_notify, elems->vht_op_mode_notify, 1);
4688 else /* for Frame without Operating Mode notify ie; default: 80M */
4689 sta->vhtpriv.vht_op_mode_notify = CHANNEL_WIDTH_80;
4690 }
4691 exit:
4692 #endif
4693
4694 return;
4695 }
4696 #endif /* CONFIG_AP_MODE */
4697
4698