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 <drv_types.h>
10 #include <rtw_debug.h>
11
12 extern unsigned char RTW_WPA_OUI[];
13 extern unsigned char WMM_OUI[];
14 extern unsigned char WPS_OUI[];
15 extern unsigned char P2P_OUI[];
16 extern unsigned char WFD_OUI[];
17
init_mlme_ap_info(struct adapter * padapter)18 void init_mlme_ap_info(struct adapter *padapter)
19 {
20 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
21 struct sta_priv *pstapriv = &padapter->stapriv;
22 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
23
24
25 spin_lock_init(&pmlmepriv->bcn_update_lock);
26
27 /* for ACL */
28 _rtw_init_queue(&pacl_list->acl_node_q);
29
30 /* pmlmeext->bstart_bss = false; */
31
32 start_ap_mode(padapter);
33 }
34
free_mlme_ap_info(struct adapter * padapter)35 void free_mlme_ap_info(struct adapter *padapter)
36 {
37 struct sta_info *psta = NULL;
38 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
39 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
40 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
41
42 /* stop_ap_mode(padapter); */
43
44 pmlmepriv->update_bcn = false;
45 pmlmeext->bstart_bss = false;
46
47 rtw_sta_flush(padapter);
48
49 pmlmeinfo->state = _HW_STATE_NOLINK_;
50
51 /* free_assoc_sta_resources */
52 rtw_free_all_stainfo(padapter);
53
54 /* free bc/mc sta_info */
55 psta = rtw_get_bcmc_stainfo(padapter);
56 rtw_free_stainfo(padapter, psta);
57 }
58
update_BCNTIM(struct adapter * padapter)59 static void update_BCNTIM(struct adapter *padapter)
60 {
61 struct sta_priv *pstapriv = &padapter->stapriv;
62 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
63 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
64 struct wlan_bssid_ex *pnetwork_mlmeext = &(pmlmeinfo->network);
65 unsigned char *pie = pnetwork_mlmeext->IEs;
66
67 /* DBG_871X("%s\n", __func__); */
68
69 /* update TIM IE */
70 /* if (pstapriv->tim_bitmap) */
71 if (true) {
72
73 u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
74 __le16 tim_bitmap_le;
75 uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
76
77 tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
78
79 p = rtw_get_ie(
80 pie + _FIXED_IE_LENGTH_,
81 _TIM_IE_,
82 &tim_ielen,
83 pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_
84 );
85 if (p != NULL && tim_ielen > 0) {
86
87 tim_ielen += 2;
88
89 premainder_ie = p+tim_ielen;
90
91 tim_ie_offset = (sint)(p - pie);
92
93 remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
94
95 /* append TIM IE from dst_ie offset */
96 dst_ie = p;
97 } else{
98
99
100 tim_ielen = 0;
101
102 /* calucate head_len */
103 offset = _FIXED_IE_LENGTH_;
104
105 /* get ssid_ie len */
106 p = rtw_get_ie(
107 pie + _BEACON_IE_OFFSET_,
108 _SSID_IE_,
109 &tmp_len,
110 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_)
111 );
112 if (p != NULL)
113 offset += tmp_len+2;
114
115 /* get supported rates len */
116 p = rtw_get_ie(
117 pie + _BEACON_IE_OFFSET_,
118 _SUPPORTEDRATES_IE_, &tmp_len,
119 (pnetwork_mlmeext->IELength - _BEACON_IE_OFFSET_)
120 );
121 if (p != NULL)
122 offset += tmp_len+2;
123
124
125 /* DS Parameter Set IE, len =3 */
126 offset += 3;
127
128 premainder_ie = pie + offset;
129
130 remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
131
132 /* append TIM IE from offset */
133 dst_ie = pie + offset;
134
135 }
136
137
138 if (remainder_ielen > 0) {
139
140 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
141 if (pbackup_remainder_ie && premainder_ie)
142 memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
143 }
144
145 *dst_ie++ = _TIM_IE_;
146
147 if ((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fe))
148 tim_ielen = 5;
149 else
150 tim_ielen = 4;
151
152 *dst_ie++ = tim_ielen;
153
154 *dst_ie++ = 0;/* DTIM count */
155 *dst_ie++ = 1;/* DTIM peroid */
156
157 if (pstapriv->tim_bitmap&BIT(0))/* for bc/mc frames */
158 *dst_ie++ = BIT(0);/* bitmap ctrl */
159 else
160 *dst_ie++ = 0;
161
162 if (tim_ielen == 4) {
163
164 __le16 pvb;
165
166 if (pstapriv->tim_bitmap&0xff00)
167 pvb = cpu_to_le16(pstapriv->tim_bitmap >> 8);
168 else
169 pvb = tim_bitmap_le;
170
171 *dst_ie++ = le16_to_cpu(pvb);
172
173 } else if (tim_ielen == 5) {
174
175
176 memcpy(dst_ie, &tim_bitmap_le, 2);
177 dst_ie += 2;
178 }
179
180 /* copy remainder IE */
181 if (pbackup_remainder_ie) {
182
183 memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
184
185 kfree(pbackup_remainder_ie);
186 }
187
188 offset = (uint)(dst_ie - pie);
189 pnetwork_mlmeext->IELength = offset + remainder_ielen;
190
191 }
192 }
193
194 u8 chk_sta_is_alive(struct sta_info *psta);
chk_sta_is_alive(struct sta_info * psta)195 u8 chk_sta_is_alive(struct sta_info *psta)
196 {
197 #ifdef DBG_EXPIRATION_CHK
198 DBG_871X(
199 "sta:"MAC_FMT", rssi:%d, rx:"STA_PKTS_FMT", expire_to:%u, %s%ssq_len:%u\n"
200 , MAC_ARG(psta->hwaddr)
201 , psta->rssi_stat.UndecoratedSmoothedPWDB
202 /* STA_RX_PKTS_ARG(psta) */
203 , STA_RX_PKTS_DIFF_ARG(psta)
204 , psta->expire_to
205 , psta->state&WIFI_SLEEP_STATE?"PS, ":""
206 , psta->state&WIFI_STA_ALIVE_CHK_STATE?"SAC, ":""
207 , psta->sleepq_len
208 );
209 #endif
210
211 sta_update_last_rx_pkts(psta);
212
213 return true;
214 }
215
expire_timeout_chk(struct adapter * padapter)216 void expire_timeout_chk(struct adapter *padapter)
217 {
218 struct list_head *phead, *plist;
219 u8 updated = false;
220 struct sta_info *psta = NULL;
221 struct sta_priv *pstapriv = &padapter->stapriv;
222 u8 chk_alive_num = 0;
223 char chk_alive_list[NUM_STA];
224 int i;
225
226
227 spin_lock_bh(&pstapriv->auth_list_lock);
228
229 phead = &pstapriv->auth_list;
230 plist = get_next(phead);
231
232 /* check auth_queue */
233 #ifdef DBG_EXPIRATION_CHK
234 if (phead != plist) {
235 DBG_871X(FUNC_NDEV_FMT" auth_list, cnt:%u\n"
236 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->auth_list_cnt);
237 }
238 #endif
239 while (phead != plist) {
240
241 psta = LIST_CONTAINOR(plist, struct sta_info, auth_list);
242
243 plist = get_next(plist);
244
245 if (psta->expire_to > 0) {
246
247 psta->expire_to--;
248 if (psta->expire_to == 0) {
249
250 list_del_init(&psta->auth_list);
251 pstapriv->auth_list_cnt--;
252
253 DBG_871X(
254 "auth expire %02X%02X%02X%02X%02X%02X\n",
255 psta->hwaddr[0],
256 psta->hwaddr[1],
257 psta->hwaddr[2],
258 psta->hwaddr[3],
259 psta->hwaddr[4],
260 psta->hwaddr[5]
261 );
262
263 spin_unlock_bh(&pstapriv->auth_list_lock);
264
265 rtw_free_stainfo(padapter, psta);
266
267 spin_lock_bh(&pstapriv->auth_list_lock);
268 }
269 }
270
271 }
272
273 spin_unlock_bh(&pstapriv->auth_list_lock);
274 psta = NULL;
275
276
277 spin_lock_bh(&pstapriv->asoc_list_lock);
278
279 phead = &pstapriv->asoc_list;
280 plist = get_next(phead);
281
282 /* check asoc_queue */
283 #ifdef DBG_EXPIRATION_CHK
284 if (phead != plist) {
285 DBG_871X(FUNC_NDEV_FMT" asoc_list, cnt:%u\n"
286 , FUNC_NDEV_ARG(padapter->pnetdev), pstapriv->asoc_list_cnt);
287 }
288 #endif
289 while (phead != plist) {
290
291 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
292 plist = get_next(plist);
293 #ifdef CONFIG_AUTO_AP_MODE
294 if (psta->isrc)
295 continue;
296 #endif
297 if (chk_sta_is_alive(psta) || !psta->expire_to) {
298 psta->expire_to = pstapriv->expire_to;
299 psta->keep_alive_trycnt = 0;
300 psta->under_exist_checking = 0;
301 } else {
302 if (psta->expire_to > 0)
303 psta->expire_to--;
304 }
305
306 if (psta->expire_to == 0) {
307
308 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
309
310 if (padapter->registrypriv.wifi_spec == 1) {
311
312 psta->expire_to = pstapriv->expire_to;
313 continue;
314 }
315
316 if (psta->state & WIFI_SLEEP_STATE) {
317 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
318 /* to check if alive by another methods if staion is at ps mode. */
319 psta->expire_to = pstapriv->expire_to;
320 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
321
322 /* DBG_871X("alive chk, sta:" MAC_FMT " is at ps mode!\n", MAC_ARG(psta->hwaddr)); */
323
324 /* to update bcn with tim_bitmap for this station */
325 pstapriv->tim_bitmap |= BIT(psta->aid);
326 update_beacon(padapter, _TIM_IE_, NULL, true);
327
328 if (!pmlmeext->active_keep_alive_check)
329 continue;
330 }
331 }
332 if (pmlmeext->active_keep_alive_check) {
333 int stainfo_offset;
334
335 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
336 if (stainfo_offset_valid(stainfo_offset))
337 chk_alive_list[chk_alive_num++] = stainfo_offset;
338
339
340 continue;
341 }
342 list_del_init(&psta->asoc_list);
343 pstapriv->asoc_list_cnt--;
344 DBG_871X(
345 "asoc expire "MAC_FMT", state = 0x%x\n",
346 MAC_ARG(psta->hwaddr),
347 psta->state
348 );
349 updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
350 } else{
351
352
353 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
354 if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
355 && padapter->xmitpriv.free_xmitframe_cnt < ((
356 NR_XMITFRAME/pstapriv->asoc_list_cnt
357 )/2)
358 ) {
359 DBG_871X(
360 "%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n",
361 __func__,
362 MAC_ARG(psta->hwaddr),
363 psta->sleepq_len,
364 padapter->xmitpriv.free_xmitframe_cnt,
365 pstapriv->asoc_list_cnt
366 );
367 wakeup_sta_to_xmit(padapter, psta);
368 }
369 }
370 }
371
372 spin_unlock_bh(&pstapriv->asoc_list_lock);
373
374 if (chk_alive_num) {
375 u8 backup_oper_channel = 0;
376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
377
378 /* switch to correct channel of current network before issue keep-alive frames */
379 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
380 backup_oper_channel = rtw_get_oper_ch(padapter);
381 SelectChannel(padapter, pmlmeext->cur_channel);
382 }
383
384 /* issue null data to check sta alive*/
385 for (i = 0; i < chk_alive_num; i++) {
386 int ret = _FAIL;
387
388 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
389 if (!(psta->state & _FW_LINKED))
390 continue;
391
392 if (psta->state & WIFI_SLEEP_STATE)
393 ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
394 else
395 ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);
396
397 psta->keep_alive_trycnt++;
398 if (ret == _SUCCESS) {
399 DBG_871X(
400 "asoc check, sta(" MAC_FMT ") is alive\n",
401 MAC_ARG(psta->hwaddr)
402 );
403 psta->expire_to = pstapriv->expire_to;
404 psta->keep_alive_trycnt = 0;
405 continue;
406 } else if (psta->keep_alive_trycnt <= 3) {
407
408 DBG_871X(
409 "ack check for asoc expire, keep_alive_trycnt =%d\n",
410 psta->keep_alive_trycnt);
411 psta->expire_to = 1;
412 continue;
413 }
414
415 psta->keep_alive_trycnt = 0;
416 DBG_871X(
417 "asoc expire "MAC_FMT", state = 0x%x\n",
418 MAC_ARG(psta->hwaddr),
419 psta->state);
420 spin_lock_bh(&pstapriv->asoc_list_lock);
421 if (list_empty(&psta->asoc_list) == false) {
422 list_del_init(&psta->asoc_list);
423 pstapriv->asoc_list_cnt--;
424 updated = ap_free_sta(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
425 }
426 spin_unlock_bh(&pstapriv->asoc_list_lock);
427 }
428
429 if (backup_oper_channel > 0) /* back to the original operation channel */
430 SelectChannel(padapter, backup_oper_channel);
431 }
432
433 associated_clients_update(padapter, updated);
434 }
435
add_RATid(struct adapter * padapter,struct sta_info * psta,u8 rssi_level)436 void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
437 {
438 unsigned char sta_band = 0, shortGIrate = false;
439 unsigned int tx_ra_bitmap = 0;
440 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
441 struct wlan_bssid_ex
442 *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
443
444 if (!psta)
445 return;
446
447 if (!(psta->state & _FW_LINKED))
448 return;
449
450 rtw_hal_update_sta_rate_mask(padapter, psta);
451 tx_ra_bitmap = psta->ra_mask;
452
453 shortGIrate = query_ra_short_GI(psta);
454
455 if (pcur_network->Configuration.DSConfig > 14) {
456
457 if (tx_ra_bitmap & 0xffff000)
458 sta_band |= WIRELESS_11_5N;
459
460 if (tx_ra_bitmap & 0xff0)
461 sta_band |= WIRELESS_11A;
462 } else {
463 if (tx_ra_bitmap & 0xffff000)
464 sta_band |= WIRELESS_11_24N;
465
466 if (tx_ra_bitmap & 0xff0)
467 sta_band |= WIRELESS_11G;
468
469 if (tx_ra_bitmap & 0x0f)
470 sta_band |= WIRELESS_11B;
471 }
472
473 psta->wireless_mode = sta_band;
474 psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
475
476 if (psta->aid < NUM_STA) {
477
478 u8 arg[4] = {0};
479
480 arg[0] = psta->mac_id;
481 arg[1] = psta->raid;
482 arg[2] = shortGIrate;
483 arg[3] = psta->init_rate;
484
485 DBG_871X("%s => mac_id:%d , raid:%d , shortGIrate =%d, bitmap = 0x%x\n",
486 __func__, psta->mac_id, psta->raid, shortGIrate, tx_ra_bitmap);
487
488 rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, rssi_level);
489 } else{
490
491
492 DBG_871X("station aid %d exceed the max number\n", psta->aid);
493 }
494
495 }
496
update_bmc_sta(struct adapter * padapter)497 void update_bmc_sta(struct adapter *padapter)
498 {
499 unsigned char network_type;
500 int supportRateNum = 0;
501 unsigned int tx_ra_bitmap = 0;
502 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
503 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
504 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
505 struct wlan_bssid_ex
506 *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
507 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
508
509 if (psta) {
510
511 psta->aid = 0;/* default set to 0 */
512 /* psta->mac_id = psta->aid+4; */
513 psta->mac_id = psta->aid + 1;/* mac_id = 1 for bc/mc stainfo */
514
515 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
516
517 psta->qos_option = 0;
518 psta->htpriv.ht_option = false;
519
520 psta->ieee8021x_blocked = 0;
521
522 memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
523
524 /* psta->dot118021XPrivacy = _NO_PRIVACY_;//!!! remove it, because it has been set before this. */
525
526 /* prepare for add_RATid */
527 supportRateNum = rtw_get_rateset_len((u8 *)&pcur_network->SupportedRates);
528 network_type = rtw_check_network_type(
529 (u8 *)&pcur_network->SupportedRates,
530 supportRateNum,
531 pcur_network->Configuration.DSConfig
532 );
533 if (IsSupportedTxCCK(network_type)) {
534 network_type = WIRELESS_11B;
535 } else if (network_type == WIRELESS_INVALID) { /* error handling */
536
537 if (pcur_network->Configuration.DSConfig > 14)
538 network_type = WIRELESS_11A;
539 else
540 network_type = WIRELESS_11B;
541 }
542 update_sta_basic_rate(psta, network_type);
543 psta->wireless_mode = network_type;
544
545 rtw_hal_update_sta_rate_mask(padapter, psta);
546 tx_ra_bitmap = psta->ra_mask;
547
548 psta->raid = rtw_hal_networktype_to_raid(padapter, psta);
549
550 /* ap mode */
551 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
552
553 /* if (pHalData->fw_ractrl == true) */
554 {
555 u8 arg[4] = {0};
556
557 arg[0] = psta->mac_id;
558 arg[1] = psta->raid;
559 arg[2] = 0;
560 arg[3] = psta->init_rate;
561
562 DBG_871X("%s => mac_id:%d , raid:%d , bitmap = 0x%x\n",
563 __func__, psta->mac_id, psta->raid, tx_ra_bitmap);
564
565 rtw_hal_add_ra_tid(padapter, tx_ra_bitmap, arg, 0);
566 }
567
568 rtw_sta_media_status_rpt(padapter, psta, 1);
569
570 spin_lock_bh(&psta->lock);
571 psta->state = _FW_LINKED;
572 spin_unlock_bh(&psta->lock);
573
574 } else{
575
576
577 DBG_871X("add_RATid_bmc_sta error!\n");
578 }
579
580 }
581
582 /* notes: */
583 /* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
584 /* MAC_ID = AID+1 for sta in ap/adhoc mode */
585 /* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
586 /* MAC_ID = 0 for bssid for sta/ap/adhoc */
587 /* CAM_ID = 0~3 for default key, cmd_id =macid + 3, macid =aid+1; */
588
update_sta_info_apmode(struct adapter * padapter,struct sta_info * psta)589 void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta)
590 {
591 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
592 struct security_priv *psecuritypriv = &padapter->securitypriv;
593 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
594 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
595 struct ht_priv *phtpriv_sta = &psta->htpriv;
596 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0;
597 /* set intf_tag to if1 */
598 /* psta->intf_tag = 0; */
599
600 DBG_871X("%s\n", __func__);
601
602 /* psta->mac_id = psta->aid+4; */
603 /* psta->mac_id = psta->aid+1;//alloc macid when call rtw_alloc_stainfo(), */
604 /* release macid when call rtw_free_stainfo() */
605
606 /* ap mode */
607 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
608
609 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
610 psta->ieee8021x_blocked = true;
611 else
612 psta->ieee8021x_blocked = false;
613
614
615 /* update sta's cap */
616
617 /* ERP */
618 VCS_update(padapter, psta);
619
620 /* HT related cap */
621 if (phtpriv_sta->ht_option) {
622
623 /* check if sta supports rx ampdu */
624 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
625
626 phtpriv_sta->rx_ampdu_min_spacing = (
627 phtpriv_sta->ht_cap.ampdu_params_info&IEEE80211_HT_CAP_AMPDU_DENSITY
628 )>>2;
629
630 /* bwmode */
631 if ((
632 phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info
633 ) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH))
634 psta->bw_mode = CHANNEL_WIDTH_40;
635 else
636 psta->bw_mode = CHANNEL_WIDTH_20;
637
638 if (pmlmeext->cur_bwmode < psta->bw_mode)
639 psta->bw_mode = pmlmeext->cur_bwmode;
640
641 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
642
643
644 /* check if sta support s Short GI 20M */
645 if ((
646 phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info
647 ) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
648 phtpriv_sta->sgi_20m = true;
649
650 /* check if sta support s Short GI 40M */
651 if ((
652 phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info
653 ) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)) {
654
655 if (psta->bw_mode == CHANNEL_WIDTH_40) /* according to psta->bw_mode */
656 phtpriv_sta->sgi_40m = true;
657 else
658 phtpriv_sta->sgi_40m = false;
659 }
660
661 psta->qos_option = true;
662
663 /* B0 Config LDPC Coding Capability */
664 if (TEST_FLAG(phtpriv_ap->ldpc_cap, LDPC_HT_ENABLE_TX) &&
665 GET_HT_CAPABILITY_ELE_LDPC_CAP((u8 *)(&phtpriv_sta->ht_cap))) {
666
667 SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
668 DBG_871X("Enable HT Tx LDPC for STA(%d)\n", psta->aid);
669 }
670
671 /* B7 B8 B9 Config STBC setting */
672 if (TEST_FLAG(phtpriv_ap->stbc_cap, STBC_HT_ENABLE_TX) &&
673 GET_HT_CAPABILITY_ELE_RX_STBC((u8 *)(&phtpriv_sta->ht_cap))) {
674
675 SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
676 DBG_871X("Enable HT Tx STBC for STA(%d)\n", psta->aid);
677 }
678 } else{
679
680
681 phtpriv_sta->ampdu_enable = false;
682
683 phtpriv_sta->sgi_20m = false;
684 phtpriv_sta->sgi_40m = false;
685 psta->bw_mode = CHANNEL_WIDTH_20;
686 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
687 }
688
689 phtpriv_sta->ldpc_cap = cur_ldpc_cap;
690 phtpriv_sta->stbc_cap = cur_stbc_cap;
691 phtpriv_sta->beamform_cap = cur_beamform_cap;
692
693 /* Rx AMPDU */
694 send_delba(padapter, 0, psta->hwaddr);/* recipient */
695
696 /* TX AMPDU */
697 send_delba(padapter, 1, psta->hwaddr);/* originator */
698 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
699 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
700
701 update_ldpc_stbc_cap(psta);
702
703 /* todo: init other variables */
704
705 memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
706
707
708 /* add ratid */
709 /* add_RATid(padapter, psta);//move to ap_sta_info_defer_update() */
710
711
712 spin_lock_bh(&psta->lock);
713 psta->state |= _FW_LINKED;
714 spin_unlock_bh(&psta->lock);
715
716
717 }
718
update_ap_info(struct adapter * padapter,struct sta_info * psta)719 static void update_ap_info(struct adapter *padapter, struct sta_info *psta)
720 {
721 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
722 struct wlan_bssid_ex
723 *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
724 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
725 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
726
727 psta->wireless_mode = pmlmeext->cur_wireless_mode;
728
729 psta->bssratelen = rtw_get_rateset_len(pnetwork->SupportedRates);
730 memcpy(psta->bssrateset, pnetwork->SupportedRates, psta->bssratelen);
731
732 /* HT related cap */
733 if (phtpriv_ap->ht_option) {
734
735 /* check if sta supports rx ampdu */
736 /* phtpriv_ap->ampdu_enable = phtpriv_ap->ampdu_enable; */
737
738 /* check if sta support s Short GI 20M */
739 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20))
740 phtpriv_ap->sgi_20m = true;
741
742 /* check if sta support s Short GI 40M */
743 if ((phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_40))
744 phtpriv_ap->sgi_40m = true;
745
746
747 psta->qos_option = true;
748 } else{
749
750
751 phtpriv_ap->ampdu_enable = false;
752
753 phtpriv_ap->sgi_20m = false;
754 phtpriv_ap->sgi_40m = false;
755 }
756
757 psta->bw_mode = pmlmeext->cur_bwmode;
758 phtpriv_ap->ch_offset = pmlmeext->cur_ch_offset;
759
760 phtpriv_ap->agg_enable_bitmap = 0x0;/* reset */
761 phtpriv_ap->candidate_tid_bitmap = 0x0;/* reset */
762
763 memcpy(&psta->htpriv, &pmlmepriv->htpriv, sizeof(struct ht_priv));
764 }
765
update_hw_ht_param(struct adapter * padapter)766 static void update_hw_ht_param(struct adapter *padapter)
767 {
768 unsigned char max_AMPDU_len;
769 unsigned char min_MPDU_spacing;
770 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
771 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
772
773 DBG_871X("%s\n", __func__);
774
775
776 /* handle A-MPDU parameter field */
777 /*
778 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
779 AMPDU_para [4:2]:Min MPDU Start Spacing
780 */
781 max_AMPDU_len = pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x03;
782
783 min_MPDU_spacing = (
784 pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c
785 ) >> 2;
786
787 rtw_hal_set_hwreg(
788 padapter,
789 HW_VAR_AMPDU_MIN_SPACE,
790 (u8 *)(&min_MPDU_spacing)
791 );
792
793 rtw_hal_set_hwreg(padapter, HW_VAR_AMPDU_FACTOR, (u8 *)(&max_AMPDU_len));
794
795 /* */
796 /* Config SM Power Save setting */
797 /* */
798 pmlmeinfo->SM_PS = (le16_to_cpu(
799 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info
800 ) & 0x0C) >> 2;
801 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
802 DBG_871X("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
803
804 /* */
805 /* Config current HT Protection mode. */
806 /* */
807 /* pmlmeinfo->HT_protection = pmlmeinfo->HT_info.infos[1] & 0x3; */
808
809 }
810
start_bss_network(struct adapter * padapter,u8 * pbuf)811 void start_bss_network(struct adapter *padapter, u8 *pbuf)
812 {
813 u8 *p;
814 u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
815 u16 bcn_interval;
816 u32 acparm;
817 int ie_len;
818 struct registry_priv *pregpriv = &padapter->registrypriv;
819 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
820 struct security_priv *psecuritypriv = &(padapter->securitypriv);
821 struct wlan_bssid_ex
822 *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
823 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
824 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
825 struct wlan_bssid_ex *pnetwork_mlmeext = &(pmlmeinfo->network);
826 struct HT_info_element *pht_info = NULL;
827 u8 cbw40_enable = 0;
828
829 /* DBG_871X("%s\n", __func__); */
830
831 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
832 cur_channel = pnetwork->Configuration.DSConfig;
833 cur_bwmode = CHANNEL_WIDTH_20;
834 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
835
836
837 /* check if there is wps ie, */
838 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
839 /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
840 if (NULL == rtw_get_wps_ie(
841 pnetwork->IEs+_FIXED_IE_LENGTH_,
842 pnetwork->IELength-_FIXED_IE_LENGTH_,
843 NULL,
844 NULL
845 ))
846 pmlmeext->bstart_bss = true;
847
848
849 /* todo: update wmm, ht cap */
850 /* pmlmeinfo->WMM_enable; */
851 /* pmlmeinfo->HT_enable; */
852 if (pmlmepriv->qospriv.qos_option)
853 pmlmeinfo->WMM_enable = true;
854 if (pmlmepriv->htpriv.ht_option) {
855
856 pmlmeinfo->WMM_enable = true;
857 pmlmeinfo->HT_enable = true;
858 /* pmlmeinfo->HT_info_enable = true; */
859 /* pmlmeinfo->HT_caps_enable = true; */
860
861 update_hw_ht_param(padapter);
862 }
863
864 if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */
865
866 /* WEP Key will be set before this function, do not clear CAM. */
867 if (
868 (psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) &&
869 (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
870 )
871 flush_all_cam_entry(padapter); /* clear CAM */
872 }
873
874 /* set MSR to AP_Mode */
875 Set_MSR(padapter, _HW_STATE_AP_);
876
877 /* Set BSSID REG */
878 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress);
879
880 /* Set EDCA param reg */
881 acparm = 0x002F3217; /* VO */
882 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm));
883 acparm = 0x005E4317; /* VI */
884 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm));
885 /* acparm = 0x00105320; // BE */
886 acparm = 0x005ea42b;
887 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm));
888 acparm = 0x0000A444; /* BK */
889 rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm));
890
891 /* Set Security */
892 val8 = (
893 psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X
894 ) ? 0xcc : 0xcf;
895 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
896
897 /* Beacon Control related register */
898 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval));
899
900 rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, NULL);
901
902 if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */
903
904 /* u32 initialgain; */
905
906 /* initialgain = 0x1e; */
907
908
909 /* disable dynamic functions, such as high power, DIG */
910 /* Save_DM_Func_Flag(padapter); */
911 /* Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false); */
912
913 /* turn on all dynamic functions */
914 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
915
916 /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */
917
918 }
919
920 /* set channel, bwmode */
921 p = rtw_get_ie(
922 (pnetwork->IEs + sizeof(struct ndis_802_11_fix_ie)),
923 _HT_ADD_INFO_IE_,
924 &ie_len,
925 (pnetwork->IELength - sizeof(struct ndis_802_11_fix_ie))
926 );
927 if (p && ie_len) {
928
929 pht_info = (struct HT_info_element *)(p+2);
930
931 if (cur_channel > 14) {
932 if ((pregpriv->bw_mode & 0xf0) > 0)
933 cbw40_enable = 1;
934 } else {
935 if ((pregpriv->bw_mode & 0x0f) > 0)
936 cbw40_enable = 1;
937 }
938
939 if ((cbw40_enable) && (pht_info->infos[0] & BIT(2))) {
940
941 /* switch to the 40M Hz mode */
942 /* pmlmeext->cur_bwmode = CHANNEL_WIDTH_40; */
943 cur_bwmode = CHANNEL_WIDTH_40;
944 switch (pht_info->infos[0] & 0x3) {
945
946 case 1:
947 /* pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; */
948 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
949 break;
950
951 case 3:
952 /* pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; */
953 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
954 break;
955
956 default:
957 /* pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; */
958 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
959 break;
960 }
961
962 }
963
964 }
965
966 set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode);
967 DBG_871X(
968 "CH =%d, BW =%d, offset =%d\n",
969 cur_channel,
970 cur_bwmode,
971 cur_ch_offset
972 );
973 pmlmeext->cur_channel = cur_channel;
974 pmlmeext->cur_bwmode = cur_bwmode;
975 pmlmeext->cur_ch_offset = cur_ch_offset;
976 pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
977
978 /* let pnetwork_mlmeext == pnetwork_mlme. */
979 memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
980
981 /* update cur_wireless_mode */
982 update_wireless_mode(padapter);
983
984 /* update RRSR after set channel and bandwidth */
985 UpdateBrateTbl(padapter, pnetwork->SupportedRates);
986 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates);
987
988 /* udpate capability after cur_wireless_mode updated */
989 update_capinfo(
990 padapter,
991 rtw_get_capability((struct wlan_bssid_ex *)pnetwork)
992 );
993
994
995 if (true == pmlmeext->bstart_bss) {
996
997 update_beacon(padapter, _TIM_IE_, NULL, true);
998
999 #ifndef CONFIG_INTERRUPT_BASED_TXBCN /* other case will tx beacon when bcn interrupt coming in. */
1000 /* issue beacon frame */
1001 if (send_beacon(padapter) == _FAIL)
1002 DBG_871X("issue_beacon, fail!\n");
1003
1004 #endif /* CONFIG_INTERRUPT_BASED_TXBCN */
1005
1006 }
1007
1008
1009 /* update bc/mc sta_info */
1010 update_bmc_sta(padapter);
1011
1012 /* pmlmeext->bstart_bss = true; */
1013
1014 }
1015
rtw_check_beacon_data(struct adapter * padapter,u8 * pbuf,int len)1016 int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1017 {
1018 int ret = _SUCCESS;
1019 u8 *p;
1020 u8 *pHT_caps_ie = NULL;
1021 u8 *pHT_info_ie = NULL;
1022 struct sta_info *psta = NULL;
1023 u16 cap, ht_cap = false;
1024 uint ie_len = 0;
1025 int group_cipher, pairwise_cipher;
1026 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
1027 int supportRateNum = 0;
1028 u8 OUI1[] = {0x00, 0x50, 0xf2, 0x01};
1029 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
1030 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1031 struct security_priv *psecuritypriv = &padapter->securitypriv;
1032 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1033 struct wlan_bssid_ex
1034 *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
1035 u8 *ie = pbss_network->IEs;
1036
1037 /* SSID */
1038 /* Supported rates */
1039 /* DS Params */
1040 /* WLAN_EID_COUNTRY */
1041 /* ERP Information element */
1042 /* Extended supported rates */
1043 /* WPA/WPA2 */
1044 /* Wi-Fi Wireless Multimedia Extensions */
1045 /* ht_capab, ht_oper */
1046 /* WPS IE */
1047
1048 DBG_871X("%s, len =%d\n", __func__, len);
1049
1050 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true)
1051 return _FAIL;
1052
1053
1054 if (len < 0 || len > MAX_IE_SZ)
1055 return _FAIL;
1056
1057 pbss_network->IELength = len;
1058
1059 memset(ie, 0, MAX_IE_SZ);
1060
1061 memcpy(ie, pbuf, pbss_network->IELength);
1062
1063
1064 if (pbss_network->InfrastructureMode != Ndis802_11APMode)
1065 return _FAIL;
1066
1067 pbss_network->Rssi = 0;
1068
1069 memcpy(pbss_network->MacAddress, myid(&(padapter->eeprompriv)), ETH_ALEN);
1070
1071 /* beacon interval */
1072 p = rtw_get_beacon_interval_from_ie(ie);/* ie + 8; 8: TimeStamp, 2: Beacon Interval 2:Capability */
1073 /* pbss_network->Configuration.BeaconPeriod = le16_to_cpu(*(unsigned short*)p); */
1074 pbss_network->Configuration.BeaconPeriod = RTW_GET_LE16(p);
1075
1076 /* capability */
1077 /* cap = *(unsigned short *)rtw_get_capability_from_ie(ie); */
1078 /* cap = le16_to_cpu(cap); */
1079 cap = RTW_GET_LE16(ie);
1080
1081 /* SSID */
1082 p = rtw_get_ie(
1083 ie + _BEACON_IE_OFFSET_,
1084 _SSID_IE_,
1085 &ie_len,
1086 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1087 );
1088 if (p && ie_len > 0) {
1089
1090 memset(&pbss_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
1091 memcpy(pbss_network->Ssid.Ssid, (p + 2), ie_len);
1092 pbss_network->Ssid.SsidLength = ie_len;
1093 }
1094
1095 /* chnnel */
1096 channel = 0;
1097 pbss_network->Configuration.Length = 0;
1098 p = rtw_get_ie(
1099 ie + _BEACON_IE_OFFSET_,
1100 _DSSET_IE_, &ie_len,
1101 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1102 );
1103 if (p && ie_len > 0)
1104 channel = *(p + 2);
1105
1106 pbss_network->Configuration.DSConfig = channel;
1107
1108
1109 memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
1110 /* get supported rates */
1111 p = rtw_get_ie(
1112 ie + _BEACON_IE_OFFSET_,
1113 _SUPPORTEDRATES_IE_,
1114 &ie_len,
1115 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1116 );
1117 if (p != NULL) {
1118
1119 memcpy(supportRate, p+2, ie_len);
1120 supportRateNum = ie_len;
1121 }
1122
1123 /* get ext_supported rates */
1124 p = rtw_get_ie(
1125 ie + _BEACON_IE_OFFSET_,
1126 _EXT_SUPPORTEDRATES_IE_,
1127 &ie_len,
1128 pbss_network->IELength - _BEACON_IE_OFFSET_
1129 );
1130 if (p != NULL) {
1131
1132 memcpy(supportRate+supportRateNum, p+2, ie_len);
1133 supportRateNum += ie_len;
1134
1135 }
1136
1137 network_type = rtw_check_network_type(supportRate, supportRateNum, channel);
1138
1139 rtw_set_supported_rate(pbss_network->SupportedRates, network_type);
1140
1141
1142 /* parsing ERP_IE */
1143 p = rtw_get_ie(
1144 ie + _BEACON_IE_OFFSET_,
1145 _ERPINFO_IE_,
1146 &ie_len,
1147 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1148 );
1149 if (p && ie_len > 0)
1150 ERP_IE_handler(padapter, (struct ndis_80211_var_ie *)p);
1151
1152 /* update privacy/security */
1153 if (cap & BIT(4))
1154 pbss_network->Privacy = 1;
1155 else
1156 pbss_network->Privacy = 0;
1157
1158 psecuritypriv->wpa_psk = 0;
1159
1160 /* wpa2 */
1161 group_cipher = 0; pairwise_cipher = 0;
1162 psecuritypriv->wpa2_group_cipher = _NO_PRIVACY_;
1163 psecuritypriv->wpa2_pairwise_cipher = _NO_PRIVACY_;
1164 p = rtw_get_ie(
1165 ie + _BEACON_IE_OFFSET_,
1166 _RSN_IE_2_,
1167 &ie_len,
1168 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1169 );
1170 if (p && ie_len > 0) {
1171
1172 if (rtw_parse_wpa2_ie(
1173 p,
1174 ie_len+2,
1175 &group_cipher,
1176 &pairwise_cipher,
1177 NULL
1178 ) == _SUCCESS) {
1179
1180 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1181
1182 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1183 psecuritypriv->wpa_psk |= BIT(1);
1184
1185 psecuritypriv->wpa2_group_cipher = group_cipher;
1186 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
1187 }
1188
1189 }
1190
1191 /* wpa */
1192 ie_len = 0;
1193 group_cipher = 0; pairwise_cipher = 0;
1194 psecuritypriv->wpa_group_cipher = _NO_PRIVACY_;
1195 psecuritypriv->wpa_pairwise_cipher = _NO_PRIVACY_;
1196 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1197
1198 p = rtw_get_ie(
1199 p,
1200 _SSN_IE_1_,
1201 &ie_len,
1202 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2))
1203 );
1204 if ((p) && (!memcmp(p+2, OUI1, 4))) {
1205
1206 if (rtw_parse_wpa_ie(
1207 p,
1208 ie_len+2,
1209 &group_cipher,
1210 &pairwise_cipher,
1211 NULL
1212 ) == _SUCCESS) {
1213
1214 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1215
1216 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
1217
1218 psecuritypriv->wpa_psk |= BIT(0);
1219
1220 psecuritypriv->wpa_group_cipher = group_cipher;
1221 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
1222 }
1223
1224 break;
1225
1226 }
1227
1228 if ((p == NULL) || (ie_len == 0))
1229 break;
1230
1231
1232 }
1233
1234 /* wmm */
1235 ie_len = 0;
1236 pmlmepriv->qospriv.qos_option = 0;
1237 if (pregistrypriv->wmm_enable) {
1238
1239 for (p = ie + _BEACON_IE_OFFSET_; ; p += (ie_len + 2)) {
1240
1241 p = rtw_get_ie(
1242 p,
1243 _VENDOR_SPECIFIC_IE_,
1244 &ie_len,
1245 (pbss_network->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2))
1246 );
1247 if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) {
1248
1249 pmlmepriv->qospriv.qos_option = 1;
1250
1251 *(p+8) |= BIT(7);/* QoS Info, support U-APSD */
1252
1253 /* disable all ACM bits since the WMM admission control is not supported */
1254 *(p + 10) &= ~BIT(4); /* BE */
1255 *(p + 14) &= ~BIT(4); /* BK */
1256 *(p + 18) &= ~BIT(4); /* VI */
1257 *(p + 22) &= ~BIT(4); /* VO */
1258
1259 break;
1260 }
1261
1262 if ((p == NULL) || (ie_len == 0))
1263 break;
1264
1265 }
1266 }
1267
1268 /* parsing HT_CAP_IE */
1269 p = rtw_get_ie(
1270 ie + _BEACON_IE_OFFSET_,
1271 _HT_CAPABILITY_IE_,
1272 &ie_len,
1273 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1274 );
1275 if (p && ie_len > 0) {
1276
1277 u8 rf_type = 0;
1278 u8 max_rx_ampdu_factor = 0;
1279 struct rtw_ieee80211_ht_cap *pht_cap = (struct rtw_ieee80211_ht_cap *)(p+2);
1280
1281 pHT_caps_ie = p;
1282
1283 ht_cap = true;
1284 network_type |= WIRELESS_11_24N;
1285
1286 rtw_ht_use_default_setting(padapter);
1287
1288 if (pmlmepriv->htpriv.sgi_20m == false)
1289 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_20));
1290
1291 if (pmlmepriv->htpriv.sgi_40m == false)
1292 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_SGI_40));
1293
1294 if (!TEST_FLAG(pmlmepriv->htpriv.ldpc_cap, LDPC_HT_ENABLE_RX))
1295 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_LDPC_CODING));
1296
1297
1298 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_TX))
1299 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_TX_STBC));
1300
1301
1302 if (!TEST_FLAG(pmlmepriv->htpriv.stbc_cap, STBC_HT_ENABLE_RX))
1303 pht_cap->cap_info &= cpu_to_le16(~(IEEE80211_HT_CAP_RX_STBC_3R));
1304
1305
1306 pht_cap->ampdu_params_info &= ~(
1307 IEEE80211_HT_CAP_AMPDU_FACTOR|IEEE80211_HT_CAP_AMPDU_DENSITY
1308 );
1309
1310 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
1311 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP)) {
1312
1313 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&(0x07<<2));
1314 } else{
1315
1316
1317 pht_cap->ampdu_params_info |= (IEEE80211_HT_CAP_AMPDU_DENSITY&0x00);
1318 }
1319
1320 rtw_hal_get_def_var(
1321 padapter,
1322 HW_VAR_MAX_RX_AMPDU_FACTOR,
1323 &max_rx_ampdu_factor
1324 );
1325 pht_cap->ampdu_params_info |= (
1326 IEEE80211_HT_CAP_AMPDU_FACTOR & max_rx_ampdu_factor
1327 ); /* set Max Rx AMPDU size to 64K */
1328
1329 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
1330 if (rf_type == RF_1T1R) {
1331
1332 pht_cap->supp_mcs_set[0] = 0xff;
1333 pht_cap->supp_mcs_set[1] = 0x0;
1334 }
1335
1336 memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len);
1337
1338 }
1339
1340 /* parsing HT_INFO_IE */
1341 p = rtw_get_ie(
1342 ie + _BEACON_IE_OFFSET_,
1343 _HT_ADD_INFO_IE_,
1344 &ie_len,
1345 (pbss_network->IELength - _BEACON_IE_OFFSET_)
1346 );
1347 if (p && ie_len > 0)
1348 pHT_info_ie = p;
1349
1350
1351 switch (network_type) {
1352
1353 case WIRELESS_11B:
1354 pbss_network->NetworkTypeInUse = Ndis802_11DS;
1355 break;
1356 case WIRELESS_11G:
1357 case WIRELESS_11BG:
1358 case WIRELESS_11G_24N:
1359 case WIRELESS_11BG_24N:
1360 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
1361 break;
1362 case WIRELESS_11A:
1363 pbss_network->NetworkTypeInUse = Ndis802_11OFDM5;
1364 break;
1365 default:
1366 pbss_network->NetworkTypeInUse = Ndis802_11OFDM24;
1367 break;
1368 }
1369
1370 pmlmepriv->cur_network.network_type = network_type;
1371
1372 pmlmepriv->htpriv.ht_option = false;
1373
1374 if ((psecuritypriv->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
1375 (psecuritypriv->wpa_pairwise_cipher&WPA_CIPHER_TKIP)) {
1376
1377 /* todo: */
1378 /* ht_cap = false; */
1379 }
1380
1381 /* ht_cap */
1382 if (pregistrypriv->ht_enable && ht_cap == true) {
1383
1384 pmlmepriv->htpriv.ht_option = true;
1385 pmlmepriv->qospriv.qos_option = 1;
1386
1387 if (pregistrypriv->ampdu_enable == 1)
1388 pmlmepriv->htpriv.ampdu_enable = true;
1389
1390
1391 HT_caps_handler(padapter, (struct ndis_80211_var_ie *)pHT_caps_ie);
1392
1393 HT_info_handler(padapter, (struct ndis_80211_var_ie *)pHT_info_ie);
1394 }
1395
1396 pbss_network->Length = get_wlan_bssid_ex_sz(
1397 (struct wlan_bssid_ex *)pbss_network
1398 );
1399
1400 /* issue beacon to start bss network */
1401 /* start_bss_network(padapter, (u8 *)pbss_network); */
1402 rtw_startbss_cmd(padapter, RTW_CMDF_WAIT_ACK);
1403
1404
1405 /* alloc sta_info for ap itself */
1406 psta = rtw_get_stainfo(&padapter->stapriv, pbss_network->MacAddress);
1407 if (!psta) {
1408
1409 psta = rtw_alloc_stainfo(&padapter->stapriv, pbss_network->MacAddress);
1410 if (psta == NULL)
1411 return _FAIL;
1412
1413 }
1414
1415 /* update AP's sta info */
1416 update_ap_info(padapter, psta);
1417
1418 psta->state |= WIFI_AP_STATE; /* Aries, add, fix bug of flush_cam_entry at STOP AP mode , 0724 */
1419 rtw_indicate_connect(padapter);
1420
1421 pmlmepriv->cur_network.join_res = true;/* for check if already set beacon */
1422
1423 /* update bc/mc sta_info */
1424 /* update_bmc_sta(padapter); */
1425
1426 return ret;
1427
1428 }
1429
rtw_set_macaddr_acl(struct adapter * padapter,int mode)1430 void rtw_set_macaddr_acl(struct adapter *padapter, int mode)
1431 {
1432 struct sta_priv *pstapriv = &padapter->stapriv;
1433 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1434
1435 DBG_871X("%s, mode =%d\n", __func__, mode);
1436
1437 pacl_list->mode = mode;
1438 }
1439
rtw_acl_add_sta(struct adapter * padapter,u8 * addr)1440 int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1441 {
1442 struct list_head *plist, *phead;
1443 u8 added = false;
1444 int i, ret = 0;
1445 struct rtw_wlan_acl_node *paclnode;
1446 struct sta_priv *pstapriv = &padapter->stapriv;
1447 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1448 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1449
1450 DBG_871X(
1451 "%s(acl_num =%d) =" MAC_FMT "\n",
1452 __func__,
1453 pacl_list->num,
1454 MAC_ARG(addr)
1455 );
1456
1457 if ((NUM_ACL-1) < pacl_list->num)
1458 return (-1);
1459
1460
1461 spin_lock_bh(&(pacl_node_q->lock));
1462
1463 phead = get_list_head(pacl_node_q);
1464 plist = get_next(phead);
1465
1466 while (phead != plist) {
1467
1468 paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
1469 plist = get_next(plist);
1470
1471 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1472
1473 if (paclnode->valid == true) {
1474
1475 added = true;
1476 DBG_871X("%s, sta has been added\n", __func__);
1477 break;
1478 }
1479 }
1480 }
1481
1482 spin_unlock_bh(&(pacl_node_q->lock));
1483
1484
1485 if (added == true)
1486 return ret;
1487
1488
1489 spin_lock_bh(&(pacl_node_q->lock));
1490
1491 for (i = 0; i < NUM_ACL; i++) {
1492
1493 paclnode = &pacl_list->aclnode[i];
1494
1495 if (paclnode->valid == false) {
1496
1497 INIT_LIST_HEAD(&paclnode->list);
1498
1499 memcpy(paclnode->addr, addr, ETH_ALEN);
1500
1501 paclnode->valid = true;
1502
1503 list_add_tail(&paclnode->list, get_list_head(pacl_node_q));
1504
1505 pacl_list->num++;
1506
1507 break;
1508 }
1509 }
1510
1511 DBG_871X("%s, acl_num =%d\n", __func__, pacl_list->num);
1512
1513 spin_unlock_bh(&(pacl_node_q->lock));
1514
1515 return ret;
1516 }
1517
rtw_acl_remove_sta(struct adapter * padapter,u8 * addr)1518 int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1519 {
1520 struct list_head *plist, *phead;
1521 int ret = 0;
1522 struct rtw_wlan_acl_node *paclnode;
1523 struct sta_priv *pstapriv = &padapter->stapriv;
1524 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1525 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
1526 u8 baddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; /* Baddr is used for clearing acl_list */
1527
1528 DBG_871X(
1529 "%s(acl_num =%d) =" MAC_FMT "\n",
1530 __func__,
1531 pacl_list->num,
1532 MAC_ARG(addr)
1533 );
1534
1535 spin_lock_bh(&(pacl_node_q->lock));
1536
1537 phead = get_list_head(pacl_node_q);
1538 plist = get_next(phead);
1539
1540 while (phead != plist) {
1541
1542 paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
1543 plist = get_next(plist);
1544
1545 if (
1546 !memcmp(paclnode->addr, addr, ETH_ALEN) ||
1547 !memcmp(baddr, addr, ETH_ALEN)
1548 ) {
1549
1550 if (paclnode->valid == true) {
1551
1552 paclnode->valid = false;
1553
1554 list_del_init(&paclnode->list);
1555
1556 pacl_list->num--;
1557 }
1558 }
1559 }
1560
1561 spin_unlock_bh(&(pacl_node_q->lock));
1562
1563 DBG_871X("%s, acl_num =%d\n", __func__, pacl_list->num);
1564
1565 return ret;
1566
1567 }
1568
rtw_ap_set_pairwise_key(struct adapter * padapter,struct sta_info * psta)1569 u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta)
1570 {
1571 struct cmd_obj *ph2c;
1572 struct set_stakey_parm *psetstakey_para;
1573 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1574 u8 res = _SUCCESS;
1575
1576 ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
1577 if (ph2c == NULL) {
1578 res = _FAIL;
1579 goto exit;
1580 }
1581
1582 psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
1583 if (psetstakey_para == NULL) {
1584 kfree((u8 *) ph2c);
1585 res = _FAIL;
1586 goto exit;
1587 }
1588
1589 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
1590
1591
1592 psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
1593
1594 memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN);
1595
1596 memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16);
1597
1598
1599 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
1600
1601 exit:
1602
1603 return res;
1604
1605 }
1606
rtw_ap_set_key(struct adapter * padapter,u8 * key,u8 alg,int keyid,u8 set_tx)1607 static int rtw_ap_set_key(
1608 struct adapter *padapter,
1609 u8 *key,
1610 u8 alg,
1611 int keyid,
1612 u8 set_tx
1613 )
1614 {
1615 u8 keylen;
1616 struct cmd_obj *pcmd;
1617 struct setkey_parm *psetkeyparm;
1618 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
1619 int res = _SUCCESS;
1620
1621 /* DBG_871X("%s\n", __func__); */
1622
1623 pcmd = rtw_zmalloc(sizeof(struct cmd_obj));
1624 if (pcmd == NULL) {
1625 res = _FAIL;
1626 goto exit;
1627 }
1628 psetkeyparm = rtw_zmalloc(sizeof(struct setkey_parm));
1629 if (psetkeyparm == NULL) {
1630 kfree((unsigned char *)pcmd);
1631 res = _FAIL;
1632 goto exit;
1633 }
1634
1635 memset(psetkeyparm, 0, sizeof(struct setkey_parm));
1636
1637 psetkeyparm->keyid = (u8)keyid;
1638 if (is_wep_enc(alg))
1639 padapter->securitypriv.key_mask |= BIT(psetkeyparm->keyid);
1640
1641 psetkeyparm->algorithm = alg;
1642
1643 psetkeyparm->set_tx = set_tx;
1644
1645 switch (alg) {
1646
1647 case _WEP40_:
1648 keylen = 5;
1649 break;
1650 case _WEP104_:
1651 keylen = 13;
1652 break;
1653 case _TKIP_:
1654 case _TKIP_WTMIC_:
1655 case _AES_:
1656 default:
1657 keylen = 16;
1658 }
1659
1660 memcpy(&(psetkeyparm->key[0]), key, keylen);
1661
1662 pcmd->cmdcode = _SetKey_CMD_;
1663 pcmd->parmbuf = (u8 *)psetkeyparm;
1664 pcmd->cmdsz = (sizeof(struct setkey_parm));
1665 pcmd->rsp = NULL;
1666 pcmd->rspsz = 0;
1667
1668
1669 INIT_LIST_HEAD(&pcmd->list);
1670
1671 res = rtw_enqueue_cmd(pcmdpriv, pcmd);
1672
1673 exit:
1674
1675 return res;
1676 }
1677
rtw_ap_set_group_key(struct adapter * padapter,u8 * key,u8 alg,int keyid)1678 int rtw_ap_set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid)
1679 {
1680 DBG_871X("%s\n", __func__);
1681
1682 return rtw_ap_set_key(padapter, key, alg, keyid, 1);
1683 }
1684
rtw_ap_set_wep_key(struct adapter * padapter,u8 * key,u8 keylen,int keyid,u8 set_tx)1685 int rtw_ap_set_wep_key(
1686 struct adapter *padapter,
1687 u8 *key,
1688 u8 keylen,
1689 int keyid,
1690 u8 set_tx
1691 )
1692 {
1693 u8 alg;
1694
1695 switch (keylen) {
1696
1697 case 5:
1698 alg = _WEP40_;
1699 break;
1700 case 13:
1701 alg = _WEP104_;
1702 break;
1703 default:
1704 alg = _NO_PRIVACY_;
1705 }
1706
1707 DBG_871X("%s\n", __func__);
1708
1709 return rtw_ap_set_key(padapter, key, alg, keyid, set_tx);
1710 }
1711
update_bcn_fixed_ie(struct adapter * padapter)1712 static void update_bcn_fixed_ie(struct adapter *padapter)
1713 {
1714 DBG_871X("%s\n", __func__);
1715
1716 }
1717
update_bcn_erpinfo_ie(struct adapter * padapter)1718 static void update_bcn_erpinfo_ie(struct adapter *padapter)
1719 {
1720 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1721 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1722 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1723 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
1724 unsigned char *p, *ie = pnetwork->IEs;
1725 u32 len = 0;
1726
1727 DBG_871X("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1728
1729 if (!pmlmeinfo->ERP_enable)
1730 return;
1731
1732 /* parsing ERP_IE */
1733 p = rtw_get_ie(
1734 ie + _BEACON_IE_OFFSET_,
1735 _ERPINFO_IE_,
1736 &len,
1737 (pnetwork->IELength - _BEACON_IE_OFFSET_)
1738 );
1739 if (p && len > 0) {
1740
1741 struct ndis_80211_var_ie *pIE = (struct ndis_80211_var_ie *)p;
1742
1743 if (pmlmepriv->num_sta_non_erp == 1)
1744 pIE->data[0] |= RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION;
1745 else
1746 pIE->data[0] &= ~(
1747 RTW_ERP_INFO_NON_ERP_PRESENT|RTW_ERP_INFO_USE_PROTECTION
1748 );
1749
1750 if (pmlmepriv->num_sta_no_short_preamble > 0)
1751 pIE->data[0] |= RTW_ERP_INFO_BARKER_PREAMBLE_MODE;
1752 else
1753 pIE->data[0] &= ~(RTW_ERP_INFO_BARKER_PREAMBLE_MODE);
1754
1755 ERP_IE_handler(padapter, pIE);
1756 }
1757
1758 }
1759
update_bcn_htcap_ie(struct adapter * padapter)1760 static void update_bcn_htcap_ie(struct adapter *padapter)
1761 {
1762 DBG_871X("%s\n", __func__);
1763
1764 }
1765
update_bcn_htinfo_ie(struct adapter * padapter)1766 static void update_bcn_htinfo_ie(struct adapter *padapter)
1767 {
1768 DBG_871X("%s\n", __func__);
1769
1770 }
1771
update_bcn_rsn_ie(struct adapter * padapter)1772 static void update_bcn_rsn_ie(struct adapter *padapter)
1773 {
1774 DBG_871X("%s\n", __func__);
1775
1776 }
1777
update_bcn_wpa_ie(struct adapter * padapter)1778 static void update_bcn_wpa_ie(struct adapter *padapter)
1779 {
1780 DBG_871X("%s\n", __func__);
1781
1782 }
1783
update_bcn_wmm_ie(struct adapter * padapter)1784 static void update_bcn_wmm_ie(struct adapter *padapter)
1785 {
1786 DBG_871X("%s\n", __func__);
1787
1788 }
1789
update_bcn_wps_ie(struct adapter * padapter)1790 static void update_bcn_wps_ie(struct adapter *padapter)
1791 {
1792 u8 *pwps_ie = NULL;
1793 u8 *pwps_ie_src;
1794 u8 *premainder_ie;
1795 u8 *pbackup_remainder_ie = NULL;
1796
1797 uint wps_ielen = 0, wps_offset, remainder_ielen;
1798 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1799 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1800 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1801 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
1802 unsigned char *ie = pnetwork->IEs;
1803 u32 ielen = pnetwork->IELength;
1804
1805
1806 DBG_871X("%s\n", __func__);
1807
1808 pwps_ie = rtw_get_wps_ie(
1809 ie+_FIXED_IE_LENGTH_,
1810 ielen-_FIXED_IE_LENGTH_,
1811 NULL,
1812 &wps_ielen
1813 );
1814
1815 if (pwps_ie == NULL || wps_ielen == 0)
1816 return;
1817
1818 pwps_ie_src = pmlmepriv->wps_beacon_ie;
1819 if (pwps_ie_src == NULL)
1820 return;
1821
1822 wps_offset = (uint)(pwps_ie-ie);
1823
1824 premainder_ie = pwps_ie + wps_ielen;
1825
1826 remainder_ielen = ielen - wps_offset - wps_ielen;
1827
1828 if (remainder_ielen > 0) {
1829
1830 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
1831 if (pbackup_remainder_ie)
1832 memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
1833 }
1834
1835 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
1836 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
1837
1838 memcpy(pwps_ie, pwps_ie_src, wps_ielen+2);
1839 pwps_ie += (wps_ielen+2);
1840
1841 if (pbackup_remainder_ie)
1842 memcpy(pwps_ie, pbackup_remainder_ie, remainder_ielen);
1843
1844 /* update IELength */
1845 pnetwork->IELength = wps_offset + (wps_ielen+2) + remainder_ielen;
1846 }
1847
1848 kfree(pbackup_remainder_ie);
1849
1850 /* deal with the case without set_tx_beacon_cmd() in update_beacon() */
1851 #if defined(CONFIG_INTERRUPT_BASED_TXBCN)
1852 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
1853
1854 u8 sr = 0;
1855
1856 rtw_get_wps_attr_content(
1857 pwps_ie_src,
1858 wps_ielen,
1859 WPS_ATTR_SELECTED_REGISTRAR,
1860 (u8 *)(&sr),
1861 NULL
1862 );
1863
1864 if (sr) {
1865 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
1866 DBG_871X("%s, set WIFI_UNDER_WPS\n", __func__);
1867 }
1868 }
1869 #endif
1870 }
1871
update_bcn_p2p_ie(struct adapter * padapter)1872 static void update_bcn_p2p_ie(struct adapter *padapter)
1873 {
1874
1875 }
1876
update_bcn_vendor_spec_ie(struct adapter * padapter,u8 * oui)1877 static void update_bcn_vendor_spec_ie(struct adapter *padapter, u8 *oui)
1878 {
1879 DBG_871X("%s\n", __func__);
1880
1881 if (!memcmp(RTW_WPA_OUI, oui, 4))
1882 update_bcn_wpa_ie(padapter);
1883
1884 else if (!memcmp(WMM_OUI, oui, 4))
1885 update_bcn_wmm_ie(padapter);
1886
1887 else if (!memcmp(WPS_OUI, oui, 4))
1888 update_bcn_wps_ie(padapter);
1889
1890 else if (!memcmp(P2P_OUI, oui, 4))
1891 update_bcn_p2p_ie(padapter);
1892
1893 else
1894 DBG_871X("unknown OUI type!\n");
1895
1896
1897
1898 }
1899
update_beacon(struct adapter * padapter,u8 ie_id,u8 * oui,u8 tx)1900 void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1901 {
1902 struct mlme_priv *pmlmepriv;
1903 struct mlme_ext_priv *pmlmeext;
1904 /* struct mlme_ext_info *pmlmeinfo; */
1905
1906 /* DBG_871X("%s\n", __func__); */
1907
1908 if (!padapter)
1909 return;
1910
1911 pmlmepriv = &(padapter->mlmepriv);
1912 pmlmeext = &(padapter->mlmeextpriv);
1913 /* pmlmeinfo = &(pmlmeext->mlmext_info); */
1914
1915 if (false == pmlmeext->bstart_bss)
1916 return;
1917
1918 spin_lock_bh(&pmlmepriv->bcn_update_lock);
1919
1920 switch (ie_id) {
1921
1922 case 0xFF:
1923
1924 update_bcn_fixed_ie(padapter);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1925
1926 break;
1927
1928 case _TIM_IE_:
1929
1930 update_BCNTIM(padapter);
1931
1932 break;
1933
1934 case _ERPINFO_IE_:
1935
1936 update_bcn_erpinfo_ie(padapter);
1937
1938 break;
1939
1940 case _HT_CAPABILITY_IE_:
1941
1942 update_bcn_htcap_ie(padapter);
1943
1944 break;
1945
1946 case _RSN_IE_2_:
1947
1948 update_bcn_rsn_ie(padapter);
1949
1950 break;
1951
1952 case _HT_ADD_INFO_IE_:
1953
1954 update_bcn_htinfo_ie(padapter);
1955
1956 break;
1957
1958 case _VENDOR_SPECIFIC_IE_:
1959
1960 update_bcn_vendor_spec_ie(padapter, oui);
1961
1962 break;
1963
1964 default:
1965 break;
1966 }
1967
1968 pmlmepriv->update_bcn = true;
1969
1970 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
1971
1972 #ifndef CONFIG_INTERRUPT_BASED_TXBCN
1973 if (tx) {
1974
1975 /* send_beacon(padapter);//send_beacon must execute on TSR level */
1976 set_tx_beacon_cmd(padapter);
1977 }
1978 #endif /* CONFIG_INTERRUPT_BASED_TXBCN */
1979
1980 }
1981
1982 /*
1983 op_mode
1984 Set to 0 (HT pure) under the followign conditions
1985 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1986 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1987 Set to 1 (HT non-member protection) if there may be non-HT STAs
1988 in both the primary and the secondary channel
1989 Set to 2 if only HT STAs are associated in BSS,
1990 however and at least one 20 MHz HT STA is associated
1991 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1992 (currently non-GF HT station is considered as non-HT STA also)
1993 */
rtw_ht_operation_update(struct adapter * padapter)1994 static int rtw_ht_operation_update(struct adapter *padapter)
1995 {
1996 u16 cur_op_mode, new_op_mode;
1997 int op_mode_changes = 0;
1998 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1999 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
2000
2001 if (pmlmepriv->htpriv.ht_option == true)
2002 return 0;
2003
2004 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */
2005 /* return 0; */
2006
2007 DBG_871X("%s current operation mode = 0x%X\n",
2008 __func__, pmlmepriv->ht_op_mode);
2009
2010 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
2011 && pmlmepriv->num_sta_ht_no_gf) {
2012 pmlmepriv->ht_op_mode |=
2013 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
2014 op_mode_changes++;
2015 } else if ((pmlmepriv->ht_op_mode &
2016 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
2017 pmlmepriv->num_sta_ht_no_gf == 0) {
2018 pmlmepriv->ht_op_mode &=
2019 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
2020 op_mode_changes++;
2021 }
2022
2023 if (!(pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
2024 (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
2025 pmlmepriv->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
2026 op_mode_changes++;
2027 } else if ((pmlmepriv->ht_op_mode &
2028 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
2029 (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
2030 pmlmepriv->ht_op_mode &=
2031 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
2032 op_mode_changes++;
2033 }
2034
2035 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
2036 * station is associated. Probably it's a theoretical case, since
2037 * it looks like all known HT STAs support greenfield.
2038 */
2039 new_op_mode = 0;
2040 if (pmlmepriv->num_sta_no_ht ||
2041 (pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
2042 new_op_mode = OP_MODE_MIXED;
2043 else if (
2044 (le16_to_cpu(phtpriv_ap->ht_cap.cap_info) & IEEE80211_HT_CAP_SUP_WIDTH)
2045 && pmlmepriv->num_sta_ht_20mhz)
2046 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
2047 else if (pmlmepriv->olbc_ht)
2048 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
2049 else
2050 new_op_mode = OP_MODE_PURE;
2051
2052 cur_op_mode = pmlmepriv->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
2053 if (cur_op_mode != new_op_mode) {
2054 pmlmepriv->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
2055 pmlmepriv->ht_op_mode |= new_op_mode;
2056 op_mode_changes++;
2057 }
2058
2059 DBG_871X("%s new operation mode = 0x%X changes =%d\n",
2060 __func__, pmlmepriv->ht_op_mode, op_mode_changes);
2061
2062 return op_mode_changes;
2063
2064 }
2065
associated_clients_update(struct adapter * padapter,u8 updated)2066 void associated_clients_update(struct adapter *padapter, u8 updated)
2067 {
2068 /* update associcated stations cap. */
2069 if (updated == true) {
2070
2071 struct list_head *phead, *plist;
2072 struct sta_info *psta = NULL;
2073 struct sta_priv *pstapriv = &padapter->stapriv;
2074
2075 spin_lock_bh(&pstapriv->asoc_list_lock);
2076
2077 phead = &pstapriv->asoc_list;
2078 plist = get_next(phead);
2079
2080 /* check asoc_queue */
2081 while (phead != plist) {
2082
2083 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
2084
2085 plist = get_next(plist);
2086
2087 VCS_update(padapter, psta);
2088 }
2089
2090 spin_unlock_bh(&pstapriv->asoc_list_lock);
2091
2092 }
2093
2094 }
2095
2096 /* called > TSR LEVEL for USB or SDIO Interface*/
bss_cap_update_on_sta_join(struct adapter * padapter,struct sta_info * psta)2097 void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
2098 {
2099 u8 beacon_updated = false;
2100 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2101 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2102
2103 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
2104
2105 if (!psta->no_short_preamble_set) {
2106
2107 psta->no_short_preamble_set = 1;
2108
2109 pmlmepriv->num_sta_no_short_preamble++;
2110
2111 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
2112 (pmlmepriv->num_sta_no_short_preamble == 1)) {
2113
2114 beacon_updated = true;
2115 update_beacon(padapter, 0xFF, NULL, true);
2116 }
2117
2118 }
2119 } else{
2120
2121
2122 if (psta->no_short_preamble_set) {
2123
2124 psta->no_short_preamble_set = 0;
2125
2126 pmlmepriv->num_sta_no_short_preamble--;
2127
2128 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
2129 (pmlmepriv->num_sta_no_short_preamble == 0)) {
2130
2131 beacon_updated = true;
2132 update_beacon(padapter, 0xFF, NULL, true);
2133 }
2134
2135 }
2136 }
2137
2138 if (psta->flags & WLAN_STA_NONERP) {
2139
2140 if (!psta->nonerp_set) {
2141
2142 psta->nonerp_set = 1;
2143
2144 pmlmepriv->num_sta_non_erp++;
2145
2146 if (pmlmepriv->num_sta_non_erp == 1) {
2147
2148 beacon_updated = true;
2149 update_beacon(padapter, _ERPINFO_IE_, NULL, true);
2150 }
2151 }
2152
2153 } else{
2154
2155
2156 if (psta->nonerp_set) {
2157
2158 psta->nonerp_set = 0;
2159
2160 pmlmepriv->num_sta_non_erp--;
2161
2162 if (pmlmepriv->num_sta_non_erp == 0) {
2163
2164 beacon_updated = true;
2165 update_beacon(padapter, _ERPINFO_IE_, NULL, true);
2166 }
2167 }
2168
2169 }
2170
2171
2172 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT)) {
2173
2174 if (!psta->no_short_slot_time_set) {
2175
2176 psta->no_short_slot_time_set = 1;
2177
2178 pmlmepriv->num_sta_no_short_slot_time++;
2179
2180 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
2181 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
2182
2183 beacon_updated = true;
2184 update_beacon(padapter, 0xFF, NULL, true);
2185 }
2186
2187 }
2188 } else{
2189
2190
2191 if (psta->no_short_slot_time_set) {
2192
2193 psta->no_short_slot_time_set = 0;
2194
2195 pmlmepriv->num_sta_no_short_slot_time--;
2196
2197 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
2198 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
2199
2200 beacon_updated = true;
2201 update_beacon(padapter, 0xFF, NULL, true);
2202 }
2203 }
2204 }
2205
2206 if (psta->flags & WLAN_STA_HT) {
2207
2208 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
2209
2210 DBG_871X("HT: STA " MAC_FMT " HT Capabilities "
2211 "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
2212
2213 if (psta->no_ht_set) {
2214 psta->no_ht_set = 0;
2215 pmlmepriv->num_sta_no_ht--;
2216 }
2217
2218 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
2219 if (!psta->no_ht_gf_set) {
2220 psta->no_ht_gf_set = 1;
2221 pmlmepriv->num_sta_ht_no_gf++;
2222 }
2223 DBG_871X("%s STA " MAC_FMT " - no "
2224 "greenfield, num of non-gf stations %d\n",
2225 __func__, MAC_ARG(psta->hwaddr),
2226 pmlmepriv->num_sta_ht_no_gf);
2227 }
2228
2229 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
2230 if (!psta->ht_20mhz_set) {
2231 psta->ht_20mhz_set = 1;
2232 pmlmepriv->num_sta_ht_20mhz++;
2233 }
2234 DBG_871X("%s STA " MAC_FMT " - 20 MHz HT, "
2235 "num of 20MHz HT STAs %d\n",
2236 __func__, MAC_ARG(psta->hwaddr),
2237 pmlmepriv->num_sta_ht_20mhz);
2238 }
2239
2240 } else{
2241
2242
2243 if (!psta->no_ht_set) {
2244 psta->no_ht_set = 1;
2245 pmlmepriv->num_sta_no_ht++;
2246 }
2247 if (pmlmepriv->htpriv.ht_option == true) {
2248 DBG_871X("%s STA " MAC_FMT
2249 " - no HT, num of non-HT stations %d\n",
2250 __func__, MAC_ARG(psta->hwaddr),
2251 pmlmepriv->num_sta_no_ht);
2252 }
2253 }
2254
2255 if (rtw_ht_operation_update(padapter) > 0) {
2256
2257 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
2258 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
2259 }
2260
2261 /* update associcated stations cap. */
2262 associated_clients_update(padapter, beacon_updated);
2263
2264 DBG_871X("%s, updated =%d\n", __func__, beacon_updated);
2265
2266 }
2267
bss_cap_update_on_sta_leave(struct adapter * padapter,struct sta_info * psta)2268 u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
2269 {
2270 u8 beacon_updated = false;
2271 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2272 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2273
2274 if (!psta)
2275 return beacon_updated;
2276
2277 if (psta->no_short_preamble_set) {
2278 psta->no_short_preamble_set = 0;
2279 pmlmepriv->num_sta_no_short_preamble--;
2280 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
2281 && pmlmepriv->num_sta_no_short_preamble == 0){
2282
2283 beacon_updated = true;
2284 update_beacon(padapter, 0xFF, NULL, true);
2285 }
2286 }
2287
2288 if (psta->nonerp_set) {
2289 psta->nonerp_set = 0;
2290 pmlmepriv->num_sta_non_erp--;
2291 if (pmlmepriv->num_sta_non_erp == 0) {
2292
2293 beacon_updated = true;
2294 update_beacon(padapter, _ERPINFO_IE_, NULL, true);
2295 }
2296 }
2297
2298 if (psta->no_short_slot_time_set) {
2299 psta->no_short_slot_time_set = 0;
2300 pmlmepriv->num_sta_no_short_slot_time--;
2301 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
2302 && pmlmepriv->num_sta_no_short_slot_time == 0){
2303
2304 beacon_updated = true;
2305 update_beacon(padapter, 0xFF, NULL, true);
2306 }
2307 }
2308
2309 if (psta->no_ht_gf_set) {
2310 psta->no_ht_gf_set = 0;
2311 pmlmepriv->num_sta_ht_no_gf--;
2312 }
2313
2314 if (psta->no_ht_set) {
2315 psta->no_ht_set = 0;
2316 pmlmepriv->num_sta_no_ht--;
2317 }
2318
2319 if (psta->ht_20mhz_set) {
2320 psta->ht_20mhz_set = 0;
2321 pmlmepriv->num_sta_ht_20mhz--;
2322 }
2323
2324 if (rtw_ht_operation_update(padapter) > 0) {
2325
2326 update_beacon(padapter, _HT_CAPABILITY_IE_, NULL, false);
2327 update_beacon(padapter, _HT_ADD_INFO_IE_, NULL, true);
2328 }
2329
2330 /* update associcated stations cap. */
2331 /* associated_clients_update(padapter, beacon_updated); //move it to avoid deadlock */
2332
2333 DBG_871X("%s, updated =%d\n", __func__, beacon_updated);
2334
2335 return beacon_updated;
2336
2337 }
2338
ap_free_sta(struct adapter * padapter,struct sta_info * psta,bool active,u16 reason)2339 u8 ap_free_sta(
2340 struct adapter *padapter,
2341 struct sta_info *psta,
2342 bool active,
2343 u16 reason
2344 )
2345 {
2346 u8 beacon_updated = false;
2347
2348 if (!psta)
2349 return beacon_updated;
2350
2351 if (active == true) {
2352
2353 /* tear down Rx AMPDU */
2354 send_delba(padapter, 0, psta->hwaddr);/* recipient */
2355
2356 /* tear down TX AMPDU */
2357 send_delba(padapter, 1, psta->hwaddr);/* // originator */
2358
2359 issue_deauth(padapter, psta->hwaddr, reason);
2360 }
2361
2362 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
2363 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
2364
2365
2366 /* report_del_sta_event(padapter, psta->hwaddr, reason); */
2367
2368 /* clear cam entry / key */
2369 rtw_clearstakey_cmd(padapter, psta, true);
2370
2371
2372 spin_lock_bh(&psta->lock);
2373 psta->state &= ~_FW_LINKED;
2374 spin_unlock_bh(&psta->lock);
2375
2376 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
2377
2378 report_del_sta_event(padapter, psta->hwaddr, reason);
2379
2380 beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
2381
2382 rtw_free_stainfo(padapter, psta);
2383
2384
2385 return beacon_updated;
2386
2387 }
2388
rtw_sta_flush(struct adapter * padapter)2389 int rtw_sta_flush(struct adapter *padapter)
2390 {
2391 struct list_head *phead, *plist;
2392 int ret = 0;
2393 struct sta_info *psta = NULL;
2394 struct sta_priv *pstapriv = &padapter->stapriv;
2395 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2396 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2397 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2398
2399 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
2400
2401 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
2402 return ret;
2403
2404
2405 spin_lock_bh(&pstapriv->asoc_list_lock);
2406 phead = &pstapriv->asoc_list;
2407 plist = get_next(phead);
2408
2409 /* free sta asoc_queue */
2410 while (phead != plist) {
2411
2412 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
2413
2414 plist = get_next(plist);
2415
2416 list_del_init(&psta->asoc_list);
2417 pstapriv->asoc_list_cnt--;
2418
2419 /* spin_unlock_bh(&pstapriv->asoc_list_lock); */
2420 ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
2421 /* spin_lock_bh(&pstapriv->asoc_list_lock); */
2422 }
2423 spin_unlock_bh(&pstapriv->asoc_list_lock);
2424
2425
2426 issue_deauth(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
2427
2428 associated_clients_update(padapter, true);
2429
2430 return ret;
2431
2432 }
2433
2434 /* called > TSR LEVEL for USB or SDIO Interface*/
sta_info_update(struct adapter * padapter,struct sta_info * psta)2435 void sta_info_update(struct adapter *padapter, struct sta_info *psta)
2436 {
2437 int flags = psta->flags;
2438 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2439
2440
2441 /* update wmm cap. */
2442 if (WLAN_STA_WME&flags)
2443 psta->qos_option = 1;
2444 else
2445 psta->qos_option = 0;
2446
2447 if (pmlmepriv->qospriv.qos_option == 0)
2448 psta->qos_option = 0;
2449
2450 /* update 802.11n ht cap. */
2451 if (WLAN_STA_HT&flags) {
2452
2453 psta->htpriv.ht_option = true;
2454 psta->qos_option = 1;
2455 } else{
2456
2457
2458 psta->htpriv.ht_option = false;
2459 }
2460
2461 if (pmlmepriv->htpriv.ht_option == false)
2462 psta->htpriv.ht_option = false;
2463
2464 update_sta_info_apmode(padapter, psta);
2465
2466
2467 }
2468
2469 /* called >= TSR LEVEL for USB or SDIO Interface*/
ap_sta_info_defer_update(struct adapter * padapter,struct sta_info * psta)2470 void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta)
2471 {
2472 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2473 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2474
2475 if (psta->state & _FW_LINKED) {
2476
2477 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
2478
2479 /* add ratid */
2480 add_RATid(padapter, psta, 0);/* DM_RATR_STA_INIT */
2481 }
2482 }
2483 /* restore hw setting from sw data structures */
rtw_ap_restore_network(struct adapter * padapter)2484 void rtw_ap_restore_network(struct adapter *padapter)
2485 {
2486 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2487 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2488 struct sta_priv *pstapriv = &padapter->stapriv;
2489 struct sta_info *psta;
2490 struct security_priv *psecuritypriv = &(padapter->securitypriv);
2491 struct list_head *phead, *plist;
2492 u8 chk_alive_num = 0;
2493 char chk_alive_list[NUM_STA];
2494 int i;
2495
2496 rtw_setopmode_cmd(padapter, Ndis802_11APMode, false);
2497
2498 set_channel_bwmode(
2499 padapter,
2500 pmlmeext->cur_channel,
2501 pmlmeext->cur_ch_offset,
2502 pmlmeext->cur_bwmode
2503 );
2504
2505 start_bss_network(padapter, (u8 *)&mlmepriv->cur_network.network);
2506
2507 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
2508 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
2509
2510 /* restore group key, WEP keys is restored in ips_leave() */
2511 rtw_set_key(
2512 padapter,
2513 psecuritypriv,
2514 psecuritypriv->dot118021XGrpKeyid,
2515 0,
2516 false
2517 );
2518 }
2519
2520 spin_lock_bh(&pstapriv->asoc_list_lock);
2521
2522 phead = &pstapriv->asoc_list;
2523 plist = get_next(phead);
2524
2525 while (phead != plist) {
2526 int stainfo_offset;
2527
2528 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
2529 plist = get_next(plist);
2530
2531 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
2532 if (stainfo_offset_valid(stainfo_offset))
2533 chk_alive_list[chk_alive_num++] = stainfo_offset;
2534
2535 }
2536
2537 spin_unlock_bh(&pstapriv->asoc_list_lock);
2538
2539 for (i = 0; i < chk_alive_num; i++) {
2540 psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);
2541
2542 if (psta == NULL) {
2543 DBG_871X(FUNC_ADPT_FMT" sta_info is null\n", FUNC_ADPT_ARG(padapter));
2544 } else if (psta->state & _FW_LINKED) {
2545 rtw_sta_media_status_rpt(padapter, psta, 1);
2546 Update_RA_Entry(padapter, psta);
2547 /* pairwise key */
2548 /* per sta pairwise key and settings */
2549 if ((padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_) ||
2550 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
2551
2552 rtw_setstakey_cmd(padapter, psta, true, false);
2553 }
2554 }
2555 }
2556
2557 }
2558
start_ap_mode(struct adapter * padapter)2559 void start_ap_mode(struct adapter *padapter)
2560 {
2561 int i;
2562 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2563 struct sta_priv *pstapriv = &padapter->stapriv;
2564 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2565 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
2566
2567 pmlmepriv->update_bcn = false;
2568
2569 /* init_mlme_ap_info(padapter); */
2570 pmlmeext->bstart_bss = false;
2571
2572 pmlmepriv->num_sta_non_erp = 0;
2573
2574 pmlmepriv->num_sta_no_short_slot_time = 0;
2575
2576 pmlmepriv->num_sta_no_short_preamble = 0;
2577
2578 pmlmepriv->num_sta_ht_no_gf = 0;
2579 pmlmepriv->num_sta_no_ht = 0;
2580 pmlmepriv->num_sta_ht_20mhz = 0;
2581
2582 pmlmepriv->olbc = false;
2583
2584 pmlmepriv->olbc_ht = false;
2585
2586 pmlmepriv->ht_op_mode = 0;
2587
2588 for (i = 0; i < NUM_STA; i++)
2589 pstapriv->sta_aid[i] = NULL;
2590
2591 pmlmepriv->wps_beacon_ie = NULL;
2592 pmlmepriv->wps_probe_resp_ie = NULL;
2593 pmlmepriv->wps_assoc_resp_ie = NULL;
2594
2595 pmlmepriv->p2p_beacon_ie = NULL;
2596 pmlmepriv->p2p_probe_resp_ie = NULL;
2597
2598
2599 /* for ACL */
2600 INIT_LIST_HEAD(&(pacl_list->acl_node_q.queue));
2601 pacl_list->num = 0;
2602 pacl_list->mode = 0;
2603 for (i = 0; i < NUM_ACL; i++) {
2604 INIT_LIST_HEAD(&pacl_list->aclnode[i].list);
2605 pacl_list->aclnode[i].valid = false;
2606 }
2607
2608 }
2609
stop_ap_mode(struct adapter * padapter)2610 void stop_ap_mode(struct adapter *padapter)
2611 {
2612 struct list_head *phead, *plist;
2613 struct rtw_wlan_acl_node *paclnode;
2614 struct sta_info *psta = NULL;
2615 struct sta_priv *pstapriv = &padapter->stapriv;
2616 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2617 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2618 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
2619 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
2620
2621 pmlmepriv->update_bcn = false;
2622 pmlmeext->bstart_bss = false;
2623
2624 /* reset and init security priv , this can refine with rtw_reset_securitypriv */
2625 memset(
2626 (unsigned char *)&padapter->securitypriv,
2627 0,
2628 sizeof(struct security_priv)
2629 );
2630 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
2631 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
2632
2633 /* for ACL */
2634 spin_lock_bh(&(pacl_node_q->lock));
2635 phead = get_list_head(pacl_node_q);
2636 plist = get_next(phead);
2637 while (phead != plist) {
2638
2639 paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
2640 plist = get_next(plist);
2641
2642 if (paclnode->valid == true) {
2643
2644 paclnode->valid = false;
2645
2646 list_del_init(&paclnode->list);
2647
2648 pacl_list->num--;
2649 }
2650 }
2651 spin_unlock_bh(&(pacl_node_q->lock));
2652
2653 DBG_871X("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
2654
2655 rtw_sta_flush(padapter);
2656
2657 /* free_assoc_sta_resources */
2658 rtw_free_all_stainfo(padapter);
2659
2660 psta = rtw_get_bcmc_stainfo(padapter);
2661 rtw_free_stainfo(padapter, psta);
2662
2663 rtw_init_bcmc_stainfo(padapter);
2664
2665 rtw_free_mlme_priv_ie_data(pmlmepriv);
2666
2667 rtw_btcoex_MediaStatusNotify(padapter, 0); /* disconnect */
2668 }
2669