Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2 | /* |
| 3 | * HE handling |
| 4 | * |
| 5 | * Copyright(c) 2017 Intel Deutschland GmbH |
Ilan Peer | c4d800d | 2020-01-31 13:12:53 +0200 | [diff] [blame] | 6 | * Copyright(c) 2019 - 2020 Intel Corporation |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "ieee80211_i.h" |
| 10 | |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 11 | static void |
| 12 | ieee80211_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 Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 55 | void |
| 56 | ieee80211_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 Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 59 | const struct ieee80211_he_6ghz_capa *he_6ghz_capa, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 60 | 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 Berg | cf2c9cc | 2020-01-31 13:12:41 +0200 | [diff] [blame] | 98 | |
| 99 | sta->cur_max_bandwidth = ieee80211_sta_cap_rx_bw(sta); |
| 100 | sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta); |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 101 | |
| 102 | if (sband->band == NL80211_BAND_6GHZ && he_6ghz_capa) |
| 103 | ieee80211_update_from_he_6ghz_capa(he_6ghz_capa, sta); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 104 | } |
John Crispin | 697f6c5 | 2019-07-29 12:23:42 +0200 | [diff] [blame] | 105 | |
| 106 | void |
| 107 | ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif, |
Rajkumar Manoharan | 60689de | 2020-04-24 15:41:39 -0700 | [diff] [blame] | 108 | const struct ieee80211_he_operation *he_op_ie) |
John Crispin | 697f6c5 | 2019-07-29 12:23:42 +0200 | [diff] [blame] | 109 | { |
Rajkumar Manoharan | 60689de | 2020-04-24 15:41:39 -0700 | [diff] [blame] | 110 | memset(&vif->bss_conf.he_oper, 0, sizeof(vif->bss_conf.he_oper)); |
| 111 | if (!he_op_ie) |
John Crispin | 697f6c5 | 2019-07-29 12:23:42 +0200 | [diff] [blame] | 112 | return; |
John Crispin | 697f6c5 | 2019-07-29 12:23:42 +0200 | [diff] [blame] | 113 | |
Rajkumar Manoharan | 60689de | 2020-04-24 15:41:39 -0700 | [diff] [blame] | 114 | 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 Crispin | 697f6c5 | 2019-07-29 12:23:42 +0200 | [diff] [blame] | 116 | } |
John Crispin | 1ced169 | 2019-07-30 18:37:01 +0200 | [diff] [blame] | 117 | |
| 118 | void |
| 119 | ieee80211_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 Crispin | 5db16ba | 2019-08-13 09:07:12 +0200 | [diff] [blame] | 124 | const u8 *data; |
John Crispin | 1ced169 | 2019-07-30 18:37:01 +0200 | [diff] [blame] | 125 | |
| 126 | memset(he_obss_pd, 0, sizeof(*he_obss_pd)); |
| 127 | |
| 128 | if (!he_spr_ie_elem) |
| 129 | return; |
John Crispin | 5db16ba | 2019-08-13 09:07:12 +0200 | [diff] [blame] | 130 | data = he_spr_ie_elem->optional; |
John Crispin | 1ced169 | 2019-07-30 18:37:01 +0200 | [diff] [blame] | 131 | |
| 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 | } |