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