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