xref: /openbmc/linux/net/mac80211/he.c (revision 15e3ae36)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * HE handling
4  *
5  * Copyright(c) 2017 Intel Deutschland GmbH
6  * Copyright(c) 2019 - 2020 Intel Corporation
7  */
8 
9 #include "ieee80211_i.h"
10 
11 void
12 ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata,
13 				  struct ieee80211_supported_band *sband,
14 				  const u8 *he_cap_ie, u8 he_cap_len,
15 				  struct sta_info *sta)
16 {
17 	struct ieee80211_sta_he_cap *he_cap = &sta->sta.he_cap;
18 	struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie;
19 	u8 he_ppe_size;
20 	u8 mcs_nss_size;
21 	u8 he_total_size;
22 
23 	memset(he_cap, 0, sizeof(*he_cap));
24 
25 	if (!he_cap_ie || !ieee80211_get_he_sta_cap(sband))
26 		return;
27 
28 	/* Make sure size is OK */
29 	mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap_ie_elem);
30 	he_ppe_size =
31 		ieee80211_he_ppe_size(he_cap_ie[sizeof(he_cap->he_cap_elem) +
32 						mcs_nss_size],
33 				      he_cap_ie_elem->phy_cap_info);
34 	he_total_size = sizeof(he_cap->he_cap_elem) + mcs_nss_size +
35 			he_ppe_size;
36 	if (he_cap_len < he_total_size)
37 		return;
38 
39 	memcpy(&he_cap->he_cap_elem, he_cap_ie, sizeof(he_cap->he_cap_elem));
40 
41 	/* HE Tx/Rx HE MCS NSS Support Field */
42 	memcpy(&he_cap->he_mcs_nss_supp,
43 	       &he_cap_ie[sizeof(he_cap->he_cap_elem)], mcs_nss_size);
44 
45 	/* Check if there are (optional) PPE Thresholds */
46 	if (he_cap->he_cap_elem.phy_cap_info[6] &
47 	    IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
48 		memcpy(he_cap->ppe_thres,
49 		       &he_cap_ie[sizeof(he_cap->he_cap_elem) + mcs_nss_size],
50 		       he_ppe_size);
51 
52 	he_cap->has_he = true;
53 
54 	sta->cur_max_bandwidth = ieee80211_sta_cap_rx_bw(sta);
55 	sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
56 }
57 
58 void
59 ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif,
60 			const struct ieee80211_he_operation *he_op_ie_elem)
61 {
62 	struct ieee80211_he_operation *he_operation =
63 					&vif->bss_conf.he_operation;
64 
65 	if (!he_op_ie_elem) {
66 		memset(he_operation, 0, sizeof(*he_operation));
67 		return;
68 	}
69 
70 	vif->bss_conf.he_operation = *he_op_ie_elem;
71 }
72 
73 void
74 ieee80211_he_spr_ie_to_bss_conf(struct ieee80211_vif *vif,
75 				const struct ieee80211_he_spr *he_spr_ie_elem)
76 {
77 	struct ieee80211_he_obss_pd *he_obss_pd =
78 					&vif->bss_conf.he_obss_pd;
79 	const u8 *data;
80 
81 	memset(he_obss_pd, 0, sizeof(*he_obss_pd));
82 
83 	if (!he_spr_ie_elem)
84 		return;
85 	data = he_spr_ie_elem->optional;
86 
87 	if (he_spr_ie_elem->he_sr_control &
88 	    IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
89 		data++;
90 	if (he_spr_ie_elem->he_sr_control &
91 	    IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
92 		he_obss_pd->max_offset = *data++;
93 		he_obss_pd->min_offset = *data++;
94 		he_obss_pd->enable = true;
95 	}
96 }
97