root/drivers/staging/rtl8188eu/core/rtw_ap.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. init_mlme_ap_info
  2. free_mlme_ap_info
  3. update_BCNTIM
  4. chk_sta_is_alive
  5. expire_timeout_chk
  6. add_RATid
  7. update_bmc_sta
  8. update_sta_info_apmode
  9. update_hw_ht_param
  10. start_bss_network
  11. rtw_check_beacon_data
  12. rtw_set_macaddr_acl
  13. rtw_acl_add_sta
  14. rtw_acl_remove_sta
  15. update_bcn_erpinfo_ie
  16. update_bcn_wps_ie
  17. update_bcn_vendor_spec_ie
  18. update_beacon
  19. rtw_ht_operation_update
  20. associated_clients_update
  21. bss_cap_update_on_sta_join
  22. bss_cap_update_on_sta_leave
  23. ap_free_sta
  24. rtw_sta_flush
  25. sta_info_update
  26. ap_sta_info_defer_update
  27. start_ap_mode
  28. stop_ap_mode

   1 // SPDX-License-Identifier: GPL-2.0
   2 /******************************************************************************
   3  *
   4  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
   5  *
   6  ******************************************************************************/
   7 #define _RTW_AP_C_
   8 
   9 #include <linux/ieee80211.h>
  10 
  11 #include <osdep_service.h>
  12 #include <drv_types.h>
  13 #include <wifi.h>
  14 #include <ieee80211.h>
  15 #include <asm/unaligned.h>
  16 
  17 #ifdef CONFIG_88EU_AP_MODE
  18 
  19 void init_mlme_ap_info(struct adapter *padapter)
  20 {
  21         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  22         struct sta_priv *pstapriv = &padapter->stapriv;
  23         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  24 
  25         spin_lock_init(&pmlmepriv->bcn_update_lock);
  26 
  27         /* for ACL */
  28         _rtw_init_queue(&pacl_list->acl_node_q);
  29 
  30         start_ap_mode(padapter);
  31 }
  32 
  33 void free_mlme_ap_info(struct adapter *padapter)
  34 {
  35         struct sta_info *psta = NULL;
  36         struct sta_priv *pstapriv = &padapter->stapriv;
  37         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  38         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  39         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
  40 
  41         pmlmepriv->update_bcn = false;
  42         pmlmeext->bstart_bss = false;
  43 
  44         rtw_sta_flush(padapter);
  45 
  46         pmlmeinfo->state = _HW_STATE_NOLINK_;
  47 
  48         /* free_assoc_sta_resources */
  49         rtw_free_all_stainfo(padapter);
  50 
  51         /* free bc/mc sta_info */
  52         psta = rtw_get_bcmc_stainfo(padapter);
  53         spin_lock_bh(&pstapriv->sta_hash_lock);
  54         rtw_free_stainfo(padapter, psta);
  55         spin_unlock_bh(&pstapriv->sta_hash_lock);
  56 }
  57 
  58 static void update_BCNTIM(struct adapter *padapter)
  59 {
  60         struct sta_priv *pstapriv = &padapter->stapriv;
  61         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  62         struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  63         struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
  64         unsigned char *pie = pnetwork_mlmeext->ies;
  65         u8 *p, *dst_ie, *premainder_ie = NULL;
  66         u8 *pbackup_remainder_ie = NULL;
  67         uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
  68 
  69         /* update TIM IE */
  70         p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen,
  71                        pnetwork_mlmeext->ie_length - _FIXED_IE_LENGTH_);
  72         if (p && tim_ielen > 0) {
  73                 tim_ielen += 2;
  74                 premainder_ie = p + tim_ielen;
  75                 tim_ie_offset = (int)(p - pie);
  76                 remainder_ielen = pnetwork_mlmeext->ie_length -
  77                                         tim_ie_offset - tim_ielen;
  78                 /* append TIM IE from dst_ie offset */
  79                 dst_ie = p;
  80         } else {
  81                 tim_ielen = 0;
  82 
  83                 /* calculate head_len */
  84                 offset = _FIXED_IE_LENGTH_;
  85                 offset += pnetwork_mlmeext->ssid.ssid_length + 2;
  86 
  87                 /*  get supported rates len */
  88                 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_,
  89                                &tmp_len, (pnetwork_mlmeext->ie_length -
  90                                           _BEACON_IE_OFFSET_));
  91                 if (p)
  92                         offset += tmp_len + 2;
  93 
  94                 /* DS Parameter Set IE, len = 3 */
  95                 offset += 3;
  96 
  97                 premainder_ie = pie + offset;
  98 
  99                 remainder_ielen = pnetwork_mlmeext->ie_length -
 100                                         offset - tim_ielen;
 101 
 102                 /* append TIM IE from offset */
 103                 dst_ie = pie + offset;
 104         }
 105 
 106         if (remainder_ielen > 0) {
 107                 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
 108                 if (pbackup_remainder_ie && premainder_ie)
 109                         memcpy(pbackup_remainder_ie, premainder_ie,
 110                                remainder_ielen);
 111         }
 112         *dst_ie++ = _TIM_IE_;
 113 
 114         if ((pstapriv->tim_bitmap & 0xff00) && (pstapriv->tim_bitmap & 0x00fc))
 115                 tim_ielen = 5;
 116         else
 117                 tim_ielen = 4;
 118 
 119         *dst_ie++ = tim_ielen;
 120 
 121         *dst_ie++ = 0;/* DTIM count */
 122         *dst_ie++ = 1;/* DTIM period */
 123 
 124         if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
 125                 *dst_ie++ = BIT(0);/* bitmap ctrl */
 126         else
 127                 *dst_ie++ = 0;
 128 
 129         if (tim_ielen == 4) {
 130                 *dst_ie++ = pstapriv->tim_bitmap & 0xff;
 131         } else if (tim_ielen == 5) {
 132                 put_unaligned_le16(pstapriv->tim_bitmap, dst_ie);
 133                 dst_ie += 2;
 134         }
 135 
 136         /* copy remainder IE */
 137         if (pbackup_remainder_ie) {
 138                 memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
 139 
 140                 kfree(pbackup_remainder_ie);
 141         }
 142         offset =  (uint)(dst_ie - pie);
 143         pnetwork_mlmeext->ie_length = offset + remainder_ielen;
 144 
 145         set_tx_beacon_cmd(padapter);
 146 }
 147 
 148 static u8 chk_sta_is_alive(struct sta_info *psta)
 149 {
 150         u8 ret = false;
 151 
 152         if ((psta->sta_stats.last_rx_data_pkts +
 153                         psta->sta_stats.last_rx_ctrl_pkts) ==
 154                         (psta->sta_stats.rx_data_pkts +
 155                         psta->sta_stats.rx_ctrl_pkts))
 156                 ;
 157         else
 158                 ret = true;
 159 
 160         sta_update_last_rx_pkts(psta);
 161 
 162         return ret;
 163 }
 164 
 165 void expire_timeout_chk(struct adapter *padapter)
 166 {
 167         struct list_head *phead, *plist;
 168         u8 updated = 0;
 169         struct sta_info *psta = NULL;
 170         struct sta_priv *pstapriv = &padapter->stapriv;
 171         u8 chk_alive_num = 0;
 172         char chk_alive_list[NUM_STA];
 173         int i;
 174 
 175         spin_lock_bh(&pstapriv->auth_list_lock);
 176 
 177         phead = &pstapriv->auth_list;
 178         plist = phead->next;
 179 
 180         /* check auth_queue */
 181         while (phead != plist) {
 182                 psta = container_of(plist, struct sta_info, auth_list);
 183                 plist = plist->next;
 184 
 185                 if (psta->expire_to > 0) {
 186                         psta->expire_to--;
 187                         if (psta->expire_to == 0) {
 188                                 list_del_init(&psta->auth_list);
 189                                 pstapriv->auth_list_cnt--;
 190 
 191                                 DBG_88E("auth expire %6ph\n",
 192                                         psta->hwaddr);
 193 
 194                                 spin_unlock_bh(&pstapriv->auth_list_lock);
 195 
 196                                 spin_lock_bh(&pstapriv->sta_hash_lock);
 197                                 rtw_free_stainfo(padapter, psta);
 198                                 spin_unlock_bh(&pstapriv->sta_hash_lock);
 199 
 200                                 spin_lock_bh(&pstapriv->auth_list_lock);
 201                         }
 202                 }
 203         }
 204         spin_unlock_bh(&pstapriv->auth_list_lock);
 205 
 206         psta = NULL;
 207 
 208         spin_lock_bh(&pstapriv->asoc_list_lock);
 209 
 210         phead = &pstapriv->asoc_list;
 211         plist = phead->next;
 212 
 213         /* check asoc_queue */
 214         while (phead != plist) {
 215                 psta = container_of(plist, struct sta_info, asoc_list);
 216                 plist = plist->next;
 217 
 218                 if (chk_sta_is_alive(psta) || !psta->expire_to) {
 219                         psta->expire_to = pstapriv->expire_to;
 220                         psta->keep_alive_trycnt = 0;
 221                         psta->under_exist_checking = 0;
 222                 } else {
 223                         psta->expire_to--;
 224                 }
 225 
 226                 if (psta->expire_to <= 0) {
 227                         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
 228 
 229                         if (padapter->registrypriv.wifi_spec == 1) {
 230                                 psta->expire_to = pstapriv->expire_to;
 231                                 continue;
 232                         }
 233 
 234                         if (psta->state & WIFI_SLEEP_STATE) {
 235                                 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
 236                                         /* to check if alive by another methods
 237                                          * if station is at ps mode.
 238                                          */
 239                                         psta->expire_to = pstapriv->expire_to;
 240                                         psta->state |= WIFI_STA_ALIVE_CHK_STATE;
 241 
 242                                         /* to update bcn with tim_bitmap
 243                                          * for this station
 244                                          */
 245                                         pstapriv->tim_bitmap |= BIT(psta->aid);
 246                                         update_beacon(padapter, _TIM_IE_, NULL,
 247                                                       false);
 248 
 249                                         if (!pmlmeext->active_keep_alive_check)
 250                                                 continue;
 251                                 }
 252                         }
 253                         if (pmlmeext->active_keep_alive_check) {
 254                                 int stainfo_offset;
 255 
 256                                 stainfo_offset =
 257                                         rtw_stainfo_offset(pstapriv, psta);
 258                                 if (stainfo_offset_valid(stainfo_offset))
 259                                         chk_alive_list[chk_alive_num++] =
 260                                                 stainfo_offset;
 261                                 continue;
 262                         }
 263 
 264                         list_del_init(&psta->asoc_list);
 265                         pstapriv->asoc_list_cnt--;
 266 
 267                         DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
 268                         updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
 269                 } else {
 270                         /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
 271                         if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) &&
 272                             padapter->xmitpriv.free_xmitframe_cnt < (NR_XMITFRAME / pstapriv->asoc_list_cnt / 2)) {
 273                                 DBG_88E("%s sta:%pM, sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__,
 274                                         (psta->hwaddr), psta->sleepq_len,
 275                                         padapter->xmitpriv.free_xmitframe_cnt,
 276                                         pstapriv->asoc_list_cnt);
 277                                 wakeup_sta_to_xmit(padapter, psta);
 278                         }
 279                 }
 280         }
 281 
 282         spin_unlock_bh(&pstapriv->asoc_list_lock);
 283 
 284         if (chk_alive_num) {
 285                 u8 backup_oper_channel = 0;
 286                 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
 287                 /* switch to correct channel of current network  before issue keep-alive frames */
 288                 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
 289                         backup_oper_channel = rtw_get_oper_ch(padapter);
 290                         SelectChannel(padapter, pmlmeext->cur_channel);
 291                 }
 292 
 293                 /* issue null data to check sta alive*/
 294                 for (i = 0; i < chk_alive_num; i++) {
 295                         int ret = _FAIL;
 296 
 297                         psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
 298 
 299                         if (psta->state & WIFI_SLEEP_STATE)
 300                                 ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
 301                         else
 302                                 ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
 303 
 304                         psta->keep_alive_trycnt++;
 305                         if (ret == _SUCCESS) {
 306                                 DBG_88E("asoc check, sta(%pM) is alive\n", (psta->hwaddr));
 307                                 psta->expire_to = pstapriv->expire_to;
 308                                 psta->keep_alive_trycnt = 0;
 309                                 continue;
 310                         } else if (psta->keep_alive_trycnt <= 3) {
 311                                 DBG_88E("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
 312                                 psta->expire_to = 1;
 313                                 continue;
 314                         }
 315 
 316                         psta->keep_alive_trycnt = 0;
 317 
 318                         DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
 319                         spin_lock_bh(&pstapriv->asoc_list_lock);
 320                         list_del_init(&psta->asoc_list);
 321                         pstapriv->asoc_list_cnt--;
 322                         updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
 323                         spin_unlock_bh(&pstapriv->asoc_list_lock);
 324                 }
 325 
 326                 if (backup_oper_channel > 0) /* back to the original operation channel */
 327                         SelectChannel(padapter, backup_oper_channel);
 328         }
 329 
 330         associated_clients_update(padapter, updated);
 331 }
 332 
 333 void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
 334 {
 335         int i;
 336         u32 init_rate = 0;
 337         unsigned char sta_band = 0, raid, shortGIrate = false;
 338         unsigned int tx_ra_bitmap = 0;
 339         struct ht_priv  *psta_ht = NULL;
 340 
 341         if (psta)
 342                 psta_ht = &psta->htpriv;
 343         else
 344                 return;
 345 
 346         if (!(psta->state & _FW_LINKED))
 347                 return;
 348 
 349         /* b/g mode ra_bitmap */
 350         for (i = 0; i < sizeof(psta->bssrateset); i++) {
 351                 if (psta->bssrateset[i])
 352                         tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i] & 0x7f);
 353         }
 354         /* n mode ra_bitmap */
 355         if (psta_ht->ht_option) {
 356                 for (i = 0; i < 8; i++)
 357                         if (psta_ht->ht_cap.mcs.rx_mask[0] & BIT(i))
 358                                 tx_ra_bitmap |= BIT(i + 12);
 359 
 360                 /* max short GI rate */
 361                 shortGIrate = psta_ht->sgi;
 362         }
 363 
 364         if (tx_ra_bitmap & 0xffff000)
 365                 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
 366         else if (tx_ra_bitmap & 0xff0)
 367                 sta_band |= WIRELESS_11G | WIRELESS_11B;
 368         else
 369                 sta_band |= WIRELESS_11B;
 370 
 371         psta->wireless_mode = sta_band;
 372 
 373         raid = networktype_to_raid(sta_band);
 374         init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f;
 375 
 376         if (psta->aid < NUM_STA) {
 377                 u8 arg = 0;
 378 
 379                 arg = psta->mac_id & 0x1f;
 380 
 381                 arg |= BIT(7);/* support entry 2~31 */
 382 
 383                 if (shortGIrate)
 384                         arg |= BIT(5);
 385 
 386                 tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
 387 
 388                 DBG_88E("%s => mac_id:%d , raid:%d , bitmap = 0x%x, arg = 0x%x\n",
 389                         __func__, psta->mac_id, raid, tx_ra_bitmap, arg);
 390 
 391                 /* bitmap[0:27] = tx_rate_bitmap */
 392                 /* bitmap[28:31]= Rate Adaptive id */
 393                 /* arg[0:4] = macid */
 394                 /* arg[5] = Short GI */
 395                 rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, rssi_level);
 396 
 397                 if (shortGIrate)
 398                         init_rate |= BIT(6);
 399 
 400                 /* set ra_id, init_rate */
 401                 psta->raid = raid;
 402                 psta->init_rate = init_rate;
 403 
 404         } else {
 405                 DBG_88E("station aid %d exceed the max number\n", psta->aid);
 406         }
 407 }
 408 
 409 static void update_bmc_sta(struct adapter *padapter)
 410 {
 411         u32 init_rate = 0;
 412         unsigned char   network_type, raid;
 413         int i, supportRateNum = 0;
 414         unsigned int tx_ra_bitmap = 0;
 415         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 416         struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
 417         struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
 418 
 419         if (psta) {
 420                 psta->aid = 0;/* default set to 0 */
 421                 psta->mac_id = psta->aid + 1;
 422 
 423                 psta->qos_option = 0;
 424                 psta->htpriv.ht_option = false;
 425 
 426                 psta->ieee8021x_blocked = 0;
 427 
 428                 memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
 429 
 430                 /* prepare for add_RATid */
 431                 supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
 432                 network_type = rtw_check_network_type((u8 *)&pcur_network->SupportedRates, supportRateNum, 1);
 433 
 434                 memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
 435                 psta->bssratelen = supportRateNum;
 436 
 437                 /* b/g mode ra_bitmap */
 438                 for (i = 0; i < supportRateNum; i++) {
 439                         if (psta->bssrateset[i])
 440                                 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value(psta->bssrateset[i] & 0x7f);
 441                 }
 442 
 443                 if (pcur_network->Configuration.DSConfig > 14) {
 444                         /* force to A mode. 5G doesn't support CCK rates */
 445                         network_type = WIRELESS_11A;
 446                         tx_ra_bitmap = 0x150; /*  6, 12, 24 Mbps */
 447                 } else {
 448                         /* force to b mode */
 449                         network_type = WIRELESS_11B;
 450                         tx_ra_bitmap = 0xf;
 451                 }
 452 
 453                 raid = networktype_to_raid(network_type);
 454                 init_rate = get_highest_rate_idx(tx_ra_bitmap & 0x0fffffff) & 0x3f;
 455 
 456                 /* ap mode */
 457                 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
 458 
 459                 {
 460                         u8 arg = 0;
 461 
 462                         arg = psta->mac_id & 0x1f;
 463                         arg |= BIT(7);
 464                         tx_ra_bitmap |= ((raid << 28) & 0xf0000000);
 465                         DBG_88E("%s, mask = 0x%x, arg = 0x%x\n", __func__, tx_ra_bitmap, arg);
 466 
 467                         /* bitmap[0:27] = tx_rate_bitmap */
 468                         /* bitmap[28:31]= Rate Adaptive id */
 469                         /* arg[0:4] = macid */
 470                         /* arg[5] = Short GI */
 471                         rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, 0);
 472                 }
 473                 /* set ra_id, init_rate */
 474                 psta->raid = raid;
 475                 psta->init_rate = init_rate;
 476 
 477                 rtw_stassoc_hw_rpt(padapter, psta);
 478 
 479                 spin_lock_bh(&psta->lock);
 480                 psta->state = _FW_LINKED;
 481                 spin_unlock_bh(&psta->lock);
 482 
 483         } else {
 484                 DBG_88E("add_RATid_bmc_sta error!\n");
 485         }
 486 }
 487 
 488 /* notes: */
 489 /* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
 490 /* MAC_ID = AID+1 for sta in ap/adhoc mode */
 491 /* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
 492 /* MAC_ID = 0 for bssid for sta/ap/adhoc */
 493 /* CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
 494 
 495 void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta)
 496 {
 497         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 498         struct security_priv *psecuritypriv = &padapter->securitypriv;
 499         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
 500         struct ht_priv  *phtpriv_ap = &pmlmepriv->htpriv;
 501         struct ht_priv  *phtpriv_sta = &psta->htpriv;
 502 
 503         psta->mac_id = psta->aid + 1;
 504         DBG_88E("%s\n", __func__);
 505 
 506         /* ap mode */
 507         rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
 508 
 509         if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
 510                 psta->ieee8021x_blocked = true;
 511         else
 512                 psta->ieee8021x_blocked = false;
 513 
 514         /* update sta's cap */
 515 
 516         /* ERP */
 517         VCS_update(padapter, psta);
 518         /* HT related cap */
 519         if (phtpriv_sta->ht_option) {
 520                 /* check if sta supports rx ampdu */
 521                 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
 522 
 523                 /* check if sta support s Short GI */
 524                 if (le16_to_cpu(phtpriv_sta->ht_cap.cap_info &
 525                                 phtpriv_ap->ht_cap.cap_info) &
 526                     (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40))
 527                         phtpriv_sta->sgi = true;
 528 
 529                 /*  bwmode */
 530                 if (le16_to_cpu(phtpriv_sta->ht_cap.cap_info &
 531                                 phtpriv_ap->ht_cap.cap_info) &
 532                     IEEE80211_HT_CAP_SUP_WIDTH) {
 533                         phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
 534                         phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
 535                 }
 536                 psta->qos_option = true;
 537         } else {
 538                 phtpriv_sta->ampdu_enable = false;
 539                 phtpriv_sta->sgi = false;
 540                 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
 541                 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 542         }
 543 
 544         /* Rx AMPDU */
 545         send_delba(padapter, 0, psta->hwaddr);/*  recipient */
 546 
 547         /* TX AMPDU */
 548         send_delba(padapter, 1, psta->hwaddr);/* originator */
 549         phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
 550         phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
 551 
 552         /* todo: init other variables */
 553 
 554         memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
 555 
 556         spin_lock_bh(&psta->lock);
 557         psta->state |= _FW_LINKED;
 558         spin_unlock_bh(&psta->lock);
 559 }
 560 
 561 static void update_hw_ht_param(struct adapter *padapter)
 562 {
 563         unsigned char           max_AMPDU_len;
 564         unsigned char           min_MPDU_spacing;
 565         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
 566         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
 567 
 568         DBG_88E("%s\n", __func__);
 569 
 570         /* handle A-MPDU parameter field */
 571         /*
 572                 ampdu_params_info [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
 573                 ampdu_params_info [4:2]:Min MPDU Start Spacing
 574         */
 575         max_AMPDU_len = pmlmeinfo->HT_caps.ampdu_params_info & 0x03;
 576 
 577         min_MPDU_spacing = (pmlmeinfo->HT_caps.ampdu_params_info & 0x1c) >> 2;
 578 
 579         rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_MIN_SPACE, (u8 *)(&min_MPDU_spacing));
 580 
 581         rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
 582 
 583         /*  */
 584         /*  Config SM Power Save setting */
 585         /*  */
 586         pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->HT_caps.cap_info) & 0x0C) >> 2;
 587         if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
 588                 DBG_88E("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
 589 }
 590 
 591 static void start_bss_network(struct adapter *padapter, u8 *pbuf)
 592 {
 593         u8 *p;
 594         u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
 595         u16 bcn_interval;
 596         u32     acparm;
 597         uint    ie_len;
 598         struct registry_priv     *pregpriv = &padapter->registrypriv;
 599         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 600         struct security_priv *psecuritypriv = &padapter->securitypriv;
 601         struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
 602         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
 603         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
 604         struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
 605         struct HT_info_element *pht_info = NULL;
 606 
 607         bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
 608         cur_channel = pnetwork->Configuration.DSConfig;
 609         cur_bwmode = HT_CHANNEL_WIDTH_20;
 610         cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 611 
 612         /* check if there is wps ie,
 613          * if there is wpsie in beacon, the hostapd will update
 614          * beacon twice when stating hostapd, and at first time the
 615          * security ie (RSN/WPA IE) will not include in beacon.
 616          */
 617         if (!rtw_get_wps_ie(pnetwork->ies + _FIXED_IE_LENGTH_, pnetwork->ie_length - _FIXED_IE_LENGTH_, NULL, NULL))
 618                 pmlmeext->bstart_bss = true;
 619 
 620         /* todo: update wmm, ht cap */
 621         if (pmlmepriv->qospriv.qos_option)
 622                 pmlmeinfo->WMM_enable = true;
 623         if (pmlmepriv->htpriv.ht_option) {
 624                 pmlmeinfo->WMM_enable = true;
 625                 pmlmeinfo->HT_enable = true;
 626 
 627                 update_hw_ht_param(padapter);
 628         }
 629 
 630         /* setting only at  first time */
 631         if (!pmlmepriv->cur_network.join_res) {
 632                 /* WEP Key will be set before this function, do not
 633                  * clear CAM.
 634                  */
 635                 if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) &&
 636                     (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_))
 637                         flush_all_cam_entry(padapter);  /* clear CAM */
 638         }
 639 
 640         /* set MSR to AP_Mode */
 641         Set_MSR(padapter, _HW_STATE_AP_);
 642 
 643         /* Set BSSID REG */
 644         rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
 645 
 646         /* Set EDCA param reg */
 647         acparm = 0x002F3217; /*  VO */
 648         rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
 649         acparm = 0x005E4317; /*  VI */
 650         rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
 651         acparm = 0x005ea42b;
 652         rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
 653         acparm = 0x0000A444; /*  BK */
 654         rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
 655 
 656         /* Set Security */
 657         val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
 658         rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
 659 
 660         /* Beacon Control related register */
 661         rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
 662 
 663         UpdateBrateTbl(padapter, pnetwork->SupportedRates);
 664         rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
 665 
 666         if (!pmlmepriv->cur_network.join_res) { /* setting only at  first time */
 667                 /* turn on all dynamic functions */
 668                 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
 669         }
 670         /* set channel, bwmode */
 671         p = rtw_get_ie((pnetwork->ies + sizeof(struct ndis_802_11_fixed_ie)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->ie_length - sizeof(struct ndis_802_11_fixed_ie)));
 672         if (p && ie_len) {
 673                 pht_info = (struct HT_info_element *)(p + 2);
 674 
 675                 if ((pregpriv->cbw40_enable) &&  (pht_info->infos[0] & BIT(2))) {
 676                         /* switch to the 40M Hz mode */
 677                         cur_bwmode = HT_CHANNEL_WIDTH_40;
 678                         switch (pht_info->infos[0] & 0x3) {
 679                         case 1:
 680                                 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
 681                                 break;
 682                         case 3:
 683                                 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
 684                                 break;
 685                         default:
 686                                 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 687                                 break;
 688                         }
 689                 }
 690         }
 691         /* TODO: need to judge the phy parameters on concurrent
 692          * mode for single phy
 693          */
 694         set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
 695 
 696         DBG_88E("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode, cur_ch_offset);
 697 
 698         /*  */
 699         pmlmeext->cur_channel = cur_channel;
 700         pmlmeext->cur_bwmode = cur_bwmode;
 701         pmlmeext->cur_ch_offset = cur_ch_offset;
 702         pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
 703 
 704         /* update cur_wireless_mode */
 705         update_wireless_mode(padapter);
 706 
 707         /* update capability after cur_wireless_mode updated */
 708         update_capinfo(padapter, rtw_get_capability((struct wlan_bssid_ex *)pnetwork));
 709 
 710         /* let pnetwork_mlmeext == pnetwork_mlme. */
 711         memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
 712 
 713         if (pmlmeext->bstart_bss) {
 714                 update_beacon(padapter, _TIM_IE_, NULL, false);
 715 
 716                 /* issue beacon frame */
 717                 if (send_beacon(padapter) == _FAIL)
 718                         DBG_88E("send_beacon, fail!\n");
 719         }
 720 
 721         /* update bc/mc sta_info */
 722         update_bmc_sta(padapter);
 723 }
 724 
 725 int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf,  int len)
 726 {
 727         int ret = _SUCCESS;
 728         u8 *p;
 729         u8 *pHT_caps_ie = NULL;
 730         u8 *pHT_info_ie = NULL;
 731         struct sta_info *psta = NULL;
 732         u16 cap, ht_cap = false;
 733         uint ie_len = 0;
 734         int group_cipher, pairwise_cipher;
 735         u8      channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
 736         int supportRateNum = 0;
 737         u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
 738         u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
 739         struct registry_priv *pregistrypriv = &padapter->registrypriv;
 740         struct security_priv *psecuritypriv = &padapter->securitypriv;
 741         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 742         struct wlan_bssid_ex *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
 743         u8 *ie = pbss_network->ies;
 744 
 745         /* SSID */
 746         /* Supported rates */
 747         /* DS Params */
 748         /* WLAN_EID_COUNTRY */
 749         /* ERP Information element */
 750         /* Extended supported rates */
 751         /* WPA/WPA2 */
 752         /* Wi-Fi Wireless Multimedia Extensions */
 753         /* ht_capab, ht_oper */
 754         /* WPS IE */
 755 
 756         DBG_88E("%s, len =%d\n", __func__, len);
 757 
 758         if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
 759                 return _FAIL;
 760 
 761         if (len < 0 || len > MAX_IE_SZ)
 762                 return _FAIL;
 763 
 764         pbss_network->ie_length = len;
 765 
 766         memset(ie, 0, MAX_IE_SZ);
 767 
 768         memcpy(ie, pbuf, pbss_network->ie_length);
 769 
 770         if (pbss_network->InfrastructureMode != Ndis802_11APMode)
 771                 return _FAIL;
 772 
 773         pbss_network->Rssi = 0;
 774 
 775         ether_addr_copy(pbss_network->MacAddress, myid(&padapter->eeprompriv));
 776 
 777         /* beacon interval */
 778         p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
 779         pbss_network->Configuration.BeaconPeriod = get_unaligned_le16(p);
 780 
 781         /* capability */
 782         cap = get_unaligned_le16(ie);
 783 
 784         /* SSID */
 785         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SSID_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 786         if (p && ie_len > 0) {
 787                 memset(&pbss_network->ssid, 0, sizeof(struct ndis_802_11_ssid));
 788                 memcpy(pbss_network->ssid.ssid, (p + 2), ie_len);
 789                 pbss_network->ssid.ssid_length = ie_len;
 790         }
 791 
 792         /* channel */
 793         channel = 0;
 794         pbss_network->Configuration.Length = 0;
 795         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _DSSET_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 796         if (p && ie_len > 0)
 797                 channel = *(p + 2);
 798 
 799         pbss_network->Configuration.DSConfig = channel;
 800 
 801         memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
 802         /*  get supported rates */
 803         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 804         if (p) {
 805                 memcpy(supportRate, p + 2, ie_len);
 806                 supportRateNum = ie_len;
 807         }
 808 
 809         /* get ext_supported rates */
 810         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->ie_length - _BEACON_IE_OFFSET_);
 811         if (p) {
 812                 memcpy(supportRate + supportRateNum, p + 2, ie_len);
 813                 supportRateNum += ie_len;
 814         }
 815 
 816         network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
 817 
 818         rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
 819 
 820         /* parsing ERP_IE */
 821         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 822         if (p && ie_len > 0)
 823                 ERP_IE_handler(padapter, (struct ndis_802_11_var_ie *)p);
 824 
 825         /* update privacy/security */
 826         if (cap & BIT(4))
 827                 pbss_network->Privacy = 1;
 828         else
 829                 pbss_network->Privacy = 0;
 830 
 831         psecuritypriv->wpa_psk = 0;
 832 
 833         /* wpa2 */
 834         group_cipher = 0;
 835         pairwise_cipher = 0;
 836         psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
 837         psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
 838         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 839         if (p && ie_len > 0) {
 840                 if (rtw_parse_wpa2_ie(p, ie_len + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
 841                         psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
 842 
 843                         psecuritypriv->dot8021xalg = 1;/* psk,  todo:802.1x */
 844                         psecuritypriv->wpa_psk |= BIT(1);
 845 
 846                         psecuritypriv->wpa2_group_cipher = group_cipher;
 847                         psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
 848                 }
 849         }
 850         /* wpa */
 851         ie_len = 0;
 852         group_cipher = 0;
 853         pairwise_cipher = 0;
 854         psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
 855         psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
 856         for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) {
 857                 p = rtw_get_ie(p, _SSN_IE_1_, &ie_len,
 858                                (pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2)));
 859                 if ((p) && (!memcmp(p + 2, OUI1, 4))) {
 860                         if (rtw_parse_wpa_ie(p, ie_len + 2, &group_cipher,
 861                                              &pairwise_cipher, NULL) == _SUCCESS) {
 862                                 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
 863 
 864                                 psecuritypriv->dot8021xalg = 1;/* psk,  todo:802.1x */
 865 
 866                                 psecuritypriv->wpa_psk |= BIT(0);
 867 
 868                                 psecuritypriv->wpa_group_cipher = group_cipher;
 869                                 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
 870                         }
 871                         break;
 872                 }
 873                 if ((!p) || (ie_len == 0))
 874                         break;
 875         }
 876 
 877         /* wmm */
 878         ie_len = 0;
 879         pmlmepriv->qospriv.qos_option = 0;
 880         if (pregistrypriv->wmm_enable) {
 881                 for (p = ie + _BEACON_IE_OFFSET_;; p += (ie_len + 2)) {
 882                         p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len,
 883                                        (pbss_network->ie_length - _BEACON_IE_OFFSET_ - (ie_len + 2)));
 884                         if ((p) && !memcmp(p + 2, WMM_PARA_IE, 6)) {
 885                                 pmlmepriv->qospriv.qos_option = 1;
 886 
 887                                 /* QoS Info, support U-APSD */
 888                                 *(p + 8) |= BIT(7);
 889 
 890                                 /* disable all ACM bits since the WMM
 891                                  * admission control is not supported
 892                                  */
 893                                 *(p + 10) &= ~BIT(4); /* BE */
 894                                 *(p + 14) &= ~BIT(4); /* BK */
 895                                 *(p + 18) &= ~BIT(4); /* VI */
 896                                 *(p + 22) &= ~BIT(4); /* VO */
 897                                 break;
 898                         }
 899 
 900                         if ((!p) || (ie_len == 0))
 901                                 break;
 902                 }
 903         }
 904         /* parsing HT_CAP_IE */
 905         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len,
 906                        (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 907         if (p && ie_len > 0) {
 908                 struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p + 2);
 909 
 910                 pHT_caps_ie = p;
 911                 ht_cap = true;
 912                 network_type |= WIRELESS_11_24N;
 913 
 914                 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
 915                     (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
 916                         pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & (0x07 << 2));
 917                 else
 918                         pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
 919 
 920                 /* set  Max Rx AMPDU size  to 64K */
 921                 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_FACTOR & 0x03);
 922 
 923                 pht_cap->mcs.rx_mask[0] = 0xff;
 924                 pht_cap->mcs.rx_mask[1] = 0x0;
 925                 memcpy(&pmlmepriv->htpriv.ht_cap, p + 2, ie_len);
 926         }
 927 
 928         /* parsing HT_INFO_IE */
 929         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len,
 930                        (pbss_network->ie_length - _BEACON_IE_OFFSET_));
 931         if (p && ie_len > 0)
 932                 pHT_info_ie = p;
 933         switch (network_type) {
 934         case WIRELESS_11B:
 935                 pbss_network->NetworkTypeInUse = Ndis802_11DS;
 936                 break;
 937         case WIRELESS_11G:
 938         case WIRELESS_11BG:
 939         case WIRELESS_11G_24N:
 940         case WIRELESS_11BG_24N:
 941                 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
 942                 break;
 943         case WIRELESS_11A:
 944                 pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
 945                 break;
 946         default:
 947                 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
 948                 break;
 949         }
 950 
 951         pmlmepriv->cur_network.network_type = network_type;
 952 
 953         pmlmepriv->htpriv.ht_option = false;
 954 
 955         if ((psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_TKIP) ||
 956             (psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_TKIP)) {
 957                 /* todo: */
 958                 /* ht_cap = false; */
 959         }
 960 
 961         /* ht_cap */
 962         if (pregistrypriv->ht_enable && ht_cap) {
 963                 pmlmepriv->htpriv.ht_option = true;
 964                 pmlmepriv->qospriv.qos_option = 1;
 965 
 966                 if (pregistrypriv->ampdu_enable == 1)
 967                         pmlmepriv->htpriv.ampdu_enable = true;
 968                 HT_caps_handler(padapter, (struct ndis_802_11_var_ie *)pHT_caps_ie);
 969 
 970                 HT_info_handler(padapter, (struct ndis_802_11_var_ie *)pHT_info_ie);
 971         }
 972 
 973         pbss_network->Length = get_wlan_bssid_ex_sz((struct wlan_bssid_ex  *)pbss_network);
 974 
 975         /* issue beacon to start bss network */
 976         start_bss_network(padapter, (u8 *)pbss_network);
 977 
 978         /* alloc sta_info for ap itself */
 979         psta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
 980         if (!psta) {
 981                 psta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
 982                 if (!psta)
 983                         return _FAIL;
 984         }
 985 
 986         /* fix bug of flush_cam_entry at STOP AP mode */
 987         psta->state |= WIFI_AP_STATE;
 988         rtw_indicate_connect(padapter);
 989         pmlmepriv->cur_network.join_res = true;/* for check if already set beacon */
 990         return ret;
 991 }
 992 
 993 void rtw_set_macaddr_acl(struct adapter *padapter, int mode)
 994 {
 995         struct sta_priv *pstapriv = &padapter->stapriv;
 996         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
 997 
 998         DBG_88E("%s, mode =%d\n", __func__, mode);
 999 
1000         pacl_list->mode = mode;
1001 }
1002 
1003 int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1004 {
1005         struct list_head *plist, *phead;
1006         u8 added = false;
1007         int i, ret = 0;
1008         struct rtw_wlan_acl_node *paclnode;
1009         struct sta_priv *pstapriv = &padapter->stapriv;
1010         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1011         struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1012 
1013         DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr));
1014 
1015         if ((NUM_ACL - 1) < pacl_list->num)
1016                 return -1;
1017 
1018         spin_lock_bh(&pacl_node_q->lock);
1019 
1020         phead = get_list_head(pacl_node_q);
1021         plist = phead->next;
1022 
1023         while (phead != plist) {
1024                 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1025                 plist = plist->next;
1026 
1027                 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1028                         if (paclnode->valid) {
1029                                 added = true;
1030                                 DBG_88E("%s, sta has been added\n", __func__);
1031                                 break;
1032                         }
1033                 }
1034         }
1035 
1036         spin_unlock_bh(&pacl_node_q->lock);
1037 
1038         if (added)
1039                 return ret;
1040 
1041         spin_lock_bh(&pacl_node_q->lock);
1042 
1043         for (i = 0; i < NUM_ACL; i++) {
1044                 paclnode = &pacl_list->aclnode[i];
1045 
1046                 if (!paclnode->valid) {
1047                         INIT_LIST_HEAD(&paclnode->list);
1048 
1049                         ether_addr_copy(paclnode->addr, addr);
1050 
1051                         paclnode->valid = true;
1052 
1053                         list_add_tail(&paclnode->list, get_list_head(pacl_node_q));
1054 
1055                         pacl_list->num++;
1056 
1057                         break;
1058                 }
1059         }
1060 
1061         DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1062 
1063         spin_unlock_bh(&pacl_node_q->lock);
1064 
1065         return ret;
1066 }
1067 
1068 int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1069 {
1070         struct list_head *plist, *phead;
1071         struct rtw_wlan_acl_node *paclnode;
1072         struct sta_priv *pstapriv = &padapter->stapriv;
1073         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1074         struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1075 
1076         DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr));
1077 
1078         spin_lock_bh(&pacl_node_q->lock);
1079 
1080         phead = get_list_head(pacl_node_q);
1081         plist = phead->next;
1082 
1083         while (phead != plist) {
1084                 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1085                 plist = plist->next;
1086 
1087                 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1088                         if (paclnode->valid) {
1089                                 paclnode->valid = false;
1090 
1091                                 list_del_init(&paclnode->list);
1092 
1093                                 pacl_list->num--;
1094                         }
1095                 }
1096         }
1097 
1098         spin_unlock_bh(&pacl_node_q->lock);
1099 
1100         DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1101         return 0;
1102 }
1103 
1104 static void update_bcn_erpinfo_ie(struct adapter *padapter)
1105 {
1106         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1107         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
1108         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1109         struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1110         unsigned char *p, *ie = pnetwork->ies;
1111         u32 len = 0;
1112 
1113         DBG_88E("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1114 
1115         if (!pmlmeinfo->ERP_enable)
1116                 return;
1117 
1118         /* parsing ERP_IE */
1119         p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _ERPINFO_IE_, &len,
1120                        (pnetwork->ie_length - _BEACON_IE_OFFSET_));
1121         if (p && len > 0) {
1122                 struct ndis_802_11_var_ie *pIE = (struct ndis_802_11_var_ie *)p;
1123 
1124                 if (pmlmepriv->num_sta_non_erp == 1)
1125                         pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT |
1126                                         RTW_ERP_INFO_USE_PROTECTION;
1127                 else
1128                         pIE->data[0] &= ~(RTW_ERP_INFO_NON_ERP_PRESENT |
1129                                           RTW_ERP_INFO_USE_PROTECTION);
1130 
1131                 if (pmlmepriv->num_sta_no_short_preamble > 0)
1132                         pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
1133                 else
1134                         pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
1135 
1136                 ERP_IE_handler(padapter, pIE);
1137         }
1138 }
1139 
1140 static void update_bcn_wps_ie(struct adapter *padapter)
1141 {
1142         u8 *pwps_ie = NULL, *pwps_ie_src;
1143         u8 *premainder_ie, *pbackup_remainder_ie = NULL;
1144         uint wps_ielen = 0, wps_offset, remainder_ielen;
1145         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1146         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
1147         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1148         struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1149         unsigned char *ie = pnetwork->ies;
1150         u32 ielen = pnetwork->ie_length;
1151 
1152         DBG_88E("%s\n", __func__);
1153 
1154         pwps_ie_src = pmlmepriv->wps_beacon_ie;
1155         if (!pwps_ie_src)
1156                 return;
1157 
1158         pwps_ie = rtw_get_wps_ie(ie + _FIXED_IE_LENGTH_,
1159                                  ielen - _FIXED_IE_LENGTH_, NULL, &wps_ielen);
1160 
1161         if (!pwps_ie || wps_ielen == 0)
1162                 return;
1163 
1164         wps_offset = (uint)(pwps_ie - ie);
1165 
1166         premainder_ie = pwps_ie + wps_ielen;
1167 
1168         remainder_ielen = ielen - wps_offset - wps_ielen;
1169 
1170         if (remainder_ielen > 0) {
1171                 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
1172                 if (pbackup_remainder_ie)
1173                         memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
1174         }
1175 
1176         wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
1177         if (wps_offset + wps_ielen + 2 + remainder_ielen <= MAX_IE_SZ) {
1178                 memcpy(pwps_ie, pwps_ie_src, wps_ielen + 2);
1179                 pwps_ie += wps_ielen + 2;
1180 
1181                 if (pbackup_remainder_ie)
1182                         memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
1183 
1184                 /* update ie_length */
1185                 pnetwork->ie_length = wps_offset + wps_ielen + 2 + remainder_ielen;
1186         }
1187 
1188         kfree(pbackup_remainder_ie);
1189 }
1190 
1191 static void update_bcn_vendor_spec_ie(struct adapter *padapter, u8 *oui)
1192 {
1193         DBG_88E("%s\n", __func__);
1194 
1195         if (!memcmp(WPS_OUI, oui, 4))
1196                 update_bcn_wps_ie(padapter);
1197         else
1198                 DBG_88E("unknown OUI type!\n");
1199 }
1200 
1201 void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1202 {
1203         struct mlme_priv *pmlmepriv;
1204         struct mlme_ext_priv    *pmlmeext;
1205 
1206         if (!padapter)
1207                 return;
1208 
1209         pmlmepriv = &padapter->mlmepriv;
1210         pmlmeext = &padapter->mlmeextpriv;
1211 
1212         if (!pmlmeext->bstart_bss)
1213                 return;
1214 
1215         spin_lock_bh(&pmlmepriv->bcn_update_lock);
1216 
1217         switch (ie_id) {
1218         case _TIM_IE_:
1219                 update_BCNTIM(padapter);
1220                 break;
1221         case _ERPINFO_IE_:
1222                 update_bcn_erpinfo_ie(padapter);
1223                 break;
1224         case _VENDOR_SPECIFIC_IE_:
1225                 update_bcn_vendor_spec_ie(padapter, oui);
1226                 break;
1227         default:
1228                 break;
1229         }
1230 
1231         pmlmepriv->update_bcn = true;
1232 
1233         spin_unlock_bh(&pmlmepriv->bcn_update_lock);
1234 
1235         if (tx)
1236                 set_tx_beacon_cmd(padapter);
1237 }
1238 
1239 /*
1240 op_mode
1241 Set to 0 (HT pure) under the following conditions
1242         - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1243         - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1244 Set to 1 (HT non-member protection) if there may be non-HT STAs
1245         in both the primary and the secondary channel
1246 Set to 2 if only HT STAs are associated in BSS,
1247         however and at least one 20 MHz HT STA is associated
1248 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1249         (currently non-GF HT station is considered as non-HT STA also)
1250 */
1251 static int rtw_ht_operation_update(struct adapter *padapter)
1252 {
1253         u16 cur_op_mode, new_op_mode;
1254         int op_mode_changes = 0;
1255         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1256         struct ht_priv  *phtpriv_ap = &pmlmepriv->htpriv;
1257 
1258         if (pmlmepriv->htpriv.ht_option)
1259                 return 0;
1260 
1261         DBG_88E("%s current operation mode = 0x%X\n",
1262                 __func__, pmlmepriv->ht_op_mode);
1263 
1264         if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
1265             pmlmepriv->num_sta_ht_no_gf) {
1266                 pmlmepriv->ht_op_mode |=
1267                         HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
1268                 op_mode_changes++;
1269         } else if ((pmlmepriv->ht_op_mode &
1270                    HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
1271                    pmlmepriv->num_sta_ht_no_gf == 0) {
1272                 pmlmepriv->ht_op_mode &=
1273                         ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
1274                 op_mode_changes++;
1275         }
1276 
1277         if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
1278             (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
1279                 pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
1280                 op_mode_changes++;
1281         } else if ((pmlmepriv->ht_op_mode &
1282                     HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
1283                    (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
1284                 pmlmepriv->ht_op_mode &=
1285                         ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
1286                 op_mode_changes++;
1287         }
1288 
1289         /* Note: currently we switch to the MIXED op mode if HT non-greenfield
1290          * station is associated. Probably it's a theoretical case, since
1291          * it looks like all known HT STAs support greenfield.
1292          */
1293         new_op_mode = 0;
1294         if (pmlmepriv->num_sta_no_ht ||
1295             (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
1296                 new_op_mode = OP_MODE_MIXED;
1297         else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) &
1298                   IEEE80211_HT_CAP_SUP_WIDTH) &&
1299                  pmlmepriv->num_sta_ht_20mhz)
1300                 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
1301         else if (pmlmepriv->olbc_ht)
1302                 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
1303         else
1304                 new_op_mode = OP_MODE_PURE;
1305 
1306         cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
1307         if (cur_op_mode != new_op_mode) {
1308                 pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
1309                 pmlmepriv->ht_op_mode |= new_op_mode;
1310                 op_mode_changes++;
1311         }
1312 
1313         DBG_88E("%s new operation mode = 0x%X changes =%d\n",
1314                 __func__, pmlmepriv->ht_op_mode, op_mode_changes);
1315 
1316         return op_mode_changes;
1317 }
1318 
1319 void associated_clients_update(struct adapter *padapter, u8 updated)
1320 {
1321         /* update associated stations cap. */
1322         if (updated) {
1323                 struct list_head *phead, *plist;
1324                 struct sta_info *psta = NULL;
1325                 struct sta_priv *pstapriv = &padapter->stapriv;
1326 
1327                 spin_lock_bh(&pstapriv->asoc_list_lock);
1328 
1329                 phead = &pstapriv->asoc_list;
1330                 plist = phead->next;
1331 
1332                 /* check asoc_queue */
1333                 while (phead != plist) {
1334                         psta = container_of(plist, struct sta_info, asoc_list);
1335 
1336                         plist = plist->next;
1337 
1338                         VCS_update(padapter, psta);
1339                 }
1340                 spin_unlock_bh(&pstapriv->asoc_list_lock);
1341         }
1342 }
1343 
1344 /* called > TSR LEVEL for USB or SDIO Interface*/
1345 void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1346 {
1347         u8 beacon_updated = false;
1348         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1349         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1350 
1351         if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1352                 if (!psta->no_short_preamble_set) {
1353                         psta->no_short_preamble_set = 1;
1354 
1355                         pmlmepriv->num_sta_no_short_preamble++;
1356 
1357                         if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1358                             (pmlmepriv->num_sta_no_short_preamble == 1)) {
1359                                 beacon_updated = true;
1360                                 update_beacon(padapter, 0xFF, NULL, true);
1361                         }
1362                 }
1363         } else {
1364                 if (psta->no_short_preamble_set) {
1365                         psta->no_short_preamble_set = 0;
1366 
1367                         pmlmepriv->num_sta_no_short_preamble--;
1368 
1369                         if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1370                             (pmlmepriv->num_sta_no_short_preamble == 0)) {
1371                                 beacon_updated = true;
1372                                 update_beacon(padapter, 0xFF, NULL, true);
1373                         }
1374                 }
1375         }
1376 
1377         if (psta->flags & WLAN_STA_NONERP) {
1378                 if (!psta->nonerp_set) {
1379                         psta->nonerp_set = 1;
1380 
1381                         pmlmepriv->num_sta_non_erp++;
1382 
1383                         if (pmlmepriv->num_sta_non_erp == 1) {
1384                                 beacon_updated = true;
1385                                 update_beacon(padapter, _ERPINFO_IE_, NULL, true);
1386                         }
1387                 }
1388         } else {
1389                 if (psta->nonerp_set) {
1390                         psta->nonerp_set = 0;
1391 
1392                         pmlmepriv->num_sta_non_erp--;
1393 
1394                         if (pmlmepriv->num_sta_non_erp == 0) {
1395                                 beacon_updated = true;
1396                                 update_beacon(padapter, _ERPINFO_IE_, NULL, true);
1397                         }
1398                 }
1399         }
1400 
1401         if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1402                 if (!psta->no_short_slot_time_set) {
1403                         psta->no_short_slot_time_set = 1;
1404 
1405                         pmlmepriv->num_sta_no_short_slot_time++;
1406 
1407                         if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1408                             (pmlmepriv->num_sta_no_short_slot_time == 1)) {
1409                                 beacon_updated = true;
1410                                 update_beacon(padapter, 0xFF, NULL, true);
1411                         }
1412                 }
1413         } else {
1414                 if (psta->no_short_slot_time_set) {
1415                         psta->no_short_slot_time_set = 0;
1416 
1417                         pmlmepriv->num_sta_no_short_slot_time--;
1418 
1419                         if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1420                             (pmlmepriv->num_sta_no_short_slot_time == 0)) {
1421                                 beacon_updated = true;
1422                                 update_beacon(padapter, 0xFF, NULL, true);
1423                         }
1424                 }
1425         }
1426 
1427         if (psta->flags & WLAN_STA_HT) {
1428                 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
1429 
1430                 DBG_88E("HT: STA %pM HT Capabilities Info: 0x%04x\n",
1431                         (psta->hwaddr), ht_capab);
1432 
1433                 if (psta->no_ht_set) {
1434                         psta->no_ht_set = 0;
1435                         pmlmepriv->num_sta_no_ht--;
1436                 }
1437 
1438                 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
1439                         if (!psta->no_ht_gf_set) {
1440                                 psta->no_ht_gf_set = 1;
1441                                 pmlmepriv->num_sta_ht_no_gf++;
1442                         }
1443                         DBG_88E("%s STA %pM - no greenfield, num of non-gf stations %d\n",
1444                                 __func__, (psta->hwaddr),
1445                                 pmlmepriv->num_sta_ht_no_gf);
1446                 }
1447 
1448                 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
1449                         if (!psta->ht_20mhz_set) {
1450                                 psta->ht_20mhz_set = 1;
1451                                 pmlmepriv->num_sta_ht_20mhz++;
1452                         }
1453                         DBG_88E("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n",
1454                                 __func__, (psta->hwaddr),
1455                                 pmlmepriv->num_sta_ht_20mhz);
1456                 }
1457         } else {
1458                 if (!psta->no_ht_set) {
1459                         psta->no_ht_set = 1;
1460                         pmlmepriv->num_sta_no_ht++;
1461                 }
1462                 if (pmlmepriv->htpriv.ht_option) {
1463                         DBG_88E("%s STA %pM - no HT, num of non-HT stations %d\n",
1464                                 __func__, (psta->hwaddr),
1465                                 pmlmepriv->num_sta_no_ht);
1466                 }
1467         }
1468 
1469         if (rtw_ht_operation_update(padapter) > 0) {
1470                 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
1471                 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
1472         }
1473 
1474         /* update associated stations cap. */
1475         associated_clients_update(padapter,  beacon_updated);
1476 
1477         DBG_88E("%s, updated =%d\n", __func__, beacon_updated);
1478 }
1479 
1480 u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
1481 {
1482         u8 beacon_updated = false;
1483         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1484         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1485 
1486         if (!psta)
1487                 return beacon_updated;
1488 
1489         if (psta->no_short_preamble_set) {
1490                 psta->no_short_preamble_set = 0;
1491                 pmlmepriv->num_sta_no_short_preamble--;
1492                 if (pmlmeext->cur_wireless_mode > WIRELESS_11B &&
1493                     pmlmepriv->num_sta_no_short_preamble == 0) {
1494                         beacon_updated = true;
1495                         update_beacon(padapter, 0xFF, NULL, true);
1496                 }
1497         }
1498 
1499         if (psta->nonerp_set) {
1500                 psta->nonerp_set = 0;
1501                 pmlmepriv->num_sta_non_erp--;
1502                 if (pmlmepriv->num_sta_non_erp == 0) {
1503                         beacon_updated = true;
1504                         update_beacon(padapter, _ERPINFO_IE_, NULL, true);
1505                 }
1506         }
1507 
1508         if (psta->no_short_slot_time_set) {
1509                 psta->no_short_slot_time_set = 0;
1510                 pmlmepriv->num_sta_no_short_slot_time--;
1511                 if (pmlmeext->cur_wireless_mode > WIRELESS_11B &&
1512                     pmlmepriv->num_sta_no_short_slot_time == 0) {
1513                         beacon_updated = true;
1514                         update_beacon(padapter, 0xFF, NULL, true);
1515                 }
1516         }
1517 
1518         if (psta->no_ht_gf_set) {
1519                 psta->no_ht_gf_set = 0;
1520                 pmlmepriv->num_sta_ht_no_gf--;
1521         }
1522 
1523         if (psta->no_ht_set) {
1524                 psta->no_ht_set = 0;
1525                 pmlmepriv->num_sta_no_ht--;
1526         }
1527 
1528         if (psta->ht_20mhz_set) {
1529                 psta->ht_20mhz_set = 0;
1530                 pmlmepriv->num_sta_ht_20mhz--;
1531         }
1532 
1533         if (rtw_ht_operation_update(padapter) > 0) {
1534                 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
1535                 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
1536         }
1537 
1538         /* update associated stations cap. */
1539 
1540         DBG_88E("%s, updated =%d\n", __func__, beacon_updated);
1541 
1542         return beacon_updated;
1543 }
1544 
1545 u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta,
1546                bool active, u16 reason)
1547 {
1548         u8 beacon_updated = false;
1549         struct sta_priv *pstapriv = &padapter->stapriv;
1550 
1551         if (!psta)
1552                 return beacon_updated;
1553 
1554         /* tear down Rx AMPDU */
1555         send_delba(padapter, 0, psta->hwaddr);/*  recipient */
1556 
1557         /* tear down TX AMPDU */
1558         send_delba(padapter, 1, psta->hwaddr);/*  originator */
1559         psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
1560         psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
1561 
1562         if (active)
1563                 issue_deauth(padapter, psta->hwaddr, reason);
1564 
1565         /* clear cam entry / key */
1566         rtw_clearstakey_cmd(padapter, (u8 *)psta, (u8)(psta->mac_id + 3), true);
1567 
1568         spin_lock_bh(&psta->lock);
1569         psta->state &= ~_FW_LINKED;
1570         spin_unlock_bh(&psta->lock);
1571 
1572         rtw_indicate_sta_disassoc_event(padapter, psta);
1573 
1574         report_del_sta_event(padapter, psta->hwaddr, reason);
1575 
1576         beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
1577 
1578         spin_lock_bh(&pstapriv->sta_hash_lock);
1579         rtw_free_stainfo(padapter, psta);
1580         spin_unlock_bh(&pstapriv->sta_hash_lock);
1581 
1582         return beacon_updated;
1583 }
1584 
1585 int rtw_sta_flush(struct adapter *padapter)
1586 {
1587         struct list_head *phead, *plist;
1588         struct sta_info *psta = NULL;
1589         struct sta_priv *pstapriv = &padapter->stapriv;
1590         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1591         struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1592         u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1593 
1594         DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1595 
1596         if ((pmlmeinfo->state & 0x03) != WIFI_FW_AP_STATE)
1597                 return 0;
1598 
1599         spin_lock_bh(&pstapriv->asoc_list_lock);
1600         phead = &pstapriv->asoc_list;
1601         plist = phead->next;
1602 
1603         /* free sta asoc_queue */
1604         while (phead != plist) {
1605                 psta = container_of(plist, struct sta_info, asoc_list);
1606 
1607                 plist = plist->next;
1608 
1609                 list_del_init(&psta->asoc_list);
1610                 pstapriv->asoc_list_cnt--;
1611 
1612                 ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
1613         }
1614         spin_unlock_bh(&pstapriv->asoc_list_lock);
1615 
1616         issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
1617 
1618         associated_clients_update(padapter, true);
1619 
1620         return 0;
1621 }
1622 
1623 /* called > TSR LEVEL for USB or SDIO Interface*/
1624 void sta_info_update(struct adapter *padapter, struct sta_info *psta)
1625 {
1626         int flags = psta->flags;
1627         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1628 
1629         /* update wmm cap. */
1630         if (WLAN_STA_WME & flags)
1631                 psta->qos_option = 1;
1632         else
1633                 psta->qos_option = 0;
1634 
1635         if (pmlmepriv->qospriv.qos_option == 0)
1636                 psta->qos_option = 0;
1637 
1638         /* update 802.11n ht cap. */
1639         if (WLAN_STA_HT & flags) {
1640                 psta->htpriv.ht_option = true;
1641                 psta->qos_option = 1;
1642         } else {
1643                 psta->htpriv.ht_option = false;
1644         }
1645 
1646         if (!pmlmepriv->htpriv.ht_option)
1647                 psta->htpriv.ht_option = false;
1648 
1649         update_sta_info_apmode(padapter, psta);
1650 }
1651 
1652 /* called >= TSR LEVEL for USB or SDIO Interface*/
1653 void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta)
1654 {
1655         if (psta->state & _FW_LINKED) {
1656                 /* add ratid */
1657                 add_RATid(padapter, psta, 0);/* DM_RATR_STA_INIT */
1658         }
1659 }
1660 
1661 void start_ap_mode(struct adapter *padapter)
1662 {
1663         int i;
1664         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1665         struct sta_priv *pstapriv = &padapter->stapriv;
1666         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1667         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1668 
1669         pmlmepriv->update_bcn = false;
1670 
1671         pmlmeext->bstart_bss = false;
1672 
1673         pmlmepriv->num_sta_non_erp = 0;
1674 
1675         pmlmepriv->num_sta_no_short_slot_time = 0;
1676 
1677         pmlmepriv->num_sta_no_short_preamble = 0;
1678 
1679         pmlmepriv->num_sta_ht_no_gf = 0;
1680         pmlmepriv->num_sta_no_ht = 0;
1681         pmlmepriv->num_sta_ht_20mhz = 0;
1682 
1683         pmlmepriv->olbc = false;
1684 
1685         pmlmepriv->olbc_ht = false;
1686 
1687         pmlmepriv->ht_op_mode = 0;
1688 
1689         for (i = 0; i < NUM_STA; i++)
1690                 pstapriv->sta_aid[i] = NULL;
1691 
1692         pmlmepriv->wps_beacon_ie = NULL;
1693         pmlmepriv->wps_probe_resp_ie = NULL;
1694         pmlmepriv->wps_assoc_resp_ie = NULL;
1695 
1696         /* for ACL */
1697         INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
1698         pacl_list->num = 0;
1699         pacl_list->mode = 0;
1700         for (i = 0; i < NUM_ACL; i++) {
1701                 INIT_LIST_HEAD(&pacl_list->aclnode[i].list);
1702                 pacl_list->aclnode[i].valid = false;
1703         }
1704 }
1705 
1706 void stop_ap_mode(struct adapter *padapter)
1707 {
1708         struct list_head *phead, *plist;
1709         struct rtw_wlan_acl_node *paclnode;
1710         struct sta_info *psta = NULL;
1711         struct sta_priv *pstapriv = &padapter->stapriv;
1712         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1713         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1714         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1715         struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1716 
1717         pmlmepriv->update_bcn = false;
1718         pmlmeext->bstart_bss = false;
1719 
1720         /* reset and init security priv , this can refine with
1721          * rtw_reset_securitypriv
1722          */
1723         memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
1724         padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1725         padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
1726 
1727         /* for ACL */
1728         spin_lock_bh(&pacl_node_q->lock);
1729         phead = get_list_head(pacl_node_q);
1730         plist = phead->next;
1731         while (phead != plist) {
1732                 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1733                 plist = plist->next;
1734 
1735                 if (paclnode->valid) {
1736                         paclnode->valid = false;
1737 
1738                         list_del_init(&paclnode->list);
1739 
1740                         pacl_list->num--;
1741                 }
1742         }
1743         spin_unlock_bh(&pacl_node_q->lock);
1744 
1745         DBG_88E("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
1746 
1747         rtw_sta_flush(padapter);
1748 
1749         /* free_assoc_sta_resources */
1750         rtw_free_all_stainfo(padapter);
1751 
1752         psta = rtw_get_bcmc_stainfo(padapter);
1753         spin_lock_bh(&pstapriv->sta_hash_lock);
1754         rtw_free_stainfo(padapter, psta);
1755         spin_unlock_bh(&pstapriv->sta_hash_lock);
1756 
1757         rtw_init_bcmc_stainfo(padapter);
1758 
1759         rtw_free_mlme_priv_ie_data(pmlmepriv);
1760 }
1761 
1762 #endif /* CONFIG_88EU_AP_MODE */

/* [<][>][^][v][top][bottom][index][help] */