blob: 0086d5a2f92bd381bcf122febcaf463c5c13ff72 [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>
Vaishali Thakkarb5e38b12015-02-20 14:18:45 +053023#include <asm/unaligned.h>
Larry Finger5e93f352014-03-28 21:37:38 -050024
Larry Finger5e93f352014-03-28 21:37:38 -050025extern unsigned char WMM_OUI23A[];
26extern unsigned char WPS_OUI23A[];
27extern unsigned char P2P_OUI23A[];
Larry Finger5e93f352014-03-28 21:37:38 -050028
29void init_mlme_ap_info23a(struct rtw_adapter *padapter)
30{
31 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
32 struct sta_priv *pstapriv = &padapter->stapriv;
33 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
34
35 spin_lock_init(&pmlmepriv->bcn_update_lock);
36
37 /* for ACL */
38 _rtw_init_queue23a(&pacl_list->acl_node_q);
39
40 start_ap_mode23a(padapter);
41}
42
43void free_mlme_ap_info23a(struct rtw_adapter *padapter)
44{
45 struct sta_info *psta = NULL;
46 struct sta_priv *pstapriv = &padapter->stapriv;
47 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
48 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
49 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
50
51 pmlmepriv->update_bcn = false;
52 pmlmeext->bstart_bss = false;
53
54 rtw_sta_flush23a(padapter);
55
Jes Sorensen6ec26272014-07-17 22:59:46 +020056 pmlmeinfo->state = MSR_NOLINK;
Larry Finger5e93f352014-03-28 21:37:38 -050057
58 /* free_assoc_sta_resources */
59 rtw_free_all_stainfo23a(padapter);
60
61 /* free bc/mc sta_info */
62 psta = rtw_get_bcmc_stainfo23a(padapter);
63 spin_lock_bh(&pstapriv->sta_hash_lock);
64 rtw_free_stainfo23a(padapter, psta);
65 spin_unlock_bh(&pstapriv->sta_hash_lock);
66}
67
68static void update_BCNTIM(struct rtw_adapter *padapter)
69{
70 struct sta_priv *pstapriv = &padapter->stapriv;
71 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
72 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
73 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
74 unsigned char *pie = pnetwork_mlmeext->IEs;
75 u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
Larry Finger5e93f352014-03-28 21:37:38 -050076 uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
77
Jes Sorensen1de65cc2014-06-24 15:03:30 +020078 p = rtw_get_ie23a(pie, WLAN_EID_TIM, &tim_ielen,
79 pnetwork_mlmeext->IELength);
MihaelaGamanadabff82014-09-14 12:56:43 +030080 if (p != NULL && tim_ielen > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -050081 tim_ielen += 2;
82
83 premainder_ie = p+tim_ielen;
84
Tapasweni Pathak7d364292014-09-21 19:38:30 +053085 tim_ie_offset = (int)(p - pie);
Larry Finger5e93f352014-03-28 21:37:38 -050086
87 remainder_ielen = pnetwork_mlmeext->IELength - tim_ie_offset - tim_ielen;
88
89 /* append TIM IE from dst_ie offset */
90 dst_ie = p;
91 } else {
92 tim_ielen = 0;
93
Masanari Iida96b0a5b2014-07-22 23:42:45 +090094 /* calculate head_len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +020095 offset = 0;
Larry Finger5e93f352014-03-28 21:37:38 -050096
97 /* get ssid_ie len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +020098 p = rtw_get_ie23a(pie, WLAN_EID_SSID,
99 &tmp_len, pnetwork_mlmeext->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500100 if (p != NULL)
101 offset += tmp_len+2;
102
103 /* get supported rates len */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200104 p = rtw_get_ie23a(pie, WLAN_EID_SUPP_RATES,
105 &tmp_len, pnetwork_mlmeext->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500106 if (p != NULL)
107 offset += tmp_len+2;
108
109 /* DS Parameter Set IE, len = 3 */
110 offset += 3;
111
112 premainder_ie = pie + offset;
113
114 remainder_ielen = pnetwork_mlmeext->IELength - offset - tim_ielen;
115
116 /* append TIM IE from offset */
117 dst_ie = pie + offset;
118 }
119
120 if (remainder_ielen > 0) {
121 pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
122 if (pbackup_remainder_ie && premainder_ie)
123 memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
124 }
125
MihaelaGamanadabff82014-09-14 12:56:43 +0300126 *dst_ie++ = WLAN_EID_TIM;
Larry Finger5e93f352014-03-28 21:37:38 -0500127
128 if ((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fc))
129 tim_ielen = 5;
130 else
131 tim_ielen = 4;
132
MihaelaGamanadabff82014-09-14 12:56:43 +0300133 *dst_ie++ = tim_ielen;
Larry Finger5e93f352014-03-28 21:37:38 -0500134
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700135 *dst_ie++ = 0; /* DTIM count */
136 *dst_ie++ = 1; /* DTIM period */
Larry Finger5e93f352014-03-28 21:37:38 -0500137
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700138 if (pstapriv->tim_bitmap & BIT(0)) /* for bc/mc frames */
139 *dst_ie++ = BIT(0); /* bitmap ctrl */
Larry Finger5e93f352014-03-28 21:37:38 -0500140 else
141 *dst_ie++ = 0;
142
143 if (tim_ielen == 4) {
Vaishali Thakkarb5e38b12015-02-20 14:18:45 +0530144 *dst_ie++ = pstapriv->tim_bitmap & 0xff;
Larry Finger5e93f352014-03-28 21:37:38 -0500145 } else if (tim_ielen == 5) {
Vaishali Thakkarb5e38b12015-02-20 14:18:45 +0530146 put_unaligned_le16(pstapriv->tim_bitmap, dst_ie);
MihaelaGamanadabff82014-09-14 12:56:43 +0300147 dst_ie += 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500148 }
149
150 /* copy remainder IE */
151 if (pbackup_remainder_ie) {
152 memcpy(dst_ie, pbackup_remainder_ie, remainder_ielen);
153
154 kfree(pbackup_remainder_ie);
155 }
156
157 offset = (uint)(dst_ie - pie);
158 pnetwork_mlmeext->IELength = offset + remainder_ielen;
159
160 set_tx_beacon_cmd23a(padapter);
161}
162
163static u8 chk_sta_is_alive(struct sta_info *psta)
164{
165 u8 ret = false;
166
167 if ((psta->sta_stats.last_rx_data_pkts +
168 psta->sta_stats.last_rx_ctrl_pkts) !=
169 (psta->sta_stats.rx_data_pkts + psta->sta_stats.rx_ctrl_pkts))
170 ret = true;
171
172 sta_update_last_rx_pkts(psta);
173
174 return ret;
175}
176
177void expire_timeout_chk23a(struct rtw_adapter *padapter)
178{
179 struct list_head *phead, *plist, *ptmp;
180 u8 updated = 0;
181 struct sta_info *psta;
182 struct sta_priv *pstapriv = &padapter->stapriv;
183 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +0200184 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -0500185 int i;
186
187 spin_lock_bh(&pstapriv->auth_list_lock);
188
189 phead = &pstapriv->auth_list;
190
191 /* check auth_queue */
192 list_for_each_safe(plist, ptmp, phead) {
193 psta = container_of(plist, struct sta_info, auth_list);
194
MihaelaGamanadabff82014-09-14 12:56:43 +0300195 if (psta->expire_to > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -0500196 psta->expire_to--;
197 if (psta->expire_to == 0) {
198 list_del_init(&psta->auth_list);
199 pstapriv->auth_list_cnt--;
200
201 DBG_8723A("auth expire %pM\n", psta->hwaddr);
202
203 spin_unlock_bh(&pstapriv->auth_list_lock);
204
205 spin_lock_bh(&pstapriv->sta_hash_lock);
206 rtw_free_stainfo23a(padapter, psta);
207 spin_unlock_bh(&pstapriv->sta_hash_lock);
208
209 spin_lock_bh(&pstapriv->auth_list_lock);
210 }
211 }
212
213 }
214
215 spin_unlock_bh(&pstapriv->auth_list_lock);
216
217 spin_lock_bh(&pstapriv->asoc_list_lock);
218
219 phead = &pstapriv->asoc_list;
220
221 /* check asoc_queue */
222 list_for_each_safe(plist, ptmp, phead) {
223 psta = container_of(plist, struct sta_info, asoc_list);
224
225 if (chk_sta_is_alive(psta) || !psta->expire_to) {
226 psta->expire_to = pstapriv->expire_to;
227 psta->keep_alive_trycnt = 0;
228 } else {
229 psta->expire_to--;
230 }
231
Tina Ruchandanif2372162014-10-23 20:16:51 -0700232 if (psta->expire_to <= 0) {
Larry Finger5e93f352014-03-28 21:37:38 -0500233 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
234
Tina Ruchandanif2372162014-10-23 20:16:51 -0700235 if (padapter->registrypriv.wifi_spec == 1) {
Larry Finger5e93f352014-03-28 21:37:38 -0500236 psta->expire_to = pstapriv->expire_to;
237 continue;
238 }
239
240 if (psta->state & WIFI_SLEEP_STATE) {
241 if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700242 /*
243 * check if alive by another method
244 * if station is at ps mode.
245 */
Larry Finger5e93f352014-03-28 21:37:38 -0500246 psta->expire_to = pstapriv->expire_to;
247 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700248 /*
249 * update bcn with tim_bitmap
250 * for this station
251 */
Larry Finger5e93f352014-03-28 21:37:38 -0500252 pstapriv->tim_bitmap |= CHKBIT(psta->aid);
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200253 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500254
255 if (!pmlmeext->active_keep_alive_check)
256 continue;
257 }
258 }
259
260 if (pmlmeext->active_keep_alive_check) {
Jes Sorensen69642132014-05-09 15:03:47 +0200261 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -0500262 continue;
263 }
264
265 list_del_init(&psta->asoc_list);
266 pstapriv->asoc_list_cnt--;
267
Joe Perchesea072782015-03-24 11:10:09 -0700268 DBG_8723A("asoc expire %pM, state = 0x%x\n",
269 psta->hwaddr, psta->state);
Larry Finger5e93f352014-03-28 21:37:38 -0500270 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
271 } else {
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700272 /*
273 * TODO: Aging mechanism to digest frames in
274 * sleep_q to avoid running out of xmitframe
275 */
Larry Finger5e93f352014-03-28 21:37:38 -0500276 if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
277 && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME/pstapriv->asoc_list_cnt)/2)
278 ) {
Joe Perchesea072782015-03-24 11:10:09 -0700279 DBG_8723A("%s sta:%pM, sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n",
280 __func__,
281 psta->hwaddr,
Larry Finger5e93f352014-03-28 21:37:38 -0500282 psta->sleepq_len,
283 padapter->xmitpriv.free_xmitframe_cnt,
284 pstapriv->asoc_list_cnt);
285 wakeup_sta_to_xmit23a(padapter, psta);
286 }
287 }
288 }
289
290 spin_unlock_bh(&pstapriv->asoc_list_lock);
291
292 if (chk_alive_num) {
293
294 u8 backup_oper_channel = 0;
295 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700296 /*
297 * switch to correct channel of current
298 * network before issue keep-alive frames
299 */
Larry Finger5e93f352014-03-28 21:37:38 -0500300 if (rtw_get_oper_ch23a(padapter) != pmlmeext->cur_channel) {
301 backup_oper_channel = rtw_get_oper_ch23a(padapter);
302 SelectChannel23a(padapter, pmlmeext->cur_channel);
Jes Sorensen69642132014-05-09 15:03:47 +0200303 }
Larry Finger5e93f352014-03-28 21:37:38 -0500304
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700305 /* issue null data to check sta alive */
Larry Finger5e93f352014-03-28 21:37:38 -0500306 for (i = 0; i < chk_alive_num; i++) {
307
308 int ret = _FAIL;
309
Jes Sorensen69642132014-05-09 15:03:47 +0200310 psta = chk_alive_list[i];
Aybuke Ozdemirb34ba0c2014-09-28 17:22:36 +0300311 if (!(psta->state & _FW_LINKED))
Larry Finger5e93f352014-03-28 21:37:38 -0500312 continue;
313
314 if (psta->state & WIFI_SLEEP_STATE)
315 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 1, 50);
316 else
317 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 3, 50);
318
319 psta->keep_alive_trycnt++;
Tina Ruchandanif2372162014-10-23 20:16:51 -0700320 if (ret == _SUCCESS) {
Joe Perchesea072782015-03-24 11:10:09 -0700321 DBG_8723A("asoc check, sta(%pM) is alive\n",
322 psta->hwaddr);
Larry Finger5e93f352014-03-28 21:37:38 -0500323 psta->expire_to = pstapriv->expire_to;
324 psta->keep_alive_trycnt = 0;
325 continue;
Tina Ruchandanif2372162014-10-23 20:16:51 -0700326 } else if (psta->keep_alive_trycnt <= 3) {
Larry Finger5e93f352014-03-28 21:37:38 -0500327 DBG_8723A("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
328 psta->expire_to = 1;
329 continue;
330 }
331
332 psta->keep_alive_trycnt = 0;
333
Joe Perchesea072782015-03-24 11:10:09 -0700334 DBG_8723A("asoc expire %pM, state = 0x%x\n",
335 psta->hwaddr, psta->state);
Larry Finger5e93f352014-03-28 21:37:38 -0500336 spin_lock_bh(&pstapriv->asoc_list_lock);
337 if (!list_empty(&psta->asoc_list)) {
338 list_del_init(&psta->asoc_list);
339 pstapriv->asoc_list_cnt--;
340 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
341 }
342 spin_unlock_bh(&pstapriv->asoc_list_lock);
343
344 }
345
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700346 if (backup_oper_channel > 0) /* back to original operation channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500347 SelectChannel23a(padapter, backup_oper_channel);
348}
349
350 associated_clients_update23a(padapter, updated);
351}
352
353void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_level)
354{
355 int i;
356 u8 rf_type;
357 u32 init_rate = 0;
358 unsigned char sta_band = 0, raid, shortGIrate = false;
359 unsigned char limit;
360 unsigned int tx_ra_bitmap = 0;
361 struct ht_priv *psta_ht = NULL;
362 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200363 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500364
365 if (psta)
366 psta_ht = &psta->htpriv;
367 else
368 return;
369
370 if (!(psta->state & _FW_LINKED))
371 return;
372
373 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700374 for (i = 0; i < sizeof(psta->bssrateset); i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500375 if (psta->bssrateset[i])
376 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
377 }
378 /* n mode ra_bitmap */
Jes Sorensenc2370e82014-04-09 23:20:53 +0200379 if (psta_ht->ht_option) {
380 rf_type = rtl8723a_get_rf_type(padapter);
381
Larry Finger5e93f352014-03-28 21:37:38 -0500382 if (rf_type == RF_2T2R)
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700383 limit = 16; /* 2R */
Larry Finger5e93f352014-03-28 21:37:38 -0500384 else
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700385 limit = 8; /* 1R */
Larry Finger5e93f352014-03-28 21:37:38 -0500386
Jes Sorensen5a4438932014-05-09 15:04:15 +0200387 for (i = 0; i < limit; i++) {
388 if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
389 tx_ra_bitmap |= BIT(i + 12);
Larry Finger5e93f352014-03-28 21:37:38 -0500390 }
391
392 /* max short GI rate */
393 shortGIrate = psta_ht->sgi;
394 }
395
Jes Sorensen37cb9822014-05-21 09:37:40 +0200396 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500397 /* 5G band */
398 if (tx_ra_bitmap & 0xffff000)
399 sta_band |= WIRELESS_11_5N | WIRELESS_11A;
400 else
401 sta_band |= WIRELESS_11A;
402 } else {
403 if (tx_ra_bitmap & 0xffff000)
404 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
405 else if (tx_ra_bitmap & 0xff0)
Aybuke Ozdemirdd609252014-09-28 17:22:37 +0300406 sta_band |= WIRELESS_11G | WIRELESS_11B;
Larry Finger5e93f352014-03-28 21:37:38 -0500407 else
408 sta_band |= WIRELESS_11B;
409 }
410
411 psta->wireless_mode = sta_band;
412
413 raid = networktype_to_raid23a(sta_band);
414 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
415
Tina Ruchandanif2372162014-10-23 20:16:51 -0700416 if (psta->aid < NUM_STA) {
Amitoj Kaur Chawlad538ae32015-10-15 13:38:21 +0530417 u8 arg;
Larry Finger5e93f352014-03-28 21:37:38 -0500418
419 arg = psta->mac_id&0x1f;
420
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700421 arg |= BIT(7); /* support entry 2~31 */
Larry Finger5e93f352014-03-28 21:37:38 -0500422
423 if (shortGIrate == true)
424 arg |= BIT(5);
425
426 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
427
428 DBG_8723A("%s => mac_id:%d , raid:%d , bitmap = 0x%x, arg = "
429 "0x%x\n",
430 __func__, psta->mac_id, raid, tx_ra_bitmap, arg);
431
432 /* bitmap[0:27] = tx_rate_bitmap */
433 /* bitmap[28:31]= Rate Adaptive id */
434 /* arg[0:4] = macid */
435 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200436 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, rssi_level);
Larry Finger5e93f352014-03-28 21:37:38 -0500437
438 if (shortGIrate == true)
439 init_rate |= BIT(6);
440
441 /* set ra_id, init_rate */
442 psta->raid = raid;
443 psta->init_rate = init_rate;
444
Tina Ruchandanif2372162014-10-23 20:16:51 -0700445 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500446 DBG_8723A("station aid %d exceed the max number\n", psta->aid);
Larry Finger5e93f352014-03-28 21:37:38 -0500447}
448
449static void update_bmc_sta(struct rtw_adapter *padapter)
450{
451 u32 init_rate = 0;
452 unsigned char network_type, raid;
453 int i, supportRateNum = 0;
454 unsigned int tx_ra_bitmap = 0;
455 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200456 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500457 struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter);
458
Tina Ruchandanif2372162014-10-23 20:16:51 -0700459 if (psta) {
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700460 psta->aid = 0; /* default set to 0 */
Larry Finger5e93f352014-03-28 21:37:38 -0500461 psta->mac_id = psta->aid + 1;
462
463 psta->qos_option = 0;
464 psta->htpriv.ht_option = false;
465
466 psta->ieee8021x_blocked = 0;
467
Greg Donald7e6646d2014-09-06 19:42:03 -0500468 memset((void *)&psta->sta_stats, 0,
469 sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500470
471 /* prepare for add_RATid23a */
Joe Borg22faca22014-12-16 02:54:32 -0500472 supportRateNum = rtw_get_rateset_len23a((u8 *)&pcur_network->SupportedRates);
473 network_type = rtw_check_network_type23a((u8 *)&pcur_network->SupportedRates, supportRateNum, 1);
Larry Finger5e93f352014-03-28 21:37:38 -0500474
475 memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
476 psta->bssratelen = supportRateNum;
477
478 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700479 for (i = 0; i < supportRateNum; i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500480 if (psta->bssrateset[i])
481 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
482 }
483
Jes Sorensen37cb9822014-05-21 09:37:40 +0200484 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500485 /* force to A mode. 5G doesn't support CCK rates */
486 network_type = WIRELESS_11A;
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700487 tx_ra_bitmap = 0x150; /* 6, 12, 24 Mbps */
Larry Finger5e93f352014-03-28 21:37:38 -0500488 } else {
489 /* force to b mode */
490 network_type = WIRELESS_11B;
491 tx_ra_bitmap = 0xf;
492 }
493
494 raid = networktype_to_raid23a(network_type);
495 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
496
497 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200498 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500499
500 {
Amitoj Kaur Chawlad538ae32015-10-15 13:38:21 +0530501 u8 arg;
Larry Finger5e93f352014-03-28 21:37:38 -0500502
503 arg = psta->mac_id&0x1f;
504
505 arg |= BIT(7);
506
507 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
508
509 DBG_8723A("update_bmc_sta, mask = 0x%x, arg = 0x%x\n", tx_ra_bitmap, arg);
510
511 /* bitmap[0:27] = tx_rate_bitmap */
512 /* bitmap[28:31]= Rate Adaptive id */
513 /* arg[0:4] = macid */
514 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200515 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, 0);
Larry Finger5e93f352014-03-28 21:37:38 -0500516 }
517
518 /* set ra_id, init_rate */
519 psta->raid = raid;
520 psta->init_rate = init_rate;
521
Larry Finger5e93f352014-03-28 21:37:38 -0500522 spin_lock_bh(&psta->lock);
523 psta->state = _FW_LINKED;
524 spin_unlock_bh(&psta->lock);
525
Tina Ruchandanif2372162014-10-23 20:16:51 -0700526 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500527 DBG_8723A("add_RATid23a_bmc_sta error!\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500528}
529
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700530/*
531 * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode
532 * MAC_ID = AID+1 for sta in ap/adhoc mode
533 * MAC_ID = 1 for bc/mc for sta/ap/adhoc
534 * MAC_ID = 0 for bssid for sta/ap/adhoc
535 * CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid + 1;
536 */
Larry Finger5e93f352014-03-28 21:37:38 -0500537void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info *psta)
538{
539 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
540 struct security_priv *psecuritypriv = &padapter->securitypriv;
541 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
542 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
543 struct ht_priv *phtpriv_sta = &psta->htpriv;
544 /* set intf_tag to if1 */
545
546 psta->mac_id = psta->aid+1;
547 DBG_8723A("%s\n", __func__);
548
549 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200550 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500551
552 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
553 psta->ieee8021x_blocked = true;
554 else
555 psta->ieee8021x_blocked = false;
556
557 /* update sta's cap */
558
559 /* ERP */
560 VCS_update23a(padapter, psta);
561 /* HT related cap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700562 if (phtpriv_sta->ht_option) {
Larry Finger5e93f352014-03-28 21:37:38 -0500563 /* check if sta supports rx ampdu */
564 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
565
566 /* check if sta support s Short GI */
567 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))
568 phtpriv_sta->sgi = true;
569
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700570 /* bwmode */
Larry Finger5e93f352014-03-28 21:37:38 -0500571 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
572 /* phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_40; */
573 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
574 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
575
576 }
577
578 psta->qos_option = true;
579
Tina Ruchandanif2372162014-10-23 20:16:51 -0700580 } else {
Larry Finger5e93f352014-03-28 21:37:38 -0500581 phtpriv_sta->ampdu_enable = false;
582
583 phtpriv_sta->sgi = false;
584 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
585 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
586 }
587
588 /* Rx AMPDU */
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700589 send_delba23a(padapter, 0, psta->hwaddr); /* recipient */
Larry Finger5e93f352014-03-28 21:37:38 -0500590
591 /* TX AMPDU */
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700592 send_delba23a(padapter, 1, psta->hwaddr); /* originator */
Larry Finger5e93f352014-03-28 21:37:38 -0500593 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
594 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
595
596 /* todo: init other variables */
597
Greg Donald7e6646d2014-09-06 19:42:03 -0500598 memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500599
600 spin_lock_bh(&psta->lock);
601 psta->state |= _FW_LINKED;
602 spin_unlock_bh(&psta->lock);
603}
604
605static void update_hw_ht_param(struct rtw_adapter *padapter)
606{
607 unsigned char max_AMPDU_len;
608 unsigned char min_MPDU_spacing;
609 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
610 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
611
612 DBG_8723A("%s\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -0500613 /*
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700614 * handle A-MPDU parameter field
615 * AMPDU_para [1:0]:Max AMPDU Len => 0:8k, 1:16k, 2:32k, 3:64k
616 * AMPDU_para [4:2]:Min MPDU Start Spacing
Larry Finger5e93f352014-03-28 21:37:38 -0500617 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200618 max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
619 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500620
Jes Sorensen65be27d2014-05-31 18:05:11 +0200621 min_MPDU_spacing = (pmlmeinfo->ht_cap.ampdu_params_info &
622 IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500623
Jes Sorensendce610a2014-04-09 23:20:32 +0200624 rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
625 rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
Larry Finger5e93f352014-03-28 21:37:38 -0500626
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700627 /* Config SM Power Save setting */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200628 pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->ht_cap.cap_info) &
629 IEEE80211_HT_CAP_SM_PS) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500630 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
631 DBG_8723A("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
632}
633
634static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
635{
Jes Sorensen731f9da2014-04-15 19:44:02 +0200636 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -0500637 u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
638 u16 bcn_interval;
639 u32 acparm;
Larry Finger5e93f352014-03-28 21:37:38 -0500640 struct registry_priv *pregpriv = &padapter->registrypriv;
641 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Greg Donald4e66cf02014-08-22 10:57:49 -0500642 struct security_priv *psecuritypriv = &padapter->securitypriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200643 struct wlan_bssid_ex *pnetwork = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500644 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
645 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
646 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200647 struct ieee80211_ht_operation *pht_info = NULL;
Larry Finger5e93f352014-03-28 21:37:38 -0500648
Jes Sorensen143ced22014-06-19 11:37:22 +0200649 bcn_interval = (u16)pnetwork->beacon_interval;
Jes Sorensen37cb9822014-05-21 09:37:40 +0200650 cur_channel = pnetwork->DSConfig;
Roberta Dobrescub9b42242014-10-26 23:30:06 +0200651 cur_bwmode = HT_CHANNEL_WIDTH_20;
Larry Finger5e93f352014-03-28 21:37:38 -0500652 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
653
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700654 /*
655 * check if there is wps ie
656 * if there is wpsie in beacon the hostapd will
657 * update beacon twice when stating hostapd
658 * and at first time the security
659 * ie (RSN/WPA IE) will not include in beacon
660 */
Alison Schofield48c95782015-10-23 21:32:20 -0700661 if (!cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
662 WLAN_OUI_TYPE_MICROSOFT_WPS,
663 pnetwork->IEs,
664 pnetwork->IELength))
Larry Finger5e93f352014-03-28 21:37:38 -0500665 pmlmeext->bstart_bss = true;
666
667 /* todo: update wmm, ht cap */
668 /* pmlmeinfo->WMM_enable; */
669 /* pmlmeinfo->HT_enable; */
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200670 if (pmlmepriv->qos_option)
Larry Finger5e93f352014-03-28 21:37:38 -0500671 pmlmeinfo->WMM_enable = true;
672 if (pmlmepriv->htpriv.ht_option) {
673 pmlmeinfo->WMM_enable = true;
674 pmlmeinfo->HT_enable = true;
675
676 update_hw_ht_param(padapter);
677 }
678
679 if (pmlmepriv->cur_network.join_res != true) {
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700680 /*
681 * setting only at first time
682 * WEP Key will be set before this
683 * function, do not clear CAM.
684 */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200685 if (psecuritypriv->dot11PrivacyAlgrthm !=
686 WLAN_CIPHER_SUITE_WEP40 &&
687 psecuritypriv->dot11PrivacyAlgrthm !=
688 WLAN_CIPHER_SUITE_WEP104)
Larry Finger5e93f352014-03-28 21:37:38 -0500689 flush_all_cam_entry23a(padapter); /* clear CAM */
690 }
691
692 /* set MSR to AP_Mode */
Jes Sorensen6ec26272014-07-17 22:59:46 +0200693 rtl8723a_set_media_status(padapter, MSR_AP);
Larry Finger5e93f352014-03-28 21:37:38 -0500694
695 /* Set BSSID REG */
Jes Sorensen38dd10b2014-04-09 23:20:20 +0200696 hw_var_set_bssid(padapter, pnetwork->MacAddress);
Larry Finger5e93f352014-03-28 21:37:38 -0500697
698 /* Set EDCA param reg */
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700699 acparm = 0x002F3217; /* VO */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200700 rtl8723a_set_ac_param_vo(padapter, acparm);
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700701 acparm = 0x005E4317; /* VI */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200702 rtl8723a_set_ac_param_vi(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500703 acparm = 0x005ea42b;
Jes Sorensen2487205e2014-04-09 23:20:30 +0200704 rtl8723a_set_ac_param_be(padapter, acparm);
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700705 acparm = 0x0000A444; /* BK */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200706 rtl8723a_set_ac_param_bk(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500707
708 /* Set Security */
Jes Sorensenb8e99162014-04-09 23:20:27 +0200709 val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ?
MihaelaGamanadabff82014-09-14 12:56:43 +0300710 0xcc : 0xcf;
Jes Sorensenb8e99162014-04-09 23:20:27 +0200711 rtl8723a_set_sec_cfg(padapter, val8);
Larry Finger5e93f352014-03-28 21:37:38 -0500712
713 /* Beacon Control related register */
Jes Sorensen477f0082014-04-09 23:20:23 +0200714 rtl8723a_set_beacon_interval(padapter, bcn_interval);
Larry Finger5e93f352014-03-28 21:37:38 -0500715
716 UpdateBrateTbl23a(padapter, pnetwork->SupportedRates);
Jes Sorensenfa2e5202014-04-09 23:20:18 +0200717 HalSetBrateCfg23a(padapter, pnetwork->SupportedRates);
Larry Finger5e93f352014-03-28 21:37:38 -0500718
719 if (!pmlmepriv->cur_network.join_res) {
720 /* setting only at first time */
721
722 /* disable dynamic functions, such as high power, DIG */
723
724 /* turn on all dynamic functions */
Jes Sorensen585eefb2014-04-09 23:20:43 +0200725 rtl8723a_odm_support_ability_set(padapter,
726 DYNAMIC_ALL_FUNC_ENABLE);
Larry Finger5e93f352014-03-28 21:37:38 -0500727 }
728 /* set channel, bwmode */
Jes Sorensenc164bcf2014-05-21 09:37:41 +0200729
Jes Sorensen68e6c792014-06-24 15:03:29 +0200730 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION, pnetwork->IEs,
731 pnetwork->IELength);
Jes Sorensen731f9da2014-04-15 19:44:02 +0200732 if (p && p[1]) {
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200733 pht_info = (struct ieee80211_ht_operation *)(p + 2);
Larry Finger5e93f352014-03-28 21:37:38 -0500734
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200735 if (pregpriv->cbw40_enable && pht_info->ht_param &
736 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) {
Larry Finger5e93f352014-03-28 21:37:38 -0500737 /* switch to the 40M Hz mode */
738 cur_bwmode = HT_CHANNEL_WIDTH_40;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200739 switch (pht_info->ht_param &
740 IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
741 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700742 /*
743 * pmlmeext->cur_ch_offset =
744 * HAL_PRIME_CHNL_OFFSET_LOWER;
745 */
Larry Finger5e93f352014-03-28 21:37:38 -0500746 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
747 break;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200748 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Larry Finger5e93f352014-03-28 21:37:38 -0500749 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
750 break;
751 default:
752 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
753 break;
754 }
755 }
756 }
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700757 /*
758 * TODO: need to judge the phy parameters
759 * on concurrent mode for single phy
760 */
Larry Finger5e93f352014-03-28 21:37:38 -0500761 set_channel_bwmode23a(padapter, cur_channel, cur_ch_offset, cur_bwmode);
762
763 DBG_8723A("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode,
764 cur_ch_offset);
765
766 pmlmeext->cur_channel = cur_channel;
767 pmlmeext->cur_bwmode = cur_bwmode;
768 pmlmeext->cur_ch_offset = cur_ch_offset;
769 pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
770
771 /* update cur_wireless_mode */
772 update_wireless_mode23a(padapter);
773
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900774 /* update capability after cur_wireless_mode updated */
Jes Sorensena94e12b2014-06-19 11:37:34 +0200775 update_capinfo23a(padapter, pnetwork->capability);
Larry Finger5e93f352014-03-28 21:37:38 -0500776
777 /* let pnetwork_mlmeext == pnetwork_mlme. */
778 memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
779
Larry Finger5e93f352014-03-28 21:37:38 -0500780 if (pmlmeext->bstart_bss) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200781 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500782
783 /* issue beacon frame */
784 if (send_beacon23a(padapter) == _FAIL)
785 DBG_8723A("issue_beacon23a, fail!\n");
786 }
787
788 /* update bc/mc sta_info */
789 update_bmc_sta(padapter);
790}
791
Jes Sorensenfb5fd462014-06-24 15:03:20 +0200792int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
793 struct ieee80211_mgmt *mgmt, unsigned int len)
Larry Finger5e93f352014-03-28 21:37:38 -0500794{
795 int ret = _SUCCESS;
796 u8 *p;
797 u8 *pHT_caps_ie = NULL;
798 u8 *pHT_info_ie = NULL;
799 struct sta_info *psta = NULL;
Jes Sorensen51a26d22014-06-24 15:03:21 +0200800 u16 ht_cap = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500801 uint ie_len = 0;
802 int group_cipher, pairwise_cipher;
803 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
804 int supportRateNum = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500805 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
806 struct registry_priv *pregistrypriv = &padapter->registrypriv;
807 struct security_priv *psecuritypriv = &padapter->securitypriv;
808 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
809 struct wlan_bssid_ex *pbss_network = &pmlmepriv->cur_network.network;
810 u8 *ie = pbss_network->IEs;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200811 u8 *pbuf = mgmt->u.beacon.variable;
Dilek Uzulmez91701e42015-02-24 15:14:26 +0200812
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200813 len -= offsetof(struct ieee80211_mgmt, u.beacon.variable);
Larry Finger5e93f352014-03-28 21:37:38 -0500814 /* SSID */
815 /* Supported rates */
816 /* DS Params */
817 /* WLAN_EID_COUNTRY */
818 /* ERP Information element */
819 /* Extended supported rates */
820 /* WPA/WPA2 */
821 /* Wi-Fi Wireless Multimedia Extensions */
822 /* ht_capab, ht_oper */
823 /* WPS IE */
824
825 DBG_8723A("%s, len =%d\n", __func__, len);
826
827 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
828 return _FAIL;
829
Jes Sorensen8282aeb2014-04-26 18:54:53 +0200830 if (len > MAX_IE_SZ)
Larry Finger5e93f352014-03-28 21:37:38 -0500831 return _FAIL;
832
833 pbss_network->IELength = len;
834
835 memset(ie, 0, MAX_IE_SZ);
836
837 memcpy(ie, pbuf, pbss_network->IELength);
838
Jes Sorensenefc71442014-05-21 09:37:26 +0200839 if (pbss_network->ifmode != NL80211_IFTYPE_AP &&
840 pbss_network->ifmode != NL80211_IFTYPE_P2P_GO)
Larry Finger5e93f352014-03-28 21:37:38 -0500841 return _FAIL;
842
843 pbss_network->Rssi = 0;
844
845 memcpy(pbss_network->MacAddress, myid(&padapter->eeprompriv), ETH_ALEN);
846
Larry Finger5e93f352014-03-28 21:37:38 -0500847 /* SSID */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200848 p = rtw_get_ie23a(ie, WLAN_EID_SSID, &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500849 if (p && ie_len > 0) {
850 memset(&pbss_network->Ssid, 0, sizeof(struct cfg80211_ssid));
851 memcpy(pbss_network->Ssid.ssid, (p + 2), ie_len);
852 pbss_network->Ssid.ssid_len = ie_len;
853 }
854
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900855 /* channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500856 channel = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200857 p = rtw_get_ie23a(ie, WLAN_EID_DS_PARAMS, &ie_len,
858 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500859 if (p && ie_len > 0)
860 channel = *(p + 2);
861
Jes Sorensen37cb9822014-05-21 09:37:40 +0200862 pbss_network->DSConfig = channel;
Larry Finger5e93f352014-03-28 21:37:38 -0500863
864 memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
865 /* get supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200866 p = rtw_get_ie23a(ie, WLAN_EID_SUPP_RATES, &ie_len,
867 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500868 if (p) {
869 memcpy(supportRate, p+2, ie_len);
870 supportRateNum = ie_len;
871 }
872
873 /* get ext_supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200874 p = rtw_get_ie23a(ie, WLAN_EID_EXT_SUPP_RATES,
875 &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500876 if (p) {
877 memcpy(supportRate+supportRateNum, p+2, ie_len);
878 supportRateNum += ie_len;
879 }
880
881 network_type = rtw_check_network_type23a(supportRate,
882 supportRateNum, channel);
883
884 rtw_set_supported_rate23a(pbss_network->SupportedRates, network_type);
885
886 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200887 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &ie_len,
888 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500889 if (p && ie_len > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +0200890 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -0500891
892 /* update privacy/security */
Jes Sorensen51a26d22014-06-24 15:03:21 +0200893 if (pbss_network->capability & BIT(4))
Larry Finger5e93f352014-03-28 21:37:38 -0500894 pbss_network->Privacy = 1;
895 else
896 pbss_network->Privacy = 0;
897
898 psecuritypriv->wpa_psk = 0;
899
900 /* wpa2 */
901 group_cipher = 0; pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200902 psecuritypriv->wpa2_group_cipher = 0;
903 psecuritypriv->wpa2_pairwise_cipher = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200904 p = rtw_get_ie23a(ie, WLAN_EID_RSN, &ie_len,
905 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500906 if (p && ie_len > 0) {
907 if (rtw_parse_wpa2_ie23a(p, ie_len+2, &group_cipher,
908 &pairwise_cipher, NULL) == _SUCCESS) {
909 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
910
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700911 psecuritypriv->dot8021xalg = 1; /* psk, todo:802.1x */
Larry Finger5e93f352014-03-28 21:37:38 -0500912 psecuritypriv->wpa_psk |= BIT(1);
913
914 psecuritypriv->wpa2_group_cipher = group_cipher;
915 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
916 }
917 }
918
919 /* wpa */
920 ie_len = 0;
921 group_cipher = 0;
922 pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200923 psecuritypriv->wpa_group_cipher = 0;
924 psecuritypriv->wpa_pairwise_cipher = 0;
Joe Borg22faca22014-12-16 02:54:32 -0500925 for (p = ie; ; p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200926 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200927 pbss_network->IELength - (ie_len + 2));
Jes Sorensen819d1812014-04-26 18:55:44 +0200928 if ((p) && (!memcmp(p+2, RTW_WPA_OUI23A_TYPE, 4))) {
Larry Finger5e93f352014-03-28 21:37:38 -0500929 if (rtw_parse_wpa_ie23a(p, ie_len+2, &group_cipher,
930 &pairwise_cipher, NULL) == _SUCCESS) {
931 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
932
933 /* psk, todo:802.1x */
934 psecuritypriv->dot8021xalg = 1;
935
936 psecuritypriv->wpa_psk |= BIT(0);
937
938 psecuritypriv->wpa_group_cipher = group_cipher;
939 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
940 }
941 break;
942 }
943
Alison Schofield2f31c4b2015-10-16 11:46:29 -0700944 if (!p || !ie_len)
945 break;
Larry Finger5e93f352014-03-28 21:37:38 -0500946 }
947
948 /* wmm */
949 ie_len = 0;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200950 pmlmepriv->qos_option = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500951 if (pregistrypriv->wmm_enable) {
Joe Borg22faca22014-12-16 02:54:32 -0500952 for (p = ie; ; p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200953 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Larry Finger5e93f352014-03-28 21:37:38 -0500954 (pbss_network->IELength -
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200955 (ie_len + 2)));
Larry Finger5e93f352014-03-28 21:37:38 -0500956 if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) {
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200957 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500958
Alison Schofielde9cd7af2015-10-23 21:28:00 -0700959 *(p + 8) |= BIT(7);/* QoS Info:support U-APSD */
Larry Finger5e93f352014-03-28 21:37:38 -0500960
961 /* disable all ACM bits since the WMM admission
962 * control is not supported
963 */
964 *(p + 10) &= ~BIT(4); /* BE */
965 *(p + 14) &= ~BIT(4); /* BK */
966 *(p + 18) &= ~BIT(4); /* VI */
967 *(p + 22) &= ~BIT(4); /* VO */
968 break;
969 }
970 if ((p == NULL) || (ie_len == 0))
971 break;
972 }
973 }
974 /* parsing HT_CAP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200975 p = rtw_get_ie23a(ie, WLAN_EID_HT_CAPABILITY, &ie_len,
976 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500977 if (p && ie_len > 0) {
978 u8 rf_type;
979
980 struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p+2);
981
982 pHT_caps_ie = p;
983
984 ht_cap = true;
985 network_type |= WIRELESS_11_24N;
986
Jes Sorensenc2370e82014-04-09 23:20:53 +0200987 rf_type = rtl8723a_get_rf_type(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500988
989 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
990 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
991 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY & (0x07<<2));
992 else
993 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY&0x00);
994
995 /* set Max Rx AMPDU size to 64K */
996 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_FACTOR & 0x03);
997
998 if (rf_type == RF_1T1R) {
999 pht_cap->mcs.rx_mask[0] = 0xff;
1000 pht_cap->mcs.rx_mask[1] = 0x0;
1001 }
1002
1003 memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len);
1004 }
1005
1006 /* parsing HT_INFO_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +02001007 p = rtw_get_ie23a(ie, WLAN_EID_HT_OPERATION, &ie_len,
1008 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -05001009 if (p && ie_len > 0)
1010 pHT_info_ie = p;
1011
Larry Finger5e93f352014-03-28 21:37:38 -05001012 pmlmepriv->cur_network.network_type = network_type;
1013
1014 pmlmepriv->htpriv.ht_option = false;
1015
1016 /* ht_cap */
1017 if (pregistrypriv->ht_enable && ht_cap) {
1018 pmlmepriv->htpriv.ht_option = true;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +02001019 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -05001020
1021 if (pregistrypriv->ampdu_enable == 1)
1022 pmlmepriv->htpriv.ampdu_enable = true;
1023
Jes Sorensenb171da32014-05-21 09:37:42 +02001024 HT_caps_handler23a(padapter, pHT_caps_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001025
Jes Sorensenb171da32014-05-21 09:37:42 +02001026 HT_info_handler23a(padapter, pHT_info_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001027 }
1028
Jes Sorensen52017952014-04-26 18:55:09 +02001029 pbss_network->Length = get_wlan_bssid_ex_sz(pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001030
1031 /* issue beacon to start bss network */
Greg Donald7e6646d2014-09-06 19:42:03 -05001032 start_bss_network(padapter, (u8 *)pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001033
1034 /* alloc sta_info for ap itself */
1035 psta = rtw_get_stainfo23a(&padapter->stapriv, pbss_network->MacAddress);
1036 if (!psta) {
Jes Sorensen6e8bc712014-05-09 15:03:49 +02001037 psta = rtw_alloc_stainfo23a(&padapter->stapriv,
1038 pbss_network->MacAddress,
1039 GFP_KERNEL);
Larry Finger5e93f352014-03-28 21:37:38 -05001040 if (!psta)
1041 return _FAIL;
1042 }
1043 /* fix bug of flush_cam_entry at STOP AP mode */
1044 psta->state |= WIFI_AP_STATE;
1045 rtw_indicate_connect23a(padapter);
1046
1047 /* for check if already set beacon */
1048 pmlmepriv->cur_network.join_res = true;
1049
1050 return ret;
1051}
1052
1053void rtw_set_macaddr_acl23a(struct rtw_adapter *padapter, int mode)
1054{
1055 struct sta_priv *pstapriv = &padapter->stapriv;
1056 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1057
1058 DBG_8723A("%s, mode =%d\n", __func__, mode);
1059
1060 pacl_list->mode = mode;
1061}
1062
1063int rtw_acl_add_sta23a(struct rtw_adapter *padapter, u8 *addr)
1064{
1065 struct list_head *plist, *phead;
1066 u8 added = false;
1067 int i, ret = 0;
1068 struct rtw_wlan_acl_node *paclnode;
1069 struct sta_priv *pstapriv = &padapter->stapriv;
1070 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1071 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1072
Joe Perchesea072782015-03-24 11:10:09 -07001073 DBG_8723A("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, addr);
Larry Finger5e93f352014-03-28 21:37:38 -05001074
1075 if ((NUM_ACL-1) < pacl_list->num)
1076 return -1;
1077
1078 spin_lock_bh(&pacl_node_q->lock);
1079
1080 phead = get_list_head(pacl_node_q);
1081
1082 list_for_each(plist, phead) {
1083 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1084
1085 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1086 if (paclnode->valid == true) {
1087 added = true;
1088 DBG_8723A("%s, sta has been added\n", __func__);
1089 break;
1090 }
1091 }
1092 }
1093
1094 spin_unlock_bh(&pacl_node_q->lock);
1095
1096 if (added)
1097 return ret;
1098
1099 spin_lock_bh(&pacl_node_q->lock);
1100
1101 for (i = 0; i < NUM_ACL; i++) {
1102 paclnode = &pacl_list->aclnode[i];
1103
1104 if (!paclnode->valid) {
1105 INIT_LIST_HEAD(&paclnode->list);
1106
1107 memcpy(paclnode->addr, addr, ETH_ALEN);
1108
1109 paclnode->valid = true;
1110
1111 list_add_tail(&paclnode->list, get_list_head(pacl_node_q));
1112
1113 pacl_list->num++;
1114
1115 break;
1116 }
1117 }
1118
1119 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1120
1121 spin_unlock_bh(&pacl_node_q->lock);
1122 return ret;
1123}
1124
1125int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
1126{
1127 struct list_head *plist, *phead, *ptmp;
1128 struct rtw_wlan_acl_node *paclnode;
1129 struct sta_priv *pstapriv = &padapter->stapriv;
1130 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1131 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
Larry Finger5e93f352014-03-28 21:37:38 -05001132
1133 DBG_8723A("%s(acl_num =%d) = %pM\n", __func__, pacl_list->num, addr);
1134
1135 spin_lock_bh(&pacl_node_q->lock);
1136
1137 phead = get_list_head(pacl_node_q);
1138
1139 list_for_each_safe(plist, ptmp, phead) {
1140 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1141
1142 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1143 if (paclnode->valid) {
1144 paclnode->valid = false;
1145
1146 list_del_init(&paclnode->list);
1147
1148 pacl_list->num--;
1149 }
1150 }
1151 }
1152
1153 spin_unlock_bh(&pacl_node_q->lock);
1154
1155 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1156
Heena Sirwanif9800f82014-10-07 14:46:30 +05301157 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001158}
1159
1160static void update_bcn_fixed_ie(struct rtw_adapter *padapter)
1161{
1162 DBG_8723A("%s\n", __func__);
1163}
1164
1165static void update_bcn_erpinfo_ie(struct rtw_adapter *padapter)
1166{
1167 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1168 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1169 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1170 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1171 unsigned char *p, *ie = pnetwork->IEs;
1172 u32 len = 0;
1173
1174 DBG_8723A("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1175
1176 if (!pmlmeinfo->ERP_enable)
1177 return;
1178
1179 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +02001180 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &len, pnetwork->IELength);
Jes Sorensenb171da32014-05-21 09:37:42 +02001181 if (p && len > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001182 if (pmlmepriv->num_sta_non_erp == 1)
Jes Sorensenb171da32014-05-21 09:37:42 +02001183 p[2] |= WLAN_ERP_NON_ERP_PRESENT |
Larry Finger5e93f352014-03-28 21:37:38 -05001184 WLAN_ERP_USE_PROTECTION;
1185 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001186 p[2] &= ~(WLAN_ERP_NON_ERP_PRESENT |
1187 WLAN_ERP_USE_PROTECTION);
Larry Finger5e93f352014-03-28 21:37:38 -05001188
1189 if (pmlmepriv->num_sta_no_short_preamble > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +02001190 p[2] |= WLAN_ERP_BARKER_PREAMBLE;
Larry Finger5e93f352014-03-28 21:37:38 -05001191 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001192 p[2] &= ~(WLAN_ERP_BARKER_PREAMBLE);
Larry Finger5e93f352014-03-28 21:37:38 -05001193
Jes Sorensenb171da32014-05-21 09:37:42 +02001194 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -05001195 }
1196}
1197
1198static void update_bcn_htcap_ie(struct rtw_adapter *padapter)
1199{
1200 DBG_8723A("%s\n", __func__);
1201}
1202
1203static void update_bcn_htinfo_ie(struct rtw_adapter *padapter)
1204{
1205 DBG_8723A("%s\n", __func__);
1206}
1207
1208static void update_bcn_rsn_ie(struct rtw_adapter *padapter)
1209{
1210 DBG_8723A("%s\n", __func__);
1211}
1212
1213static void update_bcn_wpa_ie(struct rtw_adapter *padapter)
1214{
1215 DBG_8723A("%s\n", __func__);
1216}
1217
1218static void update_bcn_wmm_ie(struct rtw_adapter *padapter)
1219{
1220 DBG_8723A("%s\n", __func__);
1221}
1222
1223static void update_bcn_wps_ie(struct rtw_adapter *padapter)
1224{
Larry Finger5e93f352014-03-28 21:37:38 -05001225 DBG_8723A("%s\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -05001226}
1227
1228static void update_bcn_p2p_ie(struct rtw_adapter *padapter)
1229{
1230}
1231
Joe Borg22faca22014-12-16 02:54:32 -05001232static void update_bcn_vendor_spec_ie(struct rtw_adapter *padapter, u8 *oui)
Larry Finger5e93f352014-03-28 21:37:38 -05001233{
1234 DBG_8723A("%s\n", __func__);
1235
Jes Sorensen7964eba02014-04-15 19:44:11 +02001236 if (!memcmp(RTW_WPA_OUI23A_TYPE, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001237 update_bcn_wpa_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001238 else if (!memcmp(WMM_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001239 update_bcn_wmm_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001240 else if (!memcmp(WPS_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001241 update_bcn_wps_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001242 else if (!memcmp(P2P_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001243 update_bcn_p2p_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001244 else
Larry Finger5e93f352014-03-28 21:37:38 -05001245 DBG_8723A("unknown OUI type!\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001246}
1247
1248void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1249{
1250 struct mlme_priv *pmlmepriv;
1251 struct mlme_ext_priv *pmlmeext;
1252 /* struct mlme_ext_info *pmlmeinfo; */
1253
1254 /* DBG_8723A("%s\n", __func__); */
1255
1256 if (!padapter)
1257 return;
1258
1259 pmlmepriv = &padapter->mlmepriv;
1260 pmlmeext = &padapter->mlmeextpriv;
1261 /* pmlmeinfo = &pmlmeext->mlmext_info; */
1262
1263 if (false == pmlmeext->bstart_bss)
1264 return;
1265
1266 spin_lock_bh(&pmlmepriv->bcn_update_lock);
1267
Tina Ruchandanif2372162014-10-23 20:16:51 -07001268 switch (ie_id) {
Jes Sorensenb54e8802014-04-09 23:20:52 +02001269 case 0xFF:
1270 /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1271 update_bcn_fixed_ie(padapter);
1272 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001273
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001274 case WLAN_EID_TIM:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001275 update_BCNTIM(padapter);
1276 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001277
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001278 case WLAN_EID_ERP_INFO:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001279 update_bcn_erpinfo_ie(padapter);
1280 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001281
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001282 case WLAN_EID_HT_CAPABILITY:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001283 update_bcn_htcap_ie(padapter);
1284 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001285
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001286 case WLAN_EID_RSN:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001287 update_bcn_rsn_ie(padapter);
1288 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001289
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001290 case WLAN_EID_HT_OPERATION:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001291 update_bcn_htinfo_ie(padapter);
1292 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001293
Jes Sorensen9300c942014-04-15 19:43:21 +02001294 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001295 update_bcn_vendor_spec_ie(padapter, oui);
1296 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001297
Jes Sorensenb54e8802014-04-09 23:20:52 +02001298 default:
1299 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001300 }
1301
1302 pmlmepriv->update_bcn = true;
1303
1304 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
1305
1306 if (tx)
1307 set_tx_beacon_cmd23a(padapter);
1308}
1309
1310/*
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001311 * op_mode
1312 * Set to 0 (HT pure) under the following conditions
1313 * - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1314 * - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1315 * Set to 1 (HT non-member protection) if there may be non-HT STAs
1316 * in both the primary and the secondary channel
1317 * Set to 2 if only HT STAs are associated in BSS,
1318 * however and at least one 20 MHz HT STA is associated
1319 * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1320 * (currently non-GF HT station is considered as non-HT STA also)
Larry Finger5e93f352014-03-28 21:37:38 -05001321*/
1322static int rtw_ht_operation_update(struct rtw_adapter *padapter)
1323{
1324 u16 cur_op_mode, new_op_mode;
1325 int op_mode_changes = 0;
1326 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1327 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
1328
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001329 if (pmlmepriv->htpriv.ht_option)
Larry Finger5e93f352014-03-28 21:37:38 -05001330 return 0;
1331
1332 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */
1333 /* return 0; */
1334
1335 DBG_8723A("%s current operation mode = 0x%X\n",
1336 __func__, pmlmepriv->ht_op_mode);
1337
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001338 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
Larry Finger5e93f352014-03-28 21:37:38 -05001339 && pmlmepriv->num_sta_ht_no_gf) {
1340 pmlmepriv->ht_op_mode |=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001341 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001342 op_mode_changes++;
1343 } else if ((pmlmepriv->ht_op_mode &
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001344 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001345 pmlmepriv->num_sta_ht_no_gf == 0) {
1346 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001347 ~IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001348 op_mode_changes++;
1349 }
1350
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001351 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001352 (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001353 pmlmepriv->ht_op_mode |= IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001354 op_mode_changes++;
1355 } else if ((pmlmepriv->ht_op_mode &
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001356 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001357 (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
1358 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001359 ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001360 op_mode_changes++;
1361 }
1362
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001363 /*
1364 * Note: currently we switch to the MIXED op mode if HT non-greenfield
Larry Finger5e93f352014-03-28 21:37:38 -05001365 * station is associated. Probably it's a theoretical case, since
1366 * it looks like all known HT STAs support greenfield.
1367 */
Larry Finger5e93f352014-03-28 21:37:38 -05001368 if (pmlmepriv->num_sta_no_ht ||
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001369 (pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
Jes Sorensenc3899282014-05-21 09:37:51 +02001370 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Larry Fingera96ae6f2014-04-26 18:55:18 +02001371 else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) &
1372 IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
1373 pmlmepriv->num_sta_ht_20mhz)
Jes Sorensenc3899282014-05-21 09:37:51 +02001374 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
Larry Finger5e93f352014-03-28 21:37:38 -05001375 else if (pmlmepriv->olbc_ht)
Jes Sorensenc3899282014-05-21 09:37:51 +02001376 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER;
Larry Finger5e93f352014-03-28 21:37:38 -05001377 else
Jes Sorensenc3899282014-05-21 09:37:51 +02001378 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
Larry Finger5e93f352014-03-28 21:37:38 -05001379
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001380 cur_op_mode = pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001381 if (cur_op_mode != new_op_mode) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001382 pmlmepriv->ht_op_mode &= ~IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001383 pmlmepriv->ht_op_mode |= new_op_mode;
1384 op_mode_changes++;
1385 }
1386
1387 DBG_8723A("%s new operation mode = 0x%X changes =%d\n",
1388 __func__, pmlmepriv->ht_op_mode, op_mode_changes);
1389
1390 return op_mode_changes;
1391}
1392
1393void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated)
1394{
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001395 /* update associated stations cap. */
Tina Ruchandanif2372162014-10-23 20:16:51 -07001396 if (updated == true) {
Larry Finger5e93f352014-03-28 21:37:38 -05001397 struct list_head *phead, *plist, *ptmp;
1398 struct sta_info *psta;
1399 struct sta_priv *pstapriv = &padapter->stapriv;
1400
1401 spin_lock_bh(&pstapriv->asoc_list_lock);
1402
1403 phead = &pstapriv->asoc_list;
1404
1405 list_for_each_safe(plist, ptmp, phead) {
1406 psta = container_of(plist, struct sta_info, asoc_list);
1407
1408 VCS_update23a(padapter, psta);
1409 }
1410
1411 spin_unlock_bh(&pstapriv->asoc_list_lock);
1412 }
1413}
1414
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001415/* called > TSR LEVEL for USB or SDIO Interface */
Larry Finger5e93f352014-03-28 21:37:38 -05001416void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info *psta)
1417{
1418 u8 beacon_updated = false;
1419 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1420 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1421
Tina Ruchandanif2372162014-10-23 20:16:51 -07001422 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1423 if (!psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001424 psta->no_short_preamble_set = 1;
1425
1426 pmlmepriv->num_sta_no_short_preamble++;
1427
1428 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001429 (pmlmepriv->num_sta_no_short_preamble == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001430 beacon_updated = true;
1431 update_beacon23a(padapter, 0xFF, NULL, true);
1432 }
1433
1434 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001435 } else {
1436 if (psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001437 psta->no_short_preamble_set = 0;
1438
1439 pmlmepriv->num_sta_no_short_preamble--;
1440
1441 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001442 (pmlmepriv->num_sta_no_short_preamble == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001443 beacon_updated = true;
1444 update_beacon23a(padapter, 0xFF, NULL, true);
1445 }
1446
1447 }
1448 }
1449
Tina Ruchandanif2372162014-10-23 20:16:51 -07001450 if (psta->flags & WLAN_STA_NONERP) {
1451 if (!psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001452 psta->nonerp_set = 1;
1453
1454 pmlmepriv->num_sta_non_erp++;
1455
Tina Ruchandanif2372162014-10-23 20:16:51 -07001456 if (pmlmepriv->num_sta_non_erp == 1) {
Larry Finger5e93f352014-03-28 21:37:38 -05001457 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001458 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001459 }
1460 }
1461
Tina Ruchandanif2372162014-10-23 20:16:51 -07001462 } else {
1463 if (psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001464 psta->nonerp_set = 0;
1465
1466 pmlmepriv->num_sta_non_erp--;
1467
Tina Ruchandanif2372162014-10-23 20:16:51 -07001468 if (pmlmepriv->num_sta_non_erp == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001469 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001470 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001471 }
1472 }
1473
1474 }
1475
Tina Ruchandanif2372162014-10-23 20:16:51 -07001476 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1477 if (!psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001478 psta->no_short_slot_time_set = 1;
1479
1480 pmlmepriv->num_sta_no_short_slot_time++;
1481
1482 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001483 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001484 beacon_updated = true;
1485 update_beacon23a(padapter, 0xFF, NULL, true);
1486 }
1487
1488 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001489 } else {
1490 if (psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001491 psta->no_short_slot_time_set = 0;
1492
1493 pmlmepriv->num_sta_no_short_slot_time--;
1494
1495 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001496 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001497 beacon_updated = true;
1498 update_beacon23a(padapter, 0xFF, NULL, true);
1499 }
1500 }
1501 }
1502
Tina Ruchandanif2372162014-10-23 20:16:51 -07001503 if (psta->flags & WLAN_STA_HT) {
Larry Finger5e93f352014-03-28 21:37:38 -05001504 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
1505
Joe Perchesea072782015-03-24 11:10:09 -07001506 DBG_8723A("HT: STA %pM HT Capabilities Info: 0x%04x\n",
1507 psta->hwaddr, ht_capab);
Larry Finger5e93f352014-03-28 21:37:38 -05001508
1509 if (psta->no_ht_set) {
1510 psta->no_ht_set = 0;
1511 pmlmepriv->num_sta_no_ht--;
1512 }
1513
1514 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
1515 if (!psta->no_ht_gf_set) {
1516 psta->no_ht_gf_set = 1;
1517 pmlmepriv->num_sta_ht_no_gf++;
1518 }
Joe Perchesea072782015-03-24 11:10:09 -07001519 DBG_8723A("%s STA %pM - no greenfield, num of non-gf stations %d\n",
1520 __func__, psta->hwaddr,
1521 pmlmepriv->num_sta_ht_no_gf);
Larry Finger5e93f352014-03-28 21:37:38 -05001522 }
1523
1524 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH_20_40) == 0) {
1525 if (!psta->ht_20mhz_set) {
1526 psta->ht_20mhz_set = 1;
1527 pmlmepriv->num_sta_ht_20mhz++;
1528 }
Joe Perchesea072782015-03-24 11:10:09 -07001529 DBG_8723A("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n",
1530 __func__, psta->hwaddr,
1531 pmlmepriv->num_sta_ht_20mhz);
Larry Finger5e93f352014-03-28 21:37:38 -05001532 }
1533
Tina Ruchandanif2372162014-10-23 20:16:51 -07001534 } else {
Larry Finger5e93f352014-03-28 21:37:38 -05001535 if (!psta->no_ht_set) {
1536 psta->no_ht_set = 1;
1537 pmlmepriv->num_sta_no_ht++;
1538 }
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001539 if (pmlmepriv->htpriv.ht_option) {
Joe Perchesea072782015-03-24 11:10:09 -07001540 DBG_8723A("%s STA %pM - no HT, num of non-HT stations %d\n",
1541 __func__, psta->hwaddr,
1542 pmlmepriv->num_sta_no_ht);
Larry Finger5e93f352014-03-28 21:37:38 -05001543 }
1544 }
1545
Tina Ruchandanif2372162014-10-23 20:16:51 -07001546 if (rtw_ht_operation_update(padapter) > 0) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001547 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1548 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001549 }
1550
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001551 /* update associated stations cap. */
Larry Finger5e93f352014-03-28 21:37:38 -05001552 associated_clients_update23a(padapter, beacon_updated);
1553
1554 DBG_8723A("%s, updated =%d\n", __func__, beacon_updated);
1555}
1556
1557u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info *psta)
1558{
1559 u8 beacon_updated = false;
1560 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1561 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1562
1563 if (!psta)
1564 return beacon_updated;
1565
1566 if (psta->no_short_preamble_set) {
1567 psta->no_short_preamble_set = 0;
1568 pmlmepriv->num_sta_no_short_preamble--;
1569 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
Tina Ruchandanif2372162014-10-23 20:16:51 -07001570 && pmlmepriv->num_sta_no_short_preamble == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001571 beacon_updated = true;
1572 update_beacon23a(padapter, 0xFF, NULL, true);
1573 }
1574 }
1575
1576 if (psta->nonerp_set) {
1577 psta->nonerp_set = 0;
1578 pmlmepriv->num_sta_non_erp--;
Tina Ruchandanif2372162014-10-23 20:16:51 -07001579 if (pmlmepriv->num_sta_non_erp == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001580 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001581 update_beacon23a(padapter, WLAN_EID_ERP_INFO,
1582 NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001583 }
1584 }
1585
1586 if (psta->no_short_slot_time_set) {
1587 psta->no_short_slot_time_set = 0;
1588 pmlmepriv->num_sta_no_short_slot_time--;
1589 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
Tina Ruchandanif2372162014-10-23 20:16:51 -07001590 && pmlmepriv->num_sta_no_short_slot_time == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001591 beacon_updated = true;
1592 update_beacon23a(padapter, 0xFF, NULL, true);
1593 }
1594 }
1595
1596 if (psta->no_ht_gf_set) {
1597 psta->no_ht_gf_set = 0;
1598 pmlmepriv->num_sta_ht_no_gf--;
1599 }
1600
1601 if (psta->no_ht_set) {
1602 psta->no_ht_set = 0;
1603 pmlmepriv->num_sta_no_ht--;
1604 }
1605
1606 if (psta->ht_20mhz_set) {
1607 psta->ht_20mhz_set = 0;
1608 pmlmepriv->num_sta_ht_20mhz--;
1609 }
1610
Tina Ruchandanif2372162014-10-23 20:16:51 -07001611 if (rtw_ht_operation_update(padapter) > 0) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001612 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1613 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001614 }
1615
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001616 /* update associated stations cap. */
Larry Finger5e93f352014-03-28 21:37:38 -05001617
1618 DBG_8723A("%s, updated =%d\n", __func__, beacon_updated);
1619
1620 return beacon_updated;
1621}
1622
1623u8 ap_free_sta23a(struct rtw_adapter *padapter, struct sta_info *psta, bool active, u16 reason)
1624{
1625 struct sta_priv *pstapriv = &padapter->stapriv;
1626 u8 beacon_updated = false;
1627
1628 if (!psta)
1629 return beacon_updated;
1630
Roberta Dobrescu08551cb2014-10-26 23:30:05 +02001631 if (active) {
Larry Finger5e93f352014-03-28 21:37:38 -05001632 /* tear down Rx AMPDU */
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001633 send_delba23a(padapter, 0, psta->hwaddr); /* recipient */
Larry Finger5e93f352014-03-28 21:37:38 -05001634
1635 /* tear down TX AMPDU */
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001636 send_delba23a(padapter, 1, psta->hwaddr); /* originator */
Larry Finger5e93f352014-03-28 21:37:38 -05001637
1638 issue_deauth23a(padapter, psta->hwaddr, reason);
1639 }
1640
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001641 psta->htpriv.agg_enable_bitmap = 0x0; /* reset */
1642 psta->htpriv.candidate_tid_bitmap = 0x0; /* reset */
Larry Finger5e93f352014-03-28 21:37:38 -05001643
1644 /* report_del_sta_event23a(padapter, psta->hwaddr, reason); */
1645
1646 /* clear cam entry / key */
1647 /* clear_cam_entry23a(padapter, (psta->mac_id + 3)); */
Greg Donald7e6646d2014-09-06 19:42:03 -05001648 rtw_clearstakey_cmd23a(padapter, (u8 *)psta, (u8)(psta->mac_id + 3),
1649 true);
Larry Finger5e93f352014-03-28 21:37:38 -05001650
1651 spin_lock_bh(&psta->lock);
1652 psta->state &= ~_FW_LINKED;
1653 spin_unlock_bh(&psta->lock);
1654
1655 rtw_cfg80211_indicate_sta_disassoc(padapter, psta->hwaddr, reason);
1656
1657 report_del_sta_event23a(padapter, psta->hwaddr, reason);
1658
1659 beacon_updated = bss_cap_update_on_sta_leave23a(padapter, psta);
1660
1661 spin_lock_bh(&pstapriv->sta_hash_lock);
1662 rtw_free_stainfo23a(padapter, psta);
1663 spin_unlock_bh(&pstapriv->sta_hash_lock);
1664
1665 return beacon_updated;
1666}
1667
Joglekar Tejas2a049f72015-06-14 04:25:28 +00001668int rtw_ap_inform_ch_switch23a(struct rtw_adapter *padapter, u8 new_ch, u8 ch_offset)
Larry Finger5e93f352014-03-28 21:37:38 -05001669{
1670 struct list_head *phead, *plist;
Larry Finger5e93f352014-03-28 21:37:38 -05001671 struct sta_info *psta = NULL;
1672 struct sta_priv *pstapriv = &padapter->stapriv;
1673 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1674 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1675 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1676
Jes Sorensen6ec26272014-07-17 22:59:46 +02001677 if ((pmlmeinfo->state&0x03) != MSR_AP)
Heena Sirwanif9800f82014-10-07 14:46:30 +05301678 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001679
Jes Sorensena790d582014-05-09 15:04:04 +02001680 DBG_8723A("%s(%s): with ch:%u, offset:%u\n", __func__,
1681 padapter->pnetdev->name, new_ch, ch_offset);
Larry Finger5e93f352014-03-28 21:37:38 -05001682
1683 spin_lock_bh(&pstapriv->asoc_list_lock);
1684 phead = &pstapriv->asoc_list;
1685
1686 list_for_each(plist, phead) {
1687 psta = container_of(plist, struct sta_info, asoc_list);
1688
Joglekar Tejas2a049f72015-06-14 04:25:28 +00001689 issue_action_spct_ch_switch23a(padapter, psta->hwaddr, new_ch, ch_offset);
Larry Finger5e93f352014-03-28 21:37:38 -05001690 psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
1691 }
1692 spin_unlock_bh(&pstapriv->asoc_list_lock);
1693
Joglekar Tejas2a049f72015-06-14 04:25:28 +00001694 issue_action_spct_ch_switch23a(padapter, bc_addr, new_ch, ch_offset);
Larry Finger5e93f352014-03-28 21:37:38 -05001695
Heena Sirwanif9800f82014-10-07 14:46:30 +05301696 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001697}
1698
1699int rtw_sta_flush23a(struct rtw_adapter *padapter)
1700{
1701 struct list_head *phead, *plist, *ptmp;
Larry Finger5e93f352014-03-28 21:37:38 -05001702 struct sta_info *psta;
1703 struct sta_priv *pstapriv = &padapter->stapriv;
1704 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1705 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1706 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1707 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +02001708 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -05001709 int i;
1710
Jes Sorensena790d582014-05-09 15:04:04 +02001711 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name);
Larry Finger5e93f352014-03-28 21:37:38 -05001712
Jes Sorensen6ec26272014-07-17 22:59:46 +02001713 if ((pmlmeinfo->state&0x03) != MSR_AP)
Heena Sirwanif9800f82014-10-07 14:46:30 +05301714 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001715
1716 spin_lock_bh(&pstapriv->asoc_list_lock);
1717 phead = &pstapriv->asoc_list;
1718
1719 list_for_each_safe(plist, ptmp, phead) {
Larry Finger5e93f352014-03-28 21:37:38 -05001720 psta = container_of(plist, struct sta_info, asoc_list);
1721
1722 /* Remove sta from asoc_list */
1723 list_del_init(&psta->asoc_list);
1724 pstapriv->asoc_list_cnt--;
1725
1726 /* Keep sta for ap_free_sta23a() beyond this asoc_list loop */
Jes Sorensen69642132014-05-09 15:03:47 +02001727 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -05001728 }
1729 spin_unlock_bh(&pstapriv->asoc_list_lock);
1730
1731 /* For each sta in chk_alive_list, call ap_free_sta23a */
Jes Sorensen69642132014-05-09 15:03:47 +02001732 for (i = 0; i < chk_alive_num; i++)
1733 ap_free_sta23a(padapter, chk_alive_list[i], true,
1734 WLAN_REASON_DEAUTH_LEAVING);
Larry Finger5e93f352014-03-28 21:37:38 -05001735
1736 issue_deauth23a(padapter, bc_addr, WLAN_REASON_DEAUTH_LEAVING);
1737
1738 associated_clients_update23a(padapter, true);
1739
Heena Sirwanif9800f82014-10-07 14:46:30 +05301740 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001741}
1742
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001743/* called > TSR LEVEL for USB or SDIO Interface */
Larry Finger5e93f352014-03-28 21:37:38 -05001744void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1745{
1746 int flags = psta->flags;
1747 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1748
1749 /* update wmm cap. */
1750 if (WLAN_STA_WME&flags)
1751 psta->qos_option = 1;
1752 else
1753 psta->qos_option = 0;
1754
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +02001755 if (pmlmepriv->qos_option == 0)
Larry Finger5e93f352014-03-28 21:37:38 -05001756 psta->qos_option = 0;
1757
1758 /* update 802.11n ht cap. */
Tina Ruchandanif2372162014-10-23 20:16:51 -07001759 if (WLAN_STA_HT&flags) {
Larry Finger5e93f352014-03-28 21:37:38 -05001760 psta->htpriv.ht_option = true;
1761 psta->qos_option = 1;
Tina Ruchandanif2372162014-10-23 20:16:51 -07001762 } else {
Larry Finger5e93f352014-03-28 21:37:38 -05001763 psta->htpriv.ht_option = false;
1764 }
1765
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001766 if (!pmlmepriv->htpriv.ht_option)
Larry Finger5e93f352014-03-28 21:37:38 -05001767 psta->htpriv.ht_option = false;
1768
1769 update_sta_info23a_apmode23a(padapter, psta);
1770}
1771
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001772/* called >= TSR LEVEL for USB or SDIO Interface */
Larry Finger5e93f352014-03-28 21:37:38 -05001773void ap_sta_info_defer_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1774{
Tina Ruchandanif2372162014-10-23 20:16:51 -07001775 if (psta->state & _FW_LINKED) {
Larry Finger5e93f352014-03-28 21:37:38 -05001776 /* add ratid */
1777 add_RATid23a(padapter, psta, 0);/* DM_RATR_STA_INIT */
1778 }
1779}
1780
1781/* restore hw setting from sw data structures */
1782void rtw_ap_restore_network(struct rtw_adapter *padapter)
1783{
1784 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
1785 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Greg Donald8e3d1612014-10-02 18:28:41 -05001786 struct sta_priv *pstapriv = &padapter->stapriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001787 struct sta_info *psta;
1788 struct security_priv *psecuritypriv = &padapter->securitypriv;
1789 struct list_head *phead, *plist, *ptmp;
1790 u8 chk_alive_num = 0;
Jes Sorensen69642132014-05-09 15:03:47 +02001791 struct sta_info *chk_alive_list[NUM_STA];
Larry Finger5e93f352014-03-28 21:37:38 -05001792 int i;
1793
Jes Sorensenefc71442014-05-21 09:37:26 +02001794 rtw_setopmode_cmd23a(padapter, NL80211_IFTYPE_AP);
Larry Finger5e93f352014-03-28 21:37:38 -05001795
1796 set_channel_bwmode23a(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
1797
Greg Donald7e6646d2014-09-06 19:42:03 -05001798 start_bss_network(padapter, (u8 *)&mlmepriv->cur_network.network);
Larry Finger5e93f352014-03-28 21:37:38 -05001799
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001800 if (padapter->securitypriv.dot11PrivacyAlgrthm ==
1801 WLAN_CIPHER_SUITE_TKIP ||
1802 padapter->securitypriv.dot11PrivacyAlgrthm ==
1803 WLAN_CIPHER_SUITE_CCMP) {
Larry Finger5e93f352014-03-28 21:37:38 -05001804 /* restore group key, WEP keys is restored in ips_leave23a() */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001805 rtw_set_key23a(padapter, psecuritypriv,
1806 psecuritypriv->dot118021XGrpKeyid, 0);
Larry Finger5e93f352014-03-28 21:37:38 -05001807 }
1808
1809 /* per sta pairwise key and settings */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +02001810 if (padapter->securitypriv.dot11PrivacyAlgrthm !=
1811 WLAN_CIPHER_SUITE_TKIP &&
1812 padapter->securitypriv.dot11PrivacyAlgrthm !=
1813 WLAN_CIPHER_SUITE_CCMP) {
Larry Finger5e93f352014-03-28 21:37:38 -05001814 return;
1815 }
1816
1817 spin_lock_bh(&pstapriv->asoc_list_lock);
1818
1819 phead = &pstapriv->asoc_list;
1820
1821 list_for_each_safe(plist, ptmp, phead) {
Larry Finger5e93f352014-03-28 21:37:38 -05001822 psta = container_of(plist, struct sta_info, asoc_list);
1823
Jes Sorensen69642132014-05-09 15:03:47 +02001824 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -05001825 }
1826
1827 spin_unlock_bh(&pstapriv->asoc_list_lock);
1828
1829 for (i = 0; i < chk_alive_num; i++) {
Jes Sorensen69642132014-05-09 15:03:47 +02001830 psta = chk_alive_list[i];
Larry Finger5e93f352014-03-28 21:37:38 -05001831
MihaelaGamanadabff82014-09-14 12:56:43 +03001832 if (psta->state & _FW_LINKED) {
Larry Finger5e93f352014-03-28 21:37:38 -05001833 Update_RA_Entry23a(padapter, psta);
1834 /* pairwise key */
1835 rtw_setstakey_cmd23a(padapter, (unsigned char *)psta, true);
1836 }
1837 }
1838}
1839
1840void start_ap_mode23a(struct rtw_adapter *padapter)
1841{
1842 int i;
1843 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1844 struct sta_priv *pstapriv = &padapter->stapriv;
1845 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1846 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1847
1848 pmlmepriv->update_bcn = false;
1849
1850 /* init_mlme_ap_info23a(padapter); */
1851 pmlmeext->bstart_bss = false;
1852
1853 pmlmepriv->num_sta_non_erp = 0;
1854
1855 pmlmepriv->num_sta_no_short_slot_time = 0;
1856
1857 pmlmepriv->num_sta_no_short_preamble = 0;
1858
1859 pmlmepriv->num_sta_ht_no_gf = 0;
1860 pmlmepriv->num_sta_no_ht = 0;
1861 pmlmepriv->num_sta_ht_20mhz = 0;
1862
1863 pmlmepriv->olbc = false;
1864
1865 pmlmepriv->olbc_ht = false;
1866
1867 pmlmepriv->ht_op_mode = 0;
1868
MihaelaGamanadabff82014-09-14 12:56:43 +03001869 for (i = 0; i < NUM_STA; i++)
Larry Finger5e93f352014-03-28 21:37:38 -05001870 pstapriv->sta_aid[i] = NULL;
1871
Larry Finger5e93f352014-03-28 21:37:38 -05001872 /* for ACL */
1873 INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
1874 pacl_list->num = 0;
1875 pacl_list->mode = 0;
1876 for (i = 0; i < NUM_ACL; i++) {
1877 INIT_LIST_HEAD(&pacl_list->aclnode[i].list);
1878 pacl_list->aclnode[i].valid = false;
1879 }
1880}
1881
1882void stop_ap_mode23a(struct rtw_adapter *padapter)
1883{
1884 struct list_head *phead, *plist, *ptmp;
1885 struct rtw_wlan_acl_node *paclnode;
1886 struct sta_info *psta = NULL;
1887 struct sta_priv *pstapriv = &padapter->stapriv;
1888 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1889 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1890 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1891 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1892
1893 pmlmepriv->update_bcn = false;
1894 pmlmeext->bstart_bss = false;
1895
Alison Schofielde9cd7af2015-10-23 21:28:00 -07001896 /*
1897 * reset and init security priv , this can
1898 * refine with rtw_reset_securitypriv23a
1899 */
Joglekar Tejas2a049f72015-06-14 04:25:28 +00001900 memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
Larry Finger5e93f352014-03-28 21:37:38 -05001901 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1902 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
1903
1904 /* for ACL */
1905 spin_lock_bh(&pacl_node_q->lock);
1906 phead = get_list_head(pacl_node_q);
1907
1908 list_for_each_safe(plist, ptmp, phead) {
1909 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1910
1911 if (paclnode->valid == true) {
1912 paclnode->valid = false;
1913
1914 list_del_init(&paclnode->list);
1915
1916 pacl_list->num--;
1917 }
1918 }
1919 spin_unlock_bh(&pacl_node_q->lock);
1920
1921 DBG_8723A("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
1922
1923 rtw_sta_flush23a(padapter);
1924
1925 /* free_assoc_sta_resources */
1926 rtw_free_all_stainfo23a(padapter);
1927
1928 psta = rtw_get_bcmc_stainfo23a(padapter);
1929 spin_lock_bh(&pstapriv->sta_hash_lock);
1930 rtw_free_stainfo23a(padapter, psta);
1931 spin_unlock_bh(&pstapriv->sta_hash_lock);
1932
1933 rtw_init_bcmc_stainfo23a(padapter);
1934
1935 rtw23a_free_mlme_priv_ie_data(pmlmepriv);
1936}