Path: blob/master/ALFA-W1F1/RTL8814AU/core/rtw_ieee80211.c
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#define _IEEE80211_C1516#ifdef CONFIG_PLATFORM_INTEL_BYT17#include <linux/fs.h>18#endif19#include <drv_types.h>202122u8 RTW_WPA_OUI_TYPE[] = { 0x00, 0x50, 0xf2, 1 };23u16 RTW_WPA_VERSION = 1;24u8 WPA_AUTH_KEY_MGMT_NONE[] = { 0x00, 0x50, 0xf2, 0 };25u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[] = { 0x00, 0x50, 0xf2, 1 };26u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[] = { 0x00, 0x50, 0xf2, 2 };27u8 WPA_CIPHER_SUITE_NONE[] = { 0x00, 0x50, 0xf2, 0 };28u8 WPA_CIPHER_SUITE_WEP40[] = { 0x00, 0x50, 0xf2, 1 };29u8 WPA_CIPHER_SUITE_TKIP[] = { 0x00, 0x50, 0xf2, 2 };30u8 WPA_CIPHER_SUITE_WRAP[] = { 0x00, 0x50, 0xf2, 3 };31u8 WPA_CIPHER_SUITE_CCMP[] = { 0x00, 0x50, 0xf2, 4 };32u8 WPA_CIPHER_SUITE_WEP104[] = { 0x00, 0x50, 0xf2, 5 };3334u16 RSN_VERSION_BSD = 1;35u8 RSN_CIPHER_SUITE_NONE[] = { 0x00, 0x0f, 0xac, 0 };36u8 RSN_CIPHER_SUITE_WEP40[] = { 0x00, 0x0f, 0xac, 1 };37u8 RSN_CIPHER_SUITE_TKIP[] = { 0x00, 0x0f, 0xac, 2 };38u8 RSN_CIPHER_SUITE_WRAP[] = { 0x00, 0x0f, 0xac, 3 };39u8 RSN_CIPHER_SUITE_CCMP[] = { 0x00, 0x0f, 0xac, 4 };40u8 RSN_CIPHER_SUITE_WEP104[] = { 0x00, 0x0f, 0xac, 5 };4142u8 WLAN_AKM_8021X[] = {0x00, 0x0f, 0xac, 1};43u8 WLAN_AKM_PSK[] = {0x00, 0x0f, 0xac, 2};44u8 WLAN_AKM_FT_8021X[] = {0x00, 0x0f, 0xac, 3};45u8 WLAN_AKM_FT_PSK[] = {0x00, 0x0f, 0xac, 4};46u8 WLAN_AKM_8021X_SHA256[] = {0x00, 0x0f, 0xac, 5};47u8 WLAN_AKM_PSK_SHA256[] = {0x00, 0x0f, 0xac, 6};48u8 WLAN_AKM_TDLS[] = {0x00, 0x0f, 0xac, 7};49u8 WLAN_AKM_SAE[] = {0x00, 0x0f, 0xac, 8};50u8 WLAN_AKM_FT_OVER_SAE[] = {0x00, 0x0f, 0xac, 9};51u8 WLAN_AKM_8021X_SUITE_B[] = {0x00, 0x0f, 0xac, 11};52u8 WLAN_AKM_8021X_SUITE_B_192[] = {0x00, 0x0f, 0xac, 12};53u8 WLAN_AKM_FILS_SHA256[] = {0x00, 0x0f, 0xac, 14};54u8 WLAN_AKM_FILS_SHA384[] = {0x00, 0x0f, 0xac, 15};55u8 WLAN_AKM_FT_FILS_SHA256[] = {0x00, 0x0f, 0xac, 16};56u8 WLAN_AKM_FT_FILS_SHA384[] = {0x00, 0x0f, 0xac, 17};57/* -----------------------------------------------------------58* for adhoc-master to generate ie and provide supported-rate to fw59* ----------------------------------------------------------- */6061u8 WIFI_CCKRATES[] = {62(IEEE80211_CCK_RATE_1MB | IEEE80211_BASIC_RATE_MASK),63(IEEE80211_CCK_RATE_2MB | IEEE80211_BASIC_RATE_MASK),64(IEEE80211_CCK_RATE_5MB | IEEE80211_BASIC_RATE_MASK),65(IEEE80211_CCK_RATE_11MB | IEEE80211_BASIC_RATE_MASK)66};6768u8 WIFI_OFDMRATES[] = {69(IEEE80211_OFDM_RATE_6MB),70(IEEE80211_OFDM_RATE_9MB),71(IEEE80211_OFDM_RATE_12MB),72(IEEE80211_OFDM_RATE_18MB),73(IEEE80211_OFDM_RATE_24MB),74IEEE80211_OFDM_RATE_36MB,75IEEE80211_OFDM_RATE_48MB,76IEEE80211_OFDM_RATE_54MB77};7879u8 mgn_rates_cck[4] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M};80u8 mgn_rates_ofdm[8] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M};81u8 mgn_rates_mcs0_7[8] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7};82u8 mgn_rates_mcs8_15[8] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15};83u8 mgn_rates_mcs16_23[8] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23};84u8 mgn_rates_mcs24_31[8] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31};85u8 mgn_rates_vht1ss[10] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS486, MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS987};88u8 mgn_rates_vht2ss[10] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS489, MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS990};91u8 mgn_rates_vht3ss[10] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS492, MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS993};94u8 mgn_rates_vht4ss[10] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS495, MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS996};9798static const char *const _rate_section_str[] = {99"CCK",100"OFDM",101"HT_1SS",102"HT_2SS",103"HT_3SS",104"HT_4SS",105"VHT_1SS",106"VHT_2SS",107"VHT_3SS",108"VHT_4SS",109"RATE_SECTION_UNKNOWN",110};111112const char *rate_section_str(u8 section)113{114section = (section >= RATE_SECTION_NUM) ? RATE_SECTION_NUM : section;115return _rate_section_str[section];116}117118struct rate_section_ent rates_by_sections[RATE_SECTION_NUM] = {119{RF_1TX, 4, mgn_rates_cck},120{RF_1TX, 8, mgn_rates_ofdm},121{RF_1TX, 8, mgn_rates_mcs0_7},122{RF_2TX, 8, mgn_rates_mcs8_15},123{RF_3TX, 8, mgn_rates_mcs16_23},124{RF_4TX, 8, mgn_rates_mcs24_31},125{RF_1TX, 10, mgn_rates_vht1ss},126{RF_2TX, 10, mgn_rates_vht2ss},127{RF_3TX, 10, mgn_rates_vht3ss},128{RF_4TX, 10, mgn_rates_vht4ss},129};130131int rtw_get_bit_value_from_ieee_value(u8 val)132{133unsigned char dot11_rate_table[] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; /* last element must be zero!! */134135int i = 0;136while (dot11_rate_table[i] != 0) {137if (dot11_rate_table[i] == val)138return BIT(i);139i++;140}141return 0;142}143uint rtw_get_cckrate_size(u8 *rate, u32 rate_length)144{145int i = 0;146while(i < rate_length){147RTW_DBG("%s, rate[%d]=%u\n", __FUNCTION__, i, rate[i]);148if (((rate[i] & 0x7f) == 2) || ((rate[i] & 0x7f) == 4) ||149((rate[i] & 0x7f) == 11) || ((rate[i] & 0x7f) == 22))150i++;151else152break;153}154return i;155}156157uint rtw_is_cckrates_included(u8 *rate)158{159u32 i = 0;160161while (rate[i] != 0) {162if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||163(((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))164return _TRUE;165i++;166}167168return _FALSE;169}170171uint rtw_is_cckratesonly_included(u8 *rate)172{173u32 i = 0;174175176while (rate[i] != 0) {177if ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&178(((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22))179return _FALSE;180181i++;182}183184return _TRUE;185186}187188int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)189{190if (channel > 14) {191if ((rtw_is_cckrates_included(rate)) == _TRUE)192return WIRELESS_INVALID;193else194return WIRELESS_11A;195} else { /* could be pure B, pure G, or B/G */196if ((rtw_is_cckratesonly_included(rate)) == _TRUE)197return WIRELESS_11B;198else if ((rtw_is_cckrates_included(rate)) == _TRUE)199return WIRELESS_11BG;200else201return WIRELESS_11G;202}203204}205206u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,207unsigned int *frlen)208{209_rtw_memcpy((void *)pbuf, (void *)source, len);210*frlen = *frlen + len;211return pbuf + len;212}213214/* rtw_set_ie will update frame length */215u8 *rtw_set_ie216(217u8 *pbuf,218sint index,219uint len,220const u8 *source,221uint *frlen /* frame length */222)223{224*pbuf = (u8)index;225226*(pbuf + 1) = (u8)len;227228if (len > 0)229_rtw_memcpy((void *)(pbuf + 2), (void *)source, len);230231if (frlen)232*frlen = *frlen + (len + 2);233234return pbuf + len + 2;235}236237inline u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,238u8 new_ch, u8 ch_switch_cnt)239{240u8 ie_data[3];241242ie_data[0] = ch_switch_mode;243ie_data[1] = new_ch;244ie_data[2] = ch_switch_cnt;245return rtw_set_ie(buf, WLAN_EID_CHANNEL_SWITCH, 3, ie_data, buf_len);246}247248inline u8 secondary_ch_offset_to_hal_ch_offset(u8 ch_offset)249{250if (ch_offset == SCN)251return HAL_PRIME_CHNL_OFFSET_DONT_CARE;252else if (ch_offset == SCA)253return HAL_PRIME_CHNL_OFFSET_LOWER;254else if (ch_offset == SCB)255return HAL_PRIME_CHNL_OFFSET_UPPER;256257return HAL_PRIME_CHNL_OFFSET_DONT_CARE;258}259260inline u8 hal_ch_offset_to_secondary_ch_offset(u8 ch_offset)261{262if (ch_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE)263return SCN;264else if (ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)265return SCA;266else if (ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)267return SCB;268269return SCN;270}271272inline u8 *rtw_set_ie_secondary_ch_offset(u8 *buf, u32 *buf_len, u8 secondary_ch_offset)273{274return rtw_set_ie(buf, WLAN_EID_SECONDARY_CHANNEL_OFFSET, 1, &secondary_ch_offset, buf_len);275}276277inline u8 *rtw_set_ie_mesh_ch_switch_parm(u8 *buf, u32 *buf_len, u8 ttl,278u8 flags, u16 reason, u16 precedence)279{280u8 ie_data[6];281282ie_data[0] = ttl;283ie_data[1] = flags;284RTW_PUT_LE16((u8 *)&ie_data[2], reason);285RTW_PUT_LE16((u8 *)&ie_data[4], precedence);286287return rtw_set_ie(buf, 0x118, 6, ie_data, buf_len);288}289290/*----------------------------------------------------------------------------291index: the information element id index, limit is the limit for search292-----------------------------------------------------------------------------*/293u8 *rtw_get_ie(const u8 *pbuf, sint index, sint *len, sint limit)294{295sint tmp, i;296const u8 *p;297if (limit < 1) {298return NULL;299}300301p = pbuf;302i = 0;303*len = 0;304while (1) {305if (*p == index) {306*len = *(p + 1);307return (u8 *)p;308} else {309tmp = *(p + 1);310p += (tmp + 2);311i += (tmp + 2);312}313if (i >= limit)314break;315}316return NULL;317}318319/**320* rtw_get_ie_ex - Search specific IE from a series of IEs321* @in_ie: Address of IEs to search322* @in_len: Length limit from in_ie323* @eid: Element ID to match324* @oui: OUI to match325* @oui_len: OUI length326* @ie: If not NULL and the specific IE is found, the IE will be copied to the buf starting from the specific IE327* @ielen: If not NULL and the specific IE is found, will set to the length of the entire IE328*329* Returns: The address of the specific IE found, or NULL330*/331u8 *rtw_get_ie_ex(const u8 *in_ie, uint in_len, u8 eid, const u8 *oui, u8 oui_len, u8 *ie, uint *ielen)332{333uint cnt;334const u8 *target_ie = NULL;335336337if (ielen)338*ielen = 0;339340if (!in_ie || in_len <= 0)341return (u8 *)target_ie;342343cnt = 0;344345while (cnt < in_len) {346if (eid == in_ie[cnt]347&& (!oui || _rtw_memcmp(&in_ie[cnt + 2], oui, oui_len) == _TRUE)) {348target_ie = &in_ie[cnt];349350if (ie)351_rtw_memcpy(ie, &in_ie[cnt], in_ie[cnt + 1] + 2);352353if (ielen)354*ielen = in_ie[cnt + 1] + 2;355356break;357} else {358cnt += in_ie[cnt + 1] + 2; /* goto next */359}360361}362363return (u8 *)target_ie;364}365366/**367* rtw_ies_remove_ie - Find matching IEs and remove368* @ies: Address of IEs to search369* @ies_len: Pointer of length of ies, will update to new length370* @offset: The offset to start scarch371* @eid: Element ID to match372* @oui: OUI to match373* @oui_len: OUI length374*375* Returns: _SUCCESS: ies is updated, _FAIL: not updated376*/377int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len)378{379int ret = _FAIL;380u8 *target_ie;381u32 target_ielen;382u8 *start;383uint search_len;384385if (!ies || !ies_len || *ies_len <= offset)386goto exit;387388start = ies + offset;389search_len = *ies_len - offset;390391while (1) {392target_ie = rtw_get_ie_ex(start, search_len, eid, oui, oui_len, NULL, &target_ielen);393if (target_ie && target_ielen) {394u8 *remain_ies = target_ie + target_ielen;395uint remain_len = search_len - (remain_ies - start);396397_rtw_memmove(target_ie, remain_ies, remain_len);398*ies_len = *ies_len - target_ielen;399ret = _SUCCESS;400401start = target_ie;402search_len = remain_len;403} else404break;405}406exit:407return ret;408}409410void rtw_set_supported_rate(u8 *SupportedRates, uint mode)411{412413_rtw_memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);414415switch (mode) {416case WIRELESS_11B:417_rtw_memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);418break;419420case WIRELESS_11G:421case WIRELESS_11A:422case WIRELESS_11_5N:423case WIRELESS_11A_5N: /* Todo: no basic rate for ofdm ? */424case WIRELESS_11_5AC:425_rtw_memcpy(SupportedRates, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);426break;427428case WIRELESS_11BG:429case WIRELESS_11G_24N:430case WIRELESS_11_24N:431case WIRELESS_11BG_24N:432_rtw_memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);433_rtw_memcpy(SupportedRates + IEEE80211_CCK_RATE_LEN, WIFI_OFDMRATES, IEEE80211_NUM_OFDM_RATESLEN);434break;435436}437}438439void rtw_filter_suppport_rateie(WLAN_BSSID_EX *pbss_network, u8 keep)440{441u8 i, idx = 0, new_rate[NDIS_802_11_LENGTH_RATES_EX], *p;442uint iscck, isofdm, ie_orilen = 0, remain_len;443u8 *remain_ies;444445p = rtw_get_ie(pbss_network->IEs + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_, &ie_orilen, (pbss_network->IELength - _BEACON_IE_OFFSET_));446if (!p)447return;448449_rtw_memset(new_rate, 0, NDIS_802_11_LENGTH_RATES_EX);450for (i=0; i < ie_orilen; i++) {451iscck = rtw_is_cck_rate(p[i+2]);452isofdm= rtw_is_ofdm_rate(p[i+2]);453if (((keep == CCK) && iscck)454|| ((keep == OFDM) && isofdm))455new_rate[idx++]= rtw_is_basic_rate_ofdm(p[i+2]) ? p[i+2]|IEEE80211_BASIC_RATE_MASK : p[i+2];456}457/* update rate ie */458p[1] = idx;459_rtw_memcpy(p+2, new_rate, idx);460/* update remain ie & IELength*/461remain_ies = p + 2 + ie_orilen;462remain_len = pbss_network->IELength - (remain_ies - pbss_network->IEs);463_rtw_memmove(p+2+idx, remain_ies, remain_len);464pbss_network->IELength -= (ie_orilen - idx);465}466467468/*469Adjust those items by given wireless_mode4701. pbss_network->IELength4712. pbss_network->IE (SUPPORTRATE & EXT_SUPPORTRATE)4723. pbss_network->SupportedRates473*/474475u8 rtw_update_rate_bymode(WLAN_BSSID_EX *pbss_network, u32 mode)476{477u8 network_type, *p, *ie = pbss_network->IEs;478sint ie_len;479uint network_ielen = pbss_network->IELength;480481if (mode == WIRELESS_11B) {482/*only keep CCK in support_rate IE and remove whole ext_support_rate IE*/483rtw_filter_suppport_rateie(pbss_network, CCK);484p = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, &ie_len, pbss_network->IELength - _BEACON_IE_OFFSET_);485if (p) {486rtw_ies_remove_ie(ie , &network_ielen, _BEACON_IE_OFFSET_, _EXT_SUPPORTEDRATES_IE_, NULL, 0);487pbss_network->IELength -= ie_len;488}489network_type = WIRELESS_11B;490} else if ((mode & WIRELESS_11B) == 0) {491/* Remove CCK in support_rate IE */492rtw_filter_suppport_rateie(pbss_network, OFDM);493if (pbss_network->Configuration.DSConfig > 14)494network_type = WIRELESS_11A;495else496network_type = WIRELESS_11G;497} else498network_type = WIRELESS_11BG; /* do nothing */499500rtw_set_supported_rate(pbss_network->SupportedRates, network_type);501return network_type;502}503504uint rtw_get_rateset_len(u8 *rateset)505{506uint i = 0;507while (1) {508if ((rateset[i]) == 0)509break;510511if (i > 12)512break;513514i++;515}516return i;517}518519int rtw_generate_ie(struct registry_priv *pregistrypriv)520{521u8 wireless_mode;522int sz = 0, rateLen;523WLAN_BSSID_EX *pdev_network = &pregistrypriv->dev_network;524u8 *ie = pdev_network->IEs;525526527/* timestamp will be inserted by hardware */528sz += 8;529ie += sz;530531/* beacon interval : 2bytes */532*(u16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod); /* BCN_INTERVAL; */533sz += 2;534ie += 2;535536/* capability info */537*(u16 *)ie = 0;538539*(u16 *)ie |= cpu_to_le16(cap_IBSS);540541if (pregistrypriv->preamble == PREAMBLE_SHORT)542*(u16 *)ie |= cpu_to_le16(cap_ShortPremble);543544if (pdev_network->Privacy)545*(u16 *)ie |= cpu_to_le16(cap_Privacy);546547sz += 2;548ie += 2;549550/* SSID */551ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->Ssid.SsidLength, pdev_network->Ssid.Ssid, &sz);552553/* supported rates */554if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) {555if (pdev_network->Configuration.DSConfig > 14)556wireless_mode = WIRELESS_11A_5N;557else558wireless_mode = WIRELESS_11BG_24N;559} else if (pregistrypriv->wireless_mode == WIRELESS_MODE_MAX) { /* WIRELESS_11ABGN | WIRELESS_11AC */560if (pdev_network->Configuration.DSConfig > 14)561wireless_mode = WIRELESS_11_5AC;562else563wireless_mode = WIRELESS_11BG_24N;564} else565wireless_mode = pregistrypriv->wireless_mode;566567rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode) ;568569rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);570571if (rateLen > 8) {572ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, 8, pdev_network->SupportedRates, &sz);573/* ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz); */574} else575ie = rtw_set_ie(ie, _SUPPORTEDRATES_IE_, rateLen, pdev_network->SupportedRates, &sz);576577/* DS parameter set */578ie = rtw_set_ie(ie, _DSSET_IE_, 1, (u8 *)&(pdev_network->Configuration.DSConfig), &sz);579580581/* IBSS Parameter Set */582583ie = rtw_set_ie(ie, _IBSS_PARA_IE_, 2, (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);584585if (rateLen > 8)586ie = rtw_set_ie(ie, _EXT_SUPPORTEDRATES_IE_, (rateLen - 8), (pdev_network->SupportedRates + 8), &sz);587588#ifdef CONFIG_80211N_HT589/* HT Cap. */590if (is_supported_ht(pregistrypriv->wireless_mode)591&& (pregistrypriv->ht_enable == _TRUE)) {592/* todo: */593}594#endif /* CONFIG_80211N_HT */595596/* pdev_network->IELength = sz; */ /* update IELength */597598599/* return _SUCCESS; */600601return sz;602603}604605unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)606{607int len;608u16 val16;609unsigned char wpa_oui_type[] = {0x00, 0x50, 0xf2, 0x01};610u8 *pbuf = pie;611int limit_new = limit;612613while (1) {614pbuf = rtw_get_ie(pbuf, _WPA_IE_ID_, &len, limit_new);615616if (pbuf) {617618/* check if oui matches... */619if (_rtw_memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)) == _FALSE)620621goto check_next_ie;622623/* check version... */624_rtw_memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));625626val16 = le16_to_cpu(val16);627if (val16 != 0x0001)628goto check_next_ie;629630*wpa_ie_len = *(pbuf + 1);631632return pbuf;633634} else {635636*wpa_ie_len = 0;637return NULL;638}639640check_next_ie:641642limit_new = limit - (pbuf - pie) - 2 - len;643644if (limit_new <= 0)645break;646647pbuf += (2 + len);648649}650651*wpa_ie_len = 0;652653return NULL;654655}656657unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit)658{659660return rtw_get_ie(pie, _WPA2_IE_ID_, rsn_ie_len, limit);661662}663664int rtw_get_wpa_cipher_suite(u8 *s)665{666if (_rtw_memcmp(s, WPA_CIPHER_SUITE_NONE, WPA_SELECTOR_LEN) == _TRUE)667return WPA_CIPHER_NONE;668if (_rtw_memcmp(s, WPA_CIPHER_SUITE_WEP40, WPA_SELECTOR_LEN) == _TRUE)669return WPA_CIPHER_WEP40;670if (_rtw_memcmp(s, WPA_CIPHER_SUITE_TKIP, WPA_SELECTOR_LEN) == _TRUE)671return WPA_CIPHER_TKIP;672if (_rtw_memcmp(s, WPA_CIPHER_SUITE_CCMP, WPA_SELECTOR_LEN) == _TRUE)673return WPA_CIPHER_CCMP;674if (_rtw_memcmp(s, WPA_CIPHER_SUITE_WEP104, WPA_SELECTOR_LEN) == _TRUE)675return WPA_CIPHER_WEP104;676677return 0;678}679680int rtw_get_wpa2_cipher_suite(u8 *s)681{682if (_rtw_memcmp(s, RSN_CIPHER_SUITE_NONE, RSN_SELECTOR_LEN) == _TRUE)683return WPA_CIPHER_NONE;684if (_rtw_memcmp(s, RSN_CIPHER_SUITE_WEP40, RSN_SELECTOR_LEN) == _TRUE)685return WPA_CIPHER_WEP40;686if (_rtw_memcmp(s, RSN_CIPHER_SUITE_TKIP, RSN_SELECTOR_LEN) == _TRUE)687return WPA_CIPHER_TKIP;688if (_rtw_memcmp(s, RSN_CIPHER_SUITE_CCMP, RSN_SELECTOR_LEN) == _TRUE)689return WPA_CIPHER_CCMP;690if (_rtw_memcmp(s, RSN_CIPHER_SUITE_WEP104, RSN_SELECTOR_LEN) == _TRUE)691return WPA_CIPHER_WEP104;692693return 0;694}695696u32 rtw_get_akm_suite_bitmap(u8 *s)697{698if (_rtw_memcmp(s, WLAN_AKM_8021X, RSN_SELECTOR_LEN) == _TRUE)699return WLAN_AKM_TYPE_8021X;700if (_rtw_memcmp(s, WLAN_AKM_PSK, RSN_SELECTOR_LEN) == _TRUE)701return WLAN_AKM_TYPE_PSK;702if (_rtw_memcmp(s, WLAN_AKM_FT_8021X, RSN_SELECTOR_LEN) == _TRUE)703return WLAN_AKM_TYPE_FT_8021X;704if (_rtw_memcmp(s, WLAN_AKM_FT_PSK, RSN_SELECTOR_LEN) == _TRUE)705return WLAN_AKM_TYPE_FT_PSK;706if (_rtw_memcmp(s, WLAN_AKM_8021X_SHA256, RSN_SELECTOR_LEN) == _TRUE)707return WLAN_AKM_TYPE_8021X_SHA256;708if (_rtw_memcmp(s, WLAN_AKM_PSK_SHA256, RSN_SELECTOR_LEN) == _TRUE)709return WLAN_AKM_TYPE_PSK_SHA256;710if (_rtw_memcmp(s, WLAN_AKM_TDLS, RSN_SELECTOR_LEN) == _TRUE)711return WLAN_AKM_TYPE_TDLS;712if (_rtw_memcmp(s, WLAN_AKM_SAE, RSN_SELECTOR_LEN) == _TRUE)713return WLAN_AKM_TYPE_SAE;714if (_rtw_memcmp(s, WLAN_AKM_FT_OVER_SAE, RSN_SELECTOR_LEN) == _TRUE)715return WLAN_AKM_TYPE_FT_OVER_SAE;716if (_rtw_memcmp(s, WLAN_AKM_8021X_SUITE_B, RSN_SELECTOR_LEN) == _TRUE)717return WLAN_AKM_TYPE_8021X_SUITE_B;718if (_rtw_memcmp(s, WLAN_AKM_8021X_SUITE_B_192, RSN_SELECTOR_LEN) == _TRUE)719return WLAN_AKM_TYPE_8021X_SUITE_B_192;720if (_rtw_memcmp(s, WLAN_AKM_FILS_SHA256, RSN_SELECTOR_LEN) == _TRUE)721return WLAN_AKM_TYPE_FILS_SHA256;722if (_rtw_memcmp(s, WLAN_AKM_FILS_SHA384, RSN_SELECTOR_LEN) == _TRUE)723return WLAN_AKM_TYPE_FILS_SHA384;724if (_rtw_memcmp(s, WLAN_AKM_FT_FILS_SHA256, RSN_SELECTOR_LEN) == _TRUE)725return WLAN_AKM_TYPE_FT_FILS_SHA256;726if (_rtw_memcmp(s, WLAN_AKM_FT_FILS_SHA384, RSN_SELECTOR_LEN) == _TRUE)727return WLAN_AKM_TYPE_FT_FILS_SHA384;728729return 0;730}731732int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,733int *pairwise_cipher, u32 *akm)734{735int i, ret = _SUCCESS;736int left, count;737u8 *pos;738u8 SUITE_1X[4] = {0x00, 0x50, 0xf2, 1};739740if (wpa_ie_len <= 0) {741/* No WPA IE - fail silently */742return _FAIL;743}744745746if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie + 1) != (u8)(wpa_ie_len - 2)) ||747(_rtw_memcmp(wpa_ie + 2, RTW_WPA_OUI_TYPE, WPA_SELECTOR_LEN) != _TRUE))748return _FAIL;749750pos = wpa_ie;751752pos += 8;753left = wpa_ie_len - 8;754755756/* group_cipher */757if (left >= WPA_SELECTOR_LEN) {758759*group_cipher = rtw_get_wpa_cipher_suite(pos);760761pos += WPA_SELECTOR_LEN;762left -= WPA_SELECTOR_LEN;763764} else if (left > 0) {765766return _FAIL;767}768769770/* pairwise_cipher */771if (left >= 2) {772/* count = le16_to_cpu(*(u16*)pos); */773count = RTW_GET_LE16(pos);774pos += 2;775left -= 2;776777if (count == 0 || left < count * WPA_SELECTOR_LEN) {778return _FAIL;779}780781for (i = 0; i < count; i++) {782*pairwise_cipher |= rtw_get_wpa_cipher_suite(pos);783784pos += WPA_SELECTOR_LEN;785left -= WPA_SELECTOR_LEN;786}787788} else if (left == 1) {789return _FAIL;790}791792if (akm) {793if (left >= 6) {794pos += 2;795if (_rtw_memcmp(pos, SUITE_1X, 4) == 1) {796*akm = WLAN_AKM_TYPE_8021X;797}798}799}800801return ret;802803}804805int rtw_rsne_info_parse(const u8 *ie, uint ie_len, struct rsne_info *info)806{807const u8 *pos = ie;808u16 cnt;809810_rtw_memset(info, 0, sizeof(struct rsne_info));811812if (ie + ie_len < pos + 4)813goto err;814815if (*ie != WLAN_EID_RSN || *(ie + 1) != ie_len - 2)816goto err;817pos += 2 + 2;818819/* Group CS */820if (ie + ie_len < pos + 4) {821if (ie + ie_len != pos)822goto err;823goto exit;824}825info->gcs = (u8 *)pos;826pos += 4;827828/* Pairwise CS */829if (ie + ie_len < pos + 2) {830if (ie + ie_len != pos)831goto err;832goto exit;833}834cnt = RTW_GET_LE16(pos);835pos += 2;836if (ie + ie_len < pos + 4 * cnt) {837if (ie + ie_len != pos)838goto err;839goto exit;840}841info->pcs_cnt = cnt;842info->pcs_list = (u8 *)pos;843pos += 4 * cnt;844845/* AKM */846if (ie + ie_len < pos + 2) {847if (ie + ie_len != pos)848goto err;849goto exit;850}851cnt = RTW_GET_LE16(pos);852pos += 2;853if (ie + ie_len < pos + 4 * cnt) {854if (ie + ie_len != pos)855goto err;856goto exit;857}858info->akm_cnt = cnt;859info->akm_list = (u8 *)pos;860pos += 4 * cnt;861862/* RSN cap */863if (ie + ie_len < pos + 2) {864if (ie + ie_len != pos)865goto err;866goto exit;867}868info->cap = (u8 *)pos;869pos += 2;870871/* PMKID */872if (ie + ie_len < pos + 2) {873if (ie + ie_len != pos)874goto err;875goto exit;876}877cnt = RTW_GET_LE16(pos);878pos += 2;879if (ie + ie_len < pos + 16 * cnt) {880if (ie + ie_len != pos)881goto err;882goto exit;883}884info->pmkid_cnt = cnt;885info->pmkid_list = (u8 *)pos;886pos += 16 * cnt;887888/* Group Mgmt CS */889if (ie + ie_len < pos + 4) {890if (ie + ie_len != pos)891goto err;892goto exit;893}894info->gmcs = (u8 *)pos;895896exit:897return _SUCCESS;898899err:900info->err = 1;901return _FAIL;902}903904int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,905int *pairwise_cipher, u32 *akm, u8 *mfp_opt)906{907struct rsne_info info;908int i, ret = _SUCCESS;909910ret = rtw_rsne_info_parse(rsn_ie, rsn_ie_len, &info);911if (ret != _SUCCESS)912goto exit;913914if (group_cipher) {915if (info.gcs)916*group_cipher = rtw_get_wpa2_cipher_suite(info.gcs);917else918*group_cipher = 0;919}920921if (pairwise_cipher) {922*pairwise_cipher = 0;923for (i = 0; i < info.pcs_cnt; i++)924*pairwise_cipher |= rtw_get_wpa2_cipher_suite(info.pcs_list + 4 * i);925}926927if (akm) {928*akm = 0;929for (i = 0; i < info.akm_cnt; i++)930*akm |= rtw_get_akm_suite_bitmap(info.akm_list + 4 * i);931}932933if (mfp_opt) {934*mfp_opt = MFP_NO;935if (info.cap)936*mfp_opt = GET_RSN_CAP_MFP_OPTION(info.cap);937}938939exit:940return ret;941}942943/* #ifdef CONFIG_WAPI_SUPPORT */944int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)945{946int len = 0;947u8 authmode;948uint cnt;949u8 wapi_oui1[4] = {0x0, 0x14, 0x72, 0x01};950u8 wapi_oui2[4] = {0x0, 0x14, 0x72, 0x02};951952953if (wapi_len)954*wapi_len = 0;955956if (!in_ie || in_len <= 0)957return len;958959cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);960961while (cnt < in_len) {962authmode = in_ie[cnt];963964/* if(authmode==_WAPI_IE_) */965if (authmode == _WAPI_IE_ && (_rtw_memcmp(&in_ie[cnt + 6], wapi_oui1, 4) == _TRUE ||966_rtw_memcmp(&in_ie[cnt + 6], wapi_oui2, 4) == _TRUE)) {967if (wapi_ie)968_rtw_memcpy(wapi_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);969970if (wapi_len)971*wapi_len = in_ie[cnt + 1] + 2;972973cnt += in_ie[cnt + 1] + 2; /* get next */974} else {975cnt += in_ie[cnt + 1] + 2; /* get next */976}977}978979if (wapi_len)980len = *wapi_len;981982983return len;984985}986/* #endif */987988int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, u16 *wpa_len)989{990u8 authmode, sec_idx;991u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};992uint cnt;993994995/* Search required WPA or WPA2 IE and copy to sec_ie[ ] */996997cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);998999sec_idx = 0;10001001while (cnt < in_len) {1002authmode = in_ie[cnt];10031004if ((authmode == _WPA_IE_ID_) && (_rtw_memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4) == _TRUE)) {10051006if (wpa_ie)1007_rtw_memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);10081009*wpa_len = in_ie[cnt + 1] + 2;1010cnt += in_ie[cnt + 1] + 2; /* get next */1011} else {1012if (authmode == _WPA2_IE_ID_) {10131014if (rsn_ie)1015_rtw_memcpy(rsn_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);10161017*rsn_len = in_ie[cnt + 1] + 2;1018cnt += in_ie[cnt + 1] + 2; /* get next */1019} else {1020cnt += in_ie[cnt + 1] + 2; /* get next */1021}1022}10231024}102510261027return *rsn_len + *wpa_len;10281029}10301031u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen)1032{1033u8 match = _FALSE;1034u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};10351036if (ie_ptr == NULL)1037return match;10381039eid = ie_ptr[0];10401041if ((eid == _WPA_IE_ID_) && (_rtw_memcmp(&ie_ptr[2], wps_oui, 4) == _TRUE)) {1042/* RTW_INFO("==> found WPS_IE.....\n"); */1043*wps_ielen = ie_ptr[1] + 2;1044match = _TRUE;1045}1046return match;1047}10481049u8 *rtw_get_wps_ie_from_scan_queue(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen, enum bss_type frame_type)1050{1051u8 *wps = NULL;10521053RTW_INFO("[%s] frame_type = %d\n", __FUNCTION__, frame_type);1054switch (frame_type) {1055case BSS_TYPE_BCN:1056case BSS_TYPE_PROB_RSP: {1057/* Beacon or Probe Response */1058wps = rtw_get_wps_ie(in_ie + _PROBERSP_IE_OFFSET_, in_len - _PROBERSP_IE_OFFSET_, wps_ie, wps_ielen);1059break;1060}1061case BSS_TYPE_PROB_REQ: {1062/* Probe Request */1063wps = rtw_get_wps_ie(in_ie + _PROBEREQ_IE_OFFSET_ , in_len - _PROBEREQ_IE_OFFSET_ , wps_ie, wps_ielen);1064break;1065}1066default:1067case BSS_TYPE_UNDEF:1068break;1069}1070return wps;1071}10721073/**1074* rtw_get_wps_ie - Search WPS IE from a series of IEs1075* @in_ie: Address of IEs to search1076* @in_len: Length limit from in_ie1077* @wps_ie: If not NULL and WPS IE is found, WPS IE will be copied to the buf starting from wps_ie1078* @wps_ielen: If not NULL and WPS IE is found, will set to the length of the entire WPS IE1079*1080* Returns: The address of the WPS IE found, or NULL1081*/1082u8 *rtw_get_wps_ie(const u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)1083{1084uint cnt;1085const u8 *wpsie_ptr = NULL;1086u8 eid, wps_oui[4] = {0x00, 0x50, 0xf2, 0x04};10871088if (wps_ielen)1089*wps_ielen = 0;10901091if (!in_ie) {1092rtw_warn_on(1);1093return (u8 *)wpsie_ptr;1094}10951096if (in_len <= 0)1097return (u8 *)wpsie_ptr;10981099cnt = 0;11001101while (cnt + 1 + 4 < in_len) {1102eid = in_ie[cnt];11031104if (cnt + 1 + 4 >= MAX_IE_SZ) {1105rtw_warn_on(1);1106return NULL;1107}11081109if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], wps_oui, 4) == _TRUE) {1110wpsie_ptr = in_ie + cnt;11111112if (wps_ie)1113_rtw_memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);11141115if (wps_ielen)1116*wps_ielen = in_ie[cnt + 1] + 2;11171118break;1119} else1120cnt += in_ie[cnt + 1] + 2;11211122}11231124return (u8 *)wpsie_ptr;1125}11261127/**1128* rtw_get_wps_attr - Search a specific WPS attribute from a given WPS IE1129* @wps_ie: Address of WPS IE to search1130* @wps_ielen: Length limit from wps_ie1131* @target_attr_id: The attribute ID of WPS attribute to search1132* @buf_attr: If not NULL and the WPS attribute is found, WPS attribute will be copied to the buf starting from buf_attr1133* @len_attr: If not NULL and the WPS attribute is found, will set to the length of the entire WPS attribute1134*1135* Returns: the address of the specific WPS attribute found, or NULL1136*/1137u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_attr, u32 *len_attr)1138{1139u8 *attr_ptr = NULL;1140u8 *target_attr_ptr = NULL;1141u8 wps_oui[4] = {0x00, 0x50, 0xF2, 0x04};11421143if (len_attr)1144*len_attr = 0;11451146if ((wps_ie[0] != _VENDOR_SPECIFIC_IE_) ||1147(_rtw_memcmp(wps_ie + 2, wps_oui , 4) != _TRUE))1148return attr_ptr;11491150/* 6 = 1(Element ID) + 1(Length) + 4(WPS OUI) */1151attr_ptr = wps_ie + 6; /* goto first attr */11521153while (attr_ptr - wps_ie < wps_ielen) {1154/* 4 = 2(Attribute ID) + 2(Length) */1155u16 attr_id = RTW_GET_BE16(attr_ptr);1156u16 attr_data_len = RTW_GET_BE16(attr_ptr + 2);1157u16 attr_len = attr_data_len + 4;11581159/* RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __FUNCTION__, attr_ptr, attr_id, attr_data_len); */1160if (attr_id == target_attr_id) {1161target_attr_ptr = attr_ptr;11621163if (buf_attr)1164_rtw_memcpy(buf_attr, attr_ptr, attr_len);11651166if (len_attr)1167*len_attr = attr_len;11681169break;1170} else {1171attr_ptr += attr_len; /* goto next */1172}11731174}11751176return target_attr_ptr;1177}11781179/**1180* rtw_get_wps_attr_content - Search a specific WPS attribute content from a given WPS IE1181* @wps_ie: Address of WPS IE to search1182* @wps_ielen: Length limit from wps_ie1183* @target_attr_id: The attribute ID of WPS attribute to search1184* @buf_content: If not NULL and the WPS attribute is found, WPS attribute content will be copied to the buf starting from buf_content1185* @len_content: If not NULL and the WPS attribute is found, will set to the length of the WPS attribute content1186*1187* Returns: the address of the specific WPS attribute content found, or NULL1188*/1189u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_content, uint *len_content)1190{1191u8 *attr_ptr;1192u32 attr_len;11931194if (len_content)1195*len_content = 0;11961197attr_ptr = rtw_get_wps_attr(wps_ie, wps_ielen, target_attr_id, NULL, &attr_len);11981199if (attr_ptr && attr_len) {1200if (buf_content)1201_rtw_memcpy(buf_content, attr_ptr + 4, attr_len - 4);12021203if (len_content)1204*len_content = attr_len - 4;12051206return attr_ptr + 4;1207}12081209return NULL;1210}12111212static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,1213struct rtw_ieee802_11_elems *elems,1214int show_errors)1215{1216unsigned int oui;12171218/* first 3 bytes in vendor specific information element are the IEEE1219* OUI of the vendor. The following byte is used a vendor specific1220* sub-type. */1221if (elen < 4) {1222if (show_errors) {1223RTW_INFO("short vendor specific "1224"information element ignored (len=%lu)\n",1225(unsigned long) elen);1226}1227return -1;1228}12291230oui = RTW_GET_BE24(pos);1231switch (oui) {1232case OUI_MICROSOFT:1233/* Microsoft/Wi-Fi information elements are further typed and1234* subtyped */1235switch (pos[3]) {1236case 1:1237/* Microsoft OUI (00:50:F2) with OUI Type 1:1238* real WPA information element */1239elems->wpa_ie = pos;1240elems->wpa_ie_len = elen;1241break;1242case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */1243if (elen < 5) {1244RTW_DBG("short WME "1245"information element ignored "1246"(len=%lu)\n",1247(unsigned long) elen);1248return -1;1249}1250switch (pos[4]) {1251case WME_OUI_SUBTYPE_INFORMATION_ELEMENT:1252case WME_OUI_SUBTYPE_PARAMETER_ELEMENT:1253elems->wme = pos;1254elems->wme_len = elen;1255break;1256case WME_OUI_SUBTYPE_TSPEC_ELEMENT:1257elems->wme_tspec = pos;1258elems->wme_tspec_len = elen;1259break;1260default:1261RTW_DBG("unknown WME "1262"information element ignored "1263"(subtype=%d len=%lu)\n",1264pos[4], (unsigned long) elen);1265return -1;1266}1267break;1268case 4:1269/* Wi-Fi Protected Setup (WPS) IE */1270elems->wps_ie = pos;1271elems->wps_ie_len = elen;1272break;1273default:1274RTW_DBG("Unknown Microsoft "1275"information element ignored "1276"(type=%d len=%lu)\n",1277pos[3], (unsigned long) elen);1278return -1;1279}1280break;12811282case OUI_BROADCOM:1283switch (pos[3]) {1284case VENDOR_HT_CAPAB_OUI_TYPE:1285elems->vendor_ht_cap = pos;1286elems->vendor_ht_cap_len = elen;1287break;1288default:1289RTW_DBG("Unknown Broadcom "1290"information element ignored "1291"(type=%d len=%lu)\n",1292pos[3], (unsigned long) elen);1293return -1;1294}1295break;12961297default:1298RTW_DBG("unknown vendor specific information "1299"element ignored (vendor OUI %02x:%02x:%02x "1300"len=%lu)\n",1301pos[0], pos[1], pos[2], (unsigned long) elen);1302return -1;1303}13041305return 0;13061307}13081309/**1310* ieee802_11_parse_elems - Parse information elements in management frames1311* @start: Pointer to the start of IEs1312* @len: Length of IE buffer in octets1313* @elems: Data structure for parsed elements1314* @show_errors: Whether to show parsing errors in debug log1315* Returns: Parsing result1316*/1317ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,1318struct rtw_ieee802_11_elems *elems,1319int show_errors)1320{1321uint left = len;1322u8 *pos = start;1323int unknown = 0;13241325_rtw_memset(elems, 0, sizeof(*elems));13261327while (left >= 2) {1328u8 id, elen;13291330id = *pos++;1331elen = *pos++;1332left -= 2;13331334if (elen > left) {1335if (show_errors) {1336RTW_INFO("IEEE 802.11 element "1337"parse failed (id=%d elen=%d "1338"left=%lu)\n",1339id, elen, (unsigned long) left);1340}1341return ParseFailed;1342}13431344switch (id) {1345case WLAN_EID_SSID:1346elems->ssid = pos;1347elems->ssid_len = elen;1348break;1349case WLAN_EID_SUPP_RATES:1350elems->supp_rates = pos;1351elems->supp_rates_len = elen;1352break;1353case WLAN_EID_FH_PARAMS:1354elems->fh_params = pos;1355elems->fh_params_len = elen;1356break;1357case WLAN_EID_DS_PARAMS:1358elems->ds_params = pos;1359elems->ds_params_len = elen;1360break;1361case WLAN_EID_CF_PARAMS:1362elems->cf_params = pos;1363elems->cf_params_len = elen;1364break;1365case WLAN_EID_TIM:1366elems->tim = pos;1367elems->tim_len = elen;1368break;1369case WLAN_EID_IBSS_PARAMS:1370elems->ibss_params = pos;1371elems->ibss_params_len = elen;1372break;1373case WLAN_EID_CHALLENGE:1374elems->challenge = pos;1375elems->challenge_len = elen;1376break;1377case WLAN_EID_ERP_INFO:1378elems->erp_info = pos;1379elems->erp_info_len = elen;1380break;1381case WLAN_EID_EXT_SUPP_RATES:1382elems->ext_supp_rates = pos;1383elems->ext_supp_rates_len = elen;1384break;1385case WLAN_EID_VENDOR_SPECIFIC:1386if (rtw_ieee802_11_parse_vendor_specific(pos, elen,1387elems,1388show_errors))1389unknown++;1390break;1391case WLAN_EID_RSN:1392elems->rsn_ie = pos;1393elems->rsn_ie_len = elen;1394break;1395case WLAN_EID_PWR_CAPABILITY:1396elems->power_cap = pos;1397elems->power_cap_len = elen;1398break;1399case WLAN_EID_SUPPORTED_CHANNELS:1400elems->supp_channels = pos;1401elems->supp_channels_len = elen;1402break;1403case WLAN_EID_MOBILITY_DOMAIN:1404elems->mdie = pos;1405elems->mdie_len = elen;1406break;1407case WLAN_EID_FAST_BSS_TRANSITION:1408elems->ftie = pos;1409elems->ftie_len = elen;1410break;1411case WLAN_EID_TIMEOUT_INTERVAL:1412elems->timeout_int = pos;1413elems->timeout_int_len = elen;1414break;1415case WLAN_EID_HT_CAP:1416elems->ht_capabilities = pos;1417elems->ht_capabilities_len = elen;1418break;1419case WLAN_EID_HT_OPERATION:1420elems->ht_operation = pos;1421elems->ht_operation_len = elen;1422break;1423case WLAN_EID_VHT_CAPABILITY:1424elems->vht_capabilities = pos;1425elems->vht_capabilities_len = elen;1426break;1427case WLAN_EID_VHT_OPERATION:1428elems->vht_operation = pos;1429elems->vht_operation_len = elen;1430break;1431case WLAN_EID_VHT_OP_MODE_NOTIFY:1432elems->vht_op_mode_notify = pos;1433elems->vht_op_mode_notify_len = elen;1434break;1435case _EID_RRM_EN_CAP_IE_:1436elems->rm_en_cap = pos;1437elems->rm_en_cap_len = elen;1438break;1439#ifdef CONFIG_RTW_MESH1440case WLAN_EID_PREQ:1441elems->preq = pos;1442elems->preq_len = elen;1443break;1444case WLAN_EID_PREP:1445elems->prep = pos;1446elems->prep_len = elen;1447break;1448case WLAN_EID_PERR:1449elems->perr = pos;1450elems->perr_len = elen;1451break;1452case WLAN_EID_RANN:1453elems->rann = pos;1454elems->rann_len = elen;1455break;1456#endif1457default:1458unknown++;1459if (!show_errors)1460break;1461RTW_DBG("IEEE 802.11 element parse "1462"ignored unknown element (id=%d elen=%d)\n",1463id, elen);1464break;1465}14661467left -= elen;1468pos += elen;1469}14701471if (left)1472return ParseFailed;14731474return unknown ? ParseUnknown : ParseOK;14751476}14771478static u8 key_char2num(u8 ch);1479static u8 key_char2num(u8 ch)1480{1481if ((ch >= '0') && (ch <= '9'))1482return ch - '0';1483else if ((ch >= 'a') && (ch <= 'f'))1484return ch - 'a' + 10;1485else if ((ch >= 'A') && (ch <= 'F'))1486return ch - 'A' + 10;1487else1488return 0xff;1489}14901491u8 str_2char2num(u8 hch, u8 lch);1492u8 str_2char2num(u8 hch, u8 lch)1493{1494return (key_char2num(hch) * 10) + key_char2num(lch);1495}14961497u8 key_2char2num(u8 hch, u8 lch);1498u8 key_2char2num(u8 hch, u8 lch)1499{1500return (key_char2num(hch) << 4) | key_char2num(lch);1501}15021503void macstr2num(u8 *dst, u8 *src);1504void macstr2num(u8 *dst, u8 *src)1505{1506int jj, kk;1507for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)1508dst[jj] = key_2char2num(src[kk], src[kk + 1]);1509}15101511u8 convert_ip_addr(u8 hch, u8 mch, u8 lch)1512{1513return (key_char2num(hch) * 100) + (key_char2num(mch) * 10) + key_char2num(lch);1514}15151516#ifdef CONFIG_PLATFORM_INTEL_BYT1517#define MAC_ADDRESS_LEN 1215181519int rtw_get_mac_addr_intel(unsigned char *buf)1520{1521int ret = 0;1522int i;1523struct file *fp = NULL;1524mm_segment_t oldfs;1525unsigned char c_mac[MAC_ADDRESS_LEN];1526char fname[] = "/config/wifi/mac.txt";1527int jj, kk;15281529RTW_INFO("%s Enter\n", __FUNCTION__);15301531ret = rtw_retrieve_from_file(fname, c_mac, MAC_ADDRESS_LEN);1532if (ret < MAC_ADDRESS_LEN)1533return -1;15341535for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 2)1536buf[jj] = key_2char2num(c_mac[kk], c_mac[kk + 1]);15371538RTW_INFO("%s: read from file mac address: "MAC_FMT"\n",1539__FUNCTION__, MAC_ARG(buf));15401541return 0;1542}1543#endif /* CONFIG_PLATFORM_INTEL_BYT */15441545/*1546* Description:1547* rtw_check_invalid_mac_address:1548* This is only used for checking mac address valid or not.1549*1550* Input:1551* adapter: mac_address pointer.1552* check_local_bit: check locally bit or not.1553*1554* Output:1555* _TRUE: The mac address is invalid.1556* _FALSE: The mac address is valid.1557*1558* Auther: Isaac.Li1559*/1560u8 rtw_check_invalid_mac_address(u8 *mac_addr, u8 check_local_bit)1561{1562u8 null_mac_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};1563u8 multi_mac_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};1564u8 res = _FALSE;15651566if (_rtw_memcmp(mac_addr, null_mac_addr, ETH_ALEN)) {1567res = _TRUE;1568goto func_exit;1569}15701571if (_rtw_memcmp(mac_addr, multi_mac_addr, ETH_ALEN)) {1572res = _TRUE;1573goto func_exit;1574}15751576if (mac_addr[0] & BIT0) {1577res = _TRUE;1578goto func_exit;1579}15801581if (check_local_bit == _TRUE) {1582if (mac_addr[0] & BIT1) {1583res = _TRUE;1584goto func_exit;1585}1586}15871588func_exit:1589return res;1590}15911592extern char *rtw_initmac;1593/**1594* rtw_macaddr_cfg - Decide the mac address used1595* @out: buf to store mac address decided1596* @hw_mac_addr: mac address from efuse/epprom1597*/1598void rtw_macaddr_cfg(u8 *out, const u8 *hw_mac_addr)1599{1600#define DEFAULT_RANDOM_MACADDR 11601u8 mac[ETH_ALEN];16021603if (out == NULL) {1604rtw_warn_on(1);1605return;1606}16071608/* Users specify the mac address */1609if (rtw_initmac) {1610int jj, kk;16111612for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)1613mac[jj] = key_2char2num(rtw_initmac[kk], rtw_initmac[kk + 1]);16141615goto err_chk;1616}16171618/* platform specified */1619#ifdef CONFIG_PLATFORM_INTEL_BYT1620if (rtw_get_mac_addr_intel(mac) == 0)1621goto err_chk;1622#endif16231624/* Use the mac address stored in the Efuse */1625if (hw_mac_addr) {1626_rtw_memcpy(mac, hw_mac_addr, ETH_ALEN);1627goto err_chk;1628}16291630err_chk:1631if (rtw_check_invalid_mac_address(mac, _TRUE) == _TRUE) {1632#if DEFAULT_RANDOM_MACADDR1633RTW_ERR("invalid mac addr:"MAC_FMT", assign random MAC\n", MAC_ARG(mac));1634*((u32 *)(&mac[2])) = rtw_random32();1635mac[0] = 0x00;1636mac[1] = 0xe0;1637mac[2] = 0x4c;1638#else1639RTW_ERR("invalid mac addr:"MAC_FMT", assign default one\n", MAC_ARG(mac));1640mac[0] = 0x00;1641mac[1] = 0xe0;1642mac[2] = 0x4c;1643mac[3] = 0x87;1644mac[4] = 0x00;1645mac[5] = 0x00;1646#endif1647}16481649_rtw_memcpy(out, mac, ETH_ALEN);1650RTW_INFO("%s mac addr:"MAC_FMT"\n", __func__, MAC_ARG(out));1651}16521653#ifdef CONFIG_80211N_HT1654void dump_ht_cap_ie_content(void *sel, const u8 *buf, u32 buf_len)1655{1656if (buf_len != HT_CAP_IE_LEN) {1657RTW_PRINT_SEL(sel, "Invalid HT capability IE len:%d != %d\n", buf_len, HT_CAP_IE_LEN);1658return;1659}16601661RTW_PRINT_SEL(sel, "cap_info:%02x%02x:%s\n", *(buf), *(buf + 1)1662, GET_HT_CAP_ELE_CHL_WIDTH(buf) ? " 40MHz" : " 20MHz");1663RTW_PRINT_SEL(sel, "A-MPDU Parameters:"HT_AMPDU_PARA_FMT"\n"1664, HT_AMPDU_PARA_ARG(HT_CAP_ELE_AMPDU_PARA(buf)));1665RTW_PRINT_SEL(sel, "Supported MCS Set:"HT_SUP_MCS_SET_FMT"\n"1666, HT_SUP_MCS_SET_ARG(HT_CAP_ELE_SUP_MCS_SET(buf)));1667}16681669void dump_ht_cap_ie(void *sel, const u8 *ie, u32 ie_len)1670{1671const u8 *ht_cap_ie;1672sint ht_cap_ielen;16731674ht_cap_ie = rtw_get_ie(ie, WLAN_EID_HT_CAP, &ht_cap_ielen, ie_len);1675if (!ie || ht_cap_ie != ie)1676return;16771678dump_ht_cap_ie_content(sel, ht_cap_ie + 2, ht_cap_ielen);1679}16801681const char *const _ht_sc_offset_str[] = {1682"SCN",1683"SCA",1684"SC-RSVD",1685"SCB",1686};16871688void dump_ht_op_ie_content(void *sel, const u8 *buf, u32 buf_len)1689{1690if (buf_len != HT_OP_IE_LEN) {1691RTW_PRINT_SEL(sel, "Invalid HT operation IE len:%d != %d\n", buf_len, HT_OP_IE_LEN);1692return;1693}16941695RTW_PRINT_SEL(sel, "ch:%u%s %s\n"1696, GET_HT_OP_ELE_PRI_CHL(buf)1697, GET_HT_OP_ELE_STA_CHL_WIDTH(buf) ? "" : " 20MHz only"1698, ht_sc_offset_str(GET_HT_OP_ELE_2ND_CHL_OFFSET(buf))1699);1700}17011702void dump_ht_op_ie(void *sel, const u8 *ie, u32 ie_len)1703{1704const u8 *ht_op_ie;1705sint ht_op_ielen;17061707ht_op_ie = rtw_get_ie(ie, WLAN_EID_HT_OPERATION, &ht_op_ielen, ie_len);1708if (!ie || ht_op_ie != ie)1709return;17101711dump_ht_op_ie_content(sel, ht_op_ie + 2, ht_op_ielen);1712}1713#endif /* CONFIG_80211N_HT */17141715void dump_ies(void *sel, const u8 *buf, u32 buf_len)1716{1717const u8 *pos = buf;1718u8 id, len;17191720while (pos - buf + 1 < buf_len) {1721id = *pos;1722len = *(pos + 1);17231724RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u\n", __FUNCTION__, id, len);1725#ifdef CONFIG_80211N_HT1726dump_ht_cap_ie(sel, pos, len + 2);1727dump_ht_op_ie(sel, pos, len + 2);1728#endif1729#ifdef CONFIG_80211AC_VHT1730dump_vht_cap_ie(sel, pos, len + 2);1731dump_vht_op_ie(sel, pos, len + 2);1732#endif1733dump_wps_ie(sel, pos, len + 2);1734#ifdef CONFIG_P2P1735dump_p2p_ie(sel, pos, len + 2);1736#ifdef CONFIG_WFD1737dump_wfd_ie(sel, pos, len + 2);1738#endif1739#endif17401741pos += (2 + len);1742}1743}17441745void dump_wps_ie(void *sel, const u8 *ie, u32 ie_len)1746{1747const u8 *pos = ie;1748u16 id;1749u16 len;17501751const u8 *wps_ie;1752uint wps_ielen;17531754wps_ie = rtw_get_wps_ie(ie, ie_len, NULL, &wps_ielen);1755if (wps_ie != ie || wps_ielen == 0)1756return;17571758pos += 6;1759while (pos - ie + 4 <= ie_len) {1760id = RTW_GET_BE16(pos);1761len = RTW_GET_BE16(pos + 2);17621763RTW_PRINT_SEL(sel, "%s ID:0x%04x, LEN:%u%s\n", __func__, id, len1764, ((pos - ie + 4 + len) <= ie_len) ? "" : "(exceed ie_len)");17651766pos += (4 + len);1767}1768}17691770/**1771* rtw_ies_get_chbw - get operation ch, bw, offset from IEs of BSS.1772* @ies: pointer of the first tlv IE1773* @ies_len: length of @ies1774* @ch: pointer of ch, used as output1775* @bw: pointer of bw, used as output1776* @offset: pointer of offset, used as output1777* @ht: check HT IEs1778* @vht: check VHT IEs, if true imply ht is true1779*/1780void rtw_ies_get_chbw(u8 *ies, int ies_len, u8 *ch, u8 *bw, u8 *offset, u8 ht, u8 vht)1781{1782u8 *p;1783int ie_len;17841785*ch = 0;1786*bw = CHANNEL_WIDTH_20;1787*offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;17881789p = rtw_get_ie(ies, _DSSET_IE_, &ie_len, ies_len);1790if (p && ie_len > 0)1791*ch = *(p + 2);17921793#ifdef CONFIG_80211N_HT1794if (ht || vht) {1795u8 *ht_cap_ie, *ht_op_ie;1796int ht_cap_ielen, ht_op_ielen;17971798ht_cap_ie = rtw_get_ie(ies, EID_HTCapability, &ht_cap_ielen, ies_len);1799if (ht_cap_ie && ht_cap_ielen) {1800if (GET_HT_CAP_ELE_CHL_WIDTH(ht_cap_ie + 2))1801*bw = CHANNEL_WIDTH_40;1802}18031804ht_op_ie = rtw_get_ie(ies, EID_HTInfo, &ht_op_ielen, ies_len);1805if (ht_op_ie && ht_op_ielen) {1806if (*ch == 0)1807*ch = GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2);1808else if (*ch != 0 && *ch != GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2)) {1809RTW_INFO("%s ch inconsistent, DSSS:%u, HT primary:%u\n"1810, __func__, *ch, GET_HT_OP_ELE_PRI_CHL(ht_op_ie + 2));1811}18121813if (!GET_HT_OP_ELE_STA_CHL_WIDTH(ht_op_ie + 2))1814*bw = CHANNEL_WIDTH_20;18151816if (*bw == CHANNEL_WIDTH_40) {1817switch (GET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op_ie + 2)) {1818case SCA:1819*offset = HAL_PRIME_CHNL_OFFSET_LOWER;1820break;1821case SCB:1822*offset = HAL_PRIME_CHNL_OFFSET_UPPER;1823break;1824}1825}1826}18271828#ifdef CONFIG_80211AC_VHT1829if (vht) {1830u8 *vht_op_ie;1831int vht_op_ielen;18321833vht_op_ie = rtw_get_ie(ies, EID_VHTOperation, &vht_op_ielen, ies_len);1834if (vht_op_ie && vht_op_ielen) {1835if (GET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op_ie + 2) >= 1)1836*bw = CHANNEL_WIDTH_80;1837}1838}1839#endif /* CONFIG_80211AC_VHT */18401841}1842#endif /* CONFIG_80211N_HT */1843}18441845void rtw_bss_get_chbw(WLAN_BSSID_EX *bss, u8 *ch, u8 *bw, u8 *offset, u8 ht, u8 vht)1846{1847rtw_ies_get_chbw(bss->IEs + sizeof(NDIS_802_11_FIXED_IEs)1848, bss->IELength - sizeof(NDIS_802_11_FIXED_IEs)1849, ch, bw, offset, ht, vht);18501851if (*ch == 0)1852*ch = bss->Configuration.DSConfig;1853else if (*ch != bss->Configuration.DSConfig) {1854RTW_INFO("inconsistent ch - ies:%u bss->Configuration.DSConfig:%u\n"1855, *ch, bss->Configuration.DSConfig);1856*ch = bss->Configuration.DSConfig;1857rtw_warn_on(1);1858}1859}18601861/**1862* rtw_is_chbw_grouped - test if the two ch settings can be grouped together1863* @ch_a: ch of set a1864* @bw_a: bw of set a1865* @offset_a: offset of set a1866* @ch_b: ch of set b1867* @bw_b: bw of set b1868* @offset_b: offset of set b1869*/1870bool rtw_is_chbw_grouped(u8 ch_a, u8 bw_a, u8 offset_a1871, u8 ch_b, u8 bw_b, u8 offset_b)1872{1873bool is_grouped = _FALSE;18741875if (ch_a != ch_b) {1876/* ch is different */1877goto exit;1878} else if ((bw_a == CHANNEL_WIDTH_40 || bw_a == CHANNEL_WIDTH_80)1879&& (bw_b == CHANNEL_WIDTH_40 || bw_b == CHANNEL_WIDTH_80)1880) {1881if (offset_a != offset_b)1882goto exit;1883}18841885is_grouped = _TRUE;18861887exit:1888return is_grouped;1889}18901891/**1892* rtw_sync_chbw - obey g_ch, adjust g_bw, g_offset, bw, offset1893* @req_ch: pointer of the request ch, may be modified further1894* @req_bw: pointer of the request bw, may be modified further1895* @req_offset: pointer of the request offset, may be modified further1896* @g_ch: pointer of the ongoing group ch1897* @g_bw: pointer of the ongoing group bw, may be modified further1898* @g_offset: pointer of the ongoing group offset, may be modified further1899*/1900void rtw_sync_chbw(u8 *req_ch, u8 *req_bw, u8 *req_offset1901, u8 *g_ch, u8 *g_bw, u8 *g_offset)1902{19031904*req_ch = *g_ch;19051906if (*req_bw == CHANNEL_WIDTH_80 && *g_ch <= 14) {1907/*2.4G ch, downgrade to 40Mhz */1908*req_bw = CHANNEL_WIDTH_40;1909}19101911switch (*req_bw) {1912case CHANNEL_WIDTH_80:1913if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)1914*req_offset = *g_offset;1915else if (*g_bw == CHANNEL_WIDTH_20)1916rtw_get_offset_by_chbw(*req_ch, *req_bw, req_offset);19171918if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {1919RTW_ERR("%s req 80MHz BW without offset, down to 20MHz\n", __func__);1920rtw_warn_on(1);1921*req_bw = CHANNEL_WIDTH_20;1922}1923break;1924case CHANNEL_WIDTH_40:1925if (*g_bw == CHANNEL_WIDTH_40 || *g_bw == CHANNEL_WIDTH_80)1926*req_offset = *g_offset;1927else if (*g_bw == CHANNEL_WIDTH_20)1928rtw_get_offset_by_chbw(*req_ch, *req_bw, req_offset);19291930if (*req_offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {1931RTW_ERR("%s req 40MHz BW without offset, down to 20MHz\n", __func__);1932rtw_warn_on(1);1933*req_bw = CHANNEL_WIDTH_20;1934}1935break;1936case CHANNEL_WIDTH_20:1937*req_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;1938break;1939default:1940RTW_ERR("%s req unsupported BW:%u\n", __func__, *req_bw);1941rtw_warn_on(1);1942}19431944if (*req_bw > *g_bw) {1945*g_bw = *req_bw;1946*g_offset = *req_offset;1947}1948}19491950/**1951* rtw_get_p2p_merged_len - Get merged ie length from muitiple p2p ies.1952* @in_ie: Pointer of the first p2p ie1953* @in_len: Total len of muiltiple p2p ies1954* Returns: Length of merged p2p ie length1955*/1956u32 rtw_get_p2p_merged_ies_len(u8 *in_ie, u32 in_len)1957{1958PNDIS_802_11_VARIABLE_IEs pIE;1959u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };1960int i = 0;1961int len = 0;19621963while (i < in_len) {1964pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);19651966if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && _rtw_memcmp(pIE->data, OUI, 4)) {1967len += pIE->Length - 4; /* 4 is P2P OUI length, don't count it in this loop */1968}19691970i += (pIE->Length + 2);1971}19721973return len + 4; /* Append P2P OUI length at last. */1974}19751976/**1977* rtw_p2p_merge_ies - Merge muitiple p2p ies into one1978* @in_ie: Pointer of the first p2p ie1979* @in_len: Total len of muiltiple p2p ies1980* @merge_ie: Pointer of merged ie1981* Returns: Length of merged p2p ie1982*/1983int rtw_p2p_merge_ies(u8 *in_ie, u32 in_len, u8 *merge_ie)1984{1985PNDIS_802_11_VARIABLE_IEs pIE;1986u8 len = 0;1987u8 OUI[4] = { 0x50, 0x6f, 0x9a, 0x09 };1988u8 ELOUI[6] = { 0xDD, 0x00, 0x50, 0x6f, 0x9a, 0x09 }; /* EID;Len;OUI, Len would copy at the end of function */1989int i = 0;19901991if (merge_ie != NULL) {1992/* Set first P2P OUI */1993_rtw_memcpy(merge_ie, ELOUI, 6);1994merge_ie += 6;19951996while (i < in_len) {1997pIE = (PNDIS_802_11_VARIABLE_IEs)(in_ie + i);19981999/* Take out the rest of P2P OUIs */2000if (pIE->ElementID == _VENDOR_SPECIFIC_IE_ && _rtw_memcmp(pIE->data, OUI, 4)) {2001_rtw_memcpy(merge_ie, pIE->data + 4, pIE->Length - 4);2002len += pIE->Length - 4;2003merge_ie += pIE->Length - 4;2004}20052006i += (pIE->Length + 2);2007}20082009return len + 4; /* 4 is for P2P OUI */20102011}20122013return 0;2014}20152016void dump_p2p_ie(void *sel, const u8 *ie, u32 ie_len)2017{2018const u8 *pos = ie;2019u8 id;2020u16 len;20212022const u8 *p2p_ie;2023uint p2p_ielen;20242025p2p_ie = rtw_get_p2p_ie(ie, ie_len, NULL, &p2p_ielen);2026if (p2p_ie != ie || p2p_ielen == 0)2027return;20282029pos += 6;2030while (pos - ie + 3 <= ie_len) {2031id = *pos;2032len = RTW_GET_LE16(pos + 1);20332034RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len2035, ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");20362037pos += (3 + len);2038}2039}20402041/**2042* rtw_get_p2p_ie - Search P2P IE from a series of IEs2043* @in_ie: Address of IEs to search2044* @in_len: Length limit from in_ie2045* @p2p_ie: If not NULL and P2P IE is found, P2P IE will be copied to the buf starting from p2p_ie2046* @p2p_ielen: If not NULL and P2P IE is found, will set to the length of the entire P2P IE2047*2048* Returns: The address of the P2P IE found, or NULL2049*/2050u8 *rtw_get_p2p_ie(const u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen)2051{2052uint cnt;2053const u8 *p2p_ie_ptr = NULL;2054u8 eid, p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};20552056if (p2p_ielen)2057*p2p_ielen = 0;20582059if (!in_ie || in_len < 0) {2060rtw_warn_on(1);2061return (u8 *)p2p_ie_ptr;2062}20632064if (in_len <= 0)2065return (u8 *)p2p_ie_ptr;20662067cnt = 0;20682069while (cnt + 1 + 4 < in_len) {2070eid = in_ie[cnt];20712072if (cnt + 1 + 4 >= MAX_IE_SZ) {2073rtw_warn_on(1);2074return NULL;2075}20762077if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], p2p_oui, 4) == _TRUE) {2078p2p_ie_ptr = in_ie + cnt;20792080if (p2p_ie)2081_rtw_memcpy(p2p_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);20822083if (p2p_ielen)2084*p2p_ielen = in_ie[cnt + 1] + 2;20852086break;2087} else2088cnt += in_ie[cnt + 1] + 2;20892090}20912092return (u8 *)p2p_ie_ptr;2093}20942095/**2096* rtw_get_p2p_attr - Search a specific P2P attribute from a given P2P IE2097* @p2p_ie: Address of P2P IE to search2098* @p2p_ielen: Length limit from p2p_ie2099* @target_attr_id: The attribute ID of P2P attribute to search2100* @buf_attr: If not NULL and the P2P attribute is found, P2P attribute will be copied to the buf starting from buf_attr2101* @len_attr: If not NULL and the P2P attribute is found, will set to the length of the entire P2P attribute2102*2103* Returns: the address of the specific WPS attribute found, or NULL2104*/2105u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_attr, u32 *len_attr)2106{2107u8 *attr_ptr = NULL;2108u8 *target_attr_ptr = NULL;2109u8 p2p_oui[4] = {0x50, 0x6F, 0x9A, 0x09};21102111if (len_attr)2112*len_attr = 0;21132114if (!p2p_ie2115|| p2p_ielen <= 62116|| (p2p_ie[0] != WLAN_EID_VENDOR_SPECIFIC)2117|| (_rtw_memcmp(p2p_ie + 2, p2p_oui, 4) != _TRUE))2118return attr_ptr;21192120/* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */2121attr_ptr = p2p_ie + 6; /* goto first attr */21222123while ((attr_ptr - p2p_ie + 3) <= p2p_ielen) {2124/* 3 = 1(Attribute ID) + 2(Length) */2125u8 attr_id = *attr_ptr;2126u16 attr_data_len = RTW_GET_LE16(attr_ptr + 1);2127u16 attr_len = attr_data_len + 3;21282129if (0)2130RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);21312132if ((attr_ptr - p2p_ie + attr_len) > p2p_ielen)2133break;21342135if (attr_id == target_attr_id) {2136target_attr_ptr = attr_ptr;21372138if (buf_attr)2139_rtw_memcpy(buf_attr, attr_ptr, attr_len);21402141if (len_attr)2142*len_attr = attr_len;21432144break;2145} else2146attr_ptr += attr_len;2147}21482149return target_attr_ptr;2150}21512152/**2153* rtw_get_p2p_attr_content - Search a specific P2P attribute content from a given P2P IE2154* @p2p_ie: Address of P2P IE to search2155* @p2p_ielen: Length limit from p2p_ie2156* @target_attr_id: The attribute ID of P2P attribute to search2157* @buf_content: If not NULL and the P2P attribute is found, P2P attribute content will be copied to the buf starting from buf_content2158* @len_content: If not NULL and the P2P attribute is found, will set to the length of the P2P attribute content2159*2160* Returns: the address of the specific P2P attribute content found, or NULL2161*/2162u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id , u8 *buf_content, uint *len_content)2163{2164u8 *attr_ptr;2165u32 attr_len;21662167if (len_content)2168*len_content = 0;21692170attr_ptr = rtw_get_p2p_attr(p2p_ie, p2p_ielen, target_attr_id, NULL, &attr_len);21712172if (attr_ptr && attr_len) {2173if (buf_content)2174_rtw_memcpy(buf_content, attr_ptr + 3, attr_len - 3);21752176if (len_content)2177*len_content = attr_len - 3;21782179return attr_ptr + 3;2180}21812182return NULL;2183}21842185u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len, u8 *pdata_attr)2186{2187u32 a_len;21882189*pbuf = attr_id;21902191/* *(u16*)(pbuf + 1) = cpu_to_le16(attr_len); */2192RTW_PUT_LE16(pbuf + 1, attr_len);21932194if (pdata_attr)2195_rtw_memcpy(pbuf + 3, pdata_attr, attr_len);21962197a_len = attr_len + 3;21982199return a_len;2200}22012202uint rtw_del_p2p_ie(u8 *ies, uint ies_len_ori, const char *msg)2203{2204#define DBG_DEL_P2P_IE 022052206u8 *target_ie;2207u32 target_ie_len;2208uint ies_len = ies_len_ori;2209int index = 0;22102211while (1) {2212target_ie = rtw_get_p2p_ie(ies, ies_len, NULL, &target_ie_len);2213if (target_ie && target_ie_len) {2214u8 *next_ie = target_ie + target_ie_len;2215uint remain_len = ies_len - (next_ie - ies);22162217if (DBG_DEL_P2P_IE && msg) {2218RTW_INFO("%s %d before\n", __func__, index);2219dump_ies(RTW_DBGDUMP, ies, ies_len);22202221RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);2222RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);2223RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);2224}22252226_rtw_memmove(target_ie, next_ie, remain_len);2227_rtw_memset(target_ie + remain_len, 0, target_ie_len);2228ies_len -= target_ie_len;22292230if (DBG_DEL_P2P_IE && msg) {2231RTW_INFO("%s %d after\n", __func__, index);2232dump_ies(RTW_DBGDUMP, ies, ies_len);2233}22342235index++;2236} else2237break;2238}22392240return ies_len;2241}22422243uint rtw_del_p2p_attr(u8 *ie, uint ielen_ori, u8 attr_id)2244{2245#define DBG_DEL_P2P_ATTR 022462247u8 *target_attr;2248u32 target_attr_len;2249uint ielen = ielen_ori;2250int index = 0;22512252while (1) {2253target_attr = rtw_get_p2p_attr(ie, ielen, attr_id, NULL, &target_attr_len);2254if (target_attr && target_attr_len) {2255u8 *next_attr = target_attr + target_attr_len;2256uint remain_len = ielen - (next_attr - ie);22572258if (DBG_DEL_P2P_ATTR) {2259RTW_INFO("%s %d before\n", __func__, index);2260dump_ies(RTW_DBGDUMP, ie, ielen);22612262RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);2263RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);2264RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);2265}22662267_rtw_memmove(target_attr, next_attr, remain_len);2268_rtw_memset(target_attr + remain_len, 0, target_attr_len);2269*(ie + 1) -= target_attr_len;2270ielen -= target_attr_len;22712272if (DBG_DEL_P2P_ATTR) {2273RTW_INFO("%s %d after\n", __func__, index);2274dump_ies(RTW_DBGDUMP, ie, ielen);2275}22762277index++;2278} else2279break;2280}22812282return ielen;2283}22842285inline u8 *rtw_bss_ex_get_p2p_ie(WLAN_BSSID_EX *bss_ex, u8 *p2p_ie, uint *p2p_ielen)2286{2287return rtw_get_p2p_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), p2p_ie, p2p_ielen);2288}22892290void rtw_bss_ex_del_p2p_ie(WLAN_BSSID_EX *bss_ex)2291{2292#define DBG_BSS_EX_DEL_P2P_IE 022932294u8 *ies = BSS_EX_TLV_IES(bss_ex);2295uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);2296uint ies_len;22972298ies_len = rtw_del_p2p_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_P2P_IE ? __func__ : NULL);2299bss_ex->IELength -= ies_len_ori - ies_len;2300}23012302void rtw_bss_ex_del_p2p_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)2303{2304#define DBG_BSS_EX_DEL_P2P_ATTR 023052306u8 *ies = BSS_EX_TLV_IES(bss_ex);2307uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);23082309u8 *ie;2310uint ie_len, ie_len_ori;23112312int index = 0;23132314while (1) {2315ie = rtw_get_p2p_ie(ies, ies_len, NULL, &ie_len_ori);2316if (ie) {2317u8 *next_ie_ori = ie + ie_len_ori;2318uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);2319u8 has_target_attr = 0;23202321if (DBG_BSS_EX_DEL_P2P_ATTR) {2322if (rtw_get_p2p_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {2323RTW_INFO("%s %d before\n", __func__, index);2324dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));23252326RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);2327RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);2328RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);2329has_target_attr = 1;2330}2331}23322333ie_len = rtw_del_p2p_attr(ie, ie_len_ori, attr_id);2334if (ie_len != ie_len_ori) {2335u8 *next_ie = ie + ie_len;23362337_rtw_memmove(next_ie, next_ie_ori, remain_len);2338_rtw_memset(next_ie + remain_len, 0, ie_len_ori - ie_len);2339bss_ex->IELength -= ie_len_ori - ie_len;23402341ies = next_ie;2342} else2343ies = next_ie_ori;23442345if (DBG_BSS_EX_DEL_P2P_ATTR) {2346if (has_target_attr) {2347RTW_INFO("%s %d after\n", __func__, index);2348dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));2349}2350}23512352ies_len = remain_len;23532354index++;2355} else2356break;2357}2358}23592360void dump_wfd_ie(void *sel, const u8 *ie, u32 ie_len)2361{2362const u8 *pos = ie;2363u8 id;2364u16 len;23652366const u8 *wfd_ie;2367uint wfd_ielen;23682369wfd_ie = rtw_get_wfd_ie(ie, ie_len, NULL, &wfd_ielen);2370if (wfd_ie != ie || wfd_ielen == 0)2371return;23722373pos += 6;2374while (pos - ie + 3 <= ie_len) {2375id = *pos;2376len = RTW_GET_BE16(pos + 1);23772378RTW_PRINT_SEL(sel, "%s ID:%u, LEN:%u%s\n", __func__, id, len2379, ((pos - ie + 3 + len) <= ie_len) ? "" : "(exceed ie_len)");23802381pos += (3 + len);2382}2383}23842385/**2386* rtw_get_wfd_ie - Search WFD IE from a series of IEs2387* @in_ie: Address of IEs to search2388* @in_len: Length limit from in_ie2389* @wfd_ie: If not NULL and WFD IE is found, WFD IE will be copied to the buf starting from wfd_ie2390* @wfd_ielen: If not NULL and WFD IE is found, will set to the length of the entire WFD IE2391*2392* Returns: The address of the P2P IE found, or NULL2393*/2394u8 *rtw_get_wfd_ie(const u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen)2395{2396uint cnt;2397const u8 *wfd_ie_ptr = NULL;2398u8 eid, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};23992400if (wfd_ielen)2401*wfd_ielen = 0;24022403if (!in_ie || in_len < 0) {2404rtw_warn_on(1);2405return (u8 *)wfd_ie_ptr;2406}24072408if (in_len <= 0)2409return (u8 *)wfd_ie_ptr;24102411cnt = 0;24122413while (cnt + 1 + 4 < in_len) {2414eid = in_ie[cnt];24152416if (cnt + 1 + 4 >= MAX_IE_SZ) {2417rtw_warn_on(1);2418return NULL;2419}24202421if (eid == WLAN_EID_VENDOR_SPECIFIC && _rtw_memcmp(&in_ie[cnt + 2], wfd_oui, 4) == _TRUE) {2422wfd_ie_ptr = in_ie + cnt;24232424if (wfd_ie)2425_rtw_memcpy(wfd_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);24262427if (wfd_ielen)2428*wfd_ielen = in_ie[cnt + 1] + 2;24292430break;2431} else2432cnt += in_ie[cnt + 1] + 2;24332434}24352436return (u8 *)wfd_ie_ptr;2437}24382439/**2440* rtw_get_wfd_attr - Search a specific WFD attribute from a given WFD IE2441* @wfd_ie: Address of WFD IE to search2442* @wfd_ielen: Length limit from wfd_ie2443* @target_attr_id: The attribute ID of WFD attribute to search2444* @buf_attr: If not NULL and the WFD attribute is found, WFD attribute will be copied to the buf starting from buf_attr2445* @len_attr: If not NULL and the WFD attribute is found, will set to the length of the entire WFD attribute2446*2447* Returns: the address of the specific WPS attribute found, or NULL2448*/2449u8 *rtw_get_wfd_attr(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_attr, u32 *len_attr)2450{2451u8 *attr_ptr = NULL;2452u8 *target_attr_ptr = NULL;2453u8 wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A};24542455if (len_attr)2456*len_attr = 0;24572458if (!wfd_ie2459|| wfd_ielen <= 62460|| (wfd_ie[0] != WLAN_EID_VENDOR_SPECIFIC)2461|| (_rtw_memcmp(wfd_ie + 2, wfd_oui, 4) != _TRUE))2462return attr_ptr;24632464/* 6 = 1(Element ID) + 1(Length) + 3 (OUI) + 1(OUI Type) */2465attr_ptr = wfd_ie + 6; /* goto first attr */24662467while ((attr_ptr - wfd_ie + 3) <= wfd_ielen) {2468/* 3 = 1(Attribute ID) + 2(Length) */2469u8 attr_id = *attr_ptr;2470u16 attr_data_len = RTW_GET_BE16(attr_ptr + 1);2471u16 attr_len = attr_data_len + 3;24722473if (0)2474RTW_INFO("%s attr_ptr:%p, id:%u, length:%u\n", __func__, attr_ptr, attr_id, attr_data_len);24752476if ((attr_ptr - wfd_ie + attr_len) > wfd_ielen)2477break;24782479if (attr_id == target_attr_id) {2480target_attr_ptr = attr_ptr;24812482if (buf_attr)2483_rtw_memcpy(buf_attr, attr_ptr, attr_len);24842485if (len_attr)2486*len_attr = attr_len;24872488break;2489} else2490attr_ptr += attr_len;2491}24922493return target_attr_ptr;2494}24952496/**2497* rtw_get_wfd_attr_content - Search a specific WFD attribute content from a given WFD IE2498* @wfd_ie: Address of WFD IE to search2499* @wfd_ielen: Length limit from wfd_ie2500* @target_attr_id: The attribute ID of WFD attribute to search2501* @buf_content: If not NULL and the WFD attribute is found, WFD attribute content will be copied to the buf starting from buf_content2502* @len_content: If not NULL and the WFD attribute is found, will set to the length of the WFD attribute content2503*2504* Returns: the address of the specific WFD attribute content found, or NULL2505*/2506u8 *rtw_get_wfd_attr_content(u8 *wfd_ie, uint wfd_ielen, u8 target_attr_id, u8 *buf_content, uint *len_content)2507{2508u8 *attr_ptr;2509u32 attr_len;25102511if (len_content)2512*len_content = 0;25132514attr_ptr = rtw_get_wfd_attr(wfd_ie, wfd_ielen, target_attr_id, NULL, &attr_len);25152516if (attr_ptr && attr_len) {2517if (buf_content)2518_rtw_memcpy(buf_content, attr_ptr + 3, attr_len - 3);25192520if (len_content)2521*len_content = attr_len - 3;25222523return attr_ptr + 3;2524}25252526return NULL;2527}25282529uint rtw_del_wfd_ie(u8 *ies, uint ies_len_ori, const char *msg)2530{2531#define DBG_DEL_WFD_IE 025322533u8 *target_ie;2534u32 target_ie_len;2535uint ies_len = ies_len_ori;2536int index = 0;25372538while (1) {2539target_ie = rtw_get_wfd_ie(ies, ies_len, NULL, &target_ie_len);2540if (target_ie && target_ie_len) {2541u8 *next_ie = target_ie + target_ie_len;2542uint remain_len = ies_len - (next_ie - ies);25432544if (DBG_DEL_WFD_IE && msg) {2545RTW_INFO("%s %d before\n", __func__, index);2546dump_ies(RTW_DBGDUMP, ies, ies_len);25472548RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);2549RTW_INFO("target_ie:%p, target_ie_len:%u\n", target_ie, target_ie_len);2550RTW_INFO("next_ie:%p, remain_len:%u\n", next_ie, remain_len);2551}25522553_rtw_memmove(target_ie, next_ie, remain_len);2554_rtw_memset(target_ie + remain_len, 0, target_ie_len);2555ies_len -= target_ie_len;25562557if (DBG_DEL_WFD_IE && msg) {2558RTW_INFO("%s %d after\n", __func__, index);2559dump_ies(RTW_DBGDUMP, ies, ies_len);2560}25612562index++;2563} else2564break;2565}25662567return ies_len;2568}25692570uint rtw_del_wfd_attr(u8 *ie, uint ielen_ori, u8 attr_id)2571{2572#define DBG_DEL_WFD_ATTR 025732574u8 *target_attr;2575u32 target_attr_len;2576uint ielen = ielen_ori;2577int index = 0;25782579while (1) {2580target_attr = rtw_get_wfd_attr(ie, ielen, attr_id, NULL, &target_attr_len);2581if (target_attr && target_attr_len) {2582u8 *next_attr = target_attr + target_attr_len;2583uint remain_len = ielen - (next_attr - ie);25842585if (DBG_DEL_WFD_ATTR) {2586RTW_INFO("%s %d before\n", __func__, index);2587dump_ies(RTW_DBGDUMP, ie, ielen);25882589RTW_INFO("ie:%p, ielen:%u\n", ie, ielen);2590RTW_INFO("target_attr:%p, target_attr_len:%u\n", target_attr, target_attr_len);2591RTW_INFO("next_attr:%p, remain_len:%u\n", next_attr, remain_len);2592}25932594_rtw_memmove(target_attr, next_attr, remain_len);2595_rtw_memset(target_attr + remain_len, 0, target_attr_len);2596*(ie + 1) -= target_attr_len;2597ielen -= target_attr_len;25982599if (DBG_DEL_WFD_ATTR) {2600RTW_INFO("%s %d after\n", __func__, index);2601dump_ies(RTW_DBGDUMP, ie, ielen);2602}26032604index++;2605} else2606break;2607}26082609return ielen;2610}26112612inline u8 *rtw_bss_ex_get_wfd_ie(WLAN_BSSID_EX *bss_ex, u8 *wfd_ie, uint *wfd_ielen)2613{2614return rtw_get_wfd_ie(BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex), wfd_ie, wfd_ielen);2615}26162617void rtw_bss_ex_del_wfd_ie(WLAN_BSSID_EX *bss_ex)2618{2619#define DBG_BSS_EX_DEL_WFD_IE 02620u8 *ies = BSS_EX_TLV_IES(bss_ex);2621uint ies_len_ori = BSS_EX_TLV_IES_LEN(bss_ex);2622uint ies_len;26232624ies_len = rtw_del_wfd_ie(ies, ies_len_ori, DBG_BSS_EX_DEL_WFD_IE ? __func__ : NULL);2625bss_ex->IELength -= ies_len_ori - ies_len;2626}26272628void rtw_bss_ex_del_wfd_attr(WLAN_BSSID_EX *bss_ex, u8 attr_id)2629{2630#define DBG_BSS_EX_DEL_WFD_ATTR 026312632u8 *ies = BSS_EX_TLV_IES(bss_ex);2633uint ies_len = BSS_EX_TLV_IES_LEN(bss_ex);26342635u8 *ie;2636uint ie_len, ie_len_ori;26372638int index = 0;26392640while (1) {2641ie = rtw_get_wfd_ie(ies, ies_len, NULL, &ie_len_ori);2642if (ie) {2643u8 *next_ie_ori = ie + ie_len_ori;2644uint remain_len = bss_ex->IELength - (next_ie_ori - bss_ex->IEs);2645u8 has_target_attr = 0;26462647if (DBG_BSS_EX_DEL_WFD_ATTR) {2648if (rtw_get_wfd_attr(ie, ie_len_ori, attr_id, NULL, NULL)) {2649RTW_INFO("%s %d before\n", __func__, index);2650dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));26512652RTW_INFO("ies:%p, ies_len:%u\n", ies, ies_len);2653RTW_INFO("ie:%p, ie_len_ori:%u\n", ie, ie_len_ori);2654RTW_INFO("next_ie_ori:%p, remain_len:%u\n", next_ie_ori, remain_len);2655has_target_attr = 1;2656}2657}26582659ie_len = rtw_del_wfd_attr(ie, ie_len_ori, attr_id);2660if (ie_len != ie_len_ori) {2661u8 *next_ie = ie + ie_len;26622663_rtw_memmove(next_ie, next_ie_ori, remain_len);2664_rtw_memset(next_ie + remain_len, 0, ie_len_ori - ie_len);2665bss_ex->IELength -= ie_len_ori - ie_len;26662667ies = next_ie;2668} else2669ies = next_ie_ori;26702671if (DBG_BSS_EX_DEL_WFD_ATTR) {2672if (has_target_attr) {2673RTW_INFO("%s %d after\n", __func__, index);2674dump_ies(RTW_DBGDUMP, BSS_EX_TLV_IES(bss_ex), BSS_EX_TLV_IES_LEN(bss_ex));2675}2676}26772678ies_len = remain_len;26792680index++;2681} else2682break;2683}2684}26852686/* Baron adds to avoid FreeBSD warning */2687int ieee80211_is_empty_essid(const char *essid, int essid_len)2688{2689/* Single white space is for Linksys APs */2690if (essid_len == 1 && essid[0] == ' ')2691return 1;26922693/* Otherwise, if the entire essid is 0, we assume it is hidden */2694while (essid_len) {2695essid_len--;2696if (essid[essid_len] != '\0')2697return 0;2698}26992700return 1;2701}27022703int ieee80211_get_hdrlen(u16 fc)2704{2705int hdrlen = 24;27062707switch (WLAN_FC_GET_TYPE(fc)) {2708case RTW_IEEE80211_FTYPE_DATA:2709if (fc & RTW_IEEE80211_STYPE_QOS_DATA)2710hdrlen += 2;2711if ((fc & RTW_IEEE80211_FCTL_FROMDS) && (fc & RTW_IEEE80211_FCTL_TODS))2712hdrlen += 6; /* Addr4 */2713break;2714case RTW_IEEE80211_FTYPE_CTL:2715switch (WLAN_FC_GET_STYPE(fc)) {2716case RTW_IEEE80211_STYPE_CTS:2717case RTW_IEEE80211_STYPE_ACK:2718hdrlen = 10;2719break;2720default:2721hdrlen = 16;2722break;2723}2724break;2725}27262727return hdrlen;2728}27292730u8 rtw_ht_mcsset_to_nss(u8 *supp_mcs_set)2731{2732u8 nss = 1;27332734if (supp_mcs_set[3])2735nss = 4;2736else if (supp_mcs_set[2])2737nss = 3;2738else if (supp_mcs_set[1])2739nss = 2;2740else if (supp_mcs_set[0])2741nss = 1;2742else2743RTW_INFO("%s,%d, warning! supp_mcs_set is zero\n", __func__, __LINE__);2744/* RTW_INFO("%s HT: %dSS\n", __FUNCTION__, nss); */2745return nss;2746}27472748u32 rtw_ht_mcs_set_to_bitmap(u8 *mcs_set, u8 nss)2749{2750u8 i;2751u32 bitmap = 0;27522753for (i = 0; i < nss; i++)2754bitmap |= mcs_set[i] << (i * 8);27552756RTW_INFO("ht_mcs_set=%02x %02x %02x %02x, nss=%u, bitmap=%08x\n"2757, mcs_set[0], mcs_set[1], mcs_set[2], mcs_set[3], nss, bitmap);27582759return bitmap;2760}27612762/* show MCS rate, unit: 100Kbps */2763u16 rtw_ht_mcs_rate(u8 bw_40MHz, u8 short_GI, unsigned char *MCS_rate)2764{2765u16 max_rate = 0;27662767if (MCS_rate[3]) {2768if (MCS_rate[3] & BIT(7))2769max_rate = (bw_40MHz) ? ((short_GI) ? 6000 : 5400) : ((short_GI) ? 2889 : 2600);2770else if (MCS_rate[3] & BIT(6))2771max_rate = (bw_40MHz) ? ((short_GI) ? 5400 : 4860) : ((short_GI) ? 2600 : 2340);2772else if (MCS_rate[3] & BIT(5))2773max_rate = (bw_40MHz) ? ((short_GI) ? 4800 : 4320) : ((short_GI) ? 2311 : 2080);2774else if (MCS_rate[3] & BIT(4))2775max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);2776else if (MCS_rate[3] & BIT(3))2777max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);2778else if (MCS_rate[3] & BIT(2))2779max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);2780else if (MCS_rate[3] & BIT(1))2781max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);2782else if (MCS_rate[3] & BIT(0))2783max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);2784} else if (MCS_rate[2]) {2785if (MCS_rate[2] & BIT(7))2786max_rate = (bw_40MHz) ? ((short_GI) ? 4500 : 4050) : ((short_GI) ? 2167 : 1950);2787else if (MCS_rate[2] & BIT(6))2788max_rate = (bw_40MHz) ? ((short_GI) ? 4050 : 3645) : ((short_GI) ? 1950 : 1750);2789else if (MCS_rate[2] & BIT(5))2790max_rate = (bw_40MHz) ? ((short_GI) ? 3600 : 3240) : ((short_GI) ? 1733 : 1560);2791else if (MCS_rate[2] & BIT(4))2792max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);2793else if (MCS_rate[2] & BIT(3))2794max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);2795else if (MCS_rate[2] & BIT(2))2796max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);2797else if (MCS_rate[2] & BIT(1))2798max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);2799else if (MCS_rate[2] & BIT(0))2800max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);2801} else if (MCS_rate[1]) {2802if (MCS_rate[1] & BIT(7))2803max_rate = (bw_40MHz) ? ((short_GI) ? 3000 : 2700) : ((short_GI) ? 1444 : 1300);2804else if (MCS_rate[1] & BIT(6))2805max_rate = (bw_40MHz) ? ((short_GI) ? 2700 : 2430) : ((short_GI) ? 1300 : 1170);2806else if (MCS_rate[1] & BIT(5))2807max_rate = (bw_40MHz) ? ((short_GI) ? 2400 : 2160) : ((short_GI) ? 1156 : 1040);2808else if (MCS_rate[1] & BIT(4))2809max_rate = (bw_40MHz) ? ((short_GI) ? 1800 : 1620) : ((short_GI) ? 867 : 780);2810else if (MCS_rate[1] & BIT(3))2811max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);2812else if (MCS_rate[1] & BIT(2))2813max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);2814else if (MCS_rate[1] & BIT(1))2815max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);2816else if (MCS_rate[1] & BIT(0))2817max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);2818} else {2819if (MCS_rate[0] & BIT(7))2820max_rate = (bw_40MHz) ? ((short_GI) ? 1500 : 1350) : ((short_GI) ? 722 : 650);2821else if (MCS_rate[0] & BIT(6))2822max_rate = (bw_40MHz) ? ((short_GI) ? 1350 : 1215) : ((short_GI) ? 650 : 585);2823else if (MCS_rate[0] & BIT(5))2824max_rate = (bw_40MHz) ? ((short_GI) ? 1200 : 1080) : ((short_GI) ? 578 : 520);2825else if (MCS_rate[0] & BIT(4))2826max_rate = (bw_40MHz) ? ((short_GI) ? 900 : 810) : ((short_GI) ? 433 : 390);2827else if (MCS_rate[0] & BIT(3))2828max_rate = (bw_40MHz) ? ((short_GI) ? 600 : 540) : ((short_GI) ? 289 : 260);2829else if (MCS_rate[0] & BIT(2))2830max_rate = (bw_40MHz) ? ((short_GI) ? 450 : 405) : ((short_GI) ? 217 : 195);2831else if (MCS_rate[0] & BIT(1))2832max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);2833else if (MCS_rate[0] & BIT(0))2834max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);2835}28362837return max_rate;2838}28392840int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *action)2841{2842const u8 *frame_body = frame + sizeof(struct rtw_ieee80211_hdr_3addr);2843u16 fc;2844u8 c;2845u8 a = ACT_PUBLIC_MAX;28462847fc = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)frame)->frame_ctl);28482849if ((fc & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE))2850!= (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION)2851)2852return _FALSE;28532854c = frame_body[0];28552856switch (c) {2857case RTW_WLAN_CATEGORY_P2P: /* vendor-specific */2858break;2859default:2860a = frame_body[1];2861}28622863if (category)2864*category = c;2865if (action)2866*action = a;28672868return _TRUE;2869}28702871static const char *_action_public_str[] = {2872"ACT_PUB_BSSCOEXIST",2873"ACT_PUB_DSE_ENABLE",2874"ACT_PUB_DSE_DEENABLE",2875"ACT_PUB_DSE_REG_LOCATION",2876"ACT_PUB_EXT_CHL_SWITCH",2877"ACT_PUB_DSE_MSR_REQ",2878"ACT_PUB_DSE_MSR_RPRT",2879"ACT_PUB_MP",2880"ACT_PUB_DSE_PWR_CONSTRAINT",2881"ACT_PUB_VENDOR",2882"ACT_PUB_GAS_INITIAL_REQ",2883"ACT_PUB_GAS_INITIAL_RSP",2884"ACT_PUB_GAS_COMEBACK_REQ",2885"ACT_PUB_GAS_COMEBACK_RSP",2886"ACT_PUB_TDLS_DISCOVERY_RSP",2887"ACT_PUB_LOCATION_TRACK",2888"ACT_PUB_RSVD",2889};28902891const char *action_public_str(u8 action)2892{2893action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;2894return _action_public_str[action];2895}2896289728982899