1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <drv_types.h>
27 extern unsigned char RTW_WPA_OUI[];
28 extern unsigned char WMM_OUI[];
29 extern unsigned char WPS_OUI[];
30 extern unsigned char P2P_OUI[];
31 extern unsigned char WFD_OUI[];
33 void init_mlme_ap_info(_adapter *padapter)
35 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
36 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
38 _rtw_spinlock_init(&pmlmepriv->bcn_update_lock);
40 /* pmlmeext->bstart_bss = _FALSE; */
44 void free_mlme_ap_info(_adapter *padapter)
46 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
48 stop_ap_mode(padapter);
49 _rtw_spinlock_free(&pmlmepriv->bcn_update_lock);
53 static void update_BCNTIM(_adapter *padapter)
55 struct sta_priv *pstapriv = &padapter->stapriv;
56 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
57 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
58 WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
59 unsigned char *pie = pnetwork_mlmeext->IEs;
65 /* if(pstapriv->tim_bitmap) */
68 u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
70 uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
72 tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
74 p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
75 if (p != NULL && tim_ielen > 0) {
78 premainder_ie = p + tim_ielen;
80 tim_ie_offset = (sint)(p - pie);
82 remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
84 /*append TIM IE from dst_ie offset*/
89 /*calculate head_len*/
90 offset = _FIXED_IE_LENGTH_;
93 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SSID_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
95 offset += tmp_len + 2;
97 /*get supported rates len*/
98 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &tmp_len, (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_));
100 offset += tmp_len + 2;
102 /*DS Parameter Set IE, len=3*/
105 premainder_ie = pie + offset;
107 remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
109 /*append TIM IE from offset*/
110 dst_ie = pie + offset;
114 if (remainder_ielen > 0) {
115 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
116 if (pbackup_remainder_ie && premainder_ie)
117 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
120 *dst_ie++ = _TIM_IE_;
122 if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fe))
127 *dst_ie++ = tim_ielen;
129 *dst_ie++ = 0;/*DTIM count*/
130 *dst_ie++ = 1;/*DTIM period*/
132 if (pstapriv->tim_bitmap & BIT(0))/*for bc/mc frames*/
133 *dst_ie++ = BIT(0);/*bitmap ctrl */
137 if (tim_ielen == 4) {
140 if (pstapriv->tim_bitmap & 0x00fe)
141 pvb = (u8)tim_bitmap_le;
142 else if (pstapriv->tim_bitmap & 0xff00)
143 pvb = (u8)(tim_bitmap_le >> 8);
145 pvb = (u8)tim_bitmap_le;
149 } else if (tim_ielen == 5) {
150 _rtw_memcpy(dst_ie, &tim_bitmap_le, 2);
154 /*copy remainder IE*/
155 if (pbackup_remainder_ie) {
156 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
158 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
161 offset = (uint)(dst_ie - pie);
162 pnetwork_mlmeext->IELength = offset + remainder_ielen;
167 void rtw_add_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index, u8 *data, u8 len)
169 PNDIS_802_11_VARIABLE_IEs pIE;
171 u8 *pie = pnetwork->IEs;
172 u8 *p = NULL, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
173 u32 i, offset, ielen, ie_offset, remainder_ielen = 0;
175 for (i = sizeof(NDIS_802_11_FIXED_IEs); i < pnetwork->IELength;) {
176 pIE = (PNDIS_802_11_VARIABLE_IEs)(pnetwork->IEs + i);
178 if (pIE->ElementID > index)
180 else if (pIE->ElementID == index) { /* already exist the same IE */
189 i += (pIE->Length + 2);
192 if (p != NULL && ielen > 0) {
195 premainder_ie = p + ielen;
197 ie_offset = (sint)(p - pie);
199 remainder_ielen = pnetwork->IELength - ie_offset - ielen;
204 dst_ie = (p + ielen);
210 if (remainder_ielen > 0) {
211 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
212 if (pbackup_remainder_ie && premainder_ie)
213 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
219 _rtw_memcpy(dst_ie, data, len);
222 /* copy remainder IE */
223 if (pbackup_remainder_ie) {
224 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
226 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
229 offset = (uint)(dst_ie - pie);
230 pnetwork->IELength = offset + remainder_ielen;
233 void rtw_remove_bcn_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 index)
235 u8 *p, *dst_ie = NULL, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
236 uint offset, ielen, ie_offset, remainder_ielen = 0;
237 u8 *pie = pnetwork->IEs;
239 p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, index, &ielen, pnetwork->IELength - _FIXED_IE_LENGTH_);
240 if (p != NULL && ielen > 0) {
243 premainder_ie = p + ielen;
245 ie_offset = (sint)(p - pie);
247 remainder_ielen = pnetwork->IELength - ie_offset - ielen;
253 if (remainder_ielen > 0) {
254 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
255 if (pbackup_remainder_ie && premainder_ie)
256 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
259 /* copy remainder IE */
260 if (pbackup_remainder_ie) {
261 _rtw_memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
263 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
266 offset = (uint)(dst_ie - pie);
267 pnetwork->IELength = offset + remainder_ielen;
271 u8 chk_sta_is_alive(struct sta_info *psta);
272 u8 chk_sta_is_alive(struct sta_info *psta)
275 #ifdef DBG_EXPIRATION_CHK
276 RTW_INFO("sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
277 , MAC_ARG(psta->hwaddr)
278 , psta->rssi_stat.UndecoratedSmoothedPWDB
279 /* , STA_RX_PKTS_ARG(psta) */
280 , STA_RX_PKTS_DIFF_ARG(psta)
282 , psta->state & WIFI_SLEEP_STATE ? "PS, " : ""
283 , psta->state & WIFI_STA_ALIVE_CHK_STATE ? "SAC, " : ""
288 /* if(sta_last_rx_pkts(psta) == sta_rx_pkts(psta)) */
289 if ((psta->sta_stats.last_rx_data_pkts + psta->sta_stats.last_rx_ctrl_pkts) == (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts)) {
291 if (psta->state & WIFI_SLEEP_STATE)
297 sta_update_last_rx_pkts(psta);
302 void expire_timeout_chk(_adapter *padapter)
305 _list *phead, *plist;
307 struct sta_info *psta = NULL;
308 struct sta_priv *pstapriv = &padapter->stapriv;
309 u8 chk_alive_num = 0;
310 char chk_alive_list[NUM_STA];
314 #ifdef CONFIG_MCC_MODE
315 /* then driver may check fail due to not recv client's frame under sitesurvey,
316 * don't expire timeout chk under MCC under sitesurvey */
318 if (rtw_hal_mcc_link_status_chk(padapter, __func__) == _FALSE)
322 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
324 phead = &pstapriv->auth_list;
325 plist = get_next(phead);
327 /* check auth_queue */
328 #ifdef DBG_EXPIRATION_CHK
329 if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
330 RTW_INFO(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
331 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
334 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
335 psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
337 plist = get_next(plist);
340 #ifdef CONFIG_ATMEL_RC_PATCH
341 if (_TRUE == _rtw_memcmp((void *)(pstapriv->atmel_rc_pattern), (void *)(psta->hwaddr), ETH_ALEN))
343 if (psta->flag_atmel_rc)
346 if (psta->expire_to > 0) {
348 if (psta->expire_to == 0) {
349 rtw_list_delete(&psta->auth_list);
350 pstapriv->auth_list_cnt--;
352 RTW_INFO("auth expire %02X%02X%02X%02X%02X%02X\n",
353 psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4], psta->hwaddr[5]);
355 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
357 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
358 rtw_free_stainfo(padapter, psta);
359 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
361 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL);
367 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL);
371 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
373 phead = &pstapriv->asoc_list;
374 plist = get_next(phead);
376 /* check asoc_queue */
377 #ifdef DBG_EXPIRATION_CHK
378 if (rtw_end_of_queue_search(phead, plist) == _FALSE) {
379 RTW_INFO(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
380 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
383 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
384 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
385 plist = get_next(plist);
386 #ifdef CONFIG_ATMEL_RC_PATCH
387 RTW_INFO("%s:%d psta=%p, %02x,%02x||%02x,%02x \n\n", __func__, __LINE__,
388 psta, pstapriv->atmel_rc_pattern[0], pstapriv->atmel_rc_pattern[5], psta->hwaddr[0], psta->hwaddr[5]);
389 if (_TRUE == _rtw_memcmp((void *)pstapriv->atmel_rc_pattern, (void *)(psta->hwaddr), ETH_ALEN))
391 if (psta->flag_atmel_rc)
393 RTW_INFO("%s: debug line:%d\n", __func__, __LINE__);
395 #ifdef CONFIG_AUTO_AP_MODE
399 if (chk_sta_is_alive(psta) || !psta->expire_to) {
400 psta->expire_to = pstapriv->expire_to;
401 psta->keep_alive_trycnt = 0;
402 #ifdef CONFIG_TX_MCAST2UNI
403 psta->under_exist_checking = 0;
404 #endif /* CONFIG_TX_MCAST2UNI */
408 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
409 #ifdef CONFIG_80211N_HT
410 #ifdef CONFIG_TX_MCAST2UNI
411 if ((psta->flags & WLAN_STA_HT) && (psta->htpriv.agg_enable_bitmap || psta->under_exist_checking)) {
412 /* check sta by delba(addba) for 11n STA */
413 /* ToDo: use CCX report to check for all STAs */
414 /* 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); */
416 if (psta->expire_to <= (pstapriv->expire_to - 50)) {
417 RTW_INFO("asoc expire by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
418 psta->under_exist_checking = 0;
420 } else if (psta->expire_to <= (pstapriv->expire_to - 3) && (psta->under_exist_checking == 0)) {
421 RTW_INFO("asoc check by DELBA/ADDBA! (%d s)\n", (pstapriv->expire_to - psta->expire_to) * 2);
422 psta->under_exist_checking = 1;
423 /* tear down TX AMPDU */
424 send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
425 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
426 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
429 #endif /* CONFIG_TX_MCAST2UNI */
430 #endif /* CONFIG_80211N_HT */
431 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
433 if (psta->expire_to <= 0) {
434 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
436 if (padapter->registrypriv.wifi_spec == 1) {
437 psta->expire_to = pstapriv->expire_to;
441 #ifndef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
442 #ifdef CONFIG_80211N_HT
444 #define KEEP_ALIVE_TRYCNT (3)
446 if (psta->keep_alive_trycnt > 0 && psta->keep_alive_trycnt <= KEEP_ALIVE_TRYCNT) {
447 if (psta->state & WIFI_STA_ALIVE_CHK_STATE)
448 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
450 psta->keep_alive_trycnt = 0;
452 } else if ((psta->keep_alive_trycnt > KEEP_ALIVE_TRYCNT) && !(psta->state & WIFI_STA_ALIVE_CHK_STATE))
453 psta->keep_alive_trycnt = 0;
454 if ((psta->htpriv.ht_option == _TRUE) && (psta->htpriv.ampdu_enable == _TRUE)) {
455 uint priority = 1; /* test using BK */
458 /* issued = (psta->htpriv.agg_enable_bitmap>>priority)&0x1; */
459 issued |= (psta->htpriv.candidate_tid_bitmap >> priority) & 0x1;
462 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
463 psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
465 if (psta->state & WIFI_SLEEP_STATE)
466 psta->expire_to = 2; /* 2x2=4 sec */
468 psta->expire_to = 1; /* 2 sec */
470 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
472 /* add_ba_hdl(padapter, (u8*)paddbareq_parm); */
474 RTW_INFO("issue addba_req to check if sta alive, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
476 issue_addba_req(padapter, psta->hwaddr, (u8)priority);
478 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
480 psta->keep_alive_trycnt++;
486 if (psta->keep_alive_trycnt > 0 && psta->state & WIFI_STA_ALIVE_CHK_STATE) {
487 psta->keep_alive_trycnt = 0;
488 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
489 RTW_INFO("change to another methods to check alive if staion is at ps mode\n");
492 #endif /* CONFIG_80211N_HT */
493 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
494 if (psta->state & WIFI_SLEEP_STATE) {
495 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
496 /* to check if alive by another methods if staion is at ps mode. */
497 psta->expire_to = pstapriv->expire_to;
498 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
500 /* RTW_INFO("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->hwaddr)); */
502 /* to update bcn with tim_bitmap for this station */
503 pstapriv->tim_bitmap |= BIT(psta->aid);
504 update_beacon(padapter, _TIM_IE_, NULL, _TRUE);
506 if (!pmlmeext->active_keep_alive_check)
510 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
511 if (pmlmeext->active_keep_alive_check) {
514 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
515 if (stainfo_offset_valid(stainfo_offset))
516 chk_alive_list[chk_alive_num++] = stainfo_offset;
520 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
521 rtw_list_delete(&psta->asoc_list);
522 pstapriv->asoc_list_cnt--;
523 RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
524 updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
526 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
527 if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt)
528 && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME / pstapriv->asoc_list_cnt) / 2)
530 RTW_INFO("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__
531 , MAC_ARG(psta->hwaddr)
532 , psta->sleepq_len, padapter->xmitpriv.free_xmitframe_cnt, pstapriv->asoc_list_cnt);
533 wakeup_sta_to_xmit(padapter, psta);
538 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
540 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
543 u8 backup_oper_channel = 0, switch_channel = _TRUE;
544 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
546 #ifdef CONFIG_MCC_MODE
547 if (MCC_EN(padapter)) {
548 /* driver doesn't switch channel under MCC */
549 if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
550 switch_channel = _FALSE;
553 /* switch to correct channel of current network before issue keep-alive frames */
554 if (switch_channel) {
555 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
556 backup_oper_channel = rtw_get_oper_ch(padapter);
557 SelectChannel(padapter, pmlmeext->cur_channel);
561 /* issue null data to check sta alive*/
562 for (i = 0; i < chk_alive_num; i++) {
565 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
566 #ifdef CONFIG_ATMEL_RC_PATCH
567 if (_TRUE == _rtw_memcmp(pstapriv->atmel_rc_pattern, psta->hwaddr, ETH_ALEN))
569 if (psta->flag_atmel_rc)
572 if (!(psta->state & _FW_LINKED))
575 if (psta->state & WIFI_SLEEP_STATE)
576 ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
578 ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
580 psta->keep_alive_trycnt++;
581 if (ret == _SUCCESS) {
582 RTW_INFO("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
583 psta->expire_to = pstapriv->expire_to;
584 psta->keep_alive_trycnt = 0;
586 } else if (psta->keep_alive_trycnt <= 3) {
587 RTW_INFO("ack check for asoc expire, keep_alive_trycnt=%d\n", psta->keep_alive_trycnt);
592 psta->keep_alive_trycnt = 0;
593 RTW_INFO("asoc expire "MAC_FMT", state=0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
594 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
595 if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
596 rtw_list_delete(&psta->asoc_list);
597 pstapriv->asoc_list_cnt--;
598 updated = ap_free_sta(padapter, psta, _FALSE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
600 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
604 if (switch_channel) {
605 if (backup_oper_channel > 0) /* back to the original operation channel */
606 SelectChannel(padapter, backup_oper_channel);
609 #endif /* CONFIG_ACTIVE_KEEP_ALIVE_CHECK */
611 associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
614 void add_RATid(_adapter *padapter, struct sta_info *psta, u8 rssi_level)
618 unsigned char sta_band = 0, shortGIrate = _FALSE;
619 u64 tx_ra_bitmap = 0;
620 struct ht_priv *psta_ht = NULL;
621 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
622 WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
624 #ifdef CONFIG_80211N_HT
626 psta_ht = &psta->htpriv;
629 #endif /* CONFIG_80211N_HT */
631 if (!(psta->state & _FW_LINKED))
635 if (get_rf_mimo_mode(padapter) == RTL8712_RF_2T2R) {
636 /* is this a 2r STA? */
637 if ((pstat->tx_ra_bitmap & 0x0ff00000) != 0 && !(priv->pshare->has_2r_sta & BIT(pstat->aid))) {
638 priv->pshare->has_2r_sta |= BIT(pstat->aid);
639 if (rtw_read16(padapter, 0x102501f6) != 0xffff) {
640 rtw_write16(padapter, 0x102501f6, 0xffff);
641 reset_1r_sta_RA(priv, 0xffff);
642 Switch_1SS_Antenna(priv, 3);
644 } else { /* bg or 1R STA? */
645 if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat->ht_cap_len && priv->pshare->has_2r_sta == 0) {
646 if (rtw_read16(padapter, 0x102501f6) != 0x7777) {
648 rtw_write16(padapter, 0x102501f6, 0x7777);
649 reset_1r_sta_RA(priv, 0x7777);
650 Switch_1SS_Antenna(priv, 2);
657 if ((pstat->rssi_level < 1) || (pstat->rssi_level > 3)) {
658 if (pstat->rssi >= priv->pshare->rf_ft_var.raGoDownUpper)
659 pstat->rssi_level = 1;
660 else if ((pstat->rssi >= priv->pshare->rf_ft_var.raGoDown20MLower) ||
661 ((priv->pshare->is_40m_bw) && (pstat->ht_cap_len) &&
662 (pstat->rssi >= priv->pshare->rf_ft_var.raGoDown40MLower) &&
663 (pstat->ht_cap_buf.ht_cap_info & cpu_to_le16(_HTCAP_SUPPORT_CH_WDTH_))))
664 pstat->rssi_level = 2;
666 pstat->rssi_level = 3;
669 /* rate adaptive by rssi */
670 if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11N) && pstat->ht_cap_len) {
671 if ((get_rf_mimo_mode(priv) == MIMO_1T2R) || (get_rf_mimo_mode(priv) == MIMO_1T1R)) {
672 switch (pstat->rssi_level) {
674 pstat->tx_ra_bitmap &= 0x100f0000;
677 pstat->tx_ra_bitmap &= 0x100ff000;
680 if (priv->pshare->is_40m_bw)
681 pstat->tx_ra_bitmap &= 0x100ff005;
683 pstat->tx_ra_bitmap &= 0x100ff001;
688 switch (pstat->rssi_level) {
690 pstat->tx_ra_bitmap &= 0x1f0f0000;
693 pstat->tx_ra_bitmap &= 0x1f0ff000;
696 if (priv->pshare->is_40m_bw)
697 pstat->tx_ra_bitmap &= 0x000ff005;
699 pstat->tx_ra_bitmap &= 0x000ff001;
704 /* Don't need to mask high rates due to new rate adaptive parameters */
705 /* if (pstat->is_broadcom_sta) */ /* use MCS12 as the highest rate vs. Broadcom sta */
706 /* pstat->tx_ra_bitmap &= 0x81ffffff; */
708 /* NIC driver will report not supporting MCS15 and MCS14 in asoc req */
709 /* if (pstat->is_rtl8190_sta && !pstat->is_2t_mimo_sta) */
710 /* pstat->tx_ra_bitmap &= 0x83ffffff; */ /* if Realtek 1x2 sta, don't use MCS15 and MCS14 */
712 } else if ((priv->pmib->dot11BssType.net_work_type & WIRELESS_11G) && isErpSta(pstat)) {
713 switch (pstat->rssi_level) {
715 pstat->tx_ra_bitmap &= 0x00000f00;
718 pstat->tx_ra_bitmap &= 0x00000ff0;
721 pstat->tx_ra_bitmap &= 0x00000ff5;
725 pstat->tx_ra_bitmap &= 0x0000000d;
727 /* disable tx short GI when station cannot rx MCS15(AP is 2T2R) */
728 /* disable tx short GI when station cannot rx MCS7 (AP is 1T2R or 1T1R) */
729 /* if there is only 1r STA and we are 2T2R, DO NOT mask SGI rate */
730 if ((!(pstat->tx_ra_bitmap & 0x8000000) && (priv->pshare->has_2r_sta > 0) && (get_rf_mimo_mode(padapter) == RTL8712_RF_2T2R)) ||
731 (!(pstat->tx_ra_bitmap & 0x80000) && (get_rf_mimo_mode(padapter) != RTL8712_RF_2T2R)))
732 pstat->tx_ra_bitmap &= ~BIT(28);
735 rtw_hal_update_sta_rate_mask(padapter, psta);
736 tx_ra_bitmap = psta->ra_mask;
738 shortGIrate = query_ra_short_GI(psta);
740 if (pcur_network->Configuration.DSConfig > 14) {
742 if (tx_ra_bitmap & 0xffff000)
743 sta_band |= WIRELESS_11_5N ;
745 if (tx_ra_bitmap & 0xff0)
746 sta_band |= WIRELESS_11A;
749 #ifdef CONFIG_80211AC_VHT
750 if (psta->vhtpriv.vht_option)
751 sta_band = WIRELESS_11_5AC;
755 if (tx_ra_bitmap & 0xffff000)
756 sta_band |= WIRELESS_11_24N;
758 if (tx_ra_bitmap & 0xff0)
759 sta_band |= WIRELESS_11G;
761 if (tx_ra_bitmap & 0x0f)
762 sta_band |= WIRELESS_11B;
765 psta->wireless_mode = sta_band;
766 psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
768 if (psta->aid < NUM_STA) {
771 arg[0] = psta->mac_id;
773 arg[2] = shortGIrate;
774 arg[3] = psta->init_rate;
776 RTW_INFO("%s=> mac_id:%d , raid:%d , shortGIrate=%d, tx_ra_bitmap:0x%016llx, networkType:0x%02x\n",
777 __FUNCTION__, psta->mac_id, psta->raid, shortGIrate, tx_ra_bitmap, psta->wireless_mode);
779 rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, rssi_level);
781 RTW_INFO("station aid %d exceed the max number\n", psta->aid);
785 void update_bmc_sta(_adapter *padapter)
788 unsigned char network_type;
789 int supportRateNum = 0;
790 u64 tx_ra_bitmap = 0;
791 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
792 WLAN_BSSID_EX *pcur_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
793 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
796 psta->aid = 0;/* default set to 0 */
797 psta->qos_option = 0;
798 #ifdef CONFIG_80211N_HT
799 psta->htpriv.ht_option = _FALSE;
800 #endif /* CONFIG_80211N_HT */
802 psta->ieee8021x_blocked = 0;
804 _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
806 /* psta->dot118021XPrivacy = _NO_PRIVACY_; */ /* !!! remove it, because it has been set before this. */
808 /* prepare for add_RATid */
809 supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
810 network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, pcur_network->Configuration.DSConfig);
811 if (IsSupportedTxCCK(network_type))
812 network_type = WIRELESS_11B;
813 else if (network_type == WIRELESS_INVALID) { /* error handling */
814 if (pcur_network->Configuration.DSConfig > 14)
815 network_type = WIRELESS_11A;
817 network_type = WIRELESS_11B;
819 update_sta_basic_rate(psta, network_type);
820 psta->wireless_mode = network_type;
822 rtw_hal_update_sta_rate_mask(padapter, psta);
823 tx_ra_bitmap = psta->ra_mask;
825 psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
827 rtw_sta_media_status_rpt(padapter, psta, 1);
829 _enter_critical_bh(&psta->lock, &irqL);
830 psta->state = _FW_LINKED;
831 _exit_critical_bh(&psta->lock, &irqL);
834 RTW_INFO("add_RATid_bmc_sta error!\n");
839 * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
840 void update_sta_info_apmode(_adapter *padapter, struct sta_info *psta)
843 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
844 struct security_priv *psecuritypriv = &padapter->securitypriv;
845 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
846 #ifdef CONFIG_80211N_HT
847 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
848 struct ht_priv *phtpriv_sta = &psta->htpriv;
849 #endif /* CONFIG_80211N_HT */
850 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0;
851 /* set intf_tag to if1 */
852 /* psta->intf_tag = 0; */
854 RTW_INFO("%s\n", __FUNCTION__);
856 /*alloc macid when call rtw_alloc_stainfo(),release macid when call rtw_free_stainfo()*/
859 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _TRUE);
861 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
862 psta->ieee8021x_blocked = _TRUE;
864 psta->ieee8021x_blocked = _FALSE;
867 /* update sta's cap */
870 VCS_update(padapter, psta);
871 #ifdef CONFIG_80211N_HT
873 if (phtpriv_sta->ht_option) {
874 /* check if sta supports rx ampdu */
875 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
877 phtpriv_sta->rx_ampdu_min_spacing = (phtpriv_sta->ht_cap.ampdu_params_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
880 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
881 psta->bw_mode = CHANNEL_WIDTH_40;
883 psta->bw_mode = CHANNEL_WIDTH_20;
885 if (psta->ht_40mhz_intolerant)
886 psta->bw_mode = CHANNEL_WIDTH_20;
888 if (pmlmeext->cur_bwmode < psta->bw_mode)
889 psta->bw_mode = pmlmeext->cur_bwmode;
891 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
894 /* check if sta support s Short GI 20M */
895 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
896 phtpriv_sta->sgi_20m = _TRUE;
898 /* check if sta support s Short GI 40M */
899 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
900 if (psta->bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
901 phtpriv_sta->sgi_40m = _TRUE;
903 phtpriv_sta->sgi_40m = _FALSE;
906 psta->qos_option = _TRUE;
908 /* B0 Config LDPC Coding Capability */
909 if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
910 GET_HT_CAP_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
911 SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
912 RTW_INFO("Enable HT Tx LDPC for STA(%d)\n", psta->aid);
915 /* B7 B8 B9 Config STBC setting */
916 if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
917 GET_HT_CAP_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
918 SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
919 RTW_INFO("Enable HT Tx STBC for STA(%d)\n", psta->aid);
922 #ifdef CONFIG_BEAMFORMING
923 /*Config Tx beamforming setting*/
924 if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
925 GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
926 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
927 /*Shift to BEAMFORMING_HT_BEAMFORMEE_CHNL_EST_CAP*/
928 SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 6);
931 if (TEST_FLAG(phtpriv_ap->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
932 GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
933 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
934 /*Shift to BEAMFORMING_HT_BEAMFORMER_STEER_NUM*/
935 SET_FLAG(cur_beamform_cap, GET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS((u8 *)(&phtpriv_sta->ht_cap)) << 4);
937 if (cur_beamform_cap)
938 RTW_INFO("Client STA(%d) HT Beamforming Cap = 0x%02X\n", psta->aid, cur_beamform_cap);
939 #endif /*CONFIG_BEAMFORMING*/
941 phtpriv_sta->ampdu_enable = _FALSE;
943 phtpriv_sta->sgi_20m = _FALSE;
944 phtpriv_sta->sgi_40m = _FALSE;
945 psta->bw_mode = CHANNEL_WIDTH_20;
946 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
949 phtpriv_sta->ldpc_cap = cur_ldpc_cap;
950 phtpriv_sta->stbc_cap = cur_stbc_cap;
951 phtpriv_sta->beamform_cap = cur_beamform_cap;
954 send_delba(padapter, 0, psta->hwaddr);/* recipient */
957 send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
958 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
959 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
960 #endif /* CONFIG_80211N_HT */
962 #ifdef CONFIG_80211AC_VHT
963 update_sta_vht_info_apmode(padapter, psta);
966 update_ldpc_stbc_cap(psta);
968 /* todo: init other variables */
970 _rtw_memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
974 /* add_RATid(padapter, psta); */ /* move to ap_sta_info_defer_update() */
977 _enter_critical_bh(&psta->lock, &irqL);
978 psta->state |= _FW_LINKED;
979 _exit_critical_bh(&psta->lock, &irqL);
984 static void update_ap_info(_adapter *padapter, struct sta_info *psta)
986 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
987 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
988 struct security_priv *psecuritypriv = &padapter->securitypriv;
989 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
990 #ifdef CONFIG_80211N_HT
991 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
992 #endif /* CONFIG_80211N_HT */
994 psta->wireless_mode = pmlmeext->cur_wireless_mode;
996 psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
997 _rtw_memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
999 #ifdef CONFIG_80211N_HT
1000 /* HT related cap */
1001 if (phtpriv_ap->ht_option) {
1002 /* check if sta supports rx ampdu */
1003 /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
1005 /* check if sta support s Short GI 20M */
1006 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
1007 phtpriv_ap->sgi_20m = _TRUE;
1008 /* check if sta support s Short GI 40M */
1009 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
1010 phtpriv_ap->sgi_40m = _TRUE;
1012 psta->qos_option = _TRUE;
1014 phtpriv_ap->ampdu_enable = _FALSE;
1016 phtpriv_ap->sgi_20m = _FALSE;
1017 phtpriv_ap->sgi_40m = _FALSE;
1020 psta->bw_mode = pmlmeext->cur_bwmode;
1021 phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
1023 phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
1024 phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
1026 _rtw_memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
1028 #ifdef CONFIG_80211AC_VHT
1029 _rtw_memcpy(&psta->vhtpriv, &pmlmepriv->vhtpriv, sizeof(struct vht_priv));
1030 #endif /* CONFIG_80211AC_VHT */
1032 #endif /* CONFIG_80211N_HT */
1034 psta->state |= WIFI_AP_STATE; /* Aries, add,fix bug of flush_cam_entry at STOP AP mode , 0724 */
1037 static void rtw_set_hw_wmm_param(_adapter *padapter)
1039 u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
1043 u32 edca[4], inx[4];
1044 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1045 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1046 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1047 struct registry_priv *pregpriv = &padapter->registrypriv;
1051 if (IsSupported5G(pmlmeext->cur_wireless_mode) ||
1052 (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
1057 if (pmlmeinfo->WMM_enable == 0) {
1058 padapter->mlmepriv.acm_mask = 0;
1060 AIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
1062 if (pmlmeext->cur_wireless_mode & (WIRELESS_11G | WIRELESS_11A)) {
1065 } else if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
1074 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1075 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
1076 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
1077 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
1082 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1083 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
1086 edca[0] = edca[1] = edca[2] = edca[3] = 0;
1090 padapter->mlmepriv.acm_mask = acm_mask;
1094 /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
1096 AIFS = (7 * pmlmeinfo->slotTime) + aSifsTime;
1100 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1101 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
1102 edca[XMIT_BK_QUEUE] = acParm;
1103 RTW_INFO("WMM(BK): %x\n", acParm);
1106 AIFS = (3 * pmlmeinfo->slotTime) + aSifsTime;
1110 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1111 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
1112 edca[XMIT_BE_QUEUE] = acParm;
1113 RTW_INFO("WMM(BE): %x\n", acParm);
1116 AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1120 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1121 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
1122 edca[XMIT_VI_QUEUE] = acParm;
1123 RTW_INFO("WMM(VI): %x\n", acParm);
1126 AIFS = (1 * pmlmeinfo->slotTime) + aSifsTime;
1130 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
1131 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
1132 edca[XMIT_VO_QUEUE] = acParm;
1133 RTW_INFO("WMM(VO): %x\n", acParm);
1136 if (padapter->registrypriv.acm_method == 1)
1137 rtw_hal_set_hwreg(padapter, HW_VAR_ACM_CTRL, (u8 *)(&acm_mask));
1139 padapter->mlmepriv.acm_mask = acm_mask;
1146 if (pregpriv->wifi_spec == 1) {
1147 u32 j, tmp, change_inx = _FALSE;
1149 /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
1150 for (i = 0 ; i < 4 ; i++) {
1151 for (j = i + 1 ; j < 4 ; j++) {
1152 /* compare CW and AIFS */
1153 if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF))
1155 else if ((edca[j] & 0xFFFF) == (edca[i] & 0xFFFF)) {
1157 if ((edca[j] >> 16) > (edca[i] >> 16))
1170 change_inx = _FALSE;
1176 for (i = 0 ; i < 4 ; i++) {
1177 pxmitpriv->wmm_para_seq[i] = inx[i];
1178 RTW_INFO("wmm_para_seq(%d): %d\n", i, pxmitpriv->wmm_para_seq[i]);
1185 static void update_hw_ht_param(_adapter *padapter)
1187 unsigned char max_AMPDU_len;
1188 unsigned char min_MPDU_spacing;
1189 struct registry_priv *pregpriv = &padapter->registrypriv;
1190 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1191 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1193 RTW_INFO("%s\n", __FUNCTION__);
1196 /* handle A-MPDU parameter field */
1198 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
1199 AMPDU_para [4:2]:Min MPDU Start Spacing
1201 max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
1203 min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) >> 2;
1205 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
1207 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
1210 /* Config SM Power Save setting */
1212 pmlmeinfo->SM_PS = (pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info & 0x0C) >> 2;
1213 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC) {
1216 /* update the MCS rates */
1217 for (i = 0; i < 16; i++)
1218 pmlmeinfo->HT_caps.HT_cap_element.MCS_rate[i] &= MCS_rate_1R[i];
1220 RTW_INFO("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __FUNCTION__);
1224 /* Config current HT Protection mode. */
1226 /* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
1230 static void rtw_ap_check_scan(_adapter *padapter)
1233 _list *plist, *phead;
1234 u32 delta_time, lifetime;
1235 struct wlan_network *pnetwork = NULL;
1236 WLAN_BSSID_EX *pbss = NULL;
1237 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1238 _queue *queue = &(pmlmepriv->scanned_queue);
1239 u8 do_scan = _FALSE;
1240 u8 reason = RTW_AUTO_SCAN_REASON_UNSPECIFIED;
1242 lifetime = SCANQUEUE_LIFETIME; /* 20 sec */
1244 _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1245 phead = get_list_head(queue);
1246 if (rtw_end_of_queue_search(phead, get_next(phead)) == _TRUE)
1247 if (padapter->registrypriv.wifi_spec) {
1249 reason |= RTW_AUTO_SCAN_REASON_2040_BSS;
1251 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1253 #ifdef CONFIG_AUTO_CHNL_SEL_NHM
1254 if (padapter->registrypriv.acs_auto_scan) {
1256 reason |= RTW_AUTO_SCAN_REASON_ACS;
1257 rtw_acs_start(padapter, _TRUE);
1261 if (_TRUE == do_scan) {
1262 RTW_INFO("%s : drv scans by itself and wait_completed\n", __func__);
1263 rtw_drv_scan_by_self(padapter, reason);
1264 rtw_scan_wait_completed(padapter);
1267 #ifdef CONFIG_AUTO_CHNL_SEL_NHM
1268 if (padapter->registrypriv.acs_auto_scan)
1269 rtw_acs_start(padapter, _FALSE);
1271 _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1273 phead = get_list_head(queue);
1274 plist = get_next(phead);
1278 if (rtw_end_of_queue_search(phead, plist) == _TRUE)
1281 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
1283 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
1284 && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == _TRUE
1285 && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))) {
1286 delta_time = (u32) rtw_get_passing_time_ms(pnetwork->last_scanned);
1288 if (delta_time < lifetime) {
1294 pbss = &pnetwork->network;
1297 /*check if HT CAP INFO IE exists or not*/
1298 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss->IELength - _BEACON_IE_OFFSET_));
1300 /* HT CAP INFO IE don't exist, it is b/g mode bss.*/
1302 if (pmlmepriv->olbc == _FALSE)
1303 pmlmepriv->olbc = _TRUE;
1305 if (pmlmepriv->olbc_ht == _FALSE)
1306 pmlmepriv->olbc_ht = _TRUE;
1311 plist = get_next(plist);
1315 _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
1317 pmlmepriv->num_sta_no_ht = 0; /* reset to 0 after ap do scanning*/
1321 void rtw_start_bss_hdl_after_chbw_decided(_adapter *adapter)
1323 WLAN_BSSID_EX *pnetwork = &(adapter->mlmepriv.cur_network.network);
1324 struct sta_info *sta = NULL;
1326 /* update cur_wireless_mode */
1327 update_wireless_mode(adapter);
1329 /* update RRSR and RTS_INIT_RATE register after set channel and bandwidth */
1330 UpdateBrateTbl(adapter, pnetwork->SupportedRates);
1331 rtw_hal_set_hwreg(adapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
1333 /* update capability after cur_wireless_mode updated */
1334 update_capinfo(adapter, rtw_get_capability(pnetwork));
1336 /* update bc/mc sta_info */
1337 update_bmc_sta(adapter);
1339 /* update AP's sta info */
1340 sta = rtw_get_stainfo(&adapter->stapriv, pnetwork->MacAddress);
1342 RTW_INFO(FUNC_ADPT_FMT" !sta for macaddr="MAC_FMT"\n", FUNC_ADPT_ARG(adapter), MAC_ARG(pnetwork->MacAddress));
1347 update_ap_info(adapter, sta);
1350 void start_bss_network(_adapter *padapter, struct createbss_parm *parm)
1352 #define DUMP_ADAPTERS_STATUS 0
1357 struct registry_priv *pregpriv = &padapter->registrypriv;
1358 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1359 struct security_priv *psecuritypriv = &(padapter->securitypriv);
1360 WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network; /* used as input */
1361 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1362 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1363 WLAN_BSSID_EX *pnetwork_mlmeext = &(pmlmeinfo->network);
1364 struct dvobj_priv *pdvobj = padapter->dvobj;
1365 s16 req_ch = -1, req_bw = -1, req_offset = -1;
1366 bool ch_setting_changed = _FALSE;
1367 u8 ch_to_set = 0, bw_to_set, offset_to_set;
1369 /* use for check ch bw offset can be allowed or not */
1370 u8 chbw_allow = _TRUE;
1372 if (parm->req_ch != 0) {
1373 /* bypass other setting, go checking ch, bw, offset */
1374 req_ch = parm->req_ch;
1375 req_bw = parm->req_bw;
1376 req_offset = parm->req_offset;
1380 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
1382 /* check if there is wps ie, */
1383 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
1384 /* and at first time the security ie ( RSN/WPA IE) will not include in beacon. */
1385 if (NULL == rtw_get_wps_ie(pnetwork->IEs + _FIXED_IE_LENGTH_, pnetwork->IELength - _FIXED_IE_LENGTH_, NULL, NULL))
1386 pmlmeext->bstart_bss = _TRUE;
1388 /* todo: update wmm, ht cap */
1389 /* pmlmeinfo->WMM_enable; */
1390 /* pmlmeinfo->HT_enable; */
1391 if (pmlmepriv->qospriv.qos_option)
1392 pmlmeinfo->WMM_enable = _TRUE;
1393 #ifdef CONFIG_80211N_HT
1394 if (pmlmepriv->htpriv.ht_option) {
1395 pmlmeinfo->WMM_enable = _TRUE;
1396 pmlmeinfo->HT_enable = _TRUE;
1397 /* pmlmeinfo->HT_info_enable = _TRUE; */
1398 /* pmlmeinfo->HT_caps_enable = _TRUE; */
1400 update_hw_ht_param(padapter);
1402 #endif /* #CONFIG_80211N_HT */
1404 #ifdef CONFIG_80211AC_VHT
1405 if (pmlmepriv->vhtpriv.vht_option) {
1406 pmlmeinfo->VHT_enable = _TRUE;
1407 update_hw_vht_param(padapter);
1409 #endif /* CONFIG_80211AC_VHT */
1411 if (pmlmepriv->cur_network.join_res != _TRUE) { /* setting only at first time */
1412 /* WEP Key will be set before this function, do not clear CAM. */
1413 if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
1414 flush_all_cam_entry(padapter); /* clear CAM */
1417 /* set MSR to AP_Mode */
1418 Set_MSR(padapter, _HW_STATE_AP_);
1421 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
1423 /* Set EDCA param reg */
1424 #ifdef CONFIG_CONCURRENT_MODE
1425 acparm = 0x005ea42b;
1427 acparm = 0x002F3217; /* VO */
1429 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
1430 acparm = 0x005E4317; /* VI */
1431 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
1432 /* acparm = 0x00105320; */ /* BE */
1433 acparm = 0x005ea42b;
1434 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
1435 acparm = 0x0000A444; /* BK */
1436 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
1439 val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
1440 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
1442 /* Beacon Control related register */
1443 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
1446 ch_setting_changed = rtw_ap_chbw_decision(padapter, req_ch, req_bw, req_offset
1447 , &ch_to_set, &bw_to_set, &offset_to_set, &chbw_allow);
1449 /* let pnetwork_mlmeext == pnetwork_mlme. */
1450 _rtw_memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
1452 rtw_start_bss_hdl_after_chbw_decided(padapter);
1454 #if defined(CONFIG_DFS_MASTER)
1455 rtw_dfs_master_status_apply(padapter, MLME_AP_STARTED);
1458 #ifdef CONFIG_MCC_MODE
1459 /* issue null data to AP for all interface connecting to AP before switch channel setting for softap */
1460 rtw_hal_mcc_issue_null_data(padapter, chbw_allow, 1);
1461 #endif /* CONFIG_MCC_MODE */
1464 rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
1466 if (ch_to_set != 0) {
1467 set_channel_bwmode(padapter, ch_to_set, offset_to_set, bw_to_set);
1468 rtw_mi_update_union_chan_inf(padapter, ch_to_set, offset_to_set, bw_to_set);
1472 rtw_hal_set_hwreg(padapter , HW_VAR_DO_IQK , &doiqk);
1474 #ifdef CONFIG_MCC_MODE
1475 /* after set_channel_bwmode for backup IQK */
1476 rtw_hal_set_mcc_setting_start_bss_network(padapter, chbw_allow);
1479 if (DUMP_ADAPTERS_STATUS) {
1480 RTW_INFO(FUNC_ADPT_FMT" done\n", FUNC_ADPT_ARG(padapter));
1481 dump_adapters_status(RTW_DBGDUMP , adapter_to_dvobj(padapter));
1484 /* update beacon content only if bstart_bss is _TRUE */
1485 if (_TRUE == pmlmeext->bstart_bss) {
1489 if ((pmlmepriv->olbc == _TRUE) || (pmlmepriv->olbc_ht == _TRUE)) {
1491 /* AP is not starting a 40 MHz BSS in presence of an 802.11g BSS. */
1493 pmlmepriv->ht_op_mode &= (~HT_INFO_OPERATION_MODE_OP_MODE_MASK);
1494 pmlmepriv->ht_op_mode |= OP_MODE_MAY_BE_LEGACY_STAS;
1495 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
1498 update_beacon(padapter, _TIM_IE_, NULL, _FALSE);
1500 #ifdef CONFIG_SWTIMER_BASED_TXBCN
1501 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
1502 if (rtw_is_list_empty(&padapter->list)) {
1503 rtw_list_insert_tail(&padapter->list, get_list_head(&pdvobj->ap_if_q));
1505 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
1507 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
1509 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
1511 #endif /*CONFIG_SWTIMER_BASED_TXBCN*/
1515 rtw_scan_wait_completed(padapter);
1518 if ((0 == rtw_mi_check_fwstate(padapter, _FW_UNDER_SURVEY))
1519 && (0 == rtw_mi_check_fwstate(padapter, WIFI_OP_CH_SWITCHING))
1522 /*update_beacon(padapter, _TIM_IE_, NULL, _TRUE);*/
1524 #if !defined(CONFIG_INTERRUPT_BASED_TXBCN)
1525 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1526 #ifdef CONFIG_SWTIMER_BASED_TXBCN
1527 if (pdvobj->nr_ap_if == 1) {
1528 RTW_INFO("start SW BCN TIMER!\n");
1529 _set_timer(&pdvobj->txbcn_timer, bcn_interval);
1532 /* other case will tx beacon when bcn interrupt coming in. */
1533 if (send_beacon(padapter) == _FAIL)
1534 RTW_INFO("issue_beacon, fail!\n");
1537 #endif /* !defined(CONFIG_INTERRUPT_BASED_TXBCN) */
1540 /*Set EDCA param reg after update cur_wireless_mode & update_capinfo*/
1541 if (pregpriv->wifi_spec == 1)
1542 rtw_set_hw_wmm_param(padapter);
1544 /*pmlmeext->bstart_bss = _TRUE;*/
1547 int rtw_check_beacon_data(_adapter *padapter, u8 *pbuf, int len)
1551 u8 *pHT_caps_ie = NULL;
1552 u8 *pHT_info_ie = NULL;
1553 u16 cap, ht_cap = _FALSE;
1555 int group_cipher, pairwise_cipher;
1556 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
1557 int supportRateNum = 0;
1558 u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
1559 u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
1560 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
1561 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1562 struct security_priv *psecuritypriv = &padapter->securitypriv;
1563 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1564 WLAN_BSSID_EX *pbss_network = (WLAN_BSSID_EX *)&pmlmepriv->cur_network.network;
1565 struct sta_priv *pstapriv = &padapter->stapriv;
1566 u8 *ie = pbss_network->IEs;
1567 u8 vht_cap = _FALSE;
1568 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1569 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1573 /* Supported rates */
1575 /* WLAN_EID_COUNTRY */
1576 /* ERP Information element */
1577 /* Extended supported rates */
1579 /* Wi-Fi Wireless Multimedia Extensions */
1580 /* ht_capab, ht_oper */
1583 RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
1585 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
1589 if (len > MAX_IE_SZ)
1592 pbss_network->IELength = len;
1594 _rtw_memset(ie, 0, MAX_IE_SZ);
1596 _rtw_memcpy(ie, pbuf, pbss_network->IELength);
1599 if (pbss_network->InfrastructureMode != Ndis802_11APMode)
1603 rtw_ap_check_scan(padapter);
1606 pbss_network->Rssi = 0;
1608 _rtw_memcpy(pbss_network->MacAddress, adapter_mac_addr(padapter), ETH_ALEN);
1610 /* beacon interval */
1611 p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; */ /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1612 /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
1613 pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
1616 /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
1617 /* cap = le16_to_cpu(cap); */
1618 cap = RTW_GET_LE16(ie);
1621 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1622 if (p && ie_len > 0) {
1623 _rtw_memset(&pbss_network->Ssid, 0, sizeof(NDIS_802_11_SSID));
1624 _rtw_memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
1625 pbss_network->Ssid.SsidLength = ie_len;
1627 _rtw_memcpy(padapter->wdinfo.p2p_group_ssid, pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
1628 padapter->wdinfo.p2p_group_ssid_len = pbss_network->Ssid.SsidLength;
1634 pbss_network->Configuration.Length = 0;
1635 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1636 if (p && ie_len > 0)
1639 pbss_network->Configuration.DSConfig = channel;
1642 _rtw_memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
1643 /* get supported rates */
1644 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1646 _rtw_memcpy(supportRate, p + 2, ie_len);
1647 supportRateNum = ie_len;
1650 /* get ext_supported rates */
1651 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);
1653 _rtw_memcpy(supportRate + supportRateNum, p + 2, ie_len);
1654 supportRateNum += ie_len;
1658 network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
1660 rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
1663 /* parsing ERP_IE */
1664 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1665 if (p && ie_len > 0)
1666 ERP_IE_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)p);
1668 /* update privacy/security */
1670 pbss_network->Privacy = 1;
1672 pbss_network->Privacy = 0;
1674 psecuritypriv->wpa_psk = 0;
1678 pairwise_cipher = 0;
1679 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1680 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1681 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1682 if (p && ie_len > 0) {
1683 if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1684 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1686 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1687 psecuritypriv->wpa_psk |= BIT(1);
1689 psecuritypriv->wpa2_group_cipher = group_cipher;
1690 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
1692 switch (group_cipher) {
1693 case WPA_CIPHER_NONE:
1694 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1696 case WPA_CIPHER_WEP40:
1697 psecuritypriv->wpa2_group_cipher = _WEP40_;
1699 case WPA_CIPHER_TKIP:
1700 psecuritypriv->wpa2_group_cipher = _TKIP_;
1702 case WPA_CIPHER_CCMP:
1703 psecuritypriv->wpa2_group_cipher = _AES_;
1705 case WPA_CIPHER_WEP104:
1706 psecuritypriv->wpa2_group_cipher = _WEP104_;
1710 switch (pairwise_cipher) {
1711 case WPA_CIPHER_NONE:
1712 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1714 case WPA_CIPHER_WEP40:
1715 psecuritypriv->wpa2_pairwise_cipher = _WEP40_;
1717 case WPA_CIPHER_TKIP:
1718 psecuritypriv->wpa2_pairwise_cipher = _TKIP_;
1720 case WPA_CIPHER_CCMP:
1721 psecuritypriv->wpa2_pairwise_cipher = _AES_;
1723 case WPA_CIPHER_WEP104:
1724 psecuritypriv->wpa2_pairwise_cipher = _WEP104_;
1735 pairwise_cipher = 0;
1736 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1737 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1738 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1739 p = rtw_get_ie(p, _SSN_IE_1_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
1740 if ((p) && (_rtw_memcmp(p + 2, OUI1, 4))) {
1741 if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1742 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1744 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1746 psecuritypriv->wpa_psk |= BIT(0);
1748 psecuritypriv->wpa_group_cipher = group_cipher;
1749 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
1752 switch (group_cipher) {
1753 case WPA_CIPHER_NONE:
1754 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1756 case WPA_CIPHER_WEP40:
1757 psecuritypriv->wpa_group_cipher = _WEP40_;
1759 case WPA_CIPHER_TKIP:
1760 psecuritypriv->wpa_group_cipher = _TKIP_;
1762 case WPA_CIPHER_CCMP:
1763 psecuritypriv->wpa_group_cipher = _AES_;
1765 case WPA_CIPHER_WEP104:
1766 psecuritypriv->wpa_group_cipher = _WEP104_;
1770 switch (pairwise_cipher) {
1771 case WPA_CIPHER_NONE:
1772 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1774 case WPA_CIPHER_WEP40:
1775 psecuritypriv->wpa_pairwise_cipher = _WEP40_;
1777 case WPA_CIPHER_TKIP:
1778 psecuritypriv->wpa_pairwise_cipher = _TKIP_;
1780 case WPA_CIPHER_CCMP:
1781 psecuritypriv->wpa_pairwise_cipher = _AES_;
1783 case WPA_CIPHER_WEP104:
1784 psecuritypriv->wpa_pairwise_cipher = _WEP104_;
1794 if ((p == NULL) || (ie_len == 0))
1801 pmlmepriv->qospriv.qos_option = 0;
1802 if (pregistrypriv->wmm_enable) {
1803 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1804 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
1805 if ((p) && _rtw_memcmp(p + 2, WMM_PARA_IE, 6)) {
1806 pmlmepriv->qospriv.qos_option = 1;
1808 *(p + 8) |= BIT(7); /* QoS Info, support U-APSD */
1810 /* disable all ACM bits since the WMM admission control is not supported */
1811 *(p + 10) &= ~BIT(4); /* BE */
1812 *(p + 14) &= ~BIT(4); /* BK */
1813 *(p + 18) &= ~BIT(4); /* VI */
1814 *(p + 22) &= ~BIT(4); /* VO */
1819 if ((p == NULL) || (ie_len == 0))
1823 #ifdef CONFIG_80211N_HT
1824 /* parsing HT_CAP_IE */
1825 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1826 if (p && ie_len > 0) {
1828 HT_CAP_AMPDU_FACTOR max_rx_ampdu_factor = MAX_AMPDU_FACTOR_64K;
1829 struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p + 2);
1832 RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE from upper layer:\n", FUNC_ADPT_ARG(padapter));
1833 dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
1839 network_type |= WIRELESS_11_24N;
1841 rtw_ht_use_default_setting(padapter);
1843 /* Update HT Capabilities Info field */
1844 if (pmlmepriv->htpriv.sgi_20m == _FALSE)
1845 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_20);
1847 if (pmlmepriv->htpriv.sgi_40m == _FALSE)
1848 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_SGI_40);
1850 if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
1851 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_LDPC_CODING);
1853 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
1854 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_TX_STBC);
1856 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
1857 pht_cap->cap_info &= ~(IEEE80211_HT_CAP_RX_STBC_3R);
1859 /* Update A-MPDU Parameters field */
1860 pht_cap->ampdu_params_info &= ~(IEEE80211_HT_CAP_AMPDU_FACTOR | IEEE80211_HT_CAP_AMPDU_DENSITY);
1862 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
1863 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
1864 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
1866 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
1868 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
1869 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor); /* set Max Rx AMPDU size to 64K */
1871 _rtw_memcpy(&(pmlmeinfo->HT_caps), pht_cap, sizeof(struct HT_caps_element));
1873 /* Update Supported MCS Set field */
1877 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
1879 /* RX MCS Bitmask */
1882 case RF_1T2R: /* ? */
1883 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_1R);
1886 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_2R);
1889 set_mcs_rate_by_mask(HT_CAP_ELE_RX_MCS_MAP(pht_cap), MCS_RATE_3R);
1892 RTW_INFO("[warning] rf_type %d is not expected\n", rf_type);
1894 for (i = 0; i < 10; i++)
1895 *(HT_CAP_ELE_RX_MCS_MAP(pht_cap) + i) &= padapter->mlmeextpriv.default_supported_mcs_set[i];
1898 #ifdef CONFIG_BEAMFORMING
1899 /* Use registry value to enable HT Beamforming. */
1900 /* ToDo: use configure file to set these capability. */
1901 pht_cap->tx_BF_cap_info = 0;
1904 if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE)) {
1905 /* Transmit NDP Capable */
1906 SET_HT_CAP_TXBF_TRANSMIT_NDP_CAP(pht_cap, 1);
1907 /* Explicit Compressed Steering Capable */
1908 SET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(pht_cap, 1);
1909 /* Compressed Steering Number Antennas */
1910 SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, 1);
1911 rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMER_CAP, (u8 *)&rf_num);
1912 SET_HT_CAP_TXBF_CHNL_ESTIMATION_NUM_ANTENNAS(pht_cap, rf_num);
1916 if (TEST_FLAG(pmlmepriv->htpriv.beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE)) {
1917 /* Receive NDP Capable */
1918 SET_HT_CAP_TXBF_RECEIVE_NDP_CAP(pht_cap, 1);
1919 /* Explicit Compressed Beamforming Feedback Capable */
1920 SET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(pht_cap, 2);
1921 rtw_hal_get_def_var(padapter, HAL_DEF_BEAMFORMEE_CAP, (u8 *)&rf_num);
1922 SET_HT_CAP_TXBF_COMP_STEERING_NUM_ANTENNAS(pht_cap, rf_num);
1924 #endif /* CONFIG_BEAMFORMING */
1926 _rtw_memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
1929 RTW_INFO(FUNC_ADPT_FMT" HT_CAP_IE driver masked:\n", FUNC_ADPT_ARG(padapter));
1930 dump_ht_cap_ie_content(RTW_DBGDUMP, p + 2, ie_len);
1934 /* parsing HT_INFO_IE */
1935 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1936 if (p && ie_len > 0)
1938 #endif /* CONFIG_80211N_HT */
1939 switch (network_type) {
1941 pbss_network->NetworkTypeInUse = Ndis802_11DS;
1945 case WIRELESS_11G_24N:
1946 case WIRELESS_11BG_24N:
1947 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
1950 pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
1953 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
1957 pmlmepriv->cur_network.network_type = network_type;
1959 #ifdef CONFIG_80211N_HT
1960 pmlmepriv->htpriv.ht_option = _FALSE;
1962 if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
1963 (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
1965 /* ht_cap = _FALSE; */
1969 if (pregistrypriv->ht_enable && ht_cap == _TRUE) {
1970 pmlmepriv->htpriv.ht_option = _TRUE;
1971 pmlmepriv->qospriv.qos_option = 1;
1973 if (pregistrypriv->ampdu_enable == 1)
1974 pmlmepriv->htpriv.ampdu_enable = _TRUE;
1976 HT_caps_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_caps_ie);
1978 HT_info_handler(padapter, (PNDIS_802_11_VARIABLE_IEs)pHT_info_ie);
1982 #ifdef CONFIG_80211AC_VHT
1984 /* Parsing VHT CAP IE */
1985 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, EID_VHTCapability, &ie_len, (pbss_network->IELength - _BEACON_IE_OFFSET_));
1986 if (p && ie_len > 0)
1988 /* Parsing VHT OPERATION IE */
1991 pmlmepriv->vhtpriv.vht_option = _FALSE;
1992 /* if channel in 5G band, then add vht ie . */
1993 if ((pbss_network->Configuration.DSConfig > 14)
1994 && (pmlmepriv->htpriv.ht_option == _TRUE)
1995 && REGSTY_IS_11AC_ENABLE(pregistrypriv)
1996 && hal_chk_proto_cap(padapter, PROTO_CAP_11AC)
1997 && (!pmlmepriv->country_ent || COUNTRY_CHPLAN_EN_11AC(pmlmepriv->country_ent))
1999 if (vht_cap == _TRUE)
2000 pmlmepriv->vhtpriv.vht_option = _TRUE;
2001 else if (REGSTY_IS_11AC_AUTO(pregistrypriv)) {
2002 u8 cap_len, operation_len;
2004 rtw_vht_use_default_setting(padapter);
2007 /* VHT Operation mode notifiy bit in Extended IE (127) */
2010 SET_EXT_CAPABILITY_ELE_OP_MODE_NOTIF(pmlmepriv->ext_capab_ie_data, 1);
2011 pmlmepriv->ext_capab_ie_len = 10;
2012 rtw_set_ie(pbss_network->IEs + pbss_network->IELength, EID_EXTCapability, 8, pmlmepriv->ext_capab_ie_data, &len);
2013 pbss_network->IELength += pmlmepriv->ext_capab_ie_len;
2016 /* VHT Capabilities element */
2017 cap_len = rtw_build_vht_cap_ie(padapter, pbss_network->IEs + pbss_network->IELength);
2018 pbss_network->IELength += cap_len;
2020 /* VHT Operation element */
2021 operation_len = rtw_build_vht_operation_ie(padapter, pbss_network->IEs + pbss_network->IELength, pbss_network->Configuration.DSConfig);
2022 pbss_network->IELength += operation_len;
2024 pmlmepriv->vhtpriv.vht_option = _TRUE;
2027 #endif /* CONFIG_80211AC_VHT */
2029 pbss_network->Length = get_WLAN_BSSID_EX_sz((WLAN_BSSID_EX *)pbss_network);
2031 rtw_ies_get_chbw(pbss_network->IEs + _BEACON_IE_OFFSET_, pbss_network->IELength - _BEACON_IE_OFFSET_
2032 , &pmlmepriv->ori_ch, &pmlmepriv->ori_bw, &pmlmepriv->ori_offset);
2033 rtw_warn_on(pmlmepriv->ori_ch == 0);
2036 /* alloc sta_info for ap itself */
2038 struct sta_info *sta;
2040 sta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
2042 sta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
2048 rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
2050 int sk_band = RTW_GET_SCAN_BAND_SKIP(padapter);
2053 RTW_CLR_SCAN_BAND_SKIP(padapter, sk_band);
2056 rtw_indicate_connect(padapter);
2058 pmlmepriv->cur_network.join_res = _TRUE;/* for check if already set beacon */
2060 /* update bc/mc sta_info */
2061 /* update_bmc_sta(padapter); */
2067 #if CONFIG_RTW_MACADDR_ACL
2068 void rtw_macaddr_acl_init(_adapter *adapter)
2070 struct sta_priv *stapriv = &adapter->stapriv;
2071 struct wlan_acl_pool *acl = &stapriv->acl_list;
2072 _queue *acl_node_q = &acl->acl_node_q;
2076 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2077 _rtw_init_listhead(&(acl_node_q->queue));
2079 acl->mode = RTW_ACL_MODE_DISABLED;
2080 for (i = 0; i < NUM_ACL; i++) {
2081 _rtw_init_listhead(&acl->aclnode[i].list);
2082 acl->aclnode[i].valid = _FALSE;
2084 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2087 void rtw_macaddr_acl_deinit(_adapter *adapter)
2089 struct sta_priv *stapriv = &adapter->stapriv;
2090 struct wlan_acl_pool *acl = &stapriv->acl_list;
2091 _queue *acl_node_q = &acl->acl_node_q;
2094 struct rtw_wlan_acl_node *acl_node;
2096 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2097 head = get_list_head(acl_node_q);
2098 list = get_next(head);
2099 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2100 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2101 list = get_next(list);
2103 if (acl_node->valid == _TRUE) {
2104 acl_node->valid = _FALSE;
2105 rtw_list_delete(&acl_node->list);
2109 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2111 rtw_warn_on(acl->num);
2112 acl->mode = RTW_ACL_MODE_DISABLED;
2115 void rtw_set_macaddr_acl(_adapter *adapter, int mode)
2117 struct sta_priv *stapriv = &adapter->stapriv;
2118 struct wlan_acl_pool *acl = &stapriv->acl_list;
2120 RTW_INFO(FUNC_ADPT_FMT" mode=%d\n", FUNC_ADPT_ARG(adapter), mode);
2124 if (mode == RTW_ACL_MODE_DISABLED)
2125 rtw_macaddr_acl_deinit(adapter);
2128 int rtw_acl_add_sta(_adapter *adapter, const u8 *addr)
2133 int i = -1, ret = 0;
2134 struct rtw_wlan_acl_node *acl_node;
2135 struct sta_priv *stapriv = &adapter->stapriv;
2136 struct wlan_acl_pool *acl = &stapriv->acl_list;
2137 _queue *acl_node_q = &acl->acl_node_q;
2139 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2141 head = get_list_head(acl_node_q);
2142 list = get_next(head);
2144 /* search for existed entry */
2145 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2146 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2147 list = get_next(list);
2149 if (_rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2150 if (acl_node->valid == _TRUE) {
2159 if (acl->num >= NUM_ACL)
2162 /* find empty one and use */
2163 for (i = 0; i < NUM_ACL; i++) {
2165 acl_node = &acl->aclnode[i];
2166 if (acl_node->valid == _FALSE) {
2168 _rtw_init_listhead(&acl_node->list);
2169 _rtw_memcpy(acl_node->addr, addr, ETH_ALEN);
2170 acl_node->valid = _TRUE;
2172 rtw_list_insert_tail(&acl_node->list, get_list_head(acl_node_q));
2179 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2181 if (!existed && (i < 0 || i >= NUM_ACL))
2184 RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
2185 , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
2186 , (existed ? "existed" : ((i < 0 || i >= NUM_ACL) ? "no room" : "added"))
2192 int rtw_acl_remove_sta(_adapter *adapter, const u8 *addr)
2197 struct rtw_wlan_acl_node *acl_node;
2198 struct sta_priv *stapriv = &adapter->stapriv;
2199 struct wlan_acl_pool *acl = &stapriv->acl_list;
2200 _queue *acl_node_q = &acl->acl_node_q;
2201 u8 is_baddr = is_broadcast_mac_addr(addr);
2204 _enter_critical_bh(&(acl_node_q->lock), &irqL);
2206 head = get_list_head(acl_node_q);
2207 list = get_next(head);
2209 while (rtw_end_of_queue_search(head, list) == _FALSE) {
2210 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
2211 list = get_next(list);
2213 if (is_baddr || _rtw_memcmp(acl_node->addr, addr, ETH_ALEN)) {
2214 if (acl_node->valid == _TRUE) {
2215 acl_node->valid = _FALSE;
2216 rtw_list_delete(&acl_node->list);
2223 _exit_critical_bh(&(acl_node_q->lock), &irqL);
2225 RTW_INFO(FUNC_ADPT_FMT" "MAC_FMT" %s (acl_num=%d)\n"
2226 , FUNC_ADPT_ARG(adapter), MAC_ARG(addr)
2227 , is_baddr ? "clear all" : (match ? "match" : "no found")
2232 #endif /* CONFIG_RTW_MACADDR_ACL */
2234 u8 rtw_ap_set_pairwise_key(_adapter *padapter, struct sta_info *psta)
2236 struct cmd_obj *ph2c;
2237 struct set_stakey_parm *psetstakey_para;
2238 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
2241 ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2247 psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm));
2248 if (psetstakey_para == NULL) {
2249 rtw_mfree((u8 *) ph2c, sizeof(struct cmd_obj));
2254 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
2257 psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
2259 _rtw_memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN);
2261 _rtw_memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
2264 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
2272 static int rtw_ap_set_key(_adapter *padapter, u8 *key, u8 alg, int keyid, u8 set_tx)
2275 struct cmd_obj *pcmd;
2276 struct setkey_parm *psetkeyparm;
2277 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
2280 /* RTW_INFO("%s\n", __FUNCTION__); */
2282 pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
2287 psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
2288 if (psetkeyparm == NULL) {
2289 rtw_mfree((unsigned char *)pcmd, sizeof(struct cmd_obj));
2294 _rtw_memset(psetkeyparm, 0, sizeof(struct setkey_parm));
2296 psetkeyparm->keyid = (u8)keyid;
2297 if (is_wep_enc(alg))
2298 padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
2300 psetkeyparm->algorithm = alg;
2302 psetkeyparm->set_tx = set_tx;
2318 _rtw_memcpy(&(psetkeyparm->key[0]), key, keylen);
2320 pcmd->cmdcode = _SetKey_CMD_;
2321 pcmd->parmbuf = (u8 *)psetkeyparm;
2322 pcmd->cmdsz = (sizeof(struct setkey_parm));
2327 _rtw_init_listhead(&pcmd->list);
2329 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
2336 int rtw_ap_set_group_key(_adapter *padapter, u8 *key, u8 alg, int keyid)
2338 RTW_INFO("%s\n", __FUNCTION__);
2340 return rtw_ap_set_key(padapter, key, alg, keyid, 1);
2343 int rtw_ap_set_wep_key(_adapter *padapter, u8 *key, u8 keylen, int keyid, u8 set_tx)
2358 RTW_INFO("%s\n", __FUNCTION__);
2360 return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
2363 u8 rtw_ap_bmc_frames_hdl(_adapter *padapter)
2365 #define HIQ_XMIT_COUNTS (6)
2367 struct sta_info *psta_bmc;
2368 _list *xmitframe_plist, *xmitframe_phead;
2369 struct xmit_frame *pxmitframe = NULL;
2370 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2371 struct sta_priv *pstapriv = &padapter->stapriv;
2372 bool update_tim = _FALSE;
2375 if (padapter->registrypriv.wifi_spec != 1)
2379 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2384 _enter_critical_bh(&pxmitpriv->lock, &irqL);
2386 if ((pstapriv->tim_bitmap & BIT(0)) && (psta_bmc->sleepq_len > 0)) {
2389 _update_beacon(padapter, _TIM_IE_, NULL, _FALSE, "update TIM with TIB=1");
2391 RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);
2393 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2394 xmitframe_plist = get_next(xmitframe_phead);
2396 while ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == _FALSE) {
2397 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2399 xmitframe_plist = get_next(xmitframe_plist);
2401 rtw_list_delete(&pxmitframe->list);
2403 psta_bmc->sleepq_len--;
2406 if (psta_bmc->sleepq_len > 0)
2407 pxmitframe->attrib.mdata = 1;
2409 pxmitframe->attrib.mdata = 0;
2411 if (tx_counts == HIQ_XMIT_COUNTS)
2412 pxmitframe->attrib.mdata = 0;
2414 pxmitframe->attrib.triggered = 1;
2416 if (xmitframe_hiq_filter(pxmitframe) == _TRUE)
2417 pxmitframe->attrib.qsel = QSLT_HIGH;/*HIQ*/
2419 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2421 if (tx_counts == HIQ_XMIT_COUNTS)
2427 if (psta_bmc->sleepq_len == 0) {
2429 /*RTW_INFO("sleepq_len of bmc_sta = %d\n", psta_bmc->sleepq_len);*/
2431 if (pstapriv->tim_bitmap & BIT(0))
2434 pstapriv->tim_bitmap &= ~BIT(0);
2435 pstapriv->sta_dz_bitmap &= ~BIT(0);
2437 if (update_tim == _TRUE) {
2438 RTW_INFO("clear TIB\n");
2439 _update_beacon(padapter, _TIM_IE_, NULL, _TRUE, "bmc sleepq and HIQ empty");
2444 _exit_critical_bh(&pxmitpriv->lock, &irqL);
2448 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2450 while (_FALSE == empty && rtw_get_passing_time_ms(start) < 3000) {
2452 rtw_hal_get_hwreg(padapter, HW_VAR_CHK_HI_QUEUE_EMPTY, &empty);
2456 printk("check if hiq empty=%d\n", empty);
2462 #ifdef CONFIG_NATIVEAP_MLME
2464 static void associated_stainfo_update(_adapter *padapter, struct sta_info *psta, u32 sta_info_type)
2466 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2468 RTW_INFO("%s: "MAC_FMT", updated_type=0x%x\n", __func__, MAC_ARG(psta->hwaddr), sta_info_type);
2470 if (sta_info_type & STA_INFO_UPDATE_BW) {
2472 if ((psta->flags & WLAN_STA_HT) && !psta->ht_20mhz_set) {
2473 if (pmlmepriv->sw_to_20mhz) {
2474 psta->bw_mode = CHANNEL_WIDTH_20;
2475 /*psta->htpriv.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;*/
2476 psta->htpriv.sgi_40m = _FALSE;
2478 /*TODO: Switch back to 40MHZ?80MHZ*/
2484 if (sta_info_type & STA_INFO_UPDATE_RATE) {
2489 if (sta_info_type & STA_INFO_UPDATE_PROTECTION_MODE)
2490 VCS_update(padapter, psta);
2493 if (sta_info_type & STA_INFO_UPDATE_CAP) {
2497 if (sta_info_type & STA_INFO_UPDATE_HT_CAP) {
2501 if (sta_info_type & STA_INFO_UPDATE_VHT_CAP) {
2508 static void update_bcn_ext_capab_ie(_adapter *padapter)
2511 unsigned char *pbuf;
2512 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2513 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2514 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2515 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2516 u8 *ie = pnetwork->IEs;
2517 u8 null_extcap_data[8] = {0};
2519 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_CAP_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2520 if (pbuf && ie_len > 0)
2521 rtw_remove_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_);
2523 if ((pmlmepriv->ext_capab_ie_len > 0) &&
2524 (_rtw_memcmp(pmlmepriv->ext_capab_ie_data, null_extcap_data, sizeof(null_extcap_data)) == _FALSE))
2525 rtw_add_bcn_ie(padapter, pnetwork, _EXT_CAP_IE_, pmlmepriv->ext_capab_ie_data, pmlmepriv->ext_capab_ie_len);
2529 static void update_bcn_fixed_ie(_adapter *padapter)
2531 RTW_INFO("%s\n", __FUNCTION__);
2535 static void update_bcn_erpinfo_ie(_adapter *padapter)
2537 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2538 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2539 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2540 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2541 unsigned char *p, *ie = pnetwork->IEs;
2544 RTW_INFO("%s, ERP_enable=%d\n", __FUNCTION__, pmlmeinfo->ERP_enable);
2546 if (!pmlmeinfo->ERP_enable)
2549 /* parsing ERP_IE */
2550 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2552 PNDIS_802_11_VARIABLE_IEs pIE = (PNDIS_802_11_VARIABLE_IEs)p;
2554 if (pmlmepriv->num_sta_non_erp == 1)
2555 pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION;
2557 pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT | RTW_ERP_INFO_USE_PROTECTION);
2559 if (pmlmepriv->num_sta_no_short_preamble > 0)
2560 pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
2562 pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
2564 ERP_IE_handler(padapter, pIE);
2569 static void update_bcn_htcap_ie(_adapter *padapter)
2571 RTW_INFO("%s\n", __FUNCTION__);
2575 static void update_bcn_htinfo_ie(_adapter *padapter)
2578 u8 beacon_updated = _FALSE;
2579 u32 sta_info_update_type = STA_INFO_UPDATE_NONE;
2581 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2582 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2583 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2584 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2585 unsigned char *p, *ie = pnetwork->IEs;
2588 if (pmlmepriv->htpriv.ht_option == _FALSE)
2591 if (pmlmeinfo->HT_info_enable != 1)
2595 RTW_INFO("%s current operation mode=0x%X\n",
2596 __FUNCTION__, pmlmepriv->ht_op_mode);
2598 RTW_INFO("num_sta_40mhz_intolerant(%d), 20mhz_width_req(%d), intolerant_ch_rpt(%d), olbc(%d)\n",
2599 pmlmepriv->num_sta_40mhz_intolerant, pmlmepriv->ht_20mhz_width_req, pmlmepriv->ht_intolerant_ch_reported, pmlmepriv->olbc);
2601 /*parsing HT_INFO_IE, currently only update ht_op_mode - pht_info->infos[1] & pht_info->infos[2] for wifi logo test*/
2602 p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2604 struct HT_info_element *pht_info = NULL;
2606 pht_info = (struct HT_info_element *)(p + 2);
2608 /* for STA Channel Width/Secondary Channel Offset*/
2609 if ((pmlmepriv->sw_to_20mhz == 0) && (pmlmeext->cur_channel <= 14)) {
2610 if ((pmlmepriv->num_sta_40mhz_intolerant > 0) || (pmlmepriv->ht_20mhz_width_req == _TRUE)
2611 || (pmlmepriv->ht_intolerant_ch_reported == _TRUE) || (pmlmepriv->olbc == _TRUE)) {
2612 SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info, 0);
2613 SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 0);
2615 pmlmepriv->sw_to_20mhz = 1;
2617 sta_info_update_type |= STA_INFO_UPDATE_BW;
2618 beacon_updated = _TRUE;
2621 RTW_INFO("%s:switching to 20Mhz\n", __FUNCTION__);
2623 /*TODO : cur_bwmode/cur_ch_offset switches to 20Mhz*/
2627 if ((pmlmepriv->num_sta_40mhz_intolerant == 0) && (pmlmepriv->ht_20mhz_width_req == _FALSE)
2628 && (pmlmepriv->ht_intolerant_ch_reported == _FALSE) && (pmlmepriv->olbc == _FALSE)) {
2630 if (pmlmeext->cur_bwmode >= CHANNEL_WIDTH_40) {
2632 SET_HT_OP_ELE_STA_CHL_WIDTH(pht_info, 1);
2634 SET_HT_OP_ELE_2ND_CHL_OFFSET(pht_info,
2635 (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) ?
2636 HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE : HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW);
2638 pmlmepriv->sw_to_20mhz = 0;
2640 sta_info_update_type |= STA_INFO_UPDATE_BW;
2641 beacon_updated = _TRUE;
2644 RTW_INFO("%s:switching back to 40Mhz\n", __FUNCTION__);
2649 /* to update ht_op_mode*/
2650 *(u16 *)(pht_info->infos + 1) = cpu_to_le16(pmlmepriv->ht_op_mode);
2654 /*associated_clients_update(padapter, beacon_updated, sta_info_update_type);*/
2658 static void update_bcn_rsn_ie(_adapter *padapter)
2660 RTW_INFO("%s\n", __FUNCTION__);
2664 static void update_bcn_wpa_ie(_adapter *padapter)
2666 RTW_INFO("%s\n", __FUNCTION__);
2670 static void update_bcn_wmm_ie(_adapter *padapter)
2672 RTW_INFO("%s\n", __FUNCTION__);
2676 static void update_bcn_wps_ie(_adapter *padapter)
2678 u8 *pwps_ie = NULL, *pwps_ie_src, *premainder_ie, *pbackup_remainder_ie = NULL;
2679 uint wps_ielen = 0, wps_offset, remainder_ielen;
2680 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2681 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2682 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2683 WLAN_BSSID_EX *pnetwork = &(pmlmeinfo->network);
2684 unsigned char *ie = pnetwork->IEs;
2685 u32 ielen = pnetwork->IELength;
2688 RTW_INFO("%s\n", __FUNCTION__);
2690 pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_, ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
2692 if (pwps_ie == NULL || wps_ielen == 0)
2695 pwps_ie_src = pmlmepriv->wps_beacon_ie;
2696 if (pwps_ie_src == NULL)
2699 wps_offset = (uint)(pwps_ie - ie);
2701 premainder_ie = pwps_ie + wps_ielen;
2703 remainder_ielen = ielen - wps_offset - wps_ielen;
2705 if (remainder_ielen > 0) {
2706 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
2707 if (pbackup_remainder_ie)
2708 _rtw_memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
2711 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
2712 if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
2713 _rtw_memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
2714 pwps_ie += (wps_ielen + 2);
2716 if (pbackup_remainder_ie)
2717 _rtw_memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
2719 /* update IELength */
2720 pnetwork->IELength = wps_offset + (wps_ielen + 2) + remainder_ielen;
2723 if (pbackup_remainder_ie)
2724 rtw_mfree(pbackup_remainder_ie, remainder_ielen);
2726 /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
2727 #if defined(CONFIG_INTERRUPT_BASED_TXBCN) || defined(CONFIG_PCI_HCI)
2728 if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
2730 rtw_get_wps_attr_content(pwps_ie_src, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
2733 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
2734 RTW_INFO("%s, set WIFI_UNDER_WPS\n", __func__);
2740 static void update_bcn_p2p_ie(_adapter *padapter)
2745 static void update_bcn_vendor_spec_ie(_adapter *padapter, u8 *oui)
2747 RTW_INFO("%s\n", __FUNCTION__);
2749 if (_rtw_memcmp(RTW_WPA_OUI, oui, 4))
2750 update_bcn_wpa_ie(padapter);
2751 else if (_rtw_memcmp(WMM_OUI, oui, 4))
2752 update_bcn_wmm_ie(padapter);
2753 else if (_rtw_memcmp(WPS_OUI, oui, 4))
2754 update_bcn_wps_ie(padapter);
2755 else if (_rtw_memcmp(P2P_OUI, oui, 4))
2756 update_bcn_p2p_ie(padapter);
2758 RTW_INFO("unknown OUI type!\n");
2763 void _update_beacon(_adapter *padapter, u8 ie_id, u8 *oui, u8 tx, const char *tag)
2766 struct mlme_priv *pmlmepriv;
2767 struct mlme_ext_priv *pmlmeext;
2768 /* struct mlme_ext_info *pmlmeinfo; */
2770 /* RTW_INFO("%s\n", __FUNCTION__); */
2775 pmlmepriv = &(padapter->mlmepriv);
2776 pmlmeext = &(padapter->mlmeextpriv);
2777 /* pmlmeinfo = &(pmlmeext->mlmext_info); */
2779 if (_FALSE == pmlmeext->bstart_bss)
2782 _enter_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
2787 update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
2793 update_BCNTIM(padapter);
2799 update_bcn_erpinfo_ie(padapter);
2803 case _HT_CAPABILITY_IE_:
2805 update_bcn_htcap_ie(padapter);
2811 update_bcn_rsn_ie(padapter);
2815 case _HT_ADD_INFO_IE_:
2817 update_bcn_htinfo_ie(padapter);
2823 update_bcn_ext_capab_ie(padapter);
2827 case _VENDOR_SPECIFIC_IE_:
2829 update_bcn_vendor_spec_ie(padapter, oui);
2837 pmlmepriv->update_bcn = _TRUE;
2839 _exit_critical_bh(&pmlmepriv->bcn_update_lock, &irqL);
2841 #ifndef CONFIG_INTERRUPT_BASED_TXBCN
2842 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2844 /* send_beacon(padapter); */ /* send_beacon must execute on TSR level */
2846 RTW_INFO(FUNC_ADPT_FMT" ie_id:%u - %s\n", FUNC_ADPT_ARG(padapter), ie_id, tag);
2847 set_tx_beacon_cmd(padapter);
2851 /* PCI will issue beacon when BCN interrupt occurs. */
2854 #endif /* !CONFIG_INTERRUPT_BASED_TXBCN */
2858 #ifdef CONFIG_80211N_HT
2860 void rtw_process_public_act_bsscoex(_adapter *padapter, u8 *pframe, uint frame_len)
2862 struct sta_info *psta;
2863 struct sta_priv *pstapriv = &padapter->stapriv;
2864 u8 beacon_updated = _FALSE;
2865 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2866 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
2867 uint frame_body_len = frame_len - sizeof(struct rtw_ieee80211_hdr_3addr);
2868 u8 category, action;
2870 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
2875 category = frame_body[0];
2876 action = frame_body[1];
2878 if (frame_body_len > 0) {
2879 if ((frame_body[2] == EID_BSSCoexistence) && (frame_body[3] > 0)) {
2880 u8 ie_data = frame_body[4];
2882 if (ie_data & RTW_WLAN_20_40_BSS_COEX_40MHZ_INTOL) {
2883 if (psta->ht_40mhz_intolerant == 0) {
2884 psta->ht_40mhz_intolerant = 1;
2885 pmlmepriv->num_sta_40mhz_intolerant++;
2886 beacon_updated = _TRUE;
2888 } else if (ie_data & RTW_WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ) {
2889 if (pmlmepriv->ht_20mhz_width_req == _FALSE) {
2890 pmlmepriv->ht_20mhz_width_req = _TRUE;
2891 beacon_updated = _TRUE;
2894 beacon_updated = _FALSE;
2898 if (frame_body_len > 8) {
2899 /* if EID_BSSIntolerantChlReport ie exists */
2900 if ((frame_body[5] == EID_BSSIntolerantChlReport) && (frame_body[6] > 0)) {
2902 if (pmlmepriv->ht_intolerant_ch_reported == _FALSE) {
2903 pmlmepriv->ht_intolerant_ch_reported = _TRUE;
2904 beacon_updated = _TRUE;
2909 if (beacon_updated) {
2911 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
2913 associated_stainfo_update(padapter, psta, STA_INFO_UPDATE_BW);
2920 void rtw_process_ht_action_smps(_adapter *padapter, u8 *ta, u8 ctrl_field)
2922 u8 e_field, m_field;
2923 struct sta_info *psta;
2924 struct sta_priv *pstapriv = &padapter->stapriv;
2926 psta = rtw_get_stainfo(pstapriv, ta);
2930 e_field = (ctrl_field & BIT(0)) ? 1 : 0;
2931 m_field = (ctrl_field & BIT(1)) ? 1 : 0;
2936 /* 0:static SMPS, 1:dynamic SMPS, 3:SMPS disabled, 2:reserved*/
2938 if (m_field) /*mode*/
2939 psta->htpriv.smps_cap = 1;
2941 psta->htpriv.smps_cap = 0;
2944 psta->htpriv.smps_cap = 3;
2947 rtw_dm_ra_mask_wk_cmd(padapter, (u8 *)psta);
2953 Set to 0 (HT pure) under the followign conditions
2954 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
2955 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
2956 Set to 1 (HT non-member protection) if there may be non-HT STAs
2957 in both the primary and the secondary channel
2958 Set to 2 if only HT STAs are associated in BSS,
2959 however and at least one 20 MHz HT STA is associated
2960 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
2961 (currently non-GF HT station is considered as non-HT STA also)
2963 static int rtw_ht_operation_update(_adapter *padapter)
2965 u16 cur_op_mode, new_op_mode;
2966 int op_mode_changes = 0;
2967 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2968 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
2970 if (pmlmepriv->htpriv.ht_option == _FALSE)
2973 /*if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
2976 RTW_INFO("%s current operation mode=0x%X\n",
2977 __FUNCTION__, pmlmepriv->ht_op_mode);
2979 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
2980 && pmlmepriv->num_sta_ht_no_gf) {
2981 pmlmepriv->ht_op_mode |=
2982 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
2984 } else if ((pmlmepriv->ht_op_mode &
2985 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
2986 pmlmepriv->num_sta_ht_no_gf == 0) {
2987 pmlmepriv->ht_op_mode &=
2988 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
2992 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
2993 (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
2994 pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
2996 } else if ((pmlmepriv->ht_op_mode &
2997 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
2998 (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
2999 pmlmepriv->ht_op_mode &=
3000 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
3004 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
3005 * station is associated. Probably it's a theoretical case, since
3006 * it looks like all known HT STAs support greenfield.
3009 if (pmlmepriv->num_sta_no_ht /*||
3010 (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)*/)
3011 new_op_mode = OP_MODE_MIXED;
3012 else if ((phtpriv_ap->ht_cap.cap_info & IEEE80211_HT_CAP_SUP_WIDTH)
3013 && pmlmepriv->num_sta_ht_20mhz)
3014 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
3015 else if (pmlmepriv->olbc_ht)
3016 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
3018 new_op_mode = OP_MODE_PURE;
3020 cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3021 if (cur_op_mode != new_op_mode) {
3022 pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
3023 pmlmepriv->ht_op_mode |= new_op_mode;
3027 RTW_INFO("%s new operation mode=0x%X changes=%d\n",
3028 __FUNCTION__, pmlmepriv->ht_op_mode, op_mode_changes);
3030 return op_mode_changes;
3034 #endif /* CONFIG_80211N_HT */
3036 void associated_clients_update(_adapter *padapter, u8 updated, u32 sta_info_type)
3038 /* update associcated stations cap. */
3039 if (updated == _TRUE) {
3041 _list *phead, *plist;
3042 struct sta_info *psta = NULL;
3043 struct sta_priv *pstapriv = &padapter->stapriv;
3045 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3047 phead = &pstapriv->asoc_list;
3048 plist = get_next(phead);
3050 /* check asoc_queue */
3051 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3052 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3054 plist = get_next(plist);
3056 associated_stainfo_update(padapter, psta, sta_info_type);
3059 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3065 /* called > TSR LEVEL for USB or SDIO Interface*/
3066 void bss_cap_update_on_sta_join(_adapter *padapter, struct sta_info *psta)
3068 u8 beacon_updated = _FALSE;
3069 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3070 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3074 if (!(psta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
3075 !psta->no_short_preamble_set) {
3076 psta->no_short_preamble_set = 1;
3077 pmlmepriv->num_sta_no_short_preamble++;
3078 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3079 (pmlmepriv->num_sta_no_short_preamble == 1))
3080 ieee802_11_set_beacons(hapd->iface);
3085 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
3086 if (!psta->no_short_preamble_set) {
3087 psta->no_short_preamble_set = 1;
3089 pmlmepriv->num_sta_no_short_preamble++;
3091 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3092 (pmlmepriv->num_sta_no_short_preamble == 1)) {
3093 beacon_updated = _TRUE;
3094 update_beacon(padapter, 0xFF, NULL, _TRUE);
3099 if (psta->no_short_preamble_set) {
3100 psta->no_short_preamble_set = 0;
3102 pmlmepriv->num_sta_no_short_preamble--;
3104 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3105 (pmlmepriv->num_sta_no_short_preamble == 0)) {
3106 beacon_updated = _TRUE;
3107 update_beacon(padapter, 0xFF, NULL, _TRUE);
3114 if (psta->flags & WLAN_STA_NONERP && !psta->nonerp_set) {
3115 psta->nonerp_set = 1;
3116 pmlmepriv->num_sta_non_erp++;
3117 if (pmlmepriv->num_sta_non_erp == 1)
3118 ieee802_11_set_beacons(hapd->iface);
3122 if (psta->flags & WLAN_STA_NONERP) {
3123 if (!psta->nonerp_set) {
3124 psta->nonerp_set = 1;
3126 pmlmepriv->num_sta_non_erp++;
3128 if (pmlmepriv->num_sta_non_erp == 1) {
3129 beacon_updated = _TRUE;
3130 update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
3135 if (psta->nonerp_set) {
3136 psta->nonerp_set = 0;
3138 pmlmepriv->num_sta_non_erp--;
3140 if (pmlmepriv->num_sta_non_erp == 0) {
3141 beacon_updated = _TRUE;
3142 update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
3150 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT) &&
3151 !psta->no_short_slot_time_set) {
3152 psta->no_short_slot_time_set = 1;
3153 pmlmepriv->num_sta_no_short_slot_time++;
3154 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3155 (pmlmepriv->num_sta_no_short_slot_time == 1))
3156 ieee802_11_set_beacons(hapd->iface);
3160 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
3161 if (!psta->no_short_slot_time_set) {
3162 psta->no_short_slot_time_set = 1;
3164 pmlmepriv->num_sta_no_short_slot_time++;
3166 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3167 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
3168 beacon_updated = _TRUE;
3169 update_beacon(padapter, 0xFF, NULL, _TRUE);
3174 if (psta->no_short_slot_time_set) {
3175 psta->no_short_slot_time_set = 0;
3177 pmlmepriv->num_sta_no_short_slot_time--;
3179 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
3180 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
3181 beacon_updated = _TRUE;
3182 update_beacon(padapter, 0xFF, NULL, _TRUE);
3187 #ifdef CONFIG_80211N_HT
3189 if (psta->flags & WLAN_STA_HT) {
3190 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
3192 RTW_INFO("HT: STA " MAC_FMT " HT Capabilities "
3193 "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
3195 if (psta->no_ht_set) {
3196 psta->no_ht_set = 0;
3197 pmlmepriv->num_sta_no_ht--;
3200 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
3201 if (!psta->no_ht_gf_set) {
3202 psta->no_ht_gf_set = 1;
3203 pmlmepriv->num_sta_ht_no_gf++;
3205 RTW_INFO("%s STA " MAC_FMT " - no "
3206 "greenfield, num of non-gf stations %d\n",
3207 __FUNCTION__, MAC_ARG(psta->hwaddr),
3208 pmlmepriv->num_sta_ht_no_gf);
3211 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
3212 if (!psta->ht_20mhz_set) {
3213 psta->ht_20mhz_set = 1;
3214 pmlmepriv->num_sta_ht_20mhz++;
3216 RTW_INFO("%s STA " MAC_FMT " - 20 MHz HT, "
3217 "num of 20MHz HT STAs %d\n",
3218 __FUNCTION__, MAC_ARG(psta->hwaddr),
3219 pmlmepriv->num_sta_ht_20mhz);
3223 if (ht_capab & RTW_IEEE80211_HT_CAP_40MHZ_INTOLERANT) {
3225 if (!psta->ht_40mhz_intolerant) {
3226 psta->ht_40mhz_intolerant = 1;
3227 pmlmepriv->num_sta_40mhz_intolerant++;
3228 RTW_INFO("%s STA " MAC_FMT " - HT_CAP_40MHZ_INTOLERANT is set\n" ,
3229 __FUNCTION__, MAC_ARG(psta->hwaddr));
3230 beacon_updated = _TRUE;
3234 if (pmlmepriv->ht_40mhz_intolerant == _FALSE) {
3236 pmlmepriv->ht_40mhz_intolerant = _TRUE;
3238 RTW_INFO("%s STA " MAC_FMT " - HT_CAP_40MHZ_INTOLERANT is set\n" ,
3239 __FUNCTION__, MAC_ARG(psta->hwaddr));
3241 beacon_updated = _TRUE;
3245 /*update ext_capab_ie_len & ext_capab_ie_data for beacon, probersp, assocrsp.*/
3246 if (pmlmepriv->ext_capab_ie_len == 0)
3247 pmlmepriv->ext_capab_ie_len = 1;
3248 SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 1);
3250 update_beacon(padapter, _EXT_CAP_IE_, NULL, _FALSE);
3254 if (!psta->no_ht_set) {
3255 psta->no_ht_set = 1;
3256 pmlmepriv->num_sta_no_ht++;
3258 if (pmlmepriv->htpriv.ht_option == _TRUE) {
3259 RTW_INFO("%s STA " MAC_FMT
3260 " - no HT, num of non-HT stations %d\n",
3261 __FUNCTION__, MAC_ARG(psta->hwaddr),
3262 pmlmepriv->num_sta_no_ht);
3266 if (rtw_ht_operation_update(padapter) > 0) {
3267 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
3268 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
3269 /*beacon_updated = _TRUE;*/
3272 #endif /* CONFIG_80211N_HT */
3274 /* update associcated stations cap. */
3275 associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL);
3277 RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3281 u8 bss_cap_update_on_sta_leave(_adapter *padapter, struct sta_info *psta)
3283 u8 beacon_updated = _FALSE;
3284 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3285 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3288 return beacon_updated;
3290 if (psta->no_short_preamble_set) {
3291 psta->no_short_preamble_set = 0;
3292 pmlmepriv->num_sta_no_short_preamble--;
3293 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
3294 && pmlmepriv->num_sta_no_short_preamble == 0) {
3295 beacon_updated = _TRUE;
3296 update_beacon(padapter, 0xFF, NULL, _TRUE);
3300 if (psta->nonerp_set) {
3301 psta->nonerp_set = 0;
3302 pmlmepriv->num_sta_non_erp--;
3303 if (pmlmepriv->num_sta_non_erp == 0) {
3304 beacon_updated = _TRUE;
3305 update_beacon(padapter, _ERPINFO_IE_, NULL, _TRUE);
3309 if (psta->no_short_slot_time_set) {
3310 psta->no_short_slot_time_set = 0;
3311 pmlmepriv->num_sta_no_short_slot_time--;
3312 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
3313 && pmlmepriv->num_sta_no_short_slot_time == 0) {
3314 beacon_updated = _TRUE;
3315 update_beacon(padapter, 0xFF, NULL, _TRUE);
3319 #ifdef CONFIG_80211N_HT
3321 if (psta->no_ht_gf_set) {
3322 psta->no_ht_gf_set = 0;
3323 pmlmepriv->num_sta_ht_no_gf--;
3326 if (psta->no_ht_set) {
3327 psta->no_ht_set = 0;
3328 pmlmepriv->num_sta_no_ht--;
3331 if (psta->ht_20mhz_set) {
3332 psta->ht_20mhz_set = 0;
3333 pmlmepriv->num_sta_ht_20mhz--;
3336 if (psta->ht_40mhz_intolerant) {
3337 psta->ht_40mhz_intolerant = 0;
3338 pmlmepriv->num_sta_40mhz_intolerant--;
3340 /*update ext_capab_ie_len & ext_capab_ie_data for beacon, probersp, assocrsp.*/
3341 if ((pmlmepriv->ext_capab_ie_len > 0) && (pmlmepriv->num_sta_40mhz_intolerant == 0)) {
3342 SET_EXT_CAPABILITY_ELE_BSS_COEXIST(pmlmepriv->ext_capab_ie_data, 0);
3343 update_beacon(padapter, _EXT_CAP_IE_, NULL, _FALSE);
3346 beacon_updated = _TRUE;
3348 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _FALSE);
3351 if (rtw_ht_operation_update(padapter) > 0) {
3352 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, _FALSE);
3353 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, _TRUE);
3356 #endif /* CONFIG_80211N_HT */
3359 /* update associated stations cap. */
3360 associated_clients_update(padapter, beacon_updated, STA_INFO_UPDATE_ALL); /* move it to avoid deadlock */
3363 RTW_INFO("%s, updated=%d\n", __func__, beacon_updated);
3365 return beacon_updated;
3369 u8 ap_free_sta(_adapter *padapter, struct sta_info *psta, bool active, u16 reason, bool enqueue)
3372 u8 beacon_updated = _FALSE;
3373 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3374 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3375 struct sta_priv *pstapriv = &padapter->stapriv;
3378 return beacon_updated;
3380 if (active == _TRUE) {
3381 #ifdef CONFIG_80211N_HT
3382 /* tear down Rx AMPDU */
3383 send_delba(padapter, 0, psta->hwaddr);/* recipient */
3385 /* tear down TX AMPDU */
3386 send_delba(padapter, 1, psta->hwaddr);/* */ /* originator */
3388 #endif /* CONFIG_80211N_HT */
3390 issue_deauth(padapter, psta->hwaddr, reason);
3393 #ifdef CONFIG_BEAMFORMING
3394 beamforming_wk_cmd(padapter, BEAMFORMING_CTRL_LEAVE, psta->hwaddr, ETH_ALEN, 1);
3397 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
3398 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
3400 /* clear cam entry / key */
3401 rtw_clearstakey_cmd(padapter, psta, enqueue);
3404 _enter_critical_bh(&psta->lock, &irqL);
3405 psta->state &= ~_FW_LINKED;
3406 _exit_critical_bh(&psta->lock, &irqL);
3408 #ifdef CONFIG_IOCTL_CFG80211
3410 #ifdef COMPAT_KERNEL_RELEASE
3411 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
3412 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
3413 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
3414 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3415 /* will call rtw_cfg80211_indicate_sta_disassoc() in cmd_thread for old API context */
3416 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER) */
3418 #endif /* CONFIG_IOCTL_CFG80211 */
3420 rtw_indicate_sta_disassoc_event(padapter, psta);
3423 report_del_sta_event(padapter, psta->hwaddr, reason, enqueue, _FALSE);
3425 beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
3427 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3428 rtw_free_stainfo(padapter, psta);
3429 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3432 return beacon_updated;
3436 int rtw_ap_inform_ch_switch(_adapter *padapter, u8 new_ch, u8 ch_offset)
3439 _list *phead, *plist;
3441 struct sta_info *psta = NULL;
3442 struct sta_priv *pstapriv = &padapter->stapriv;
3443 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3444 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3445 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3447 if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
3450 RTW_INFO(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
3451 FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
3453 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3454 phead = &pstapriv->asoc_list;
3455 plist = get_next(phead);
3457 /* for each sta in asoc_queue */
3458 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3459 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3460 plist = get_next(plist);
3462 issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
3463 psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
3465 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3467 issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
3472 int rtw_sta_flush(_adapter *padapter, bool enqueue)
3475 _list *phead, *plist;
3477 struct sta_info *psta = NULL;
3478 struct sta_priv *pstapriv = &padapter->stapriv;
3479 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3480 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3481 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3483 char flush_list[NUM_STA];
3486 if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
3489 RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
3491 /* pick sta from sta asoc_queue */
3492 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3493 phead = &pstapriv->asoc_list;
3494 plist = get_next(phead);
3495 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3498 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3499 plist = get_next(plist);
3501 rtw_list_delete(&psta->asoc_list);
3502 pstapriv->asoc_list_cnt--;
3504 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
3505 if (stainfo_offset_valid(stainfo_offset))
3506 flush_list[flush_num++] = stainfo_offset;
3510 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3512 /* call ap_free_sta() for each sta picked */
3513 for (i = 0; i < flush_num; i++) {
3514 psta = rtw_get_stainfo_by_offset(pstapriv, flush_list[i]);
3515 ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, enqueue);
3518 issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
3520 associated_clients_update(padapter, _TRUE, STA_INFO_UPDATE_ALL);
3525 /* called > TSR LEVEL for USB or SDIO Interface*/
3526 void sta_info_update(_adapter *padapter, struct sta_info *psta)
3528 int flags = psta->flags;
3529 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3532 /* update wmm cap. */
3533 if (WLAN_STA_WME & flags)
3534 psta->qos_option = 1;
3536 psta->qos_option = 0;
3538 if (pmlmepriv->qospriv.qos_option == 0)
3539 psta->qos_option = 0;
3542 #ifdef CONFIG_80211N_HT
3543 /* update 802.11n ht cap. */
3544 if (WLAN_STA_HT & flags) {
3545 psta->htpriv.ht_option = _TRUE;
3546 psta->qos_option = 1;
3548 psta->htpriv.smps_cap = (psta->htpriv.ht_cap.cap_info & IEEE80211_HT_CAP_SM_PS) >> 2;
3550 psta->htpriv.ht_option = _FALSE;
3552 if (pmlmepriv->htpriv.ht_option == _FALSE)
3553 psta->htpriv.ht_option = _FALSE;
3556 #ifdef CONFIG_80211AC_VHT
3557 /* update 802.11AC vht cap. */
3558 if (WLAN_STA_VHT & flags)
3559 psta->vhtpriv.vht_option = _TRUE;
3561 psta->vhtpriv.vht_option = _FALSE;
3563 if (pmlmepriv->vhtpriv.vht_option == _FALSE)
3564 psta->vhtpriv.vht_option = _FALSE;
3568 update_sta_info_apmode(padapter, psta);
3573 /* called >= TSR LEVEL for USB or SDIO Interface*/
3574 void ap_sta_info_defer_update(_adapter *padapter, struct sta_info *psta)
3576 if (psta->state & _FW_LINKED) {
3578 add_RATid(padapter, psta, 0);/* DM_RATR_STA_INIT */
3581 /* restore hw setting from sw data structures */
3582 void rtw_ap_restore_network(_adapter *padapter)
3584 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
3585 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3586 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3587 struct sta_priv *pstapriv = &padapter->stapriv;
3588 struct sta_info *psta;
3589 struct security_priv *psecuritypriv = &(padapter->securitypriv);
3591 _list *phead, *plist;
3592 u8 chk_alive_num = 0;
3593 char chk_alive_list[NUM_STA];
3596 rtw_setopmode_cmd(padapter, Ndis802_11APMode, _FALSE);
3598 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
3600 rtw_startbss_cmd(padapter, RTW_CMDF_DIRECTLY);
3602 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
3603 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
3604 /* restore group key, WEP keys is restored in ips_leave() */
3605 rtw_set_key(padapter, psecuritypriv, psecuritypriv->dot118021XGrpKeyid, 0, _FALSE);
3608 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3610 phead = &pstapriv->asoc_list;
3611 plist = get_next(phead);
3613 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
3616 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
3617 plist = get_next(plist);
3619 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
3620 if (stainfo_offset_valid(stainfo_offset))
3621 chk_alive_list[chk_alive_num++] = stainfo_offset;
3624 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
3626 for (i = 0; i < chk_alive_num; i++) {
3627 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
3630 RTW_INFO(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
3631 else if (psta->state & _FW_LINKED) {
3632 rtw_sta_media_status_rpt(padapter, psta, 1);
3633 Update_RA_Entry(padapter, psta);
3635 /* per sta pairwise key and settings */
3636 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
3637 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_))
3638 rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _FALSE);
3644 void start_ap_mode(_adapter *padapter)
3647 struct sta_info *psta = NULL;
3648 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3649 struct sta_priv *pstapriv = &padapter->stapriv;
3650 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3651 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3652 struct security_priv *psecuritypriv = &padapter->securitypriv;
3654 pmlmepriv->update_bcn = _FALSE;
3656 /*init_mlme_ap_info(padapter);*/
3658 pmlmeext->bstart_bss = _FALSE;
3660 pmlmepriv->num_sta_non_erp = 0;
3662 pmlmepriv->num_sta_no_short_slot_time = 0;
3664 pmlmepriv->num_sta_no_short_preamble = 0;
3666 pmlmepriv->num_sta_ht_no_gf = 0;
3667 #ifdef CONFIG_80211N_HT
3668 pmlmepriv->num_sta_no_ht = 0;
3669 #endif /* CONFIG_80211N_HT */
3670 pmlmeinfo->HT_info_enable = 0;
3671 pmlmeinfo->HT_caps_enable = 0;
3672 pmlmeinfo->HT_enable = 0;
3674 pmlmepriv->num_sta_ht_20mhz = 0;
3675 pmlmepriv->num_sta_40mhz_intolerant = 0;
3676 pmlmepriv->olbc = _FALSE;
3677 pmlmepriv->olbc_ht = _FALSE;
3679 #ifdef CONFIG_80211N_HT
3680 pmlmepriv->ht_20mhz_width_req = _FALSE;
3681 pmlmepriv->ht_intolerant_ch_reported = _FALSE;
3682 pmlmepriv->ht_op_mode = 0;
3683 pmlmepriv->sw_to_20mhz = 0;
3686 _rtw_memset(pmlmepriv->ext_capab_ie_data, 0, sizeof(pmlmepriv->ext_capab_ie_data));
3687 pmlmepriv->ext_capab_ie_len = 0;
3689 #ifdef CONFIG_CONCURRENT_MODE
3690 psecuritypriv->dot118021x_bmc_cam_id = INVALID_SEC_MAC_CAM_ID;
3693 for (i = 0 ; i < NUM_STA ; i++)
3694 pstapriv->sta_aid[i] = NULL;
3696 #if CONFIG_RTW_MACADDR_ACL
3697 rtw_macaddr_acl_init(padapter);
3700 psta = rtw_get_bcmc_stainfo(padapter);
3701 /*_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3703 rtw_free_stainfo(padapter, psta);
3704 /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3706 rtw_init_bcmc_stainfo(padapter);
3708 if (rtw_mi_get_ap_num(padapter))
3709 RTW_SET_SCAN_BAND_SKIP(padapter, BAND_5G);
3713 void stop_ap_mode(_adapter *padapter)
3716 struct sta_info *psta = NULL;
3717 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3718 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3719 struct dvobj_priv *pdvobj = padapter->dvobj;
3721 RTW_INFO("%s -"ADPT_FMT"\n", __func__, ADPT_ARG(padapter));
3723 pmlmepriv->update_bcn = _FALSE;
3724 /*pmlmeext->bstart_bss = _FALSE;*/
3725 padapter->netif_up = _FALSE;
3726 /* _rtw_spinlock_free(&pmlmepriv->bcn_update_lock); */
3728 /* reset and init security priv , this can refine with rtw_reset_securitypriv */
3729 _rtw_memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
3730 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
3731 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
3733 #ifdef CONFIG_DFS_MASTER
3734 rtw_dfs_master_status_apply(padapter, MLME_AP_STOPPED);
3737 /* free scan queue */
3738 rtw_free_network_queue(padapter, _TRUE);
3740 #if CONFIG_RTW_MACADDR_ACL
3741 rtw_macaddr_acl_deinit(padapter);
3744 rtw_sta_flush(padapter, _TRUE);
3746 /* free_assoc_sta_resources */
3747 rtw_free_all_stainfo(padapter);
3749 psta = rtw_get_bcmc_stainfo(padapter);
3750 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
3751 rtw_free_stainfo(padapter, psta);
3752 /*_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);*/
3754 rtw_free_mlme_priv_ie_data(pmlmepriv);
3756 #ifdef CONFIG_SWTIMER_BASED_TXBCN
3757 if (pmlmeext->bstart_bss == _TRUE) {
3758 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
3760 if (pdvobj->nr_ap_if > 0)
3761 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL / pdvobj->nr_ap_if;
3763 pdvobj->inter_bcn_space = DEFAULT_BCN_INTERVAL;
3765 rtw_list_delete(&padapter->list);
3766 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
3768 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pdvobj->inter_bcn_space));
3770 if (pdvobj->nr_ap_if == 0)
3771 _cancel_timer_ex(&pdvobj->txbcn_timer);
3775 pmlmeext->bstart_bss = _FALSE;
3777 #ifdef CONFIG_BT_COEXIST
3778 rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
3783 #endif /* CONFIG_NATIVEAP_MLME */
3785 void rtw_ap_update_bss_chbw(_adapter *adapter, WLAN_BSSID_EX *bss, u8 ch, u8 bw, u8 offset)
3787 #define UPDATE_VHT_CAP 1
3788 #define UPDATE_HT_CAP 1
3790 #ifdef CONFIG_80211AC_VHT
3792 struct vht_priv *vhtpriv = &adapter->mlmepriv.vhtpriv;
3793 u8 *vht_cap_ie, *vht_op_ie;
3794 int vht_cap_ielen, vht_op_ielen;
3797 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)));
3798 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)));
3799 center_freq = rtw_get_center_ch(ch, bw, offset);
3801 /* update vht cap ie */
3802 if (vht_cap_ie && vht_cap_ielen) {
3804 /* if ((bw == CHANNEL_WIDTH_160 || bw == CHANNEL_WIDTH_80_80) && pvhtpriv->sgi_160m)
3805 SET_VHT_CAPABILITY_ELE_SHORT_GI160M(pvht_cap_ie + 2, 1);
3807 SET_VHT_CAPABILITY_ELE_SHORT_GI160M(vht_cap_ie + 2, 0);
3809 if (bw >= CHANNEL_WIDTH_80 && vhtpriv->sgi_80m)
3810 SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 1);
3812 SET_VHT_CAPABILITY_ELE_SHORT_GI80M(vht_cap_ie + 2, 0);
3816 /* update vht op ie */
3817 if (vht_op_ie && vht_op_ielen) {
3818 if (bw < CHANNEL_WIDTH_80) {
3819 SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 0);
3820 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, 0);
3821 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
3822 } else if (bw == CHANNEL_WIDTH_80) {
3823 SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2, 1);
3824 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op_ie + 2, center_freq);
3825 SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op_ie + 2, 0);
3827 RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
3832 #endif /* CONFIG_80211AC_VHT */
3833 #ifdef CONFIG_80211N_HT
3835 struct ht_priv *htpriv = &adapter->mlmepriv.htpriv;
3836 u8 *ht_cap_ie, *ht_op_ie;
3837 int ht_cap_ielen, ht_op_ielen;
3839 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)));
3840 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)));
3842 /* update ht cap ie */
3843 if (ht_cap_ie && ht_cap_ielen) {
3845 if (bw >= CHANNEL_WIDTH_40)
3846 SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 1);
3848 SET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2, 0);
3850 if (bw >= CHANNEL_WIDTH_40 && htpriv->sgi_40m)
3851 SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 1);
3853 SET_HT_CAP_ELE_SHORT_GI40M(ht_cap_ie + 2, 0);
3855 if (htpriv->sgi_20m)
3856 SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 1);
3858 SET_HT_CAP_ELE_SHORT_GI20M(ht_cap_ie + 2, 0);
3862 /* update ht op ie */
3863 if (ht_op_ie && ht_op_ielen) {
3864 SET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2, ch);
3866 case HAL_PRIME_CHNL_OFFSET_LOWER:
3867 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCA);
3869 case HAL_PRIME_CHNL_OFFSET_UPPER:
3870 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCB);
3872 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
3874 SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2, SCN);
3878 if (bw >= CHANNEL_WIDTH_40)
3879 SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 1);
3881 SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2, 0);
3884 #endif /* CONFIG_80211N_HT */
3889 u8 old_ch = bss->Configuration.DSConfig;
3890 bool change_band = _FALSE;
3892 if ((ch <= 14 && old_ch >= 36) || (ch >= 36 && old_ch <= 14))
3893 change_band = _TRUE;
3895 /* update channel in IE */
3896 p = rtw_get_ie((bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)), _DSSET_IE_, &ie_len, (bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)));
3897 if (p && ie_len > 0)
3900 bss->Configuration.DSConfig = ch;
3902 /* band is changed, update ERP, support rate, ext support rate IE */
3903 if (change_band == _TRUE)
3904 change_band_update_ie(adapter, bss, ch);
3909 bool rtw_ap_chbw_decision(_adapter *adapter, s16 req_ch, s8 req_bw, s8 req_offset
3910 , u8 *ch, u8 *bw, u8 *offset, u8 *chbw_allow)
3912 u8 cur_ie_ch, cur_ie_bw, cur_ie_offset;
3913 u8 dec_ch, dec_bw, dec_offset;
3914 u8 u_ch = 0, u_offset, u_bw;
3915 bool changed = _FALSE;
3916 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3917 WLAN_BSSID_EX *network = &(adapter->mlmepriv.cur_network.network);
3923 bool set_u_ch = _FALSE, set_dec_ch = _FALSE;
3925 rtw_ies_get_chbw(network->IEs + sizeof(NDIS_802_11_FIXED_IEs)
3926 , network->IELength - sizeof(NDIS_802_11_FIXED_IEs)
3927 , &cur_ie_ch, &cur_ie_bw, &cur_ie_offset);
3929 /* use chbw of cur_ie updated with specifying req as temporary decision */
3930 dec_ch = (req_ch <= 0) ? cur_ie_ch : req_ch;
3931 dec_bw = (req_bw < 0) ? cur_ie_bw : req_bw;
3932 dec_offset = (req_offset < 0) ? cur_ie_offset : req_offset;
3934 rtw_mi_status_no_self(adapter, &sta_num, &ld_sta_num, &lg_sta_num, &ap_num, &ld_ap_num, NULL);
3935 RTW_INFO(FUNC_ADPT_FMT" ld_sta_num:%u, lg_sta_num%u, ap_num:%u\n"
3936 , FUNC_ADPT_ARG(adapter), ld_sta_num, lg_sta_num, ap_num);
3938 if (ld_sta_num || ap_num) {
3939 /* has linked STA or AP mode, follow */
3941 rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
3943 RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
3944 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
3946 rtw_adjust_chbw(adapter, u_ch, &dec_bw, &dec_offset);
3947 #ifdef CONFIG_MCC_MODE
3948 if (MCC_EN(adapter)) {
3949 if (!rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
3950 mlmeext->cur_channel = *ch = dec_ch;
3951 mlmeext->cur_bwmode = *bw = dec_bw;
3952 mlmeext->cur_ch_offset = *offset = dec_offset;
3953 /* channel bw offset can not be allowed, need MCC */
3954 *chbw_allow = _FALSE;
3955 RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
3956 , *ch, *bw, *offset);
3959 /* channel bw offset can be allowed, not need MCC */
3960 *chbw_allow = _TRUE;
3962 #endif /* CONFIG_MCC_MODE */
3963 rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
3964 , &u_ch, &u_bw, &u_offset);
3966 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
3967 , dec_ch, dec_bw, dec_offset);
3970 } else if (lg_sta_num) {
3971 /* has linking STA */
3973 rtw_warn_on(!rtw_mi_get_ch_setting_union_no_self(adapter, &u_ch, &u_bw, &u_offset));
3975 RTW_INFO(FUNC_ADPT_FMT" union no self: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
3976 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
3978 rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
3980 if (rtw_is_chbw_grouped(u_ch, u_bw, u_offset, dec_ch, dec_bw, dec_offset)) {
3982 rtw_sync_chbw(&dec_ch, &dec_bw, &dec_offset
3983 , &u_ch, &u_bw, &u_offset);
3985 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
3986 , dec_ch, dec_bw, dec_offset);
3990 /* channel bw offset can be allowed, not need MCC */
3991 *chbw_allow = _TRUE;
3993 #ifdef CONFIG_MCC_MODE
3994 if (MCC_EN(adapter)) {
3995 mlmeext->cur_channel = *ch = dec_ch;
3996 mlmeext->cur_bwmode = *bw = dec_bw;
3997 mlmeext->cur_ch_offset = *offset = dec_offset;
3999 /* channel bw offset can not be allowed, need MCC */
4000 *chbw_allow = _FALSE;
4001 RTW_INFO(FUNC_ADPT_FMT" enable mcc: %u,%u,%u\n", FUNC_ADPT_ARG(adapter)
4002 , *ch, *bw, *offset);
4005 #endif /* CONFIG_MCC_MODE */
4006 /* set this for possible ch change when join down*/
4007 set_fwstate(&adapter->mlmepriv, WIFI_OP_CH_SWITCHING);
4010 /* single AP mode */
4012 RTW_INFO(FUNC_ADPT_FMT" req: %d,%d,%d\n", FUNC_ADPT_ARG(adapter), req_ch, req_bw, req_offset);
4014 /* check temporary decision first */
4015 rtw_adjust_chbw(adapter, dec_ch, &dec_bw, &dec_offset);
4016 if (!rtw_get_offset_by_chbw(dec_ch, dec_bw, &dec_offset)) {
4017 #if defined(CONFIG_DFS_MASTER)
4018 if (req_ch == -1 || req_bw == -1)
4021 RTW_WARN(FUNC_ADPT_FMT" req: %u,%u has no valid offset\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw);
4022 *chbw_allow = _FALSE;
4026 if (!rtw_chset_is_chbw_valid(mlmeext->channel_set, dec_ch, dec_bw, dec_offset)) {
4027 #if defined(CONFIG_DFS_MASTER)
4028 if (req_ch == -1 || req_bw == -1)
4031 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);
4032 *chbw_allow = _FALSE;
4036 if (rtw_chset_is_ch_non_ocp(mlmeext->channel_set, dec_ch, dec_bw, dec_offset) == _FALSE)
4037 goto update_bss_chbw;
4043 #if defined(CONFIG_DFS_MASTER)
4044 /* choose 5G DFS channel for debug */
4045 if (adapter_to_rfctl(adapter)->dbg_dfs_master_choose_dfs_ch_first
4046 && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, RTW_CHF_2G | RTW_CHF_NON_DFS) == _TRUE)
4047 RTW_INFO(FUNC_ADPT_FMT" choose 5G DFS channel for debug\n", FUNC_ADPT_ARG(adapter));
4048 else if (adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags
4049 && rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, adapter_to_rfctl(adapter)->dfs_ch_sel_d_flags) == _TRUE)
4050 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);
4051 else if (rtw_choose_shortest_waiting_ch(adapter, req_bw, &dec_ch, &dec_bw, &dec_offset, 0) == _FALSE) {
4052 RTW_WARN(FUNC_ADPT_FMT" no available channel\n", FUNC_ADPT_ARG(adapter));
4053 *chbw_allow = _FALSE;
4056 #endif /* defined(CONFIG_DFS_MASTER) */
4059 rtw_ap_update_bss_chbw(adapter, &(adapter->mlmepriv.cur_network.network)
4060 , dec_ch, dec_bw, dec_offset);
4062 /* channel bw offset can be allowed for single AP, not need MCC */
4063 *chbw_allow = _TRUE;
4067 if (rtw_mi_check_fwstate(adapter, _FW_UNDER_SURVEY)) {
4068 /* scanning, leave ch setting to scan state machine */
4069 set_u_ch = set_dec_ch = _FALSE;
4072 if (mlmeext->cur_channel != dec_ch
4073 || mlmeext->cur_bwmode != dec_bw
4074 || mlmeext->cur_ch_offset != dec_offset)
4077 if (changed == _TRUE && rtw_linked_check(adapter) == _TRUE) {
4078 #ifdef CONFIG_SPCT_CH_SWITCH
4080 rtw_ap_inform_ch_switch(adapter, dec_ch, dec_offset);
4083 rtw_sta_flush(adapter, _FALSE);
4086 mlmeext->cur_channel = dec_ch;
4087 mlmeext->cur_bwmode = dec_bw;
4088 mlmeext->cur_ch_offset = dec_offset;
4091 RTW_INFO(FUNC_ADPT_FMT" union: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), u_ch, u_bw, u_offset);
4093 RTW_INFO(FUNC_ADPT_FMT" dec: %u,%u,%u\n", FUNC_ADPT_ARG(adapter), dec_ch, dec_bw, dec_offset);
4095 if (set_u_ch == _TRUE) {
4099 } else if (set_dec_ch == _TRUE) {
4102 *offset = dec_offset;
4108 /*#define DBG_SWTIMER_BASED_TXBCN*/
4110 #ifdef CONFIG_SWTIMER_BASED_TXBCN
4111 void tx_beacon_handlder(struct dvobj_priv *pdvobj)
4113 #define BEACON_EARLY_TIME 20 /* unit:TU*/
4115 _list *plist, *phead;
4117 u32 bcn_interval_us; /* unit : usec */
4119 u32 cur_tick, time_offset; /* unit : usec */
4120 u32 inter_bcn_space_us; /* unit : usec */
4121 int nr_vap, idx, bcn_idx;
4124 _adapter *padapter = NULL;
4128 /* get first ap mode interface */
4129 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4130 if (rtw_is_list_empty(&pdvobj->ap_if_q.queue) || (pdvobj->nr_ap_if == 0)) {
4131 RTW_INFO("[%s] ERROR: ap_if_q is empty!or nr_ap = %d\n", __func__, pdvobj->nr_ap_if);
4132 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4135 padapter = LIST_CONTAINOR(get_next(&(pdvobj->ap_if_q.queue)), struct _ADAPTER, list);
4136 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4138 if (NULL == padapter) {
4139 RTW_INFO("[%s] ERROR: no any ap interface!\n", __func__);
4144 bcn_interval_us = DEFAULT_BCN_INTERVAL * NET80211_TU_TO_US;
4145 if (0 == bcn_interval_us) {
4146 RTW_INFO("[%s] ERROR: beacon interval = 0\n", __func__);
4151 timestamp[1] = rtw_read32(padapter, 0x560 + 4);
4152 timestamp[0] = rtw_read32(padapter, 0x560);
4153 while (timestamp[1]) {
4154 time = (0xFFFFFFFF % bcn_interval_us + 1) * timestamp[1] + timestamp[0];
4155 timestamp[0] = (u32)time;
4156 timestamp[1] = (u32)(time >> 32);
4158 cur_tick = timestamp[0] % bcn_interval_us;
4161 _enter_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4163 nr_vap = (pdvobj->nr_ap_if - 1);
4165 inter_bcn_space_us = pdvobj->inter_bcn_space * NET80211_TU_TO_US; /* beacon_interval / (nr_vap+1); */
4166 idx = cur_tick / inter_bcn_space_us;
4167 if (idx < nr_vap) /* if (idx < (nr_vap+1))*/
4168 bcn_idx = idx + 1; /* bcn_idx = (idx + 1) % (nr_vap+1);*/
4172 /* to get padapter based on bcn_idx */
4174 phead = get_list_head(&pdvobj->ap_if_q);
4175 plist = get_next(phead);
4176 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
4177 padapter = LIST_CONTAINOR(plist, struct _ADAPTER, list);
4179 plist = get_next(plist);
4186 if ((NULL == padapter) || (i > pdvobj->nr_ap_if)) {
4187 RTW_INFO("[%s] ERROR: nr_ap_if = %d, padapter=%p, bcn_idx=%d, index=%d\n",
4188 __func__, pdvobj->nr_ap_if, padapter, bcn_idx, i);
4189 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4192 #ifdef DBG_SWTIMER_BASED_TXBCN
4193 RTW_INFO("BCN_IDX=%d, cur_tick=%d, padapter=%p\n", bcn_idx, cur_tick, padapter);
4195 if (((idx + 2 == nr_vap + 1) && (idx < nr_vap + 1)) || (0 == bcn_idx)) {
4196 time_offset = bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4197 if ((s32)time_offset < 0)
4198 time_offset += inter_bcn_space_us;
4201 time_offset = (idx + 2) * inter_bcn_space_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4202 if (time_offset > (inter_bcn_space_us + (inter_bcn_space_us >> 1))) {
4203 time_offset -= inter_bcn_space_us;
4208 /*#endif*/ { /* MBSSID */
4209 time_offset = 2 * bcn_interval_us - cur_tick - BEACON_EARLY_TIME * NET80211_TU_TO_US;
4210 if (time_offset > (bcn_interval_us + (bcn_interval_us >> 1))) {
4211 time_offset -= bcn_interval_us;
4215 _exit_critical_bh(&pdvobj->ap_if_q.lock, &irqL);
4217 #ifdef DBG_SWTIMER_BASED_TXBCN
4218 RTW_INFO("set sw bcn timer %d us\n", time_offset);
4220 _set_timer(&pdvobj->txbcn_timer, time_offset / NET80211_TU_TO_US);
4223 #ifdef DBG_SWTIMER_BASED_TXBCN
4224 RTW_INFO("padapter=%p, PORT=%d\n", padapter, padapter->hw_port);
4226 /*update_beacon(padapter, _TIM_IE_, NULL, _FALSE);*/
4227 issue_beacon(padapter, 0);
4231 /* handle any buffered BC/MC frames*/
4232 /* Don't dynamically change DIS_ATIM due to HW will auto send ACQ after HIQ empty.*/
4233 val8 = *((unsigned char *)priv->beaconbuf + priv->timoffset + 4);
4235 process_mcast_dzqueue(priv);
4236 priv->pkt_in_dtimQ = 0;
4242 void tx_beacon_timer_handlder(struct dvobj_priv *pdvobj)
4244 _adapter *padapter = pdvobj->padapters[0];
4247 set_tx_beacon_cmd(padapter);
4251 #endif /* CONFIG_AP_MODE */