Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * VHT handling |
| 3 | * |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 4 | * Portions of this file |
Sara Sharon | 65554d0 | 2016-02-16 12:48:17 +0200 | [diff] [blame] | 5 | * Copyright(c) 2015 - 2016 Intel Deutschland GmbH |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 6 | * |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/ieee80211.h> |
| 13 | #include <linux/export.h> |
| 14 | #include <net/mac80211.h> |
| 15 | #include "ieee80211_i.h" |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 16 | #include "rate.h" |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 17 | |
| 18 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 19 | static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata, |
| 20 | struct ieee80211_sta_vht_cap *vht_cap, |
| 21 | u32 flag) |
| 22 | { |
| 23 | __le32 le_flag = cpu_to_le32(flag); |
| 24 | |
| 25 | if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag && |
| 26 | !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag)) |
| 27 | vht_cap->cap &= ~flag; |
| 28 | } |
| 29 | |
| 30 | void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata, |
| 31 | struct ieee80211_sta_vht_cap *vht_cap) |
| 32 | { |
| 33 | int i; |
| 34 | u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n; |
| 35 | |
| 36 | if (!vht_cap->vht_supported) |
| 37 | return; |
| 38 | |
| 39 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 40 | return; |
| 41 | |
| 42 | __check_vhtcap_disable(sdata, vht_cap, |
| 43 | IEEE80211_VHT_CAP_RXLDPC); |
| 44 | __check_vhtcap_disable(sdata, vht_cap, |
| 45 | IEEE80211_VHT_CAP_SHORT_GI_80); |
| 46 | __check_vhtcap_disable(sdata, vht_cap, |
| 47 | IEEE80211_VHT_CAP_SHORT_GI_160); |
| 48 | __check_vhtcap_disable(sdata, vht_cap, |
| 49 | IEEE80211_VHT_CAP_TXSTBC); |
| 50 | __check_vhtcap_disable(sdata, vht_cap, |
| 51 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 52 | __check_vhtcap_disable(sdata, vht_cap, |
| 53 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); |
| 54 | __check_vhtcap_disable(sdata, vht_cap, |
| 55 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN); |
| 56 | __check_vhtcap_disable(sdata, vht_cap, |
| 57 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN); |
| 58 | |
| 59 | /* Allow user to decrease AMPDU length exponent */ |
| 60 | if (sdata->u.mgd.vht_capa_mask.vht_cap_info & |
| 61 | cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) { |
| 62 | u32 cap, n; |
| 63 | |
| 64 | n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) & |
| 65 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 66 | n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 67 | cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 68 | cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 69 | |
| 70 | if (n < cap) { |
| 71 | vht_cap->cap &= |
| 72 | ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 73 | vht_cap->cap |= |
| 74 | n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* Allow the user to decrease MCSes */ |
| 79 | rxmcs_mask = |
| 80 | le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map); |
| 81 | rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map); |
| 82 | rxmcs_n &= rxmcs_mask; |
| 83 | rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 84 | |
| 85 | txmcs_mask = |
| 86 | le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map); |
| 87 | txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map); |
| 88 | txmcs_n &= txmcs_mask; |
| 89 | txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 90 | for (i = 0; i < 8; i++) { |
| 91 | u8 m, n, c; |
| 92 | |
| 93 | m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 94 | n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 95 | c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 96 | |
| 97 | if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) || |
| 98 | n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) { |
| 99 | rxmcs_cap &= ~(3 << 2*i); |
| 100 | rxmcs_cap |= (rxmcs_n & (3 << 2*i)); |
| 101 | } |
| 102 | |
| 103 | m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 104 | n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 105 | c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 106 | |
| 107 | if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) || |
| 108 | n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) { |
| 109 | txmcs_cap &= ~(3 << 2*i); |
| 110 | txmcs_cap |= (txmcs_n & (3 << 2*i)); |
| 111 | } |
| 112 | } |
| 113 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap); |
| 114 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap); |
| 115 | } |
| 116 | |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 117 | void |
| 118 | ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata, |
| 119 | struct ieee80211_supported_band *sband, |
| 120 | const struct ieee80211_vht_cap *vht_cap_ie, |
| 121 | struct sta_info *sta) |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 122 | { |
Johannes Berg | 4a34215 | 2013-02-07 11:58:58 +0100 | [diff] [blame] | 123 | struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap; |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 124 | struct ieee80211_sta_vht_cap own_cap; |
| 125 | u32 cap_info, i; |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 126 | bool have_80mhz; |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 127 | |
| 128 | memset(vht_cap, 0, sizeof(*vht_cap)); |
| 129 | |
Johannes Berg | 4a34215 | 2013-02-07 11:58:58 +0100 | [diff] [blame] | 130 | if (!sta->sta.ht_cap.ht_supported) |
| 131 | return; |
| 132 | |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 133 | if (!vht_cap_ie || !sband->vht_cap.vht_supported) |
| 134 | return; |
| 135 | |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 136 | /* Allow VHT if at least one channel on the sband supports 80 MHz */ |
| 137 | have_80mhz = false; |
| 138 | for (i = 0; i < sband->n_channels; i++) { |
| 139 | if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | |
| 140 | IEEE80211_CHAN_NO_80MHZ)) |
| 141 | continue; |
| 142 | |
| 143 | have_80mhz = true; |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | if (!have_80mhz) |
| 148 | return; |
| 149 | |
Johannes Berg | 4a817aa | 2014-05-09 09:56:53 +0200 | [diff] [blame] | 150 | /* |
| 151 | * A VHT STA must support 40 MHz, but if we verify that here |
| 152 | * then we break a few things - some APs (e.g. Netgear R6300v2 |
| 153 | * and others based on the BCM4360 chipset) will unset this |
| 154 | * capability bit when operating in 20 MHz. |
| 155 | */ |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 156 | |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 157 | vht_cap->vht_supported = true; |
| 158 | |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 159 | own_cap = sband->vht_cap; |
| 160 | /* |
| 161 | * If user has specified capability overrides, take care |
| 162 | * of that if the station we're setting up is the AP that |
| 163 | * we advertised a restricted capability set to. Override |
| 164 | * our own capabilities and then use those below. |
| 165 | */ |
| 166 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 167 | !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) |
| 168 | ieee80211_apply_vhtcap_overrides(sdata, &own_cap); |
| 169 | |
| 170 | /* take some capabilities as-is */ |
| 171 | cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info); |
| 172 | vht_cap->cap = cap_info; |
| 173 | vht_cap->cap &= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 | |
| 174 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | |
| 175 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 176 | IEEE80211_VHT_CAP_RXLDPC | |
| 177 | IEEE80211_VHT_CAP_VHT_TXOP_PS | |
| 178 | IEEE80211_VHT_CAP_HTC_VHT | |
| 179 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | |
| 180 | IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB | |
| 181 | IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB | |
| 182 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | |
| 183 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN; |
| 184 | |
| 185 | /* and some based on our own capabilities */ |
| 186 | switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { |
| 187 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: |
| 188 | vht_cap->cap |= cap_info & |
| 189 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 190 | break; |
| 191 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: |
| 192 | vht_cap->cap |= cap_info & |
| 193 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 194 | break; |
| 195 | default: |
| 196 | /* nothing */ |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | /* symmetric capabilities */ |
| 201 | vht_cap->cap |= cap_info & own_cap.cap & |
| 202 | (IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 203 | IEEE80211_VHT_CAP_SHORT_GI_160); |
| 204 | |
| 205 | /* remaining ones */ |
Eyal Shapira | fbdd90e | 2013-11-11 20:14:00 +0200 | [diff] [blame] | 206 | if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 207 | vht_cap->cap |= cap_info & |
| 208 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
Eyal Shapira | fbdd90e | 2013-11-11 20:14:00 +0200 | [diff] [blame] | 209 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 210 | |
| 211 | if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 212 | vht_cap->cap |= cap_info & |
Eliad Peller | 5eb7906 | 2013-08-29 15:03:14 +0300 | [diff] [blame] | 213 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
Eyal Shapira | fbdd90e | 2013-11-11 20:14:00 +0200 | [diff] [blame] | 214 | IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 215 | |
| 216 | if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 217 | vht_cap->cap |= cap_info & |
| 218 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 219 | |
| 220 | if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 221 | vht_cap->cap |= cap_info & |
| 222 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE; |
| 223 | |
| 224 | if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC) |
| 225 | vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK; |
| 226 | |
| 227 | if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK) |
| 228 | vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC; |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 229 | |
| 230 | /* Copy peer MCS info, the driver might need them. */ |
| 231 | memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs, |
| 232 | sizeof(struct ieee80211_vht_mcs_info)); |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 233 | |
Johannes Berg | 55d942f | 2013-03-01 13:07:48 +0100 | [diff] [blame] | 234 | /* but also restrict MCSes */ |
| 235 | for (i = 0; i < 8; i++) { |
| 236 | u16 own_rx, own_tx, peer_rx, peer_tx; |
| 237 | |
| 238 | own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map); |
| 239 | own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 240 | |
| 241 | own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map); |
| 242 | own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 243 | |
| 244 | peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 245 | peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 246 | |
| 247 | peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 248 | peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 249 | |
| 250 | if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) { |
| 251 | if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 252 | peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 253 | else if (own_rx < peer_tx) |
| 254 | peer_tx = own_rx; |
| 255 | } |
| 256 | |
| 257 | if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) { |
| 258 | if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 259 | peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 260 | else if (own_tx < peer_rx) |
| 261 | peer_rx = own_tx; |
| 262 | } |
| 263 | |
| 264 | vht_cap->vht_mcs.rx_mcs_map &= |
| 265 | ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2); |
| 266 | vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2); |
| 267 | |
| 268 | vht_cap->vht_mcs.tx_mcs_map &= |
| 269 | ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2); |
| 270 | vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2); |
| 271 | } |
| 272 | |
| 273 | /* finally set up the bandwidth */ |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 274 | switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { |
| 275 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: |
| 276 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: |
| 277 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160; |
| 278 | break; |
| 279 | default: |
| 280 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80; |
| 281 | } |
| 282 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 283 | sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta); |
Emmanuel Grumbach | 506bcfa | 2015-12-13 15:41:05 +0200 | [diff] [blame] | 284 | |
| 285 | /* If HT IE reported 3839 bytes only, stay with that size. */ |
| 286 | if (sta->sta.max_amsdu_len == IEEE80211_MAX_MPDU_LEN_HT_3839) |
| 287 | return; |
| 288 | |
| 289 | switch (vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) { |
| 290 | case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454: |
| 291 | sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454; |
| 292 | break; |
| 293 | case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991: |
| 294 | sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991; |
| 295 | break; |
| 296 | case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895: |
| 297 | default: |
| 298 | sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895; |
| 299 | break; |
| 300 | } |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 303 | enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta) |
| 304 | { |
| 305 | struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap; |
| 306 | u32 cap_width; |
| 307 | |
| 308 | if (!vht_cap->vht_supported) |
| 309 | return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ? |
| 310 | IEEE80211_STA_RX_BW_40 : |
| 311 | IEEE80211_STA_RX_BW_20; |
| 312 | |
| 313 | cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 314 | |
| 315 | if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ || |
| 316 | cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) |
| 317 | return IEEE80211_STA_RX_BW_160; |
| 318 | |
| 319 | return IEEE80211_STA_RX_BW_80; |
| 320 | } |
| 321 | |
| 322 | static enum ieee80211_sta_rx_bandwidth |
| 323 | ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width) |
| 324 | { |
| 325 | switch (width) { |
| 326 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 327 | case NL80211_CHAN_WIDTH_20: |
| 328 | return IEEE80211_STA_RX_BW_20; |
| 329 | case NL80211_CHAN_WIDTH_40: |
| 330 | return IEEE80211_STA_RX_BW_40; |
| 331 | case NL80211_CHAN_WIDTH_80: |
| 332 | return IEEE80211_STA_RX_BW_80; |
| 333 | case NL80211_CHAN_WIDTH_160: |
| 334 | case NL80211_CHAN_WIDTH_80P80: |
| 335 | return IEEE80211_STA_RX_BW_160; |
| 336 | default: |
| 337 | WARN_ON_ONCE(1); |
| 338 | return IEEE80211_STA_RX_BW_20; |
| 339 | } |
| 340 | } |
| 341 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 342 | enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta) |
| 343 | { |
| 344 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 345 | enum ieee80211_sta_rx_bandwidth bw; |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 346 | enum nl80211_chan_width bss_width = sdata->vif.bss_conf.chandef.width; |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 347 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 348 | bw = ieee80211_sta_cap_rx_bw(sta); |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 349 | bw = min(bw, sta->cur_max_bandwidth); |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 350 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 351 | /* do not cap the BW of TDLS WIDER_BW peers by the bss */ |
| 352 | if (!test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW)) |
| 353 | bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width)); |
| 354 | |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 355 | return bw; |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 356 | } |
Johannes Berg | 8921d04 | 2012-12-27 18:26:42 +0100 | [diff] [blame] | 357 | |
| 358 | void ieee80211_sta_set_rx_nss(struct sta_info *sta) |
| 359 | { |
| 360 | u8 ht_rx_nss = 0, vht_rx_nss = 0; |
| 361 | |
| 362 | /* if we received a notification already don't overwrite it */ |
| 363 | if (sta->sta.rx_nss) |
| 364 | return; |
| 365 | |
| 366 | if (sta->sta.ht_cap.ht_supported) { |
| 367 | if (sta->sta.ht_cap.mcs.rx_mask[0]) |
| 368 | ht_rx_nss++; |
| 369 | if (sta->sta.ht_cap.mcs.rx_mask[1]) |
| 370 | ht_rx_nss++; |
| 371 | if (sta->sta.ht_cap.mcs.rx_mask[2]) |
| 372 | ht_rx_nss++; |
| 373 | if (sta->sta.ht_cap.mcs.rx_mask[3]) |
| 374 | ht_rx_nss++; |
| 375 | /* FIXME: consider rx_highest? */ |
| 376 | } |
| 377 | |
| 378 | if (sta->sta.vht_cap.vht_supported) { |
| 379 | int i; |
| 380 | u16 rx_mcs_map; |
| 381 | |
| 382 | rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map); |
| 383 | |
| 384 | for (i = 7; i >= 0; i--) { |
| 385 | u8 mcs = (rx_mcs_map >> (2 * i)) & 3; |
| 386 | |
| 387 | if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) { |
| 388 | vht_rx_nss = i + 1; |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | /* FIXME: consider rx_highest? */ |
| 393 | } |
| 394 | |
| 395 | ht_rx_nss = max(ht_rx_nss, vht_rx_nss); |
| 396 | sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss); |
| 397 | } |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 398 | |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 399 | u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata, |
| 400 | struct sta_info *sta, u8 opmode, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 401 | enum ieee80211_band band) |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 402 | { |
| 403 | struct ieee80211_local *local = sdata->local; |
| 404 | struct ieee80211_supported_band *sband; |
| 405 | enum ieee80211_sta_rx_bandwidth new_bw; |
| 406 | u32 changed = 0; |
| 407 | u8 nss; |
| 408 | |
| 409 | sband = local->hw.wiphy->bands[band]; |
| 410 | |
| 411 | /* ignore - no support for BF yet */ |
| 412 | if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF) |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 413 | return 0; |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 414 | |
| 415 | nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; |
| 416 | nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 417 | nss += 1; |
| 418 | |
| 419 | if (sta->sta.rx_nss != nss) { |
| 420 | sta->sta.rx_nss = nss; |
| 421 | changed |= IEEE80211_RC_NSS_CHANGED; |
| 422 | } |
| 423 | |
| 424 | switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) { |
| 425 | case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ: |
| 426 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20; |
| 427 | break; |
| 428 | case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ: |
| 429 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40; |
| 430 | break; |
| 431 | case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ: |
| 432 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80; |
| 433 | break; |
| 434 | case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ: |
| 435 | sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160; |
| 436 | break; |
| 437 | } |
| 438 | |
| 439 | new_bw = ieee80211_sta_cur_vht_bw(sta); |
| 440 | if (new_bw != sta->sta.bandwidth) { |
| 441 | sta->sta.bandwidth = new_bw; |
Ilan Peer | 38745c7 | 2013-06-10 10:34:14 +0300 | [diff] [blame] | 442 | changed |= IEEE80211_RC_BW_CHANGED; |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 445 | return changed; |
| 446 | } |
| 447 | |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 448 | void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata, |
| 449 | struct ieee80211_mgmt *mgmt) |
| 450 | { |
| 451 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
| 452 | |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 453 | if (!sdata->vif.mu_mimo_owner) |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 454 | return; |
| 455 | |
| 456 | if (!memcmp(mgmt->u.action.u.vht_group_notif.position, |
| 457 | bss_conf->mu_group.position, WLAN_USER_POSITION_LEN) && |
| 458 | !memcmp(mgmt->u.action.u.vht_group_notif.membership, |
| 459 | bss_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN)) |
| 460 | return; |
| 461 | |
Sara Sharon | 0241fa1 | 2016-02-03 21:52:23 +0200 | [diff] [blame] | 462 | memcpy(bss_conf->mu_group.membership, |
| 463 | mgmt->u.action.u.vht_group_notif.membership, |
| 464 | WLAN_MEMBERSHIP_LEN); |
| 465 | memcpy(bss_conf->mu_group.position, |
| 466 | mgmt->u.action.u.vht_group_notif.position, |
| 467 | WLAN_USER_POSITION_LEN); |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 468 | |
| 469 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS); |
| 470 | } |
| 471 | |
Sara Sharon | 65554d0 | 2016-02-16 12:48:17 +0200 | [diff] [blame] | 472 | void ieee80211_update_mu_groups(struct ieee80211_vif *vif, |
| 473 | const u8 *membership, const u8 *position) |
| 474 | { |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 475 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Sara Sharon | 65554d0 | 2016-02-16 12:48:17 +0200 | [diff] [blame] | 476 | |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 477 | if (WARN_ON_ONCE(!vif->mu_mimo_owner)) |
Sara Sharon | 65554d0 | 2016-02-16 12:48:17 +0200 | [diff] [blame] | 478 | return; |
| 479 | |
| 480 | memcpy(bss_conf->mu_group.membership, membership, WLAN_MEMBERSHIP_LEN); |
| 481 | memcpy(bss_conf->mu_group.position, position, WLAN_USER_POSITION_LEN); |
| 482 | } |
| 483 | EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups); |
| 484 | |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 485 | void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata, |
| 486 | struct sta_info *sta, u8 opmode, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 487 | enum ieee80211_band band) |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 488 | { |
| 489 | struct ieee80211_local *local = sdata->local; |
| 490 | struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; |
| 491 | |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 492 | u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode, band); |
Marek Kwaczynski | b1bce14 | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 493 | |
| 494 | if (changed > 0) |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 495 | rate_control_rate_update(local, sband, sta, changed); |
| 496 | } |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 497 | |
| 498 | void ieee80211_get_vht_mask_from_cap(__le16 vht_cap, |
| 499 | u16 vht_mask[NL80211_VHT_NSS_MAX]) |
| 500 | { |
| 501 | int i; |
| 502 | u16 mask, cap = le16_to_cpu(vht_cap); |
| 503 | |
| 504 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 505 | mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 506 | switch (mask) { |
| 507 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 508 | vht_mask[i] = 0x00FF; |
| 509 | break; |
| 510 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 511 | vht_mask[i] = 0x01FF; |
| 512 | break; |
| 513 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 514 | vht_mask[i] = 0x03FF; |
| 515 | break; |
| 516 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 517 | default: |
| 518 | vht_mask[i] = 0; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | } |