xref: /openbmc/linux/net/mac80211/he.c (revision de528723)
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 
54 void
55 ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif,
56 			const struct ieee80211_he_operation *he_op_ie_elem)
57 {
58 	struct ieee80211_he_operation *he_operation =
59 					&vif->bss_conf.he_operation;
60 
61 	if (!he_op_ie_elem) {
62 		memset(he_operation, 0, sizeof(*he_operation));
63 		return;
64 	}
65 
66 	vif->bss_conf.he_operation = *he_op_ie_elem;
67 }
68 
69 void
70 ieee80211_he_spr_ie_to_bss_conf(struct ieee80211_vif *vif,
71 				const struct ieee80211_he_spr *he_spr_ie_elem)
72 {
73 	struct ieee80211_he_obss_pd *he_obss_pd =
74 					&vif->bss_conf.he_obss_pd;
75 	const u8 *data;
76 
77 	memset(he_obss_pd, 0, sizeof(*he_obss_pd));
78 
79 	if (!he_spr_ie_elem)
80 		return;
81 	data = he_spr_ie_elem->optional;
82 
83 	if (he_spr_ie_elem->he_sr_control &
84 	    IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
85 		data++;
86 	if (he_spr_ie_elem->he_sr_control &
87 	    IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
88 		he_obss_pd->max_offset = *data++;
89 		he_obss_pd->min_offset = *data++;
90 		he_obss_pd->enable = true;
91 	}
92 }
93