1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
9 #include <linux/ieee80211.h>
11 #include <drv_types.h>
12 #include <osdep_intf.h>
13 #include <ieee80211.h>
15 #include <osdep_service.h>
16 #include <wlan_bssdef.h>
18 u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
19 u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
20 u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
21 u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
22 u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
23 u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
24 u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
25 u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
26 u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
27 u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
29 u16 RSN_VERSION_BSD = 1;
30 u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
31 u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
32 u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
33 u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
34 u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
35 u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
36 u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
37 u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
39 /* for adhoc-master to generate ie and provide supported-rate to fw */
42 static u8 WIFI_CCKRATES[] = {
43 IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK,
44 IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK,
45 IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK,
46 IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK
49 static u8 WIFI_OFDMRATES[] = {
50 IEEE80211_OFDM_RATE_6MB,
51 IEEE80211_OFDM_RATE_9MB,
52 IEEE80211_OFDM_RATE_12MB,
53 IEEE80211_OFDM_RATE_18MB,
54 IEEE80211_OFDM_RATE_24MB,
55 IEEE80211_OFDM_RATE_36MB,
56 IEEE80211_OFDM_RATE_48MB,
57 IEEE80211_OFDM_RATE_54MB
60 int rtw_get_bit_value_from_ieee_value(u8 val)
62 static const unsigned char dot11_rate_table[] = {
63 2, 4, 11, 22, 12, 18, 24, 36, 48,
64 72, 96, 108, 0}; /* last element must be zero!! */
67 while (dot11_rate_table[i] != 0) {
68 if (dot11_rate_table[i] == val)
75 bool rtw_is_cckrates_included(u8 *rate)
80 if (r == 2 || r == 4 || r == 11 || r == 22)
88 bool rtw_is_cckratesonly_included(u8 *rate)
93 if (r != 2 && r != 4 && r != 11 && r != 22)
101 int rtw_check_network_type(unsigned char *rate)
103 /* could be pure B, pure G, or B/G */
104 if (rtw_is_cckratesonly_included(rate))
106 else if (rtw_is_cckrates_included(rate))
107 return WIRELESS_11BG;
112 u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source,
115 memcpy(pbuf, source, len);
116 *frlen = *frlen + len;
117 return ((u8 *)pbuf) + len;
120 /* rtw_set_ie will update frame length */
127 uint *frlen /* frame length */
132 *(pbuf + 1) = (u8)len;
135 memcpy((void *)(pbuf + 2), (void *)source, len);
137 *frlen = *frlen + (len + 2);
139 return pbuf + len + 2;
143 * ----------------------------------------------------------------------------
144 * index: the information element id index, limit is the limit for search
145 * ----------------------------------------------------------------------------
147 u8 *rtw_get_ie(u8 *pbuf, int index, uint *len, int limit)
172 void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
174 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
178 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
183 case WIRELESS_11A_5N:/* Todo: no basic rate for ofdm ? */
184 memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
187 case WIRELESS_11G_24N:
188 case WIRELESS_11_24N:
189 case WIRELESS_11BG_24N:
190 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
191 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
196 uint rtw_get_rateset_len(u8 *rateset)
200 for (i = 0; i < 13; i++)
206 int rtw_generate_ie(struct registry_priv *pregistrypriv)
211 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
212 u8 *ie = pdev_network->ies;
214 /* timestamp will be inserted by hardware */
218 /* beacon interval : 2bytes */
219 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);/* BCN_INTERVAL; */
223 /* capability info */
226 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
228 if (pregistrypriv->preamble == PREAMBLE_SHORT)
229 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
231 if (pdev_network->Privacy)
232 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
238 ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->ssid.ssid_length, pdev_network->ssid.ssid, &sz);
240 /* supported rates */
241 if (pregistrypriv->wireless_mode == WIRELESS_11ABGN)
242 wireless_mode = WIRELESS_11BG_24N;
244 wireless_mode = pregistrypriv->wireless_mode;
246 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
248 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
251 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
252 /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
254 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
257 /* DS parameter set */
258 ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&pdev_network->Configuration.DSConfig, &sz);
260 /* IBSS Parameter Set */
262 ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
265 ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
270 unsigned char *rtw_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit)
275 static const unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
277 int limit_new = limit;
280 pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
283 /* check if oui matches... */
284 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
287 /* check version... */
288 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
290 val16 = le16_to_cpu(le_tmp);
293 *wpa_ie_len = *(pbuf + 1);
300 limit_new = limit - (pbuf - pie) - 2 - len;
309 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, uint *rsn_ie_len, int limit)
311 return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
314 int rtw_get_wpa_cipher_suite(u8 *s)
316 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
317 return WPA_CIPHER_NONE;
318 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
319 return WPA_CIPHER_WEP40;
320 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
321 return WPA_CIPHER_TKIP;
322 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
323 return WPA_CIPHER_CCMP;
324 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
325 return WPA_CIPHER_WEP104;
330 int rtw_get_wpa2_cipher_suite(u8 *s)
332 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
333 return WPA_CIPHER_NONE;
334 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
335 return WPA_CIPHER_WEP40;
336 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
337 return WPA_CIPHER_TKIP;
338 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
339 return WPA_CIPHER_CCMP;
340 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
341 return WPA_CIPHER_WEP104;
346 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
348 int i, ret = _SUCCESS;
351 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
353 if (wpa_ie_len <= 0) {
354 /* No WPA IE - fail silently */
358 if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
359 (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
365 left = wpa_ie_len - 8;
368 if (left >= WPA_SELECTOR_LEN) {
369 *group_cipher = rtw_get_wpa_cipher_suite(pos);
370 pos += WPA_SELECTOR_LEN;
371 left -= WPA_SELECTOR_LEN;
372 } else if (left > 0) {
373 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
377 /* pairwise_cipher */
379 count = get_unaligned_le16(pos);
383 if (count == 0 || left < count * WPA_SELECTOR_LEN) {
384 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), count %u left %u",
385 __func__, count, left));
389 for (i = 0; i < count; i++) {
390 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
392 pos += WPA_SELECTOR_LEN;
393 left -= WPA_SELECTOR_LEN;
395 } else if (left == 1) {
396 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
403 if (!memcmp(pos, SUITE_1X, 4)) {
404 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s : there has 802.1x auth\n", __func__));
413 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
415 int i, ret = _SUCCESS;
418 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
420 if (rsn_ie_len <= 0) {
421 /* No RSN IE - fail silently */
425 if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
430 left = rsn_ie_len - 4;
433 if (left >= RSN_SELECTOR_LEN) {
434 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
436 pos += RSN_SELECTOR_LEN;
437 left -= RSN_SELECTOR_LEN;
439 } else if (left > 0) {
440 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
444 /* pairwise_cipher */
446 count = get_unaligned_le16(pos);
450 if (count == 0 || left < count * RSN_SELECTOR_LEN) {
451 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), count %u left %u",
452 __func__, count, left));
456 for (i = 0; i < count; i++) {
457 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
459 pos += RSN_SELECTOR_LEN;
460 left -= RSN_SELECTOR_LEN;
463 } else if (left == 1) {
464 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
472 if (!memcmp(pos, SUITE_1X, 4)) {
473 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s (): there has 802.1x auth\n", __func__));
481 void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
483 u8 authmode, sec_idx, i;
484 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
487 /* Search required WPA or WPA2 IE and copy to sec_ie[] */
489 cnt = _TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_;
493 while (cnt < in_len) {
494 authmode = in_ie[cnt];
496 if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
497 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
498 ("\n rtw_get_wpa_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
499 sec_idx, in_ie[cnt + 1] + 2));
502 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
504 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
505 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
506 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
507 wpa_ie[i], wpa_ie[i + 1], wpa_ie[i + 2], wpa_ie[i + 3], wpa_ie[i + 4],
508 wpa_ie[i + 5], wpa_ie[i + 6], wpa_ie[i + 7]));
512 *wpa_len = in_ie[cnt + 1] + 2;
513 cnt += in_ie[cnt + 1] + 2; /* get next */
515 if (authmode == _WPA2_IE_ID_) {
516 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
517 ("\n get_rsn_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
518 sec_idx, in_ie[cnt + 1] + 2));
521 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
523 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
524 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
525 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
526 rsn_ie[i], rsn_ie[i + 1], rsn_ie[i + 2], rsn_ie[i + 3], rsn_ie[i + 4],
527 rsn_ie[i + 5], rsn_ie[i + 6], rsn_ie[i + 7]));
531 *rsn_len = in_ie[cnt + 1] + 2;
532 cnt += in_ie[cnt + 1] + 2; /* get next */
534 cnt += in_ie[cnt + 1] + 2; /* get next */
540 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
543 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
550 if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
551 *wps_ielen = ie_ptr[1] + 2;
558 * rtw_get_wps_ie - Search WPS IE from a series of ies
559 * @in_ie: Address of ies to search
560 * @in_len: Length limit from in_ie
561 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
562 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
564 * Returns: The address of the WPS IE found, or NULL
566 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
569 u8 *wpsie_ptr = NULL;
570 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
575 if (!in_ie || in_len <= 0)
580 while (cnt < in_len) {
583 if ((eid == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
584 wpsie_ptr = &in_ie[cnt];
587 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
590 *wps_ielen = in_ie[cnt + 1] + 2;
592 cnt += in_ie[cnt + 1] + 2;
596 cnt += in_ie[cnt + 1] + 2; /* goto next */
602 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
603 * @wps_ie: Address of WPS IE to search
604 * @wps_ielen: Length limit from wps_ie
605 * @target_attr_id: The attribute ID of WPS attribute to search
606 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
607 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
609 * Returns: the address of the specific WPS attribute found, or NULL
611 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
614 u8 *target_attr_ptr = NULL;
615 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
620 if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
621 (memcmp(wps_ie + 2, wps_oui, 4)))
624 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
625 attr_ptr = wps_ie + 6; /* goto first attr */
627 while (attr_ptr - wps_ie < wps_ielen) {
628 /* 4 = 2(Attribute ID) + 2(Length) */
629 u16 attr_id = get_unaligned_be16(attr_ptr);
630 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
631 u16 attr_len = attr_data_len + 4;
633 if (attr_id == target_attr_id) {
634 target_attr_ptr = attr_ptr;
636 memcpy(buf_attr, attr_ptr, attr_len);
638 *len_attr = attr_len;
641 attr_ptr += attr_len; /* goto next */
643 return target_attr_ptr;
647 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
648 * @wps_ie: Address of WPS IE to search
649 * @wps_ielen: Length limit from wps_ie
650 * @target_attr_id: The attribute ID of WPS attribute to search
651 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
652 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
654 * Returns: the address of the specific WPS attribute content found, or NULL
656 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
664 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
666 if (attr_ptr && attr_len) {
668 memcpy(buf_content, attr_ptr + 4, attr_len - 4);
671 *len_content = attr_len - 4;
679 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
680 struct rtw_ieee802_11_elems *elems, int show_errors)
685 * first 3 bytes in vendor specific information element are the IEEE
686 * OUI of the vendor. The following byte is used a vendor specific
691 DBG_88E("short vendor specific information element ignored (len=%lu)\n",
692 (unsigned long)elen);
697 oui = RTW_GET_BE24(pos);
701 * Microsoft/Wi-Fi information elements are further typed and
707 * Microsoft OUI (00:50:F2) with OUI Type 1:
708 * real WPA information element
711 elems->wpa_ie_len = elen;
713 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
715 DBG_88E("short WME information element ignored (len=%lu)\n",
716 (unsigned long)elen);
720 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
721 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
723 elems->wme_len = elen;
725 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
726 elems->wme_tspec = pos;
727 elems->wme_tspec_len = elen;
730 DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n",
731 pos[4], (unsigned long)elen);
736 /* Wi-Fi Protected Setup (WPS) IE */
738 elems->wps_ie_len = elen;
741 DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n",
742 pos[3], (unsigned long)elen);
749 case VENDOR_HT_CAPAB_OUI_TYPE:
750 elems->vendor_ht_cap = pos;
751 elems->vendor_ht_cap_len = elen;
754 DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n",
755 pos[3], (unsigned long)elen);
760 DBG_88E("unknown vendor specific information element ignored (vendor OUI %3phC len=%lu)\n",
761 pos, (unsigned long)elen);
768 * ieee802_11_parse_elems - Parse information elements in management frames
769 * @start: Pointer to the start of ies
770 * @len: Length of IE buffer in octets
771 * @elems: Data structure for parsed elements
772 * @show_errors: Whether to show parsing errors in debug log
773 * Returns: Parsing result
775 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
776 struct rtw_ieee802_11_elems *elems,
783 memset(elems, 0, sizeof(*elems));
794 DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
795 id, elen, (unsigned long)left);
803 elems->ssid_len = elen;
805 case WLAN_EID_SUPP_RATES:
806 elems->supp_rates = pos;
807 elems->supp_rates_len = elen;
809 case WLAN_EID_FH_PARAMS:
810 elems->fh_params = pos;
811 elems->fh_params_len = elen;
813 case WLAN_EID_DS_PARAMS:
814 elems->ds_params = pos;
815 elems->ds_params_len = elen;
817 case WLAN_EID_CF_PARAMS:
818 elems->cf_params = pos;
819 elems->cf_params_len = elen;
823 elems->tim_len = elen;
825 case WLAN_EID_IBSS_PARAMS:
826 elems->ibss_params = pos;
827 elems->ibss_params_len = elen;
829 case WLAN_EID_CHALLENGE:
830 elems->challenge = pos;
831 elems->challenge_len = elen;
833 case WLAN_EID_ERP_INFO:
834 elems->erp_info = pos;
835 elems->erp_info_len = elen;
837 case WLAN_EID_EXT_SUPP_RATES:
838 elems->ext_supp_rates = pos;
839 elems->ext_supp_rates_len = elen;
841 case WLAN_EID_VENDOR_SPECIFIC:
842 if (rtw_ieee802_11_parse_vendor_specific(pos, elen, elems, show_errors))
847 elems->rsn_ie_len = elen;
849 case WLAN_EID_PWR_CAPABILITY:
850 elems->power_cap = pos;
851 elems->power_cap_len = elen;
853 case WLAN_EID_SUPPORTED_CHANNELS:
854 elems->supp_channels = pos;
855 elems->supp_channels_len = elen;
857 case WLAN_EID_MOBILITY_DOMAIN:
859 elems->mdie_len = elen;
861 case WLAN_EID_FAST_BSS_TRANSITION:
863 elems->ftie_len = elen;
865 case WLAN_EID_TIMEOUT_INTERVAL:
866 elems->timeout_int = pos;
867 elems->timeout_int_len = elen;
869 case WLAN_EID_HT_CAPABILITY:
870 elems->ht_capabilities = pos;
871 elems->ht_capabilities_len = elen;
873 case WLAN_EID_HT_OPERATION:
874 elems->ht_operation = pos;
875 elems->ht_operation_len = elen;
881 DBG_88E("IEEE 802.11 element parse ignored unknown element (id=%d elen=%d)\n",
890 return unknown ? ParseUnknown : ParseOK;
893 void rtw_macaddr_cfg(u8 *mac_addr)
900 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
901 /* Users specify the mac address */
902 ether_addr_copy(mac_addr, mac);
904 /* Use the mac address stored in the Efuse */
905 ether_addr_copy(mac, mac_addr);
908 if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) {
909 eth_random_addr(mac_addr);
910 DBG_88E("MAC Address from efuse error, assign random one !!!\n");
913 DBG_88E("%s MAC Address = %pM\n", __func__, mac_addr);
916 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
920 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
923 pbuf = rtw_get_wpa_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length - 12);
925 if (pbuf && (wpa_ielen > 0)) {
926 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: wpa_ielen: %d", __func__, wpa_ielen));
927 if (rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x) == _SUCCESS) {
928 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
929 pnetwork->BcnInfo.group_cipher = group_cipher;
930 pnetwork->BcnInfo.is_8021x = is8021x;
931 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
932 ("%s: pnetwork->pairwise_cipher: %d, is_8021x is %d",
933 __func__, pnetwork->BcnInfo.pairwise_cipher,
934 pnetwork->BcnInfo.is_8021x));
938 pbuf = rtw_get_wpa2_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length - 12);
940 if (pbuf && (wpa_ielen > 0)) {
941 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE\n"));
942 if (rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x) == _SUCCESS) {
943 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE OK!!!\n"));
944 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
945 pnetwork->BcnInfo.group_cipher = group_cipher;
946 pnetwork->BcnInfo.is_8021x = is8021x;
947 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->pairwise_cipher: %d, pnetwork->group_cipher is %d, is_8021x is %d",
948 __func__, pnetwork->BcnInfo.pairwise_cipher,
949 pnetwork->BcnInfo.group_cipher, pnetwork->BcnInfo.is_8021x));
958 void rtw_get_bcn_info(struct wlan_network *pnetwork)
960 unsigned short cap = 0;
963 u16 wpa_len = 0, rsn_len = 0;
964 struct HT_info_element *pht_info = NULL;
968 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.ies), 2);
969 cap = le16_to_cpu(le_tmp);
970 if (cap & WLAN_CAPABILITY_PRIVACY) {
972 pnetwork->network.Privacy = 1;
974 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
976 rtw_get_sec_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &rsn_len, NULL, &wpa_len);
977 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: ssid =%s\n", __func__, pnetwork->network.ssid.ssid));
978 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: wpa_len =%d rsn_len =%d\n", __func__, wpa_len, rsn_len));
979 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: ssid =%s\n", __func__, pnetwork->network.ssid.ssid));
980 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: wpa_len =%d rsn_len =%d\n", __func__, wpa_len, rsn_len));
983 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
984 } else if (wpa_len > 0) {
985 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
988 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
990 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->encryp_protocol is %x\n",
991 __func__, pnetwork->BcnInfo.encryp_protocol));
992 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->encryp_protocol is %x\n",
993 __func__, pnetwork->BcnInfo.encryp_protocol));
994 rtw_get_cipher_info(pnetwork);
996 /* get bwmode and ch_offset */
997 /* parsing HT_CAP_IE */
998 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1000 struct ieee80211_ht_cap *ht_cap =
1001 (struct ieee80211_ht_cap *)(p + 2);
1003 pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(ht_cap->cap_info);
1005 pnetwork->BcnInfo.ht_cap_info = 0;
1007 /* parsing HT_INFO_IE */
1008 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1010 pht_info = (struct HT_info_element *)(p + 2);
1011 pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1013 pnetwork->BcnInfo.ht_info_infos_0 = 0;
1017 /* show MCS rate, unit: 100Kbps */
1018 u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate)
1022 if (rf_type == RF_1T1R) {
1023 if (MCS_rate[0] & BIT(7))
1024 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1025 else if (MCS_rate[0] & BIT(6))
1026 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1027 else if (MCS_rate[0] & BIT(5))
1028 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1029 else if (MCS_rate[0] & BIT(4))
1030 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1031 else if (MCS_rate[0] & BIT(3))
1032 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1033 else if (MCS_rate[0] & BIT(2))
1034 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1035 else if (MCS_rate[0] & BIT(1))
1036 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1037 else if (MCS_rate[0] & BIT(0))
1038 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1041 if (MCS_rate[1] & BIT(7))
1042 max_rate = (bw_40MHz) ? ((short_GI_40) ? 3000 : 2700) : ((short_GI_20) ? 1444 : 1300);
1043 else if (MCS_rate[1] & BIT(6))
1044 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2700 : 2430) : ((short_GI_20) ? 1300 : 1170);
1045 else if (MCS_rate[1] & BIT(5))
1046 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2400 : 2160) : ((short_GI_20) ? 1156 : 1040);
1047 else if (MCS_rate[1] & BIT(4))
1048 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1800 : 1620) : ((short_GI_20) ? 867 : 780);
1049 else if (MCS_rate[1] & BIT(3))
1050 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1051 else if (MCS_rate[1] & BIT(2))
1052 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1053 else if (MCS_rate[1] & BIT(1))
1054 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1055 else if (MCS_rate[1] & BIT(0))
1056 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1058 if (MCS_rate[0] & BIT(7))
1059 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1060 else if (MCS_rate[0] & BIT(6))
1061 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1062 else if (MCS_rate[0] & BIT(5))
1063 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1064 else if (MCS_rate[0] & BIT(4))
1065 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1066 else if (MCS_rate[0] & BIT(3))
1067 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1068 else if (MCS_rate[0] & BIT(2))
1069 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1070 else if (MCS_rate[0] & BIT(1))
1071 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1072 else if (MCS_rate[0] & BIT(0))
1073 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);