1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
17 #include <linux/ieee80211.h>
19 #include <drv_types.h>
20 #include <osdep_intf.h>
21 #include <ieee80211.h>
23 #include <osdep_service.h>
24 #include <wlan_bssdef.h>
26 u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
27 u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };
28 u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };
29 u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };
30 u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };
31 u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };
32 u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };
33 u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };
34 u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };
35 u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };
37 u16 RSN_VERSION_BSD = 1;
38 u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x0f, 0xac, 1 };
39 u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x0f, 0xac, 2 };
40 u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };
41 u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };
42 u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };
43 u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };
44 u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };
45 u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };
47 /* for adhoc-master to generate ie and provide supported-rate to fw */
50 static u8 WIFI_CCKRATES[] = {
51 (IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
52 (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
53 (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
54 (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)
57 static u8 WIFI_OFDMRATES[] = {
58 (IEEE80211_OFDM_RATE_6MB),
59 (IEEE80211_OFDM_RATE_9MB),
60 (IEEE80211_OFDM_RATE_12MB),
61 (IEEE80211_OFDM_RATE_18MB),
62 (IEEE80211_OFDM_RATE_24MB),
63 IEEE80211_OFDM_RATE_36MB,
64 IEEE80211_OFDM_RATE_48MB,
65 IEEE80211_OFDM_RATE_54MB
69 int rtw_get_bit_value_from_ieee_value(u8 val)
71 unsigned char dot11_rate_table[] = {
72 2, 4, 11, 22, 12, 18, 24, 36, 48,
73 72, 96, 108, 0}; /* last element must be zero!! */
76 while (dot11_rate_table[i] != 0) {
77 if (dot11_rate_table[i] == val)
84 uint rtw_is_cckrates_included(u8 *rate)
88 while (rate[i] != 0) {
89 if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
90 (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
97 uint rtw_is_cckratesonly_included(u8 *rate)
101 while (rate[i] != 0) {
102 if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
103 (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
111 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
114 if ((rtw_is_cckrates_included(rate)) == true)
115 return WIRELESS_INVALID;
118 } else { /* could be pure B, pure G, or B/G */
119 if ((rtw_is_cckratesonly_included(rate)) == true)
121 else if ((rtw_is_cckrates_included(rate)) == true)
122 return WIRELESS_11BG;
128 u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source,
131 memcpy(pbuf, source, len);
132 *frlen = *frlen + len;
133 return ((u8 *)pbuf) + len;
136 /* rtw_set_ie will update frame length */
143 uint *frlen /* frame length */
148 *(pbuf + 1) = (u8)len;
151 memcpy((void *)(pbuf + 2), (void *)source, len);
153 *frlen = *frlen + (len + 2);
155 return pbuf + len + 2;
158 /*----------------------------------------------------------------------------
159 index: the information element id index, limit is the limit for search
160 -----------------------------------------------------------------------------*/
161 u8 *rtw_get_ie(u8 *pbuf, int index, uint *len, int limit)
187 void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
190 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
194 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
199 case WIRELESS_11A_5N:/* Todo: no basic rate for ofdm ? */
200 memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
203 case WIRELESS_11G_24N:
204 case WIRELESS_11_24N:
205 case WIRELESS_11BG_24N:
206 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
207 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
212 uint rtw_get_rateset_len(u8 *rateset)
217 if ((rateset[i]) == 0)
226 int rtw_generate_ie(struct registry_priv *pregistrypriv)
231 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
232 u8 *ie = pdev_network->IEs;
235 /* timestamp will be inserted by hardware */
239 /* beacon interval : 2bytes */
240 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);/* BCN_INTERVAL; */
244 /* capability info */
247 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
249 if (pregistrypriv->preamble == PREAMBLE_SHORT)
250 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
252 if (pdev_network->Privacy)
253 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
259 ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
261 /* supported rates */
262 if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {
263 if (pdev_network->Configuration.DSConfig > 14)
264 wireless_mode = WIRELESS_11A_5N;
266 wireless_mode = WIRELESS_11BG_24N;
268 wireless_mode = pregistrypriv->wireless_mode;
271 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
273 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
276 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
277 /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
279 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
282 /* DS parameter set */
283 ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz);
285 /* IBSS Parameter Set */
287 ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);
290 ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
295 unsigned char *rtw_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit)
300 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
302 int limit_new = limit;
305 pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
308 /* check if oui matches... */
309 if (!memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)) == false)
312 /* check version... */
313 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
315 val16 = le16_to_cpu(le_tmp);
318 *wpa_ie_len = *(pbuf + 1);
326 limit_new = limit - (pbuf - pie) - 2 - len;
335 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, uint *rsn_ie_len, int limit)
338 return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
341 int rtw_get_wpa_cipher_suite(u8 *s)
343 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
344 return WPA_CIPHER_NONE;
345 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
346 return WPA_CIPHER_WEP40;
347 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
348 return WPA_CIPHER_TKIP;
349 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
350 return WPA_CIPHER_CCMP;
351 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
352 return WPA_CIPHER_WEP104;
357 int rtw_get_wpa2_cipher_suite(u8 *s)
359 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
360 return WPA_CIPHER_NONE;
361 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
362 return WPA_CIPHER_WEP40;
363 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
364 return WPA_CIPHER_TKIP;
365 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
366 return WPA_CIPHER_CCMP;
367 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
368 return WPA_CIPHER_WEP104;
374 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
376 int i, ret = _SUCCESS;
379 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
381 if (wpa_ie_len <= 0) {
382 /* No WPA IE - fail silently */
387 if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
388 (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
394 left = wpa_ie_len - 8;
398 if (left >= WPA_SELECTOR_LEN) {
399 *group_cipher = rtw_get_wpa_cipher_suite(pos);
400 pos += WPA_SELECTOR_LEN;
401 left -= WPA_SELECTOR_LEN;
402 } else if (left > 0) {
403 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
407 /* pairwise_cipher */
409 count = get_unaligned_le16(pos);
413 if (count == 0 || left < count * WPA_SELECTOR_LEN) {
414 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), "
415 "count %u left %u", __func__, count, left));
419 for (i = 0; i < count; i++) {
420 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
422 pos += WPA_SELECTOR_LEN;
423 left -= WPA_SELECTOR_LEN;
425 } else if (left == 1) {
426 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
433 if (!memcmp(pos, SUITE_1X, 4)) {
434 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s : there has 802.1x auth\n", __func__));
443 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
445 int i, ret = _SUCCESS;
448 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
450 if (rsn_ie_len <= 0) {
451 /* No RSN IE - fail silently */
456 if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
461 left = rsn_ie_len - 4;
464 if (left >= RSN_SELECTOR_LEN) {
465 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
467 pos += RSN_SELECTOR_LEN;
468 left -= RSN_SELECTOR_LEN;
470 } else if (left > 0) {
471 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
475 /* pairwise_cipher */
477 count = get_unaligned_le16(pos);
481 if (count == 0 || left < count * RSN_SELECTOR_LEN) {
482 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), "
483 "count %u left %u", __func__, count, left));
487 for (i = 0; i < count; i++) {
488 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
490 pos += RSN_SELECTOR_LEN;
491 left -= RSN_SELECTOR_LEN;
494 } else if (left == 1) {
495 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
503 if (!memcmp(pos, SUITE_1X, 4)) {
504 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s (): there has 802.1x auth\n", __func__));
512 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
514 u8 authmode, sec_idx, i;
515 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
519 /* Search required WPA or WPA2 IE and copy to sec_ie[] */
521 cnt = _TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_;
525 while (cnt < in_len) {
526 authmode = in_ie[cnt];
528 if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
529 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
530 ("\n rtw_get_wpa_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
531 sec_idx, in_ie[cnt + 1] + 2));
534 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
536 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
537 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
538 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
539 wpa_ie[i], wpa_ie[i + 1], wpa_ie[i + 2], wpa_ie[i + 3], wpa_ie[i + 4],
540 wpa_ie[i + 5], wpa_ie[i + 6], wpa_ie[i + 7]));
544 *wpa_len = in_ie[cnt + 1] + 2;
545 cnt += in_ie[cnt + 1] + 2; /* get next */
547 if (authmode == _WPA2_IE_ID_) {
548 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
549 ("\n get_rsn_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
550 sec_idx, in_ie[cnt + 1] + 2));
553 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
555 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
556 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
557 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
558 rsn_ie[i], rsn_ie[i + 1], rsn_ie[i + 2], rsn_ie[i + 3], rsn_ie[i + 4],
559 rsn_ie[i + 5], rsn_ie[i + 6], rsn_ie[i + 7]));
563 *rsn_len = in_ie[cnt + 1] + 2;
564 cnt += in_ie[cnt + 1] + 2; /* get next */
566 cnt += in_ie[cnt + 1] + 2; /* get next */
572 return *rsn_len + *wpa_len;
575 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
578 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
585 if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
586 *wps_ielen = ie_ptr[1] + 2;
593 * rtw_get_wps_ie - Search WPS IE from a series of IEs
594 * @in_ie: Address of IEs to search
595 * @in_len: Length limit from in_ie
596 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
597 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
599 * Returns: The address of the WPS IE found, or NULL
601 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
604 u8 *wpsie_ptr = NULL;
605 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
610 if (!in_ie || in_len <= 0)
615 while (cnt < in_len) {
618 if ((eid == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
619 wpsie_ptr = &in_ie[cnt];
622 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
625 *wps_ielen = in_ie[cnt + 1] + 2;
627 cnt += in_ie[cnt + 1] + 2;
631 cnt += in_ie[cnt + 1] + 2; /* goto next */
638 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
639 * @wps_ie: Address of WPS IE to search
640 * @wps_ielen: Length limit from wps_ie
641 * @target_attr_id: The attribute ID of WPS attribute to search
642 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
643 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
645 * Returns: the address of the specific WPS attribute found, or NULL
647 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
650 u8 *target_attr_ptr = NULL;
651 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
656 if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
657 (memcmp(wps_ie + 2, wps_oui, 4)))
660 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
661 attr_ptr = wps_ie + 6; /* goto first attr */
663 while (attr_ptr - wps_ie < wps_ielen) {
664 /* 4 = 2(Attribute ID) + 2(Length) */
665 u16 attr_id = get_unaligned_be16(attr_ptr);
666 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
667 u16 attr_len = attr_data_len + 4;
669 if (attr_id == target_attr_id) {
670 target_attr_ptr = attr_ptr;
672 memcpy(buf_attr, attr_ptr, attr_len);
674 *len_attr = attr_len;
677 attr_ptr += attr_len; /* goto next */
680 return target_attr_ptr;
684 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
685 * @wps_ie: Address of WPS IE to search
686 * @wps_ielen: Length limit from wps_ie
687 * @target_attr_id: The attribute ID of WPS attribute to search
688 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
689 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
691 * Returns: the address of the specific WPS attribute content found, or NULL
693 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
701 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
703 if (attr_ptr && attr_len) {
705 memcpy(buf_content, attr_ptr + 4, attr_len - 4);
708 *len_content = attr_len - 4;
716 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
717 struct rtw_ieee802_11_elems *elems,
722 /* first 3 bytes in vendor specific information element are the IEEE
723 * OUI of the vendor. The following byte is used a vendor specific
727 DBG_88E("short vendor specific information element ignored (len=%lu)\n",
728 (unsigned long)elen);
733 oui = RTW_GET_BE24(pos);
736 /* Microsoft/Wi-Fi information elements are further typed and
740 /* Microsoft OUI (00:50:F2) with OUI Type 1:
741 * real WPA information element */
743 elems->wpa_ie_len = elen;
745 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
747 DBG_88E("short WME information element ignored (len=%lu)\n",
748 (unsigned long)elen);
752 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
753 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
755 elems->wme_len = elen;
757 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
758 elems->wme_tspec = pos;
759 elems->wme_tspec_len = elen;
762 DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n",
763 pos[4], (unsigned long)elen);
768 /* Wi-Fi Protected Setup (WPS) IE */
770 elems->wps_ie_len = elen;
773 DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n",
774 pos[3], (unsigned long)elen);
781 case VENDOR_HT_CAPAB_OUI_TYPE:
782 elems->vendor_ht_cap = pos;
783 elems->vendor_ht_cap_len = elen;
786 DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n",
787 pos[3], (unsigned long)elen);
792 DBG_88E("unknown vendor specific information element ignored (vendor OUI %3phC len=%lu)\n",
793 pos, (unsigned long)elen);
800 * ieee802_11_parse_elems - Parse information elements in management frames
801 * @start: Pointer to the start of IEs
802 * @len: Length of IE buffer in octets
803 * @elems: Data structure for parsed elements
804 * @show_errors: Whether to show parsing errors in debug log
805 * Returns: Parsing result
807 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
808 struct rtw_ieee802_11_elems *elems,
815 memset(elems, 0, sizeof(*elems));
826 DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
827 id, elen, (unsigned long)left);
835 elems->ssid_len = elen;
837 case WLAN_EID_SUPP_RATES:
838 elems->supp_rates = pos;
839 elems->supp_rates_len = elen;
841 case WLAN_EID_FH_PARAMS:
842 elems->fh_params = pos;
843 elems->fh_params_len = elen;
845 case WLAN_EID_DS_PARAMS:
846 elems->ds_params = pos;
847 elems->ds_params_len = elen;
849 case WLAN_EID_CF_PARAMS:
850 elems->cf_params = pos;
851 elems->cf_params_len = elen;
855 elems->tim_len = elen;
857 case WLAN_EID_IBSS_PARAMS:
858 elems->ibss_params = pos;
859 elems->ibss_params_len = elen;
861 case WLAN_EID_CHALLENGE:
862 elems->challenge = pos;
863 elems->challenge_len = elen;
865 case WLAN_EID_ERP_INFO:
866 elems->erp_info = pos;
867 elems->erp_info_len = elen;
869 case WLAN_EID_EXT_SUPP_RATES:
870 elems->ext_supp_rates = pos;
871 elems->ext_supp_rates_len = elen;
873 case WLAN_EID_VENDOR_SPECIFIC:
874 if (rtw_ieee802_11_parse_vendor_specific(pos, elen, elems, show_errors))
879 elems->rsn_ie_len = elen;
881 case WLAN_EID_PWR_CAPABILITY:
882 elems->power_cap = pos;
883 elems->power_cap_len = elen;
885 case WLAN_EID_SUPPORTED_CHANNELS:
886 elems->supp_channels = pos;
887 elems->supp_channels_len = elen;
889 case WLAN_EID_MOBILITY_DOMAIN:
891 elems->mdie_len = elen;
893 case WLAN_EID_FAST_BSS_TRANSITION:
895 elems->ftie_len = elen;
897 case WLAN_EID_TIMEOUT_INTERVAL:
898 elems->timeout_int = pos;
899 elems->timeout_int_len = elen;
901 case WLAN_EID_HT_CAPABILITY:
902 elems->ht_capabilities = pos;
903 elems->ht_capabilities_len = elen;
905 case WLAN_EID_HT_OPERATION:
906 elems->ht_operation = pos;
907 elems->ht_operation_len = elen;
913 DBG_88E("IEEE 802.11 element parse ignored unknown element (id=%d elen=%d)\n",
922 return unknown ? ParseUnknown : ParseOK;
925 void rtw_macaddr_cfg(u8 *mac_addr)
929 if (mac_addr == NULL)
932 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
933 /* Users specify the mac address */
934 memcpy(mac_addr, mac, ETH_ALEN);
936 /* Use the mac address stored in the Efuse */
937 memcpy(mac, mac_addr, ETH_ALEN);
940 if (((mac[0] == 0xff) && (mac[1] == 0xff) && (mac[2] == 0xff) &&
941 (mac[3] == 0xff) && (mac[4] == 0xff) && (mac[5] == 0xff)) ||
942 ((mac[0] == 0x0) && (mac[1] == 0x0) && (mac[2] == 0x0) &&
943 (mac[3] == 0x0) && (mac[4] == 0x0) && (mac[5] == 0x0))) {
950 /* use default mac address */
951 memcpy(mac_addr, mac, ETH_ALEN);
952 DBG_88E("MAC Address from efuse error, assign default one !!!\n");
955 DBG_88E("rtw_macaddr_cfg MAC Address = %pM\n", (mac_addr));
958 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
962 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
965 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
967 if (pbuf && (wpa_ielen > 0)) {
968 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_cipher_info: wpa_ielen: %d", wpa_ielen));
969 if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
970 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
971 pnetwork->BcnInfo.group_cipher = group_cipher;
972 pnetwork->BcnInfo.is_8021x = is8021x;
973 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->pairwise_cipher: %d, is_8021x is %d",
974 __func__, pnetwork->BcnInfo.pairwise_cipher, pnetwork->BcnInfo.is_8021x));
978 pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
980 if (pbuf && (wpa_ielen > 0)) {
981 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE\n"));
982 if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
983 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE OK!!!\n"));
984 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
985 pnetwork->BcnInfo.group_cipher = group_cipher;
986 pnetwork->BcnInfo.is_8021x = is8021x;
987 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->pairwise_cipher: %d,"
988 "pnetwork->group_cipher is %d, is_8021x is %d", __func__, pnetwork->BcnInfo.pairwise_cipher,
989 pnetwork->BcnInfo.group_cipher, pnetwork->BcnInfo.is_8021x));
998 void rtw_get_bcn_info(struct wlan_network *pnetwork)
1000 unsigned short cap = 0;
1003 u16 wpa_len = 0, rsn_len = 0;
1004 struct HT_info_element *pht_info = NULL;
1008 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
1009 cap = le16_to_cpu(le_tmp);
1010 if (cap & WLAN_CAPABILITY_PRIVACY) {
1012 pnetwork->network.Privacy = 1;
1014 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1016 rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
1017 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: ssid =%s\n", pnetwork->network.Ssid.Ssid));
1018 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
1019 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: ssid =%s\n", pnetwork->network.Ssid.Ssid));
1020 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
1023 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1024 } else if (wpa_len > 0) {
1025 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1028 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1030 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: pnetwork->encryp_protocol is %x\n",
1031 pnetwork->BcnInfo.encryp_protocol));
1032 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: pnetwork->encryp_protocol is %x\n",
1033 pnetwork->BcnInfo.encryp_protocol));
1034 rtw_get_cipher_info(pnetwork);
1036 /* get bwmode and ch_offset */
1037 /* parsing HT_CAP_IE */
1038 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1040 struct ieee80211_ht_cap *ht_cap =
1041 (struct ieee80211_ht_cap *)(p + 2);
1043 pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(ht_cap->cap_info);
1045 pnetwork->BcnInfo.ht_cap_info = 0;
1047 /* parsing HT_INFO_IE */
1048 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1050 pht_info = (struct HT_info_element *)(p + 2);
1051 pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1053 pnetwork->BcnInfo.ht_info_infos_0 = 0;
1057 /* show MCS rate, unit: 100Kbps */
1058 u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate)
1062 if (rf_type == RF_1T1R) {
1063 if (MCS_rate[0] & BIT(7))
1064 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1065 else if (MCS_rate[0] & BIT(6))
1066 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1067 else if (MCS_rate[0] & BIT(5))
1068 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1069 else if (MCS_rate[0] & BIT(4))
1070 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1071 else if (MCS_rate[0] & BIT(3))
1072 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1073 else if (MCS_rate[0] & BIT(2))
1074 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1075 else if (MCS_rate[0] & BIT(1))
1076 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1077 else if (MCS_rate[0] & BIT(0))
1078 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1081 if (MCS_rate[1] & BIT(7))
1082 max_rate = (bw_40MHz) ? ((short_GI_40) ? 3000 : 2700) : ((short_GI_20) ? 1444 : 1300);
1083 else if (MCS_rate[1] & BIT(6))
1084 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2700 : 2430) : ((short_GI_20) ? 1300 : 1170);
1085 else if (MCS_rate[1] & BIT(5))
1086 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2400 : 2160) : ((short_GI_20) ? 1156 : 1040);
1087 else if (MCS_rate[1] & BIT(4))
1088 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1800 : 1620) : ((short_GI_20) ? 867 : 780);
1089 else if (MCS_rate[1] & BIT(3))
1090 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1091 else if (MCS_rate[1] & BIT(2))
1092 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1093 else if (MCS_rate[1] & BIT(1))
1094 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1095 else if (MCS_rate[1] & BIT(0))
1096 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1098 if (MCS_rate[0] & BIT(7))
1099 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1100 else if (MCS_rate[0] & BIT(6))
1101 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1102 else if (MCS_rate[0] & BIT(5))
1103 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1104 else if (MCS_rate[0] & BIT(4))
1105 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1106 else if (MCS_rate[0] & BIT(3))
1107 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1108 else if (MCS_rate[0] & BIT(2))
1109 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1110 else if (MCS_rate[0] & BIT(1))
1111 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1112 else if (MCS_rate[0] & BIT(0))
1113 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);