blob: 645668950e9cc817545ecb1a6f9279b1afcc9a38 [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
MihaelaGamanadabff82014-09-14 12:56:43 +0300135 *dst_ie++ = 0;/* DTIM count */
136 *dst_ie++ = 1;/* DTIM period */
Larry Finger5e93f352014-03-28 21:37:38 -0500137
138 if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
139 *dst_ie++ = BIT(0);/* bitmap ctrl */
140 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)) {
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900242 /* to check if alive by another methods if station is at ps mode. */
Larry Finger5e93f352014-03-28 21:37:38 -0500243 psta->expire_to = pstapriv->expire_to;
244 psta->state |= WIFI_STA_ALIVE_CHK_STATE;
245
246 /* to update bcn with tim_bitmap for this station */
247 pstapriv->tim_bitmap |= CHKBIT(psta->aid);
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200248 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500249
250 if (!pmlmeext->active_keep_alive_check)
251 continue;
252 }
253 }
254
255 if (pmlmeext->active_keep_alive_check) {
Jes Sorensen69642132014-05-09 15:03:47 +0200256 chk_alive_list[chk_alive_num++] = psta;
Larry Finger5e93f352014-03-28 21:37:38 -0500257 continue;
258 }
259
260 list_del_init(&psta->asoc_list);
261 pstapriv->asoc_list_cnt--;
262
Joe Perchesea072782015-03-24 11:10:09 -0700263 DBG_8723A("asoc expire %pM, state = 0x%x\n",
264 psta->hwaddr, psta->state);
Larry Finger5e93f352014-03-28 21:37:38 -0500265 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
266 } else {
267 /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
268 if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
269 && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME/pstapriv->asoc_list_cnt)/2)
270 ) {
Joe Perchesea072782015-03-24 11:10:09 -0700271 DBG_8723A("%s sta:%pM, sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n",
272 __func__,
273 psta->hwaddr,
Larry Finger5e93f352014-03-28 21:37:38 -0500274 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) {
Joe Perchesea072782015-03-24 11:10:09 -0700310 DBG_8723A("asoc check, sta(%pM) is alive\n",
311 psta->hwaddr);
Larry Finger5e93f352014-03-28 21:37:38 -0500312 psta->expire_to = pstapriv->expire_to;
313 psta->keep_alive_trycnt = 0;
314 continue;
Tina Ruchandanif2372162014-10-23 20:16:51 -0700315 } else if (psta->keep_alive_trycnt <= 3) {
Larry Finger5e93f352014-03-28 21:37:38 -0500316 DBG_8723A("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
317 psta->expire_to = 1;
318 continue;
319 }
320
321 psta->keep_alive_trycnt = 0;
322
Joe Perchesea072782015-03-24 11:10:09 -0700323 DBG_8723A("asoc expire %pM, state = 0x%x\n",
324 psta->hwaddr, psta->state);
Larry Finger5e93f352014-03-28 21:37:38 -0500325 spin_lock_bh(&pstapriv->asoc_list_lock);
326 if (!list_empty(&psta->asoc_list)) {
327 list_del_init(&psta->asoc_list);
328 pstapriv->asoc_list_cnt--;
329 updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
330 }
331 spin_unlock_bh(&pstapriv->asoc_list_lock);
332
333 }
334
MihaelaGamanadabff82014-09-14 12:56:43 +0300335 if (backup_oper_channel > 0) /* back to the original operation channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500336 SelectChannel23a(padapter, backup_oper_channel);
337}
338
339 associated_clients_update23a(padapter, updated);
340}
341
342void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_level)
343{
344 int i;
345 u8 rf_type;
346 u32 init_rate = 0;
347 unsigned char sta_band = 0, raid, shortGIrate = false;
348 unsigned char limit;
349 unsigned int tx_ra_bitmap = 0;
350 struct ht_priv *psta_ht = NULL;
351 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200352 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500353
354 if (psta)
355 psta_ht = &psta->htpriv;
356 else
357 return;
358
359 if (!(psta->state & _FW_LINKED))
360 return;
361
362 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700363 for (i = 0; i < sizeof(psta->bssrateset); i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500364 if (psta->bssrateset[i])
365 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
366 }
367 /* n mode ra_bitmap */
Jes Sorensenc2370e82014-04-09 23:20:53 +0200368 if (psta_ht->ht_option) {
369 rf_type = rtl8723a_get_rf_type(padapter);
370
Larry Finger5e93f352014-03-28 21:37:38 -0500371 if (rf_type == RF_2T2R)
372 limit = 16;/* 2R */
373 else
374 limit = 8;/* 1R */
375
Jes Sorensen5a4438932014-05-09 15:04:15 +0200376 for (i = 0; i < limit; i++) {
377 if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
378 tx_ra_bitmap |= BIT(i + 12);
Larry Finger5e93f352014-03-28 21:37:38 -0500379 }
380
381 /* max short GI rate */
382 shortGIrate = psta_ht->sgi;
383 }
384
Jes Sorensen37cb9822014-05-21 09:37:40 +0200385 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500386 /* 5G band */
387 if (tx_ra_bitmap & 0xffff000)
388 sta_band |= WIRELESS_11_5N | WIRELESS_11A;
389 else
390 sta_band |= WIRELESS_11A;
391 } else {
392 if (tx_ra_bitmap & 0xffff000)
393 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
394 else if (tx_ra_bitmap & 0xff0)
Aybuke Ozdemirdd609252014-09-28 17:22:37 +0300395 sta_band |= WIRELESS_11G | WIRELESS_11B;
Larry Finger5e93f352014-03-28 21:37:38 -0500396 else
397 sta_band |= WIRELESS_11B;
398 }
399
400 psta->wireless_mode = sta_band;
401
402 raid = networktype_to_raid23a(sta_band);
403 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
404
Tina Ruchandanif2372162014-10-23 20:16:51 -0700405 if (psta->aid < NUM_STA) {
Larry Finger5e93f352014-03-28 21:37:38 -0500406 u8 arg = 0;
407
408 arg = psta->mac_id&0x1f;
409
410 arg |= BIT(7);/* support entry 2~31 */
411
412 if (shortGIrate == true)
413 arg |= BIT(5);
414
415 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
416
417 DBG_8723A("%s => mac_id:%d , raid:%d , bitmap = 0x%x, arg = "
418 "0x%x\n",
419 __func__, psta->mac_id, raid, tx_ra_bitmap, arg);
420
421 /* bitmap[0:27] = tx_rate_bitmap */
422 /* bitmap[28:31]= Rate Adaptive id */
423 /* arg[0:4] = macid */
424 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200425 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, rssi_level);
Larry Finger5e93f352014-03-28 21:37:38 -0500426
427 if (shortGIrate == true)
428 init_rate |= BIT(6);
429
430 /* set ra_id, init_rate */
431 psta->raid = raid;
432 psta->init_rate = init_rate;
433
Tina Ruchandanif2372162014-10-23 20:16:51 -0700434 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500435 DBG_8723A("station aid %d exceed the max number\n", psta->aid);
Larry Finger5e93f352014-03-28 21:37:38 -0500436}
437
438static void update_bmc_sta(struct rtw_adapter *padapter)
439{
440 u32 init_rate = 0;
441 unsigned char network_type, raid;
442 int i, supportRateNum = 0;
443 unsigned int tx_ra_bitmap = 0;
444 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200445 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500446 struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter);
447
Tina Ruchandanif2372162014-10-23 20:16:51 -0700448 if (psta) {
Larry Finger5e93f352014-03-28 21:37:38 -0500449 psta->aid = 0;/* default set to 0 */
450 psta->mac_id = psta->aid + 1;
451
452 psta->qos_option = 0;
453 psta->htpriv.ht_option = false;
454
455 psta->ieee8021x_blocked = 0;
456
Greg Donald7e6646d2014-09-06 19:42:03 -0500457 memset((void *)&psta->sta_stats, 0,
458 sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500459
460 /* prepare for add_RATid23a */
Joe Borg22faca22014-12-16 02:54:32 -0500461 supportRateNum = rtw_get_rateset_len23a((u8 *)&pcur_network->SupportedRates);
462 network_type = rtw_check_network_type23a((u8 *)&pcur_network->SupportedRates, supportRateNum, 1);
Larry Finger5e93f352014-03-28 21:37:38 -0500463
464 memcpy(psta->bssrateset, &pcur_network->SupportedRates, supportRateNum);
465 psta->bssratelen = supportRateNum;
466
467 /* b/g mode ra_bitmap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700468 for (i = 0; i < supportRateNum; i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500469 if (psta->bssrateset[i])
470 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
471 }
472
Jes Sorensen37cb9822014-05-21 09:37:40 +0200473 if (pcur_network->DSConfig > 14) {
Larry Finger5e93f352014-03-28 21:37:38 -0500474 /* force to A mode. 5G doesn't support CCK rates */
475 network_type = WIRELESS_11A;
476 tx_ra_bitmap = 0x150; /* 6, 12, 24 Mbps */
477 } else {
478 /* force to b mode */
479 network_type = WIRELESS_11B;
480 tx_ra_bitmap = 0xf;
481 }
482
483 raid = networktype_to_raid23a(network_type);
484 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
485
486 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200487 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500488
489 {
490 u8 arg = 0;
491
492 arg = psta->mac_id&0x1f;
493
494 arg |= BIT(7);
495
496 tx_ra_bitmap |= ((raid<<28)&0xf0000000);
497
498 DBG_8723A("update_bmc_sta, mask = 0x%x, arg = 0x%x\n", tx_ra_bitmap, arg);
499
500 /* bitmap[0:27] = tx_rate_bitmap */
501 /* bitmap[28:31]= Rate Adaptive id */
502 /* arg[0:4] = macid */
503 /* arg[5] = Short GI */
Jes Sorensen1ec69342014-05-16 10:04:11 +0200504 rtl8723a_add_rateatid(padapter, tx_ra_bitmap, arg, 0);
Larry Finger5e93f352014-03-28 21:37:38 -0500505 }
506
507 /* set ra_id, init_rate */
508 psta->raid = raid;
509 psta->init_rate = init_rate;
510
Larry Finger5e93f352014-03-28 21:37:38 -0500511 spin_lock_bh(&psta->lock);
512 psta->state = _FW_LINKED;
513 spin_unlock_bh(&psta->lock);
514
Tina Ruchandanif2372162014-10-23 20:16:51 -0700515 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500516 DBG_8723A("add_RATid23a_bmc_sta error!\n");
Larry Finger5e93f352014-03-28 21:37:38 -0500517}
518
519/* notes: */
520/* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
521/* MAC_ID = AID+1 for sta in ap/adhoc mode */
522/* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
523/* MAC_ID = 0 for bssid for sta/ap/adhoc */
524/* CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
525
526void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info *psta)
527{
528 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
529 struct security_priv *psecuritypriv = &padapter->securitypriv;
530 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
531 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
532 struct ht_priv *phtpriv_sta = &psta->htpriv;
533 /* set intf_tag to if1 */
534
535 psta->mac_id = psta->aid+1;
536 DBG_8723A("%s\n", __func__);
537
538 /* ap mode */
Jes Sorensendbe98492014-05-16 10:04:13 +0200539 rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
Larry Finger5e93f352014-03-28 21:37:38 -0500540
541 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X)
542 psta->ieee8021x_blocked = true;
543 else
544 psta->ieee8021x_blocked = false;
545
546 /* update sta's cap */
547
548 /* ERP */
549 VCS_update23a(padapter, psta);
550 /* HT related cap */
Tina Ruchandanif2372162014-10-23 20:16:51 -0700551 if (phtpriv_sta->ht_option) {
Larry Finger5e93f352014-03-28 21:37:38 -0500552 /* check if sta supports rx ampdu */
553 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
554
555 /* check if sta support s Short GI */
556 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))
557 phtpriv_sta->sgi = true;
558
559 /* bwmode */
560 if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
561 /* phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_40; */
562 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
563 phtpriv_sta->ch_offset = pmlmeext->cur_ch_offset;
564
565 }
566
567 psta->qos_option = true;
568
Tina Ruchandanif2372162014-10-23 20:16:51 -0700569 } else {
Larry Finger5e93f352014-03-28 21:37:38 -0500570 phtpriv_sta->ampdu_enable = false;
571
572 phtpriv_sta->sgi = false;
573 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
574 phtpriv_sta->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
575 }
576
577 /* Rx AMPDU */
578 send_delba23a(padapter, 0, psta->hwaddr);/* recipient */
579
580 /* TX AMPDU */
581 send_delba23a(padapter, 1, psta->hwaddr);/* originator */
582 phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
583 phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
584
585 /* todo: init other variables */
586
Greg Donald7e6646d2014-09-06 19:42:03 -0500587 memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
Larry Finger5e93f352014-03-28 21:37:38 -0500588
589 spin_lock_bh(&psta->lock);
590 psta->state |= _FW_LINKED;
591 spin_unlock_bh(&psta->lock);
592}
593
594static void update_hw_ht_param(struct rtw_adapter *padapter)
595{
596 unsigned char max_AMPDU_len;
597 unsigned char min_MPDU_spacing;
598 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
599 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
600
601 DBG_8723A("%s\n", __func__);
602
603 /* handle A-MPDU parameter field */
604 /*
605 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
606 AMPDU_para [4:2]:Min MPDU Start Spacing
607 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200608 max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
609 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500610
Jes Sorensen65be27d2014-05-31 18:05:11 +0200611 min_MPDU_spacing = (pmlmeinfo->ht_cap.ampdu_params_info &
612 IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500613
Jes Sorensendce610a2014-04-09 23:20:32 +0200614 rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
615 rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
Larry Finger5e93f352014-03-28 21:37:38 -0500616
617 /* Config SM Power Save setting */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200618 pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->ht_cap.cap_info) &
619 IEEE80211_HT_CAP_SM_PS) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500620 if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
621 DBG_8723A("%s(): WLAN_HT_CAP_SM_PS_STATIC\n", __func__);
622}
623
624static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
625{
Jes Sorensen731f9da2014-04-15 19:44:02 +0200626 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -0500627 u8 val8, cur_channel, cur_bwmode, cur_ch_offset;
628 u16 bcn_interval;
629 u32 acparm;
Larry Finger5e93f352014-03-28 21:37:38 -0500630 struct registry_priv *pregpriv = &padapter->registrypriv;
631 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Greg Donald4e66cf02014-08-22 10:57:49 -0500632 struct security_priv *psecuritypriv = &padapter->securitypriv;
Jes Sorensen52017952014-04-26 18:55:09 +0200633 struct wlan_bssid_ex *pnetwork = &pmlmepriv->cur_network.network;
Larry Finger5e93f352014-03-28 21:37:38 -0500634 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
635 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
636 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200637 struct ieee80211_ht_operation *pht_info = NULL;
Larry Finger5e93f352014-03-28 21:37:38 -0500638
Jes Sorensen143ced22014-06-19 11:37:22 +0200639 bcn_interval = (u16)pnetwork->beacon_interval;
Jes Sorensen37cb9822014-05-21 09:37:40 +0200640 cur_channel = pnetwork->DSConfig;
Roberta Dobrescub9b42242014-10-26 23:30:06 +0200641 cur_bwmode = HT_CHANNEL_WIDTH_20;
Larry Finger5e93f352014-03-28 21:37:38 -0500642 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
643
644 /* check if there is wps ie, */
645 /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
646 /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
Jes Sorensen715a8a72014-06-09 15:15:57 +0200647 if (NULL == cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
648 WLAN_OUI_TYPE_MICROSOFT_WPS,
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200649 pnetwork->IEs,
650 pnetwork->IELength))
Larry Finger5e93f352014-03-28 21:37:38 -0500651 pmlmeext->bstart_bss = true;
652
653 /* todo: update wmm, ht cap */
654 /* pmlmeinfo->WMM_enable; */
655 /* pmlmeinfo->HT_enable; */
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200656 if (pmlmepriv->qos_option)
Larry Finger5e93f352014-03-28 21:37:38 -0500657 pmlmeinfo->WMM_enable = true;
658 if (pmlmepriv->htpriv.ht_option) {
659 pmlmeinfo->WMM_enable = true;
660 pmlmeinfo->HT_enable = true;
661
662 update_hw_ht_param(padapter);
663 }
664
665 if (pmlmepriv->cur_network.join_res != true) {
666 /* setting only at first time */
667 /* WEP Key will be set before this function, do not clear CAM. */
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200668 if (psecuritypriv->dot11PrivacyAlgrthm !=
669 WLAN_CIPHER_SUITE_WEP40 &&
670 psecuritypriv->dot11PrivacyAlgrthm !=
671 WLAN_CIPHER_SUITE_WEP104)
Larry Finger5e93f352014-03-28 21:37:38 -0500672 flush_all_cam_entry23a(padapter); /* clear CAM */
673 }
674
675 /* set MSR to AP_Mode */
Jes Sorensen6ec26272014-07-17 22:59:46 +0200676 rtl8723a_set_media_status(padapter, MSR_AP);
Larry Finger5e93f352014-03-28 21:37:38 -0500677
678 /* Set BSSID REG */
Jes Sorensen38dd10b2014-04-09 23:20:20 +0200679 hw_var_set_bssid(padapter, pnetwork->MacAddress);
Larry Finger5e93f352014-03-28 21:37:38 -0500680
681 /* Set EDCA param reg */
682 acparm = 0x002F3217; /* VO */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200683 rtl8723a_set_ac_param_vo(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500684 acparm = 0x005E4317; /* VI */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200685 rtl8723a_set_ac_param_vi(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500686 acparm = 0x005ea42b;
Jes Sorensen2487205e2014-04-09 23:20:30 +0200687 rtl8723a_set_ac_param_be(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500688 acparm = 0x0000A444; /* BK */
Jes Sorensen2487205e2014-04-09 23:20:30 +0200689 rtl8723a_set_ac_param_bk(padapter, acparm);
Larry Finger5e93f352014-03-28 21:37:38 -0500690
691 /* Set Security */
Jes Sorensenb8e99162014-04-09 23:20:27 +0200692 val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ?
MihaelaGamanadabff82014-09-14 12:56:43 +0300693 0xcc : 0xcf;
Jes Sorensenb8e99162014-04-09 23:20:27 +0200694 rtl8723a_set_sec_cfg(padapter, val8);
Larry Finger5e93f352014-03-28 21:37:38 -0500695
696 /* Beacon Control related register */
Jes Sorensen477f0082014-04-09 23:20:23 +0200697 rtl8723a_set_beacon_interval(padapter, bcn_interval);
Larry Finger5e93f352014-03-28 21:37:38 -0500698
699 UpdateBrateTbl23a(padapter, pnetwork->SupportedRates);
Jes Sorensenfa2e5202014-04-09 23:20:18 +0200700 HalSetBrateCfg23a(padapter, pnetwork->SupportedRates);
Larry Finger5e93f352014-03-28 21:37:38 -0500701
702 if (!pmlmepriv->cur_network.join_res) {
703 /* setting only at first time */
704
705 /* disable dynamic functions, such as high power, DIG */
706
707 /* turn on all dynamic functions */
Jes Sorensen585eefb2014-04-09 23:20:43 +0200708 rtl8723a_odm_support_ability_set(padapter,
709 DYNAMIC_ALL_FUNC_ENABLE);
Larry Finger5e93f352014-03-28 21:37:38 -0500710 }
711 /* set channel, bwmode */
Jes Sorensenc164bcf2014-05-21 09:37:41 +0200712
Jes Sorensen68e6c792014-06-24 15:03:29 +0200713 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION, pnetwork->IEs,
714 pnetwork->IELength);
Jes Sorensen731f9da2014-04-15 19:44:02 +0200715 if (p && p[1]) {
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200716 pht_info = (struct ieee80211_ht_operation *)(p + 2);
Larry Finger5e93f352014-03-28 21:37:38 -0500717
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200718 if (pregpriv->cbw40_enable && pht_info->ht_param &
719 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) {
Larry Finger5e93f352014-03-28 21:37:38 -0500720 /* switch to the 40M Hz mode */
721 cur_bwmode = HT_CHANNEL_WIDTH_40;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200722 switch (pht_info->ht_param &
723 IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
724 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Jes Sorensen731f9da2014-04-15 19:44:02 +0200725 /* pmlmeext->cur_ch_offset =
726 HAL_PRIME_CHNL_OFFSET_LOWER; */
Larry Finger5e93f352014-03-28 21:37:38 -0500727 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
728 break;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200729 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Larry Finger5e93f352014-03-28 21:37:38 -0500730 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
731 break;
732 default:
733 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
734 break;
735 }
736 }
737 }
738 /* TODO: need to judge the phy parameters on concurrent mode for single phy */
739 set_channel_bwmode23a(padapter, cur_channel, cur_ch_offset, cur_bwmode);
740
741 DBG_8723A("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode,
742 cur_ch_offset);
743
744 pmlmeext->cur_channel = cur_channel;
745 pmlmeext->cur_bwmode = cur_bwmode;
746 pmlmeext->cur_ch_offset = cur_ch_offset;
747 pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type;
748
749 /* update cur_wireless_mode */
750 update_wireless_mode23a(padapter);
751
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900752 /* update capability after cur_wireless_mode updated */
Jes Sorensena94e12b2014-06-19 11:37:34 +0200753 update_capinfo23a(padapter, pnetwork->capability);
Larry Finger5e93f352014-03-28 21:37:38 -0500754
755 /* let pnetwork_mlmeext == pnetwork_mlme. */
756 memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length);
757
Larry Finger5e93f352014-03-28 21:37:38 -0500758 if (pmlmeext->bstart_bss) {
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +0200759 update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
Larry Finger5e93f352014-03-28 21:37:38 -0500760
761 /* issue beacon frame */
762 if (send_beacon23a(padapter) == _FAIL)
763 DBG_8723A("issue_beacon23a, fail!\n");
764 }
765
766 /* update bc/mc sta_info */
767 update_bmc_sta(padapter);
768}
769
Jes Sorensenfb5fd462014-06-24 15:03:20 +0200770int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
771 struct ieee80211_mgmt *mgmt, unsigned int len)
Larry Finger5e93f352014-03-28 21:37:38 -0500772{
773 int ret = _SUCCESS;
774 u8 *p;
775 u8 *pHT_caps_ie = NULL;
776 u8 *pHT_info_ie = NULL;
777 struct sta_info *psta = NULL;
Jes Sorensen51a26d22014-06-24 15:03:21 +0200778 u16 ht_cap = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500779 uint ie_len = 0;
780 int group_cipher, pairwise_cipher;
781 u8 channel, network_type, supportRate[NDIS_802_11_LENGTH_RATES_EX];
782 int supportRateNum = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500783 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
784 struct registry_priv *pregistrypriv = &padapter->registrypriv;
785 struct security_priv *psecuritypriv = &padapter->securitypriv;
786 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
787 struct wlan_bssid_ex *pbss_network = &pmlmepriv->cur_network.network;
788 u8 *ie = pbss_network->IEs;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200789 u8 *pbuf = mgmt->u.beacon.variable;
Dilek Uzulmez91701e42015-02-24 15:14:26 +0200790
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200791 len -= offsetof(struct ieee80211_mgmt, u.beacon.variable);
Larry Finger5e93f352014-03-28 21:37:38 -0500792 /* SSID */
793 /* Supported rates */
794 /* DS Params */
795 /* WLAN_EID_COUNTRY */
796 /* ERP Information element */
797 /* Extended supported rates */
798 /* WPA/WPA2 */
799 /* Wi-Fi Wireless Multimedia Extensions */
800 /* ht_capab, ht_oper */
801 /* WPS IE */
802
803 DBG_8723A("%s, len =%d\n", __func__, len);
804
805 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
806 return _FAIL;
807
Jes Sorensen8282aeb2014-04-26 18:54:53 +0200808 if (len > MAX_IE_SZ)
Larry Finger5e93f352014-03-28 21:37:38 -0500809 return _FAIL;
810
811 pbss_network->IELength = len;
812
813 memset(ie, 0, MAX_IE_SZ);
814
815 memcpy(ie, pbuf, pbss_network->IELength);
816
Jes Sorensenefc71442014-05-21 09:37:26 +0200817 if (pbss_network->ifmode != NL80211_IFTYPE_AP &&
818 pbss_network->ifmode != NL80211_IFTYPE_P2P_GO)
Larry Finger5e93f352014-03-28 21:37:38 -0500819 return _FAIL;
820
821 pbss_network->Rssi = 0;
822
823 memcpy(pbss_network->MacAddress, myid(&padapter->eeprompriv), ETH_ALEN);
824
Larry Finger5e93f352014-03-28 21:37:38 -0500825 /* SSID */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200826 p = rtw_get_ie23a(ie, WLAN_EID_SSID, &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500827 if (p && ie_len > 0) {
828 memset(&pbss_network->Ssid, 0, sizeof(struct cfg80211_ssid));
829 memcpy(pbss_network->Ssid.ssid, (p + 2), ie_len);
830 pbss_network->Ssid.ssid_len = ie_len;
831 }
832
Masanari Iida96b0a5b2014-07-22 23:42:45 +0900833 /* channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500834 channel = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200835 p = rtw_get_ie23a(ie, WLAN_EID_DS_PARAMS, &ie_len,
836 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500837 if (p && ie_len > 0)
838 channel = *(p + 2);
839
Jes Sorensen37cb9822014-05-21 09:37:40 +0200840 pbss_network->DSConfig = channel;
Larry Finger5e93f352014-03-28 21:37:38 -0500841
842 memset(supportRate, 0, NDIS_802_11_LENGTH_RATES_EX);
843 /* get supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200844 p = rtw_get_ie23a(ie, WLAN_EID_SUPP_RATES, &ie_len,
845 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500846 if (p) {
847 memcpy(supportRate, p+2, ie_len);
848 supportRateNum = ie_len;
849 }
850
851 /* get ext_supported rates */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200852 p = rtw_get_ie23a(ie, WLAN_EID_EXT_SUPP_RATES,
853 &ie_len, pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500854 if (p) {
855 memcpy(supportRate+supportRateNum, p+2, ie_len);
856 supportRateNum += ie_len;
857 }
858
859 network_type = rtw_check_network_type23a(supportRate,
860 supportRateNum, channel);
861
862 rtw_set_supported_rate23a(pbss_network->SupportedRates, network_type);
863
864 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200865 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &ie_len,
866 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500867 if (p && ie_len > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +0200868 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -0500869
870 /* update privacy/security */
Jes Sorensen51a26d22014-06-24 15:03:21 +0200871 if (pbss_network->capability & BIT(4))
Larry Finger5e93f352014-03-28 21:37:38 -0500872 pbss_network->Privacy = 1;
873 else
874 pbss_network->Privacy = 0;
875
876 psecuritypriv->wpa_psk = 0;
877
878 /* wpa2 */
879 group_cipher = 0; pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200880 psecuritypriv->wpa2_group_cipher = 0;
881 psecuritypriv->wpa2_pairwise_cipher = 0;
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200882 p = rtw_get_ie23a(ie, WLAN_EID_RSN, &ie_len,
883 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500884 if (p && ie_len > 0) {
885 if (rtw_parse_wpa2_ie23a(p, ie_len+2, &group_cipher,
886 &pairwise_cipher, NULL) == _SUCCESS) {
887 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
888
889 psecuritypriv->dot8021xalg = 1;/* psk, todo:802.1x */
890 psecuritypriv->wpa_psk |= BIT(1);
891
892 psecuritypriv->wpa2_group_cipher = group_cipher;
893 psecuritypriv->wpa2_pairwise_cipher = pairwise_cipher;
894 }
895 }
896
897 /* wpa */
898 ie_len = 0;
899 group_cipher = 0;
900 pairwise_cipher = 0;
Jes Sorensen9e3d6df2014-05-21 09:37:34 +0200901 psecuritypriv->wpa_group_cipher = 0;
902 psecuritypriv->wpa_pairwise_cipher = 0;
Joe Borg22faca22014-12-16 02:54:32 -0500903 for (p = ie; ; p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200904 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200905 pbss_network->IELength - (ie_len + 2));
Jes Sorensen819d1812014-04-26 18:55:44 +0200906 if ((p) && (!memcmp(p+2, RTW_WPA_OUI23A_TYPE, 4))) {
Larry Finger5e93f352014-03-28 21:37:38 -0500907 if (rtw_parse_wpa_ie23a(p, ie_len+2, &group_cipher,
908 &pairwise_cipher, NULL) == _SUCCESS) {
909 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
910
911 /* psk, todo:802.1x */
912 psecuritypriv->dot8021xalg = 1;
913
914 psecuritypriv->wpa_psk |= BIT(0);
915
916 psecuritypriv->wpa_group_cipher = group_cipher;
917 psecuritypriv->wpa_pairwise_cipher = pairwise_cipher;
918 }
919 break;
920 }
921
922 if ((p == NULL) || (ie_len == 0))
923 break;
924 }
925
926 /* wmm */
927 ie_len = 0;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200928 pmlmepriv->qos_option = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500929 if (pregistrypriv->wmm_enable) {
Joe Borg22faca22014-12-16 02:54:32 -0500930 for (p = ie; ; p += (ie_len + 2)) {
Jes Sorensen9300c942014-04-15 19:43:21 +0200931 p = rtw_get_ie23a(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len,
Larry Finger5e93f352014-03-28 21:37:38 -0500932 (pbss_network->IELength -
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200933 (ie_len + 2)));
Larry Finger5e93f352014-03-28 21:37:38 -0500934 if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) {
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200935 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500936
937 *(p+8) |= BIT(7);/* QoS Info, support U-APSD */
938
939 /* disable all ACM bits since the WMM admission
940 * control is not supported
941 */
942 *(p + 10) &= ~BIT(4); /* BE */
943 *(p + 14) &= ~BIT(4); /* BK */
944 *(p + 18) &= ~BIT(4); /* VI */
945 *(p + 22) &= ~BIT(4); /* VO */
946 break;
947 }
948 if ((p == NULL) || (ie_len == 0))
949 break;
950 }
951 }
952 /* parsing HT_CAP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200953 p = rtw_get_ie23a(ie, WLAN_EID_HT_CAPABILITY, &ie_len,
954 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500955 if (p && ie_len > 0) {
956 u8 rf_type;
957
958 struct ieee80211_ht_cap *pht_cap = (struct ieee80211_ht_cap *)(p+2);
959
960 pHT_caps_ie = p;
961
962 ht_cap = true;
963 network_type |= WIRELESS_11_24N;
964
Jes Sorensenc2370e82014-04-09 23:20:53 +0200965 rf_type = rtl8723a_get_rf_type(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500966
967 if ((psecuritypriv->wpa_pairwise_cipher & WPA_CIPHER_CCMP) ||
968 (psecuritypriv->wpa2_pairwise_cipher & WPA_CIPHER_CCMP))
969 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY & (0x07<<2));
970 else
971 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_DENSITY&0x00);
972
973 /* set Max Rx AMPDU size to 64K */
974 pht_cap->ampdu_params_info |= (IEEE80211_HT_AMPDU_PARM_FACTOR & 0x03);
975
976 if (rf_type == RF_1T1R) {
977 pht_cap->mcs.rx_mask[0] = 0xff;
978 pht_cap->mcs.rx_mask[1] = 0x0;
979 }
980
981 memcpy(&pmlmepriv->htpriv.ht_cap, p+2, ie_len);
982 }
983
984 /* parsing HT_INFO_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +0200985 p = rtw_get_ie23a(ie, WLAN_EID_HT_OPERATION, &ie_len,
986 pbss_network->IELength);
Larry Finger5e93f352014-03-28 21:37:38 -0500987 if (p && ie_len > 0)
988 pHT_info_ie = p;
989
Larry Finger5e93f352014-03-28 21:37:38 -0500990 pmlmepriv->cur_network.network_type = network_type;
991
992 pmlmepriv->htpriv.ht_option = false;
993
994 /* ht_cap */
995 if (pregistrypriv->ht_enable && ht_cap) {
996 pmlmepriv->htpriv.ht_option = true;
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200997 pmlmepriv->qos_option = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500998
999 if (pregistrypriv->ampdu_enable == 1)
1000 pmlmepriv->htpriv.ampdu_enable = true;
1001
Jes Sorensenb171da32014-05-21 09:37:42 +02001002 HT_caps_handler23a(padapter, pHT_caps_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001003
Jes Sorensenb171da32014-05-21 09:37:42 +02001004 HT_info_handler23a(padapter, pHT_info_ie);
Larry Finger5e93f352014-03-28 21:37:38 -05001005 }
1006
Jes Sorensen52017952014-04-26 18:55:09 +02001007 pbss_network->Length = get_wlan_bssid_ex_sz(pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001008
1009 /* issue beacon to start bss network */
Greg Donald7e6646d2014-09-06 19:42:03 -05001010 start_bss_network(padapter, (u8 *)pbss_network);
Larry Finger5e93f352014-03-28 21:37:38 -05001011
1012 /* alloc sta_info for ap itself */
1013 psta = rtw_get_stainfo23a(&padapter->stapriv, pbss_network->MacAddress);
1014 if (!psta) {
Jes Sorensen6e8bc712014-05-09 15:03:49 +02001015 psta = rtw_alloc_stainfo23a(&padapter->stapriv,
1016 pbss_network->MacAddress,
1017 GFP_KERNEL);
Larry Finger5e93f352014-03-28 21:37:38 -05001018 if (!psta)
1019 return _FAIL;
1020 }
1021 /* fix bug of flush_cam_entry at STOP AP mode */
1022 psta->state |= WIFI_AP_STATE;
1023 rtw_indicate_connect23a(padapter);
1024
1025 /* for check if already set beacon */
1026 pmlmepriv->cur_network.join_res = true;
1027
1028 return ret;
1029}
1030
1031void rtw_set_macaddr_acl23a(struct rtw_adapter *padapter, int mode)
1032{
1033 struct sta_priv *pstapriv = &padapter->stapriv;
1034 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1035
1036 DBG_8723A("%s, mode =%d\n", __func__, mode);
1037
1038 pacl_list->mode = mode;
1039}
1040
1041int rtw_acl_add_sta23a(struct rtw_adapter *padapter, u8 *addr)
1042{
1043 struct list_head *plist, *phead;
1044 u8 added = false;
1045 int i, ret = 0;
1046 struct rtw_wlan_acl_node *paclnode;
1047 struct sta_priv *pstapriv = &padapter->stapriv;
1048 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1049 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1050
Joe Perchesea072782015-03-24 11:10:09 -07001051 DBG_8723A("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, addr);
Larry Finger5e93f352014-03-28 21:37:38 -05001052
1053 if ((NUM_ACL-1) < pacl_list->num)
1054 return -1;
1055
1056 spin_lock_bh(&pacl_node_q->lock);
1057
1058 phead = get_list_head(pacl_node_q);
1059
1060 list_for_each(plist, phead) {
1061 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1062
1063 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1064 if (paclnode->valid == true) {
1065 added = true;
1066 DBG_8723A("%s, sta has been added\n", __func__);
1067 break;
1068 }
1069 }
1070 }
1071
1072 spin_unlock_bh(&pacl_node_q->lock);
1073
1074 if (added)
1075 return ret;
1076
1077 spin_lock_bh(&pacl_node_q->lock);
1078
1079 for (i = 0; i < NUM_ACL; i++) {
1080 paclnode = &pacl_list->aclnode[i];
1081
1082 if (!paclnode->valid) {
1083 INIT_LIST_HEAD(&paclnode->list);
1084
1085 memcpy(paclnode->addr, addr, ETH_ALEN);
1086
1087 paclnode->valid = true;
1088
1089 list_add_tail(&paclnode->list, get_list_head(pacl_node_q));
1090
1091 pacl_list->num++;
1092
1093 break;
1094 }
1095 }
1096
1097 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1098
1099 spin_unlock_bh(&pacl_node_q->lock);
1100 return ret;
1101}
1102
1103int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
1104{
1105 struct list_head *plist, *phead, *ptmp;
1106 struct rtw_wlan_acl_node *paclnode;
1107 struct sta_priv *pstapriv = &padapter->stapriv;
1108 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1109 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
Larry Finger5e93f352014-03-28 21:37:38 -05001110
1111 DBG_8723A("%s(acl_num =%d) = %pM\n", __func__, pacl_list->num, addr);
1112
1113 spin_lock_bh(&pacl_node_q->lock);
1114
1115 phead = get_list_head(pacl_node_q);
1116
1117 list_for_each_safe(plist, ptmp, phead) {
1118 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
1119
1120 if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
1121 if (paclnode->valid) {
1122 paclnode->valid = false;
1123
1124 list_del_init(&paclnode->list);
1125
1126 pacl_list->num--;
1127 }
1128 }
1129 }
1130
1131 spin_unlock_bh(&pacl_node_q->lock);
1132
1133 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1134
Heena Sirwanif9800f82014-10-07 14:46:30 +05301135 return 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001136}
1137
1138static void update_bcn_fixed_ie(struct rtw_adapter *padapter)
1139{
1140 DBG_8723A("%s\n", __func__);
1141}
1142
1143static void update_bcn_erpinfo_ie(struct rtw_adapter *padapter)
1144{
1145 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1146 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1147 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1148 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1149 unsigned char *p, *ie = pnetwork->IEs;
1150 u32 len = 0;
1151
1152 DBG_8723A("%s, ERP_enable =%d\n", __func__, pmlmeinfo->ERP_enable);
1153
1154 if (!pmlmeinfo->ERP_enable)
1155 return;
1156
1157 /* parsing ERP_IE */
Jes Sorensen1de65cc2014-06-24 15:03:30 +02001158 p = rtw_get_ie23a(ie, WLAN_EID_ERP_INFO, &len, pnetwork->IELength);
Jes Sorensenb171da32014-05-21 09:37:42 +02001159 if (p && len > 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001160 if (pmlmepriv->num_sta_non_erp == 1)
Jes Sorensenb171da32014-05-21 09:37:42 +02001161 p[2] |= WLAN_ERP_NON_ERP_PRESENT |
Larry Finger5e93f352014-03-28 21:37:38 -05001162 WLAN_ERP_USE_PROTECTION;
1163 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001164 p[2] &= ~(WLAN_ERP_NON_ERP_PRESENT |
1165 WLAN_ERP_USE_PROTECTION);
Larry Finger5e93f352014-03-28 21:37:38 -05001166
1167 if (pmlmepriv->num_sta_no_short_preamble > 0)
Jes Sorensenb171da32014-05-21 09:37:42 +02001168 p[2] |= WLAN_ERP_BARKER_PREAMBLE;
Larry Finger5e93f352014-03-28 21:37:38 -05001169 else
Jes Sorensenb171da32014-05-21 09:37:42 +02001170 p[2] &= ~(WLAN_ERP_BARKER_PREAMBLE);
Larry Finger5e93f352014-03-28 21:37:38 -05001171
Jes Sorensenb171da32014-05-21 09:37:42 +02001172 ERP_IE_handler23a(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -05001173 }
1174}
1175
1176static void update_bcn_htcap_ie(struct rtw_adapter *padapter)
1177{
1178 DBG_8723A("%s\n", __func__);
1179}
1180
1181static void update_bcn_htinfo_ie(struct rtw_adapter *padapter)
1182{
1183 DBG_8723A("%s\n", __func__);
1184}
1185
1186static void update_bcn_rsn_ie(struct rtw_adapter *padapter)
1187{
1188 DBG_8723A("%s\n", __func__);
1189}
1190
1191static void update_bcn_wpa_ie(struct rtw_adapter *padapter)
1192{
1193 DBG_8723A("%s\n", __func__);
1194}
1195
1196static void update_bcn_wmm_ie(struct rtw_adapter *padapter)
1197{
1198 DBG_8723A("%s\n", __func__);
1199}
1200
1201static void update_bcn_wps_ie(struct rtw_adapter *padapter)
1202{
Larry Finger5e93f352014-03-28 21:37:38 -05001203 DBG_8723A("%s\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -05001204}
1205
1206static void update_bcn_p2p_ie(struct rtw_adapter *padapter)
1207{
1208}
1209
Joe Borg22faca22014-12-16 02:54:32 -05001210static void update_bcn_vendor_spec_ie(struct rtw_adapter *padapter, u8 *oui)
Larry Finger5e93f352014-03-28 21:37:38 -05001211{
1212 DBG_8723A("%s\n", __func__);
1213
Jes Sorensen7964eba02014-04-15 19:44:11 +02001214 if (!memcmp(RTW_WPA_OUI23A_TYPE, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001215 update_bcn_wpa_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001216 else if (!memcmp(WMM_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001217 update_bcn_wmm_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001218 else if (!memcmp(WPS_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001219 update_bcn_wps_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001220 else if (!memcmp(P2P_OUI23A, oui, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001221 update_bcn_p2p_ie(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -05001222 else
Larry Finger5e93f352014-03-28 21:37:38 -05001223 DBG_8723A("unknown OUI type!\n");
Larry Finger5e93f352014-03-28 21:37:38 -05001224}
1225
1226void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1227{
1228 struct mlme_priv *pmlmepriv;
1229 struct mlme_ext_priv *pmlmeext;
1230 /* struct mlme_ext_info *pmlmeinfo; */
1231
1232 /* DBG_8723A("%s\n", __func__); */
1233
1234 if (!padapter)
1235 return;
1236
1237 pmlmepriv = &padapter->mlmepriv;
1238 pmlmeext = &padapter->mlmeextpriv;
1239 /* pmlmeinfo = &pmlmeext->mlmext_info; */
1240
1241 if (false == pmlmeext->bstart_bss)
1242 return;
1243
1244 spin_lock_bh(&pmlmepriv->bcn_update_lock);
1245
Tina Ruchandanif2372162014-10-23 20:16:51 -07001246 switch (ie_id) {
Jes Sorensenb54e8802014-04-09 23:20:52 +02001247 case 0xFF:
1248 /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1249 update_bcn_fixed_ie(padapter);
1250 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001251
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001252 case WLAN_EID_TIM:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001253 update_BCNTIM(padapter);
1254 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001255
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001256 case WLAN_EID_ERP_INFO:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001257 update_bcn_erpinfo_ie(padapter);
1258 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001259
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001260 case WLAN_EID_HT_CAPABILITY:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001261 update_bcn_htcap_ie(padapter);
1262 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001263
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001264 case WLAN_EID_RSN:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001265 update_bcn_rsn_ie(padapter);
1266 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001267
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001268 case WLAN_EID_HT_OPERATION:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001269 update_bcn_htinfo_ie(padapter);
1270 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001271
Jes Sorensen9300c942014-04-15 19:43:21 +02001272 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb54e8802014-04-09 23:20:52 +02001273 update_bcn_vendor_spec_ie(padapter, oui);
1274 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001275
Jes Sorensenb54e8802014-04-09 23:20:52 +02001276 default:
1277 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001278 }
1279
1280 pmlmepriv->update_bcn = true;
1281
1282 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
1283
1284 if (tx)
1285 set_tx_beacon_cmd23a(padapter);
1286}
1287
1288/*
1289op_mode
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001290Set to 0 (HT pure) under the following conditions
Larry Finger5e93f352014-03-28 21:37:38 -05001291 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
1292 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
1293Set to 1 (HT non-member protection) if there may be non-HT STAs
1294 in both the primary and the secondary channel
1295Set to 2 if only HT STAs are associated in BSS,
1296 however and at least one 20 MHz HT STA is associated
1297Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
1298 (currently non-GF HT station is considered as non-HT STA also)
1299*/
1300static int rtw_ht_operation_update(struct rtw_adapter *padapter)
1301{
1302 u16 cur_op_mode, new_op_mode;
1303 int op_mode_changes = 0;
1304 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1305 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
1306
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001307 if (pmlmepriv->htpriv.ht_option)
Larry Finger5e93f352014-03-28 21:37:38 -05001308 return 0;
1309
1310 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */
1311 /* return 0; */
1312
1313 DBG_8723A("%s current operation mode = 0x%X\n",
1314 __func__, pmlmepriv->ht_op_mode);
1315
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001316 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
Larry Finger5e93f352014-03-28 21:37:38 -05001317 && pmlmepriv->num_sta_ht_no_gf) {
1318 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 op_mode_changes++;
1321 } else if ((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 pmlmepriv->num_sta_ht_no_gf == 0) {
1324 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001325 ~IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001326 op_mode_changes++;
1327 }
1328
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001329 if (!(pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) &&
Larry Finger5e93f352014-03-28 21:37:38 -05001330 (pmlmepriv->num_sta_no_ht || pmlmepriv->olbc_ht)) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001331 pmlmepriv->ht_op_mode |= IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001332 op_mode_changes++;
1333 } else if ((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 (pmlmepriv->num_sta_no_ht == 0 && !pmlmepriv->olbc_ht)) {
1336 pmlmepriv->ht_op_mode &=
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001337 ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Larry Finger5e93f352014-03-28 21:37:38 -05001338 op_mode_changes++;
1339 }
1340
1341 /* Note: currently we switch to the MIXED op mode if HT non-greenfield
1342 * station is associated. Probably it's a theoretical case, since
1343 * it looks like all known HT STAs support greenfield.
1344 */
Larry Finger5e93f352014-03-28 21:37:38 -05001345 if (pmlmepriv->num_sta_no_ht ||
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001346 (pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
Jes Sorensenc3899282014-05-21 09:37:51 +02001347 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
Larry Fingera96ae6f2014-04-26 18:55:18 +02001348 else if ((le16_to_cpu(phtpriv_ap->ht_cap.cap_info) &
1349 IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
1350 pmlmepriv->num_sta_ht_20mhz)
Jes Sorensenc3899282014-05-21 09:37:51 +02001351 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
Larry Finger5e93f352014-03-28 21:37:38 -05001352 else if (pmlmepriv->olbc_ht)
Jes Sorensenc3899282014-05-21 09:37:51 +02001353 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER;
Larry Finger5e93f352014-03-28 21:37:38 -05001354 else
Jes Sorensenc3899282014-05-21 09:37:51 +02001355 new_op_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
Larry Finger5e93f352014-03-28 21:37:38 -05001356
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001357 cur_op_mode = pmlmepriv->ht_op_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001358 if (cur_op_mode != new_op_mode) {
Jes Sorensen2c50c7c2014-05-21 09:37:47 +02001359 pmlmepriv->ht_op_mode &= ~IEEE80211_HT_OP_MODE_PROTECTION;
Larry Finger5e93f352014-03-28 21:37:38 -05001360 pmlmepriv->ht_op_mode |= new_op_mode;
1361 op_mode_changes++;
1362 }
1363
1364 DBG_8723A("%s new operation mode = 0x%X changes =%d\n",
1365 __func__, pmlmepriv->ht_op_mode, op_mode_changes);
1366
1367 return op_mode_changes;
1368}
1369
1370void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated)
1371{
Masanari Iida96b0a5b2014-07-22 23:42:45 +09001372 /* update associated stations cap. */
Tina Ruchandanif2372162014-10-23 20:16:51 -07001373 if (updated == true) {
Larry Finger5e93f352014-03-28 21:37:38 -05001374 struct list_head *phead, *plist, *ptmp;
1375 struct sta_info *psta;
1376 struct sta_priv *pstapriv = &padapter->stapriv;
1377
1378 spin_lock_bh(&pstapriv->asoc_list_lock);
1379
1380 phead = &pstapriv->asoc_list;
1381
1382 list_for_each_safe(plist, ptmp, phead) {
1383 psta = container_of(plist, struct sta_info, asoc_list);
1384
1385 VCS_update23a(padapter, psta);
1386 }
1387
1388 spin_unlock_bh(&pstapriv->asoc_list_lock);
1389 }
1390}
1391
1392/* called > TSR LEVEL for USB or SDIO Interface*/
1393void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info *psta)
1394{
1395 u8 beacon_updated = false;
1396 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1397 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1398
Tina Ruchandanif2372162014-10-23 20:16:51 -07001399 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1400 if (!psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001401 psta->no_short_preamble_set = 1;
1402
1403 pmlmepriv->num_sta_no_short_preamble++;
1404
1405 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001406 (pmlmepriv->num_sta_no_short_preamble == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001407 beacon_updated = true;
1408 update_beacon23a(padapter, 0xFF, NULL, true);
1409 }
1410
1411 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001412 } else {
1413 if (psta->no_short_preamble_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001414 psta->no_short_preamble_set = 0;
1415
1416 pmlmepriv->num_sta_no_short_preamble--;
1417
1418 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001419 (pmlmepriv->num_sta_no_short_preamble == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001420 beacon_updated = true;
1421 update_beacon23a(padapter, 0xFF, NULL, true);
1422 }
1423
1424 }
1425 }
1426
Tina Ruchandanif2372162014-10-23 20:16:51 -07001427 if (psta->flags & WLAN_STA_NONERP) {
1428 if (!psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001429 psta->nonerp_set = 1;
1430
1431 pmlmepriv->num_sta_non_erp++;
1432
Tina Ruchandanif2372162014-10-23 20:16:51 -07001433 if (pmlmepriv->num_sta_non_erp == 1) {
Larry Finger5e93f352014-03-28 21:37:38 -05001434 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001435 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001436 }
1437 }
1438
Tina Ruchandanif2372162014-10-23 20:16:51 -07001439 } else {
1440 if (psta->nonerp_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001441 psta->nonerp_set = 0;
1442
1443 pmlmepriv->num_sta_non_erp--;
1444
Tina Ruchandanif2372162014-10-23 20:16:51 -07001445 if (pmlmepriv->num_sta_non_erp == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -05001446 beacon_updated = true;
Jes Sorensenaf2cb2c2014-04-15 19:43:26 +02001447 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001448 }
1449 }
1450
1451 }
1452
Tina Ruchandanif2372162014-10-23 20:16:51 -07001453 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1454 if (!psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001455 psta->no_short_slot_time_set = 1;
1456
1457 pmlmepriv->num_sta_no_short_slot_time++;
1458
1459 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001460 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001461 beacon_updated = true;
1462 update_beacon23a(padapter, 0xFF, NULL, true);
1463 }
1464
1465 }
Tina Ruchandanif2372162014-10-23 20:16:51 -07001466 } else {
1467 if (psta->no_short_slot_time_set) {
Larry Finger5e93f352014-03-28 21:37:38 -05001468 psta->no_short_slot_time_set = 0;
1469
1470 pmlmepriv->num_sta_no_short_slot_time--;
1471
1472 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
Tina Ruchandanif2372162014-10-23 20:16:51 -07001473 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001474 beacon_updated = true;
1475 update_beacon23a(padapter, 0xFF, NULL, true);
1476 }
1477 }
1478 }
1479
Tina Ruchandanif2372162014-10-23 20:16:51 -07001480 if (psta->flags & WLAN_STA_HT) {
Larry Finger5e93f352014-03-28 21:37:38 -05001481 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
1482
Joe Perchesea072782015-03-24 11:10:09 -07001483 DBG_8723A("HT: STA %pM HT Capabilities Info: 0x%04x\n",
1484 psta->hwaddr, ht_capab);
Larry Finger5e93f352014-03-28 21:37:38 -05001485
1486 if (psta->no_ht_set) {
1487 psta->no_ht_set = 0;
1488 pmlmepriv->num_sta_no_ht--;
1489 }
1490
1491 if ((ht_capab & IEEE80211_HT_CAP_GRN_FLD) == 0) {
1492 if (!psta->no_ht_gf_set) {
1493 psta->no_ht_gf_set = 1;
1494 pmlmepriv->num_sta_ht_no_gf++;
1495 }
Joe Perchesea072782015-03-24 11:10:09 -07001496 DBG_8723A("%s STA %pM - no greenfield, num of non-gf stations %d\n",
1497 __func__, psta->hwaddr,
1498 pmlmepriv->num_sta_ht_no_gf);
Larry Finger5e93f352014-03-28 21:37:38 -05001499 }
1500
1501 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH_20_40) == 0) {
1502 if (!psta->ht_20mhz_set) {
1503 psta->ht_20mhz_set = 1;
1504 pmlmepriv->num_sta_ht_20mhz++;
1505 }
Joe Perchesea072782015-03-24 11:10:09 -07001506 DBG_8723A("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n",
1507 __func__, psta->hwaddr,
1508 pmlmepriv->num_sta_ht_20mhz);
Larry Finger5e93f352014-03-28 21:37:38 -05001509 }
1510
Tina Ruchandanif2372162014-10-23 20:16:51 -07001511 } else {
Larry Finger5e93f352014-03-28 21:37:38 -05001512 if (!psta->no_ht_set) {
1513 psta->no_ht_set = 1;
1514 pmlmepriv->num_sta_no_ht++;
1515 }
Jes Sorensen6a5f6572014-06-09 15:16:07 +02001516 if (pmlmepriv->htpriv.ht_option) {
Joe Perchesea072782015-03-24 11:10:09 -07001517 DBG_8723A("%s STA %pM - no HT, num of non-HT stations %d\n",
1518 __func__, psta->hwaddr,
1519 pmlmepriv->num_sta_no_ht);
Larry Finger5e93f352014-03-28 21:37:38 -05001520 }
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}