blob: cc26f239838ba698987c776c456336254a4fd120 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002/*
3 * HE handling
4 *
5 * Copyright(c) 2017 Intel Deutschland GmbH
Ilan Peerc4d800d2020-01-31 13:12:53 +02006 * Copyright(c) 2019 - 2020 Intel Corporation
Luca Coelho41cbb0f2018-06-09 09:14:44 +03007 */
8
9#include "ieee80211_i.h"
10
Johannes Berg1bb9a8a2020-05-28 21:34:38 +020011static void
12ieee80211_update_from_he_6ghz_capa(const struct ieee80211_he_6ghz_capa *he_6ghz_capa,
13 struct sta_info *sta)
14{
15 enum ieee80211_smps_mode smps_mode;
16
17 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
18 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
19 switch (le16_get_bits(he_6ghz_capa->capa,
20 IEEE80211_HE_6GHZ_CAP_SM_PS)) {
21 case WLAN_HT_CAP_SM_PS_INVALID:
22 case WLAN_HT_CAP_SM_PS_STATIC:
23 smps_mode = IEEE80211_SMPS_STATIC;
24 break;
25 case WLAN_HT_CAP_SM_PS_DYNAMIC:
26 smps_mode = IEEE80211_SMPS_DYNAMIC;
27 break;
28 case WLAN_HT_CAP_SM_PS_DISABLED:
29 smps_mode = IEEE80211_SMPS_OFF;
30 break;
31 }
32
33 sta->sta.smps_mode = smps_mode;
34 } else {
35 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
36 }
37
38 switch (le16_get_bits(he_6ghz_capa->capa,
39 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN)) {
40 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
41 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
42 break;
43 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
44 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
45 break;
46 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
47 default:
48 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
49 break;
50 }
51
52 sta->sta.he_6ghz_capa = *he_6ghz_capa;
53}
54
Luca Coelho41cbb0f2018-06-09 09:14:44 +030055void
56ieee80211_he_cap_ie_to_sta_he_cap(struct ieee80211_sub_if_data *sdata,
57 struct ieee80211_supported_band *sband,
58 const u8 *he_cap_ie, u8 he_cap_len,
Johannes Berg1bb9a8a2020-05-28 21:34:38 +020059 const struct ieee80211_he_6ghz_capa *he_6ghz_capa,
Luca Coelho41cbb0f2018-06-09 09:14:44 +030060 struct sta_info *sta)
61{
62 struct ieee80211_sta_he_cap *he_cap = &sta->sta.he_cap;
63 struct ieee80211_he_cap_elem *he_cap_ie_elem = (void *)he_cap_ie;
64 u8 he_ppe_size;
65 u8 mcs_nss_size;
66 u8 he_total_size;
67
68 memset(he_cap, 0, sizeof(*he_cap));
69
70 if (!he_cap_ie || !ieee80211_get_he_sta_cap(sband))
71 return;
72
73 /* Make sure size is OK */
74 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap_ie_elem);
75 he_ppe_size =
76 ieee80211_he_ppe_size(he_cap_ie[sizeof(he_cap->he_cap_elem) +
77 mcs_nss_size],
78 he_cap_ie_elem->phy_cap_info);
79 he_total_size = sizeof(he_cap->he_cap_elem) + mcs_nss_size +
80 he_ppe_size;
81 if (he_cap_len < he_total_size)
82 return;
83
84 memcpy(&he_cap->he_cap_elem, he_cap_ie, sizeof(he_cap->he_cap_elem));
85
86 /* HE Tx/Rx HE MCS NSS Support Field */
87 memcpy(&he_cap->he_mcs_nss_supp,
88 &he_cap_ie[sizeof(he_cap->he_cap_elem)], mcs_nss_size);
89
90 /* Check if there are (optional) PPE Thresholds */
91 if (he_cap->he_cap_elem.phy_cap_info[6] &
92 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
93 memcpy(he_cap->ppe_thres,
94 &he_cap_ie[sizeof(he_cap->he_cap_elem) + mcs_nss_size],
95 he_ppe_size);
96
97 he_cap->has_he = true;
Johannes Bergcf2c9cc2020-01-31 13:12:41 +020098
99 sta->cur_max_bandwidth = ieee80211_sta_cap_rx_bw(sta);
100 sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
Johannes Berg1bb9a8a2020-05-28 21:34:38 +0200101
102 if (sband->band == NL80211_BAND_6GHZ && he_6ghz_capa)
103 ieee80211_update_from_he_6ghz_capa(he_6ghz_capa, sta);
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300104}
John Crispin697f6c52019-07-29 12:23:42 +0200105
106void
107ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif,
Rajkumar Manoharan60689de2020-04-24 15:41:39 -0700108 const struct ieee80211_he_operation *he_op_ie)
John Crispin697f6c52019-07-29 12:23:42 +0200109{
Rajkumar Manoharan60689de2020-04-24 15:41:39 -0700110 memset(&vif->bss_conf.he_oper, 0, sizeof(vif->bss_conf.he_oper));
111 if (!he_op_ie)
John Crispin697f6c52019-07-29 12:23:42 +0200112 return;
John Crispin697f6c52019-07-29 12:23:42 +0200113
Rajkumar Manoharan60689de2020-04-24 15:41:39 -0700114 vif->bss_conf.he_oper.params = __le32_to_cpu(he_op_ie->he_oper_params);
115 vif->bss_conf.he_oper.nss_set = __le16_to_cpu(he_op_ie->he_mcs_nss_set);
John Crispin697f6c52019-07-29 12:23:42 +0200116}
John Crispin1ced1692019-07-30 18:37:01 +0200117
118void
119ieee80211_he_spr_ie_to_bss_conf(struct ieee80211_vif *vif,
120 const struct ieee80211_he_spr *he_spr_ie_elem)
121{
122 struct ieee80211_he_obss_pd *he_obss_pd =
123 &vif->bss_conf.he_obss_pd;
John Crispin5db16ba2019-08-13 09:07:12 +0200124 const u8 *data;
John Crispin1ced1692019-07-30 18:37:01 +0200125
126 memset(he_obss_pd, 0, sizeof(*he_obss_pd));
127
128 if (!he_spr_ie_elem)
129 return;
John Crispin5db16ba2019-08-13 09:07:12 +0200130 data = he_spr_ie_elem->optional;
John Crispin1ced1692019-07-30 18:37:01 +0200131
132 if (he_spr_ie_elem->he_sr_control &
133 IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
134 data++;
135 if (he_spr_ie_elem->he_sr_control &
136 IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
137 he_obss_pd->max_offset = *data++;
138 he_obss_pd->min_offset = *data++;
139 he_obss_pd->enable = true;
140 }
141}