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 /* could be pure B, pure G, or B/G */
100 if (rtw_is_cckratesonly_included(rate))
102 if (rtw_is_cckrates_included(rate))
103 return WIRELESS_11BG;
107 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
110 memcpy((void *)pbuf, (void *)source, len);
111 *frlen = *frlen + len;
115 /* rtw_set_ie will update frame length */
116 u8 *rtw_set_ie(u8 *pbuf,
120 uint *frlen) /* frame length */
124 *(pbuf + 1) = (u8)len;
127 memcpy((void *)(pbuf + 2), (void *)source, len);
129 *frlen = *frlen + (len + 2);
131 return pbuf + len + 2;
134 /*----------------------------------------------------------------------------
135 index: the information element id index, limit is the limit for search
136 -----------------------------------------------------------------------------*/
137 u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit)
163 * rtw_get_ie_ex - Search specific IE from a series of IEs
164 * @in_ie: Address of IEs to search
165 * @in_len: Length limit from in_ie
166 * @eid: Element ID to match
168 * @oui_len: OUI length
169 * @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE
170 * @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE
172 * Returns: The address of the specific IE found, or NULL
174 u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen)
177 u8 *target_ie = NULL;
182 if (!in_ie || in_len <= 0)
187 while (cnt < in_len) {
188 if (eid == in_ie[cnt]
189 && (!oui || !memcmp(&in_ie[cnt+2], oui, oui_len))) {
190 target_ie = &in_ie[cnt];
193 memcpy(ie, &in_ie[cnt], in_ie[cnt+1]+2);
196 *ielen = in_ie[cnt+1]+2;
200 cnt += in_ie[cnt+1]+2; /* goto next */
207 * rtw_ies_remove_ie - Find matching IEs and remove
208 * @ies: Address of IEs to search
209 * @ies_len: Pointer of length of ies, will update to new length
210 * @offset: The offset to start search
211 * @eid: Element ID to match
213 * @oui_len: OUI length
215 * Returns: _SUCCESS: ies is updated, _FAIL: not updated
217 int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)
225 if (!ies || !ies_len || *ies_len <= offset)
228 start = ies + offset;
229 search_len = *ies_len - offset;
232 target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);
233 if (target_ie && target_ielen) {
234 u8 *remain_ies = target_ie + target_ielen;
235 uint remain_len = search_len - (remain_ies - start);
237 memcpy(target_ie, remain_ies, remain_len);
238 *ies_len = *ies_len - target_ielen;
242 search_len = remain_len;
251 void rtw_set_supported_rate(u8 *supported_rates, uint mode)
253 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
257 memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
261 memcpy(supported_rates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
265 case WIRELESS_11G_24N:
266 case WIRELESS_11_24N:
267 case WIRELESS_11BG_24N:
268 memcpy(supported_rates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
269 memcpy(supported_rates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
274 uint rtw_get_rateset_len(u8 *rateset)
278 for (i = 0; i < 13; i++)
284 int rtw_generate_ie(struct registry_priv *pregistrypriv)
288 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
289 u8 *ie = pdev_network->ies;
291 /* timestamp will be inserted by hardware */
295 /* beacon interval : 2bytes */
296 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->configuration.beacon_period);/* BCN_INTERVAL; */
300 /* capability info */
303 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_IBSS);
305 if (pregistrypriv->preamble == PREAMBLE_SHORT)
306 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
308 if (pdev_network->privacy)
309 *(__le16 *)ie |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
315 ie = rtw_set_ie(ie, WLAN_EID_SSID, pdev_network->ssid.ssid_length, pdev_network->ssid.ssid, &sz);
317 /* supported rates */
318 wireless_mode = pregistrypriv->wireless_mode;
320 rtw_set_supported_rate(pdev_network->supported_rates, wireless_mode);
322 rateLen = rtw_get_rateset_len(pdev_network->supported_rates);
325 ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, 8, pdev_network->supported_rates, &sz);
326 /* ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rateLen - 8), (pdev_network->supported_rates + 8), &sz); */
328 ie = rtw_set_ie(ie, WLAN_EID_SUPP_RATES, rateLen, pdev_network->supported_rates, &sz);
331 /* DS parameter set */
332 ie = rtw_set_ie(ie, WLAN_EID_DS_PARAMS, 1, (u8 *)&(pdev_network->configuration.ds_config), &sz);
334 /* IBSS Parameter Set */
336 ie = rtw_set_ie(ie, WLAN_EID_IBSS_PARAMS, 2, (u8 *)&(pdev_network->configuration.atim_window), &sz);
339 ie = rtw_set_ie(ie, WLAN_EID_EXT_SUPP_RATES, (rateLen - 8), (pdev_network->supported_rates + 8), &sz);
342 if ((pregistrypriv->wireless_mode & WIRELESS_11_24N) &&
343 (pregistrypriv->ht_enable == true)) {
347 /* pdev_network->ie_length = sz; update ie_length */
349 /* return _SUCCESS; */
354 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
358 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
360 int limit_new = limit;
364 pbuf = rtw_get_ie(pbuf, WLAN_EID_VENDOR_SPECIFIC, &len, limit_new);
367 /* check if oui matches... */
368 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
371 /* check version... */
372 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
374 val16 = le16_to_cpu(le_tmp);
378 *wpa_ie_len = *(pbuf + 1);
389 limit_new = limit - (pbuf - pie) - 2 - len;
402 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
404 return rtw_get_ie(pie, WLAN_EID_RSN, rsn_ie_len, limit);
407 int rtw_get_wpa_cipher_suite(u8 *s)
409 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
410 return WPA_CIPHER_NONE;
411 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
412 return WPA_CIPHER_WEP40;
413 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
414 return WPA_CIPHER_TKIP;
415 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
416 return WPA_CIPHER_CCMP;
417 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
418 return WPA_CIPHER_WEP104;
423 int rtw_get_wpa2_cipher_suite(u8 *s)
425 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
426 return WPA_CIPHER_NONE;
427 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
428 return WPA_CIPHER_WEP40;
429 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
430 return WPA_CIPHER_TKIP;
431 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
432 return WPA_CIPHER_CCMP;
433 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
434 return WPA_CIPHER_WEP104;
439 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
441 int i, ret = _SUCCESS;
444 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
446 if (wpa_ie_len <= 0) {
447 /* No WPA IE - fail silently */
451 if ((*wpa_ie != WLAN_EID_VENDOR_SPECIFIC) || (*(wpa_ie+1) != (u8)(wpa_ie_len - 2)) ||
452 (memcmp(wpa_ie+2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN))) {
459 left = wpa_ie_len - 8;
462 if (left >= WPA_SELECTOR_LEN) {
463 *group_cipher = rtw_get_wpa_cipher_suite(pos);
465 pos += WPA_SELECTOR_LEN;
466 left -= WPA_SELECTOR_LEN;
471 /* pairwise_cipher */
473 /* count = le16_to_cpu(*(u16*)pos); */
474 count = get_unaligned_le16(pos);
478 if (count == 0 || left < count * WPA_SELECTOR_LEN)
481 for (i = 0; i < count; i++) {
482 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
484 pos += WPA_SELECTOR_LEN;
485 left -= WPA_SELECTOR_LEN;
488 } else if (left == 1)
494 if (!memcmp(pos, SUITE_1X, 4))
502 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
504 int i, ret = _SUCCESS;
507 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
509 if (rsn_ie_len <= 0) {
510 /* No RSN IE - fail silently */
514 if ((*rsn_ie != WLAN_EID_RSN) || (*(rsn_ie+1) != (u8)(rsn_ie_len - 2)))
519 left = rsn_ie_len - 4;
522 if (left >= RSN_SELECTOR_LEN) {
523 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
525 pos += RSN_SELECTOR_LEN;
526 left -= RSN_SELECTOR_LEN;
531 /* pairwise_cipher */
533 /* count = le16_to_cpu(*(u16*)pos); */
534 count = get_unaligned_le16(pos);
538 if (count == 0 || left < count * RSN_SELECTOR_LEN)
541 for (i = 0; i < count; i++) {
542 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
544 pos += RSN_SELECTOR_LEN;
545 left -= RSN_SELECTOR_LEN;
548 } else if (left == 1)
554 if (!memcmp(pos, SUITE_1X, 4))
562 /* ifdef CONFIG_WAPI_SUPPORT */
563 int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
568 u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01};
569 u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02};
574 if (!in_ie || in_len <= 0)
577 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
579 while (cnt < in_len) {
580 authmode = in_ie[cnt];
582 /* if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY) */
583 if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY && (!memcmp(&in_ie[cnt+6], wapi_oui1, 4) ||
584 !memcmp(&in_ie[cnt+6], wapi_oui2, 4))) {
586 memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt+1]+2);
589 *wapi_len = in_ie[cnt+1]+2;
591 cnt += in_ie[cnt+1]+2; /* get next */
593 cnt += in_ie[cnt+1]+2; /* get next */
604 void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
607 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
610 /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */
612 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
614 while (cnt < in_len) {
615 authmode = in_ie[cnt];
617 if ((authmode == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&in_ie[cnt+2], &wpa_oui[0], 4))) {
619 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt+1]+2);
621 *wpa_len = in_ie[cnt + 1] + 2;
622 cnt += in_ie[cnt + 1] + 2; /* get next */
624 if (authmode == WLAN_EID_RSN) {
626 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
628 *rsn_len = in_ie[cnt+1]+2;
629 cnt += in_ie[cnt+1]+2; /* get next */
631 cnt += in_ie[cnt+1]+2; /* get next */
637 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
640 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
647 if ((eid == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
648 *wps_ielen = ie_ptr[1]+2;
655 * rtw_get_wps_ie - Search WPS IE from a series of IEs
656 * @in_ie: Address of IEs to search
657 * @in_len: Length limit from in_ie
658 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
659 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
661 * Returns: The address of the WPS IE found, or NULL
663 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
666 u8 *wpsie_ptr = NULL;
667 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
672 if (!in_ie || in_len <= 0)
677 while (cnt < in_len) {
680 if ((eid == WLAN_EID_VENDOR_SPECIFIC) && (!memcmp(&in_ie[cnt+2], wps_oui, 4))) {
681 wpsie_ptr = &in_ie[cnt];
684 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt+1]+2);
687 *wps_ielen = in_ie[cnt+1]+2;
689 cnt += in_ie[cnt+1]+2;
693 cnt += in_ie[cnt+1]+2; /* goto next */
700 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
701 * @wps_ie: Address of WPS IE to search
702 * @wps_ielen: Length limit from wps_ie
703 * @target_attr_id: The attribute ID of WPS attribute to search
704 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
705 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
707 * Returns: the address of the specific WPS attribute found, or NULL
709 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
712 u8 *target_attr_ptr = NULL;
713 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
718 if ((wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC) ||
719 (memcmp(wps_ie + 2, wps_oui, 4))) {
723 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
724 attr_ptr = wps_ie + 6; /* goto first attr */
726 while (attr_ptr - wps_ie < wps_ielen) {
727 /* 4 = 2(Attribute ID) + 2(Length) */
728 u16 attr_id = get_unaligned_be16(attr_ptr);
729 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
730 u16 attr_len = attr_data_len + 4;
732 if (attr_id == target_attr_id) {
733 target_attr_ptr = attr_ptr;
736 memcpy(buf_attr, attr_ptr, attr_len);
739 *len_attr = attr_len;
743 attr_ptr += attr_len; /* goto next */
746 return target_attr_ptr;
750 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
751 * @wps_ie: Address of WPS IE to search
752 * @wps_ielen: Length limit from wps_ie
753 * @target_attr_id: The attribute ID of WPS attribute to search
754 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
755 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
757 * Returns: the address of the specific WPS attribute content found, or NULL
759 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
767 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
769 if (attr_ptr && attr_len) {
771 memcpy(buf_content, attr_ptr+4, attr_len-4);
774 *len_content = attr_len-4;
782 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
783 struct rtw_ieee802_11_elems *elems,
788 /* first 3 bytes in vendor specific information element are the IEEE
789 * OUI of the vendor. The following byte is used a vendor specific
794 oui = get_unaligned_be24(pos);
797 /* Microsoft/Wi-Fi information elements are further typed and
801 /* Microsoft OUI (00:50:F2) with OUI Type 1:
802 * real WPA information element */
804 elems->wpa_ie_len = elen;
806 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
811 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
812 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
814 elems->wme_len = elen;
816 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
817 elems->wme_tspec = pos;
818 elems->wme_tspec_len = elen;
825 /* Wi-Fi Protected Setup (WPS) IE */
827 elems->wps_ie_len = elen;
836 case VENDOR_HT_CAPAB_OUI_TYPE:
837 elems->vendor_ht_cap = pos;
838 elems->vendor_ht_cap_len = elen;
853 * rtw_ieee802_11_parse_elems - Parse information elements in management frames
854 * @start: Pointer to the start of IEs
855 * @len: Length of IE buffer in octets
856 * @elems: Data structure for parsed elements
857 * @show_errors: Whether to show parsing errors in debug log
858 * Returns: Parsing result
860 enum ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,
861 struct rtw_ieee802_11_elems *elems,
868 memset(elems, 0, sizeof(*elems));
883 elems->ssid_len = elen;
885 case WLAN_EID_SUPP_RATES:
886 elems->supp_rates = pos;
887 elems->supp_rates_len = elen;
889 case WLAN_EID_FH_PARAMS:
890 elems->fh_params = pos;
891 elems->fh_params_len = elen;
893 case WLAN_EID_DS_PARAMS:
894 elems->ds_params = pos;
895 elems->ds_params_len = elen;
897 case WLAN_EID_CF_PARAMS:
898 elems->cf_params = pos;
899 elems->cf_params_len = elen;
903 elems->tim_len = elen;
905 case WLAN_EID_IBSS_PARAMS:
906 elems->ibss_params = pos;
907 elems->ibss_params_len = elen;
909 case WLAN_EID_CHALLENGE:
910 elems->challenge = pos;
911 elems->challenge_len = elen;
913 case WLAN_EID_ERP_INFO:
914 elems->erp_info = pos;
915 elems->erp_info_len = elen;
917 case WLAN_EID_EXT_SUPP_RATES:
918 elems->ext_supp_rates = pos;
919 elems->ext_supp_rates_len = elen;
921 case WLAN_EID_VENDOR_SPECIFIC:
922 if (rtw_ieee802_11_parse_vendor_specific(pos, elen,
929 elems->rsn_ie_len = elen;
931 case WLAN_EID_PWR_CAPABILITY:
932 elems->power_cap = pos;
933 elems->power_cap_len = elen;
935 case WLAN_EID_SUPPORTED_CHANNELS:
936 elems->supp_channels = pos;
937 elems->supp_channels_len = elen;
939 case WLAN_EID_MOBILITY_DOMAIN:
941 elems->mdie_len = elen;
943 case WLAN_EID_FAST_BSS_TRANSITION:
945 elems->ftie_len = elen;
947 case WLAN_EID_TIMEOUT_INTERVAL:
948 elems->timeout_int = pos;
949 elems->timeout_int_len = elen;
951 case WLAN_EID_HT_CAPABILITY:
952 elems->ht_capabilities = pos;
953 elems->ht_capabilities_len = elen;
955 case WLAN_EID_HT_OPERATION:
956 elems->ht_operation = pos;
957 elems->ht_operation_len = elen;
959 case WLAN_EID_VHT_CAPABILITY:
960 elems->vht_capabilities = pos;
961 elems->vht_capabilities_len = elen;
963 case WLAN_EID_VHT_OPERATION:
964 elems->vht_operation = pos;
965 elems->vht_operation_len = elen;
967 case WLAN_EID_OPMODE_NOTIF:
968 elems->vht_op_mode_notify = pos;
969 elems->vht_op_mode_notify_len = elen;
983 return unknown ? ParseUnknown : ParseOK;
986 void rtw_macaddr_cfg(struct device *dev, u8 *mac_addr)
989 struct device_node *np = dev->of_node;
990 const unsigned char *addr;
996 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
997 /* Users specify the mac address */
998 ether_addr_copy(mac_addr, mac);
1000 /* Use the mac address stored in the Efuse */
1001 ether_addr_copy(mac, mac_addr);
1004 if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) {
1005 addr = of_get_property(np, "local-mac-address", &len);
1007 if (addr && len == ETH_ALEN) {
1008 ether_addr_copy(mac_addr, addr);
1010 eth_random_addr(mac_addr);
1015 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1018 unsigned char *pbuf;
1019 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1022 pbuf = rtw_get_wpa_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length-12);
1024 if (pbuf && (wpa_ielen > 0)) {
1025 if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen+2, &group_cipher, &pairwise_cipher, &is8021x)) {
1026 pnetwork->bcn_info.pairwise_cipher = pairwise_cipher;
1027 pnetwork->bcn_info.group_cipher = group_cipher;
1028 pnetwork->bcn_info.is_8021x = is8021x;
1032 pbuf = rtw_get_wpa2_ie(&pnetwork->network.ies[12], &wpa_ielen, pnetwork->network.ie_length-12);
1034 if (pbuf && (wpa_ielen > 0)) {
1035 if (_SUCCESS == rtw_parse_wpa2_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;
1047 void rtw_get_bcn_info(struct wlan_network *pnetwork)
1049 unsigned short cap = 0;
1051 /* u8 wpa_ie[255], rsn_ie[255]; */
1052 u16 wpa_len = 0, rsn_len = 0;
1053 struct HT_info_element *pht_info = NULL;
1054 struct ieee80211_ht_cap *pht_cap = NULL;
1059 memcpy((u8 *)&le_cap, rtw_get_capability_from_ie(pnetwork->network.ies), 2);
1060 cap = le16_to_cpu(le_cap);
1061 if (cap & WLAN_CAPABILITY_PRIVACY) {
1063 pnetwork->network.privacy = 1;
1065 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1067 rtw_get_sec_ie(pnetwork->network.ies, pnetwork->network.ie_length, NULL, &rsn_len, NULL, &wpa_len);
1070 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1071 } else if (wpa_len > 0) {
1072 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1075 pnetwork->bcn_info.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1077 rtw_get_cipher_info(pnetwork);
1079 /* get bwmode and ch_offset */
1080 /* parsing HT_CAP_IE */
1081 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_CAPABILITY, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1083 pht_cap = (struct ieee80211_ht_cap *)(p + 2);
1084 pnetwork->bcn_info.ht_cap_info = le16_to_cpu(pht_cap->cap_info);
1086 pnetwork->bcn_info.ht_cap_info = 0;
1088 /* parsing HT_INFO_IE */
1089 p = rtw_get_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, WLAN_EID_HT_OPERATION, &len, pnetwork->network.ie_length - _FIXED_IE_LENGTH_);
1091 pht_info = (struct HT_info_element *)(p + 2);
1092 pnetwork->bcn_info.ht_info_infos_0 = pht_info->infos[0];
1094 pnetwork->bcn_info.ht_info_infos_0 = 0;
1098 /* show MCS rate, unit: 100Kbps */
1099 u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate)
1103 if (MCS_rate[0] & BIT(7))
1104 max_rate = (bw_40MHz) ? ((short_GI)?1500:1350):((short_GI)?722:650);
1105 else if (MCS_rate[0] & BIT(6))
1106 max_rate = (bw_40MHz) ? ((short_GI)?1350:1215):((short_GI)?650:585);
1107 else if (MCS_rate[0] & BIT(5))
1108 max_rate = (bw_40MHz) ? ((short_GI)?1200:1080):((short_GI)?578:520);
1109 else if (MCS_rate[0] & BIT(4))
1110 max_rate = (bw_40MHz) ? ((short_GI)?900:810):((short_GI)?433:390);
1111 else if (MCS_rate[0] & BIT(3))
1112 max_rate = (bw_40MHz) ? ((short_GI)?600:540):((short_GI)?289:260);
1113 else if (MCS_rate[0] & BIT(2))
1114 max_rate = (bw_40MHz) ? ((short_GI)?450:405):((short_GI)?217:195);
1115 else if (MCS_rate[0] & BIT(1))
1116 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
1117 else if (MCS_rate[0] & BIT(0))
1118 max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
1123 int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)
1125 const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr);
1128 u8 a = ACT_PUBLIC_MAX;
1130 fc = le16_to_cpu(((struct ieee80211_hdr_3addr *)frame)->frame_control);
1132 if ((fc & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE))
1133 != (IEEE80211_FTYPE_MGMT|IEEE80211_STYPE_ACTION)
1141 case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */
1155 static const char *_action_public_str[] = {
1156 "ACT_PUB_BSSCOEXIST",
1157 "ACT_PUB_DSE_ENABLE",
1158 "ACT_PUB_DSE_DEENABLE",
1159 "ACT_PUB_DSE_REG_LOCATION",
1160 "ACT_PUB_EXT_CHL_SWITCH",
1161 "ACT_PUB_DSE_MSR_REQ",
1162 "ACT_PUB_DSE_MSR_RPRT",
1164 "ACT_PUB_DSE_PWR_CONSTRAINT",
1166 "ACT_PUB_GAS_INITIAL_REQ",
1167 "ACT_PUB_GAS_INITIAL_RSP",
1168 "ACT_PUB_GAS_COMEBACK_REQ",
1169 "ACT_PUB_GAS_COMEBACK_RSP",
1170 "ACT_PUB_TDLS_DISCOVERY_RSP",
1171 "ACT_PUB_LOCATION_TRACK",
1175 const char *action_public_str(u8 action)
1177 action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
1178 return _action_public_str[action];