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, int *len, int limit)
186 void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
189 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
193 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
198 case WIRELESS_11A_5N:/* Todo: no basic rate for ofdm ? */
199 memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
202 case WIRELESS_11G_24N:
203 case WIRELESS_11_24N:
204 case WIRELESS_11BG_24N:
205 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
206 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);
211 uint rtw_get_rateset_len(u8 *rateset)
215 if ((rateset[i]) == 0)
224 int rtw_generate_ie(struct registry_priv *pregistrypriv)
228 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
229 u8 *ie = pdev_network->IEs;
232 /* timestamp will be inserted by hardware */
236 /* beacon interval : 2bytes */
237 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);/* BCN_INTERVAL; */
241 /* capability info */
244 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
246 if (pregistrypriv->preamble == PREAMBLE_SHORT)
247 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
249 if (pdev_network->Privacy)
250 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
256 ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);
258 /* supported rates */
259 if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {
260 if (pdev_network->Configuration.DSConfig > 14)
261 wireless_mode = WIRELESS_11A_5N;
263 wireless_mode = WIRELESS_11BG_24N;
265 wireless_mode = pregistrypriv->wireless_mode;
268 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
270 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
273 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);
274 /* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
276 ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);
279 /* DS parameter set */
280 ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz);
282 /* IBSS Parameter Set */
284 ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);
287 ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);
292 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
297 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
299 int limit_new = limit;
302 pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);
305 /* check if oui matches... */
306 if (!memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)) == false)
309 /* check version... */
310 memcpy((u8 *)&le_tmp, (pbuf + 6), sizeof(val16));
312 val16 = le16_to_cpu(le_tmp);
315 *wpa_ie_len = *(pbuf + 1);
323 limit_new = limit - (pbuf - pie) - 2 - len;
332 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)
335 return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
338 int rtw_get_wpa_cipher_suite(u8 *s)
340 if (!memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN))
341 return WPA_CIPHER_NONE;
342 if (!memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN))
343 return WPA_CIPHER_WEP40;
344 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN))
345 return WPA_CIPHER_TKIP;
346 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN))
347 return WPA_CIPHER_CCMP;
348 if (!memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN))
349 return WPA_CIPHER_WEP104;
354 int rtw_get_wpa2_cipher_suite(u8 *s)
356 if (!memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN))
357 return WPA_CIPHER_NONE;
358 if (!memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN))
359 return WPA_CIPHER_WEP40;
360 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN))
361 return WPA_CIPHER_TKIP;
362 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN))
363 return WPA_CIPHER_CCMP;
364 if (!memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN))
365 return WPA_CIPHER_WEP104;
371 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
373 int i, ret = _SUCCESS;
376 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
378 if (wpa_ie_len <= 0) {
379 /* No WPA IE - fail silently */
384 if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||
385 (memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN)))
391 left = wpa_ie_len - 8;
395 if (left >= WPA_SELECTOR_LEN) {
396 *group_cipher = rtw_get_wpa_cipher_suite(pos);
397 pos += WPA_SELECTOR_LEN;
398 left -= WPA_SELECTOR_LEN;
399 } else if (left > 0) {
400 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
404 /* pairwise_cipher */
406 count = get_unaligned_le16(pos);
410 if (count == 0 || left < count * WPA_SELECTOR_LEN) {
411 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), "
412 "count %u left %u", __func__, count, left));
416 for (i = 0; i < count; i++) {
417 *pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);
419 pos += WPA_SELECTOR_LEN;
420 left -= WPA_SELECTOR_LEN;
422 } else if (left == 1) {
423 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
430 if (!memcmp(pos, SUITE_1X, 4)) {
431 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s : there has 802.1x auth\n", __func__));
440 int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
442 int i, ret = _SUCCESS;
445 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
447 if (rsn_ie_len <= 0) {
448 /* No RSN IE - fail silently */
453 if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
458 left = rsn_ie_len - 4;
461 if (left >= RSN_SELECTOR_LEN) {
462 *group_cipher = rtw_get_wpa2_cipher_suite(pos);
464 pos += RSN_SELECTOR_LEN;
465 left -= RSN_SELECTOR_LEN;
467 } else if (left > 0) {
468 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie length mismatch, %u too much", __func__, left));
472 /* pairwise_cipher */
474 count = get_unaligned_le16(pos);
478 if (count == 0 || left < count * RSN_SELECTOR_LEN) {
479 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie count botch (pairwise), "
480 "count %u left %u", __func__, count, left));
484 for (i = 0; i < count; i++) {
485 *pairwise_cipher |= rtw_get_wpa2_cipher_suite(pos);
487 pos += RSN_SELECTOR_LEN;
488 left -= RSN_SELECTOR_LEN;
491 } else if (left == 1) {
492 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("%s: ie too short (for key mgmt)", __func__));
500 if (!memcmp(pos, SUITE_1X, 4)) {
501 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s (): there has 802.1x auth\n", __func__));
509 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)
511 u8 authmode, sec_idx, i;
512 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
516 /* Search required WPA or WPA2 IE and copy to sec_ie[] */
518 cnt = _TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_;
522 while (cnt < in_len) {
523 authmode = in_ie[cnt];
525 if ((authmode == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
526 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
527 ("\n rtw_get_wpa_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
528 sec_idx, in_ie[cnt + 1] + 2));
531 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
533 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
534 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
535 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
536 wpa_ie[i], wpa_ie[i + 1], wpa_ie[i + 2], wpa_ie[i + 3], wpa_ie[i + 4],
537 wpa_ie[i + 5], wpa_ie[i + 6], wpa_ie[i + 7]));
541 *wpa_len = in_ie[cnt + 1] + 2;
542 cnt += in_ie[cnt + 1] + 2; /* get next */
544 if (authmode == _WPA2_IE_ID_) {
545 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
546 ("\n get_rsn_ie: sec_idx =%d in_ie[cnt+1]+2 =%d\n",
547 sec_idx, in_ie[cnt + 1] + 2));
550 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
552 for (i = 0; i < (in_ie[cnt + 1] + 2); i += 8) {
553 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
554 ("\n %2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",
555 rsn_ie[i], rsn_ie[i + 1], rsn_ie[i + 2], rsn_ie[i + 3], rsn_ie[i + 4],
556 rsn_ie[i + 5], rsn_ie[i + 6], rsn_ie[i + 7]));
560 *rsn_len = in_ie[cnt + 1] + 2;
561 cnt += in_ie[cnt + 1] + 2; /* get next */
563 cnt += in_ie[cnt + 1] + 2; /* get next */
569 return *rsn_len + *wpa_len;
572 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)
575 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
582 if ((eid == _WPA_IE_ID_) && (!memcmp(&ie_ptr[2], wps_oui, 4))) {
583 *wps_ielen = ie_ptr[1] + 2;
590 * rtw_get_wps_ie - Search WPS IE from a series of IEs
591 * @in_ie: Address of IEs to search
592 * @in_len: Length limit from in_ie
593 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie
594 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE
596 * Returns: The address of the WPS IE found, or NULL
598 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
601 u8 *wpsie_ptr = NULL;
602 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
607 if (!in_ie || in_len <= 0)
612 while (cnt < in_len) {
615 if ((eid == _WPA_IE_ID_) && (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
616 wpsie_ptr = &in_ie[cnt];
619 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
622 *wps_ielen = in_ie[cnt + 1] + 2;
624 cnt += in_ie[cnt + 1] + 2;
628 cnt += in_ie[cnt + 1] + 2; /* goto next */
635 * rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE
636 * @wps_ie: Address of WPS IE to search
637 * @wps_ielen: Length limit from wps_ie
638 * @target_attr_id: The attribute ID of WPS attribute to search
639 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr
640 * @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute
642 * Returns: the address of the specific WPS attribute found, or NULL
644 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr)
647 u8 *target_attr_ptr = NULL;
648 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
653 if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
654 (memcmp(wps_ie + 2, wps_oui, 4)))
657 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
658 attr_ptr = wps_ie + 6; /* goto first attr */
660 while (attr_ptr - wps_ie < wps_ielen) {
661 /* 4 = 2(Attribute ID) + 2(Length) */
662 u16 attr_id = get_unaligned_be16(attr_ptr);
663 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
664 u16 attr_len = attr_data_len + 4;
666 if (attr_id == target_attr_id) {
667 target_attr_ptr = attr_ptr;
669 memcpy(buf_attr, attr_ptr, attr_len);
671 *len_attr = attr_len;
674 attr_ptr += attr_len; /* goto next */
677 return target_attr_ptr;
681 * rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE
682 * @wps_ie: Address of WPS IE to search
683 * @wps_ielen: Length limit from wps_ie
684 * @target_attr_id: The attribute ID of WPS attribute to search
685 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content
686 * @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content
688 * Returns: the address of the specific WPS attribute content found, or NULL
690 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content)
698 attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);
700 if (attr_ptr && attr_len) {
702 memcpy(buf_content, attr_ptr + 4, attr_len - 4);
705 *len_content = attr_len - 4;
713 static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
714 struct rtw_ieee802_11_elems *elems,
719 /* first 3 bytes in vendor specific information element are the IEEE
720 * OUI of the vendor. The following byte is used a vendor specific
724 DBG_88E("short vendor specific information element ignored (len=%lu)\n",
725 (unsigned long)elen);
730 oui = RTW_GET_BE24(pos);
733 /* Microsoft/Wi-Fi information elements are further typed and
737 /* Microsoft OUI (00:50:F2) with OUI Type 1:
738 * real WPA information element */
740 elems->wpa_ie_len = elen;
742 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
744 DBG_88E("short WME information element ignored (len=%lu)\n",
745 (unsigned long)elen);
749 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
750 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
752 elems->wme_len = elen;
754 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
755 elems->wme_tspec = pos;
756 elems->wme_tspec_len = elen;
759 DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n",
760 pos[4], (unsigned long)elen);
765 /* Wi-Fi Protected Setup (WPS) IE */
767 elems->wps_ie_len = elen;
770 DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n",
771 pos[3], (unsigned long)elen);
778 case VENDOR_HT_CAPAB_OUI_TYPE:
779 elems->vendor_ht_cap = pos;
780 elems->vendor_ht_cap_len = elen;
783 DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n",
784 pos[3], (unsigned long)elen);
789 DBG_88E("unknown vendor specific information element ignored (vendor OUI %3phC len=%lu)\n",
790 pos, (unsigned long)elen);
797 * ieee802_11_parse_elems - Parse information elements in management frames
798 * @start: Pointer to the start of IEs
799 * @len: Length of IE buffer in octets
800 * @elems: Data structure for parsed elements
801 * @show_errors: Whether to show parsing errors in debug log
802 * Returns: Parsing result
804 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
805 struct rtw_ieee802_11_elems *elems,
812 memset(elems, 0, sizeof(*elems));
823 DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
824 id, elen, (unsigned long)left);
832 elems->ssid_len = elen;
834 case WLAN_EID_SUPP_RATES:
835 elems->supp_rates = pos;
836 elems->supp_rates_len = elen;
838 case WLAN_EID_FH_PARAMS:
839 elems->fh_params = pos;
840 elems->fh_params_len = elen;
842 case WLAN_EID_DS_PARAMS:
843 elems->ds_params = pos;
844 elems->ds_params_len = elen;
846 case WLAN_EID_CF_PARAMS:
847 elems->cf_params = pos;
848 elems->cf_params_len = elen;
852 elems->tim_len = elen;
854 case WLAN_EID_IBSS_PARAMS:
855 elems->ibss_params = pos;
856 elems->ibss_params_len = elen;
858 case WLAN_EID_CHALLENGE:
859 elems->challenge = pos;
860 elems->challenge_len = elen;
862 case WLAN_EID_ERP_INFO:
863 elems->erp_info = pos;
864 elems->erp_info_len = elen;
866 case WLAN_EID_EXT_SUPP_RATES:
867 elems->ext_supp_rates = pos;
868 elems->ext_supp_rates_len = elen;
870 case WLAN_EID_VENDOR_SPECIFIC:
871 if (rtw_ieee802_11_parse_vendor_specific(pos, elen, elems, show_errors))
876 elems->rsn_ie_len = elen;
878 case WLAN_EID_PWR_CAPABILITY:
879 elems->power_cap = pos;
880 elems->power_cap_len = elen;
882 case WLAN_EID_SUPPORTED_CHANNELS:
883 elems->supp_channels = pos;
884 elems->supp_channels_len = elen;
886 case WLAN_EID_MOBILITY_DOMAIN:
888 elems->mdie_len = elen;
890 case WLAN_EID_FAST_BSS_TRANSITION:
892 elems->ftie_len = elen;
894 case WLAN_EID_TIMEOUT_INTERVAL:
895 elems->timeout_int = pos;
896 elems->timeout_int_len = elen;
898 case WLAN_EID_HT_CAPABILITY:
899 elems->ht_capabilities = pos;
900 elems->ht_capabilities_len = elen;
902 case WLAN_EID_HT_OPERATION:
903 elems->ht_operation = pos;
904 elems->ht_operation_len = elen;
910 DBG_88E("IEEE 802.11 element parse ignored unknown element (id=%d elen=%d)\n",
919 return unknown ? ParseUnknown : ParseOK;
922 void rtw_macaddr_cfg(u8 *mac_addr)
926 if (mac_addr == NULL)
929 if (rtw_initmac && mac_pton(rtw_initmac, mac)) {
930 /* Users specify the mac address */
931 memcpy(mac_addr, mac, ETH_ALEN);
933 /* Use the mac address stored in the Efuse */
934 memcpy(mac, mac_addr, ETH_ALEN);
937 if (((mac[0] == 0xff) && (mac[1] == 0xff) && (mac[2] == 0xff) &&
938 (mac[3] == 0xff) && (mac[4] == 0xff) && (mac[5] == 0xff)) ||
939 ((mac[0] == 0x0) && (mac[1] == 0x0) && (mac[2] == 0x0) &&
940 (mac[3] == 0x0) && (mac[4] == 0x0) && (mac[5] == 0x0))) {
947 /* use default mac address */
948 memcpy(mac_addr, mac, ETH_ALEN);
949 DBG_88E("MAC Address from efuse error, assign default one !!!\n");
952 DBG_88E("rtw_macaddr_cfg MAC Address = %pM\n", (mac_addr));
955 /* Baron adds to avoid FreeBSD warning */
956 int ieee80211_is_empty_essid(const char *essid, int essid_len)
958 /* Single white space is for Linksys APs */
959 if (essid_len == 1 && essid[0] == ' ')
962 /* Otherwise, if the entire essid is 0, we assume it is hidden */
965 if (essid[essid_len] != '\0')
972 int ieee80211_get_hdrlen(u16 fc)
976 switch (WLAN_FC_GET_TYPE(fc)) {
977 case RTW_IEEE80211_FTYPE_DATA:
978 if (fc & RTW_IEEE80211_STYPE_QOS_DATA)
980 if ((fc & RTW_IEEE80211_FCTL_FROMDS) && (fc & RTW_IEEE80211_FCTL_TODS))
981 hdrlen += 6; /* Addr4 */
983 case RTW_IEEE80211_FTYPE_CTL:
984 switch (WLAN_FC_GET_STYPE(fc)) {
985 case RTW_IEEE80211_STYPE_CTS:
986 case RTW_IEEE80211_STYPE_ACK:
999 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1002 unsigned char *pbuf;
1003 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1005 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1007 if (pbuf && (wpa_ielen > 0)) {
1008 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_cipher_info: wpa_ielen: %d", wpa_ielen));
1009 if (_SUCCESS == rtw_parse_wpa_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
1010 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1011 pnetwork->BcnInfo.group_cipher = group_cipher;
1012 pnetwork->BcnInfo.is_8021x = is8021x;
1013 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->pairwise_cipher: %d, is_8021x is %d",
1014 __func__, pnetwork->BcnInfo.pairwise_cipher, pnetwork->BcnInfo.is_8021x));
1018 pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1020 if (pbuf && (wpa_ielen > 0)) {
1021 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE\n"));
1022 if (_SUCCESS == rtw_parse_wpa2_ie(pbuf, wpa_ielen + 2, &group_cipher, &pairwise_cipher, &is8021x)) {
1023 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("get RSN IE OK!!!\n"));
1024 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1025 pnetwork->BcnInfo.group_cipher = group_cipher;
1026 pnetwork->BcnInfo.is_8021x = is8021x;
1027 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("%s: pnetwork->pairwise_cipher: %d,"
1028 "pnetwork->group_cipher is %d, is_8021x is %d", __func__, pnetwork->BcnInfo.pairwise_cipher,
1029 pnetwork->BcnInfo.group_cipher, pnetwork->BcnInfo.is_8021x));
1038 void rtw_get_bcn_info(struct wlan_network *pnetwork)
1040 unsigned short cap = 0;
1043 u16 wpa_len = 0, rsn_len = 0;
1044 struct HT_info_element *pht_info = NULL;
1048 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
1049 cap = le16_to_cpu(le_tmp);
1050 if (cap & WLAN_CAPABILITY_PRIVACY) {
1052 pnetwork->network.Privacy = 1;
1054 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1056 rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &rsn_len, NULL, &wpa_len);
1057 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: ssid =%s\n", pnetwork->network.Ssid.Ssid));
1058 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
1059 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: ssid =%s\n", pnetwork->network.Ssid.Ssid));
1060 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
1063 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1064 } else if (wpa_len > 0) {
1065 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1068 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1070 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: pnetwork->encryp_protocol is %x\n",
1071 pnetwork->BcnInfo.encryp_protocol));
1072 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_bcn_info: pnetwork->encryp_protocol is %x\n",
1073 pnetwork->BcnInfo.encryp_protocol));
1074 rtw_get_cipher_info(pnetwork);
1076 /* get bwmode and ch_offset */
1077 /* parsing HT_CAP_IE */
1078 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1080 struct ieee80211_ht_cap *ht_cap =
1081 (struct ieee80211_ht_cap *)(p + 2);
1083 pnetwork->BcnInfo.ht_cap_info = le16_to_cpu(ht_cap->cap_info);
1085 pnetwork->BcnInfo.ht_cap_info = 0;
1087 /* parsing HT_INFO_IE */
1088 p = rtw_get_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_, _HT_ADD_INFO_IE_, &len, pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1090 pht_info = (struct HT_info_element *)(p + 2);
1091 pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1093 pnetwork->BcnInfo.ht_info_infos_0 = 0;
1097 /* show MCS rate, unit: 100Kbps */
1098 u16 rtw_mcs_rate(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate)
1102 if (rf_type == RF_1T1R) {
1103 if (MCS_rate[0] & BIT(7))
1104 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1105 else if (MCS_rate[0] & BIT(6))
1106 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1107 else if (MCS_rate[0] & BIT(5))
1108 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1109 else if (MCS_rate[0] & BIT(4))
1110 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1111 else if (MCS_rate[0] & BIT(3))
1112 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1113 else if (MCS_rate[0] & BIT(2))
1114 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1115 else if (MCS_rate[0] & BIT(1))
1116 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1117 else if (MCS_rate[0] & BIT(0))
1118 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);
1121 if (MCS_rate[1] & BIT(7))
1122 max_rate = (bw_40MHz) ? ((short_GI_40) ? 3000 : 2700) : ((short_GI_20) ? 1444 : 1300);
1123 else if (MCS_rate[1] & BIT(6))
1124 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2700 : 2430) : ((short_GI_20) ? 1300 : 1170);
1125 else if (MCS_rate[1] & BIT(5))
1126 max_rate = (bw_40MHz) ? ((short_GI_40) ? 2400 : 2160) : ((short_GI_20) ? 1156 : 1040);
1127 else if (MCS_rate[1] & BIT(4))
1128 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1800 : 1620) : ((short_GI_20) ? 867 : 780);
1129 else if (MCS_rate[1] & BIT(3))
1130 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1131 else if (MCS_rate[1] & BIT(2))
1132 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1133 else if (MCS_rate[1] & BIT(1))
1134 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1135 else if (MCS_rate[1] & BIT(0))
1136 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1138 if (MCS_rate[0] & BIT(7))
1139 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1500 : 1350) : ((short_GI_20) ? 722 : 650);
1140 else if (MCS_rate[0] & BIT(6))
1141 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1350 : 1215) : ((short_GI_20) ? 650 : 585);
1142 else if (MCS_rate[0] & BIT(5))
1143 max_rate = (bw_40MHz) ? ((short_GI_40) ? 1200 : 1080) : ((short_GI_20) ? 578 : 520);
1144 else if (MCS_rate[0] & BIT(4))
1145 max_rate = (bw_40MHz) ? ((short_GI_40) ? 900 : 810) : ((short_GI_20) ? 433 : 390);
1146 else if (MCS_rate[0] & BIT(3))
1147 max_rate = (bw_40MHz) ? ((short_GI_40) ? 600 : 540) : ((short_GI_20) ? 289 : 260);
1148 else if (MCS_rate[0] & BIT(2))
1149 max_rate = (bw_40MHz) ? ((short_GI_40) ? 450 : 405) : ((short_GI_20) ? 217 : 195);
1150 else if (MCS_rate[0] & BIT(1))
1151 max_rate = (bw_40MHz) ? ((short_GI_40) ? 300 : 270) : ((short_GI_20) ? 144 : 130);
1152 else if (MCS_rate[0] & BIT(0))
1153 max_rate = (bw_40MHz) ? ((short_GI_40) ? 150 : 135) : ((short_GI_20) ? 72 : 65);