1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
11 #include <asm/unaligned.h>
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 };
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 };
35 /* for adhoc-master to generate ie and provide supported-rate to fw */
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)
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
56 int rtw_get_bit_value_from_ieee_value(u8 val)
58 unsigned char dot11_rate_table[] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; /* last element must be zero!! */
61 while (dot11_rate_table[i] != 0) {
62 if (dot11_rate_table[i] == val)
69 bool rtw_is_cckrates_included(u8 *rate)
74 if (r == 2 || r == 4 || r == 11 || r == 22)
82 bool rtw_is_cckratesonly_included(u8 *rate)
87 if (r != 2 && r != 4 && r != 11 && r != 22)
95 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
98 return WIRELESS_INVALID;
99 } else { /* could be pure B, pure G, or B/G */
100 if (rtw_is_cckratesonly_included(rate))
102 else if (rtw_is_cckrates_included(rate))
103 return WIRELESS_11BG;
109 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
112 memcpy((void *)pbuf, (void *)source, len);
113 *frlen = *frlen + len;
117 /* rtw_set_ie will update frame length */
118 u8 *rtw_set_ie(u8 *pbuf,
122 uint *frlen) /* frame length */
126 *(pbuf + 1) = (u8)len;
129 memcpy((void *)(pbuf + 2), (void *)source, len);
131 *frlen = *frlen + (len + 2);
133 return pbuf + len + 2;
136 /*----------------------------------------------------------------------------
137 index: the information element id index, limit is the limit for search
138 -----------------------------------------------------------------------------*/
139 u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit)
166 * rtw_get_ie_ex - Search specific IE from a series of IEs
167 * @in_ie: Address of IEs to search
168 * @in_len: Length limit from in_ie
169 * @eid: Element ID to match
171 * @oui_len: OUI length
172 * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE
173 * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE
175 * Returns: The address of the specific IE found, or NULL
177 u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen)
180 u8 *target_ie = NULL;
185 if (!in_ie || in_len <= 0)
190 while (cnt < in_len) {
191 if (eid == in_ie[cnt]
192 && (!oui || !memcmp(&in_ie[cnt+2], oui, oui_len))) {
193 target_ie = &in_ie[cnt];
196 memcpy(ie, &in_ie[cnt], in_ie[cnt+1]+2);
199 *ielen = in_ie[cnt+1]+2;
203 cnt += in_ie[cnt+1]+2; /* goto next */
211 * rtw_ies_remove_ie - Find matching IEs and remove
212 * @ies: Address of IEs to search
213 * @ies_len: Pointer of length of ies, will update to new length
214 * @offset: The offset to start search
215 * @eid: Element ID to match
217 * @oui_len: OUI length
219 * Returns: _SUCCESS: ies is updated, _FAIL: not updated
221 int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)
229 if (!ies || !ies_len || *ies_len <= offset)
232 start = ies + offset;
233 search_len = *ies_len - offset;
236 target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);
237 if (target_ie && target_ielen) {
238 u8 *remain_ies = target_ie + target_ielen;
239 uint remain_len = search_len - (remain_ies - start);
241 memcpy(target_ie, remain_ies, remain_len);
242 *ies_len = *ies_len - target_ielen;
246 search_len = remain_len;
255 void rtw_set_supported_rate(u8 *supported_rates, uint mode)
257 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
261 memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
265 memcpy(supported_rates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
269 case WIRELESS_11G_24N:
270 case WIRELESS_11_24N:
271 case WIRELESS_11BG_24N:
272 memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
273 memcpy(supported_rates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
278 uint rtw_get_rateset_len(u8 *rateset)
282 for (i = 0; i < 13; i++)
288 int rtw_generate_ie(struct registry_priv *pregistrypriv)
292 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
293 u8 *ie = pdev_network->ies;
295 /* timestamp will be inserted by hardware */
299 /* beacon interval : 2bytes */
300 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->configuration.beacon_period);/* BCN_INTERVAL; */
304 /* capability info */
307 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_IBSS);
309 if (pregistrypriv->preamble == PREAMBLE_SHORT)
310 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
312 if (pdev_network->privacy)
313 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
319 ie = rtw_set_ie(ie, WLAN_EID_SSID, pdev_network->ssid.ssid_length, pdev_network->ssid.ssid, &sz);
321 /* supported rates */
322 wireless_mode = pregistrypriv->wireless_mode;
324 rtw_set_supported_rate(pdev_network->supported_rates, wireless_mode);
326 rateLen = rtw_get_rateset_len(pdev_network->supported_rates);
329 ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, 8, pdev_network->supported_rates, &sz);
330 /* ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rateLen - 8), (pdev_network->supported_rates + 8), &sz); */
332 ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, rateLen, pdev_network->supported_rates, &sz);
335 /* DS parameter set */
336 ie = rtw_set_ie(ie, WLAN_EID_DS_PARAMS, 1, (u8 *)&(pdev_network->configuration.ds_config), &sz);
338 /* IBSS Parameter Set */
340 ie = rtw_set_ie(ie, WLAN_EID_IBSS_PARAMS, 2, (u8 *)&(pdev_network->configuration.atim_window), &sz);
343 ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rateLen - 8), (pdev_network->supported_rates + 8), &sz);
347 if ((pregistrypriv->wireless_mode & WIRELESS_11_24N) &&
348 (pregistrypriv->ht_enable == true)) {
352 /* pdev_network->ie_length = sz; update ie_length */
354 /* return _SUCCESS; */
359 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
363 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
365 int limit_new = limit;
369 pbuf = rtw_get_ie(pbuf, WLAN_EID_VENDOR_SPECIFIC, &len, limit_new);
372 /* check if oui matches... */
373 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type))) {
377 /* check version... */
378 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
380 val16 = le16_to_cpu(le_tmp);
384 *wpa_ie_len = *(pbuf + 1);
395 limit_new = limit - (pbuf - pie) - 2 - len;
408 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
410 return rtw_get_ie(pie, WLAN_EID_RSN, rsn_ie_len, limit);
413 int rtw_get_wpa_cipher_suite(u8 *s)
415 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
416 return WPA_CIPHER_NONE;
417 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
418 return WPA_CIPHER_WEP40;
419 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
420 return WPA_CIPHER_TKIP;
421 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
422 return WPA_CIPHER_CCMP;
423 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
424 return WPA_CIPHER_WEP104;
429 int rtw_get_wpa2_cipher_suite(u8 *s)
431 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
432 return WPA_CIPHER_NONE;
433 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
434 return WPA_CIPHER_WEP40;
435 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
436 return WPA_CIPHER_TKIP;
437 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
438 return WPA_CIPHER_CCMP;
439 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
440 return WPA_CIPHER_WEP104;
445 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
447 int i, ret = _SUCCESS;
450 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
452 if (wpa_ie_len <= 0) {
453 /* No WPA IE - fail silently */
457 if ((*wpa_ie != WLAN_EID_VENDOR_SPECIFIC) || (*(wpa_ie+1) != (u8)(wpa_ie_len - 2)) ||
458 (memcmp(wpa_ie+2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN))) {
465 left = wpa_ie_len - 8;
468 if (left >= WPA_SELECTOR_LEN) {
469 *group_cipher = rtw_get_wpa_cipher_suite(pos);
471 pos += WPA_SELECTOR_LEN;
472 left -= WPA_SELECTOR_LEN;
477 /* pairwise_cipher */
479 /* count = le16_to_cpu(*(u16*)pos); */
480 count = get_unaligned_le16(pos);
484 if (count == 0 || left < count * WPA_SELECTOR_LEN)
487 for (i = 0; i < count; i++) {
488 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
490 pos += WPA_SELECTOR_LEN;
491 left -= WPA_SELECTOR_LEN;
494 } else if (left == 1)
500 if (!memcmp(pos, SUITE_1X, 4)) {
509 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
511 int i, ret = _SUCCESS;
514 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
516 if (rsn_ie_len <= 0) {
517 /* No RSN IE - fail silently */
521 if ((*rsn_ie != WLAN_EID_RSN) || (*(rsn_ie+1) != (u8)(rsn_ie_len - 2))) {
527 left = rsn_ie_len - 4;
530 if (left >= RSN_SELECTOR_LEN) {
531 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
533 pos += RSN_SELECTOR_LEN;
534 left -= RSN_SELECTOR_LEN;
539 /* pairwise_cipher */
541 /* count = le16_to_cpu(*(u16*)pos); */
542 count = get_unaligned_le16(pos);
546 if (count == 0 || left < count * RSN_SELECTOR_LEN)
549 for (i = 0; i < count; i++) {
550 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
552 pos += RSN_SELECTOR_LEN;
553 left -= RSN_SELECTOR_LEN;
556 } else if (left == 1)
562 if (!memcmp(pos, SUITE_1X, 4))
570 /* ifdef CONFIG_WAPI_SUPPORT */
571 int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
576 u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01};
577 u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02};
582 if (!in_ie || in_len <= 0)
585 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
587 while (cnt < in_len) {
588 authmode = in_ie[cnt];
590 /* if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY) */
591 if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY && (!memcmp(&in_ie[cnt+6], wapi_oui1, 4) ||
592 !memcmp(&in_ie[cnt+6], wapi_oui2, 4))) {
594 memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt+1]+2);
597 *wapi_len = in_ie[cnt+1]+2;
599 cnt += in_ie[cnt+1]+2; /* get next */
601 cnt += in_ie[cnt+1]+2; /* get next */
612 void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
615 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
618 /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */
620 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
622 while (cnt < in_len) {
623 authmode = in_ie[cnt];
625 if ((authmode == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&in_ie[cnt+2], &wpa_oui[0], 4))) {
627 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt+1]+2);
629 *wpa_len = in_ie[cnt + 1] + 2;
630 cnt += in_ie[cnt + 1] + 2; /* get next */
632 if (authmode == WLAN_EID_RSN) {
634 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
636 *rsn_len = in_ie[cnt+1]+2;
637 cnt += in_ie[cnt+1]+2; /* get next */
639 cnt += in_ie[cnt+1]+2; /* get next */
645 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
648 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
655 if ((eid == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
656 *wps_ielen = ie_ptr[1]+2;
663 * rtw_get_wps_ie - Search WPS IE from a series of IEs
664 * @in_ie: Address of IEs to search
665 * @in_len: Length limit from in_ie
666 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
667 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
669 * Returns: The address of the WPS IE found, or NULL
671 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
674 u8 *wpsie_ptr = NULL;
675 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
680 if (!in_ie || in_len <= 0)
685 while (cnt < in_len) {
688 if ((eid == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&in_ie[cnt+2], wps_oui, 4))) {
689 wpsie_ptr = &in_ie[cnt];
692 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt+1]+2);
695 *wps_ielen = in_ie[cnt+1]+2;
697 cnt += in_ie[cnt+1]+2;
701 cnt += in_ie[cnt+1]+2; /* goto next */
709 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
710 * @wps_ie: Address of WPS IE to search
711 * @wps_ielen: Length limit from wps_ie
712 * @target_attr_id: The attribute ID of WPS attribute to search
713 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
714 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
716 * Returns: the address of the specific WPS attribute found, or NULL
718 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
721 u8 *target_attr_ptr = NULL;
722 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
727 if ((wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC) ||
728 (memcmp(wps_ie + 2, wps_oui, 4))) {
732 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
733 attr_ptr = wps_ie + 6; /* goto first attr */
735 while (attr_ptr - wps_ie < wps_ielen) {
736 /* 4 = 2(Attribute ID) + 2(Length) */
737 u16 attr_id = get_unaligned_be16(attr_ptr);
738 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
739 u16 attr_len = attr_data_len + 4;
741 if (attr_id == target_attr_id) {
742 target_attr_ptr = attr_ptr;
745 memcpy(buf_attr, attr_ptr, attr_len);
748 *len_attr = attr_len;
752 attr_ptr += attr_len; /* goto next */
756 return target_attr_ptr;
760 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
761 * @wps_ie: Address of WPS IE to search
762 * @wps_ielen: Length limit from wps_ie
763 * @target_attr_id: The attribute ID of WPS attribute to search
764 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
765 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
767 * Returns: the address of the specific WPS attribute content found, or NULL
769 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
777 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
779 if (attr_ptr && attr_len) {
781 memcpy(buf_content, attr_ptr+4, attr_len-4);
784 *len_content = attr_len-4;
792 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
793 struct rtw_ieee802_11_elems *elems,
798 /* first 3 bytes in vendor specific information element are the IEEE
799 * OUI of the vendor. The following byte is used a vendor specific
804 oui = get_unaligned_be24(pos);
807 /* Microsoft/Wi-Fi information elements are further typed and
811 /* Microsoft OUI (00:50:F2) with OUI Type 1:
812 * real WPA information element */
814 elems->wpa_ie_len = elen;
816 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
821 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
822 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
824 elems->wme_len = elen;
826 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
827 elems->wme_tspec = pos;
828 elems->wme_tspec_len = elen;
835 /* Wi-Fi Protected Setup (WPS) IE */
837 elems->wps_ie_len = elen;
846 case VENDOR_HT_CAPAB_OUI_TYPE:
847 elems->vendor_ht_cap = pos;
848 elems->vendor_ht_cap_len = elen;
863 * rtw_ieee802_11_parse_elems - Parse information elements in management frames
864 * @start: Pointer to the start of IEs
865 * @len: Length of IE buffer in octets
866 * @elems: Data structure for parsed elements
867 * @show_errors: Whether to show parsing errors in debug log
868 * Returns: Parsing result
870 enum ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,
871 struct rtw_ieee802_11_elems *elems,
878 memset(elems, 0, sizeof(*elems));
893 elems->ssid_len = elen;
895 case WLAN_EID_SUPP_RATES:
896 elems->supp_rates = pos;
897 elems->supp_rates_len = elen;
899 case WLAN_EID_FH_PARAMS:
900 elems->fh_params = pos;
901 elems->fh_params_len = elen;
903 case WLAN_EID_DS_PARAMS:
904 elems->ds_params = pos;
905 elems->ds_params_len = elen;
907 case WLAN_EID_CF_PARAMS:
908 elems->cf_params = pos;
909 elems->cf_params_len = elen;
913 elems->tim_len = elen;
915 case WLAN_EID_IBSS_PARAMS:
916 elems->ibss_params = pos;
917 elems->ibss_params_len = elen;
919 case WLAN_EID_CHALLENGE:
920 elems->challenge = pos;
921 elems->challenge_len = elen;
923 case WLAN_EID_ERP_INFO:
924 elems->erp_info = pos;
925 elems->erp_info_len = elen;
927 case WLAN_EID_EXT_SUPP_RATES:
928 elems->ext_supp_rates = pos;
929 elems->ext_supp_rates_len = elen;
931 case WLAN_EID_VENDOR_SPECIFIC:
932 if (rtw_ieee802_11_parse_vendor_specific(pos, elen,
939 elems->rsn_ie_len = elen;
941 case WLAN_EID_PWR_CAPABILITY:
942 elems->power_cap = pos;
943 elems->power_cap_len = elen;
945 case WLAN_EID_SUPPORTED_CHANNELS:
946 elems->supp_channels = pos;
947 elems->supp_channels_len = elen;
949 case WLAN_EID_MOBILITY_DOMAIN:
951 elems->mdie_len = elen;
953 case WLAN_EID_FAST_BSS_TRANSITION:
955 elems->ftie_len = elen;
957 case WLAN_EID_TIMEOUT_INTERVAL:
958 elems->timeout_int = pos;
959 elems->timeout_int_len = elen;
961 case WLAN_EID_HT_CAPABILITY:
962 elems->ht_capabilities = pos;
963 elems->ht_capabilities_len = elen;
965 case WLAN_EID_HT_OPERATION:
966 elems->ht_operation = pos;
967 elems->ht_operation_len = elen;
969 case WLAN_EID_VHT_CAPABILITY:
970 elems->vht_capabilities = pos;
971 elems->vht_capabilities_len = elen;
973 case WLAN_EID_VHT_OPERATION:
974 elems->vht_operation = pos;
975 elems->vht_operation_len = elen;
977 case WLAN_EID_OPMODE_NOTIF:
978 elems->vht_op_mode_notify = pos;
979 elems->vht_op_mode_notify_len = elen;
993 return unknown ? ParseUnknown : ParseOK;
996 void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
999 struct device_node *np = dev->of_node;
1000 const unsigned char *addr;
1006 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
1007 /* Users specify the mac address */
1008 ether_addr_copy(mac_addr, mac);
1010 /* Use the mac address stored in the Efuse */
1011 ether_addr_copy(mac, mac_addr);
1014 if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) {
1015 addr = of_get_property(np, "local-mac-address", &len);
1017 if (addr && len == ETH_ALEN) {
1018 ether_addr_copy(mac_addr, addr);
1020 eth_random_addr(mac_addr);
1025 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1028 unsigned char *pbuf;
1029 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1032 pbuf = rtw_get_wpa_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length-12);
1034 if (pbuf && (wpa_ielen > 0)) {
1035 if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is8021x)) {
1036 pnetwork->bcn_info.pairwise_cipher = pairwise_cipher;
1037 pnetwork->bcn_info.group_cipher = group_cipher;
1038 pnetwork->bcn_info.is_8021x = is8021x;
1042 pbuf = rtw_get_wpa2_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length-12);
1044 if (pbuf && (wpa_ielen > 0)) {
1045 if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is8021x)) {
1046 pnetwork->bcn_info.pairwise_cipher = pairwise_cipher;
1047 pnetwork->bcn_info.group_cipher = group_cipher;
1048 pnetwork->bcn_info.is_8021x = is8021x;
1057 void rtw_get_bcn_info(struct wlan_network *pnetwork)
1059 unsigned short cap = 0;
1061 /* u8 wpa_ie[255], rsn_ie[255]; */
1062 u16 wpa_len = 0, rsn_len = 0;
1063 struct HT_info_element *pht_info = NULL;
1064 struct ieee80211_ht_cap *pht_cap = NULL;
1069 memcpy((u8 *)&le_cap, rtw_get_capability_from_ie(pnetwork->network.ies), 2);
1070 cap = le16_to_cpu(le_cap);
1071 if (cap & WLAN_CAPABILITY_PRIVACY) {
1073 pnetwork->network.privacy = 1;
1075 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1077 rtw_get_sec_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &rsn_len, NULL, &wpa_len);
1080 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1081 } else if (wpa_len > 0) {
1082 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1085 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1087 rtw_get_cipher_info(pnetwork);
1089 /* get bwmode and ch_offset */
1090 /* parsing HT_CAP_IE */
1091 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1093 pht_cap = (struct ieee80211_ht_cap *)(p + 2);
1094 pnetwork->bcn_info.ht_cap_info = le16_to_cpu(pht_cap->cap_info);
1096 pnetwork->bcn_info.ht_cap_info = 0;
1098 /* parsing HT_INFO_IE */
1099 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_OPERATION, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1101 pht_info = (struct HT_info_element *)(p + 2);
1102 pnetwork->bcn_info.ht_info_infos_0 = pht_info->infos[0];
1104 pnetwork->bcn_info.ht_info_infos_0 = 0;
1108 /* show MCS rate, unit: 100Kbps */
1109 u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate)
1113 if (rf_type == RF_1T1R) {
1114 if (MCS_rate[0] & BIT(7))
1115 max_rate = (bw_40MHz) ? ((short_GI)?1500:1350):((short_GI)?722:650);
1116 else if (MCS_rate[0] & BIT(6))
1117 max_rate = (bw_40MHz) ? ((short_GI)?1350:1215):((short_GI)?650:585);
1118 else if (MCS_rate[0] & BIT(5))
1119 max_rate = (bw_40MHz) ? ((short_GI)?1200:1080):((short_GI)?578:520);
1120 else if (MCS_rate[0] & BIT(4))
1121 max_rate = (bw_40MHz) ? ((short_GI)?900:810):((short_GI)?433:390);
1122 else if (MCS_rate[0] & BIT(3))
1123 max_rate = (bw_40MHz) ? ((short_GI)?600:540):((short_GI)?289:260);
1124 else if (MCS_rate[0] & BIT(2))
1125 max_rate = (bw_40MHz) ? ((short_GI)?450:405):((short_GI)?217:195);
1126 else if (MCS_rate[0] & BIT(1))
1127 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
1128 else if (MCS_rate[0] & BIT(0))
1129 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
1132 if (MCS_rate[1] & BIT(7))
1133 max_rate = (bw_40MHz) ? ((short_GI)?3000:2700):((short_GI)?1444:1300);
1134 else if (MCS_rate[1] & BIT(6))
1135 max_rate = (bw_40MHz) ? ((short_GI)?2700:2430):((short_GI)?1300:1170);
1136 else if (MCS_rate[1] & BIT(5))
1137 max_rate = (bw_40MHz) ? ((short_GI)?2400:2160):((short_GI)?1156:1040);
1138 else if (MCS_rate[1] & BIT(4))
1139 max_rate = (bw_40MHz) ? ((short_GI)?1800:1620):((short_GI)?867:780);
1140 else if (MCS_rate[1] & BIT(3))
1141 max_rate = (bw_40MHz) ? ((short_GI)?1200:1080):((short_GI)?578:520);
1142 else if (MCS_rate[1] & BIT(2))
1143 max_rate = (bw_40MHz) ? ((short_GI)?900:810):((short_GI)?433:390);
1144 else if (MCS_rate[1] & BIT(1))
1145 max_rate = (bw_40MHz) ? ((short_GI)?600:540):((short_GI)?289:260);
1146 else if (MCS_rate[1] & BIT(0))
1147 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
1149 if (MCS_rate[0] & BIT(7))
1150 max_rate = (bw_40MHz) ? ((short_GI)?1500:1350):((short_GI)?722:650);
1151 else if (MCS_rate[0] & BIT(6))
1152 max_rate = (bw_40MHz) ? ((short_GI)?1350:1215):((short_GI)?650:585);
1153 else if (MCS_rate[0] & BIT(5))
1154 max_rate = (bw_40MHz) ? ((short_GI)?1200:1080):((short_GI)?578:520);
1155 else if (MCS_rate[0] & BIT(4))
1156 max_rate = (bw_40MHz) ? ((short_GI)?900:810):((short_GI)?433:390);
1157 else if (MCS_rate[0] & BIT(3))
1158 max_rate = (bw_40MHz) ? ((short_GI)?600:540):((short_GI)?289:260);
1159 else if (MCS_rate[0] & BIT(2))
1160 max_rate = (bw_40MHz) ? ((short_GI)?450:405):((short_GI)?217:195);
1161 else if (MCS_rate[0] & BIT(1))
1162 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
1163 else if (MCS_rate[0] & BIT(0))
1164 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
1170 int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)
1172 const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr);
1175 u8 a = ACT_PUBLIC_MAX;
1177 fc = le16_to_cpu(((struct ieee80211_hdr_3addr *)frame)->frame_control);
1179 if ((fc & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE))
1180 != (IEEE80211_FTYPE_MGMT|IEEE80211_STYPE_ACTION)
1188 case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */
1202 static const char *_action_public_str[] = {
1203 "ACT_PUB_BSSCOEXIST",
1204 "ACT_PUB_DSE_ENABLE",
1205 "ACT_PUB_DSE_DEENABLE",
1206 "ACT_PUB_DSE_REG_LOCATION",
1207 "ACT_PUB_EXT_CHL_SWITCH",
1208 "ACT_PUB_DSE_MSR_REQ",
1209 "ACT_PUB_DSE_MSR_RPRT",
1211 "ACT_PUB_DSE_PWR_CONSTRAINT",
1213 "ACT_PUB_GAS_INITIAL_REQ",
1214 "ACT_PUB_GAS_INITIAL_RSP",
1215 "ACT_PUB_GAS_COMEBACK_REQ",
1216 "ACT_PUB_GAS_COMEBACK_RSP",
1217 "ACT_PUB_TDLS_DISCOVERY_RSP",
1218 "ACT_PUB_LOCATION_TRACK",
1222 const char *action_public_str(u8 action)
1224 action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
1225 return _action_public_str[action];