1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #define _IEEE80211_C
5
6 #include "../include/drv_types.h"
7 #include "../include/ieee80211.h"
8 #include "../include/wifi.h"
9 #include "../include/osdep_service.h"
10 #include "../include/wlan_bssdef.h"
11 #include "../include/usb_osintf.h"
12
13 u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
14 u16 RTW_WPA_VERSION = 1;
15 u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
16 u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
17 u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
18 u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
19 u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
20 u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
21 u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
22 u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
23 u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
24
25 u16 RSN_VERSION_BSD = 1;
26 u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
27 u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
28 u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
29 u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
30 u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
31 u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
32 u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
33 u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
34 /* */
35 /* for adhoc-master to generate ie and provide supported-rate to fw */
36 /* */
37
38 static u8 WIFI_CCKRATES[] = {
39 (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
40 (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
41 (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
42 (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
43 };
44
45 static u8 WIFI_OFDMRATES[] = {
46 (IEEE80211_OFDM_RATE_6MB),
47 (IEEE80211_OFDM_RATE_9MB),
48 (IEEE80211_OFDM_RATE_12MB),
49 (IEEE80211_OFDM_RATE_18MB),
50 (IEEE80211_OFDM_RATE_24MB),
51 IEEE80211_OFDM_RATE_36MB,
52 IEEE80211_OFDM_RATE_48MB,
53 IEEE80211_OFDM_RATE_54MB
54 };
55
rtw_get_bit_value_from_ieee_value(u8 val)56 int rtw_get_bit_value_from_ieee_value(u8 val)
57 {
58 unsigned char dot11_rate_table[] = {
59 2, 4, 11, 22, 12, 18, 24, 36, 48,
60 72, 96, 108, 0}; /* last element must be zero!! */
61
62 int i = 0;
63 while (dot11_rate_table[i] != 0) {
64 if (dot11_rate_table[i] == val)
65 return BIT(i);
66 i++;
67 }
68 return 0;
69 }
70
rtw_is_cckrates_included(u8 * rate)71 bool rtw_is_cckrates_included(u8 *rate)
72 {
73 u32 i = 0;
74
75 while (rate[i] != 0) {
76 if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
77 (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
78 return true;
79 i++;
80 }
81 return false;
82 }
83
rtw_is_cckratesonly_included(u8 * rate)84 bool rtw_is_cckratesonly_included(u8 *rate)
85 {
86 u32 i = 0;
87
88 while (rate[i] != 0) {
89 if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
90 (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
91 return false;
92 i++;
93 }
94
95 return true;
96 }
97
rtw_check_network_type(unsigned char * rate,int ratelen,int channel)98 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
99 {
100 if (channel > 14)
101 return WIRELESS_INVALID;
102 /* could be pure B, pure G, or B/G */
103 if (rtw_is_cckratesonly_included(rate))
104 return WIRELESS_11B;
105 else if (rtw_is_cckrates_included(rate))
106 return WIRELESS_11BG;
107 else
108 return WIRELESS_11G;
109 }
110
rtw_set_fixed_ie(unsigned char * pbuf,unsigned int len,unsigned char * source,unsigned int * frlen)111 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
112 unsigned int *frlen)
113 {
114 memcpy((void *)pbuf, (void *)source, len);
115 *frlen = *frlen + len;
116 return pbuf + len;
117 }
118
119 /* rtw_set_ie will update frame length */
rtw_set_ie(u8 * pbuf,int index,uint len,u8 * source,uint * frlen)120 u8 *rtw_set_ie
121 (
122 u8 *pbuf,
123 int index,
124 uint len,
125 u8 *source,
126 uint *frlen /* frame length */
127 )
128 {
129
130 *pbuf = (u8)index;
131
132 *(pbuf + 1) = (u8)len;
133
134 if (len > 0)
135 memcpy((void *)(pbuf + 2), (void *)source, len);
136
137 *frlen = *frlen + (len + 2);
138
139 return pbuf + len + 2;
140 }
141
142 /*----------------------------------------------------------------------------
143 index: the information element id index, limit is the limit for search
144 -----------------------------------------------------------------------------*/
rtw_get_ie(u8 * pbuf,int index,int * len,int limit)145 u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit)
146 {
147 int tmp, i;
148 u8 *p;
149
150 if (limit < 1) {
151
152 return NULL;
153 }
154
155 p = pbuf;
156 i = 0;
157 *len = 0;
158 while (1) {
159 if (*p == index) {
160 *len = *(p + 1);
161 return p;
162 }
163 tmp = *(p + 1);
164 p += (tmp + 2);
165 i += (tmp + 2);
166 if (i >= limit)
167 break;
168 }
169
170 return NULL;
171 }
172
rtw_set_supported_rate(u8 * SupportedRates,uint mode)173 void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
174 {
175
176 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
177
178 switch (mode) {
179 case WIRELESS_11B:
180 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
181 break;
182 case WIRELESS_11G:
183 memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
184 break;
185 case WIRELESS_11BG:
186 case WIRELESS_11G_24N:
187 case WIRELESS_11_24N:
188 case WIRELESS_11BG_24N:
189 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
190 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
191 break;
192 }
193
194 }
195
rtw_get_rateset_len(u8 * rateset)196 uint rtw_get_rateset_len(u8 *rateset)
197 {
198 uint i = 0;
199
200 while (1) {
201 if ((rateset[i]) == 0)
202 break;
203 if (i > 12)
204 break;
205 i++;
206 }
207
208 return i;
209 }
210
rtw_generate_ie(struct registry_priv * pregistrypriv)211 int rtw_generate_ie(struct registry_priv *pregistrypriv)
212 {
213 u8 wireless_mode;
214 int sz = 0, rateLen;
215 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
216 u8 *ie = pdev_network->IEs;
217
218 /* timestamp will be inserted by hardware */
219 sz += 8;
220 ie += sz;
221
222 /* beacon interval : 2bytes */
223 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);/* BCN_INTERVAL; */
224 sz += 2;
225 ie += 2;
226
227 /* capability info */
228 *(u16 *)ie = 0;
229
230 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
231
232 if (pregistrypriv->preamble == PREAMBLE_SHORT)
233 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
234
235 if (pdev_network->Privacy)
236 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
237
238 sz += 2;
239 ie += 2;
240
241 /* SSID */
242 ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
243
244 /* supported rates */
245 wireless_mode = pregistrypriv->wireless_mode;
246
247 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
248
249 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
250
251 if (rateLen > 8) {
252 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
253 /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
254 } else {
255 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
256 }
257
258 /* DS parameter set */
259 ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&pdev_network->Configuration.DSConfig, &sz);
260
261 /* IBSS Parameter Set */
262
263 ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
264
265 if (rateLen > 8)
266 ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
267
268 return sz;
269 }
270
rtw_get_wpa_ie(unsigned char * pie,int * wpa_ie_len,int limit)271 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
272 {
273 int len;
274 u16 val16;
275 __le16 le_tmp;
276 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
277 u8 *pbuf = pie;
278 int limit_new = limit;
279
280 while (1) {
281 pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
282
283 if (pbuf) {
284 /* check if oui matches... */
285 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
286 goto check_next_ie;
287
288 /* check version... */
289 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
290
291 val16 = le16_to_cpu(le_tmp);
292 if (val16 != 0x0001)
293 goto check_next_ie;
294 *wpa_ie_len = *(pbuf + 1);
295 return pbuf;
296 }
297 *wpa_ie_len = 0;
298 return NULL;
299
300 check_next_ie:
301 limit_new = limit - (pbuf - pie) - 2 - len;
302 if (limit_new <= 0)
303 break;
304 pbuf += (2 + len);
305 }
306 *wpa_ie_len = 0;
307 return NULL;
308 }
309
rtw_get_wpa2_ie(unsigned char * pie,int * rsn_ie_len,int limit)310 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
311 {
312
313 return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
314 }
315
rtw_get_wpa_cipher_suite(u8 * s)316 int rtw_get_wpa_cipher_suite(u8 *s)
317 {
318 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
319 return WPA_CIPHER_NONE;
320 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
321 return WPA_CIPHER_WEP40;
322 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
323 return WPA_CIPHER_TKIP;
324 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
325 return WPA_CIPHER_CCMP;
326 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
327 return WPA_CIPHER_WEP104;
328
329 return 0;
330 }
331
rtw_get_wpa2_cipher_suite(u8 * s)332 int rtw_get_wpa2_cipher_suite(u8 *s)
333 {
334 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
335 return WPA_CIPHER_NONE;
336 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
337 return WPA_CIPHER_WEP40;
338 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
339 return WPA_CIPHER_TKIP;
340 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
341 return WPA_CIPHER_CCMP;
342 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
343 return WPA_CIPHER_WEP104;
344
345 return 0;
346 }
347
rtw_parse_wpa_ie(u8 * wpa_ie,int wpa_ie_len,int * group_cipher,int * pairwise_cipher,int * is_8021x)348 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
349 {
350 int i, ret = _SUCCESS;
351 int left, count;
352 u8 *pos;
353 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
354
355 if (wpa_ie_len <= 0) {
356 /* No WPA IE - fail silently */
357 return _FAIL;
358 }
359
360 if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
361 (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
362 return _FAIL;
363
364 pos = wpa_ie;
365
366 pos += 8;
367 left = wpa_ie_len - 8;
368
369 /* group_cipher */
370 if (left >= WPA_SELECTOR_LEN) {
371 *group_cipher = rtw_get_wpa_cipher_suite(pos);
372 pos += WPA_SELECTOR_LEN;
373 left -= WPA_SELECTOR_LEN;
374 } else if (left > 0) {
375 return _FAIL;
376 }
377
378 /* pairwise_cipher */
379 if (left >= 2) {
380 count = get_unaligned_le16(pos);
381 pos += 2;
382 left -= 2;
383
384 if (count == 0 || left < count * WPA_SELECTOR_LEN)
385 return _FAIL;
386
387 for (i = 0; i < count; i++) {
388 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
389
390 pos += WPA_SELECTOR_LEN;
391 left -= WPA_SELECTOR_LEN;
392 }
393 } else if (left == 1) {
394 return _FAIL;
395 }
396
397 if (is_8021x) {
398 if (left >= 6) {
399 pos += 2;
400 if (!memcmp(pos, SUITE_1X, 4))
401 *is_8021x = 1;
402 }
403 }
404
405 return ret;
406 }
407
rtw_parse_wpa2_ie(u8 * rsn_ie,int rsn_ie_len,int * group_cipher,int * pairwise_cipher,int * is_8021x)408 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
409 {
410 int i, ret = _SUCCESS;
411 int left, count;
412 u8 *pos;
413 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
414
415 if (rsn_ie_len <= 0) {
416 /* No RSN IE - fail silently */
417 return _FAIL;
418 }
419
420 if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
421 return _FAIL;
422
423 pos = rsn_ie;
424 pos += 4;
425 left = rsn_ie_len - 4;
426
427 /* group_cipher */
428 if (left >= RSN_SELECTOR_LEN) {
429 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
430
431 pos += RSN_SELECTOR_LEN;
432 left -= RSN_SELECTOR_LEN;
433
434 } else if (left > 0) {
435 return _FAIL;
436 }
437
438 /* pairwise_cipher */
439 if (left >= 2) {
440 count = get_unaligned_le16(pos);
441 pos += 2;
442 left -= 2;
443
444 if (count == 0 || left < count * RSN_SELECTOR_LEN)
445 return _FAIL;
446
447 for (i = 0; i < count; i++) {
448 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
449
450 pos += RSN_SELECTOR_LEN;
451 left -= RSN_SELECTOR_LEN;
452 }
453
454 } else if (left == 1) {
455 return _FAIL;
456 }
457
458 if (is_8021x) {
459 if (left >= 6) {
460 pos += 2;
461 if (!memcmp(pos, SUITE_1X, 4))
462 *is_8021x = 1;
463 }
464 }
465 return ret;
466 }
467
rtw_get_sec_ie(u8 * in_ie,uint in_len,u8 * rsn_ie,u16 * rsn_len,u8 * wpa_ie,u16 * wpa_len)468 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
469 {
470 u8 authmode;
471 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
472 uint cnt;
473
474 /* Search required WPA or WPA2 IE and copy to sec_ie[] */
475
476 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
477
478 while (cnt < in_len) {
479 authmode = in_ie[cnt];
480
481 if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
482 if (wpa_ie)
483 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
484
485 *wpa_len = in_ie[cnt + 1] + 2;
486 cnt += in_ie[cnt + 1] + 2; /* get next */
487 } else {
488 if (authmode == _WPA2_IE_ID_) {
489 if (rsn_ie)
490 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
491
492 *rsn_len = in_ie[cnt + 1] + 2;
493 cnt += in_ie[cnt + 1] + 2; /* get next */
494 } else {
495 cnt += in_ie[cnt + 1] + 2; /* get next */
496 }
497 }
498 }
499
500 return *rsn_len + *wpa_len;
501 }
502
rtw_is_wps_ie(u8 * ie_ptr,uint * wps_ielen)503 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
504 {
505 u8 match = false;
506 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
507
508 if (!ie_ptr)
509 return match;
510
511 eid = ie_ptr[0];
512
513 if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
514 *wps_ielen = ie_ptr[1] + 2;
515 match = true;
516 }
517 return match;
518 }
519
520 /**
521 * rtw_get_wps_ie - Search WPS IE from a series of IEs
522 * @in_ie: Address of IEs to search
523 * @in_len: Length limit from in_ie
524 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
525 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
526 *
527 * Returns: The address of the WPS IE found, or NULL
528 */
rtw_get_wps_ie(u8 * in_ie,uint in_len,u8 * wps_ie,uint * wps_ielen)529 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
530 {
531 uint cnt;
532 u8 *wpsie_ptr = NULL;
533 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
534
535 if (wps_ielen)
536 *wps_ielen = 0;
537
538 if (!in_ie || in_len <= 0)
539 return wpsie_ptr;
540
541 cnt = 0;
542
543 while (cnt < in_len) {
544 eid = in_ie[cnt];
545
546 if ((eid == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
547 wpsie_ptr = &in_ie[cnt];
548
549 if (wps_ie)
550 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
551
552 if (wps_ielen)
553 *wps_ielen = in_ie[cnt + 1] + 2;
554
555 cnt += in_ie[cnt + 1] + 2;
556
557 break;
558 }
559 cnt += in_ie[cnt + 1] + 2; /* goto next */
560 }
561 return wpsie_ptr;
562 }
563
564 /**
565 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
566 * @wps_ie: Address of WPS IE to search
567 * @wps_ielen: Length limit from wps_ie
568 * @target_attr_id: The attribute ID of WPS attribute to search
569 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
570 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
571 *
572 * Returns: the address of the specific WPS attribute found, or NULL
573 */
rtw_get_wps_attr(u8 * wps_ie,uint wps_ielen,u16 target_attr_id,u8 * buf_attr,u32 * len_attr)574 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
575 {
576 u8 *attr_ptr = NULL;
577 u8 *target_attr_ptr = NULL;
578 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
579
580 if (len_attr)
581 *len_attr = 0;
582
583 if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
584 (memcmp(wps_ie + 2, wps_oui, 4)))
585 return attr_ptr;
586
587 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
588 attr_ptr = wps_ie + 6; /* goto first attr */
589
590 while (attr_ptr - wps_ie < wps_ielen) {
591 /* 4 = 2(Attribute ID) + 2(Length) */
592 u16 attr_id = RTW_GET_BE16(attr_ptr);
593 u16 attr_data_len = RTW_GET_BE16(attr_ptr + 2);
594 u16 attr_len = attr_data_len + 4;
595
596 if (attr_id == target_attr_id) {
597 target_attr_ptr = attr_ptr;
598 if (buf_attr)
599 memcpy(buf_attr, attr_ptr, attr_len);
600 if (len_attr)
601 *len_attr = attr_len;
602 break;
603 }
604 attr_ptr += attr_len; /* goto next */
605 }
606 return target_attr_ptr;
607 }
608
609 /**
610 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
611 * @wps_ie: Address of WPS IE to search
612 * @wps_ielen: Length limit from wps_ie
613 * @target_attr_id: The attribute ID of WPS attribute to search
614 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
615 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
616 *
617 * Returns: the address of the specific WPS attribute content found, or NULL
618 */
rtw_get_wps_attr_content(u8 * wps_ie,uint wps_ielen,u16 target_attr_id,u8 * buf_content,uint * len_content)619 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
620 {
621 u8 *attr_ptr;
622 u32 attr_len;
623
624 if (len_content)
625 *len_content = 0;
626
627 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
628
629 if (attr_ptr && attr_len) {
630 if (buf_content)
631 memcpy(buf_content, attr_ptr + 4, attr_len - 4);
632
633 if (len_content)
634 *len_content = attr_len - 4;
635
636 return attr_ptr + 4;
637 }
638
639 return NULL;
640 }
641
rtw_ieee802_11_parse_vendor_specific(u8 * pos,uint elen,struct rtw_ieee802_11_elems * elems,int show_errors)642 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
643 struct rtw_ieee802_11_elems *elems,
644 int show_errors)
645 {
646 unsigned int oui;
647
648 /* first 3 bytes in vendor specific information element are the IEEE
649 * OUI of the vendor. The following byte is used a vendor specific
650 * sub-type. */
651 if (elen < 4)
652 return -1;
653
654 oui = RTW_GET_BE24(pos);
655 switch (oui) {
656 case OUI_MICROSOFT:
657 /* Microsoft/Wi-Fi information elements are further typed and
658 * subtyped */
659 switch (pos[3]) {
660 case 1:
661 /* Microsoft OUI (00:50:F2) with OUI Type 1:
662 * real WPA information element */
663 elems->wpa_ie = pos;
664 elems->wpa_ie_len = elen;
665 break;
666 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
667 if (elen < 5)
668 return -1;
669 switch (pos[4]) {
670 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
671 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
672 elems->wme = pos;
673 elems->wme_len = elen;
674 break;
675 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
676 elems->wme_tspec = pos;
677 elems->wme_tspec_len = elen;
678 break;
679 default:
680 return -1;
681 }
682 break;
683 case 4:
684 /* Wi-Fi Protected Setup (WPS) IE */
685 elems->wps_ie = pos;
686 elems->wps_ie_len = elen;
687 break;
688 default:
689 return -1;
690 }
691 break;
692
693 case OUI_BROADCOM:
694 switch (pos[3]) {
695 case VENDOR_HT_CAPAB_OUI_TYPE:
696 elems->vendor_ht_cap = pos;
697 elems->vendor_ht_cap_len = elen;
698 break;
699 default:
700 return -1;
701 }
702 break;
703 default:
704 return -1;
705 }
706 return 0;
707 }
708
709 /**
710 * ieee802_11_parse_elems - Parse information elements in management frames
711 * @start: Pointer to the start of IEs
712 * @len: Length of IE buffer in octets
713 * @elems: Data structure for parsed elements
714 * @show_errors: Whether to show parsing errors in debug log
715 * Returns: Parsing result
716 */
rtw_ieee802_11_parse_elems(u8 * start,uint len,struct rtw_ieee802_11_elems * elems,int show_errors)717 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
718 struct rtw_ieee802_11_elems *elems,
719 int show_errors)
720 {
721 uint left = len;
722 u8 *pos = start;
723 int unknown = 0;
724
725 memset(elems, 0, sizeof(*elems));
726
727 while (left >= 2) {
728 u8 id, elen;
729
730 id = *pos++;
731 elen = *pos++;
732 left -= 2;
733
734 if (elen > left)
735 return ParseFailed;
736
737 switch (id) {
738 case WLAN_EID_SSID:
739 elems->ssid = pos;
740 elems->ssid_len = elen;
741 break;
742 case WLAN_EID_SUPP_RATES:
743 elems->supp_rates = pos;
744 elems->supp_rates_len = elen;
745 break;
746 case WLAN_EID_FH_PARAMS:
747 elems->fh_params = pos;
748 elems->fh_params_len = elen;
749 break;
750 case WLAN_EID_DS_PARAMS:
751 elems->ds_params = pos;
752 elems->ds_params_len = elen;
753 break;
754 case WLAN_EID_CF_PARAMS:
755 elems->cf_params = pos;
756 elems->cf_params_len = elen;
757 break;
758 case WLAN_EID_TIM:
759 elems->tim = pos;
760 elems->tim_len = elen;
761 break;
762 case WLAN_EID_IBSS_PARAMS:
763 elems->ibss_params = pos;
764 elems->ibss_params_len = elen;
765 break;
766 case WLAN_EID_CHALLENGE:
767 elems->challenge = pos;
768 elems->challenge_len = elen;
769 break;
770 case WLAN_EID_ERP_INFO:
771 elems->erp_info = pos;
772 elems->erp_info_len = elen;
773 break;
774 case WLAN_EID_EXT_SUPP_RATES:
775 elems->ext_supp_rates = pos;
776 elems->ext_supp_rates_len = elen;
777 break;
778 case WLAN_EID_VENDOR_SPECIFIC:
779 if (rtw_ieee802_11_parse_vendor_specific(pos, elen, elems, show_errors))
780 unknown++;
781 break;
782 case WLAN_EID_RSN:
783 elems->rsn_ie = pos;
784 elems->rsn_ie_len = elen;
785 break;
786 case WLAN_EID_PWR_CAPABILITY:
787 elems->power_cap = pos;
788 elems->power_cap_len = elen;
789 break;
790 case WLAN_EID_SUPPORTED_CHANNELS:
791 elems->supp_channels = pos;
792 elems->supp_channels_len = elen;
793 break;
794 case WLAN_EID_MOBILITY_DOMAIN:
795 elems->mdie = pos;
796 elems->mdie_len = elen;
797 break;
798 case WLAN_EID_FAST_BSS_TRANSITION:
799 elems->ftie = pos;
800 elems->ftie_len = elen;
801 break;
802 case WLAN_EID_TIMEOUT_INTERVAL:
803 elems->timeout_int = pos;
804 elems->timeout_int_len = elen;
805 break;
806 case WLAN_EID_HT_CAP:
807 elems->ht_capabilities = pos;
808 elems->ht_capabilities_len = elen;
809 break;
810 case WLAN_EID_HT_OPERATION:
811 elems->ht_operation = pos;
812 elems->ht_operation_len = elen;
813 break;
814 default:
815 unknown++;
816 break;
817 }
818 left -= elen;
819 pos += elen;
820 }
821 if (left)
822 return ParseFailed;
823 return unknown ? ParseUnknown : ParseOK;
824 }
825
key_char2num(u8 ch)826 u8 key_char2num(u8 ch)
827 {
828 if ((ch >= '0') && (ch <= '9'))
829 return ch - '0';
830 else if ((ch >= 'a') && (ch <= 'f'))
831 return ch - 'a' + 10;
832 else if ((ch >= 'A') && (ch <= 'F'))
833 return ch - 'A' + 10;
834 else
835 return 0xff;
836 }
837
str_2char2num(u8 hch,u8 lch)838 u8 str_2char2num(u8 hch, u8 lch)
839 {
840 return (key_char2num(hch) * 10) + key_char2num(lch);
841 }
842
key_2char2num(u8 hch,u8 lch)843 u8 key_2char2num(u8 hch, u8 lch)
844 {
845 return (key_char2num(hch) << 4) | key_char2num(lch);
846 }
847
rtw_macaddr_cfg(u8 * mac_addr)848 void rtw_macaddr_cfg(u8 *mac_addr)
849 {
850 u8 mac[ETH_ALEN];
851
852 if (!mac_addr)
853 return;
854
855 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
856 /* Users specify the mac address */
857 ether_addr_copy(mac_addr, mac);
858 } else {
859 /* Use the mac address stored in the Efuse */
860 ether_addr_copy(mac, mac_addr);
861 }
862
863 if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac))
864 eth_random_addr(mac_addr);
865 }
866
867 /**
868 * rtw_get_p2p_ie - Search P2P IE from a series of IEs
869 * @in_ie: Address of IEs to search
870 * @in_len: Length limit from in_ie
871 * @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the buf starting from p2p_ie
872 * @p2p_ielen: If not NULL and P2P IE is found, will set to the length of the entire P2P IE
873 *
874 * Returns: The address of the P2P IE found, or NULL
875 */
rtw_get_p2p_ie(u8 * in_ie,int in_len,u8 * p2p_ie,uint * p2p_ielen)876 u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
877 {
878 uint cnt = 0;
879 u8 *p2p_ie_ptr;
880 u8 eid, p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
881
882 if (p2p_ielen)
883 *p2p_ielen = 0;
884
885 while (cnt < in_len) {
886 eid = in_ie[cnt];
887 if ((in_len < 0) || (cnt > MAX_IE_SZ)) {
888 dump_stack();
889 return NULL;
890 }
891 if ((eid == _VENDOR_SPECIFIC_IE_) && !memcmp(&in_ie[cnt + 2], p2p_oui, 4)) {
892 p2p_ie_ptr = in_ie + cnt;
893
894 if (p2p_ie)
895 memcpy(p2p_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
896 if (p2p_ielen)
897 *p2p_ielen = in_ie[cnt + 1] + 2;
898 return p2p_ie_ptr;
899 }
900 cnt += in_ie[cnt + 1] + 2; /* goto next */
901 }
902 return NULL;
903 }
904
905 /**
906 * rtw_get_p2p_attr - Search a specific P2P attribute from a given P2P IE
907 * @p2p_ie: Address of P2P IE to search
908 * @p2p_ielen: Length limit from p2p_ie
909 * @target_attr_id: The attribute ID of P2P attribute to search
910 * @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will be copied to the buf starting from buf_attr
911 * @len_attr: If not NULL and the P2P attribute is found, will set to the length of the entire P2P attribute
912 *
913 * Returns: the address of the specific WPS attribute found, or NULL
914 */
rtw_get_p2p_attr(u8 * p2p_ie,uint p2p_ielen,u8 target_attr_id,u8 * buf_attr,u32 * len_attr)915 u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr)
916 {
917 u8 *attr_ptr = NULL;
918 u8 *target_attr_ptr = NULL;
919 u8 p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};
920
921 if (len_attr)
922 *len_attr = 0;
923
924 if (!p2p_ie || (p2p_ie[0] != _VENDOR_SPECIFIC_IE_) ||
925 memcmp(p2p_ie + 2, p2p_oui, 4))
926 return attr_ptr;
927
928 /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
929 attr_ptr = p2p_ie + 6; /* goto first attr */
930
931 while (attr_ptr - p2p_ie < p2p_ielen) {
932 /* 3 = 1(Attribute ID) + 2(Length) */
933 u8 attr_id = *attr_ptr;
934 u16 attr_data_len = get_unaligned_le16(attr_ptr + 1);
935 u16 attr_len = attr_data_len + 3;
936
937 if (attr_id == target_attr_id) {
938 target_attr_ptr = attr_ptr;
939
940 if (buf_attr)
941 memcpy(buf_attr, attr_ptr, attr_len);
942 if (len_attr)
943 *len_attr = attr_len;
944 break;
945 }
946 attr_ptr += attr_len; /* goto next */
947 }
948 return target_attr_ptr;
949 }
950
951 /**
952 * rtw_get_p2p_attr_content - Search a specific P2P attribute content from a given P2P IE
953 * @p2p_ie: Address of P2P IE to search
954 * @p2p_ielen: Length limit from p2p_ie
955 * @target_attr_id: The attribute ID of P2P attribute to search
956 * @buf_content: If not NULL and the P2P attribute is found, P2P attribute content will be copied to the buf starting from buf_content
957 * @len_content: If not NULL and the P2P attribute is found, will set to the length of the P2P attribute content
958 *
959 * Returns: the address of the specific P2P attribute content found, or NULL
960 */
rtw_get_p2p_attr_content(u8 * p2p_ie,uint p2p_ielen,u8 target_attr_id,u8 * buf_content,uint * len_content)961 u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content)
962 {
963 u8 *attr_ptr;
964 u32 attr_len;
965
966 if (len_content)
967 *len_content = 0;
968
969 attr_ptr = rtw_get_p2p_attr(p2p_ie, p2p_ielen, target_attr_id, NULL, &attr_len);
970
971 if (attr_ptr && attr_len) {
972 if (buf_content)
973 memcpy(buf_content, attr_ptr + 3, attr_len - 3);
974
975 if (len_content)
976 *len_content = attr_len - 3;
977
978 return attr_ptr + 3;
979 }
980
981 return NULL;
982 }
983
rtw_set_p2p_attr_content(u8 * pbuf,u8 attr_id,u16 attr_len,u8 * pdata_attr)984 u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)
985 {
986 u32 a_len;
987
988 *pbuf = attr_id;
989
990 /* u16*)(pbuf + 1) = cpu_to_le16(attr_len); */
991 RTW_PUT_LE16(pbuf + 1, attr_len);
992
993 if (pdata_attr)
994 memcpy(pbuf + 3, pdata_attr, attr_len);
995
996 a_len = attr_len + 3;
997
998 return a_len;
999 }
1000
rtw_p2p_attr_remove(u8 * ie,uint ielen_ori,u8 attr_id)1001 static uint rtw_p2p_attr_remove(u8 *ie, uint ielen_ori, u8 attr_id)
1002 {
1003 u8 *target_attr;
1004 u32 target_attr_len;
1005 uint ielen = ielen_ori;
1006
1007 while (1) {
1008 target_attr = rtw_get_p2p_attr(ie, ielen, attr_id, NULL, &target_attr_len);
1009 if (target_attr && target_attr_len) {
1010 u8 *next_attr = target_attr + target_attr_len;
1011 uint remain_len = ielen - (next_attr - ie);
1012
1013 memset(target_attr, 0, target_attr_len);
1014 memcpy(target_attr, next_attr, remain_len);
1015 memset(target_attr + remain_len, 0, target_attr_len);
1016 *(ie + 1) -= target_attr_len;
1017 ielen -= target_attr_len;
1018 } else {
1019 break;
1020 }
1021 }
1022 return ielen;
1023 }
1024
rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex * bss_ex,u8 attr_id)1025 void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex, u8 attr_id)
1026 {
1027 u8 *p2p_ie;
1028 uint p2p_ielen, p2p_ielen_ori;
1029
1030 p2p_ie = rtw_get_p2p_ie(bss_ex->IEs + _FIXED_IE_LENGTH_, bss_ex->IELength - _FIXED_IE_LENGTH_, NULL, &p2p_ielen_ori);
1031 if (p2p_ie) {
1032 p2p_ielen = rtw_p2p_attr_remove(p2p_ie, p2p_ielen_ori, attr_id);
1033 if (p2p_ielen != p2p_ielen_ori) {
1034 u8 *next_ie_ori = p2p_ie + p2p_ielen_ori;
1035 u8 *next_ie = p2p_ie + p2p_ielen;
1036 uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);
1037
1038 memcpy(next_ie, next_ie_ori, remain_len);
1039 memset(next_ie + remain_len, 0, p2p_ielen_ori - p2p_ielen);
1040 bss_ex->IELength -= p2p_ielen_ori - p2p_ielen;
1041 }
1042 }
1043 }
1044
rtw_get_cipher_info(struct wlan_network * pnetwork)1045 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1046 {
1047 u32 wpa_ielen;
1048 unsigned char *pbuf;
1049 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1050 int ret = _FAIL;
1051 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1052
1053 if (pbuf && (wpa_ielen > 0)) {
1054 if (rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x) == _SUCCESS) {
1055 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1056 pnetwork->BcnInfo.group_cipher = group_cipher;
1057 pnetwork->BcnInfo.is_8021x = is8021x;
1058 ret = _SUCCESS;
1059 }
1060 } else {
1061 pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1062
1063 if (pbuf && (wpa_ielen > 0)) {
1064 if (rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x) == _SUCCESS) {
1065 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1066 pnetwork->BcnInfo.group_cipher = group_cipher;
1067 pnetwork->BcnInfo.is_8021x = is8021x;
1068 ret = _SUCCESS;
1069 }
1070 }
1071 }
1072
1073 return ret;
1074 }
1075
rtw_get_bcn_info(struct wlan_network * pnetwork)1076 void rtw_get_bcn_info(struct wlan_network *pnetwork)
1077 {
1078 unsigned short cap = 0;
1079 u8 bencrypt = 0;
1080 __le16 le_tmp;
1081 u16 wpa_len = 0, rsn_len = 0;
1082 struct HT_info_element *pht_info = NULL;
1083 struct ieee80211_ht_cap *pht_cap = NULL;
1084 unsigned int len;
1085 unsigned char *p;
1086
1087 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
1088 cap = le16_to_cpu(le_tmp);
1089 if (cap & WLAN_CAPABILITY_PRIVACY) {
1090 bencrypt = 1;
1091 pnetwork->network.Privacy = 1;
1092 } else {
1093 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1094 }
1095 rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
1096
1097 if (rsn_len > 0) {
1098 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1099 } else if (wpa_len > 0) {
1100 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1101 } else {
1102 if (bencrypt)
1103 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1104 }
1105 rtw_get_cipher_info(pnetwork);
1106
1107 /* get bwmode and ch_offset */
1108 /* parsing HT_CAP_IE */
1109 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1110 if (p && len > 0) {
1111 pht_cap = (struct ieee80211_ht_cap *)(p + 2);
1112 pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(pht_cap->cap_info);
1113 } else {
1114 pnetwork->BcnInfo.ht_cap_info = 0;
1115 }
1116 /* parsing HT_INFO_IE */
1117 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1118 if (p && len > 0) {
1119 pht_info = (struct HT_info_element *)(p + 2);
1120 pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1121 } else {
1122 pnetwork->BcnInfo.ht_info_infos_0 = 0;
1123 }
1124 }
1125
1126 /* show MCS rate, unit: 100Kbps */
rtw_mcs_rate(u8 bw_40MHz,u8 short_GI_20,u8 short_GI_40,unsigned char * MCS_rate)1127 u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate)
1128 {
1129 u16 max_rate = 0;
1130
1131 if (MCS_rate[0] & BIT(7))
1132 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1133 else if (MCS_rate[0] & BIT(6))
1134 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1135 else if (MCS_rate[0] & BIT(5))
1136 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1137 else if (MCS_rate[0] & BIT(4))
1138 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1139 else if (MCS_rate[0] & BIT(3))
1140 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1141 else if (MCS_rate[0] & BIT(2))
1142 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1143 else if (MCS_rate[0] & BIT(1))
1144 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1145 else if (MCS_rate[0] & BIT(0))
1146 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1147
1148 return max_rate;
1149 }
1150