1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * EHT handling 4 * 5 * Copyright(c) 2021-2022 Intel Corporation 6 */ 7 8 #include "ieee80211_i.h" 9 10 void 11 ieee80211_eht_cap_ie_to_sta_eht_cap(struct ieee80211_sub_if_data *sdata, 12 struct ieee80211_supported_band *sband, 13 const u8 *he_cap_ie, u8 he_cap_len, 14 const struct ieee80211_eht_cap_elem *eht_cap_ie_elem, 15 u8 eht_cap_len, struct sta_info *sta) 16 { 17 struct ieee80211_sta_eht_cap *eht_cap = &sta->sta.deflink.eht_cap; 18 struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie; 19 u8 eht_ppe_size = 0; 20 u8 mcs_nss_size; 21 u8 eht_total_size = sizeof(eht_cap->eht_cap_elem); 22 u8 *pos = (u8 *)eht_cap_ie_elem; 23 24 memset(eht_cap, 0, sizeof(*eht_cap)); 25 26 if (!eht_cap_ie_elem || 27 !ieee80211_get_eht_iftype_cap(sband, 28 ieee80211_vif_type_p2p(&sdata->vif))) 29 return; 30 31 mcs_nss_size = ieee80211_eht_mcs_nss_size(he_cap_ie_elem, 32 &eht_cap_ie_elem->fixed); 33 34 eht_total_size += mcs_nss_size; 35 36 /* Calculate the PPE thresholds length only if the header is present */ 37 if (eht_cap_ie_elem->fixed.phy_cap_info[5] & 38 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { 39 u16 eht_ppe_hdr; 40 41 if (eht_cap_len < eht_total_size + sizeof(u16)) 42 return; 43 44 eht_ppe_hdr = get_unaligned_le16(eht_cap_ie_elem->optional + mcs_nss_size); 45 eht_ppe_size = 46 ieee80211_eht_ppe_size(eht_ppe_hdr, 47 eht_cap_ie_elem->fixed.phy_cap_info); 48 eht_total_size += eht_ppe_size; 49 50 /* we calculate as if NSS > 8 are valid, but don't handle that */ 51 if (eht_ppe_size > sizeof(eht_cap->eht_ppe_thres)) 52 return; 53 } 54 55 if (eht_cap_len < eht_total_size) 56 return; 57 58 /* Copy the static portion of the EHT capabilities */ 59 memcpy(&eht_cap->eht_cap_elem, pos, sizeof(eht_cap->eht_cap_elem)); 60 pos += sizeof(eht_cap->eht_cap_elem); 61 62 /* Copy MCS/NSS which depends on the peer capabilities */ 63 memset(&eht_cap->eht_mcs_nss_supp, 0, 64 sizeof(eht_cap->eht_mcs_nss_supp)); 65 memcpy(&eht_cap->eht_mcs_nss_supp, pos, mcs_nss_size); 66 67 if (eht_ppe_size) 68 memcpy(eht_cap->eht_ppe_thres, 69 &eht_cap_ie_elem->optional[mcs_nss_size], 70 eht_ppe_size); 71 72 eht_cap->has_eht = true; 73 74 sta->deflink.cur_max_bandwidth = ieee80211_sta_cap_rx_bw(sta); 75 sta->sta.deflink.bandwidth = ieee80211_sta_cur_vht_bw(sta); 76 } 77