xref: /linux/net/mac80211/eht.c (revision d603517771d8e08a2d8fc9e1f7682ce393d3973a)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * EHT handling
4  *
5  * Copyright(c) 2021-2026 Intel Corporation
6  */
7 
8 #include "driver-ops.h"
9 #include "ieee80211_i.h"
10 
11 void
12 ieee80211_eht_cap_ie_to_sta_eht_cap(struct ieee80211_sub_if_data *sdata,
13 				    struct ieee80211_supported_band *sband,
14 				    const u8 *he_cap_ie, u8 he_cap_len,
15 				    const struct ieee80211_eht_cap_elem *eht_cap_ie_elem,
16 				    u8 eht_cap_len,
17 				    struct link_sta_info *link_sta)
18 {
19 	struct ieee80211_sta_eht_cap *eht_cap = &link_sta->pub->eht_cap;
20 	struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie;
21 	u8 eht_ppe_size = 0;
22 	u8 mcs_nss_size;
23 	u8 eht_total_size = sizeof(eht_cap->eht_cap_elem);
24 	u8 *pos = (u8 *)eht_cap_ie_elem;
25 
26 	memset(eht_cap, 0, sizeof(*eht_cap));
27 
28 	if (!eht_cap_ie_elem ||
29 	    !ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif))
30 		return;
31 
32 	mcs_nss_size = ieee80211_eht_mcs_nss_size(he_cap_ie_elem,
33 						  &eht_cap_ie_elem->fixed,
34 						  sdata->vif.type ==
35 							NL80211_IFTYPE_STATION);
36 
37 	eht_total_size += mcs_nss_size;
38 
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) {
42 		u16 eht_ppe_hdr;
43 
44 		if (eht_cap_len < eht_total_size + sizeof(u16))
45 			return;
46 
47 		eht_ppe_hdr = get_unaligned_le16(eht_cap_ie_elem->optional + mcs_nss_size);
48 		eht_ppe_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;
52 
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))
55 			return;
56 	}
57 
58 	if (eht_cap_len < eht_total_size)
59 		return;
60 
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);
64 
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);
69 
70 	if (eht_ppe_size)
71 		memcpy(eht_cap->eht_ppe_thres,
72 		       &eht_cap_ie_elem->optional[mcs_nss_size],
73 		       eht_ppe_size);
74 
75 	eht_cap->has_eht = true;
76 
77 	/*
78 	 * The MPDU length bits are reserved on all but 2.4 GHz and get set via
79 	 * VHT (5 GHz) or HE (6 GHz) capabilities.
80 	 */
81 	if (sband->band != NL80211_BAND_2GHZ)
82 		return;
83 
84 	switch (u8_get_bits(eht_cap->eht_cap_elem.mac_cap_info[0],
85 			    IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_MASK)) {
86 	case IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_11454:
87 		link_sta->pub->agg.max_amsdu_len =
88 			IEEE80211_MAX_MPDU_LEN_VHT_11454;
89 		break;
90 	case IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_7991:
91 		link_sta->pub->agg.max_amsdu_len =
92 			IEEE80211_MAX_MPDU_LEN_VHT_7991;
93 		break;
94 	case IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_3895:
95 	default:
96 		link_sta->pub->agg.max_amsdu_len =
97 			IEEE80211_MAX_MPDU_LEN_VHT_3895;
98 		break;
99 	}
100 
101 	ieee80211_sta_recalc_aggregates(&link_sta->sta->sta);
102 }
103