1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright(c) 2021-2022 Intel Corporation
8 #include "ieee80211_i.h"
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,
16 struct link_sta_info *link_sta)
18 struct ieee80211_sta_eht_cap *eht_cap = &link_sta->pub->eht_cap;
19 struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie;
22 u8 eht_total_size = sizeof(eht_cap->eht_cap_elem);
23 u8 *pos = (u8 *)eht_cap_ie_elem;
25 memset(eht_cap, 0, sizeof(*eht_cap));
27 if (!eht_cap_ie_elem ||
28 !ieee80211_get_eht_iftype_cap(sband,
29 ieee80211_vif_type_p2p(&sdata->vif)))
32 mcs_nss_size = ieee80211_eht_mcs_nss_size(he_cap_ie_elem,
33 &eht_cap_ie_elem->fixed,
35 NL80211_IFTYPE_STATION);
37 eht_total_size += mcs_nss_size;
39 /* Calculate the PPE thresholds length only if the header is present */
40 if (eht_cap_ie_elem->fixed.phy_cap_info[5] &
41 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) {
44 if (eht_cap_len < eht_total_size + sizeof(u16))
47 eht_ppe_hdr = get_unaligned_le16(eht_cap_ie_elem->optional + mcs_nss_size);
49 ieee80211_eht_ppe_size(eht_ppe_hdr,
50 eht_cap_ie_elem->fixed.phy_cap_info);
51 eht_total_size += eht_ppe_size;
53 /* we calculate as if NSS > 8 are valid, but don't handle that */
54 if (eht_ppe_size > sizeof(eht_cap->eht_ppe_thres))
58 if (eht_cap_len < eht_total_size)
61 /* Copy the static portion of the EHT capabilities */
62 memcpy(&eht_cap->eht_cap_elem, pos, sizeof(eht_cap->eht_cap_elem));
63 pos += sizeof(eht_cap->eht_cap_elem);
65 /* Copy MCS/NSS which depends on the peer capabilities */
66 memset(&eht_cap->eht_mcs_nss_supp, 0,
67 sizeof(eht_cap->eht_mcs_nss_supp));
68 memcpy(&eht_cap->eht_mcs_nss_supp, pos, mcs_nss_size);
71 memcpy(eht_cap->eht_ppe_thres,
72 &eht_cap_ie_elem->optional[mcs_nss_size],
75 eht_cap->has_eht = true;
77 link_sta->cur_max_bandwidth = ieee80211_sta_cap_rx_bw(link_sta);
78 link_sta->pub->bandwidth = ieee80211_sta_cur_vht_bw(link_sta);