xref: /linux/net/mac80211/he.c (revision 2dbc0838bcf24ca59cabc3130cf3b1d6809cdcd4)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * HE handling
4  *
5  * Copyright(c) 2017 Intel Deutschland GmbH
6  */
7 
8 #include "ieee80211_i.h"
9 
10 void
11 ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata,
12 				  struct ieee80211_supported_band *sband,
13 				  const u8 *he_cap_ie, u8 he_cap_len,
14 				  struct sta_info *sta)
15 {
16 	struct ieee80211_sta_he_cap *he_cap = &sta->sta.he_cap;
17 	struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie;
18 	u8 he_ppe_size;
19 	u8 mcs_nss_size;
20 	u8 he_total_size;
21 
22 	memset(he_cap, 0, sizeof(*he_cap));
23 
24 	if (!he_cap_ie || !ieee80211_get_he_sta_cap(sband))
25 		return;
26 
27 	/* Make sure size is OK */
28 	mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap_ie_elem);
29 	he_ppe_size =
30 		ieee80211_he_ppe_size(he_cap_ie[sizeof(he_cap->he_cap_elem) +
31 						mcs_nss_size],
32 				      he_cap_ie_elem->phy_cap_info);
33 	he_total_size = sizeof(he_cap->he_cap_elem) + mcs_nss_size +
34 			he_ppe_size;
35 	if (he_cap_len < he_total_size)
36 		return;
37 
38 	memcpy(&he_cap->he_cap_elem, he_cap_ie, sizeof(he_cap->he_cap_elem));
39 
40 	/* HE Tx/Rx HE MCS NSS Support Field */
41 	memcpy(&he_cap->he_mcs_nss_supp,
42 	       &he_cap_ie[sizeof(he_cap->he_cap_elem)], mcs_nss_size);
43 
44 	/* Check if there are (optional) PPE Thresholds */
45 	if (he_cap->he_cap_elem.phy_cap_info[6] &
46 	    IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
47 		memcpy(he_cap->ppe_thres,
48 		       &he_cap_ie[sizeof(he_cap->he_cap_elem) + mcs_nss_size],
49 		       he_ppe_size);
50 
51 	he_cap->has_he = true;
52 }
53