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