blob: e394d12c36b0c3b33f9d52b6041a95a2bc20804f [file] [log] [blame]
Larry Finger5e93f352014-03-28 21:37:38 -05001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#define _RTW_AP_C_
16
17#include <osdep_service.h>
18#include <drv_types.h>
19#include <linux/ieee80211.h>
20#include <wifi.h>
Jes Sorensen1ec69342014-05-16 10:04:11 +020021#include <rtl8723a_cmd.h>
Jes Sorensendbe98492014-05-16 10:04:13 +020022#include <rtl8723a_hal.h>
Larry Finger5e93f352014-03-28 21:37:38 -050023
Larry Finger5e93f352014-03-28 21:37:38 -050024extern unsigned char WMM_OUI23A[];
25extern unsigned char WPS_OUI23A[];
26extern unsigned char P2P_OUI23A[];
Larry Finger5e93f352014-03-28 21:37:38 -050027
28void init_mlme_ap_info23a(struct rtw_adapter *padapter)
29{
30 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
31 struct sta_priv *pstapriv = &padapter->stapriv;
32 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
33
34 spin_lock_init(&pmlmepriv->bcn_update_lock);
35
36 /* for ACL */
37 _rtw_init_queue23a(&pacl_list->acl_node_q);
38
39 start_ap_mode23a(padapter);
40}
41
42void free_mlme_ap_info23a(struct rtw_adapter *padapter)
43{
44 struct sta_info *psta = NULL;
45 struct sta_priv *pstapriv = &padapter->stapriv;
46 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
47 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
48 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
49
50 pmlmepriv->update_bcn = false;
51 pmlmeext->bstart_bss = false;
52
53 rtw_sta_flush23a(padapter);
54
Jes Sorensen6ec26272014-07-17 22:59:46 +020055 pmlmeinfo->state = MSR_NOLINK;
Larry Finger5e93f352014-03-28 21:37:38 -050056
57 /* free_assoc_sta_resources */
58 rtw_free_all_stainfo23a(padapter);
59
60 /* free bc/mc sta_info */
61 psta = rtw_get_bcmc_stainfo23a(padapter);
62 spin_lock_bh(&pstapriv->sta_hash_lock);
63 rtw_free_stainfo23a(padapter, psta);
64 spin_unlock_bh(&pstapriv->sta_hash_lock);
65}
66
67static void update_BCNTIM(struct rtw_adapter *padapter)
68{
69 struct sta_priv *pstapriv = &padapter->stapriv;
70 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
71 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
72 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
73 unsigned char *pie = pnetwork_mlmeext->IEs;
74 u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
Larry Fingera96ae6f2014-04-26 18:55:18 +020075 __le16 tim_bitmap_le;
Larry Finger5e93f352014-03-28 21:37:38 -050076 uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
77
78 tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
79
Jes Sorensen1de65cc2014-06-24 15:03:30 +020080 p = rtw_get_ie23a(pie, WLAN_EID_TIM, &tim_ielen,
81 pnetwork_mlmeext->IELength);
MihaelaGamanadabff82014-09-14 12:56:43 +030082 if (p != NULL && tim_ielen > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -050083 tim_ielen += 2;
84
85 premainder_ie = p+tim_ielen;
86
Tapasweni Pathak7d364292014-09-21 19:38:30 +053087 tim_ie_offset = (int)(p - pie);
Larry Finger5e93f352014-03-28 21:37:38 -050088
89 remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
90
91 /* append TIM IE from dst_ie offset */
92 dst_ie = p;
93 } else {
94 tim_ielen = 0;
95
Masanari Iida96b0a5b2014-07-22 23:42:45 +090096 /* calculate head_len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +020097 offset = 0;
Larry Finger5e93f352014-03-28 21:37:38 -050098
99 /* get ssid_ie len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200100 p = rtw_get_ie23a(pie, WLAN_EID_SSID,
101 &tmp_len, pnetwork_mlmeext->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500102 if (p != NULL)
103 offset += tmp_len+2;
104
105 /* get supported rates len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200106 p = rtw_get_ie23a(pie, WLAN_EID_SUPP_RATES,
107 &tmp_len, pnetwork_mlmeext->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500108 if (p != NULL)
109 offset += tmp_len+2;
110
111 /* DS Parameter Set IE, len = 3 */
112 offset += 3;
113
114 premainder_ie = pie + offset;
115
116 remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
117
118 /* append TIM IE from offset */
119 dst_ie = pie + offset;
120 }
121
122 if (remainder_ielen > 0) {
123 pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
124 if (pbackup_remainder_ie && premainder_ie)
125 memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
126 }
127
MihaelaGamanadabff82014-09-14 12:56:43 +0300128 *dst_ie++ = WLAN_EID_TIM;
Larry Finger5e93f352014-03-28 21:37:38 -0500129
130 if ((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fc))
131 tim_ielen = 5;
132 else
133 tim_ielen = 4;
134
MihaelaGamanadabff82014-09-14 12:56:43 +0300135 *dst_ie++ = tim_ielen;
Larry Finger5e93f352014-03-28 21:37:38 -0500136
MihaelaGamanadabff82014-09-14 12:56:43 +0300137 *dst_ie++ = 0;/* DTIM count */
138 *dst_ie++ = 1;/* DTIM period */
Larry Finger5e93f352014-03-28 21:37:38 -0500139
140 if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
141 *dst_ie++ = BIT(0);/* bitmap ctrl */
142 else
143 *dst_ie++ = 0;
144
145 if (tim_ielen == 4) {
Greg Donald7e6646d2014-09-06 19:42:03 -0500146 *dst_ie++ = *(u8 *)&tim_bitmap_le;
Larry Finger5e93f352014-03-28 21:37:38 -0500147 } else if (tim_ielen == 5) {
148 memcpy(dst_ie, &tim_bitmap_le, 2);
MihaelaGamanadabff82014-09-14 12:56:43 +0300149 dst_ie += 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500150 }
151
152 /* copy remainder IE */
153 if (pbackup_remainder_ie) {
154 memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
155
156 kfree(pbackup_remainder_ie);
157 }
158
159 offset = (uint)(dst_ie - pie);
160 pnetwork_mlmeext->IELength = offset + remainder_ielen;
161
162 set_tx_beacon_cmd23a(padapter);
163}
164
165static u8 chk_sta_is_alive(struct sta_info *psta)
166{
167 u8 ret = false;
168
169 if ((psta->sta_stats.last_rx_data_pkts +
170 psta->sta_stats.last_rx_ctrl_pkts) !=
171 (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts))
172 ret = true;
173
174 sta_update_last_rx_pkts(psta);
175
176 return ret;
177}
178
179void expire_timeout_chk23a(struct rtw_adapter *padapter)
180{
181 struct list_head *phead, *plist, *ptmp;
182 u8 updated = 0;
183 struct sta_info *psta;
184 struct sta_priv *pstapriv = &padapter->stapriv;
185 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +0200186 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -0500187 int i;
188
189 spin_lock_bh(&pstapriv->auth_list_lock);
190
191 phead = &pstapriv->auth_list;
192
193 /* check auth_queue */
194 list_for_each_safe(plist, ptmp, phead) {
195 psta = container_of(plist, struct sta_info, auth_list);
196
MihaelaGamanadabff82014-09-14 12:56:43 +0300197 if (psta->expire_to > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -0500198 psta->expire_to--;
199 if (psta->expire_to == 0) {
200 list_del_init(&psta->auth_list);
201 pstapriv->auth_list_cnt--;
202
203 DBG_8723A("auth expire %pM\n", psta->hwaddr);
204
205 spin_unlock_bh(&pstapriv->auth_list_lock);
206
207 spin_lock_bh(&pstapriv->sta_hash_lock);
208 rtw_free_stainfo23a(padapter, psta);
209 spin_unlock_bh(&pstapriv->sta_hash_lock);
210
211 spin_lock_bh(&pstapriv->auth_list_lock);
212 }
213 }
214
215 }
216
217 spin_unlock_bh(&pstapriv->auth_list_lock);
218
219 spin_lock_bh(&pstapriv->asoc_list_lock);
220
221 phead = &pstapriv->asoc_list;
222
223 /* check asoc_queue */
224 list_for_each_safe(plist, ptmp, phead) {
225 psta = container_of(plist, struct sta_info, asoc_list);
226
227 if (chk_sta_is_alive(psta) || !psta->expire_to) {
228 psta->expire_to = pstapriv->expire_to;
229 psta->keep_alive_trycnt = 0;
230 } else {
231 psta->expire_to--;
232 }
233
Tina Ruchandanif2372162014-10-23 20:16:51 -0700234 if (psta->expire_to <= 0) {
Larry Finger5e93f352014-03-28 21:37:38 -0500235 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
236
Tina Ruchandanif2372162014-10-23 20:16:51 -0700237 if (padapter->registrypriv.wifi_spec == 1) {
Larry Finger5e93f352014-03-28 21:37:38 -0500238 psta->expire_to = pstapriv->expire_to;
239 continue;
240 }
241
242 if (psta->state & WIFI_SLEEP_STATE) {
243 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900244 /* to check if alive by another methods if station is at ps mode. */
Larry Finger5e93f352014-03-28 21:37:38 -0500245 psta->expire_to = pstapriv->expire_to;
246 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
247
248 /* to update bcn with tim_bitmap for this station */
249 pstapriv->tim_bitmap |= CHKBIT(psta->aid);
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200250 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500251
252 if (!pmlmeext->active_keep_alive_check)
253 continue;
254 }
255 }
256
257 if (pmlmeext->active_keep_alive_check) {
Jes Sorensen69642132014-05-09 15:03:47 +0200258 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -0500259 continue;
260 }
261
262 list_del_init(&psta->asoc_list);
263 pstapriv->asoc_list_cnt--;
264
265 DBG_8723A("asoc expire "MAC_FMT", state = 0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
266 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
267 } else {
268 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
269 if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
270 && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME/pstapriv->asoc_list_cnt)/2)
271 ) {
272 DBG_8723A("%s sta:"MAC_FMT", sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__,
273 MAC_ARG(psta->hwaddr),
274 psta->sleepq_len,
275 padapter->xmitpriv.free_xmitframe_cnt,
276 pstapriv->asoc_list_cnt);
277 wakeup_sta_to_xmit23a(padapter, psta);
278 }
279 }
280 }
281
282 spin_unlock_bh(&pstapriv->asoc_list_lock);
283
284 if (chk_alive_num) {
285
286 u8 backup_oper_channel = 0;
287 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
288 /* switch to correct channel of current network before issue keep-alive frames */
289 if (rtw_get_oper_ch23a(padapter) != pmlmeext->cur_channel) {
290 backup_oper_channel = rtw_get_oper_ch23a(padapter);
291 SelectChannel23a(padapter, pmlmeext->cur_channel);
Jes Sorensen69642132014-05-09 15:03:47 +0200292 }
Larry Finger5e93f352014-03-28 21:37:38 -0500293
294 /* issue null data to check sta alive*/
295 for (i = 0; i < chk_alive_num; i++) {
296
297 int ret = _FAIL;
298
Jes Sorensen69642132014-05-09 15:03:47 +0200299 psta = chk_alive_list[i];
Aybuke Ozdemirb34ba0c2014-09-28 17:22:36 +0300300 if (!(psta->state & _FW_LINKED))
Larry Finger5e93f352014-03-28 21:37:38 -0500301 continue;
302
303 if (psta->state & WIFI_SLEEP_STATE)
304 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 1, 50);
305 else
306 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 3, 50);
307
308 psta->keep_alive_trycnt++;
Tina Ruchandanif2372162014-10-23 20:16:51 -0700309 if (ret == _SUCCESS) {
Larry Finger5e93f352014-03-28 21:37:38 -0500310 DBG_8723A("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
311 psta->expire_to = pstapriv->expire_to;
312 psta->keep_alive_trycnt = 0;
313 continue;
Tina Ruchandanif2372162014-10-23 20:16:51 -0700314 } else if (psta->keep_alive_trycnt <= 3) {
Larry Finger5e93f352014-03-28 21:37:38 -0500315 DBG_8723A("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
316 psta->expire_to = 1;
317 continue;
318 }
319
320 psta->keep_alive_trycnt = 0;
321
322 DBG_8723A("asoc expire "MAC_FMT", state = 0x%x\n", MAC_ARG(psta->hwaddr), psta->state);
323 spin_lock_bh(&pstapriv->asoc_list_lock);
324 if (!list_empty(&psta->asoc_list)) {
325 list_del_init(&psta->asoc_list);
326 pstapriv->asoc_list_cnt--;
327 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
328 }
329 spin_unlock_bh(&pstapriv->asoc_list_lock);
330
331 }
332
MihaelaGamanadabff82014-09-14 12:56:43 +0300333 if (backup_oper_channel > 0) /* back to the original operation channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500334 SelectChannel23a(padapter, backup_oper_channel);
335}
336
337 associated_clients_update23a(padapter, updated);
338}
339
340void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_level)
341{
342 int i;
343 u8 rf_type;
344 u32 init_rate = 0;
345 unsigned char sta_band = 0, raid, shortGIrate = false;
346 unsigned char limit;
347 unsigned int tx_ra_bitmap = 0;
348 struct ht_priv *psta_ht = NULL;
349 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200350 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500351
352 if (psta)
353 psta_ht = &psta->htpriv;
354 else
355 return;
356
357 if (!(psta->state & _FW_LINKED))
358 return;
359
360 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700361 for (i = 0; i < sizeof(psta->bssrateset); i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500362 if (psta->bssrateset[i])
363 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
364 }
365 /* n mode ra_bitmap */
Jes Sorensenc2370e82014-04-09 23:20:53 +0200366 if (psta_ht->ht_option) {
367 rf_type = rtl8723a_get_rf_type(padapter);
368
Larry Finger5e93f352014-03-28 21:37:38 -0500369 if (rf_type == RF_2T2R)
370 limit = 16;/* 2R */
371 else
372 limit = 8;/* 1R */
373
Jes Sorensen5a4438932014-05-09 15:04:15 +0200374 for (i = 0; i < limit; i++) {
375 if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
376 tx_ra_bitmap |= BIT(i + 12);
Larry Finger5e93f352014-03-28 21:37:38 -0500377 }
378
379 /* max short GI rate */
380 shortGIrate = psta_ht->sgi;
381 }
382
Jes Sorensen37cb9822014-05-21 09:37:40 +0200383 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500384 /* 5G band */
385 if (tx_ra_bitmap & 0xffff000)
386 sta_band |= WIRELESS_11_5N | WIRELESS_11A;
387 else
388 sta_band |= WIRELESS_11A;
389 } else {
390 if (tx_ra_bitmap & 0xffff000)
391 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
392 else if (tx_ra_bitmap & 0xff0)
Aybuke Ozdemirdd609252014-09-28 17:22:37 +0300393 sta_band |= WIRELESS_11G | WIRELESS_11B;
Larry Finger5e93f352014-03-28 21:37:38 -0500394 else
395 sta_band |= WIRELESS_11B;
396 }
397
398 psta->wireless_mode = sta_band;
399
400 raid = networktype_to_raid23a(sta_band);
401 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
402
Tina Ruchandanif2372162014-10-23 20:16:51 -0700403 if (psta->aid < NUM_STA) {
Larry Finger5e93f352014-03-28 21:37:38 -0500404 u8 arg = 0;
405
406 arg = psta->mac_id&0x1f;
407
408 arg |= BIT(7);/* support entry 2~31 */
409
410 if (shortGIrate == true)
411 arg |= BIT(5);
412
413 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
414
415 DBG_8723A("%s => mac_id:%d , raid:%d , bitmap = 0x%x, arg = "
416 "0x%x\n",
417 __func__, psta->mac_id, raid, tx_ra_bitmap, arg);
418
419 /* bitmap[0:27] = tx_rate_bitmap */
420 /* bitmap[28:31]= Rate Adaptive id */
421 /* arg[0:4] = macid */
422 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200423 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, rssi_level);
Larry Finger5e93f352014-03-28 21:37:38 -0500424
425 if (shortGIrate == true)
426 init_rate |= BIT(6);
427
428 /* set ra_id, init_rate */
429 psta->raid = raid;
430 psta->init_rate = init_rate;
431
Tina Ruchandanif2372162014-10-23 20:16:51 -0700432 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500433 DBG_8723A("station aid %d exceed the max number\n", psta->aid);
Larry Finger5e93f352014-03-28 21:37:38 -0500434}
435
436static void update_bmc_sta(struct rtw_adapter *padapter)
437{
438 u32 init_rate = 0;
439 unsigned char network_type, raid;
440 int i, supportRateNum = 0;
441 unsigned int tx_ra_bitmap = 0;
442 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200443 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500444 struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter);
445
Tina Ruchandanif2372162014-10-23 20:16:51 -0700446 if (psta) {
Larry Finger5e93f352014-03-28 21:37:38 -0500447 psta->aid = 0;/* default set to 0 */
448 psta->mac_id = psta->aid + 1;
449
450 psta->qos_option = 0;
451 psta->htpriv.ht_option = false;
452
453 psta->ieee8021x_blocked = 0;
454
Greg Donald7e6646d2014-09-06 19:42:03 -0500455 memset((void *)&psta->sta_stats, 0,
456 sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500457
458 /* prepare for add_RATid23a */
459 supportRateNum = rtw_get_rateset_len23a((u8*)&pcur_network->SupportedRates);
460 network_type = rtw_check_network_type23a((u8*)&pcur_network->SupportedRates, supportRateNum, 1);
461
462 memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
463 psta->bssratelen = supportRateNum;
464
465 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700466 for (i = 0; i < supportRateNum; i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500467 if (psta->bssrateset[i])
468 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
469 }
470
Jes Sorensen37cb9822014-05-21 09:37:40 +0200471 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500472 /* force to A mode. 5G doesn't support CCK rates */
473 network_type = WIRELESS_11A;
474 tx_ra_bitmap = 0x150; /* 6, 12, 24 Mbps */
475 } else {
476 /* force to b mode */
477 network_type = WIRELESS_11B;
478 tx_ra_bitmap = 0xf;
479 }
480
481 raid = networktype_to_raid23a(network_type);
482 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
483
484 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200485 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500486
487 {
488 u8 arg = 0;
489
490 arg = psta->mac_id&0x1f;
491
492 arg |= BIT(7);
493
494 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
495
496 DBG_8723A("update_bmc_sta, mask = 0x%x, arg = 0x%x\n", tx_ra_bitmap, arg);
497
498 /* bitmap[0:27] = tx_rate_bitmap */
499 /* bitmap[28:31]= Rate Adaptive id */
500 /* arg[0:4] = macid */
501 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200502 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, 0);
Larry Finger5e93f352014-03-28 21:37:38 -0500503 }
504
505 /* set ra_id, init_rate */
506 psta->raid = raid;
507 psta->init_rate = init_rate;
508
Larry Finger5e93f352014-03-28 21:37:38 -0500509 spin_lock_bh(&psta->lock);
510 psta->state = _FW_LINKED;
511 spin_unlock_bh(&psta->lock);
512
Tina Ruchandanif2372162014-10-23 20:16:51 -0700513 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500514 DBG_8723A("add_RATid23a_bmc_sta error!\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500515}
516
517/* notes: */
518/* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
519/* MAC_ID = AID+1 for sta in ap/adhoc mode */
520/* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
521/* MAC_ID = 0 for bssid for sta/ap/adhoc */
522/* CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
523
524void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info *psta)
525{
526 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
527 struct security_priv *psecuritypriv = &padapter->securitypriv;
528 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
529 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
530 struct ht_priv *phtpriv_sta = &psta->htpriv;
531 /* set intf_tag to if1 */
532
533 psta->mac_id = psta->aid+1;
534 DBG_8723A("%s\n", __func__);
535
536 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200537 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500538
539 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
540 psta->ieee8021x_blocked = true;
541 else
542 psta->ieee8021x_blocked = false;
543
544 /* update sta's cap */
545
546 /* ERP */
547 VCS_update23a(padapter, psta);
548 /* HT related cap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700549 if (phtpriv_sta->ht_option) {
Larry Finger5e93f352014-03-28 21:37:38 -0500550 /* check if sta supports rx ampdu */
551 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
552
553 /* check if sta support s Short GI */
554 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40))
555 phtpriv_sta->sgi = true;
556
557 /* bwmode */
558 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
559 /* phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_40; */
560 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
561 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
562
563 }
564
565 psta->qos_option = true;
566
Tina Ruchandanif2372162014-10-23 20:16:51 -0700567 } else {
Larry Finger5e93f352014-03-28 21:37:38 -0500568 phtpriv_sta->ampdu_enable = false;
569
570 phtpriv_sta->sgi = false;
571 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
572 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
573 }
574
575 /* Rx AMPDU */
576 send_delba23a(padapter, 0, psta->hwaddr);/* recipient */
577
578 /* TX AMPDU */
579 send_delba23a(padapter, 1, psta->hwaddr);/* originator */
580 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
581 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
582
583 /* todo: init other variables */
584
Greg Donald7e6646d2014-09-06 19:42:03 -0500585 memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500586
587 spin_lock_bh(&psta->lock);
588 psta->state |= _FW_LINKED;
589 spin_unlock_bh(&psta->lock);
590}
591
592static void update_hw_ht_param(struct rtw_adapter *padapter)
593{
594 unsigned char max_AMPDU_len;
595 unsigned char min_MPDU_spacing;
596 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
597 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
598
599 DBG_8723A("%s\n", __func__);
600
601 /* handle A-MPDU parameter field */
602 /*
603 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
604 AMPDU_para [4:2]:Min MPDU Start Spacing
605 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200606 max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
607 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500608
Jes Sorensen65be27d2014-05-31 18:05:11 +0200609 min_MPDU_spacing = (pmlmeinfo->ht_cap.ampdu_params_info &
610 IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500611
Jes Sorensendce610a2014-04-09 23:20:32 +0200612 rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
613 rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
Larry Finger5e93f352014-03-28 21:37:38 -0500614
615 /* Config SM Power Save setting */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200616 pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->ht_cap.cap_info) &
617 IEEE80211_HT_CAP_SM_PS) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500618 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
619 DBG_8723A("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
620}
621
622static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
623{
Jes Sorensen731f9da2014-04-15 19:44:02 +0200624 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -0500625 u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
626 u16 bcn_interval;
627 u32 acparm;
Larry Finger5e93f352014-03-28 21:37:38 -0500628 struct registry_priv *pregpriv = &padapter->registrypriv;
629 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Greg Donald4e66cf02014-08-22 10:57:49 -0500630 struct security_priv *psecuritypriv = &padapter->securitypriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200631 struct wlan_bssid_ex *pnetwork = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500632 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
633 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
634 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200635 struct ieee80211_ht_operation *pht_info = NULL;
Larry Finger5e93f352014-03-28 21:37:38 -0500636
Jes Sorensen143ced22014-06-19 11:37:22 +0200637 bcn_interval = (u16)pnetwork->beacon_interval;
Jes Sorensen37cb9822014-05-21 09:37:40 +0200638 cur_channel = pnetwork->DSConfig;
Roberta Dobrescub9b42242014-10-26 23:30:06 +0200639 cur_bwmode = HT_CHANNEL_WIDTH_20;
Larry Finger5e93f352014-03-28 21:37:38 -0500640 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
641
642 /* check if there is wps ie, */
643 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
644 /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
Jes Sorensen715a8a72014-06-09 15:15:57 +0200645 if (NULL == cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
646 WLAN_OUI_TYPE_MICROSOFT_WPS,
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200647 pnetwork->IEs,
648 pnetwork->IELength))
Larry Finger5e93f352014-03-28 21:37:38 -0500649 pmlmeext->bstart_bss = true;
650
651 /* todo: update wmm, ht cap */
652 /* pmlmeinfo->WMM_enable; */
653 /* pmlmeinfo->HT_enable; */
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200654 if (pmlmepriv->qos_option)
Larry Finger5e93f352014-03-28 21:37:38 -0500655 pmlmeinfo->WMM_enable = true;
656 if (pmlmepriv->htpriv.ht_option) {
657 pmlmeinfo->WMM_enable = true;
658 pmlmeinfo->HT_enable = true;
659
660 update_hw_ht_param(padapter);
661 }
662
663 if (pmlmepriv->cur_network.join_res != true) {
664 /* setting only at first time */
665 /* WEP Key will be set before this function, do not clear CAM. */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200666 if (psecuritypriv->dot11PrivacyAlgrthm !=
667 WLAN_CIPHER_SUITE_WEP40 &&
668 psecuritypriv->dot11PrivacyAlgrthm !=
669 WLAN_CIPHER_SUITE_WEP104)
Larry Finger5e93f352014-03-28 21:37:38 -0500670 flush_all_cam_entry23a(padapter); /* clear CAM */
671 }
672
673 /* set MSR to AP_Mode */
Jes Sorensen6ec26272014-07-17 22:59:46 +0200674 rtl8723a_set_media_status(padapter, MSR_AP);
Larry Finger5e93f352014-03-28 21:37:38 -0500675
676 /* Set BSSID REG */
Jes Sorensen38dd10b2014-04-09 23:20:20 +0200677 hw_var_set_bssid(padapter, pnetwork->MacAddress);
Larry Finger5e93f352014-03-28 21:37:38 -0500678
679 /* Set EDCA param reg */
680 acparm = 0x002F3217; /* VO */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200681 rtl8723a_set_ac_param_vo(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500682 acparm = 0x005E4317; /* VI */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200683 rtl8723a_set_ac_param_vi(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500684 acparm = 0x005ea42b;
Jes Sorensen2487205e2014-04-09 23:20:30 +0200685 rtl8723a_set_ac_param_be(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500686 acparm = 0x0000A444; /* BK */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200687 rtl8723a_set_ac_param_bk(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500688
689 /* Set Security */
Jes Sorensenb8e99162014-04-09 23:20:27 +0200690 val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ?
MihaelaGamanadabff82014-09-14 12:56:43 +0300691 0xcc : 0xcf;
Jes Sorensenb8e99162014-04-09 23:20:27 +0200692 rtl8723a_set_sec_cfg(padapter, val8);
Larry Finger5e93f352014-03-28 21:37:38 -0500693
694 /* Beacon Control related register */
Jes Sorensen477f0082014-04-09 23:20:23 +0200695 rtl8723a_set_beacon_interval(padapter, bcn_interval);
Larry Finger5e93f352014-03-28 21:37:38 -0500696
697 UpdateBrateTbl23a(padapter, pnetwork->SupportedRates);
Jes Sorensenfa2e5202014-04-09 23:20:18 +0200698 HalSetBrateCfg23a(padapter, pnetwork->SupportedRates);
Larry Finger5e93f352014-03-28 21:37:38 -0500699
700 if (!pmlmepriv->cur_network.join_res) {
701 /* setting only at first time */
702
703 /* disable dynamic functions, such as high power, DIG */
704
705 /* turn on all dynamic functions */
Jes Sorensen585eefb2014-04-09 23:20:43 +0200706 rtl8723a_odm_support_ability_set(padapter,
707 DYNAMIC_ALL_FUNC_ENABLE);
Larry Finger5e93f352014-03-28 21:37:38 -0500708 }
709 /* set channel, bwmode */
Jes Sorensenc164bcf2014-05-21 09:37:41 +0200710
Jes Sorensen68e6c792014-06-24 15:03:29 +0200711 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION, pnetwork->IEs,
712 pnetwork->IELength);
Jes Sorensen731f9da2014-04-15 19:44:02 +0200713 if (p && p[1]) {
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200714 pht_info = (struct ieee80211_ht_operation *)(p + 2);
Larry Finger5e93f352014-03-28 21:37:38 -0500715
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200716 if (pregpriv->cbw40_enable && pht_info->ht_param &
717 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) {
Larry Finger5e93f352014-03-28 21:37:38 -0500718 /* switch to the 40M Hz mode */
719 cur_bwmode = HT_CHANNEL_WIDTH_40;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200720 switch (pht_info->ht_param &
721 IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
722 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Jes Sorensen731f9da2014-04-15 19:44:02 +0200723 /* pmlmeext->cur_ch_offset =
724 HAL_PRIME_CHNL_OFFSET_LOWER; */
Larry Finger5e93f352014-03-28 21:37:38 -0500725 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
726 break;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200727 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Larry Finger5e93f352014-03-28 21:37:38 -0500728 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
729 break;
730 default:
731 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
732 break;
733 }
734 }
735 }
736 /* TODO: need to judge the phy parameters on concurrent mode for single phy */
737 set_channel_bwmode23a(padapter, cur_channel, cur_ch_offset, cur_bwmode);
738
739 DBG_8723A("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode,
740 cur_ch_offset);
741
742 pmlmeext->cur_channel = cur_channel;
743 pmlmeext->cur_bwmode = cur_bwmode;
744 pmlmeext->cur_ch_offset = cur_ch_offset;
745 pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
746
747 /* update cur_wireless_mode */
748 update_wireless_mode23a(padapter);
749
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900750 /* update capability after cur_wireless_mode updated */
Jes Sorensena94e12b2014-06-19 11:37:34 +0200751 update_capinfo23a(padapter, pnetwork->capability);
Larry Finger5e93f352014-03-28 21:37:38 -0500752
753 /* let pnetwork_mlmeext == pnetwork_mlme. */
754 memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
755
Larry Finger5e93f352014-03-28 21:37:38 -0500756 if (pmlmeext->bstart_bss) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200757 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500758
759 /* issue beacon frame */
760 if (send_beacon23a(padapter) == _FAIL)
761 DBG_8723A("issue_beacon23a, fail!\n");
762 }
763
764 /* update bc/mc sta_info */
765 update_bmc_sta(padapter);
766}
767
Jes Sorensenfb5fd462014-06-24 15:03:20 +0200768int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
769 struct ieee80211_mgmt *mgmt, unsigned int len)
Larry Finger5e93f352014-03-28 21:37:38 -0500770{
771 int ret = _SUCCESS;
772 u8 *p;
773 u8 *pHT_caps_ie = NULL;
774 u8 *pHT_info_ie = NULL;
775 struct sta_info *psta = NULL;
Jes Sorensen51a26d22014-06-24 15:03:21 +0200776 u16 ht_cap = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500777 uint ie_len = 0;
778 int group_cipher, pairwise_cipher;
779 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
780 int supportRateNum = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500781 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
782 struct registry_priv *pregistrypriv = &padapter->registrypriv;
783 struct security_priv *psecuritypriv = &padapter->securitypriv;
784 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
785 struct wlan_bssid_ex *pbss_network = &pmlmepriv->cur_network.network;
786 u8 *ie = pbss_network->IEs;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200787 u8 *pbuf = mgmt->u.beacon.variable;
788 len -= offsetof(struct ieee80211_mgmt, u.beacon.variable);
Larry Finger5e93f352014-03-28 21:37:38 -0500789 /* SSID */
790 /* Supported rates */
791 /* DS Params */
792 /* WLAN_EID_COUNTRY */
793 /* ERP Information element */
794 /* Extended supported rates */
795 /* WPA/WPA2 */
796 /* Wi-Fi Wireless Multimedia Extensions */
797 /* ht_capab, ht_oper */
798 /* WPS IE */
799
800 DBG_8723A("%s, len =%d\n", __func__, len);
801
802 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
803 return _FAIL;
804
Jes Sorensen8282aeb2014-04-26 18:54:53 +0200805 if (len > MAX_IE_SZ)
Larry Finger5e93f352014-03-28 21:37:38 -0500806 return _FAIL;
807
808 pbss_network->IELength = len;
809
810 memset(ie, 0, MAX_IE_SZ);
811
812 memcpy(ie, pbuf, pbss_network->IELength);
813
Jes Sorensenefc71442014-05-21 09:37:26 +0200814 if (pbss_network->ifmode != NL80211_IFTYPE_AP &&
815 pbss_network->ifmode != NL80211_IFTYPE_P2P_GO)
Larry Finger5e93f352014-03-28 21:37:38 -0500816 return _FAIL;
817
818 pbss_network->Rssi = 0;
819
820 memcpy(pbss_network->MacAddress, myid(&padapter->eeprompriv), ETH_ALEN);
821
Larry Finger5e93f352014-03-28 21:37:38 -0500822 /* SSID */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200823 p = rtw_get_ie23a(ie, WLAN_EID_SSID, &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500824 if (p && ie_len > 0) {
825 memset(&pbss_network->Ssid, 0, sizeof(struct cfg80211_ssid));
826 memcpy(pbss_network->Ssid.ssid, (p + 2), ie_len);
827 pbss_network->Ssid.ssid_len = ie_len;
828 }
829
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900830 /* channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500831 channel = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200832 p = rtw_get_ie23a(ie, WLAN_EID_DS_PARAMS, &ie_len,
833 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500834 if (p && ie_len > 0)
835 channel = *(p + 2);
836
Jes Sorensen37cb9822014-05-21 09:37:40 +0200837 pbss_network->DSConfig = channel;
Larry Finger5e93f352014-03-28 21:37:38 -0500838
839 memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
840 /* get supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200841 p = rtw_get_ie23a(ie, WLAN_EID_SUPP_RATES, &ie_len,
842 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500843 if (p) {
844 memcpy(supportRate, p+2, ie_len);
845 supportRateNum = ie_len;
846 }
847
848 /* get ext_supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200849 p = rtw_get_ie23a(ie, WLAN_EID_EXT_SUPP_RATES,
850 &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500851 if (p) {
852 memcpy(supportRate+supportRateNum, p+2, ie_len);
853 supportRateNum += ie_len;
854 }
855
856 network_type = rtw_check_network_type23a(supportRate,
857 supportRateNum, channel);
858
859 rtw_set_supported_rate23a(pbss_network->SupportedRates, network_type);
860
861 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200862 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &ie_len,
863 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500864 if (p && ie_len > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +0200865 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -0500866
867 /* update privacy/security */
Jes Sorensen51a26d22014-06-24 15:03:21 +0200868 if (pbss_network->capability & BIT(4))
Larry Finger5e93f352014-03-28 21:37:38 -0500869 pbss_network->Privacy = 1;
870 else
871 pbss_network->Privacy = 0;
872
873 psecuritypriv->wpa_psk = 0;
874
875 /* wpa2 */
876 group_cipher = 0; pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200877 psecuritypriv->wpa2_group_cipher = 0;
878 psecuritypriv->wpa2_pairwise_cipher = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200879 p = rtw_get_ie23a(ie, WLAN_EID_RSN, &ie_len,
880 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500881 if (p && ie_len > 0) {
882 if (rtw_parse_wpa2_ie23a(p, ie_len+2, &group_cipher,
883 &pairwise_cipher, NULL) == _SUCCESS) {
884 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
885
886 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
887 psecuritypriv->wpa_psk |= BIT(1);
888
889 psecuritypriv->wpa2_group_cipher = group_cipher;
890 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
891 }
892 }
893
894 /* wpa */
895 ie_len = 0;
896 group_cipher = 0;
897 pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200898 psecuritypriv->wpa_group_cipher = 0;
899 psecuritypriv->wpa_pairwise_cipher = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200900 for (p = ie; ;p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200901 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200902 pbss_network->IELength - (ie_len + 2));
Jes Sorensen819d1812014-04-26 18:55:44 +0200903 if ((p) && (!memcmp(p+2, RTW_WPA_OUI23A_TYPE, 4))) {
Larry Finger5e93f352014-03-28 21:37:38 -0500904 if (rtw_parse_wpa_ie23a(p, ie_len+2, &group_cipher,
905 &pairwise_cipher, NULL) == _SUCCESS) {
906 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
907
908 /* psk, todo:802.1x */
909 psecuritypriv->dot8021xalg = 1;
910
911 psecuritypriv->wpa_psk |= BIT(0);
912
913 psecuritypriv->wpa_group_cipher = group_cipher;
914 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
915 }
916 break;
917 }
918
919 if ((p == NULL) || (ie_len == 0))
920 break;
921 }
922
923 /* wmm */
924 ie_len = 0;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200925 pmlmepriv->qos_option = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500926 if (pregistrypriv->wmm_enable) {
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200927 for (p = ie; ;p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200928 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Larry Finger5e93f352014-03-28 21:37:38 -0500929 (pbss_network->IELength -
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200930 (ie_len + 2)));
Larry Finger5e93f352014-03-28 21:37:38 -0500931 if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) {
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200932 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500933
934 *(p+8) |= BIT(7);/* QoS Info, support U-APSD */
935
936 /* disable all ACM bits since the WMM admission
937 * control is not supported
938 */
939 *(p + 10) &= ~BIT(4); /* BE */
940 *(p + 14) &= ~BIT(4); /* BK */
941 *(p + 18) &= ~BIT(4); /* VI */
942 *(p + 22) &= ~BIT(4); /* VO */
943 break;
944 }
945 if ((p == NULL) || (ie_len == 0))
946 break;
947 }
948 }
949 /* parsing HT_CAP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200950 p = rtw_get_ie23a(ie, WLAN_EID_HT_CAPABILITY, &ie_len,
951 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500952 if (p && ie_len > 0) {
953 u8 rf_type;
954
955 struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p+2);
956
957 pHT_caps_ie = p;
958
959 ht_cap = true;
960 network_type |= WIRELESS_11_24N;
961
Jes Sorensenc2370e82014-04-09 23:20:53 +0200962 rf_type = rtl8723a_get_rf_type(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500963
964 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
965 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
966 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY & (0x07<<2));
967 else
968 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY&0x00);
969
970 /* set Max Rx AMPDU size to 64K */
971 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_FACTOR & 0x03);
972
973 if (rf_type == RF_1T1R) {
974 pht_cap->mcs.rx_mask[0] = 0xff;
975 pht_cap->mcs.rx_mask[1] = 0x0;
976 }
977
978 memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len);
979 }
980
981 /* parsing HT_INFO_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200982 p = rtw_get_ie23a(ie, WLAN_EID_HT_OPERATION, &ie_len,
983 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500984 if (p && ie_len > 0)
985 pHT_info_ie = p;
986
Larry Finger5e93f352014-03-28 21:37:38 -0500987 pmlmepriv->cur_network.network_type = network_type;
988
989 pmlmepriv->htpriv.ht_option = false;
990
991 /* ht_cap */
992 if (pregistrypriv->ht_enable && ht_cap) {
993 pmlmepriv->htpriv.ht_option = true;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200994 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500995
996 if (pregistrypriv->ampdu_enable == 1)
997 pmlmepriv->htpriv.ampdu_enable = true;
998
Jes Sorensenb171da32014-05-21 09:37:42 +0200999 HT_caps_handler23a(padapter, pHT_caps_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001000
Jes Sorensenb171da32014-05-21 09:37:42 +02001001 HT_info_handler23a(padapter, pHT_info_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001002 }
1003
Jes Sorensen52017952014-04-26 18:55:09 +02001004 pbss_network->Length = get_wlan_bssid_ex_sz(pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001005
1006 /* issue beacon to start bss network */
Greg Donald7e6646d2014-09-06 19:42:03 -05001007 start_bss_network(padapter, (u8 *)pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001008
1009 /* alloc sta_info for ap itself */
1010 psta = rtw_get_stainfo23a(&padapter->stapriv, pbss_network->MacAddress);
1011 if (!psta) {
Jes Sorensen6e8bc712014-05-09 15:03:49 +02001012 psta = rtw_alloc_stainfo23a(&padapter->stapriv,
1013 pbss_network->MacAddress,
1014 GFP_KERNEL);
Larry Finger5e93f352014-03-28 21:37:38 -05001015 if (!psta)
1016 return _FAIL;
1017 }
1018 /* fix bug of flush_cam_entry at STOP AP mode */
1019 psta->state |= WIFI_AP_STATE;
1020 rtw_indicate_connect23a(padapter);
1021
1022 /* for check if already set beacon */
1023 pmlmepriv->cur_network.join_res = true;
1024
1025 return ret;
1026}
1027
1028void rtw_set_macaddr_acl23a(struct rtw_adapter *padapter, int mode)
1029{
1030 struct sta_priv *pstapriv = &padapter->stapriv;
1031 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1032
1033 DBG_8723A("%s, mode =%d\n", __func__, mode);
1034
1035 pacl_list->mode = mode;
1036}
1037
1038int rtw_acl_add_sta23a(struct rtw_adapter *padapter, u8 *addr)
1039{
1040 struct list_head *plist, *phead;
1041 u8 added = false;
1042 int i, ret = 0;
1043 struct rtw_wlan_acl_node *paclnode;
1044 struct sta_priv *pstapriv = &padapter->stapriv;
1045 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1046 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1047
1048 DBG_8723A("%s(acl_num =%d) =" MAC_FMT "\n", __func__, pacl_list->num, MAC_ARG(addr));
1049
1050 if ((NUM_ACL-1) < pacl_list->num)
1051 return -1;
1052
1053 spin_lock_bh(&pacl_node_q->lock);
1054
1055 phead = get_list_head(pacl_node_q);
1056
1057 list_for_each(plist, phead) {
1058 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1059
1060 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1061 if (paclnode->valid == true) {
1062 added = true;
1063 DBG_8723A("%s, sta has been added\n", __func__);
1064 break;
1065 }
1066 }
1067 }
1068
1069 spin_unlock_bh(&pacl_node_q->lock);
1070
1071 if (added)
1072 return ret;
1073
1074 spin_lock_bh(&pacl_node_q->lock);
1075
1076 for (i = 0; i < NUM_ACL; i++) {
1077 paclnode = &pacl_list->aclnode[i];
1078
1079 if (!paclnode->valid) {
1080 INIT_LIST_HEAD(&paclnode->list);
1081
1082 memcpy(paclnode->addr, addr, ETH_ALEN);
1083
1084 paclnode->valid = true;
1085
1086 list_add_tail(&paclnode->list, get_list_head(pacl_node_q));
1087
1088 pacl_list->num++;
1089
1090 break;
1091 }
1092 }
1093
1094 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1095
1096 spin_unlock_bh(&pacl_node_q->lock);
1097 return ret;
1098}
1099
1100int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
1101{
1102 struct list_head *plist, *phead, *ptmp;
1103 struct rtw_wlan_acl_node *paclnode;
1104 struct sta_priv *pstapriv = &padapter->stapriv;
1105 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1106 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
Larry Finger5e93f352014-03-28 21:37:38 -05001107
1108 DBG_8723A("%s(acl_num =%d) = %pM\n", __func__, pacl_list->num, addr);
1109
1110 spin_lock_bh(&pacl_node_q->lock);
1111
1112 phead = get_list_head(pacl_node_q);
1113
1114 list_for_each_safe(plist, ptmp, phead) {
1115 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1116
1117 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1118 if (paclnode->valid) {
1119 paclnode->valid = false;
1120
1121 list_del_init(&paclnode->list);
1122
1123 pacl_list->num--;
1124 }
1125 }
1126 }
1127
1128 spin_unlock_bh(&pacl_node_q->lock);
1129
1130 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1131
Heena Sirwanif9800f82014-10-07 14:46:30 +05301132 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001133}
1134
1135static void update_bcn_fixed_ie(struct rtw_adapter *padapter)
1136{
1137 DBG_8723A("%s\n", __func__);
1138}
1139
1140static void update_bcn_erpinfo_ie(struct rtw_adapter *padapter)
1141{
1142 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1143 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1144 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1145 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1146 unsigned char *p, *ie = pnetwork->IEs;
1147 u32 len = 0;
1148
1149 DBG_8723A("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1150
1151 if (!pmlmeinfo->ERP_enable)
1152 return;
1153
1154 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +02001155 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &len, pnetwork->IELength);
Jes Sorensenb171da32014-05-21 09:37:42 +02001156 if (p && len > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001157 if (pmlmepriv->num_sta_non_erp == 1)
Jes Sorensenb171da32014-05-21 09:37:42 +02001158 p[2] |= WLAN_ERP_NON_ERP_PRESENT |
Larry Finger5e93f352014-03-28 21:37:38 -05001159 WLAN_ERP_USE_PROTECTION;
1160 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001161 p[2] &= ~(WLAN_ERP_NON_ERP_PRESENT |
1162 WLAN_ERP_USE_PROTECTION);
Larry Finger5e93f352014-03-28 21:37:38 -05001163
1164 if (pmlmepriv->num_sta_no_short_preamble > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +02001165 p[2] |= WLAN_ERP_BARKER_PREAMBLE;
Larry Finger5e93f352014-03-28 21:37:38 -05001166 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001167 p[2] &= ~(WLAN_ERP_BARKER_PREAMBLE);
Larry Finger5e93f352014-03-28 21:37:38 -05001168
Jes Sorensenb171da32014-05-21 09:37:42 +02001169 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -05001170 }
1171}
1172
1173static void update_bcn_htcap_ie(struct rtw_adapter *padapter)
1174{
1175 DBG_8723A("%s\n", __func__);
1176}
1177
1178static void update_bcn_htinfo_ie(struct rtw_adapter *padapter)
1179{
1180 DBG_8723A("%s\n", __func__);
1181}
1182
1183static void update_bcn_rsn_ie(struct rtw_adapter *padapter)
1184{
1185 DBG_8723A("%s\n", __func__);
1186}
1187
1188static void update_bcn_wpa_ie(struct rtw_adapter *padapter)
1189{
1190 DBG_8723A("%s\n", __func__);
1191}
1192
1193static void update_bcn_wmm_ie(struct rtw_adapter *padapter)
1194{
1195 DBG_8723A("%s\n", __func__);
1196}
1197
1198static void update_bcn_wps_ie(struct rtw_adapter *padapter)
1199{
Larry Finger5e93f352014-03-28 21:37:38 -05001200 DBG_8723A("%s\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -05001201}
1202
1203static void update_bcn_p2p_ie(struct rtw_adapter *padapter)
1204{
1205}
1206
1207static void update_bcn_vendor_spec_ie(struct rtw_adapter *padapter, u8*oui)
1208{
1209 DBG_8723A("%s\n", __func__);
1210
Jes Sorensen7964eba02014-04-15 19:44:11 +02001211 if (!memcmp(RTW_WPA_OUI23A_TYPE, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001212 update_bcn_wpa_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001213 else if (!memcmp(WMM_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001214 update_bcn_wmm_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001215 else if (!memcmp(WPS_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001216 update_bcn_wps_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001217 else if (!memcmp(P2P_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001218 update_bcn_p2p_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001219 else
Larry Finger5e93f352014-03-28 21:37:38 -05001220 DBG_8723A("unknown OUI type!\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001221}
1222
1223void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1224{
1225 struct mlme_priv *pmlmepriv;
1226 struct mlme_ext_priv *pmlmeext;
1227 /* struct mlme_ext_info *pmlmeinfo; */
1228
1229 /* DBG_8723A("%s\n", __func__); */
1230
1231 if (!padapter)
1232 return;
1233
1234 pmlmepriv = &padapter->mlmepriv;
1235 pmlmeext = &padapter->mlmeextpriv;
1236 /* pmlmeinfo = &pmlmeext->mlmext_info; */
1237
1238 if (false == pmlmeext->bstart_bss)
1239 return;
1240
1241 spin_lock_bh(&pmlmepriv->bcn_update_lock);
1242
Tina Ruchandanif2372162014-10-23 20:16:51 -07001243 switch (ie_id) {
Jes Sorensenb54e8802014-04-09 23:20:52 +02001244 case 0xFF:
1245 /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1246 update_bcn_fixed_ie(padapter);
1247 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001248
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001249 case WLAN_EID_TIM:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001250 update_BCNTIM(padapter);
1251 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001252
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001253 case WLAN_EID_ERP_INFO:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001254 update_bcn_erpinfo_ie(padapter);
1255 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001256
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001257 case WLAN_EID_HT_CAPABILITY:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001258 update_bcn_htcap_ie(padapter);
1259 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001260
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001261 case WLAN_EID_RSN:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001262 update_bcn_rsn_ie(padapter);
1263 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001264
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001265 case WLAN_EID_HT_OPERATION:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001266 update_bcn_htinfo_ie(padapter);
1267 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001268
Jes Sorensen9300c942014-04-15 19:43:21 +02001269 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001270 update_bcn_vendor_spec_ie(padapter, oui);
1271 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001272
Jes Sorensenb54e8802014-04-09 23:20:52 +02001273 default:
1274 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001275 }
1276
1277 pmlmepriv->update_bcn = true;
1278
1279 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
1280
1281 if (tx)
1282 set_tx_beacon_cmd23a(padapter);
1283}
1284
1285/*
1286op_mode
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001287Set to 0 (HT pure) under the following conditions
Larry Finger5e93f352014-03-28 21:37:38 -05001288 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1289 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1290Set to 1 (HT non-member protection) if there may be non-HT STAs
1291 in both the primary and the secondary channel
1292Set to 2 if only HT STAs are associated in BSS,
1293 however and at least one 20 MHz HT STA is associated
1294Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1295 (currently non-GF HT station is considered as non-HT STA also)
1296*/
1297static int rtw_ht_operation_update(struct rtw_adapter *padapter)
1298{
1299 u16 cur_op_mode, new_op_mode;
1300 int op_mode_changes = 0;
1301 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1302 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
1303
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001304 if (pmlmepriv->htpriv.ht_option)
Larry Finger5e93f352014-03-28 21:37:38 -05001305 return 0;
1306
1307 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */
1308 /* return 0; */
1309
1310 DBG_8723A("%s current operation mode = 0x%X\n",
1311 __func__, pmlmepriv->ht_op_mode);
1312
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001313 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
Larry Finger5e93f352014-03-28 21:37:38 -05001314 && pmlmepriv->num_sta_ht_no_gf) {
1315 pmlmepriv->ht_op_mode |=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001316 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001317 op_mode_changes++;
1318 } else if ((pmlmepriv->ht_op_mode &
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001319 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001320 pmlmepriv->num_sta_ht_no_gf == 0) {
1321 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001322 ~IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001323 op_mode_changes++;
1324 }
1325
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001326 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001327 (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001328 pmlmepriv->ht_op_mode |= IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001329 op_mode_changes++;
1330 } else if ((pmlmepriv->ht_op_mode &
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001331 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001332 (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
1333 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001334 ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001335 op_mode_changes++;
1336 }
1337
1338 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
1339 * station is associated. Probably it's a theoretical case, since
1340 * it looks like all known HT STAs support greenfield.
1341 */
Larry Finger5e93f352014-03-28 21:37:38 -05001342 if (pmlmepriv->num_sta_no_ht ||
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001343 (pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
Jes Sorensenc3899282014-05-21 09:37:51 +02001344 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Larry Fingera96ae6f2014-04-26 18:55:18 +02001345 else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) &
1346 IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
1347 pmlmepriv->num_sta_ht_20mhz)
Jes Sorensenc3899282014-05-21 09:37:51 +02001348 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
Larry Finger5e93f352014-03-28 21:37:38 -05001349 else if (pmlmepriv->olbc_ht)
Jes Sorensenc3899282014-05-21 09:37:51 +02001350 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER;
Larry Finger5e93f352014-03-28 21:37:38 -05001351 else
Jes Sorensenc3899282014-05-21 09:37:51 +02001352 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
Larry Finger5e93f352014-03-28 21:37:38 -05001353
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001354 cur_op_mode = pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001355 if (cur_op_mode != new_op_mode) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001356 pmlmepriv->ht_op_mode &= ~IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001357 pmlmepriv->ht_op_mode |= new_op_mode;
1358 op_mode_changes++;
1359 }
1360
1361 DBG_8723A("%s new operation mode = 0x%X changes =%d\n",
1362 __func__, pmlmepriv->ht_op_mode, op_mode_changes);
1363
1364 return op_mode_changes;
1365}
1366
1367void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated)
1368{
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001369 /* update associated stations cap. */
Tina Ruchandanif2372162014-10-23 20:16:51 -07001370 if (updated == true) {
Larry Finger5e93f352014-03-28 21:37:38 -05001371 struct list_head *phead, *plist, *ptmp;
1372 struct sta_info *psta;
1373 struct sta_priv *pstapriv = &padapter->stapriv;
1374
1375 spin_lock_bh(&pstapriv->asoc_list_lock);
1376
1377 phead = &pstapriv->asoc_list;
1378
1379 list_for_each_safe(plist, ptmp, phead) {
1380 psta = container_of(plist, struct sta_info, asoc_list);
1381
1382 VCS_update23a(padapter, psta);
1383 }
1384
1385 spin_unlock_bh(&pstapriv->asoc_list_lock);
1386 }
1387}
1388
1389/* called > TSR LEVEL for USB or SDIO Interface*/
1390void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info *psta)
1391{
1392 u8 beacon_updated = false;
1393 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1394 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1395
Tina Ruchandanif2372162014-10-23 20:16:51 -07001396 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1397 if (!psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001398 psta->no_short_preamble_set = 1;
1399
1400 pmlmepriv->num_sta_no_short_preamble++;
1401
1402 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001403 (pmlmepriv->num_sta_no_short_preamble == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001404 beacon_updated = true;
1405 update_beacon23a(padapter, 0xFF, NULL, true);
1406 }
1407
1408 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001409 } else {
1410 if (psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001411 psta->no_short_preamble_set = 0;
1412
1413 pmlmepriv->num_sta_no_short_preamble--;
1414
1415 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001416 (pmlmepriv->num_sta_no_short_preamble == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001417 beacon_updated = true;
1418 update_beacon23a(padapter, 0xFF, NULL, true);
1419 }
1420
1421 }
1422 }
1423
Tina Ruchandanif2372162014-10-23 20:16:51 -07001424 if (psta->flags & WLAN_STA_NONERP) {
1425 if (!psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001426 psta->nonerp_set = 1;
1427
1428 pmlmepriv->num_sta_non_erp++;
1429
Tina Ruchandanif2372162014-10-23 20:16:51 -07001430 if (pmlmepriv->num_sta_non_erp == 1) {
Larry Finger5e93f352014-03-28 21:37:38 -05001431 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001432 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001433 }
1434 }
1435
Tina Ruchandanif2372162014-10-23 20:16:51 -07001436 } else {
1437 if (psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001438 psta->nonerp_set = 0;
1439
1440 pmlmepriv->num_sta_non_erp--;
1441
Tina Ruchandanif2372162014-10-23 20:16:51 -07001442 if (pmlmepriv->num_sta_non_erp == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001443 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001444 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001445 }
1446 }
1447
1448 }
1449
Tina Ruchandanif2372162014-10-23 20:16:51 -07001450 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1451 if (!psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001452 psta->no_short_slot_time_set = 1;
1453
1454 pmlmepriv->num_sta_no_short_slot_time++;
1455
1456 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001457 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001458 beacon_updated = true;
1459 update_beacon23a(padapter, 0xFF, NULL, true);
1460 }
1461
1462 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001463 } else {
1464 if (psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001465 psta->no_short_slot_time_set = 0;
1466
1467 pmlmepriv->num_sta_no_short_slot_time--;
1468
1469 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001470 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001471 beacon_updated = true;
1472 update_beacon23a(padapter, 0xFF, NULL, true);
1473 }
1474 }
1475 }
1476
Tina Ruchandanif2372162014-10-23 20:16:51 -07001477 if (psta->flags & WLAN_STA_HT) {
Larry Finger5e93f352014-03-28 21:37:38 -05001478 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
1479
1480 DBG_8723A("HT: STA " MAC_FMT " HT Capabilities "
1481 "Info: 0x%04x\n", MAC_ARG(psta->hwaddr), ht_capab);
1482
1483 if (psta->no_ht_set) {
1484 psta->no_ht_set = 0;
1485 pmlmepriv->num_sta_no_ht--;
1486 }
1487
1488 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
1489 if (!psta->no_ht_gf_set) {
1490 psta->no_ht_gf_set = 1;
1491 pmlmepriv->num_sta_ht_no_gf++;
1492 }
1493 DBG_8723A("%s STA " MAC_FMT " - no "
1494 "greenfield, num of non-gf stations %d\n",
1495 __func__, MAC_ARG(psta->hwaddr),
1496 pmlmepriv->num_sta_ht_no_gf);
1497 }
1498
1499 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH_20_40) == 0) {
1500 if (!psta->ht_20mhz_set) {
1501 psta->ht_20mhz_set = 1;
1502 pmlmepriv->num_sta_ht_20mhz++;
1503 }
1504 DBG_8723A("%s STA " MAC_FMT " - 20 MHz HT, "
1505 "num of 20MHz HT STAs %d\n",
1506 __func__, MAC_ARG(psta->hwaddr),
1507 pmlmepriv->num_sta_ht_20mhz);
1508 }
1509
Tina Ruchandanif2372162014-10-23 20:16:51 -07001510 } else {
Larry Finger5e93f352014-03-28 21:37:38 -05001511 if (!psta->no_ht_set) {
1512 psta->no_ht_set = 1;
1513 pmlmepriv->num_sta_no_ht++;
1514 }
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001515 if (pmlmepriv->htpriv.ht_option) {
Larry Finger5e93f352014-03-28 21:37:38 -05001516 DBG_8723A("%s STA " MAC_FMT
1517 " - no HT, num of non-HT stations %d\n",
1518 __func__, MAC_ARG(psta->hwaddr),
1519 pmlmepriv->num_sta_no_ht);
1520 }
1521 }
1522
Tina Ruchandanif2372162014-10-23 20:16:51 -07001523 if (rtw_ht_operation_update(padapter) > 0) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001524 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1525 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001526 }
1527
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001528 /* update associated stations cap. */
Larry Finger5e93f352014-03-28 21:37:38 -05001529 associated_clients_update23a(padapter, beacon_updated);
1530
1531 DBG_8723A("%s, updated =%d\n", __func__, beacon_updated);
1532}
1533
1534u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info *psta)
1535{
1536 u8 beacon_updated = false;
1537 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1538 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1539
1540 if (!psta)
1541 return beacon_updated;
1542
1543 if (psta->no_short_preamble_set) {
1544 psta->no_short_preamble_set = 0;
1545 pmlmepriv->num_sta_no_short_preamble--;
1546 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
Tina Ruchandanif2372162014-10-23 20:16:51 -07001547 && pmlmepriv->num_sta_no_short_preamble == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001548 beacon_updated = true;
1549 update_beacon23a(padapter, 0xFF, NULL, true);
1550 }
1551 }
1552
1553 if (psta->nonerp_set) {
1554 psta->nonerp_set = 0;
1555 pmlmepriv->num_sta_non_erp--;
Tina Ruchandanif2372162014-10-23 20:16:51 -07001556 if (pmlmepriv->num_sta_non_erp == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001557 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001558 update_beacon23a(padapter, WLAN_EID_ERP_INFO,
1559 NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001560 }
1561 }
1562
1563 if (psta->no_short_slot_time_set) {
1564 psta->no_short_slot_time_set = 0;
1565 pmlmepriv->num_sta_no_short_slot_time--;
1566 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
Tina Ruchandanif2372162014-10-23 20:16:51 -07001567 && pmlmepriv->num_sta_no_short_slot_time == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001568 beacon_updated = true;
1569 update_beacon23a(padapter, 0xFF, NULL, true);
1570 }
1571 }
1572
1573 if (psta->no_ht_gf_set) {
1574 psta->no_ht_gf_set = 0;
1575 pmlmepriv->num_sta_ht_no_gf--;
1576 }
1577
1578 if (psta->no_ht_set) {
1579 psta->no_ht_set = 0;
1580 pmlmepriv->num_sta_no_ht--;
1581 }
1582
1583 if (psta->ht_20mhz_set) {
1584 psta->ht_20mhz_set = 0;
1585 pmlmepriv->num_sta_ht_20mhz--;
1586 }
1587
Tina Ruchandanif2372162014-10-23 20:16:51 -07001588 if (rtw_ht_operation_update(padapter) > 0) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001589 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1590 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001591 }
1592
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001593 /* update associated stations cap. */
Larry Finger5e93f352014-03-28 21:37:38 -05001594
1595 DBG_8723A("%s, updated =%d\n", __func__, beacon_updated);
1596
1597 return beacon_updated;
1598}
1599
1600u8 ap_free_sta23a(struct rtw_adapter *padapter, struct sta_info *psta, bool active, u16 reason)
1601{
1602 struct sta_priv *pstapriv = &padapter->stapriv;
1603 u8 beacon_updated = false;
1604
1605 if (!psta)
1606 return beacon_updated;
1607
Roberta Dobrescu08551cb2014-10-26 23:30:05 +02001608 if (active) {
Larry Finger5e93f352014-03-28 21:37:38 -05001609 /* tear down Rx AMPDU */
1610 send_delba23a(padapter, 0, psta->hwaddr);/* recipient */
1611
1612 /* tear down TX AMPDU */
1613 send_delba23a(padapter, 1, psta->hwaddr);/* originator */
1614
1615 issue_deauth23a(padapter, psta->hwaddr, reason);
1616 }
1617
1618 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
1619 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
1620
1621 /* report_del_sta_event23a(padapter, psta->hwaddr, reason); */
1622
1623 /* clear cam entry / key */
1624 /* clear_cam_entry23a(padapter, (psta->mac_id + 3)); */
Greg Donald7e6646d2014-09-06 19:42:03 -05001625 rtw_clearstakey_cmd23a(padapter, (u8 *)psta, (u8)(psta->mac_id + 3),
1626 true);
Larry Finger5e93f352014-03-28 21:37:38 -05001627
1628 spin_lock_bh(&psta->lock);
1629 psta->state &= ~_FW_LINKED;
1630 spin_unlock_bh(&psta->lock);
1631
1632 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
1633
1634 report_del_sta_event23a(padapter, psta->hwaddr, reason);
1635
1636 beacon_updated = bss_cap_update_on_sta_leave23a(padapter, psta);
1637
1638 spin_lock_bh(&pstapriv->sta_hash_lock);
1639 rtw_free_stainfo23a(padapter, psta);
1640 spin_unlock_bh(&pstapriv->sta_hash_lock);
1641
1642 return beacon_updated;
1643}
1644
1645int rtw_ap_inform_ch_switch23a (struct rtw_adapter *padapter, u8 new_ch, u8 ch_offset)
1646{
1647 struct list_head *phead, *plist;
Larry Finger5e93f352014-03-28 21:37:38 -05001648 struct sta_info *psta = NULL;
1649 struct sta_priv *pstapriv = &padapter->stapriv;
1650 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1651 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1652 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1653
Jes Sorensen6ec26272014-07-17 22:59:46 +02001654 if ((pmlmeinfo->state&0x03) != MSR_AP)
Heena Sirwanif9800f82014-10-07 14:46:30 +05301655 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001656
Jes Sorensena790d582014-05-09 15:04:04 +02001657 DBG_8723A("%s(%s): with ch:%u, offset:%u\n", __func__,
1658 padapter->pnetdev->name, new_ch, ch_offset);
Larry Finger5e93f352014-03-28 21:37:38 -05001659
1660 spin_lock_bh(&pstapriv->asoc_list_lock);
1661 phead = &pstapriv->asoc_list;
1662
1663 list_for_each(plist, phead) {
1664 psta = container_of(plist, struct sta_info, asoc_list);
1665
1666 issue_action_spct_ch_switch23a (padapter, psta->hwaddr, new_ch, ch_offset);
1667 psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
1668 }
1669 spin_unlock_bh(&pstapriv->asoc_list_lock);
1670
1671 issue_action_spct_ch_switch23a (padapter, bc_addr, new_ch, ch_offset);
1672
Heena Sirwanif9800f82014-10-07 14:46:30 +05301673 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001674}
1675
1676int rtw_sta_flush23a(struct rtw_adapter *padapter)
1677{
1678 struct list_head *phead, *plist, *ptmp;
Larry Finger5e93f352014-03-28 21:37:38 -05001679 struct sta_info *psta;
1680 struct sta_priv *pstapriv = &padapter->stapriv;
1681 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1682 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1683 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1684 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +02001685 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -05001686 int i;
1687
Jes Sorensena790d582014-05-09 15:04:04 +02001688 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name);
Larry Finger5e93f352014-03-28 21:37:38 -05001689
Jes Sorensen6ec26272014-07-17 22:59:46 +02001690 if ((pmlmeinfo->state&0x03) != MSR_AP)
Heena Sirwanif9800f82014-10-07 14:46:30 +05301691 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001692
1693 spin_lock_bh(&pstapriv->asoc_list_lock);
1694 phead = &pstapriv->asoc_list;
1695
1696 list_for_each_safe(plist, ptmp, phead) {
Larry Finger5e93f352014-03-28 21:37:38 -05001697 psta = container_of(plist, struct sta_info, asoc_list);
1698
1699 /* Remove sta from asoc_list */
1700 list_del_init(&psta->asoc_list);
1701 pstapriv->asoc_list_cnt--;
1702
1703 /* Keep sta for ap_free_sta23a() beyond this asoc_list loop */
Jes Sorensen69642132014-05-09 15:03:47 +02001704 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -05001705 }
1706 spin_unlock_bh(&pstapriv->asoc_list_lock);
1707
1708 /* For each sta in chk_alive_list, call ap_free_sta23a */
Jes Sorensen69642132014-05-09 15:03:47 +02001709 for (i = 0; i < chk_alive_num; i++)
1710 ap_free_sta23a(padapter, chk_alive_list[i], true,
1711 WLAN_REASON_DEAUTH_LEAVING);
Larry Finger5e93f352014-03-28 21:37:38 -05001712
1713 issue_deauth23a(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
1714
1715 associated_clients_update23a(padapter, true);
1716
Heena Sirwanif9800f82014-10-07 14:46:30 +05301717 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001718}
1719
1720/* called > TSR LEVEL for USB or SDIO Interface*/
1721void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1722{
1723 int flags = psta->flags;
1724 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1725
1726 /* update wmm cap. */
1727 if (WLAN_STA_WME&flags)
1728 psta->qos_option = 1;
1729 else
1730 psta->qos_option = 0;
1731
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +02001732 if (pmlmepriv->qos_option == 0)
Larry Finger5e93f352014-03-28 21:37:38 -05001733 psta->qos_option = 0;
1734
1735 /* update 802.11n ht cap. */
Tina Ruchandanif2372162014-10-23 20:16:51 -07001736 if (WLAN_STA_HT&flags) {
Larry Finger5e93f352014-03-28 21:37:38 -05001737 psta->htpriv.ht_option = true;
1738 psta->qos_option = 1;
Tina Ruchandanif2372162014-10-23 20:16:51 -07001739 } else {
Larry Finger5e93f352014-03-28 21:37:38 -05001740 psta->htpriv.ht_option = false;
1741 }
1742
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001743 if (!pmlmepriv->htpriv.ht_option)
Larry Finger5e93f352014-03-28 21:37:38 -05001744 psta->htpriv.ht_option = false;
1745
1746 update_sta_info23a_apmode23a(padapter, psta);
1747}
1748
1749/* called >= TSR LEVEL for USB or SDIO Interface*/
1750void ap_sta_info_defer_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1751{
Tina Ruchandanif2372162014-10-23 20:16:51 -07001752 if (psta->state & _FW_LINKED) {
Larry Finger5e93f352014-03-28 21:37:38 -05001753 /* add ratid */
1754 add_RATid23a(padapter, psta, 0);/* DM_RATR_STA_INIT */
1755 }
1756}
1757
1758/* restore hw setting from sw data structures */
1759void rtw_ap_restore_network(struct rtw_adapter *padapter)
1760{
1761 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
1762 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Greg Donald8e3d1612014-10-02 18:28:41 -05001763 struct sta_priv *pstapriv = &padapter->stapriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001764 struct sta_info *psta;
1765 struct security_priv *psecuritypriv = &padapter->securitypriv;
1766 struct list_head *phead, *plist, *ptmp;
1767 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +02001768 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -05001769 int i;
1770
Jes Sorensenefc71442014-05-21 09:37:26 +02001771 rtw_setopmode_cmd23a(padapter, NL80211_IFTYPE_AP);
Larry Finger5e93f352014-03-28 21:37:38 -05001772
1773 set_channel_bwmode23a(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
1774
Greg Donald7e6646d2014-09-06 19:42:03 -05001775 start_bss_network(padapter, (u8 *)&mlmepriv->cur_network.network);
Larry Finger5e93f352014-03-28 21:37:38 -05001776
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001777 if (padapter->securitypriv.dot11PrivacyAlgrthm ==
1778 WLAN_CIPHER_SUITE_TKIP ||
1779 padapter->securitypriv.dot11PrivacyAlgrthm ==
1780 WLAN_CIPHER_SUITE_CCMP) {
Larry Finger5e93f352014-03-28 21:37:38 -05001781 /* restore group key, WEP keys is restored in ips_leave23a() */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001782 rtw_set_key23a(padapter, psecuritypriv,
1783 psecuritypriv->dot118021XGrpKeyid, 0);
Larry Finger5e93f352014-03-28 21:37:38 -05001784 }
1785
1786 /* per sta pairwise key and settings */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001787 if (padapter->securitypriv.dot11PrivacyAlgrthm !=
1788 WLAN_CIPHER_SUITE_TKIP &&
1789 padapter->securitypriv.dot11PrivacyAlgrthm !=
1790 WLAN_CIPHER_SUITE_CCMP) {
Larry Finger5e93f352014-03-28 21:37:38 -05001791 return;
1792 }
1793
1794 spin_lock_bh(&pstapriv->asoc_list_lock);
1795
1796 phead = &pstapriv->asoc_list;
1797
1798 list_for_each_safe(plist, ptmp, phead) {
Larry Finger5e93f352014-03-28 21:37:38 -05001799 psta = container_of(plist, struct sta_info, asoc_list);
1800
Jes Sorensen69642132014-05-09 15:03:47 +02001801 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -05001802 }
1803
1804 spin_unlock_bh(&pstapriv->asoc_list_lock);
1805
1806 for (i = 0; i < chk_alive_num; i++) {
Jes Sorensen69642132014-05-09 15:03:47 +02001807 psta = chk_alive_list[i];
Larry Finger5e93f352014-03-28 21:37:38 -05001808
MihaelaGamanadabff82014-09-14 12:56:43 +03001809 if (psta->state & _FW_LINKED) {
Larry Finger5e93f352014-03-28 21:37:38 -05001810 Update_RA_Entry23a(padapter, psta);
1811 /* pairwise key */
1812 rtw_setstakey_cmd23a(padapter, (unsigned char *)psta, true);
1813 }
1814 }
1815}
1816
1817void start_ap_mode23a(struct rtw_adapter *padapter)
1818{
1819 int i;
1820 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1821 struct sta_priv *pstapriv = &padapter->stapriv;
1822 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1823 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1824
1825 pmlmepriv->update_bcn = false;
1826
1827 /* init_mlme_ap_info23a(padapter); */
1828 pmlmeext->bstart_bss = false;
1829
1830 pmlmepriv->num_sta_non_erp = 0;
1831
1832 pmlmepriv->num_sta_no_short_slot_time = 0;
1833
1834 pmlmepriv->num_sta_no_short_preamble = 0;
1835
1836 pmlmepriv->num_sta_ht_no_gf = 0;
1837 pmlmepriv->num_sta_no_ht = 0;
1838 pmlmepriv->num_sta_ht_20mhz = 0;
1839
1840 pmlmepriv->olbc = false;
1841
1842 pmlmepriv->olbc_ht = false;
1843
1844 pmlmepriv->ht_op_mode = 0;
1845
MihaelaGamanadabff82014-09-14 12:56:43 +03001846 for (i = 0; i < NUM_STA; i++)
Larry Finger5e93f352014-03-28 21:37:38 -05001847 pstapriv->sta_aid[i] = NULL;
1848
Larry Finger5e93f352014-03-28 21:37:38 -05001849 /* for ACL */
1850 INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
1851 pacl_list->num = 0;
1852 pacl_list->mode = 0;
1853 for (i = 0; i < NUM_ACL; i++) {
1854 INIT_LIST_HEAD(&pacl_list->aclnode[i].list);
1855 pacl_list->aclnode[i].valid = false;
1856 }
1857}
1858
1859void stop_ap_mode23a(struct rtw_adapter *padapter)
1860{
1861 struct list_head *phead, *plist, *ptmp;
1862 struct rtw_wlan_acl_node *paclnode;
1863 struct sta_info *psta = NULL;
1864 struct sta_priv *pstapriv = &padapter->stapriv;
1865 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1866 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1867 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1868 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1869
1870 pmlmepriv->update_bcn = false;
1871 pmlmeext->bstart_bss = false;
1872
1873 /* reset and init security priv , this can refine with rtw_reset_securitypriv23a */
1874 memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv));
1875 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1876 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
1877
1878 /* for ACL */
1879 spin_lock_bh(&pacl_node_q->lock);
1880 phead = get_list_head(pacl_node_q);
1881
1882 list_for_each_safe(plist, ptmp, phead) {
1883 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1884
1885 if (paclnode->valid == true) {
1886 paclnode->valid = false;
1887
1888 list_del_init(&paclnode->list);
1889
1890 pacl_list->num--;
1891 }
1892 }
1893 spin_unlock_bh(&pacl_node_q->lock);
1894
1895 DBG_8723A("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
1896
1897 rtw_sta_flush23a(padapter);
1898
1899 /* free_assoc_sta_resources */
1900 rtw_free_all_stainfo23a(padapter);
1901
1902 psta = rtw_get_bcmc_stainfo23a(padapter);
1903 spin_lock_bh(&pstapriv->sta_hash_lock);
1904 rtw_free_stainfo23a(padapter, psta);
1905 spin_unlock_bh(&pstapriv->sta_hash_lock);
1906
1907 rtw_init_bcmc_stainfo23a(padapter);
1908
1909 rtw23a_free_mlme_priv_ie_data(pmlmepriv);
1910}