blob: 69d9e0f17fd8390544409fd2a1dfa3ed9bbed2aa [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_WLAN_UTIL_C_
16
17#include <osdep_service.h>
18#include <drv_types.h>
19#include <linux/ieee80211.h>
20#include <wifi.h>
Jes Sorensen6ec26272014-07-17 22:59:46 +020021#include <rtl8723a_spec.h>
Larry Finger5e93f352014-03-28 21:37:38 -050022
23static unsigned char ARTHEROS_OUI1[] = {0x00, 0x03, 0x7f};
24static unsigned char ARTHEROS_OUI2[] = {0x00, 0x13, 0x74};
25
26static unsigned char BROADCOM_OUI1[] = {0x00, 0x10, 0x18};
27static unsigned char BROADCOM_OUI2[] = {0x00, 0x0a, 0xf7};
28
29static unsigned char CISCO_OUI[] = {0x00, 0x40, 0x96};
30static unsigned char MARVELL_OUI[] = {0x00, 0x50, 0x43};
31static unsigned char RALINK_OUI[] = {0x00, 0x0c, 0x43};
32static unsigned char REALTEK_OUI[] = {0x00, 0xe0, 0x4c};
33static unsigned char AIRGOCAP_OUI[] = {0x00, 0x0a, 0xf5};
34static unsigned char EPIGRAM_OUI[] = {0x00, 0x90, 0x4c};
35
Jes Sorensen78717782014-05-09 15:04:07 +020036static unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
37static unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
38
Jes Sorensenc227ed02014-05-09 15:03:27 +020039#define R2T_PHY_DELAY 0
Larry Finger5e93f352014-03-28 21:37:38 -050040
Jes Sorensenc227ed02014-05-09 15:03:27 +020041/* define WAIT_FOR_BCN_TO_MIN 3000 */
42#define WAIT_FOR_BCN_TO_MIN 6000
43#define WAIT_FOR_BCN_TO_MAX 20000
Larry Finger5e93f352014-03-28 21:37:38 -050044
45static u8 rtw_basic_rate_cck[4] = {
Jes Sorensenc227ed02014-05-09 15:03:27 +020046 IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK,
47 IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
48 IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK,
49 IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
Larry Finger5e93f352014-03-28 21:37:38 -050050};
51
52static u8 rtw_basic_rate_ofdm[3] = {
Jes Sorensenc227ed02014-05-09 15:03:27 +020053 IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK,
54 IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
55 IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
Larry Finger5e93f352014-03-28 21:37:38 -050056};
57
58static u8 rtw_basic_rate_mix[7] = {
Jes Sorensenc227ed02014-05-09 15:03:27 +020059 IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK,
60 IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
61 IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK,
62 IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK,
63 IEEE80211_OFDM_RATE_6MB | IEEE80211_BASIC_RATE_MASK,
64 IEEE80211_OFDM_RATE_12MB | IEEE80211_BASIC_RATE_MASK,
65 IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
Larry Finger5e93f352014-03-28 21:37:38 -050066};
67
68int cckrates_included23a(unsigned char *rate, int ratelen)
69{
70 int i;
71
72 for (i = 0; i < ratelen; i++) {
Jes Sorensenc227ed02014-05-09 15:03:27 +020073 if (((rate[i]) & 0x7f) == 2 || ((rate[i]) & 0x7f) == 4 ||
74 ((rate[i]) & 0x7f) == 11 || ((rate[i]) & 0x7f) == 22)
Larry Finger5e93f352014-03-28 21:37:38 -050075 return true;
76 }
77
78 return false;
79}
80
81int cckratesonly_included23a(unsigned char *rate, int ratelen)
82{
83 int i;
84
85 for (i = 0; i < ratelen; i++) {
Jes Sorensenc227ed02014-05-09 15:03:27 +020086 if (((rate[i]) & 0x7f) != 2 && ((rate[i]) & 0x7f) != 4 &&
87 ((rate[i]) & 0x7f) != 11 && ((rate[i]) & 0x7f) != 22)
Larry Finger5e93f352014-03-28 21:37:38 -050088 return false;
89 }
90
91 return true;
92}
93
94unsigned char networktype_to_raid23a(unsigned char network_type)
95{
96 unsigned char raid;
97
98 switch (network_type) {
99 case WIRELESS_11B:
100 raid = RATR_INX_WIRELESS_B;
101 break;
102 case WIRELESS_11A:
103 case WIRELESS_11G:
104 raid = RATR_INX_WIRELESS_G;
105 break;
106 case WIRELESS_11BG:
107 raid = RATR_INX_WIRELESS_GB;
108 break;
109 case WIRELESS_11_24N:
110 case WIRELESS_11_5N:
111 raid = RATR_INX_WIRELESS_N;
112 break;
113 case WIRELESS_11A_5N:
114 case WIRELESS_11G_24N:
115 raid = RATR_INX_WIRELESS_NG;
116 break;
117 case WIRELESS_11BG_24N:
118 raid = RATR_INX_WIRELESS_NGB;
119 break;
120 default:
121 raid = RATR_INX_WIRELESS_GB;
122 break;
123 }
124 return raid;
125}
126
Jes Sorensenc227ed02014-05-09 15:03:27 +0200127u8 judge_network_type23a(struct rtw_adapter *padapter,
128 unsigned char *rate, int ratelen)
Larry Finger5e93f352014-03-28 21:37:38 -0500129{
130 u8 network_type = 0;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200131 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500132 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
133
134 if (pmlmeext->cur_channel > 14) {
135 if (pmlmeinfo->HT_enable)
136 network_type = WIRELESS_11_5N;
137 network_type |= WIRELESS_11A;
138 } else {
139 if (pmlmeinfo->HT_enable)
140 network_type = WIRELESS_11_24N;
141
142 if ((cckratesonly_included23a(rate, ratelen)) == true)
143 network_type |= WIRELESS_11B;
144 else if ((cckrates_included23a(rate, ratelen)) == true)
145 network_type |= WIRELESS_11BG;
146 else
147 network_type |= WIRELESS_11G;
148 }
149 return network_type;
150}
151
Larry Fingerc0b99be2014-04-26 18:55:17 +0200152static unsigned char ratetbl_val_2wifirate(unsigned char rate)
Larry Finger5e93f352014-03-28 21:37:38 -0500153{
154 unsigned char val = 0;
155
156 switch (rate & 0x7f) {
157 case 0:
158 val = IEEE80211_CCK_RATE_1MB;
159 break;
160 case 1:
161 val = IEEE80211_CCK_RATE_2MB;
162 break;
163 case 2:
164 val = IEEE80211_CCK_RATE_5MB;
165 break;
166 case 3:
167 val = IEEE80211_CCK_RATE_11MB;
168 break;
169 case 4:
170 val = IEEE80211_OFDM_RATE_6MB;
171 break;
172 case 5:
173 val = IEEE80211_OFDM_RATE_9MB;
174 break;
175 case 6:
176 val = IEEE80211_OFDM_RATE_12MB;
177 break;
178 case 7:
179 val = IEEE80211_OFDM_RATE_18MB;
180 break;
181 case 8:
182 val = IEEE80211_OFDM_RATE_24MB;
183 break;
184 case 9:
185 val = IEEE80211_OFDM_RATE_36MB;
186 break;
187 case 10:
188 val = IEEE80211_OFDM_RATE_48MB;
189 break;
190 case 11:
191 val = IEEE80211_OFDM_RATE_54MB;
192 break;
193 }
194 return val;
195}
196
Larry Fingerc0b99be2014-04-26 18:55:17 +0200197static int is_basicrate(struct rtw_adapter *padapter, unsigned char rate)
Larry Finger5e93f352014-03-28 21:37:38 -0500198{
199 int i;
200 unsigned char val;
201 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
202
203 for (i = 0; i < NumRates; i++) {
204 val = pmlmeext->basicrate[i];
205
Jes Sorensenc227ed02014-05-09 15:03:27 +0200206 if (val != 0xff && val != 0xfe) {
Larry Finger5e93f352014-03-28 21:37:38 -0500207 if (rate == ratetbl_val_2wifirate(val))
208 return true;
209 }
210 }
211
212 return false;
213}
214
Larry Fingerc0b99be2014-04-26 18:55:17 +0200215static unsigned int ratetbl2rateset(struct rtw_adapter *padapter,
216 unsigned char *rateset)
Larry Finger5e93f352014-03-28 21:37:38 -0500217{
218 int i;
219 unsigned char rate;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200220 unsigned int len = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500221 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
222
223 for (i = 0; i < NumRates; i++) {
224 rate = pmlmeext->datarate[i];
225
226 switch (rate) {
227 case 0xff:
228 return len;
229 case 0xfe:
230 continue;
231 default:
232 rate = ratetbl_val_2wifirate(rate);
233
234 if (is_basicrate(padapter, rate) == true)
235 rate |= IEEE80211_BASIC_RATE_MASK;
236
237 rateset[len] = rate;
238 len++;
239 break;
240 }
241 }
242 return len;
243}
244
Jes Sorensenc227ed02014-05-09 15:03:27 +0200245void get_rate_set23a(struct rtw_adapter *padapter,
246 unsigned char *pbssrate, int *bssrate_len)
Larry Finger5e93f352014-03-28 21:37:38 -0500247{
248 unsigned char supportedrates[NumRates];
249
250 memset(supportedrates, 0, NumRates);
251 *bssrate_len = ratetbl2rateset(padapter, supportedrates);
252 memcpy(pbssrate, supportedrates, *bssrate_len);
253}
254
255void UpdateBrateTbl23a(struct rtw_adapter *Adapter, u8 *mBratesOS)
256{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200257 u8 i;
258 u8 rate;
Larry Finger5e93f352014-03-28 21:37:38 -0500259
260 /* 1M, 2M, 5.5M, 11M, 6M, 12M, 24M are mandatory. */
261 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
262 rate = mBratesOS[i] & 0x7f;
263 switch (rate) {
264 case IEEE80211_CCK_RATE_1MB:
265 case IEEE80211_CCK_RATE_2MB:
266 case IEEE80211_CCK_RATE_5MB:
267 case IEEE80211_CCK_RATE_11MB:
268 case IEEE80211_OFDM_RATE_6MB:
269 case IEEE80211_OFDM_RATE_12MB:
270 case IEEE80211_OFDM_RATE_24MB:
271 mBratesOS[i] |= IEEE80211_BASIC_RATE_MASK;
272 break;
273 default:
274 break;
275 }
276 }
277}
278
279void Update23aTblForSoftAP(u8 *bssrateset, u32 bssratelen)
280{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200281 u8 i;
282 u8 rate;
Larry Finger5e93f352014-03-28 21:37:38 -0500283
284 for (i = 0; i < bssratelen; i++) {
285 rate = bssrateset[i] & 0x7f;
286 switch (rate) {
287 case IEEE80211_CCK_RATE_1MB:
288 case IEEE80211_CCK_RATE_2MB:
289 case IEEE80211_CCK_RATE_5MB:
290 case IEEE80211_CCK_RATE_11MB:
291 bssrateset[i] |= IEEE80211_BASIC_RATE_MASK;
292 break;
293 }
294 }
295}
296
Larry Finger5e93f352014-03-28 21:37:38 -0500297inline u8 rtw_get_oper_ch23a(struct rtw_adapter *adapter)
298{
299 return adapter_to_dvobj(adapter)->oper_channel;
300}
301
302inline void rtw_set_oper_ch23a(struct rtw_adapter *adapter, u8 ch)
303{
304 adapter_to_dvobj(adapter)->oper_channel = ch;
305}
306
307inline u8 rtw_get_oper_bw23a(struct rtw_adapter *adapter)
308{
309 return adapter_to_dvobj(adapter)->oper_bwmode;
310}
311
312inline void rtw_set_oper_bw23a(struct rtw_adapter *adapter, u8 bw)
313{
314 adapter_to_dvobj(adapter)->oper_bwmode = bw;
315}
316
317inline u8 rtw_get_oper_ch23aoffset(struct rtw_adapter *adapter)
318{
319 return adapter_to_dvobj(adapter)->oper_ch_offset;
320}
321
322inline void rtw_set_oper_ch23aoffset23a(struct rtw_adapter *adapter, u8 offset)
323{
324 adapter_to_dvobj(adapter)->oper_ch_offset = offset;
325}
326
327void SelectChannel23a(struct rtw_adapter *padapter, unsigned char channel)
328{
329 mutex_lock(&adapter_to_dvobj(padapter)->setch_mutex);
330
331 /* saved channel info */
332 rtw_set_oper_ch23a(padapter, channel);
333
Jes Sorensen8a6f5552014-05-16 10:04:08 +0200334 PHY_SwChnl8723A(padapter, channel);
Larry Finger5e93f352014-03-28 21:37:38 -0500335
336 mutex_unlock(&adapter_to_dvobj(padapter)->setch_mutex);
337}
338
Jes Sorensen9b0cb4b2014-05-21 09:38:23 +0200339static void set_bwmode(struct rtw_adapter *padapter, unsigned short bwmode,
340 unsigned char channel_offset)
Larry Finger5e93f352014-03-28 21:37:38 -0500341{
342 mutex_lock(&adapter_to_dvobj(padapter)->setbw_mutex);
343
344 /* saved bw info */
345 rtw_set_oper_bw23a(padapter, bwmode);
346 rtw_set_oper_ch23aoffset23a(padapter, channel_offset);
347
Jes Sorensen8a6f5552014-05-16 10:04:08 +0200348 PHY_SetBWMode23a8723A(padapter, (enum ht_channel_width)bwmode,
349 channel_offset);
Larry Finger5e93f352014-03-28 21:37:38 -0500350
351 mutex_unlock(&adapter_to_dvobj(padapter)->setbw_mutex);
352}
353
354void set_channel_bwmode23a(struct rtw_adapter *padapter, unsigned char channel,
Greg Donalda82b4b02014-09-08 20:50:23 -0500355 unsigned char channel_offset, unsigned short bwmode)
Larry Finger5e93f352014-03-28 21:37:38 -0500356{
357 u8 center_ch;
358
Jes Sorensenc227ed02014-05-09 15:03:27 +0200359 if (bwmode == HT_CHANNEL_WIDTH_20 ||
360 channel_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
Larry Finger5e93f352014-03-28 21:37:38 -0500361 /* SelectChannel23a(padapter, channel); */
362 center_ch = channel;
363 } else {
364 /* switch to the proper channel */
365 if (channel_offset == HAL_PRIME_CHNL_OFFSET_LOWER) {
366 /* SelectChannel23a(padapter, channel + 2); */
367 center_ch = channel + 2;
368 } else {
369 /* SelectChannel23a(padapter, channel - 2); */
370 center_ch = channel - 2;
371 }
372 }
373
374 /* set Channel */
375 mutex_lock(&adapter_to_dvobj(padapter)->setch_mutex);
376
377 /* saved channel/bw info */
378 rtw_set_oper_ch23a(padapter, channel);
379 rtw_set_oper_bw23a(padapter, bwmode);
380 rtw_set_oper_ch23aoffset23a(padapter, channel_offset);
381
Jes Sorensen8a6f5552014-05-16 10:04:08 +0200382 PHY_SwChnl8723A(padapter, center_ch); /* set center channel */
Larry Finger5e93f352014-03-28 21:37:38 -0500383
384 mutex_unlock(&adapter_to_dvobj(padapter)->setch_mutex);
385
Jes Sorensen9b0cb4b2014-05-21 09:38:23 +0200386 set_bwmode(padapter, bwmode, channel_offset);
Larry Finger5e93f352014-03-28 21:37:38 -0500387}
388
Larry Finger5e93f352014-03-28 21:37:38 -0500389inline u8 *get_my_bssid23a(struct wlan_bssid_ex *pnetwork)
390{
391 return pnetwork->MacAddress;
392}
393
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200394bool is_client_associated_to_ap23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -0500395{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200396 struct mlme_ext_priv *pmlmeext;
397 struct mlme_ext_info *pmlmeinfo;
Larry Finger5e93f352014-03-28 21:37:38 -0500398
399 if (!padapter)
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200400 return false;
Larry Finger5e93f352014-03-28 21:37:38 -0500401
402 pmlmeext = &padapter->mlmeextpriv;
403 pmlmeinfo = &pmlmeext->mlmext_info;
404
Jes Sorensenc227ed02014-05-09 15:03:27 +0200405 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS &&
Jes Sorensen6ec26272014-07-17 22:59:46 +0200406 (pmlmeinfo->state & 0x03) == MSR_INFRA)
Larry Finger5e93f352014-03-28 21:37:38 -0500407 return true;
408 else
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200409 return false;
Larry Finger5e93f352014-03-28 21:37:38 -0500410}
411
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200412bool is_client_associated_to_ibss23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -0500413{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200414 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500415 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
416
Jes Sorensenc227ed02014-05-09 15:03:27 +0200417 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS &&
Jes Sorensen6ec26272014-07-17 22:59:46 +0200418 (pmlmeinfo->state & 0x03) == MSR_ADHOC)
Larry Finger5e93f352014-03-28 21:37:38 -0500419 return true;
420 else
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200421 return false;
Larry Finger5e93f352014-03-28 21:37:38 -0500422}
423
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200424bool is_IBSS_empty23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -0500425{
426 unsigned int i;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200427 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500428 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
429
430 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
431 if (pmlmeinfo->FW_sta_info[i].status == 1)
Jes Sorensenf6fe0a42014-05-16 10:04:39 +0200432 return false;
Larry Finger5e93f352014-03-28 21:37:38 -0500433 }
434
435 return true;
436}
437
438unsigned int decide_wait_for_beacon_timeout23a(unsigned int bcn_interval)
439{
440 if ((bcn_interval << 2) < WAIT_FOR_BCN_TO_MIN)
441 return WAIT_FOR_BCN_TO_MIN;
442 else if ((bcn_interval << 2) > WAIT_FOR_BCN_TO_MAX)
443 return WAIT_FOR_BCN_TO_MAX;
444 else
445 return bcn_interval << 2;
446}
447
Larry Finger5e93f352014-03-28 21:37:38 -0500448void clear_cam_entry23a(struct rtw_adapter *padapter, u8 entry)
449{
450 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
451
Jes Sorensenc227ed02014-05-09 15:03:27 +0200452 unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454 0x00, 0x00, 0x00, 0x00};
Larry Finger5e93f352014-03-28 21:37:38 -0500455
Jes Sorensendc0d16a2014-04-09 23:20:29 +0200456 rtl8723a_cam_write(padapter, entry, 0, null_sta, null_key);
Larry Finger5e93f352014-03-28 21:37:38 -0500457}
458
459int allocate_fw_sta_entry23a(struct rtw_adapter *padapter)
460{
461 unsigned int mac_id;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200462 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500463 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
464
465 for (mac_id = IBSS_START_MAC_ID; mac_id < NUM_STA; mac_id++) {
466 if (pmlmeinfo->FW_sta_info[mac_id].status == 0) {
467 pmlmeinfo->FW_sta_info[mac_id].status = 1;
468 pmlmeinfo->FW_sta_info[mac_id].retry = 0;
469 break;
470 }
471 }
472
473 return mac_id;
474}
475
476void flush_all_cam_entry23a(struct rtw_adapter *padapter)
477{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200478 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500479 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
480
Jes Sorensen2a3bc8a2014-07-17 22:59:53 +0200481 rtl8723a_cam_invalidate_all(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500482
Jes Sorensenc227ed02014-05-09 15:03:27 +0200483 memset(pmlmeinfo->FW_sta_info, 0, sizeof(pmlmeinfo->FW_sta_info));
Larry Finger5e93f352014-03-28 21:37:38 -0500484}
485
Jes Sorensen3cdf2772014-06-09 15:16:03 +0200486int WMM_param_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500487{
488 /* struct registry_priv *pregpriv = &padapter->registrypriv; */
489 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200490 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500491 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
492
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200493 if (pmlmepriv->qos_option == 0) {
Larry Finger5e93f352014-03-28 21:37:38 -0500494 pmlmeinfo->WMM_enable = 0;
495 return _FAIL;
496 }
497
498 pmlmeinfo->WMM_enable = 1;
Jes Sorensenb171da32014-05-21 09:37:42 +0200499 memcpy(&pmlmeinfo->WMM_param, p + 2 + 6,
Larry Finger5e93f352014-03-28 21:37:38 -0500500 sizeof(struct WMM_para_element));
501 return true;
502}
503
504void WMMOnAssocRsp23a(struct rtw_adapter *padapter)
505{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200506 u8 ACI, ACM, AIFS, ECWMin, ECWMax, aSifsTime;
507 u8 acm_mask;
508 u16 TXOP;
509 u32 acParm, i;
510 u32 edca[4], inx[4];
511 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500512 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200513 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
514 struct registry_priv *pregpriv = &padapter->registrypriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500515
516 if (pmlmeinfo->WMM_enable == 0) {
517 padapter->mlmepriv.acm_mask = 0;
518 return;
519 }
520
521 acm_mask = 0;
522
523 if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
524 aSifsTime = 10;
525 else
526 aSifsTime = 16;
527
528 for (i = 0; i < 4; i++) {
529 ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
530 ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
531
532 /* AIFS = AIFSN * slot time + SIFS - r2t phy delay */
Jes Sorensenc227ed02014-05-09 15:03:27 +0200533 AIFS = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN & 0x0f) *
534 pmlmeinfo->slotTime + aSifsTime;
Larry Finger5e93f352014-03-28 21:37:38 -0500535
Jes Sorensenc227ed02014-05-09 15:03:27 +0200536 ECWMin = pmlmeinfo->WMM_param.ac_param[i].CW & 0x0f;
Larry Finger5e93f352014-03-28 21:37:38 -0500537 ECWMax = (pmlmeinfo->WMM_param.ac_param[i].CW & 0xf0) >> 4;
538 TXOP = le16_to_cpu(pmlmeinfo->WMM_param.ac_param[i].TXOP_limit);
539
540 acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
541
542 switch (ACI) {
543 case 0x0:
Jes Sorensen2487205e2014-04-09 23:20:30 +0200544 rtl8723a_set_ac_param_be(padapter, acParm);
Larry Finger5e93f352014-03-28 21:37:38 -0500545 acm_mask |= (ACM? BIT(1):0);
546 edca[XMIT_BE_QUEUE] = acParm;
547 break;
548 case 0x1:
Jes Sorensen2487205e2014-04-09 23:20:30 +0200549 rtl8723a_set_ac_param_bk(padapter, acParm);
Larry Finger5e93f352014-03-28 21:37:38 -0500550 /* acm_mask |= (ACM? BIT(0):0); */
551 edca[XMIT_BK_QUEUE] = acParm;
552 break;
553 case 0x2:
Jes Sorensen2487205e2014-04-09 23:20:30 +0200554 rtl8723a_set_ac_param_vi(padapter, acParm);
Larry Finger5e93f352014-03-28 21:37:38 -0500555 acm_mask |= (ACM? BIT(2):0);
556 edca[XMIT_VI_QUEUE] = acParm;
557 break;
558 case 0x3:
Jes Sorensen2487205e2014-04-09 23:20:30 +0200559 rtl8723a_set_ac_param_vo(padapter, acParm);
Larry Finger5e93f352014-03-28 21:37:38 -0500560 acm_mask |= (ACM? BIT(3):0);
561 edca[XMIT_VO_QUEUE] = acParm;
562 break;
563 }
564
565 DBG_8723A("WMM(%x): %x, %x\n", ACI, ACM, acParm);
566 }
567
568 if (padapter->registrypriv.acm_method == 1)
Jes Sorensend5cdb9e2014-04-09 23:20:31 +0200569 rtl8723a_set_acm_ctrl(padapter, acm_mask);
Larry Finger5e93f352014-03-28 21:37:38 -0500570 else
571 padapter->mlmepriv.acm_mask = acm_mask;
572
573 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
574
575 if (pregpriv->wifi_spec == 1) {
Jes Sorensenc227ed02014-05-09 15:03:27 +0200576 u32 j, tmp, change_inx = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500577
578 /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */
579 for (i = 0; i < 4; i++) {
580 for (j = i+1; j < 4; j++) {
581 /* compare CW and AIFS */
582 if ((edca[j] & 0xFFFF) < (edca[i] & 0xFFFF)) {
583 change_inx = true;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200584 } else if ((edca[j] & 0xFFFF) ==
585 (edca[i] & 0xFFFF)) {
Larry Finger5e93f352014-03-28 21:37:38 -0500586 /* compare TXOP */
587 if ((edca[j] >> 16) > (edca[i] >> 16))
588 change_inx = true;
589 }
590
591 if (change_inx) {
592 tmp = edca[i];
593 edca[i] = edca[j];
594 edca[j] = tmp;
595
596 tmp = inx[i];
597 inx[i] = inx[j];
598 inx[j] = tmp;
599
600 change_inx = false;
601 }
602 }
603 }
604 }
605
606 for (i = 0; i<4; i++) {
607 pxmitpriv->wmm_para_seq[i] = inx[i];
Jes Sorensenc227ed02014-05-09 15:03:27 +0200608 DBG_8723A("wmm_para_seq(%d): %d\n", i,
609 pxmitpriv->wmm_para_seq[i]);
Larry Finger5e93f352014-03-28 21:37:38 -0500610 }
Larry Finger5e93f352014-03-28 21:37:38 -0500611}
612
Jes Sorensen7882ef42014-05-31 18:05:17 +0200613static void bwmode_update_check(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500614{
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200615 struct ieee80211_ht_operation *pHT_info;
Larry Finger5e93f352014-03-28 21:37:38 -0500616 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200617 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500618 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
619 struct registry_priv *pregistrypriv = &padapter->registrypriv;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200620 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
621 unsigned char new_bwmode;
622 unsigned char new_ch_offset;
Larry Finger5e93f352014-03-28 21:37:38 -0500623
Jes Sorensenb171da32014-05-21 09:37:42 +0200624 if (!p)
Larry Finger5e93f352014-03-28 21:37:38 -0500625 return;
626 if (!phtpriv->ht_option)
627 return;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200628 if (p[1] != sizeof(struct ieee80211_ht_operation))
Larry Finger5e93f352014-03-28 21:37:38 -0500629 return;
630
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200631 pHT_info = (struct ieee80211_ht_operation *)(p + 2);
Larry Finger5e93f352014-03-28 21:37:38 -0500632
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200633 if ((pHT_info->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) &&
634 pregistrypriv->cbw40_enable) {
Larry Finger5e93f352014-03-28 21:37:38 -0500635 new_bwmode = HT_CHANNEL_WIDTH_40;
636
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200637 switch (pHT_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET){
638 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Larry Finger5e93f352014-03-28 21:37:38 -0500639 new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
640 break;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200641 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Larry Finger5e93f352014-03-28 21:37:38 -0500642 new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
643 break;
644 default:
645 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
646 break;
647 }
648 } else {
649 new_bwmode = HT_CHANNEL_WIDTH_20;
650 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
651 }
652
Jes Sorensenc227ed02014-05-09 15:03:27 +0200653 if (new_bwmode != pmlmeext->cur_bwmode ||
654 new_ch_offset != pmlmeext->cur_ch_offset) {
Larry Finger5e93f352014-03-28 21:37:38 -0500655 pmlmeinfo->bwmode_updated = true;
656
657 pmlmeext->cur_bwmode = new_bwmode;
658 pmlmeext->cur_ch_offset = new_ch_offset;
659
660 /* update HT info also */
Jes Sorensenb171da32014-05-21 09:37:42 +0200661 HT_info_handler23a(padapter, p);
Jes Sorensenc227ed02014-05-09 15:03:27 +0200662 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500663 pmlmeinfo->bwmode_updated = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500664
665 if (pmlmeinfo->bwmode_updated) {
666 struct sta_info *psta;
667 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
668 struct sta_priv *pstapriv = &padapter->stapriv;
669
Jes Sorensenc227ed02014-05-09 15:03:27 +0200670 /* set_channel_bwmode23a(padapter, pmlmeext->cur_channel,
671 pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
Larry Finger5e93f352014-03-28 21:37:38 -0500672
673 /* update ap's stainfo */
674 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
675 if (psta) {
Jes Sorensenc227ed02014-05-09 15:03:27 +0200676 struct ht_priv *phtpriv_sta = &psta->htpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500677
678 if (phtpriv_sta->ht_option) {
679 /* bwmode */
680 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200681 phtpriv_sta->ch_offset =
682 pmlmeext->cur_ch_offset;
Larry Finger5e93f352014-03-28 21:37:38 -0500683 } else {
684 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200685 phtpriv_sta->ch_offset =
686 HAL_PRIME_CHNL_OFFSET_DONT_CARE;
Larry Finger5e93f352014-03-28 21:37:38 -0500687 }
Larry Finger5e93f352014-03-28 21:37:38 -0500688 }
689 }
690}
691
Jes Sorensen3cdf2772014-06-09 15:16:03 +0200692void HT_caps_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500693{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200694 unsigned int i;
695 u8 rf_type;
696 u8 max_AMPDU_len, min_MPDU_spacing;
697 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500698 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200699 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
700 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
Jes Sorensen65be27d2014-05-31 18:05:11 +0200701 struct ieee80211_ht_cap *cap;
702 u8 *dstcap;
Larry Finger5e93f352014-03-28 21:37:38 -0500703
Jes Sorensenb171da32014-05-21 09:37:42 +0200704 if (!p)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200705 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500706
Jes Sorensen6a5f6572014-06-09 15:16:07 +0200707 if (!phtpriv->ht_option)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200708 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500709
710 pmlmeinfo->HT_caps_enable = 1;
711
Jes Sorensen65be27d2014-05-31 18:05:11 +0200712 cap = &pmlmeinfo->ht_cap;
713 dstcap = (u8 *)cap;
Jes Sorensenb171da32014-05-21 09:37:42 +0200714 for (i = 0; i < p[1]; i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500715 if (i != 2) {
Jes Sorensen65be27d2014-05-31 18:05:11 +0200716 dstcap[i] &= p[i + 2];
Larry Finger5e93f352014-03-28 21:37:38 -0500717 } else {
718 /* modify from fw by Thomas 2010/11/17 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200719 if ((cap->ampdu_params_info &
720 IEEE80211_HT_AMPDU_PARM_FACTOR) >
721 (p[i + 2] & IEEE80211_HT_AMPDU_PARM_FACTOR))
722 max_AMPDU_len = p[i + 2] &
723 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500724 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200725 max_AMPDU_len = cap->ampdu_params_info &
726 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500727
Jes Sorensen65be27d2014-05-31 18:05:11 +0200728 if ((cap->ampdu_params_info &
729 IEEE80211_HT_AMPDU_PARM_DENSITY) >
730 (p[i + 2] & IEEE80211_HT_AMPDU_PARM_DENSITY))
731 min_MPDU_spacing = cap->ampdu_params_info &
732 IEEE80211_HT_AMPDU_PARM_DENSITY;
Larry Finger5e93f352014-03-28 21:37:38 -0500733 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200734 min_MPDU_spacing = p[i + 2] &
735 IEEE80211_HT_AMPDU_PARM_DENSITY;
Larry Finger5e93f352014-03-28 21:37:38 -0500736
Jes Sorensen65be27d2014-05-31 18:05:11 +0200737 cap->ampdu_params_info =
Jes Sorensenb171da32014-05-21 09:37:42 +0200738 max_AMPDU_len | min_MPDU_spacing;
Larry Finger5e93f352014-03-28 21:37:38 -0500739 }
740 }
741
Jes Sorensenc2370e82014-04-09 23:20:53 +0200742 rf_type = rtl8723a_get_rf_type(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500743
744 /* update the MCS rates */
Jes Sorensen198e95d2014-05-31 18:05:10 +0200745 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Jes Sorensenc227ed02014-05-09 15:03:27 +0200746 if (rf_type == RF_1T1R || rf_type == RF_1T2R)
Jes Sorensen65be27d2014-05-31 18:05:11 +0200747 cap->mcs.rx_mask[i] &= MCS_rate_1R23A[i];
Larry Finger5e93f352014-03-28 21:37:38 -0500748 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200749 cap->mcs.rx_mask[i] &= MCS_rate_2R23A[i];
Larry Finger5e93f352014-03-28 21:37:38 -0500750 }
Larry Finger5e93f352014-03-28 21:37:38 -0500751}
752
Jes Sorensen7882ef42014-05-31 18:05:17 +0200753void HT_info_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500754{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200755 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500756 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200757 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
758 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500759
Jes Sorensenb171da32014-05-21 09:37:42 +0200760 if (!p)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200761 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500762
Jes Sorensen6a5f6572014-06-09 15:16:07 +0200763 if (!phtpriv->ht_option)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200764 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500765
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200766 if (p[1] != sizeof(struct ieee80211_ht_operation))
Larry Finger5e93f352014-03-28 21:37:38 -0500767 return;
768
769 pmlmeinfo->HT_info_enable = 1;
Jes Sorensenb171da32014-05-21 09:37:42 +0200770 memcpy(&pmlmeinfo->HT_info, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -0500771}
772
773void HTOnAssocRsp23a(struct rtw_adapter *padapter)
774{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200775 unsigned char max_AMPDU_len;
776 unsigned char min_MPDU_spacing;
Larry Finger5e93f352014-03-28 21:37:38 -0500777 /* struct registry_priv *pregpriv = &padapter->registrypriv; */
Jes Sorensenc227ed02014-05-09 15:03:27 +0200778 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500779 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
780
781 DBG_8723A("%s\n", __func__);
782
Jes Sorensenc227ed02014-05-09 15:03:27 +0200783 if (pmlmeinfo->HT_info_enable && pmlmeinfo->HT_caps_enable)
Larry Finger5e93f352014-03-28 21:37:38 -0500784 pmlmeinfo->HT_enable = 1;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200785 else {
Larry Finger5e93f352014-03-28 21:37:38 -0500786 pmlmeinfo->HT_enable = 0;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200787 /* set_channel_bwmode23a(padapter, pmlmeext->cur_channel,
788 pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
Larry Finger5e93f352014-03-28 21:37:38 -0500789 return;
790 }
791
792 /* handle A-MPDU parameter field */
793 /*
794 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
795 AMPDU_para [4:2]:Min MPDU Start Spacing
796 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200797 max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
798 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500799
Jes Sorensenc227ed02014-05-09 15:03:27 +0200800 min_MPDU_spacing =
Jes Sorensen65be27d2014-05-31 18:05:11 +0200801 (pmlmeinfo->ht_cap.ampdu_params_info &
802 IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500803
Jes Sorensendce610a2014-04-09 23:20:32 +0200804 rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
805 rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
Larry Finger5e93f352014-03-28 21:37:38 -0500806}
807
Jes Sorensen7882ef42014-05-31 18:05:17 +0200808void ERP_IE_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500809{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200810 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500811 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
812
Jes Sorensenb171da32014-05-21 09:37:42 +0200813 if (p[1] > 1)
Larry Finger5e93f352014-03-28 21:37:38 -0500814 return;
815
816 pmlmeinfo->ERP_enable = 1;
Jes Sorensenb171da32014-05-21 09:37:42 +0200817 memcpy(&pmlmeinfo->ERP_IE, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -0500818}
819
820void VCS_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
821{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200822 struct registry_priv *pregpriv = &padapter->registrypriv;
823 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500824 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
825
826 switch (pregpriv->vrtl_carrier_sense) { /* 0:off 1:on 2:auto */
827 case 0: /* off */
828 psta->rtsen = 0;
829 psta->cts2self = 0;
830 break;
831 case 1: /* on */
Jes Sorensen0ceb7b12014-10-10 21:41:28 +0200832 if (pregpriv->vcs_type == RTS_CTS) {
Larry Finger5e93f352014-03-28 21:37:38 -0500833 psta->rtsen = 1;
834 psta->cts2self = 0;
835 } else {
836 psta->rtsen = 0;
837 psta->cts2self = 1;
838 }
839 break;
840 case 2: /* auto */
841 default:
Jes Sorensenc227ed02014-05-09 15:03:27 +0200842 if (pmlmeinfo->ERP_enable && pmlmeinfo->ERP_IE & BIT(1)) {
Jes Sorensen0ceb7b12014-10-10 21:41:28 +0200843 if (pregpriv->vcs_type == RTS_CTS) {
Larry Finger5e93f352014-03-28 21:37:38 -0500844 psta->rtsen = 1;
845 psta->cts2self = 0;
846 } else {
847 psta->rtsen = 0;
848 psta->cts2self = 1;
849 }
850 } else {
851 psta->rtsen = 0;
852 psta->cts2self = 0;
853 }
854 break;
855 }
856}
857
Jes Sorensenc1465512014-04-15 19:43:58 +0200858int rtw_check_bcn_info23a(struct rtw_adapter *Adapter,
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200859 struct ieee80211_mgmt *mgmt, u32 pkt_len)
Larry Finger5e93f352014-03-28 21:37:38 -0500860{
Larry Finger5e93f352014-03-28 21:37:38 -0500861 struct wlan_network *cur_network = &Adapter->mlmepriv.cur_network;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200862 struct ieee80211_ht_operation *pht_info;
Jes Sorensenc3761832014-04-15 19:44:05 +0200863 unsigned short val16;
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200864 u8 crypto, bcn_channel;
Jes Sorensenc3761832014-04-15 19:44:05 +0200865 int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0, r;
Jes Sorensen68e6c792014-06-24 15:03:29 +0200866 int pie_len, ssid_len, privacy;
Jes Sorensen17b19392014-06-09 15:16:25 +0200867 const u8 *p, *ssid;
Larry Finger5e93f352014-03-28 21:37:38 -0500868
Roberta Dobrescu08551cb2014-10-26 23:30:05 +0200869 if (!is_client_associated_to_ap23a(Adapter))
Jes Sorensen17b19392014-06-09 15:16:25 +0200870 return _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500871
Jes Sorensenc1465512014-04-15 19:43:58 +0200872 if (unlikely(!ieee80211_is_beacon(mgmt->frame_control))) {
873 printk(KERN_WARNING "%s: received a non beacon frame!\n",
874 __func__);
Larry Finger5e93f352014-03-28 21:37:38 -0500875 return _FAIL;
876 }
877
Jes Sorensen0c45e612014-06-09 15:16:24 +0200878 if (!ether_addr_equal(cur_network->network.MacAddress, mgmt->bssid)) {
879 DBG_8723A("%s: linked but recv other bssid bcn"
880 MAC_FMT MAC_FMT "\n", __func__, MAC_ARG(mgmt->bssid),
Jes Sorensenc1465512014-04-15 19:43:58 +0200881 MAC_ARG(cur_network->network.MacAddress));
Jes Sorensen5bd28bc2014-04-26 18:54:49 +0200882 return _FAIL;
Jes Sorensen17b19392014-06-09 15:16:25 +0200883 }
Larry Finger5e93f352014-03-28 21:37:38 -0500884
885 /* check bw and channel offset */
886 /* parsing HT_CAP_IE */
Jes Sorensen17b19392014-06-09 15:16:25 +0200887 pie_len = pkt_len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200888
Larry Finger5e93f352014-03-28 21:37:38 -0500889 /* Checking for channel */
Jes Sorensen17b19392014-06-09 15:16:25 +0200890 p = cfg80211_find_ie(WLAN_EID_DS_PARAMS, mgmt->u.beacon.variable,
891 pie_len);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200892 if (p)
893 bcn_channel = p[2];
894 else {
895 /* In 5G, some ap do not have DSSET IE checking HT
896 info for channel */
Jes Sorensen17b19392014-06-09 15:16:25 +0200897 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION,
898 mgmt->u.beacon.variable, pie_len);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200899
Jes Sorensened08b4d2014-05-31 18:05:14 +0200900 if (p && p[1] > 0) {
901 pht_info = (struct ieee80211_ht_operation *)(p + 2);
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200902 bcn_channel = pht_info->primary_chan;
Jes Sorensened08b4d2014-05-31 18:05:14 +0200903 } else { /* we don't find channel IE, so don't check it */
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200904 DBG_8723A("Oops: %s we don't find channel IE, so don't "
905 "check it\n", __func__);
906 bcn_channel = Adapter->mlmeextpriv.cur_channel;
907 }
Larry Finger5e93f352014-03-28 21:37:38 -0500908 }
909 if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200910 DBG_8723A("%s beacon channel:%d cur channel:%d disconnect\n",
911 __func__, bcn_channel,
912 Adapter->mlmeextpriv.cur_channel);
913 goto _mismatch;
Larry Finger5e93f352014-03-28 21:37:38 -0500914 }
915
916 /* checking SSID */
Jes Sorensen17b19392014-06-09 15:16:25 +0200917 p = cfg80211_find_ie(WLAN_EID_SSID, mgmt->u.beacon.variable, pie_len);
Jes Sorensen82695d52014-04-15 19:44:00 +0200918 if (p && p[1]) {
Jes Sorensen17b19392014-06-09 15:16:25 +0200919 ssid = p + 2;
920 ssid_len = p[1];
Jes Sorensen82695d52014-04-15 19:44:00 +0200921 } else {
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200922 DBG_8723A("%s marc: cannot find SSID for survey event\n",
923 __func__);
Jes Sorensen17b19392014-06-09 15:16:25 +0200924 ssid = NULL;
925 ssid_len = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500926 }
927
928 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
929 ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
930 "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__,
Jes Sorensen17b19392014-06-09 15:16:25 +0200931 ssid, ssid_len, cur_network->network.Ssid.ssid,
Larry Finger5e93f352014-03-28 21:37:38 -0500932 cur_network->network.Ssid.ssid_len));
933
Jes Sorensen17b19392014-06-09 15:16:25 +0200934 if (ssid_len != cur_network->network.Ssid.ssid_len || ssid_len > 32 ||
935 (ssid_len &&
936 memcmp(ssid, cur_network->network.Ssid.ssid, ssid_len))) {
937 DBG_8723A("%s(), SSID is not match return FAIL\n", __func__);
938 goto _mismatch;
Larry Finger5e93f352014-03-28 21:37:38 -0500939 }
940
941 /* check encryption info */
Jes Sorensen17b19392014-06-09 15:16:25 +0200942 val16 = le16_to_cpu(mgmt->u.beacon.capab_info);
Larry Finger5e93f352014-03-28 21:37:38 -0500943
Jes Sorensena665bcc2014-05-31 18:05:15 +0200944 if (val16 & WLAN_CAPABILITY_PRIVACY)
Jes Sorensen17b19392014-06-09 15:16:25 +0200945 privacy = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500946 else
Jes Sorensen17b19392014-06-09 15:16:25 +0200947 privacy = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500948
949 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
Jes Sorensenc3761832014-04-15 19:44:05 +0200950 ("%s(): cur_network->network.Privacy is %d, bssid.Privacy "
Jes Sorensen17b19392014-06-09 15:16:25 +0200951 "is %d\n", __func__, cur_network->network.Privacy, privacy));
952 if (cur_network->network.Privacy != privacy) {
Larry Finger5e93f352014-03-28 21:37:38 -0500953 DBG_8723A("%s(), privacy is not match return FAIL\n", __func__);
954 goto _mismatch;
955 }
956
Jes Sorensen17b19392014-06-09 15:16:25 +0200957 p = cfg80211_find_ie(WLAN_EID_RSN, mgmt->u.beacon.variable, pie_len);
Jes Sorensen77953ed2014-06-09 15:16:00 +0200958 if (p && p[1]) {
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200959 crypto = ENCRYP_PROTOCOL_WPA2;
960 if (p && p[1]) {
961 r = rtw_parse_wpa2_ie23a(p, p[1] + 2, &group_cipher,
962 &pairwise_cipher, &is_8021x);
963 if (r == _SUCCESS)
964 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
965 ("%s pnetwork->pairwise_cipher: %d, "
966 "pnetwork->group_cipher: %d, is_802x "
967 ": %d\n", __func__, pairwise_cipher,
968 group_cipher, is_8021x));
969 }
Jes Sorensen77953ed2014-06-09 15:16:00 +0200970 } else {
Jes Sorensenf88ca602014-04-15 19:44:06 +0200971 p = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
972 WLAN_OUI_TYPE_MICROSOFT_WPA,
Jes Sorensen17b19392014-06-09 15:16:25 +0200973 mgmt->u.beacon.variable, pie_len);
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200974 if (p && p[1]) {
975 crypto = ENCRYP_PROTOCOL_WPA;
Jes Sorensenf88ca602014-04-15 19:44:06 +0200976 r = rtw_parse_wpa_ie23a(p, p[1] + 2, &group_cipher,
Jes Sorensenc3761832014-04-15 19:44:05 +0200977 &pairwise_cipher, &is_8021x);
978 if (r == _SUCCESS)
Larry Finger5e93f352014-03-28 21:37:38 -0500979 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
Jes Sorensenc3761832014-04-15 19:44:05 +0200980 ("%s pnetwork->pairwise_cipher: %d, "
981 "group_cipher is %d, is_8021x is "
982 "%d\n", __func__, pairwise_cipher,
983 group_cipher, is_8021x));
Larry Finger5e93f352014-03-28 21:37:38 -0500984 } else {
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200985 if (privacy)
986 crypto = ENCRYP_PROTOCOL_WEP;
987 else
988 crypto = ENCRYP_PROTOCOL_OPENSYS;
Larry Finger5e93f352014-03-28 21:37:38 -0500989 }
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200990 }
Larry Finger5e93f352014-03-28 21:37:38 -0500991
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200992 if (cur_network->BcnInfo.encryp_protocol != crypto) {
993 DBG_8723A("%s(): encryption mismatch, return FAIL\n", __func__);
994 goto _mismatch;
995 }
996
997 if (crypto == ENCRYP_PROTOCOL_WPA || crypto == ENCRYP_PROTOCOL_WPA2) {
Larry Finger5e93f352014-03-28 21:37:38 -0500998 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
Jes Sorensenc3761832014-04-15 19:44:05 +0200999 ("%s cur_network->group_cipher is %d: %d\n", __func__,
1000 cur_network->BcnInfo.group_cipher, group_cipher));
1001 if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher ||
1002 group_cipher != cur_network->BcnInfo.group_cipher) {
1003 DBG_8723A("%s pairwise_cipher(%x:%x) or group_cipher "
1004 "(%x:%x) is not match, return FAIL\n",
1005 __func__, pairwise_cipher,
1006 cur_network->BcnInfo.pairwise_cipher,
1007 group_cipher,
1008 cur_network->BcnInfo.group_cipher);
Larry Finger5e93f352014-03-28 21:37:38 -05001009 goto _mismatch;
1010 }
1011
1012 if (is_8021x != cur_network->BcnInfo.is_8021x) {
Jes Sorensenc3761832014-04-15 19:44:05 +02001013 DBG_8723A("%s authentication is not match, return "
1014 "FAIL\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -05001015 goto _mismatch;
1016 }
1017 }
1018
Larry Finger5e93f352014-03-28 21:37:38 -05001019 return _SUCCESS;
1020
1021_mismatch:
Larry Finger5e93f352014-03-28 21:37:38 -05001022
1023 return _FAIL;
1024}
1025
Jes Sorensen7882ef42014-05-31 18:05:17 +02001026void update_beacon23a_info(struct rtw_adapter *padapter,
1027 struct ieee80211_mgmt *mgmt,
Jes Sorensenb171da32014-05-21 09:37:42 +02001028 uint pkt_len, struct sta_info *psta)
Larry Finger5e93f352014-03-28 21:37:38 -05001029{
Larry Finger5e93f352014-03-28 21:37:38 -05001030 unsigned int len;
Jes Sorensen7882ef42014-05-31 18:05:17 +02001031 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001032
Jes Sorensen7882ef42014-05-31 18:05:17 +02001033 len = pkt_len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
Larry Finger5e93f352014-03-28 21:37:38 -05001034
Jes Sorensen7882ef42014-05-31 18:05:17 +02001035 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION, mgmt->u.beacon.variable,
1036 len);
1037 if (p)
1038 bwmode_update_check(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -05001039
Jes Sorensen7882ef42014-05-31 18:05:17 +02001040 p = cfg80211_find_ie(WLAN_EID_ERP_INFO, mgmt->u.beacon.variable, len);
1041 if (p) {
1042 ERP_IE_handler23a(padapter, p);
1043 VCS_update23a(padapter, psta);
Larry Finger5e93f352014-03-28 21:37:38 -05001044 }
1045}
1046
Jes Sorensend5789242014-05-16 10:04:35 +02001047bool is_ap_in_tkip23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001048{
1049 u32 i;
Larry Finger5e93f352014-03-28 21:37:38 -05001050 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1051 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1052 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001053 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001054
Jes Sorensena94e12b2014-06-19 11:37:34 +02001055 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001056 for (i = 0; i < pmlmeinfo->network.IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001057 p = pmlmeinfo->network.IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001058
Jes Sorensenb171da32014-05-21 09:37:42 +02001059 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001060 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001061 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4) &&
1062 !memcmp(p + 2 + 12, WPA_TKIP_CIPHER, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001063 return true;
1064 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001065 case WLAN_EID_RSN:
Jes Sorensenb171da32014-05-21 09:37:42 +02001066 if (!memcmp(p + 2 + 8, RSN_TKIP_CIPHER, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001067 return true;
1068 break;
1069 default:
1070 break;
1071 }
Jes Sorensenb171da32014-05-21 09:37:42 +02001072 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001073 }
1074 return false;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001075 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001076 return false;
Larry Finger5e93f352014-03-28 21:37:38 -05001077}
1078
Greg Donald8e3d1612014-10-02 18:28:41 -05001079bool should_forbid_n_rate23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001080{
1081 u32 i;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001082 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001083 struct wlan_bssid_ex *cur_network = &pmlmepriv->cur_network.network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001084 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001085
Jes Sorensena94e12b2014-06-19 11:37:34 +02001086 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001087 for (i = 0; i < cur_network->IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001088 p = cur_network->IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001089
Jes Sorensenb171da32014-05-21 09:37:42 +02001090 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001091 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001092 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4) &&
1093 (!memcmp(p + 2 + 12,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001094 WPA_CIPHER_SUITE_CCMP23A, 4) ||
Jes Sorensenb171da32014-05-21 09:37:42 +02001095 !memcmp(p + 2 + 16,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001096 WPA_CIPHER_SUITE_CCMP23A, 4)))
Larry Finger5e93f352014-03-28 21:37:38 -05001097 return false;
1098 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001099 case WLAN_EID_RSN:
Jes Sorensenb171da32014-05-21 09:37:42 +02001100 if (!memcmp(p + 2 + 8,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001101 RSN_CIPHER_SUITE_CCMP23A, 4) ||
Jes Sorensenb171da32014-05-21 09:37:42 +02001102 !memcmp(p + 2 + 12,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001103 RSN_CIPHER_SUITE_CCMP23A, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001104 return false;
1105 default:
1106 break;
1107 }
1108
Jes Sorensenb171da32014-05-21 09:37:42 +02001109 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001110 }
1111 return true;
1112 } else {
1113 return false;
1114 }
1115}
1116
Jes Sorensend5789242014-05-16 10:04:35 +02001117bool is_ap_in_wep23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001118{
1119 u32 i;
Larry Finger5e93f352014-03-28 21:37:38 -05001120 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1121 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1122 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001123 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001124
Jes Sorensena94e12b2014-06-19 11:37:34 +02001125 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001126 for (i = 0; i < pmlmeinfo->network.IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001127 p = pmlmeinfo->network.IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001128
Jes Sorensenb171da32014-05-21 09:37:42 +02001129 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001130 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001131 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001132 return false;
1133 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001134 case WLAN_EID_RSN:
Larry Finger5e93f352014-03-28 21:37:38 -05001135 return false;
1136
1137 default:
1138 break;
1139 }
1140
Jes Sorensenb171da32014-05-21 09:37:42 +02001141 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001142 }
1143
1144 return true;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001145 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001146 return false;
Larry Finger5e93f352014-03-28 21:37:38 -05001147}
1148
Larry Fingerc0b99be2014-04-26 18:55:17 +02001149static int wifirate2_ratetbl_inx23a(unsigned char rate)
Larry Finger5e93f352014-03-28 21:37:38 -05001150{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001151 int inx = 0;
Yeliz Taneroglu547f9752014-10-09 01:22:17 +03001152
Larry Finger5e93f352014-03-28 21:37:38 -05001153 rate = rate & 0x7f;
1154
1155 switch (rate) {
1156 case 54*2:
1157 inx = 11;
1158 break;
1159 case 48*2:
1160 inx = 10;
1161 break;
1162 case 36*2:
1163 inx = 9;
1164 break;
1165 case 24*2:
1166 inx = 8;
1167 break;
1168 case 18*2:
1169 inx = 7;
1170 break;
1171 case 12*2:
1172 inx = 6;
1173 break;
1174 case 9*2:
1175 inx = 5;
1176 break;
1177 case 6*2:
1178 inx = 4;
1179 break;
1180 case 11*2:
1181 inx = 3;
1182 break;
1183 case 11:
1184 inx = 2;
1185 break;
1186 case 2*2:
1187 inx = 1;
1188 break;
1189 case 1*2:
1190 inx = 0;
1191 break;
1192 }
1193 return inx;
1194}
1195
1196unsigned int update_basic_rate23a(unsigned char *ptn, unsigned int ptn_sz)
1197{
1198 unsigned int i, num_of_rate;
1199 unsigned int mask = 0;
1200
1201 num_of_rate = (ptn_sz > NumRates)? NumRates: ptn_sz;
1202
1203 for (i = 0; i < num_of_rate; i++) {
1204 if ((*(ptn + i)) & 0x80)
1205 mask |= 0x1 << wifirate2_ratetbl_inx23a(*(ptn + i));
1206 }
1207 return mask;
1208}
1209
1210unsigned int update_supported_rate23a(unsigned char *ptn, unsigned int ptn_sz)
1211{
1212 unsigned int i, num_of_rate;
1213 unsigned int mask = 0;
1214
Jes Sorensenc227ed02014-05-09 15:03:27 +02001215 num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
Larry Finger5e93f352014-03-28 21:37:38 -05001216
1217 for (i = 0; i < num_of_rate; i++)
1218 mask |= 0x1 << wifirate2_ratetbl_inx23a(*(ptn + i));
1219 return mask;
1220}
1221
Jes Sorensen65be27d2014-05-31 18:05:11 +02001222unsigned int update_MSC_rate23a(struct ieee80211_ht_cap *pHT_caps)
Larry Finger5e93f352014-03-28 21:37:38 -05001223{
1224 unsigned int mask = 0;
1225
Jes Sorensen65be27d2014-05-31 18:05:11 +02001226 mask = pHT_caps->mcs.rx_mask[0] << 12 |
1227 pHT_caps->mcs.rx_mask[1] << 20;
Larry Finger5e93f352014-03-28 21:37:38 -05001228
1229 return mask;
1230}
1231
1232int support_short_GI23a(struct rtw_adapter *padapter,
Jes Sorensen65be27d2014-05-31 18:05:11 +02001233 struct ieee80211_ht_cap *pHT_caps)
Larry Finger5e93f352014-03-28 21:37:38 -05001234{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001235 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001236 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1237 unsigned char bit_offset;
1238
Jes Sorensenc227ed02014-05-09 15:03:27 +02001239 if (!pmlmeinfo->HT_enable)
Larry Finger5e93f352014-03-28 21:37:38 -05001240 return _FAIL;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001241 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_RALINK)
Larry Finger5e93f352014-03-28 21:37:38 -05001242 return _FAIL;
1243 bit_offset = (pmlmeext->cur_bwmode & HT_CHANNEL_WIDTH_40)? 6: 5;
1244
Jes Sorensen65be27d2014-05-31 18:05:11 +02001245 if (pHT_caps->cap_info & cpu_to_le16(0x1 << bit_offset))
Larry Finger5e93f352014-03-28 21:37:38 -05001246 return _SUCCESS;
1247 else
1248 return _FAIL;
1249}
1250
1251unsigned char get_highest_rate_idx23a(u32 mask)
1252{
1253 int i;
1254 unsigned char rate_idx = 0;
1255
1256 for (i = 27; i >= 0; i--) {
1257 if (mask & BIT(i)) {
1258 rate_idx = i;
1259 break;
1260 }
1261 }
1262 return rate_idx;
1263}
1264
Larry Finger5e93f352014-03-28 21:37:38 -05001265void Update_RA_Entry23a(struct rtw_adapter *padapter, struct sta_info *psta)
1266{
1267 rtw_hal_update_ra_mask23a(psta, 0);
1268}
1269
Larry Fingerc0b99be2014-04-26 18:55:17 +02001270static void enable_rate_adaptive(struct rtw_adapter *padapter,
1271 struct sta_info *psta)
Larry Finger5e93f352014-03-28 21:37:38 -05001272{
1273 Update_RA_Entry23a(padapter, psta);
1274}
1275
1276void set_sta_rate23a(struct rtw_adapter *padapter, struct sta_info *psta)
1277{
1278 /* rate adaptive */
1279 enable_rate_adaptive(padapter, psta);
1280}
1281
1282/* Update RRSR and Rate for USERATE */
1283void update_tx_basic_rate23a(struct rtw_adapter *padapter, u8 wirelessmode)
1284{
1285 unsigned char supported_rates[NDIS_802_11_LENGTH_RATES_EX];
Larry Finger5e93f352014-03-28 21:37:38 -05001286
1287 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
1288
Jes Sorensenff516e72014-05-09 15:03:28 +02001289 if (wirelessmode == WIRELESS_11B) {
Larry Finger5e93f352014-03-28 21:37:38 -05001290 memcpy(supported_rates, rtw_basic_rate_cck, 4);
1291 } else if (wirelessmode & WIRELESS_11B) {
1292 memcpy(supported_rates, rtw_basic_rate_mix, 7);
1293 } else {
1294 memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
1295 }
1296
1297 if (wirelessmode & WIRELESS_11B)
1298 update_mgnt_tx_rate23a(padapter, IEEE80211_CCK_RATE_1MB);
1299 else
1300 update_mgnt_tx_rate23a(padapter, IEEE80211_OFDM_RATE_6MB);
1301
Jes Sorensenfa2e5202014-04-09 23:20:18 +02001302 HalSetBrateCfg23a(padapter, supported_rates);
Larry Finger5e93f352014-03-28 21:37:38 -05001303}
1304
1305unsigned char check_assoc_AP23a(u8 *pframe, uint len)
1306{
Jes Sorensen68e6c792014-06-24 15:03:29 +02001307 int i;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001308 u8 epigram_vendor_flag;
1309 u8 ralink_vendor_flag;
Jes Sorensenb171da32014-05-21 09:37:42 +02001310 const u8 *p;
Yeliz Taneroglu547f9752014-10-09 01:22:17 +03001311
Larry Finger5e93f352014-03-28 21:37:38 -05001312 epigram_vendor_flag = 0;
1313 ralink_vendor_flag = 0;
1314
Jes Sorensen68e6c792014-06-24 15:03:29 +02001315 for (i = 0; i < len;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001316 p = pframe + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001317
Jes Sorensenb171da32014-05-21 09:37:42 +02001318 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001319 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001320 if (!memcmp(p + 2, ARTHEROS_OUI1, 3) ||
1321 !memcmp(p + 2, ARTHEROS_OUI2, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001322 DBG_8723A("link to Artheros AP\n");
1323 return HT_IOT_PEER_ATHEROS;
Jes Sorensenb171da32014-05-21 09:37:42 +02001324 } else if (!memcmp(p + 2, BROADCOM_OUI1, 3) ||
Jes Sorensenb171da32014-05-21 09:37:42 +02001325 !memcmp(p + 2, BROADCOM_OUI2, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001326 DBG_8723A("link to Broadcom AP\n");
1327 return HT_IOT_PEER_BROADCOM;
Jes Sorensenb171da32014-05-21 09:37:42 +02001328 } else if (!memcmp(p + 2, MARVELL_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001329 DBG_8723A("link to Marvell AP\n");
1330 return HT_IOT_PEER_MARVELL;
Jes Sorensenb171da32014-05-21 09:37:42 +02001331 } else if (!memcmp(p + 2, RALINK_OUI, 3)) {
Jes Sorensenc227ed02014-05-09 15:03:27 +02001332 if (!ralink_vendor_flag)
Larry Finger5e93f352014-03-28 21:37:38 -05001333 ralink_vendor_flag = 1;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001334 else {
Larry Finger5e93f352014-03-28 21:37:38 -05001335 DBG_8723A("link to Ralink AP\n");
1336 return HT_IOT_PEER_RALINK;
1337 }
Jes Sorensenb171da32014-05-21 09:37:42 +02001338 } else if (!memcmp(p + 2, CISCO_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001339 DBG_8723A("link to Cisco AP\n");
1340 return HT_IOT_PEER_CISCO;
Jes Sorensenb171da32014-05-21 09:37:42 +02001341 } else if (!memcmp(p + 2, REALTEK_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001342 DBG_8723A("link to Realtek 96B\n");
1343 return HT_IOT_PEER_REALTEK;
Jes Sorensenb171da32014-05-21 09:37:42 +02001344 } else if (!memcmp(p + 2, AIRGOCAP_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001345 DBG_8723A("link to Airgo Cap\n");
1346 return HT_IOT_PEER_AIRGO;
Jes Sorensenb171da32014-05-21 09:37:42 +02001347 } else if (!memcmp(p + 2, EPIGRAM_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001348 epigram_vendor_flag = 1;
1349 if (ralink_vendor_flag) {
1350 DBG_8723A("link to Tenda W311R AP\n");
1351 return HT_IOT_PEER_TENDA;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001352 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001353 DBG_8723A("Capture EPIGRAM_OUI\n");
Jes Sorensenc227ed02014-05-09 15:03:27 +02001354 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001355 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001356 default:
1357 break;
1358 }
1359
Jes Sorensenb171da32014-05-21 09:37:42 +02001360 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001361 }
1362
1363 if (ralink_vendor_flag && !epigram_vendor_flag) {
1364 DBG_8723A("link to Ralink AP\n");
1365 return HT_IOT_PEER_RALINK;
1366 } else if (ralink_vendor_flag && epigram_vendor_flag) {
1367 DBG_8723A("link to Tenda W311R AP\n");
1368 return HT_IOT_PEER_TENDA;
1369 } else {
1370 DBG_8723A("link to new AP\n");
1371 return HT_IOT_PEER_UNKNOWN;
1372 }
1373}
1374
1375void update_IOT_info23a(struct rtw_adapter *padapter)
1376{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001377 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001378 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1379
1380 switch (pmlmeinfo->assoc_AP_vendor) {
1381 case HT_IOT_PEER_MARVELL:
1382 pmlmeinfo->turboMode_cts2self = 1;
1383 pmlmeinfo->turboMode_rtsen = 0;
1384 break;
1385 case HT_IOT_PEER_RALINK:
1386 pmlmeinfo->turboMode_cts2self = 0;
1387 pmlmeinfo->turboMode_rtsen = 1;
1388 /* disable high power */
Jes Sorensen585eefb2014-04-09 23:20:43 +02001389 rtl8723a_odm_support_ability_clr(padapter, (u32)
1390 ~DYNAMIC_BB_DYNAMIC_TXPWR);
Larry Finger5e93f352014-03-28 21:37:38 -05001391 break;
1392 case HT_IOT_PEER_REALTEK:
1393 /* rtw_write16(padapter, 0x4cc, 0xffff); */
1394 /* rtw_write16(padapter, 0x546, 0x01c0); */
1395 /* disable high power */
Jes Sorensen585eefb2014-04-09 23:20:43 +02001396 rtl8723a_odm_support_ability_clr(padapter, (u32)
1397 ~DYNAMIC_BB_DYNAMIC_TXPWR);
Larry Finger5e93f352014-03-28 21:37:38 -05001398 break;
1399 default:
1400 pmlmeinfo->turboMode_cts2self = 0;
1401 pmlmeinfo->turboMode_rtsen = 1;
1402 break;
1403 }
1404}
1405
1406void update_capinfo23a(struct rtw_adapter *Adapter, u16 updateCap)
1407{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001408 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001409 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Larry Finger5e93f352014-03-28 21:37:38 -05001410
1411 if (updateCap & cShortPreamble) {
1412 /* Short Preamble */
1413 if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) {
1414 /* PREAMBLE_LONG or PREAMBLE_AUTO */
Larry Finger5e93f352014-03-28 21:37:38 -05001415 pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
Jes Sorensen093dd412014-04-09 23:20:26 +02001416 rtl8723a_ack_preamble(Adapter, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001417 }
1418 } else { /* Long Preamble */
1419 if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) {
1420 /* PREAMBLE_SHORT or PREAMBLE_AUTO */
Larry Finger5e93f352014-03-28 21:37:38 -05001421 pmlmeinfo->preamble_mode = PREAMBLE_LONG;
Jes Sorensen093dd412014-04-09 23:20:26 +02001422 rtl8723a_ack_preamble(Adapter, false);
Larry Finger5e93f352014-03-28 21:37:38 -05001423 }
1424 }
1425 if (updateCap & cIBSS) {
1426 /* Filen: See 802.11-2007 p.91 */
1427 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1428 } else {
1429 /* Filen: See 802.11-2007 p.90 */
Jes Sorensenc227ed02014-05-09 15:03:27 +02001430 if (pmlmeext->cur_wireless_mode &
1431 (WIRELESS_11G | WIRELESS_11_24N)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001432 if (updateCap & cShortSlotTime) { /* Short Slot Time */
1433 if (pmlmeinfo->slotTime != SHORT_SLOT_TIME)
1434 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1435 } else { /* Long Slot Time */
1436 if (pmlmeinfo->slotTime != NON_SHORT_SLOT_TIME)
Jes Sorensenc227ed02014-05-09 15:03:27 +02001437 pmlmeinfo->slotTime =
1438 NON_SHORT_SLOT_TIME;
Larry Finger5e93f352014-03-28 21:37:38 -05001439 }
Jes Sorensenc227ed02014-05-09 15:03:27 +02001440 } else if (pmlmeext->cur_wireless_mode &
1441 (WIRELESS_11A | WIRELESS_11_5N)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001442 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1443 } else {
1444 /* B Mode */
1445 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1446 }
1447 }
Jes Sorensen04c38422014-04-09 23:20:24 +02001448 rtl8723a_set_slot_time(Adapter, pmlmeinfo->slotTime);
Larry Finger5e93f352014-03-28 21:37:38 -05001449}
1450
1451void update_wireless_mode23a(struct rtw_adapter *padapter)
1452{
1453 int ratelen, network_type = 0;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001454 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001455 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1456 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001457 unsigned char *rate = cur_network->SupportedRates;
Larry Finger5e93f352014-03-28 21:37:38 -05001458
1459 ratelen = rtw_get_rateset_len23a(cur_network->SupportedRates);
1460
1461 if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
1462 pmlmeinfo->HT_enable = 1;
1463
1464 if (pmlmeext->cur_channel > 14) {
1465 if (pmlmeinfo->HT_enable)
1466 network_type = WIRELESS_11_5N;
1467 network_type |= WIRELESS_11A;
1468 } else {
1469 if (pmlmeinfo->HT_enable)
1470 network_type = WIRELESS_11_24N;
1471
Jes Sorensenc227ed02014-05-09 15:03:27 +02001472 if (cckratesonly_included23a(rate, ratelen) == true)
Larry Finger5e93f352014-03-28 21:37:38 -05001473 network_type |= WIRELESS_11B;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001474 else if (cckrates_included23a(rate, ratelen) == true)
Larry Finger5e93f352014-03-28 21:37:38 -05001475 network_type |= WIRELESS_11BG;
1476 else
1477 network_type |= WIRELESS_11G;
1478 }
1479
Jes Sorensenc227ed02014-05-09 15:03:27 +02001480 pmlmeext->cur_wireless_mode =
1481 network_type & padapter->registrypriv.wireless_mode;
Larry Finger5e93f352014-03-28 21:37:38 -05001482
Jes Sorensen7b7aefa2014-04-09 23:20:25 +02001483 /* 0x0808 -> for CCK, 0x0a0a -> for OFDM */
1484 /* change this value if having IOT issues. */
1485 rtl8723a_set_resp_sifs(padapter, 0x08, 0x08, 0x0a, 0x0a);
Larry Finger5e93f352014-03-28 21:37:38 -05001486
1487 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1488 update_mgnt_tx_rate23a(padapter, IEEE80211_CCK_RATE_1MB);
1489 else
1490 update_mgnt_tx_rate23a(padapter, IEEE80211_OFDM_RATE_6MB);
1491}
1492
1493void update_bmc_sta_support_rate23a(struct rtw_adapter *padapter, u32 mac_id)
1494{
1495 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1496 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1497
1498 if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
1499 /* Only B, B/G, and B/G/N AP could use CCK rate */
Jes Sorensen5bd28bc2014-04-26 18:54:49 +02001500 memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates),
1501 rtw_basic_rate_cck, 4);
Larry Finger5e93f352014-03-28 21:37:38 -05001502 } else {
Jes Sorensenc227ed02014-05-09 15:03:27 +02001503 memcpy(pmlmeinfo->FW_sta_info[mac_id].SupportedRates,
Jes Sorensen5bd28bc2014-04-26 18:54:49 +02001504 rtw_basic_rate_ofdm, 3);
Larry Finger5e93f352014-03-28 21:37:38 -05001505 }
1506}
1507
Jes Sorensenbf350272014-04-15 19:44:01 +02001508int update_sta_support_rate23a(struct rtw_adapter *padapter, u8 *pvar_ie,
1509 uint var_ie_len, int cam_idx)
Larry Finger5e93f352014-03-28 21:37:38 -05001510{
Jes Sorensenbf350272014-04-15 19:44:01 +02001511 int supportRateNum = 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001512 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1513 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenbf350272014-04-15 19:44:01 +02001514 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001515
Jes Sorensenbf350272014-04-15 19:44:01 +02001516 p = cfg80211_find_ie(WLAN_EID_SUPP_RATES, pvar_ie, var_ie_len);
1517 if (!p)
Larry Finger5e93f352014-03-28 21:37:38 -05001518 return _FAIL;
1519
Jes Sorensenbf350272014-04-15 19:44:01 +02001520 memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, p + 2, p[1]);
1521 supportRateNum = p[1];
Larry Finger5e93f352014-03-28 21:37:38 -05001522
Jes Sorensenbf350272014-04-15 19:44:01 +02001523 p = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, pvar_ie, var_ie_len);
1524 if (p)
1525 memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates +
1526 supportRateNum, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -05001527 return _SUCCESS;
1528}
1529
Jes Sorensenc227ed02014-05-09 15:03:27 +02001530void process_addba_req23a(struct rtw_adapter *padapter,
1531 u8 *paddba_req, u8 *addr)
Larry Finger5e93f352014-03-28 21:37:38 -05001532{
1533 struct sta_info *psta;
1534 u16 tid, start_seq, param;
1535 struct recv_reorder_ctrl *preorder_ctrl;
1536 struct sta_priv *pstapriv = &padapter->stapriv;
Greg Donald7e6646d2014-09-06 19:42:03 -05001537 struct ADDBA_request *preq = (struct ADDBA_request *)paddba_req;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001538 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001539 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1540
1541 psta = rtw_get_stainfo23a(pstapriv, addr);
1542
1543 if (psta) {
1544 start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
1545
1546 param = le16_to_cpu(preq->BA_para_set);
Jes Sorensenc227ed02014-05-09 15:03:27 +02001547 tid = (param >> 2) & 0x0f;
Larry Finger5e93f352014-03-28 21:37:38 -05001548
1549 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1550
1551 preorder_ctrl->indicate_seq = 0xffff;
1552
Jes Sorensenc227ed02014-05-09 15:03:27 +02001553 preorder_ctrl->enable = (pmlmeinfo->bAcceptAddbaReq == true) ?
1554 true : false;
Larry Finger5e93f352014-03-28 21:37:38 -05001555 }
1556}