blob: c0b0047a9d3a26697a21b77230b37aa035f4bc07 [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 }
611
612 return;
613}
614
Jes Sorensen7882ef42014-05-31 18:05:17 +0200615static void bwmode_update_check(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500616{
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200617 struct ieee80211_ht_operation *pHT_info;
Larry Finger5e93f352014-03-28 21:37:38 -0500618 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200619 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500620 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
621 struct registry_priv *pregistrypriv = &padapter->registrypriv;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200622 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
623 unsigned char new_bwmode;
624 unsigned char new_ch_offset;
Larry Finger5e93f352014-03-28 21:37:38 -0500625
Jes Sorensenb171da32014-05-21 09:37:42 +0200626 if (!p)
Larry Finger5e93f352014-03-28 21:37:38 -0500627 return;
628 if (!phtpriv->ht_option)
629 return;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200630 if (p[1] != sizeof(struct ieee80211_ht_operation))
Larry Finger5e93f352014-03-28 21:37:38 -0500631 return;
632
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200633 pHT_info = (struct ieee80211_ht_operation *)(p + 2);
Larry Finger5e93f352014-03-28 21:37:38 -0500634
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200635 if ((pHT_info->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY) &&
636 pregistrypriv->cbw40_enable) {
Larry Finger5e93f352014-03-28 21:37:38 -0500637 new_bwmode = HT_CHANNEL_WIDTH_40;
638
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200639 switch (pHT_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET){
640 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Larry Finger5e93f352014-03-28 21:37:38 -0500641 new_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
642 break;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200643 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Larry Finger5e93f352014-03-28 21:37:38 -0500644 new_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
645 break;
646 default:
647 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
648 break;
649 }
650 } else {
651 new_bwmode = HT_CHANNEL_WIDTH_20;
652 new_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
653 }
654
Jes Sorensenc227ed02014-05-09 15:03:27 +0200655 if (new_bwmode != pmlmeext->cur_bwmode ||
656 new_ch_offset != pmlmeext->cur_ch_offset) {
Larry Finger5e93f352014-03-28 21:37:38 -0500657 pmlmeinfo->bwmode_updated = true;
658
659 pmlmeext->cur_bwmode = new_bwmode;
660 pmlmeext->cur_ch_offset = new_ch_offset;
661
662 /* update HT info also */
Jes Sorensenb171da32014-05-21 09:37:42 +0200663 HT_info_handler23a(padapter, p);
Jes Sorensenc227ed02014-05-09 15:03:27 +0200664 } else
Larry Finger5e93f352014-03-28 21:37:38 -0500665 pmlmeinfo->bwmode_updated = false;
Larry Finger5e93f352014-03-28 21:37:38 -0500666
667 if (pmlmeinfo->bwmode_updated) {
668 struct sta_info *psta;
669 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
670 struct sta_priv *pstapriv = &padapter->stapriv;
671
Jes Sorensenc227ed02014-05-09 15:03:27 +0200672 /* set_channel_bwmode23a(padapter, pmlmeext->cur_channel,
673 pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
Larry Finger5e93f352014-03-28 21:37:38 -0500674
675 /* update ap's stainfo */
676 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
677 if (psta) {
Jes Sorensenc227ed02014-05-09 15:03:27 +0200678 struct ht_priv *phtpriv_sta = &psta->htpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500679
680 if (phtpriv_sta->ht_option) {
681 /* bwmode */
682 phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200683 phtpriv_sta->ch_offset =
684 pmlmeext->cur_ch_offset;
Larry Finger5e93f352014-03-28 21:37:38 -0500685 } else {
686 phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_20;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200687 phtpriv_sta->ch_offset =
688 HAL_PRIME_CHNL_OFFSET_DONT_CARE;
Larry Finger5e93f352014-03-28 21:37:38 -0500689 }
Larry Finger5e93f352014-03-28 21:37:38 -0500690 }
691 }
692}
693
Jes Sorensen3cdf2772014-06-09 15:16:03 +0200694void HT_caps_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500695{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200696 unsigned int i;
697 u8 rf_type;
698 u8 max_AMPDU_len, min_MPDU_spacing;
699 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500700 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200701 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
702 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
Jes Sorensen65be27d2014-05-31 18:05:11 +0200703 struct ieee80211_ht_cap *cap;
704 u8 *dstcap;
Larry Finger5e93f352014-03-28 21:37:38 -0500705
Jes Sorensenb171da32014-05-21 09:37:42 +0200706 if (!p)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200707 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500708
Jes Sorensen6a5f6572014-06-09 15:16:07 +0200709 if (!phtpriv->ht_option)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200710 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500711
712 pmlmeinfo->HT_caps_enable = 1;
713
Jes Sorensen65be27d2014-05-31 18:05:11 +0200714 cap = &pmlmeinfo->ht_cap;
715 dstcap = (u8 *)cap;
Jes Sorensenb171da32014-05-21 09:37:42 +0200716 for (i = 0; i < p[1]; i++) {
Larry Finger5e93f352014-03-28 21:37:38 -0500717 if (i != 2) {
Jes Sorensen65be27d2014-05-31 18:05:11 +0200718 dstcap[i] &= p[i + 2];
Larry Finger5e93f352014-03-28 21:37:38 -0500719 } else {
720 /* modify from fw by Thomas 2010/11/17 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200721 if ((cap->ampdu_params_info &
722 IEEE80211_HT_AMPDU_PARM_FACTOR) >
723 (p[i + 2] & IEEE80211_HT_AMPDU_PARM_FACTOR))
724 max_AMPDU_len = p[i + 2] &
725 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500726 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200727 max_AMPDU_len = cap->ampdu_params_info &
728 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500729
Jes Sorensen65be27d2014-05-31 18:05:11 +0200730 if ((cap->ampdu_params_info &
731 IEEE80211_HT_AMPDU_PARM_DENSITY) >
732 (p[i + 2] & IEEE80211_HT_AMPDU_PARM_DENSITY))
733 min_MPDU_spacing = cap->ampdu_params_info &
734 IEEE80211_HT_AMPDU_PARM_DENSITY;
Larry Finger5e93f352014-03-28 21:37:38 -0500735 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200736 min_MPDU_spacing = p[i + 2] &
737 IEEE80211_HT_AMPDU_PARM_DENSITY;
Larry Finger5e93f352014-03-28 21:37:38 -0500738
Jes Sorensen65be27d2014-05-31 18:05:11 +0200739 cap->ampdu_params_info =
Jes Sorensenb171da32014-05-21 09:37:42 +0200740 max_AMPDU_len | min_MPDU_spacing;
Larry Finger5e93f352014-03-28 21:37:38 -0500741 }
742 }
743
Jes Sorensenc2370e82014-04-09 23:20:53 +0200744 rf_type = rtl8723a_get_rf_type(padapter);
Larry Finger5e93f352014-03-28 21:37:38 -0500745
746 /* update the MCS rates */
Jes Sorensen198e95d2014-05-31 18:05:10 +0200747 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Jes Sorensenc227ed02014-05-09 15:03:27 +0200748 if (rf_type == RF_1T1R || rf_type == RF_1T2R)
Jes Sorensen65be27d2014-05-31 18:05:11 +0200749 cap->mcs.rx_mask[i] &= MCS_rate_1R23A[i];
Larry Finger5e93f352014-03-28 21:37:38 -0500750 else
Jes Sorensen65be27d2014-05-31 18:05:11 +0200751 cap->mcs.rx_mask[i] &= MCS_rate_2R23A[i];
Larry Finger5e93f352014-03-28 21:37:38 -0500752 }
753 return;
754}
755
Jes Sorensen7882ef42014-05-31 18:05:17 +0200756void HT_info_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500757{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200758 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500759 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200760 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
761 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500762
Jes Sorensenb171da32014-05-21 09:37:42 +0200763 if (!p)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200764 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500765
Jes Sorensen6a5f6572014-06-09 15:16:07 +0200766 if (!phtpriv->ht_option)
Jes Sorensenc227ed02014-05-09 15:03:27 +0200767 return;
Larry Finger5e93f352014-03-28 21:37:38 -0500768
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200769 if (p[1] != sizeof(struct ieee80211_ht_operation))
Larry Finger5e93f352014-03-28 21:37:38 -0500770 return;
771
772 pmlmeinfo->HT_info_enable = 1;
Jes Sorensenb171da32014-05-21 09:37:42 +0200773 memcpy(&pmlmeinfo->HT_info, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -0500774 return;
775}
776
777void HTOnAssocRsp23a(struct rtw_adapter *padapter)
778{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200779 unsigned char max_AMPDU_len;
780 unsigned char min_MPDU_spacing;
Larry Finger5e93f352014-03-28 21:37:38 -0500781 /* struct registry_priv *pregpriv = &padapter->registrypriv; */
Jes Sorensenc227ed02014-05-09 15:03:27 +0200782 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500783 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
784
785 DBG_8723A("%s\n", __func__);
786
Jes Sorensenc227ed02014-05-09 15:03:27 +0200787 if (pmlmeinfo->HT_info_enable && pmlmeinfo->HT_caps_enable)
Larry Finger5e93f352014-03-28 21:37:38 -0500788 pmlmeinfo->HT_enable = 1;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200789 else {
Larry Finger5e93f352014-03-28 21:37:38 -0500790 pmlmeinfo->HT_enable = 0;
Jes Sorensenc227ed02014-05-09 15:03:27 +0200791 /* set_channel_bwmode23a(padapter, pmlmeext->cur_channel,
792 pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); */
Larry Finger5e93f352014-03-28 21:37:38 -0500793 return;
794 }
795
796 /* handle A-MPDU parameter field */
797 /*
798 AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
799 AMPDU_para [4:2]:Min MPDU Start Spacing
800 */
Jes Sorensen65be27d2014-05-31 18:05:11 +0200801 max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
802 IEEE80211_HT_AMPDU_PARM_FACTOR;
Larry Finger5e93f352014-03-28 21:37:38 -0500803
Jes Sorensenc227ed02014-05-09 15:03:27 +0200804 min_MPDU_spacing =
Jes Sorensen65be27d2014-05-31 18:05:11 +0200805 (pmlmeinfo->ht_cap.ampdu_params_info &
806 IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Larry Finger5e93f352014-03-28 21:37:38 -0500807
Jes Sorensendce610a2014-04-09 23:20:32 +0200808 rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
809 rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
Larry Finger5e93f352014-03-28 21:37:38 -0500810}
811
Jes Sorensen7882ef42014-05-31 18:05:17 +0200812void ERP_IE_handler23a(struct rtw_adapter *padapter, const u8 *p)
Larry Finger5e93f352014-03-28 21:37:38 -0500813{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200814 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500815 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
816
Jes Sorensenb171da32014-05-21 09:37:42 +0200817 if (p[1] > 1)
Larry Finger5e93f352014-03-28 21:37:38 -0500818 return;
819
820 pmlmeinfo->ERP_enable = 1;
Jes Sorensenb171da32014-05-21 09:37:42 +0200821 memcpy(&pmlmeinfo->ERP_IE, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -0500822}
823
824void VCS_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
825{
Jes Sorensenc227ed02014-05-09 15:03:27 +0200826 struct registry_priv *pregpriv = &padapter->registrypriv;
827 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -0500828 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
829
830 switch (pregpriv->vrtl_carrier_sense) { /* 0:off 1:on 2:auto */
831 case 0: /* off */
832 psta->rtsen = 0;
833 psta->cts2self = 0;
834 break;
835 case 1: /* on */
836 if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */
837 psta->rtsen = 1;
838 psta->cts2self = 0;
839 } else {
840 psta->rtsen = 0;
841 psta->cts2self = 1;
842 }
843 break;
844 case 2: /* auto */
845 default:
Jes Sorensenc227ed02014-05-09 15:03:27 +0200846 if (pmlmeinfo->ERP_enable && pmlmeinfo->ERP_IE & BIT(1)) {
Larry Finger5e93f352014-03-28 21:37:38 -0500847 if (pregpriv->vcs_type == 1) {
848 psta->rtsen = 1;
849 psta->cts2self = 0;
850 } else {
851 psta->rtsen = 0;
852 psta->cts2self = 1;
853 }
854 } else {
855 psta->rtsen = 0;
856 psta->cts2self = 0;
857 }
858 break;
859 }
860}
861
Jes Sorensenc1465512014-04-15 19:43:58 +0200862int rtw_check_bcn_info23a(struct rtw_adapter *Adapter,
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200863 struct ieee80211_mgmt *mgmt, u32 pkt_len)
Larry Finger5e93f352014-03-28 21:37:38 -0500864{
Larry Finger5e93f352014-03-28 21:37:38 -0500865 struct wlan_network *cur_network = &Adapter->mlmepriv.cur_network;
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200866 struct ieee80211_ht_operation *pht_info;
Jes Sorensenc3761832014-04-15 19:44:05 +0200867 unsigned short val16;
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200868 u8 crypto, bcn_channel;
Jes Sorensenc3761832014-04-15 19:44:05 +0200869 int group_cipher = 0, pairwise_cipher = 0, is_8021x = 0, r;
Jes Sorensen68e6c792014-06-24 15:03:29 +0200870 int pie_len, ssid_len, privacy;
Jes Sorensen17b19392014-06-09 15:16:25 +0200871 const u8 *p, *ssid;
Larry Finger5e93f352014-03-28 21:37:38 -0500872
873 if (is_client_associated_to_ap23a(Adapter) == false)
Jes Sorensen17b19392014-06-09 15:16:25 +0200874 return _SUCCESS;
Larry Finger5e93f352014-03-28 21:37:38 -0500875
Jes Sorensenc1465512014-04-15 19:43:58 +0200876 if (unlikely(!ieee80211_is_beacon(mgmt->frame_control))) {
877 printk(KERN_WARNING "%s: received a non beacon frame!\n",
878 __func__);
Larry Finger5e93f352014-03-28 21:37:38 -0500879 return _FAIL;
880 }
881
Jes Sorensen0c45e612014-06-09 15:16:24 +0200882 if (!ether_addr_equal(cur_network->network.MacAddress, mgmt->bssid)) {
883 DBG_8723A("%s: linked but recv other bssid bcn"
884 MAC_FMT MAC_FMT "\n", __func__, MAC_ARG(mgmt->bssid),
Jes Sorensenc1465512014-04-15 19:43:58 +0200885 MAC_ARG(cur_network->network.MacAddress));
Jes Sorensen5bd28bc2014-04-26 18:54:49 +0200886 return _FAIL;
Jes Sorensen17b19392014-06-09 15:16:25 +0200887 }
Larry Finger5e93f352014-03-28 21:37:38 -0500888
889 /* check bw and channel offset */
890 /* parsing HT_CAP_IE */
Jes Sorensen17b19392014-06-09 15:16:25 +0200891 pie_len = pkt_len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200892
Larry Finger5e93f352014-03-28 21:37:38 -0500893 /* Checking for channel */
Jes Sorensen17b19392014-06-09 15:16:25 +0200894 p = cfg80211_find_ie(WLAN_EID_DS_PARAMS, mgmt->u.beacon.variable,
895 pie_len);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200896 if (p)
897 bcn_channel = p[2];
898 else {
899 /* In 5G, some ap do not have DSSET IE checking HT
900 info for channel */
Jes Sorensen17b19392014-06-09 15:16:25 +0200901 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION,
902 mgmt->u.beacon.variable, pie_len);
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200903
Jes Sorensened08b4d2014-05-31 18:05:14 +0200904 if (p && p[1] > 0) {
905 pht_info = (struct ieee80211_ht_operation *)(p + 2);
Jes Sorensen4dc5f8b2014-05-31 18:05:13 +0200906 bcn_channel = pht_info->primary_chan;
Jes Sorensened08b4d2014-05-31 18:05:14 +0200907 } else { /* we don't find channel IE, so don't check it */
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200908 DBG_8723A("Oops: %s we don't find channel IE, so don't "
909 "check it\n", __func__);
910 bcn_channel = Adapter->mlmeextpriv.cur_channel;
911 }
Larry Finger5e93f352014-03-28 21:37:38 -0500912 }
913 if (bcn_channel != Adapter->mlmeextpriv.cur_channel) {
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200914 DBG_8723A("%s beacon channel:%d cur channel:%d disconnect\n",
915 __func__, bcn_channel,
916 Adapter->mlmeextpriv.cur_channel);
917 goto _mismatch;
Larry Finger5e93f352014-03-28 21:37:38 -0500918 }
919
920 /* checking SSID */
Jes Sorensen17b19392014-06-09 15:16:25 +0200921 p = cfg80211_find_ie(WLAN_EID_SSID, mgmt->u.beacon.variable, pie_len);
Jes Sorensen82695d52014-04-15 19:44:00 +0200922 if (p && p[1]) {
Jes Sorensen17b19392014-06-09 15:16:25 +0200923 ssid = p + 2;
924 ssid_len = p[1];
Jes Sorensen82695d52014-04-15 19:44:00 +0200925 } else {
Jes Sorensen3ffa4352014-04-15 19:43:59 +0200926 DBG_8723A("%s marc: cannot find SSID for survey event\n",
927 __func__);
Jes Sorensen17b19392014-06-09 15:16:25 +0200928 ssid = NULL;
929 ssid_len = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500930 }
931
932 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
933 ("%s bssid.Ssid.Ssid:%s bssid.Ssid.SsidLength:%d "
934 "cur_network->network.Ssid.Ssid:%s len:%d\n", __func__,
Jes Sorensen17b19392014-06-09 15:16:25 +0200935 ssid, ssid_len, cur_network->network.Ssid.ssid,
Larry Finger5e93f352014-03-28 21:37:38 -0500936 cur_network->network.Ssid.ssid_len));
937
Jes Sorensen17b19392014-06-09 15:16:25 +0200938 if (ssid_len != cur_network->network.Ssid.ssid_len || ssid_len > 32 ||
939 (ssid_len &&
940 memcmp(ssid, cur_network->network.Ssid.ssid, ssid_len))) {
941 DBG_8723A("%s(), SSID is not match return FAIL\n", __func__);
942 goto _mismatch;
Larry Finger5e93f352014-03-28 21:37:38 -0500943 }
944
945 /* check encryption info */
Jes Sorensen17b19392014-06-09 15:16:25 +0200946 val16 = le16_to_cpu(mgmt->u.beacon.capab_info);
Larry Finger5e93f352014-03-28 21:37:38 -0500947
Jes Sorensena665bcc2014-05-31 18:05:15 +0200948 if (val16 & WLAN_CAPABILITY_PRIVACY)
Jes Sorensen17b19392014-06-09 15:16:25 +0200949 privacy = 1;
Larry Finger5e93f352014-03-28 21:37:38 -0500950 else
Jes Sorensen17b19392014-06-09 15:16:25 +0200951 privacy = 0;
Larry Finger5e93f352014-03-28 21:37:38 -0500952
953 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
Jes Sorensenc3761832014-04-15 19:44:05 +0200954 ("%s(): cur_network->network.Privacy is %d, bssid.Privacy "
Jes Sorensen17b19392014-06-09 15:16:25 +0200955 "is %d\n", __func__, cur_network->network.Privacy, privacy));
956 if (cur_network->network.Privacy != privacy) {
Larry Finger5e93f352014-03-28 21:37:38 -0500957 DBG_8723A("%s(), privacy is not match return FAIL\n", __func__);
958 goto _mismatch;
959 }
960
Jes Sorensen17b19392014-06-09 15:16:25 +0200961 p = cfg80211_find_ie(WLAN_EID_RSN, mgmt->u.beacon.variable, pie_len);
Jes Sorensen77953ed2014-06-09 15:16:00 +0200962 if (p && p[1]) {
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200963 crypto = ENCRYP_PROTOCOL_WPA2;
964 if (p && p[1]) {
965 r = rtw_parse_wpa2_ie23a(p, p[1] + 2, &group_cipher,
966 &pairwise_cipher, &is_8021x);
967 if (r == _SUCCESS)
968 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
969 ("%s pnetwork->pairwise_cipher: %d, "
970 "pnetwork->group_cipher: %d, is_802x "
971 ": %d\n", __func__, pairwise_cipher,
972 group_cipher, is_8021x));
973 }
Jes Sorensen77953ed2014-06-09 15:16:00 +0200974 } else {
Jes Sorensenf88ca602014-04-15 19:44:06 +0200975 p = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
976 WLAN_OUI_TYPE_MICROSOFT_WPA,
Jes Sorensen17b19392014-06-09 15:16:25 +0200977 mgmt->u.beacon.variable, pie_len);
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200978 if (p && p[1]) {
979 crypto = ENCRYP_PROTOCOL_WPA;
Jes Sorensenf88ca602014-04-15 19:44:06 +0200980 r = rtw_parse_wpa_ie23a(p, p[1] + 2, &group_cipher,
Jes Sorensenc3761832014-04-15 19:44:05 +0200981 &pairwise_cipher, &is_8021x);
982 if (r == _SUCCESS)
Larry Finger5e93f352014-03-28 21:37:38 -0500983 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
Jes Sorensenc3761832014-04-15 19:44:05 +0200984 ("%s pnetwork->pairwise_cipher: %d, "
985 "group_cipher is %d, is_8021x is "
986 "%d\n", __func__, pairwise_cipher,
987 group_cipher, is_8021x));
Larry Finger5e93f352014-03-28 21:37:38 -0500988 } else {
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200989 if (privacy)
990 crypto = ENCRYP_PROTOCOL_WEP;
991 else
992 crypto = ENCRYP_PROTOCOL_OPENSYS;
Larry Finger5e93f352014-03-28 21:37:38 -0500993 }
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200994 }
Larry Finger5e93f352014-03-28 21:37:38 -0500995
Jes Sorensenbbf5fdb2014-06-09 15:16:26 +0200996 if (cur_network->BcnInfo.encryp_protocol != crypto) {
997 DBG_8723A("%s(): encryption mismatch, return FAIL\n", __func__);
998 goto _mismatch;
999 }
1000
1001 if (crypto == ENCRYP_PROTOCOL_WPA || crypto == ENCRYP_PROTOCOL_WPA2) {
Larry Finger5e93f352014-03-28 21:37:38 -05001002 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
Jes Sorensenc3761832014-04-15 19:44:05 +02001003 ("%s cur_network->group_cipher is %d: %d\n", __func__,
1004 cur_network->BcnInfo.group_cipher, group_cipher));
1005 if (pairwise_cipher != cur_network->BcnInfo.pairwise_cipher ||
1006 group_cipher != cur_network->BcnInfo.group_cipher) {
1007 DBG_8723A("%s pairwise_cipher(%x:%x) or group_cipher "
1008 "(%x:%x) is not match, return FAIL\n",
1009 __func__, pairwise_cipher,
1010 cur_network->BcnInfo.pairwise_cipher,
1011 group_cipher,
1012 cur_network->BcnInfo.group_cipher);
Larry Finger5e93f352014-03-28 21:37:38 -05001013 goto _mismatch;
1014 }
1015
1016 if (is_8021x != cur_network->BcnInfo.is_8021x) {
Jes Sorensenc3761832014-04-15 19:44:05 +02001017 DBG_8723A("%s authentication is not match, return "
1018 "FAIL\n", __func__);
Larry Finger5e93f352014-03-28 21:37:38 -05001019 goto _mismatch;
1020 }
1021 }
1022
Larry Finger5e93f352014-03-28 21:37:38 -05001023 return _SUCCESS;
1024
1025_mismatch:
Larry Finger5e93f352014-03-28 21:37:38 -05001026
1027 return _FAIL;
1028}
1029
Jes Sorensen7882ef42014-05-31 18:05:17 +02001030void update_beacon23a_info(struct rtw_adapter *padapter,
1031 struct ieee80211_mgmt *mgmt,
Jes Sorensenb171da32014-05-21 09:37:42 +02001032 uint pkt_len, struct sta_info *psta)
Larry Finger5e93f352014-03-28 21:37:38 -05001033{
Larry Finger5e93f352014-03-28 21:37:38 -05001034 unsigned int len;
Jes Sorensen7882ef42014-05-31 18:05:17 +02001035 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001036
Jes Sorensen7882ef42014-05-31 18:05:17 +02001037 len = pkt_len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
Larry Finger5e93f352014-03-28 21:37:38 -05001038
Jes Sorensen7882ef42014-05-31 18:05:17 +02001039 p = cfg80211_find_ie(WLAN_EID_HT_OPERATION, mgmt->u.beacon.variable,
1040 len);
1041 if (p)
1042 bwmode_update_check(padapter, p);
Larry Finger5e93f352014-03-28 21:37:38 -05001043
Jes Sorensen7882ef42014-05-31 18:05:17 +02001044 p = cfg80211_find_ie(WLAN_EID_ERP_INFO, mgmt->u.beacon.variable, len);
1045 if (p) {
1046 ERP_IE_handler23a(padapter, p);
1047 VCS_update23a(padapter, psta);
Larry Finger5e93f352014-03-28 21:37:38 -05001048 }
1049}
1050
Jes Sorensend5789242014-05-16 10:04:35 +02001051bool is_ap_in_tkip23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001052{
1053 u32 i;
Larry Finger5e93f352014-03-28 21:37:38 -05001054 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1055 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1056 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001057 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001058
Jes Sorensena94e12b2014-06-19 11:37:34 +02001059 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001060 for (i = 0; i < pmlmeinfo->network.IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001061 p = pmlmeinfo->network.IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001062
Jes Sorensenb171da32014-05-21 09:37:42 +02001063 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001064 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001065 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4) &&
1066 !memcmp(p + 2 + 12, WPA_TKIP_CIPHER, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001067 return true;
1068 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001069 case WLAN_EID_RSN:
Jes Sorensenb171da32014-05-21 09:37:42 +02001070 if (!memcmp(p + 2 + 8, RSN_TKIP_CIPHER, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001071 return true;
1072 break;
1073 default:
1074 break;
1075 }
Jes Sorensenb171da32014-05-21 09:37:42 +02001076 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001077 }
1078 return false;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001079 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001080 return false;
Larry Finger5e93f352014-03-28 21:37:38 -05001081}
1082
Greg Donald8e3d1612014-10-02 18:28:41 -05001083bool should_forbid_n_rate23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001084{
1085 u32 i;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001086 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001087 struct wlan_bssid_ex *cur_network = &pmlmepriv->cur_network.network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001088 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001089
Jes Sorensena94e12b2014-06-19 11:37:34 +02001090 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001091 for (i = 0; i < cur_network->IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001092 p = cur_network->IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001093
Jes Sorensenb171da32014-05-21 09:37:42 +02001094 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001095 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001096 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4) &&
1097 (!memcmp(p + 2 + 12,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001098 WPA_CIPHER_SUITE_CCMP23A, 4) ||
Jes Sorensenb171da32014-05-21 09:37:42 +02001099 !memcmp(p + 2 + 16,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001100 WPA_CIPHER_SUITE_CCMP23A, 4)))
Larry Finger5e93f352014-03-28 21:37:38 -05001101 return false;
1102 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001103 case WLAN_EID_RSN:
Jes Sorensenb171da32014-05-21 09:37:42 +02001104 if (!memcmp(p + 2 + 8,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001105 RSN_CIPHER_SUITE_CCMP23A, 4) ||
Jes Sorensenb171da32014-05-21 09:37:42 +02001106 !memcmp(p + 2 + 12,
Jes Sorensenc227ed02014-05-09 15:03:27 +02001107 RSN_CIPHER_SUITE_CCMP23A, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001108 return false;
1109 default:
1110 break;
1111 }
1112
Jes Sorensenb171da32014-05-21 09:37:42 +02001113 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001114 }
1115 return true;
1116 } else {
1117 return false;
1118 }
1119}
1120
Jes Sorensend5789242014-05-16 10:04:35 +02001121bool is_ap_in_wep23a(struct rtw_adapter *padapter)
Larry Finger5e93f352014-03-28 21:37:38 -05001122{
1123 u32 i;
Larry Finger5e93f352014-03-28 21:37:38 -05001124 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1125 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1126 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenb171da32014-05-21 09:37:42 +02001127 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001128
Jes Sorensena94e12b2014-06-19 11:37:34 +02001129 if (cur_network->capability & WLAN_CAPABILITY_PRIVACY) {
Jes Sorensen68e6c792014-06-24 15:03:29 +02001130 for (i = 0; i < pmlmeinfo->network.IELength;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001131 p = pmlmeinfo->network.IEs + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001132
Jes Sorensenb171da32014-05-21 09:37:42 +02001133 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001134 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001135 if (!memcmp(p + 2, RTW_WPA_OUI23A_TYPE, 4))
Larry Finger5e93f352014-03-28 21:37:38 -05001136 return false;
1137 break;
Jes Sorensen25c934f2014-04-15 19:43:29 +02001138 case WLAN_EID_RSN:
Larry Finger5e93f352014-03-28 21:37:38 -05001139 return false;
1140
1141 default:
1142 break;
1143 }
1144
Jes Sorensenb171da32014-05-21 09:37:42 +02001145 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001146 }
1147
1148 return true;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001149 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001150 return false;
Larry Finger5e93f352014-03-28 21:37:38 -05001151}
1152
Larry Fingerc0b99be2014-04-26 18:55:17 +02001153static int wifirate2_ratetbl_inx23a(unsigned char rate)
Larry Finger5e93f352014-03-28 21:37:38 -05001154{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001155 int inx = 0;
Yeliz Taneroglu547f9752014-10-09 01:22:17 +03001156
Larry Finger5e93f352014-03-28 21:37:38 -05001157 rate = rate & 0x7f;
1158
1159 switch (rate) {
1160 case 54*2:
1161 inx = 11;
1162 break;
1163 case 48*2:
1164 inx = 10;
1165 break;
1166 case 36*2:
1167 inx = 9;
1168 break;
1169 case 24*2:
1170 inx = 8;
1171 break;
1172 case 18*2:
1173 inx = 7;
1174 break;
1175 case 12*2:
1176 inx = 6;
1177 break;
1178 case 9*2:
1179 inx = 5;
1180 break;
1181 case 6*2:
1182 inx = 4;
1183 break;
1184 case 11*2:
1185 inx = 3;
1186 break;
1187 case 11:
1188 inx = 2;
1189 break;
1190 case 2*2:
1191 inx = 1;
1192 break;
1193 case 1*2:
1194 inx = 0;
1195 break;
1196 }
1197 return inx;
1198}
1199
1200unsigned int update_basic_rate23a(unsigned char *ptn, unsigned int ptn_sz)
1201{
1202 unsigned int i, num_of_rate;
1203 unsigned int mask = 0;
1204
1205 num_of_rate = (ptn_sz > NumRates)? NumRates: ptn_sz;
1206
1207 for (i = 0; i < num_of_rate; i++) {
1208 if ((*(ptn + i)) & 0x80)
1209 mask |= 0x1 << wifirate2_ratetbl_inx23a(*(ptn + i));
1210 }
1211 return mask;
1212}
1213
1214unsigned int update_supported_rate23a(unsigned char *ptn, unsigned int ptn_sz)
1215{
1216 unsigned int i, num_of_rate;
1217 unsigned int mask = 0;
1218
Jes Sorensenc227ed02014-05-09 15:03:27 +02001219 num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
Larry Finger5e93f352014-03-28 21:37:38 -05001220
1221 for (i = 0; i < num_of_rate; i++)
1222 mask |= 0x1 << wifirate2_ratetbl_inx23a(*(ptn + i));
1223 return mask;
1224}
1225
Jes Sorensen65be27d2014-05-31 18:05:11 +02001226unsigned int update_MSC_rate23a(struct ieee80211_ht_cap *pHT_caps)
Larry Finger5e93f352014-03-28 21:37:38 -05001227{
1228 unsigned int mask = 0;
1229
Jes Sorensen65be27d2014-05-31 18:05:11 +02001230 mask = pHT_caps->mcs.rx_mask[0] << 12 |
1231 pHT_caps->mcs.rx_mask[1] << 20;
Larry Finger5e93f352014-03-28 21:37:38 -05001232
1233 return mask;
1234}
1235
1236int support_short_GI23a(struct rtw_adapter *padapter,
Jes Sorensen65be27d2014-05-31 18:05:11 +02001237 struct ieee80211_ht_cap *pHT_caps)
Larry Finger5e93f352014-03-28 21:37:38 -05001238{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001239 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001240 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1241 unsigned char bit_offset;
1242
Jes Sorensenc227ed02014-05-09 15:03:27 +02001243 if (!pmlmeinfo->HT_enable)
Larry Finger5e93f352014-03-28 21:37:38 -05001244 return _FAIL;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001245 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_RALINK)
Larry Finger5e93f352014-03-28 21:37:38 -05001246 return _FAIL;
1247 bit_offset = (pmlmeext->cur_bwmode & HT_CHANNEL_WIDTH_40)? 6: 5;
1248
Jes Sorensen65be27d2014-05-31 18:05:11 +02001249 if (pHT_caps->cap_info & cpu_to_le16(0x1 << bit_offset))
Larry Finger5e93f352014-03-28 21:37:38 -05001250 return _SUCCESS;
1251 else
1252 return _FAIL;
1253}
1254
1255unsigned char get_highest_rate_idx23a(u32 mask)
1256{
1257 int i;
1258 unsigned char rate_idx = 0;
1259
1260 for (i = 27; i >= 0; i--) {
1261 if (mask & BIT(i)) {
1262 rate_idx = i;
1263 break;
1264 }
1265 }
1266 return rate_idx;
1267}
1268
Larry Finger5e93f352014-03-28 21:37:38 -05001269void Update_RA_Entry23a(struct rtw_adapter *padapter, struct sta_info *psta)
1270{
1271 rtw_hal_update_ra_mask23a(psta, 0);
1272}
1273
Larry Fingerc0b99be2014-04-26 18:55:17 +02001274static void enable_rate_adaptive(struct rtw_adapter *padapter,
1275 struct sta_info *psta)
Larry Finger5e93f352014-03-28 21:37:38 -05001276{
1277 Update_RA_Entry23a(padapter, psta);
1278}
1279
1280void set_sta_rate23a(struct rtw_adapter *padapter, struct sta_info *psta)
1281{
1282 /* rate adaptive */
1283 enable_rate_adaptive(padapter, psta);
1284}
1285
1286/* Update RRSR and Rate for USERATE */
1287void update_tx_basic_rate23a(struct rtw_adapter *padapter, u8 wirelessmode)
1288{
1289 unsigned char supported_rates[NDIS_802_11_LENGTH_RATES_EX];
Larry Finger5e93f352014-03-28 21:37:38 -05001290
1291 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
1292
Jes Sorensenff516e72014-05-09 15:03:28 +02001293 if (wirelessmode == WIRELESS_11B) {
Larry Finger5e93f352014-03-28 21:37:38 -05001294 memcpy(supported_rates, rtw_basic_rate_cck, 4);
1295 } else if (wirelessmode & WIRELESS_11B) {
1296 memcpy(supported_rates, rtw_basic_rate_mix, 7);
1297 } else {
1298 memcpy(supported_rates, rtw_basic_rate_ofdm, 3);
1299 }
1300
1301 if (wirelessmode & WIRELESS_11B)
1302 update_mgnt_tx_rate23a(padapter, IEEE80211_CCK_RATE_1MB);
1303 else
1304 update_mgnt_tx_rate23a(padapter, IEEE80211_OFDM_RATE_6MB);
1305
Jes Sorensenfa2e5202014-04-09 23:20:18 +02001306 HalSetBrateCfg23a(padapter, supported_rates);
Larry Finger5e93f352014-03-28 21:37:38 -05001307}
1308
1309unsigned char check_assoc_AP23a(u8 *pframe, uint len)
1310{
Jes Sorensen68e6c792014-06-24 15:03:29 +02001311 int i;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001312 u8 epigram_vendor_flag;
1313 u8 ralink_vendor_flag;
Jes Sorensenb171da32014-05-21 09:37:42 +02001314 const u8 *p;
Yeliz Taneroglu547f9752014-10-09 01:22:17 +03001315
Larry Finger5e93f352014-03-28 21:37:38 -05001316 epigram_vendor_flag = 0;
1317 ralink_vendor_flag = 0;
1318
Jes Sorensen68e6c792014-06-24 15:03:29 +02001319 for (i = 0; i < len;) {
Jes Sorensenb171da32014-05-21 09:37:42 +02001320 p = pframe + i;
Larry Finger5e93f352014-03-28 21:37:38 -05001321
Jes Sorensenb171da32014-05-21 09:37:42 +02001322 switch (p[0]) {
Jes Sorensen9300c942014-04-15 19:43:21 +02001323 case WLAN_EID_VENDOR_SPECIFIC:
Jes Sorensenb171da32014-05-21 09:37:42 +02001324 if (!memcmp(p + 2, ARTHEROS_OUI1, 3) ||
1325 !memcmp(p + 2, ARTHEROS_OUI2, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001326 DBG_8723A("link to Artheros AP\n");
1327 return HT_IOT_PEER_ATHEROS;
Jes Sorensenb171da32014-05-21 09:37:42 +02001328 } else if (!memcmp(p + 2, BROADCOM_OUI1, 3) ||
1329 !memcmp(p + 2, BROADCOM_OUI2, 3) ||
1330 !memcmp(p + 2, BROADCOM_OUI2, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001331 DBG_8723A("link to Broadcom AP\n");
1332 return HT_IOT_PEER_BROADCOM;
Jes Sorensenb171da32014-05-21 09:37:42 +02001333 } else if (!memcmp(p + 2, MARVELL_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001334 DBG_8723A("link to Marvell AP\n");
1335 return HT_IOT_PEER_MARVELL;
Jes Sorensenb171da32014-05-21 09:37:42 +02001336 } else if (!memcmp(p + 2, RALINK_OUI, 3)) {
Jes Sorensenc227ed02014-05-09 15:03:27 +02001337 if (!ralink_vendor_flag)
Larry Finger5e93f352014-03-28 21:37:38 -05001338 ralink_vendor_flag = 1;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001339 else {
Larry Finger5e93f352014-03-28 21:37:38 -05001340 DBG_8723A("link to Ralink AP\n");
1341 return HT_IOT_PEER_RALINK;
1342 }
Jes Sorensenb171da32014-05-21 09:37:42 +02001343 } else if (!memcmp(p + 2, CISCO_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001344 DBG_8723A("link to Cisco AP\n");
1345 return HT_IOT_PEER_CISCO;
Jes Sorensenb171da32014-05-21 09:37:42 +02001346 } else if (!memcmp(p + 2, REALTEK_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001347 DBG_8723A("link to Realtek 96B\n");
1348 return HT_IOT_PEER_REALTEK;
Jes Sorensenb171da32014-05-21 09:37:42 +02001349 } else if (!memcmp(p + 2, AIRGOCAP_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001350 DBG_8723A("link to Airgo Cap\n");
1351 return HT_IOT_PEER_AIRGO;
Jes Sorensenb171da32014-05-21 09:37:42 +02001352 } else if (!memcmp(p + 2, EPIGRAM_OUI, 3)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001353 epigram_vendor_flag = 1;
1354 if (ralink_vendor_flag) {
1355 DBG_8723A("link to Tenda W311R AP\n");
1356 return HT_IOT_PEER_TENDA;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001357 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001358 DBG_8723A("Capture EPIGRAM_OUI\n");
Jes Sorensenc227ed02014-05-09 15:03:27 +02001359 } else
Larry Finger5e93f352014-03-28 21:37:38 -05001360 break;
Larry Finger5e93f352014-03-28 21:37:38 -05001361 default:
1362 break;
1363 }
1364
Jes Sorensenb171da32014-05-21 09:37:42 +02001365 i += (p[1] + 2);
Larry Finger5e93f352014-03-28 21:37:38 -05001366 }
1367
1368 if (ralink_vendor_flag && !epigram_vendor_flag) {
1369 DBG_8723A("link to Ralink AP\n");
1370 return HT_IOT_PEER_RALINK;
1371 } else if (ralink_vendor_flag && epigram_vendor_flag) {
1372 DBG_8723A("link to Tenda W311R AP\n");
1373 return HT_IOT_PEER_TENDA;
1374 } else {
1375 DBG_8723A("link to new AP\n");
1376 return HT_IOT_PEER_UNKNOWN;
1377 }
1378}
1379
1380void update_IOT_info23a(struct rtw_adapter *padapter)
1381{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001382 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001383 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1384
1385 switch (pmlmeinfo->assoc_AP_vendor) {
1386 case HT_IOT_PEER_MARVELL:
1387 pmlmeinfo->turboMode_cts2self = 1;
1388 pmlmeinfo->turboMode_rtsen = 0;
1389 break;
1390 case HT_IOT_PEER_RALINK:
1391 pmlmeinfo->turboMode_cts2self = 0;
1392 pmlmeinfo->turboMode_rtsen = 1;
1393 /* disable high power */
Jes Sorensen585eefb2014-04-09 23:20:43 +02001394 rtl8723a_odm_support_ability_clr(padapter, (u32)
1395 ~DYNAMIC_BB_DYNAMIC_TXPWR);
Larry Finger5e93f352014-03-28 21:37:38 -05001396 break;
1397 case HT_IOT_PEER_REALTEK:
1398 /* rtw_write16(padapter, 0x4cc, 0xffff); */
1399 /* rtw_write16(padapter, 0x546, 0x01c0); */
1400 /* disable high power */
Jes Sorensen585eefb2014-04-09 23:20:43 +02001401 rtl8723a_odm_support_ability_clr(padapter, (u32)
1402 ~DYNAMIC_BB_DYNAMIC_TXPWR);
Larry Finger5e93f352014-03-28 21:37:38 -05001403 break;
1404 default:
1405 pmlmeinfo->turboMode_cts2self = 0;
1406 pmlmeinfo->turboMode_rtsen = 1;
1407 break;
1408 }
1409}
1410
1411void update_capinfo23a(struct rtw_adapter *Adapter, u16 updateCap)
1412{
Jes Sorensenc227ed02014-05-09 15:03:27 +02001413 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001414 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Larry Finger5e93f352014-03-28 21:37:38 -05001415
1416 if (updateCap & cShortPreamble) {
1417 /* Short Preamble */
1418 if (pmlmeinfo->preamble_mode != PREAMBLE_SHORT) {
1419 /* PREAMBLE_LONG or PREAMBLE_AUTO */
Larry Finger5e93f352014-03-28 21:37:38 -05001420 pmlmeinfo->preamble_mode = PREAMBLE_SHORT;
Jes Sorensen093dd412014-04-09 23:20:26 +02001421 rtl8723a_ack_preamble(Adapter, true);
Larry Finger5e93f352014-03-28 21:37:38 -05001422 }
1423 } else { /* Long Preamble */
1424 if (pmlmeinfo->preamble_mode != PREAMBLE_LONG) {
1425 /* PREAMBLE_SHORT or PREAMBLE_AUTO */
Larry Finger5e93f352014-03-28 21:37:38 -05001426 pmlmeinfo->preamble_mode = PREAMBLE_LONG;
Jes Sorensen093dd412014-04-09 23:20:26 +02001427 rtl8723a_ack_preamble(Adapter, false);
Larry Finger5e93f352014-03-28 21:37:38 -05001428 }
1429 }
1430 if (updateCap & cIBSS) {
1431 /* Filen: See 802.11-2007 p.91 */
1432 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1433 } else {
1434 /* Filen: See 802.11-2007 p.90 */
Jes Sorensenc227ed02014-05-09 15:03:27 +02001435 if (pmlmeext->cur_wireless_mode &
1436 (WIRELESS_11G | WIRELESS_11_24N)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001437 if (updateCap & cShortSlotTime) { /* Short Slot Time */
1438 if (pmlmeinfo->slotTime != SHORT_SLOT_TIME)
1439 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1440 } else { /* Long Slot Time */
1441 if (pmlmeinfo->slotTime != NON_SHORT_SLOT_TIME)
Jes Sorensenc227ed02014-05-09 15:03:27 +02001442 pmlmeinfo->slotTime =
1443 NON_SHORT_SLOT_TIME;
Larry Finger5e93f352014-03-28 21:37:38 -05001444 }
Jes Sorensenc227ed02014-05-09 15:03:27 +02001445 } else if (pmlmeext->cur_wireless_mode &
1446 (WIRELESS_11A | WIRELESS_11_5N)) {
Larry Finger5e93f352014-03-28 21:37:38 -05001447 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
1448 } else {
1449 /* B Mode */
1450 pmlmeinfo->slotTime = NON_SHORT_SLOT_TIME;
1451 }
1452 }
Jes Sorensen04c38422014-04-09 23:20:24 +02001453 rtl8723a_set_slot_time(Adapter, pmlmeinfo->slotTime);
Larry Finger5e93f352014-03-28 21:37:38 -05001454}
1455
1456void update_wireless_mode23a(struct rtw_adapter *padapter)
1457{
1458 int ratelen, network_type = 0;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001459 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001460 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1461 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001462 unsigned char *rate = cur_network->SupportedRates;
Larry Finger5e93f352014-03-28 21:37:38 -05001463
1464 ratelen = rtw_get_rateset_len23a(cur_network->SupportedRates);
1465
1466 if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
1467 pmlmeinfo->HT_enable = 1;
1468
1469 if (pmlmeext->cur_channel > 14) {
1470 if (pmlmeinfo->HT_enable)
1471 network_type = WIRELESS_11_5N;
1472 network_type |= WIRELESS_11A;
1473 } else {
1474 if (pmlmeinfo->HT_enable)
1475 network_type = WIRELESS_11_24N;
1476
Jes Sorensenc227ed02014-05-09 15:03:27 +02001477 if (cckratesonly_included23a(rate, ratelen) == true)
Larry Finger5e93f352014-03-28 21:37:38 -05001478 network_type |= WIRELESS_11B;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001479 else if (cckrates_included23a(rate, ratelen) == true)
Larry Finger5e93f352014-03-28 21:37:38 -05001480 network_type |= WIRELESS_11BG;
1481 else
1482 network_type |= WIRELESS_11G;
1483 }
1484
Jes Sorensenc227ed02014-05-09 15:03:27 +02001485 pmlmeext->cur_wireless_mode =
1486 network_type & padapter->registrypriv.wireless_mode;
Larry Finger5e93f352014-03-28 21:37:38 -05001487
Jes Sorensen7b7aefa2014-04-09 23:20:25 +02001488 /* 0x0808 -> for CCK, 0x0a0a -> for OFDM */
1489 /* change this value if having IOT issues. */
1490 rtl8723a_set_resp_sifs(padapter, 0x08, 0x08, 0x0a, 0x0a);
Larry Finger5e93f352014-03-28 21:37:38 -05001491
1492 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1493 update_mgnt_tx_rate23a(padapter, IEEE80211_CCK_RATE_1MB);
1494 else
1495 update_mgnt_tx_rate23a(padapter, IEEE80211_OFDM_RATE_6MB);
1496}
1497
1498void update_bmc_sta_support_rate23a(struct rtw_adapter *padapter, u32 mac_id)
1499{
1500 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1501 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1502
1503 if (pmlmeext->cur_wireless_mode & WIRELESS_11B) {
1504 /* Only B, B/G, and B/G/N AP could use CCK rate */
Jes Sorensen5bd28bc2014-04-26 18:54:49 +02001505 memcpy((pmlmeinfo->FW_sta_info[mac_id].SupportedRates),
1506 rtw_basic_rate_cck, 4);
Larry Finger5e93f352014-03-28 21:37:38 -05001507 } else {
Jes Sorensenc227ed02014-05-09 15:03:27 +02001508 memcpy(pmlmeinfo->FW_sta_info[mac_id].SupportedRates,
Jes Sorensen5bd28bc2014-04-26 18:54:49 +02001509 rtw_basic_rate_ofdm, 3);
Larry Finger5e93f352014-03-28 21:37:38 -05001510 }
1511}
1512
Jes Sorensenbf350272014-04-15 19:44:01 +02001513int update_sta_support_rate23a(struct rtw_adapter *padapter, u8 *pvar_ie,
1514 uint var_ie_len, int cam_idx)
Larry Finger5e93f352014-03-28 21:37:38 -05001515{
Jes Sorensenbf350272014-04-15 19:44:01 +02001516 int supportRateNum = 0;
Larry Finger5e93f352014-03-28 21:37:38 -05001517 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1518 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensenbf350272014-04-15 19:44:01 +02001519 const u8 *p;
Larry Finger5e93f352014-03-28 21:37:38 -05001520
Jes Sorensenbf350272014-04-15 19:44:01 +02001521 p = cfg80211_find_ie(WLAN_EID_SUPP_RATES, pvar_ie, var_ie_len);
1522 if (!p)
Larry Finger5e93f352014-03-28 21:37:38 -05001523 return _FAIL;
1524
Jes Sorensenbf350272014-04-15 19:44:01 +02001525 memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates, p + 2, p[1]);
1526 supportRateNum = p[1];
Larry Finger5e93f352014-03-28 21:37:38 -05001527
Jes Sorensenbf350272014-04-15 19:44:01 +02001528 p = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, pvar_ie, var_ie_len);
1529 if (p)
1530 memcpy(pmlmeinfo->FW_sta_info[cam_idx].SupportedRates +
1531 supportRateNum, p + 2, p[1]);
Larry Finger5e93f352014-03-28 21:37:38 -05001532 return _SUCCESS;
1533}
1534
Jes Sorensenc227ed02014-05-09 15:03:27 +02001535void process_addba_req23a(struct rtw_adapter *padapter,
1536 u8 *paddba_req, u8 *addr)
Larry Finger5e93f352014-03-28 21:37:38 -05001537{
1538 struct sta_info *psta;
1539 u16 tid, start_seq, param;
1540 struct recv_reorder_ctrl *preorder_ctrl;
1541 struct sta_priv *pstapriv = &padapter->stapriv;
Greg Donald7e6646d2014-09-06 19:42:03 -05001542 struct ADDBA_request *preq = (struct ADDBA_request *)paddba_req;
Jes Sorensenc227ed02014-05-09 15:03:27 +02001543 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
Larry Finger5e93f352014-03-28 21:37:38 -05001544 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1545
1546 psta = rtw_get_stainfo23a(pstapriv, addr);
1547
1548 if (psta) {
1549 start_seq = le16_to_cpu(preq->BA_starting_seqctrl) >> 4;
1550
1551 param = le16_to_cpu(preq->BA_para_set);
Jes Sorensenc227ed02014-05-09 15:03:27 +02001552 tid = (param >> 2) & 0x0f;
Larry Finger5e93f352014-03-28 21:37:38 -05001553
1554 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1555
1556 preorder_ctrl->indicate_seq = 0xffff;
1557
Jes Sorensenc227ed02014-05-09 15:03:27 +02001558 preorder_ctrl->enable = (pmlmeinfo->bAcceptAddbaReq == true) ?
1559 true : false;
Larry Finger5e93f352014-03-28 21:37:38 -05001560 }
1561}