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 <drv_types.h>
18 #include <linux/ieee80211.h>
19 #include <ieee80211.h>
21 #include <osdep_service.h>
22 #include <wlan_bssdef.h>
24 u8 RTW_WPA_OUI23A_TYPE[] = { 0x00, 0x50, 0xf2, 1 };
25 u16 RTW_WPA_VERSION23A = 1;
26 u8 WPA_AUTH_KEY_MGMT_NONE23A[] = { 0x00, 0x50, 0xf2, 0 };
27 u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X23A[] = { 0x00, 0x50, 0xf2, 1 };
28 u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X23A[] = { 0x00, 0x50, 0xf2, 2 };
29 u8 WPA_CIPHER_SUITE_NONE23A[] = { 0x00, 0x50, 0xf2, 0 };
30 u8 WPA_CIPHER_SUITE_WEP4023A[] = { 0x00, 0x50, 0xf2, 1 };
31 u8 WPA_CIPHER_SUITE_TKIP23A[] = { 0x00, 0x50, 0xf2, 2 };
32 u8 WPA_CIPHER_SUITE_WRAP23A[] = { 0x00, 0x50, 0xf2, 3 };
33 u8 WPA_CIPHER_SUITE_CCMP23A[] = { 0x00, 0x50, 0xf2, 4 };
34 u8 WPA_CIPHER_SUITE_WEP10423A[] = { 0x00, 0x50, 0xf2, 5 };
36 u16 RSN_VERSION_BSD23A = 1;
37 u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X23A[] = { 0x00, 0x0f, 0xac, 1 };
38 u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X23A[] = { 0x00, 0x0f, 0xac, 2 };
39 u8 RSN_CIPHER_SUITE_NONE23A[] = { 0x00, 0x0f, 0xac, 0 };
40 u8 RSN_CIPHER_SUITE_WEP4023A[] = { 0x00, 0x0f, 0xac, 1 };
41 u8 RSN_CIPHER_SUITE_TKIP23A[] = { 0x00, 0x0f, 0xac, 2 };
42 u8 RSN_CIPHER_SUITE_WRAP23A[] = { 0x00, 0x0f, 0xac, 3 };
43 u8 RSN_CIPHER_SUITE_CCMP23A[] = { 0x00, 0x0f, 0xac, 4 };
44 u8 RSN_CIPHER_SUITE_WEP10423A[] = { 0x00, 0x0f, 0xac, 5 };
46 /* for adhoc-master to generate ie and provide supported-rate to fw */
49 static u8 WIFI_CCKRATES[] =
50 {(IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),
51 (IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),
52 (IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),
53 (IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)};
55 static u8 WIFI_OFDMRATES[] =
56 {(IEEE80211_OFDM_RATE_6MB),
57 (IEEE80211_OFDM_RATE_9MB),
58 (IEEE80211_OFDM_RATE_12MB),
59 (IEEE80211_OFDM_RATE_18MB),
60 (IEEE80211_OFDM_RATE_24MB),
61 IEEE80211_OFDM_RATE_36MB,
62 IEEE80211_OFDM_RATE_48MB,
63 IEEE80211_OFDM_RATE_54MB};
65 int rtw_get_bit_value_from_ieee_value23a(u8 val)
67 unsigned char dot11_rate_table[]=
68 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0};
71 while (dot11_rate_table[i] != 0) {
72 if (dot11_rate_table[i] == val)
79 uint rtw_is_cckrates_included23a(u8 *rate)
83 while (rate[i] != 0) {
84 if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
85 (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
93 uint rtw_is_cckratesonly_included23a(u8 *rate)
97 while (rate[i] != 0) {
98 if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
99 (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))
108 int rtw_check_network_type23a(unsigned char *rate, int ratelen, int channel)
111 if ((rtw_is_cckrates_included23a(rate)) == true)
112 return WIRELESS_INVALID;
115 } else { /* could be pure B, pure G, or B/G */
116 if ((rtw_is_cckratesonly_included23a(rate)) == true)
118 else if ((rtw_is_cckrates_included23a(rate)) == true)
119 return WIRELESS_11BG;
125 u8 *rtw_set_fixed_ie23a(unsigned char *pbuf, unsigned int len,
126 unsigned char *source, unsigned int *frlen)
128 memcpy((void *)pbuf, (void *)source, len);
129 *frlen = *frlen + len;
133 /* rtw_set_ie23a will update frame length */
134 u8 *rtw_set_ie23a(u8 *pbuf, int index, uint len, u8 *source, uint *frlen)
139 *(pbuf + 1) = (u8)len;
142 memcpy((void *)(pbuf + 2), (void *)source, len);
144 *frlen = *frlen + (len + 2);
147 return pbuf + len + 2;
150 inline u8 *rtw_set_ie23a_ch_switch (u8 *buf, u32 *buf_len, u8 ch_switch_mode,
151 u8 new_ch, u8 ch_switch_cnt)
155 ie_data[0] = ch_switch_mode;
157 ie_data[2] = ch_switch_cnt;
158 return rtw_set_ie23a(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len);
161 inline u8 secondary_ch_offset_to_hal_ch_offset23a(u8 ch_offset)
163 if (ch_offset == SCN)
164 return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
165 else if (ch_offset == SCA)
166 return HAL_PRIME_CHNL_OFFSET_UPPER;
167 else if (ch_offset == SCB)
168 return HAL_PRIME_CHNL_OFFSET_LOWER;
170 return HAL_PRIME_CHNL_OFFSET_DONT_CARE;
173 inline u8 hal_ch_offset_to_secondary_ch_offset23a(u8 ch_offset)
175 if (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)
177 else if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
179 else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
185 inline u8 *rtw_set_ie23a_secondary_ch_offset(u8 *buf, u32 *buf_len,
186 u8 secondary_ch_offset)
188 return rtw_set_ie23a(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET,
189 1, &secondary_ch_offset, buf_len);
192 inline u8 *rtw_set_ie23a_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,
193 u8 flags, u16 reason, u16 precedence)
199 put_unaligned_le16(reason, (u8*)&ie_data[2]);
200 put_unaligned_le16(precedence, (u8*)&ie_data[4]);
202 return rtw_set_ie23a(buf, 0x118, 6, ie_data, buf_len);
205 /*----------------------------------------------------------------------------
206 index: the information element id index, limit is the limit for search
207 -----------------------------------------------------------------------------*/
208 u8 *rtw_get_ie23a(u8 *pbuf, int index, int *len, int limit)
238 * rtw_get_ie23a_ex - Search specific IE from a series of IEs
239 * @in_ie: Address of IEs to search
240 * @in_len: Length limit from in_ie
241 * @eid: Element ID to match
243 * @oui_len: OUI length
244 * @ie: If not NULL and the specific IE is found, the IE will be copied
245 * to the buf starting from the specific IE
246 * @ielen: If not NULL and the specific IE is found, will set to the length
249 * Returns: The address of the specific IE found, or NULL
251 u8 *rtw_get_ie23a_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len,
255 u8 *target_ie = NULL;
260 if (!in_ie || in_len <= 0)
265 while (cnt < in_len) {
266 if (eid == in_ie[cnt] &&
267 (!oui || !memcmp(&in_ie[cnt+2], oui, oui_len))) {
268 target_ie = &in_ie[cnt];
271 memcpy(ie, &in_ie[cnt], in_ie[cnt+1]+2);
274 *ielen = in_ie[cnt+1]+2;
277 cnt += in_ie[cnt + 1] + 2; /* goto next */
285 * rtw_ies_remove_ie23a - Find matching IEs and remove
286 * @ies: Address of IEs to search
287 * @ies_len: Pointer of length of ies, will update to new length
288 * @offset: The offset to start scarch
289 * @eid: Element ID to match
291 * @oui_len: OUI length
293 * Returns: _SUCCESS: ies is updated, _FAIL: not updated
295 int rtw_ies_remove_ie23a(u8 *ies, uint *ies_len, uint offset, u8 eid,
304 if (!ies || !ies_len || *ies_len <= offset)
307 start = ies + offset;
308 search_len = *ies_len - offset;
311 target_ie = rtw_get_ie23a_ex(start, search_len, eid, oui, oui_len,
312 NULL, &target_ielen);
313 if (target_ie && target_ielen) {
314 u8 buf[MAX_IE_SZ] = {0};
315 u8 *remain_ies = target_ie + target_ielen;
316 uint remain_len = search_len - (remain_ies - start);
318 memcpy(buf, remain_ies, remain_len);
319 memcpy(target_ie, buf, remain_len);
320 *ies_len = *ies_len - target_ielen;
324 search_len = remain_len;
333 void rtw_set_supported_rate23a(u8* SupportedRates, uint mode)
337 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
342 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
348 case WIRELESS_11A_5N:/* Todo: no basic rate for ofdm ? */
349 memcpy(SupportedRates, WIFI_OFDMRATES,
350 IEEE80211_NUM_OFDM_RATESLEN);
354 case WIRELESS_11G_24N:
355 case WIRELESS_11_24N:
356 case WIRELESS_11BG_24N:
357 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
358 memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES,
359 IEEE80211_NUM_OFDM_RATESLEN);
365 uint rtw_get_rateset_len23a(u8 *rateset)
370 if ((rateset[i]) == 0)
382 int rtw_generate_ie23a(struct registry_priv *pregistrypriv)
386 struct wlan_bssid_ex* pdev_network = &pregistrypriv->dev_network;
387 u8* ie = pdev_network->IEs;
391 /* timestamp will be inserted by hardware */
395 /* beacon interval : 2bytes */
397 *(u16*)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);
401 /* capability info */
404 *(u16*)ie |= cpu_to_le16(cap_IBSS);
406 if (pregistrypriv->preamble == PREAMBLE_SHORT)
407 *(u16*)ie |= cpu_to_le16(cap_ShortPremble);
409 if (pdev_network->Privacy)
410 *(u16*)ie |= cpu_to_le16(cap_Privacy);
416 ie = rtw_set_ie23a(ie, _SSID_IE_, pdev_network->Ssid.ssid_len,
417 pdev_network->Ssid.ssid, &sz);
419 /* supported rates */
420 if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {
421 if (pdev_network->Configuration.DSConfig > 14)
422 wireless_mode = WIRELESS_11A_5N;
424 wireless_mode = WIRELESS_11BG_24N;
426 wireless_mode = pregistrypriv->wireless_mode;
429 rtw_set_supported_rate23a(pdev_network->SupportedRates, wireless_mode) ;
431 rateLen = rtw_get_rateset_len23a(pdev_network->SupportedRates);
434 ie = rtw_set_ie23a(ie, _SUPPORTEDRATES_IE_, 8,
435 pdev_network->SupportedRates, &sz);
436 /* ie = rtw_set_ie23a(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */
438 ie = rtw_set_ie23a(ie, _SUPPORTEDRATES_IE_, rateLen,
439 pdev_network->SupportedRates, &sz);
442 /* DS parameter set */
443 ie = rtw_set_ie23a(ie, _DSSET_IE_, 1,
444 (u8 *)&pdev_network->Configuration.DSConfig, &sz);
446 /* IBSS Parameter Set */
448 ie = rtw_set_ie23a(ie, _IBSS_PARA_IE_, 2,
449 (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
452 ie = rtw_set_ie23a(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8),
453 (pdev_network->SupportedRates + 8), &sz);
458 /* return _SUCCESS; */
463 unsigned char *rtw_get_wpa_ie23a(unsigned char *pie, int *wpa_ie_len, int limit)
467 unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};
469 int limit_new = limit;
472 pbuf = rtw_get_ie23a(pbuf, _WPA_IE_ID_, &len, limit_new);
475 /* check if oui matches... */
476 if (memcmp((pbuf + 2), wpa_oui_type,
477 sizeof(wpa_oui_type))) {
481 /* check version... */
482 memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));
484 val16 = le16_to_cpu(val16);
488 *wpa_ie_len = *(pbuf + 1);
498 limit_new = limit - (pbuf - pie) - 2 - len;
511 unsigned char *rtw_get_wpa2_ie23a(unsigned char *pie, int *rsn_ie_len, int limit)
513 return rtw_get_ie23a(pie, _WPA2_IE_ID_, rsn_ie_len, limit);
516 int rtw_get_wpa_cipher_suite23a(u8 *s)
518 if (!memcmp(s, WPA_CIPHER_SUITE_NONE23A, WPA_SELECTOR_LEN))
519 return WPA_CIPHER_NONE;
520 if (!memcmp(s, WPA_CIPHER_SUITE_WEP4023A, WPA_SELECTOR_LEN))
521 return WPA_CIPHER_WEP40;
522 if (!memcmp(s, WPA_CIPHER_SUITE_TKIP23A, WPA_SELECTOR_LEN))
523 return WPA_CIPHER_TKIP;
524 if (!memcmp(s, WPA_CIPHER_SUITE_CCMP23A, WPA_SELECTOR_LEN))
525 return WPA_CIPHER_CCMP;
526 if (!memcmp(s, WPA_CIPHER_SUITE_WEP10423A, WPA_SELECTOR_LEN))
527 return WPA_CIPHER_WEP104;
532 int rtw_get_wpa2_cipher_suite23a(u8 *s)
534 if (!memcmp(s, RSN_CIPHER_SUITE_NONE23A, RSN_SELECTOR_LEN))
535 return WPA_CIPHER_NONE;
536 if (!memcmp(s, RSN_CIPHER_SUITE_WEP4023A, RSN_SELECTOR_LEN))
537 return WPA_CIPHER_WEP40;
538 if (!memcmp(s, RSN_CIPHER_SUITE_TKIP23A, RSN_SELECTOR_LEN))
539 return WPA_CIPHER_TKIP;
540 if (!memcmp(s, RSN_CIPHER_SUITE_CCMP23A, RSN_SELECTOR_LEN))
541 return WPA_CIPHER_CCMP;
542 if (!memcmp(s, RSN_CIPHER_SUITE_WEP10423A, RSN_SELECTOR_LEN))
543 return WPA_CIPHER_WEP104;
548 int rtw_parse_wpa_ie23a(u8* wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
550 int i, ret = _SUCCESS;
553 u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};
555 if (wpa_ie_len <= 0) {
556 /* No WPA IE - fail silently */
560 if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie+1) != (u8)(wpa_ie_len - 2)) ||
561 memcmp(wpa_ie + 2, RTW_WPA_OUI23A_TYPE, WPA_SELECTOR_LEN)) {
568 left = wpa_ie_len - 8;
571 if (left >= WPA_SELECTOR_LEN) {
573 *group_cipher = rtw_get_wpa_cipher_suite23a(pos);
575 pos += WPA_SELECTOR_LEN;
576 left -= WPA_SELECTOR_LEN;
577 } else if (left > 0) {
578 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
579 ("%s: ie length mismatch, %u too much",
585 /* pairwise_cipher */
587 /* count = le16_to_cpu(*(u16*)pos); */
588 count = get_unaligned_le16(pos);
592 if (count == 0 || left < count * WPA_SELECTOR_LEN) {
593 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
594 ("%s: ie count botch (pairwise), "
595 "count %u left %u", __func__,
600 for (i = 0; i < count; i++) {
601 *pairwise_cipher |= rtw_get_wpa_cipher_suite23a(pos);
603 pos += WPA_SELECTOR_LEN;
604 left -= WPA_SELECTOR_LEN;
606 } else if (left == 1) {
607 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
608 ("%s: ie too short (for key mgmt)", __func__));
615 if (!memcmp(pos, SUITE_1X, 4)) {
616 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
617 ("%s : there has 802.1x auth\n",
627 int rtw_parse_wpa2_ie23a(u8* rsn_ie, int rsn_ie_len, int *group_cipher,
628 int *pairwise_cipher, int *is_8021x)
630 int i, ret = _SUCCESS;
633 u8 SUITE_1X[4] = {0x00, 0x0f, 0xac, 0x01};
635 if (rsn_ie_len <= 0) {
636 /* No RSN IE - fail silently */
640 if ((*rsn_ie!= _WPA2_IE_ID_) || (*(rsn_ie+1) != (u8)(rsn_ie_len - 2))) {
646 left = rsn_ie_len - 4;
649 if (left >= RSN_SELECTOR_LEN) {
650 *group_cipher = rtw_get_wpa2_cipher_suite23a(pos);
652 pos += RSN_SELECTOR_LEN;
653 left -= RSN_SELECTOR_LEN;
654 } else if (left > 0) {
655 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
656 ("%s: ie length mismatch, %u too much",
661 /* pairwise_cipher */
663 /* count = le16_to_cpu(*(u16*)pos); */
664 count = get_unaligned_le16(pos);
668 if (count == 0 || left < count * RSN_SELECTOR_LEN) {
669 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
670 ("%s: ie count botch (pairwise), "
672 __func__, count, left));
676 for (i = 0; i < count; i++) {
677 *pairwise_cipher |= rtw_get_wpa2_cipher_suite23a(pos);
679 pos += RSN_SELECTOR_LEN;
680 left -= RSN_SELECTOR_LEN;
682 } else if (left == 1) {
683 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
684 ("%s: ie too short (for key mgmt)", __func__));
692 if (!memcmp(pos, SUITE_1X, 4)) {
693 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
694 ("%s (): there has 802.1x auth\n",
704 int rtw_get_sec_ie23a(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
705 u8 *wpa_ie, u16 *wpa_len)
707 u8 authmode, sec_idx, i;
708 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
713 /* Search required WPA or WPA2 IE and copy to sec_ie[ ] */
715 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
719 while(cnt < in_len) {
720 authmode = in_ie[cnt];
722 if ((authmode == _WPA_IE_ID_) &&
723 !memcmp(&in_ie[cnt+2], &wpa_oui[0], 4)) {
724 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
725 ("\n rtw_get_wpa_ie23a: sec_idx =%d "
726 "in_ie[cnt+1]+2 =%d\n",
727 sec_idx, in_ie[cnt + 1] + 2));
730 memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt+1]+2);
732 for (i = 0; i < (in_ie[cnt + 1] + 2); i = i + 8) {
733 RT_TRACE(_module_rtl871x_mlme_c_,
735 ("\n %2x,%2x,%2x,%2x,%2x,%2x,"
736 "%2x,%2x\n", wpa_ie[i],
737 wpa_ie[i + 1], wpa_ie[i + 2],
738 wpa_ie[i + 3], wpa_ie[i + 4],
739 wpa_ie[i + 5], wpa_ie[i + 6],
744 *wpa_len = in_ie[cnt + 1] + 2;
745 cnt += in_ie[cnt + 1] + 2; /* get next */
747 if (authmode == _WPA2_IE_ID_) {
748 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
749 ("\n get_rsn_ie: sec_idx =%d in_ie"
750 "[cnt+1]+2 =%d\n", sec_idx,
751 in_ie[cnt + 1] + 2));
754 memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
756 for (i = 0; i < (in_ie[cnt + 1] + 2); i = i + 8) {
757 RT_TRACE(_module_rtl871x_mlme_c_,
759 ("\n %2x,%2x,%2x,%2x,%2x,%2x,"
760 "%2x,%2x\n", rsn_ie[i],
761 rsn_ie[i + 1], rsn_ie[i + 2],
762 rsn_ie[i + 3], rsn_ie[i + 4],
763 rsn_ie[i + 5], rsn_ie[i + 6],
768 *rsn_len = in_ie[cnt + 1] + 2;
769 cnt += in_ie[cnt + 1] + 2; /* get next */
771 cnt += in_ie[cnt + 1] + 2; /* get next */
778 return *rsn_len + *wpa_len;
781 u8 rtw_is_wps_ie23a(u8 *ie_ptr, uint *wps_ielen)
784 u8 eid, wps_oui[4]= {0x0, 0x50, 0xf2, 0x04};
791 if ((eid == _WPA_IE_ID_) && !memcmp(&ie_ptr[2], wps_oui, 4)) {
792 /* DBG_8723A("==> found WPS_IE.....\n"); */
793 *wps_ielen = ie_ptr[1] + 2;
800 * rtw_get_wps_ie23a - Search WPS IE from a series of IEs
801 * @in_ie: Address of IEs to search
802 * @in_len: Length limit from in_ie
803 * @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the
804 * buf starting from wps_ie
805 * @wps_ielen: If not NULL and WPS IE is found, will set to the length of
808 * Returns: The address of the WPS IE found, or NULL
810 u8 *rtw_get_wps_ie23a(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
813 u8 *wpsie_ptr = NULL;
814 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
819 if (!in_ie || in_len <= 0)
824 while (cnt < in_len) {
827 if ((eid == _WPA_IE_ID_) && !memcmp(&in_ie[cnt+2], wps_oui, 4)) {
828 wpsie_ptr = &in_ie[cnt];
831 memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
834 *wps_ielen = in_ie[cnt + 1] + 2;
836 cnt += in_ie[cnt + 1] + 2;
840 cnt += in_ie[cnt + 1] + 2; /* goto next */
848 * rtw_get_wps_attr23a - Search a specific WPS attribute from a given WPS IE
849 * @wps_ie: Address of WPS IE to search
850 * @wps_ielen: Length limit from wps_ie
851 * @target_attr_id: The attribute ID of WPS attribute to search
852 * @buf_attr: If not NULL and the WPS attribute is found, WPS attribute
853 * will be copied to the buf starting from buf_attr
854 * @len_attr: If not NULL and the WPS attribute is found, will set to the
855 * length of the entire WPS attribute
857 * Returns: the address of the specific WPS attribute found, or NULL
859 u8 *rtw_get_wps_attr23a(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
860 u8 *buf_attr, u32 *len_attr)
863 u8 * target_attr_ptr = NULL;
864 u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};
869 if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||
870 memcmp(wps_ie + 2, wps_oui, 4)) {
874 /* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */
875 attr_ptr = wps_ie + 6; /* goto first attr */
877 while (attr_ptr - wps_ie < wps_ielen) {
878 /* 4 = 2(Attribute ID) + 2(Length) */
879 u16 attr_id = get_unaligned_be16(attr_ptr);
880 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
881 u16 attr_len = attr_data_len + 4;
883 /* DBG_8723A("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len); */
884 if (attr_id == target_attr_id) {
885 target_attr_ptr = attr_ptr;
888 memcpy(buf_attr, attr_ptr, attr_len);
891 *len_attr = attr_len;
895 attr_ptr += attr_len; /* goto next */
899 return target_attr_ptr;
903 * rtw_get_wps_attr_content23a - Search a specific WPS attribute content
904 * from a given WPS IE
905 * @wps_ie: Address of WPS IE to search
906 * @wps_ielen: Length limit from wps_ie
907 * @target_attr_id: The attribute ID of WPS attribute to search
908 * @buf_content: If not NULL and the WPS attribute is found, WPS attribute
909 * content will be copied to the buf starting from buf_content
910 * @len_content: If not NULL and the WPS attribute is found, will set to the
911 * length of the WPS attribute content
913 * Returns: the address of the specific WPS attribute content found, or NULL
915 u8 *rtw_get_wps_attr_content23a(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
916 u8 *buf_content, uint *len_content)
924 attr_ptr = rtw_get_wps_attr23a(wps_ie, wps_ielen, target_attr_id,
927 if (attr_ptr && attr_len) {
929 memcpy(buf_content, attr_ptr + 4, attr_len - 4);
932 *len_content = attr_len - 4;
941 rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
942 struct rtw_ieee802_11_elems *elems,
947 /* first 3 bytes in vendor specific information element are the IEEE
948 * OUI of the vendor. The following byte is used a vendor specific
952 DBG_8723A("short vendor specific "
953 "information element ignored (len =%lu)\n",
954 (unsigned long) elen);
959 oui = RTW_GET_BE24(pos);
961 case WLAN_OUI_MICROSOFT:
962 /* Microsoft/Wi-Fi information elements are further typed and
966 /* Microsoft OUI (00:50:F2) with OUI Type 1:
967 * real WPA information element */
969 elems->wpa_ie_len = elen;
971 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
973 DBG_8723A("short WME "
974 "information element ignored "
976 (unsigned long) elen);
980 case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:
981 case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:
983 elems->wme_len = elen;
985 case WME_OUI_SUBTYPE_TSPEC_ELEMENT:
986 elems->wme_tspec = pos;
987 elems->wme_tspec_len = elen;
990 DBG_8723A("unknown WME "
991 "information element ignored "
992 "(subtype =%d len =%lu)\n",
993 pos[4], (unsigned long) elen);
998 /* Wi-Fi Protected Setup (WPS) IE */
1000 elems->wps_ie_len = elen;
1003 DBG_8723A("Unknown Microsoft "
1004 "information element ignored "
1005 "(type =%d len =%lu)\n",
1006 pos[3], (unsigned long) elen);
1013 case VENDOR_HT_CAPAB_OUI_TYPE:
1014 elems->vendor_ht_cap = pos;
1015 elems->vendor_ht_cap_len = elen;
1018 DBG_8723A("Unknown Broadcom "
1019 "information element ignored "
1020 "(type =%d len =%lu)\n",
1021 pos[3], (unsigned long) elen);
1027 DBG_8723A("unknown vendor specific information "
1028 "element ignored (vendor OUI %02x:%02x:%02x "
1030 pos[0], pos[1], pos[2], (unsigned long) elen);
1038 * ieee802_11_parse_elems - Parse information elements in management frames
1039 * @start: Pointer to the start of IEs
1040 * @len: Length of IE buffer in octets
1041 * @elems: Data structure for parsed elements
1042 * @show_errors: Whether to show parsing errors in debug log
1043 * Returns: Parsing result
1045 enum parse_res rtw_ieee802_11_parse_elems23a(u8 *start, uint len,
1046 struct rtw_ieee802_11_elems *elems,
1053 memset(elems, 0, sizeof(*elems));
1064 DBG_8723A("IEEE 802.11 element "
1065 "parse failed (id =%d elen =%d "
1067 id, elen, (unsigned long) left);
1075 elems->ssid_len = elen;
1077 case WLAN_EID_SUPP_RATES:
1078 elems->supp_rates = pos;
1079 elems->supp_rates_len = elen;
1081 case WLAN_EID_FH_PARAMS:
1082 elems->fh_params = pos;
1083 elems->fh_params_len = elen;
1085 case WLAN_EID_DS_PARAMS:
1086 elems->ds_params = pos;
1087 elems->ds_params_len = elen;
1089 case WLAN_EID_CF_PARAMS:
1090 elems->cf_params = pos;
1091 elems->cf_params_len = elen;
1095 elems->tim_len = elen;
1097 case WLAN_EID_IBSS_PARAMS:
1098 elems->ibss_params = pos;
1099 elems->ibss_params_len = elen;
1101 case WLAN_EID_CHALLENGE:
1102 elems->challenge = pos;
1103 elems->challenge_len = elen;
1105 case WLAN_EID_ERP_INFO:
1106 elems->erp_info = pos;
1107 elems->erp_info_len = elen;
1109 case WLAN_EID_EXT_SUPP_RATES:
1110 elems->ext_supp_rates = pos;
1111 elems->ext_supp_rates_len = elen;
1113 case WLAN_EID_VENDOR_SPECIFIC:
1114 if (rtw_ieee802_11_parse_vendor_specific(pos, elen,
1120 elems->rsn_ie = pos;
1121 elems->rsn_ie_len = elen;
1123 case WLAN_EID_PWR_CAPABILITY:
1124 elems->power_cap = pos;
1125 elems->power_cap_len = elen;
1127 case WLAN_EID_SUPPORTED_CHANNELS:
1128 elems->supp_channels = pos;
1129 elems->supp_channels_len = elen;
1131 case WLAN_EID_MOBILITY_DOMAIN:
1133 elems->mdie_len = elen;
1135 case WLAN_EID_FAST_BSS_TRANSITION:
1137 elems->ftie_len = elen;
1139 case WLAN_EID_TIMEOUT_INTERVAL:
1140 elems->timeout_int = pos;
1141 elems->timeout_int_len = elen;
1143 case WLAN_EID_HT_CAPABILITY:
1144 elems->ht_capabilities = pos;
1145 elems->ht_capabilities_len = elen;
1147 case WLAN_EID_HT_OPERATION:
1148 elems->ht_operation = pos;
1149 elems->ht_operation_len = elen;
1155 DBG_8723A("IEEE 802.11 element parse "
1156 "ignored unknown element (id =%d elen =%d)\n",
1168 return unknown ? ParseUnknown : ParseOK;
1171 static u8 key_char2num(u8 ch)
1173 if ((ch >= '0') && (ch <= '9'))
1175 else if ((ch >= 'a') && (ch <= 'f'))
1176 return ch - 'a' + 10;
1177 else if ((ch >= 'A') && (ch <= 'F'))
1178 return ch - 'A' + 10;
1183 u8 str_2char2num23a(u8 hch, u8 lch)
1185 return (key_char2num(hch) * 10) + key_char2num(lch);
1188 u8 key_2char2num23a(u8 hch, u8 lch)
1190 return (key_char2num(hch) << 4) | key_char2num(lch);
1193 void rtw_macaddr_cfg23a(u8 *mac_addr)
1199 memcpy(mac, mac_addr, ETH_ALEN);
1201 if (is_broadcast_ether_addr(mac) || is_zero_ether_addr(mac)) {
1208 /* use default mac addresss */
1209 memcpy(mac_addr, mac, ETH_ALEN);
1210 DBG_8723A("MAC Address from efuse error, assign default "
1213 DBG_8723A("rtw_macaddr_cfg23a MAC Address = "MAC_FMT"\n",
1217 void dump_ies23a(u8 *buf, u32 buf_len) {
1221 while (pos-buf <= buf_len) {
1225 DBG_8723A("%s ID:%u, LEN:%u\n", __func__, id, len);
1226 #ifdef CONFIG_8723AU_P2P
1227 dump_p2p_ie23a(pos, len);
1229 dump_wps_ie23a(pos, len);
1235 void dump_wps_ie23a(u8 *ie, u32 ie_len) {
1243 wps_ie = rtw_get_wps_ie23a(ie, ie_len, NULL, &wps_ielen);
1244 if (wps_ie != ie || wps_ielen == 0)
1248 while (pos-ie < ie_len) {
1249 id = get_unaligned_be16(pos);
1250 len = get_unaligned_be16(pos + 2);
1252 DBG_8723A("%s ID:0x%04x, LEN:%u\n", __func__, id, len);
1258 #ifdef CONFIG_8723AU_P2P
1259 void dump_p2p_ie23a(u8 *ie, u32 ie_len) {
1267 p2p_ie = rtw_get_p2p_ie23a(ie, ie_len, NULL, &p2p_ielen);
1268 if (p2p_ie != ie || p2p_ielen == 0)
1272 while (pos-ie < ie_len) {
1274 len = get_unaligned_le16(pos+1);
1276 DBG_8723A("%s ID:%u, LEN:%u\n", __func__, id, len);
1283 * rtw_get_p2p_ie23a - Search P2P IE from a series of IEs
1284 * @in_ie: Address of IEs to search
1285 * @in_len: Length limit from in_ie
1286 * @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the
1287 * buf starting from p2p_ie
1288 * @p2p_ielen: If not NULL and P2P IE is found, will set to the length of
1291 * Returns: The address of the P2P IE found, or NULL
1293 u8 *rtw_get_p2p_ie23a(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)
1297 u8 eid, p2p_oui[4]={0x50, 0x6F, 0x9A, 0x09};
1302 while (cnt<in_len) {
1304 if ((in_len < 0) || (cnt > MAX_IE_SZ)) {
1308 if ((eid == _VENDOR_SPECIFIC_IE_) &&
1309 !memcmp(&in_ie[cnt + 2], p2p_oui, 4)) {
1310 p2p_ie_ptr = in_ie + cnt;
1312 if (p2p_ie != NULL) {
1313 memcpy(p2p_ie, &in_ie[cnt],
1314 in_ie[cnt + 1] + 2);
1317 if (p2p_ielen != NULL) {
1318 *p2p_ielen = in_ie[cnt + 1] + 2;
1325 cnt += in_ie[cnt + 1] + 2; /* goto next */
1333 * rtw_get_p2p_attr23a - Search a specific P2P attribute from a given P2P IE
1334 * @p2p_ie: Address of P2P IE to search
1335 * @p2p_ielen: Length limit from p2p_ie
1336 * @target_attr_id: The attribute ID of P2P attribute to search
1337 * @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will
1338 * be copied to the buf starting from buf_attr
1339 * @len_attr: If not NULL and the P2P attribute is found, will set to the
1340 * length of the entire P2P attribute
1342 * Returns: the address of the specific WPS attribute found, or NULL
1344 u8 *rtw_get_p2p_attr23a(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
1345 u8 *buf_attr, u32 *len_attr)
1347 u8 *attr_ptr = NULL;
1348 u8 *target_attr_ptr = NULL;
1349 u8 p2p_oui[4]={0x50, 0x6F, 0x9A, 0x09};
1354 if (!p2p_ie || (p2p_ie[0] != _VENDOR_SPECIFIC_IE_) ||
1355 memcmp(p2p_ie + 2, p2p_oui, 4)) {
1359 /* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */
1360 attr_ptr = p2p_ie + 6; /* goto first attr */
1362 while (attr_ptr - p2p_ie < p2p_ielen) {
1363 /* 3 = 1(Attribute ID) + 2(Length) */
1364 u8 attr_id = *attr_ptr;
1365 u16 attr_data_len = get_unaligned_le16(attr_ptr + 1);
1366 u16 attr_len = attr_data_len + 3;
1368 /* DBG_8723A("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len); */
1369 if (attr_id == target_attr_id) {
1370 target_attr_ptr = attr_ptr;
1373 memcpy(buf_attr, attr_ptr, attr_len);
1376 *len_attr = attr_len;
1380 attr_ptr += attr_len; /* goto next */
1384 return target_attr_ptr;
1388 * rtw_get_p2p_attr23a_content - Search a specific P2P attribute content from
1390 * @p2p_ie: Address of P2P IE to search
1391 * @p2p_ielen: Length limit from p2p_ie
1392 * @target_attr_id: The attribute ID of P2P attribute to search
1393 * @buf_content: If not NULL and the P2P attribute is found, P2P attribute
1394 * content will be copied to the buf starting from buf_content
1395 * @len_content: If not NULL and the P2P attribute is found, will set to the
1396 * length of the P2P attribute content
1398 * Returns: the address of the specific P2P attribute content found, or NULL
1400 u8 *rtw_get_p2p_attr23a_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
1401 u8 *buf_content, uint *len_content)
1409 attr_ptr = rtw_get_p2p_attr23a(p2p_ie, p2p_ielen, target_attr_id,
1412 if (attr_ptr && attr_len) {
1414 memcpy(buf_content, attr_ptr + 3, attr_len - 3);
1417 *len_content = attr_len - 3;
1425 u32 rtw_set_p2p_attr_content23a(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)
1431 /* u16*)(pbuf + 1) = cpu_to_le16(attr_len); */
1432 put_unaligned_le16(attr_len, pbuf + 1);
1435 memcpy(pbuf + 3, pdata_attr, attr_len);
1437 a_len = attr_len + 3;
1442 static uint rtw_p2p_attr_remove(u8 *ie, uint ielen_ori, u8 attr_id)
1445 u32 target_attr_len;
1446 uint ielen = ielen_ori;
1449 target_attr = rtw_get_p2p_attr23a(ie, ielen, attr_id, NULL,
1451 if (target_attr && target_attr_len) {
1452 u8 *next_attr = target_attr+target_attr_len;
1453 uint remain_len = ielen-(next_attr-ie);
1454 /* dump_ies23a(ie, ielen); */
1456 memset(target_attr, 0, target_attr_len);
1457 memcpy(target_attr, next_attr, remain_len);
1458 memset(target_attr+remain_len, 0, target_attr_len);
1459 *(ie + 1) -= target_attr_len;
1460 ielen -= target_attr_len;
1463 /* dump_ies23a(ie, ielen); */
1471 void rtw_wlan_bssid_ex_remove_p2p_attr23a(struct wlan_bssid_ex *bss_ex, u8 attr_id)
1474 uint p2p_ielen, p2p_ielen_ori;
1476 if ((p2p_ie = rtw_get_p2p_ie23a(bss_ex->IEs + _FIXED_IE_LENGTH_,
1477 bss_ex->IELength - _FIXED_IE_LENGTH_,
1478 NULL, &p2p_ielen_ori))) {
1479 p2p_ielen = rtw_p2p_attr_remove(p2p_ie, p2p_ielen_ori, attr_id);
1480 if (p2p_ielen != p2p_ielen_ori) {
1481 u8 *next_ie_ori = p2p_ie+p2p_ielen_ori;
1482 u8 *next_ie = p2p_ie+p2p_ielen;
1484 remain_len = bss_ex->IELength-(next_ie_ori-bss_ex->IEs);
1486 memcpy(next_ie, next_ie_ori, remain_len);
1487 memset(next_ie+remain_len, 0, p2p_ielen_ori-p2p_ielen);
1488 bss_ex->IELength -= p2p_ielen_ori-p2p_ielen;
1493 #endif /* CONFIG_8723AU_P2P */
1495 #ifdef CONFIG_8723AU_P2P
1496 int rtw_get_wfd_ie(u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen)
1500 u8 eid, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
1508 while (cnt < in_len)
1512 if ((eid == _VENDOR_SPECIFIC_IE_) &&
1513 !memcmp(&in_ie[cnt+2], wfd_oui, 4)) {
1514 if (wfd_ie != NULL) {
1515 memcpy(wfd_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
1518 if (wfd_ielen != NULL) {
1523 if (wfd_ielen != NULL) {
1524 *wfd_ielen = in_ie[cnt + 1] + 2;
1527 cnt += in_ie[cnt + 1] + 2;
1532 cnt += in_ie[cnt + 1] +2; /* goto next */
1536 if (match == true) {
1543 /* attr_content: The output buffer, contains the "body field" of
1545 /* attr_contentlen: The data length of the "body field" of WFD
1547 int rtw_get_wfd_attr_content(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id,
1548 u8 *attr_content, uint *attr_contentlen)
1552 u8 attr_id, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};
1556 if ((wfd_ie[0] != _VENDOR_SPECIFIC_IE_) ||
1557 memcmp(wfd_ie + 2, wfd_oui, 4)) {
1561 /* 1 (WFD IE) + 1 (Length) + 3 (OUI) + 1 (OUI Type) */
1563 while (cnt < wfd_ielen) {
1564 u16 attrlen = get_unaligned_be16(wfd_ie + cnt + 1);
1566 attr_id = wfd_ie[cnt];
1567 if (attr_id == target_attr_id) {
1568 /* 3 -> 1 byte for attribute ID field, 2
1569 bytes for length field */
1571 memcpy(attr_content, &wfd_ie[cnt + 3], attrlen);
1573 if (attr_contentlen)
1574 *attr_contentlen = attrlen;
1581 cnt += attrlen + 3; /* goto next */
1587 #endif /* CONFIG_8723AU_P2P */
1589 /* Baron adds to avoid FreeBSD warning */
1590 int ieee80211_is_empty_essid23a(const char *essid, int essid_len)
1592 /* Single white space is for Linksys APs */
1593 if (essid_len == 1 && essid[0] == ' ')
1596 /* Otherwise, if the entire essid is 0, we assume it is hidden */
1599 if (essid[essid_len] != '\0')
1606 static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1609 unsigned char *pbuf;
1610 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1613 pbuf = rtw_get_wpa_ie23a(&pnetwork->network.IEs[12], &wpa_ielen,
1614 pnetwork->network.IELength - 12);
1616 if (pbuf && (wpa_ielen > 0)) {
1617 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1618 ("rtw_get_cipher_info: wpa_ielen: %d", wpa_ielen));
1619 r = rtw_parse_wpa_ie23a(pbuf, wpa_ielen + 2, &group_cipher,
1620 &pairwise_cipher, &is8021x);
1621 if (r == _SUCCESS) {
1622 pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher;
1623 pnetwork->BcnInfo.group_cipher = group_cipher;
1624 pnetwork->BcnInfo.is_8021x = is8021x;
1625 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1626 ("%s: pnetwork->pairwise_cipher: %d, is_"
1627 "8021x is %d", __func__,
1628 pnetwork->BcnInfo.pairwise_cipher,
1629 pnetwork->BcnInfo.is_8021x));
1633 pbuf = rtw_get_wpa2_ie23a(&pnetwork->network.IEs[12], &wpa_ielen,
1634 pnetwork->network.IELength - 12);
1636 if (pbuf && (wpa_ielen > 0)) {
1637 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1639 r = rtw_parse_wpa2_ie23a(pbuf, wpa_ielen + 2,
1640 &group_cipher, &pairwise_cipher,
1642 if (r == _SUCCESS) {
1643 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1644 ("get RSN IE OK!!!\n"));
1645 pnetwork->BcnInfo.pairwise_cipher =
1647 pnetwork->BcnInfo.group_cipher = group_cipher;
1648 pnetwork->BcnInfo.is_8021x = is8021x;
1649 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1650 ("%s: pnetwork->pairwise_cipher: %d,"
1651 "pnetwork->group_cipher is %d, "
1652 "is_8021x is %d", __func__,
1653 pnetwork->BcnInfo.pairwise_cipher,
1654 pnetwork->BcnInfo.group_cipher,
1655 pnetwork->BcnInfo.is_8021x));
1664 void rtw_get_bcn_info23a(struct wlan_network *pnetwork)
1666 unsigned short cap = 0;
1668 /* u8 wpa_ie[255], rsn_ie[255]; */
1669 u16 wpa_len = 0, rsn_len = 0;
1670 struct HT_info_element *pht_info = NULL;
1671 struct ieee80211_ht_cap *pht_cap = NULL;
1675 memcpy(&cap, rtw_get_capability23a_from_ie(pnetwork->network.IEs), 2);
1676 cap = le16_to_cpu(cap);
1677 if (cap & WLAN_CAPABILITY_PRIVACY) {
1679 pnetwork->network.Privacy = 1;
1681 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_OPENSYS;
1683 rtw_get_sec_ie23a(pnetwork->network.IEs, pnetwork->network.IELength,
1684 NULL, &rsn_len, NULL, &wpa_len);
1685 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1686 ("rtw_get_bcn_info23a: ssid =%s\n", pnetwork->network.Ssid.ssid));
1687 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1688 ("rtw_get_bcn_info23a: wpa_len =%d rsn_len =%d\n",
1690 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1691 ("rtw_get_bcn_info23a: ssid =%s\n", pnetwork->network.Ssid.ssid));
1692 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1693 ("rtw_get_bcn_info23a: wpa_len =%d rsn_len =%d\n",
1697 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA2;
1698 } else if (wpa_len > 0) {
1699 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WPA;
1702 pnetwork->BcnInfo.encryp_protocol = ENCRYP_PROTOCOL_WEP;
1704 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1705 ("rtw_get_bcn_info23a: pnetwork->encryp_protocol is %x\n",
1706 pnetwork->BcnInfo.encryp_protocol));
1707 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
1708 ("rtw_get_bcn_info23a: pnetwork->encryp_protocol is %x\n",
1709 pnetwork->BcnInfo.encryp_protocol));
1710 rtw_get_cipher_info(pnetwork);
1712 /* get bwmode and ch_offset */
1713 /* parsing HT_CAP_IE */
1714 p = rtw_get_ie23a(pnetwork->network.IEs + _FIXED_IE_LENGTH_,
1715 _HT_CAPABILITY_IE_, &len,
1716 pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1718 pht_cap = (struct ieee80211_ht_cap *)(p + 2);
1719 pnetwork->BcnInfo.ht_cap_info = pht_cap->cap_info;
1721 pnetwork->BcnInfo.ht_cap_info = 0;
1723 /* parsing HT_INFO_IE */
1724 p = rtw_get_ie23a(pnetwork->network.IEs + _FIXED_IE_LENGTH_,
1725 _HT_ADD_INFO_IE_, &len,
1726 pnetwork->network.IELength - _FIXED_IE_LENGTH_);
1728 pht_info = (struct HT_info_element *)(p + 2);
1729 pnetwork->BcnInfo.ht_info_infos_0 = pht_info->infos[0];
1731 pnetwork->BcnInfo.ht_info_infos_0 = 0;
1735 /* show MCS rate, unit: 100Kbps */
1736 u16 rtw_mcs_rate23a(u8 rf_type, u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40,
1737 unsigned char * MCS_rate)
1741 if (rf_type == RF_1T1R) {
1742 if (MCS_rate[0] & BIT(7))
1743 max_rate = (bw_40MHz) ? ((short_GI_40)?1500:1350):
1744 ((short_GI_20)?722:650);
1745 else if (MCS_rate[0] & BIT(6))
1746 max_rate = (bw_40MHz) ? ((short_GI_40)?1350:1215):
1747 ((short_GI_20)?650:585);
1748 else if (MCS_rate[0] & BIT(5))
1749 max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080):
1750 ((short_GI_20)?578:520);
1751 else if (MCS_rate[0] & BIT(4))
1752 max_rate = (bw_40MHz) ? ((short_GI_40)?900:810):
1753 ((short_GI_20)?433:390);
1754 else if (MCS_rate[0] & BIT(3))
1755 max_rate = (bw_40MHz) ? ((short_GI_40)?600:540):
1756 ((short_GI_20)?289:260);
1757 else if (MCS_rate[0] & BIT(2))
1758 max_rate = (bw_40MHz) ? ((short_GI_40)?450:405):
1759 ((short_GI_20)?217:195);
1760 else if (MCS_rate[0] & BIT(1))
1761 max_rate = (bw_40MHz) ? ((short_GI_40)?300:270):
1762 ((short_GI_20)?144:130);
1763 else if (MCS_rate[0] & BIT(0))
1764 max_rate = (bw_40MHz) ? ((short_GI_40)?150:135):
1765 ((short_GI_20)?72:65);
1768 if (MCS_rate[1] & BIT(7))
1769 max_rate = (bw_40MHz) ? ((short_GI_40)?3000:2700):((short_GI_20)?1444:1300);
1770 else if (MCS_rate[1] & BIT(6))
1771 max_rate = (bw_40MHz) ? ((short_GI_40)?2700:2430):((short_GI_20)?1300:1170);
1772 else if (MCS_rate[1] & BIT(5))
1773 max_rate = (bw_40MHz) ? ((short_GI_40)?2400:2160):((short_GI_20)?1156:1040);
1774 else if (MCS_rate[1] & BIT(4))
1775 max_rate = (bw_40MHz) ? ((short_GI_40)?1800:1620):((short_GI_20)?867:780);
1776 else if (MCS_rate[1] & BIT(3))
1777 max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080):((short_GI_20)?578:520);
1778 else if (MCS_rate[1] & BIT(2))
1779 max_rate = (bw_40MHz) ? ((short_GI_40)?900:810):((short_GI_20)?433:390);
1780 else if (MCS_rate[1] & BIT(1))
1781 max_rate = (bw_40MHz) ? ((short_GI_40)?600:540):((short_GI_20)?289:260);
1782 else if (MCS_rate[1] & BIT(0))
1783 max_rate = (bw_40MHz) ? ((short_GI_40)?300:270):((short_GI_20)?144:130);
1785 if (MCS_rate[0] & BIT(7))
1786 max_rate = (bw_40MHz) ? ((short_GI_40)?1500:1350):((short_GI_20)?722:650);
1787 else if (MCS_rate[0] & BIT(6))
1788 max_rate = (bw_40MHz) ? ((short_GI_40)?1350:1215):((short_GI_20)?650:585);
1789 else if (MCS_rate[0] & BIT(5))
1790 max_rate = (bw_40MHz) ? ((short_GI_40)?1200:1080):((short_GI_20)?578:520);
1791 else if (MCS_rate[0] & BIT(4))
1792 max_rate = (bw_40MHz) ? ((short_GI_40)?900:810):((short_GI_20)?433:390);
1793 else if (MCS_rate[0] & BIT(3))
1794 max_rate = (bw_40MHz) ? ((short_GI_40)?600:540):((short_GI_20)?289:260);
1795 else if (MCS_rate[0] & BIT(2))
1796 max_rate = (bw_40MHz) ? ((short_GI_40)?450:405):((short_GI_20)?217:195);
1797 else if (MCS_rate[0] & BIT(1))
1798 max_rate = (bw_40MHz) ? ((short_GI_40)?300:270):((short_GI_20)?144:130);
1799 else if (MCS_rate[0] & BIT(0))
1800 max_rate = (bw_40MHz) ? ((short_GI_40)?150:135):((short_GI_20)?72:65);
1806 int rtw_action_frame_parse23a(const u8 *frame, u32 frame_len, u8* category,
1809 const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr);
1813 fc = le16_to_cpu(((struct ieee80211_hdr_3addr *)frame)->frame_control);
1815 if ((fc & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)) !=
1816 (IEEE80211_FTYPE_MGMT|IEEE80211_STYPE_ACTION)) {
1823 case WLAN_CATEGORY_VENDOR_SPECIFIC: /* vendor-specific */
1837 static const char *_action_public_str23a[] = {
1838 "ACT_PUB_BSSCOEXIST",
1839 "ACT_PUB_DSE_ENABLE",
1840 "ACT_PUB_DSE_DEENABLE",
1841 "ACT_PUB_DSE_REG_LOCATION",
1842 "ACT_PUB_EXT_CHL_SWITCH",
1843 "ACT_PUB_DSE_MSR_REQ",
1844 "ACT_PUB_DSE_MSR_RPRT",
1846 "ACT_PUB_DSE_PWR_CONSTRAINT",
1848 "ACT_PUB_GAS_INITIAL_REQ",
1849 "ACT_PUB_GAS_INITIAL_RSP",
1850 "ACT_PUB_GAS_COMEBACK_REQ",
1851 "ACT_PUB_GAS_COMEBACK_RSP",
1852 "ACT_PUB_TDLS_DISCOVERY_RSP",
1853 "ACT_PUB_LOCATION_TRACK",
1857 const char *action_public_str23a(u8 action)
1859 action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
1860 return _action_public_str23a[action];