blob: 006d82e4a39762794c8cba0f3e7621b5f5c15f8a [file] [log] [blame]
Mahesh Palivela818255e2012-10-10 11:33:04 +00001/*
2 * VHT handling
3 *
Sara Sharon23a1f8d2015-12-08 16:04:31 +02004 * Portions of this file
Sara Sharon65554d02016-02-16 12:48:17 +02005 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
Johannes Berge80d6422018-08-31 11:31:19 +03006 * Copyright (C) 2018 Intel Corporation
Sara Sharon23a1f8d2015-12-08 16:04:31 +02007 *
Mahesh Palivela818255e2012-10-10 11:33:04 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/ieee80211.h>
14#include <linux/export.h>
15#include <net/mac80211.h>
16#include "ieee80211_i.h"
Johannes Berg0af83d32012-12-27 18:55:36 +010017#include "rate.h"
Mahesh Palivela818255e2012-10-10 11:33:04 +000018
19
Johannes Bergdd5ecfe2013-02-21 17:40:19 +010020static void __check_vhtcap_disable(struct ieee80211_sub_if_data *sdata,
21 struct ieee80211_sta_vht_cap *vht_cap,
22 u32 flag)
23{
24 __le32 le_flag = cpu_to_le32(flag);
25
26 if (sdata->u.mgd.vht_capa_mask.vht_cap_info & le_flag &&
27 !(sdata->u.mgd.vht_capa.vht_cap_info & le_flag))
28 vht_cap->cap &= ~flag;
29}
30
31void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data *sdata,
32 struct ieee80211_sta_vht_cap *vht_cap)
33{
34 int i;
35 u16 rxmcs_mask, rxmcs_cap, rxmcs_n, txmcs_mask, txmcs_cap, txmcs_n;
36
37 if (!vht_cap->vht_supported)
38 return;
39
40 if (sdata->vif.type != NL80211_IFTYPE_STATION)
41 return;
42
43 __check_vhtcap_disable(sdata, vht_cap,
44 IEEE80211_VHT_CAP_RXLDPC);
45 __check_vhtcap_disable(sdata, vht_cap,
46 IEEE80211_VHT_CAP_SHORT_GI_80);
47 __check_vhtcap_disable(sdata, vht_cap,
48 IEEE80211_VHT_CAP_SHORT_GI_160);
49 __check_vhtcap_disable(sdata, vht_cap,
50 IEEE80211_VHT_CAP_TXSTBC);
51 __check_vhtcap_disable(sdata, vht_cap,
52 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
53 __check_vhtcap_disable(sdata, vht_cap,
54 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
55 __check_vhtcap_disable(sdata, vht_cap,
56 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN);
57 __check_vhtcap_disable(sdata, vht_cap,
58 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN);
59
60 /* Allow user to decrease AMPDU length exponent */
61 if (sdata->u.mgd.vht_capa_mask.vht_cap_info &
62 cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK)) {
63 u32 cap, n;
64
65 n = le32_to_cpu(sdata->u.mgd.vht_capa.vht_cap_info) &
66 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
67 n >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
68 cap = vht_cap->cap & IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
69 cap >>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
70
71 if (n < cap) {
72 vht_cap->cap &=
73 ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
74 vht_cap->cap |=
75 n << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
76 }
77 }
78
79 /* Allow the user to decrease MCSes */
80 rxmcs_mask =
81 le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.rx_mcs_map);
82 rxmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.rx_mcs_map);
83 rxmcs_n &= rxmcs_mask;
84 rxmcs_cap = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
85
86 txmcs_mask =
87 le16_to_cpu(sdata->u.mgd.vht_capa_mask.supp_mcs.tx_mcs_map);
88 txmcs_n = le16_to_cpu(sdata->u.mgd.vht_capa.supp_mcs.tx_mcs_map);
89 txmcs_n &= txmcs_mask;
90 txmcs_cap = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
91 for (i = 0; i < 8; i++) {
92 u8 m, n, c;
93
94 m = (rxmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
95 n = (rxmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
96 c = (rxmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
97
98 if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
99 n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
100 rxmcs_cap &= ~(3 << 2*i);
101 rxmcs_cap |= (rxmcs_n & (3 << 2*i));
102 }
103
104 m = (txmcs_mask >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
105 n = (txmcs_n >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
106 c = (txmcs_cap >> 2*i) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
107
108 if (m && ((c != IEEE80211_VHT_MCS_NOT_SUPPORTED && n < c) ||
109 n == IEEE80211_VHT_MCS_NOT_SUPPORTED)) {
110 txmcs_cap &= ~(3 << 2*i);
111 txmcs_cap |= (txmcs_n & (3 << 2*i));
112 }
113 }
114 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_cap);
115 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_cap);
116}
117
Johannes Berg4a3cb702013-02-12 16:43:19 +0100118void
119ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data *sdata,
120 struct ieee80211_supported_band *sband,
121 const struct ieee80211_vht_cap *vht_cap_ie,
122 struct sta_info *sta)
Mahesh Palivela818255e2012-10-10 11:33:04 +0000123{
Johannes Berg4a342152013-02-07 11:58:58 +0100124 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
Johannes Berg55d942f2013-03-01 13:07:48 +0100125 struct ieee80211_sta_vht_cap own_cap;
126 u32 cap_info, i;
Arik Nemtsov52a45f32015-08-15 22:39:53 +0300127 bool have_80mhz;
Mahesh Palivela818255e2012-10-10 11:33:04 +0000128
129 memset(vht_cap, 0, sizeof(*vht_cap));
130
Johannes Berg4a342152013-02-07 11:58:58 +0100131 if (!sta->sta.ht_cap.ht_supported)
132 return;
133
Mahesh Palivela818255e2012-10-10 11:33:04 +0000134 if (!vht_cap_ie || !sband->vht_cap.vht_supported)
135 return;
136
Arik Nemtsov52a45f32015-08-15 22:39:53 +0300137 /* Allow VHT if at least one channel on the sband supports 80 MHz */
138 have_80mhz = false;
139 for (i = 0; i < sband->n_channels; i++) {
140 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
141 IEEE80211_CHAN_NO_80MHZ))
142 continue;
143
144 have_80mhz = true;
145 break;
146 }
147
148 if (!have_80mhz)
149 return;
150
Johannes Berg4a817aa2014-05-09 09:56:53 +0200151 /*
152 * A VHT STA must support 40 MHz, but if we verify that here
153 * then we break a few things - some APs (e.g. Netgear R6300v2
154 * and others based on the BCM4360 chipset) will unset this
155 * capability bit when operating in 20 MHz.
156 */
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100157
Mahesh Palivela818255e2012-10-10 11:33:04 +0000158 vht_cap->vht_supported = true;
159
Johannes Berg55d942f2013-03-01 13:07:48 +0100160 own_cap = sband->vht_cap;
161 /*
162 * If user has specified capability overrides, take care
163 * of that if the station we're setting up is the AP that
164 * we advertised a restricted capability set to. Override
165 * our own capabilities and then use those below.
166 */
167 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
168 !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
169 ieee80211_apply_vhtcap_overrides(sdata, &own_cap);
170
171 /* take some capabilities as-is */
172 cap_info = le32_to_cpu(vht_cap_ie->vht_cap_info);
173 vht_cap->cap = cap_info;
174 vht_cap->cap &= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
175 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
176 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
177 IEEE80211_VHT_CAP_RXLDPC |
178 IEEE80211_VHT_CAP_VHT_TXOP_PS |
179 IEEE80211_VHT_CAP_HTC_VHT |
180 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
181 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB |
182 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB |
183 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
184 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
185
186 /* and some based on our own capabilities */
187 switch (own_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
188 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
189 vht_cap->cap |= cap_info &
190 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
191 break;
192 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
193 vht_cap->cap |= cap_info &
194 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
195 break;
196 default:
197 /* nothing */
198 break;
199 }
200
201 /* symmetric capabilities */
202 vht_cap->cap |= cap_info & own_cap.cap &
203 (IEEE80211_VHT_CAP_SHORT_GI_80 |
204 IEEE80211_VHT_CAP_SHORT_GI_160);
205
206 /* remaining ones */
Eyal Shapirafbdd90e2013-11-11 20:14:00 +0200207 if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
Johannes Berg55d942f2013-03-01 13:07:48 +0100208 vht_cap->cap |= cap_info &
209 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
Eyal Shapirafbdd90e2013-11-11 20:14:00 +0200210 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
Johannes Berg55d942f2013-03-01 13:07:48 +0100211
212 if (own_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
213 vht_cap->cap |= cap_info &
Eliad Peller5eb79062013-08-29 15:03:14 +0300214 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
Eyal Shapirafbdd90e2013-11-11 20:14:00 +0200215 IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
Johannes Berg55d942f2013-03-01 13:07:48 +0100216
217 if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
218 vht_cap->cap |= cap_info &
219 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
220
221 if (own_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
222 vht_cap->cap |= cap_info &
223 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
224
225 if (own_cap.cap & IEEE80211_VHT_CAP_TXSTBC)
226 vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_RXSTBC_MASK;
227
228 if (own_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK)
229 vht_cap->cap |= cap_info & IEEE80211_VHT_CAP_TXSTBC;
Mahesh Palivela818255e2012-10-10 11:33:04 +0000230
231 /* Copy peer MCS info, the driver might need them. */
232 memcpy(&vht_cap->vht_mcs, &vht_cap_ie->supp_mcs,
233 sizeof(struct ieee80211_vht_mcs_info));
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100234
Johannes Berge80d6422018-08-31 11:31:19 +0300235 /* copy EXT_NSS_BW Support value or remove the capability */
236 if (ieee80211_hw_check(&sdata->local->hw, SUPPORTS_VHT_EXT_NSS_BW))
237 vht_cap->cap |= (cap_info & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
238 else
239 vht_cap->vht_mcs.tx_highest &=
240 ~cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
241
Johannes Berg55d942f2013-03-01 13:07:48 +0100242 /* but also restrict MCSes */
243 for (i = 0; i < 8; i++) {
244 u16 own_rx, own_tx, peer_rx, peer_tx;
245
246 own_rx = le16_to_cpu(own_cap.vht_mcs.rx_mcs_map);
247 own_rx = (own_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
248
249 own_tx = le16_to_cpu(own_cap.vht_mcs.tx_mcs_map);
250 own_tx = (own_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
251
252 peer_rx = le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
253 peer_rx = (peer_rx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
254
255 peer_tx = le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
256 peer_tx = (peer_tx >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
257
258 if (peer_tx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
259 if (own_rx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
260 peer_tx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
261 else if (own_rx < peer_tx)
262 peer_tx = own_rx;
263 }
264
265 if (peer_rx != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
266 if (own_tx == IEEE80211_VHT_MCS_NOT_SUPPORTED)
267 peer_rx = IEEE80211_VHT_MCS_NOT_SUPPORTED;
268 else if (own_tx < peer_rx)
269 peer_rx = own_tx;
270 }
271
272 vht_cap->vht_mcs.rx_mcs_map &=
273 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
274 vht_cap->vht_mcs.rx_mcs_map |= cpu_to_le16(peer_rx << i * 2);
275
276 vht_cap->vht_mcs.tx_mcs_map &=
277 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << i * 2);
278 vht_cap->vht_mcs.tx_mcs_map |= cpu_to_le16(peer_tx << i * 2);
279 }
280
Filip Matusiakc8eaf342016-11-02 10:04:26 +0100281 /*
282 * This is a workaround for VHT-enabled STAs which break the spec
283 * and have the VHT-MCS Rx map filled in with value 3 for all eight
284 * spacial streams, an example is AR9462.
285 *
286 * As per spec, in section 22.1.1 Introduction to the VHT PHY
287 * A VHT STA shall support at least single spactial stream VHT-MCSs
288 * 0 to 7 (transmit and receive) in all supported channel widths.
289 */
290 if (vht_cap->vht_mcs.rx_mcs_map == cpu_to_le16(0xFFFF)) {
291 vht_cap->vht_supported = false;
292 sdata_info(sdata, "Ignoring VHT IE from %pM due to invalid rx_mcs_map\n",
293 sta->addr);
294 return;
295 }
296
Johannes Berg55d942f2013-03-01 13:07:48 +0100297 /* finally set up the bandwidth */
Johannes Berg0af83d32012-12-27 18:55:36 +0100298 switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
299 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
300 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
301 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
302 break;
303 default:
304 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
Johannes Berge80d6422018-08-31 11:31:19 +0300305
306 if (!(vht_cap->vht_mcs.tx_highest &
307 cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE)))
308 break;
309
310 /*
311 * If this is non-zero, then it does support 160 MHz after all,
312 * in one form or the other. We don't distinguish here (or even
313 * above) between 160 and 80+80 yet.
314 */
315 if (cap_info & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK)
316 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
Johannes Berg0af83d32012-12-27 18:55:36 +0100317 }
318
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100319 sta->sta.bandwidth = ieee80211_sta_cur_vht_bw(sta);
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +0200320
321 /* If HT IE reported 3839 bytes only, stay with that size. */
322 if (sta->sta.max_amsdu_len == IEEE80211_MAX_MPDU_LEN_HT_3839)
323 return;
324
325 switch (vht_cap->cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
326 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
327 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
328 break;
329 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
330 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
331 break;
332 case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
333 default:
334 sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
335 break;
336 }
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100337}
338
Eliad Peller1c45c5c2014-12-14 11:05:51 +0200339enum ieee80211_sta_rx_bandwidth ieee80211_sta_cap_rx_bw(struct sta_info *sta)
340{
341 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
342 u32 cap_width;
343
344 if (!vht_cap->vht_supported)
345 return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
346 IEEE80211_STA_RX_BW_40 :
347 IEEE80211_STA_RX_BW_20;
348
349 cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
350
351 if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
352 cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
353 return IEEE80211_STA_RX_BW_160;
354
355 return IEEE80211_STA_RX_BW_80;
356}
357
Arik Nemtsov59021c62016-03-02 23:28:32 +0200358enum nl80211_chan_width ieee80211_sta_cap_chan_bw(struct sta_info *sta)
359{
360 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
361 u32 cap_width;
362
363 if (!vht_cap->vht_supported) {
364 if (!sta->sta.ht_cap.ht_supported)
365 return NL80211_CHAN_WIDTH_20_NOHT;
366
367 return sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
368 NL80211_CHAN_WIDTH_40 : NL80211_CHAN_WIDTH_20;
369 }
370
371 cap_width = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
372
373 if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
374 return NL80211_CHAN_WIDTH_160;
375 else if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
376 return NL80211_CHAN_WIDTH_80P80;
377
378 return NL80211_CHAN_WIDTH_80;
379}
380
tamizhr@codeaurora.org97f5f422018-03-27 19:16:17 +0530381enum nl80211_chan_width
382ieee80211_sta_rx_bw_to_chan_width(struct sta_info *sta)
383{
384 enum ieee80211_sta_rx_bandwidth cur_bw = sta->sta.bandwidth;
385 struct ieee80211_sta_vht_cap *vht_cap = &sta->sta.vht_cap;
386 u32 cap_width;
387
388 switch (cur_bw) {
389 case IEEE80211_STA_RX_BW_20:
390 if (!sta->sta.ht_cap.ht_supported)
391 return NL80211_CHAN_WIDTH_20_NOHT;
392 else
393 return NL80211_CHAN_WIDTH_20;
394 case IEEE80211_STA_RX_BW_40:
395 return NL80211_CHAN_WIDTH_40;
396 case IEEE80211_STA_RX_BW_80:
397 return NL80211_CHAN_WIDTH_80;
398 case IEEE80211_STA_RX_BW_160:
399 cap_width =
400 vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
401
402 if (cap_width == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)
403 return NL80211_CHAN_WIDTH_160;
404
405 return NL80211_CHAN_WIDTH_80P80;
406 default:
407 return NL80211_CHAN_WIDTH_20;
408 }
409}
410
Arik Nemtsov59021c62016-03-02 23:28:32 +0200411enum ieee80211_sta_rx_bandwidth
Eliad Peller1c45c5c2014-12-14 11:05:51 +0200412ieee80211_chan_width_to_rx_bw(enum nl80211_chan_width width)
413{
414 switch (width) {
415 case NL80211_CHAN_WIDTH_20_NOHT:
416 case NL80211_CHAN_WIDTH_20:
417 return IEEE80211_STA_RX_BW_20;
418 case NL80211_CHAN_WIDTH_40:
419 return IEEE80211_STA_RX_BW_40;
420 case NL80211_CHAN_WIDTH_80:
421 return IEEE80211_STA_RX_BW_80;
422 case NL80211_CHAN_WIDTH_160:
423 case NL80211_CHAN_WIDTH_80P80:
424 return IEEE80211_STA_RX_BW_160;
425 default:
426 WARN_ON_ONCE(1);
427 return IEEE80211_STA_RX_BW_20;
428 }
429}
430
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100431enum ieee80211_sta_rx_bandwidth ieee80211_sta_cur_vht_bw(struct sta_info *sta)
432{
433 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg0af83d32012-12-27 18:55:36 +0100434 enum ieee80211_sta_rx_bandwidth bw;
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300435 enum nl80211_chan_width bss_width = sdata->vif.bss_conf.chandef.width;
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100436
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300437 bw = ieee80211_sta_cap_rx_bw(sta);
Eliad Peller1c45c5c2014-12-14 11:05:51 +0200438 bw = min(bw, sta->cur_max_bandwidth);
Manikanta Pubbisetty504871e2017-09-26 00:39:15 +0530439
440 /* Don't consider AP's bandwidth for TDLS peers, section 11.23.1 of
441 * IEEE80211-2016 specification makes higher bandwidth operation
442 * possible on the TDLS link if the peers have wider bandwidth
443 * capability.
444 */
445 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
446 test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW))
447 return bw;
448
Arik Nemtsov59021c62016-03-02 23:28:32 +0200449 bw = min(bw, ieee80211_chan_width_to_rx_bw(bss_width));
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300450
Johannes Berg0af83d32012-12-27 18:55:36 +0100451 return bw;
Mahesh Palivela818255e2012-10-10 11:33:04 +0000452}
Johannes Berg8921d042012-12-27 18:26:42 +0100453
454void ieee80211_sta_set_rx_nss(struct sta_info *sta)
455{
456 u8 ht_rx_nss = 0, vht_rx_nss = 0;
457
458 /* if we received a notification already don't overwrite it */
459 if (sta->sta.rx_nss)
460 return;
461
462 if (sta->sta.ht_cap.ht_supported) {
463 if (sta->sta.ht_cap.mcs.rx_mask[0])
464 ht_rx_nss++;
465 if (sta->sta.ht_cap.mcs.rx_mask[1])
466 ht_rx_nss++;
467 if (sta->sta.ht_cap.mcs.rx_mask[2])
468 ht_rx_nss++;
469 if (sta->sta.ht_cap.mcs.rx_mask[3])
470 ht_rx_nss++;
471 /* FIXME: consider rx_highest? */
472 }
473
474 if (sta->sta.vht_cap.vht_supported) {
475 int i;
476 u16 rx_mcs_map;
477
478 rx_mcs_map = le16_to_cpu(sta->sta.vht_cap.vht_mcs.rx_mcs_map);
479
480 for (i = 7; i >= 0; i--) {
481 u8 mcs = (rx_mcs_map >> (2 * i)) & 3;
482
483 if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
484 vht_rx_nss = i + 1;
485 break;
486 }
487 }
488 /* FIXME: consider rx_highest? */
489 }
490
491 ht_rx_nss = max(ht_rx_nss, vht_rx_nss);
492 sta->sta.rx_nss = max_t(u8, 1, ht_rx_nss);
493}
Johannes Berg0af83d32012-12-27 18:55:36 +0100494
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100495u32 __ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
496 struct sta_info *sta, u8 opmode,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200497 enum nl80211_band band)
Johannes Berg0af83d32012-12-27 18:55:36 +0100498{
Johannes Berg0af83d32012-12-27 18:55:36 +0100499 enum ieee80211_sta_rx_bandwidth new_bw;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +0530500 struct sta_opmode_info sta_opmode = {};
Johannes Berg0af83d32012-12-27 18:55:36 +0100501 u32 changed = 0;
502 u8 nss;
503
Johannes Berg0af83d32012-12-27 18:55:36 +0100504 /* ignore - no support for BF yet */
505 if (opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100506 return 0;
Johannes Berg0af83d32012-12-27 18:55:36 +0100507
508 nss = opmode & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
509 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
510 nss += 1;
511
512 if (sta->sta.rx_nss != nss) {
513 sta->sta.rx_nss = nss;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +0530514 sta_opmode.rx_nss = nss;
Johannes Berg0af83d32012-12-27 18:55:36 +0100515 changed |= IEEE80211_RC_NSS_CHANGED;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +0530516 sta_opmode.changed |= STA_OPMODE_N_SS_CHANGED;
Johannes Berg0af83d32012-12-27 18:55:36 +0100517 }
518
519 switch (opmode & IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK) {
520 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ:
521 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_20;
522 break;
523 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ:
524 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_40;
525 break;
526 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ:
527 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_80;
528 break;
529 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ:
530 sta->cur_max_bandwidth = IEEE80211_STA_RX_BW_160;
531 break;
532 }
533
534 new_bw = ieee80211_sta_cur_vht_bw(sta);
535 if (new_bw != sta->sta.bandwidth) {
536 sta->sta.bandwidth = new_bw;
tamizhr@codeaurora.org97f5f422018-03-27 19:16:17 +0530537 sta_opmode.bw = ieee80211_sta_rx_bw_to_chan_width(sta);
Ilan Peer38745c72013-06-10 10:34:14 +0300538 changed |= IEEE80211_RC_BW_CHANGED;
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +0530539 sta_opmode.changed |= STA_OPMODE_MAX_BW_CHANGED;
Johannes Berg0af83d32012-12-27 18:55:36 +0100540 }
541
tamizhr@codeaurora.orgff84e7b2018-01-31 16:24:50 +0530542 if (sta_opmode.changed)
543 cfg80211_sta_opmode_change_notify(sdata->dev, sta->addr,
544 &sta_opmode, GFP_KERNEL);
545
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100546 return changed;
547}
548
Sara Sharon23a1f8d2015-12-08 16:04:31 +0200549void ieee80211_process_mu_groups(struct ieee80211_sub_if_data *sdata,
550 struct ieee80211_mgmt *mgmt)
551{
552 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
553
Sara Sharonb5a33d52016-02-16 12:48:18 +0200554 if (!sdata->vif.mu_mimo_owner)
Sara Sharon23a1f8d2015-12-08 16:04:31 +0200555 return;
556
557 if (!memcmp(mgmt->u.action.u.vht_group_notif.position,
558 bss_conf->mu_group.position, WLAN_USER_POSITION_LEN) &&
559 !memcmp(mgmt->u.action.u.vht_group_notif.membership,
560 bss_conf->mu_group.membership, WLAN_MEMBERSHIP_LEN))
561 return;
562
Sara Sharon0241fa12016-02-03 21:52:23 +0200563 memcpy(bss_conf->mu_group.membership,
564 mgmt->u.action.u.vht_group_notif.membership,
565 WLAN_MEMBERSHIP_LEN);
566 memcpy(bss_conf->mu_group.position,
567 mgmt->u.action.u.vht_group_notif.position,
568 WLAN_USER_POSITION_LEN);
Sara Sharon23a1f8d2015-12-08 16:04:31 +0200569
570 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
571}
572
Sara Sharon65554d02016-02-16 12:48:17 +0200573void ieee80211_update_mu_groups(struct ieee80211_vif *vif,
574 const u8 *membership, const u8 *position)
575{
Sara Sharonb5a33d52016-02-16 12:48:18 +0200576 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Sara Sharon65554d02016-02-16 12:48:17 +0200577
Sara Sharonb5a33d52016-02-16 12:48:18 +0200578 if (WARN_ON_ONCE(!vif->mu_mimo_owner))
Sara Sharon65554d02016-02-16 12:48:17 +0200579 return;
580
581 memcpy(bss_conf->mu_group.membership, membership, WLAN_MEMBERSHIP_LEN);
582 memcpy(bss_conf->mu_group.position, position, WLAN_USER_POSITION_LEN);
583}
584EXPORT_SYMBOL_GPL(ieee80211_update_mu_groups);
585
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100586void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data *sdata,
587 struct sta_info *sta, u8 opmode,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200588 enum nl80211_band band)
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100589{
590 struct ieee80211_local *local = sdata->local;
591 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
592
Eyal Shapiracf1e05c2015-12-08 16:04:36 +0200593 u32 changed = __ieee80211_vht_handle_opmode(sdata, sta, opmode, band);
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +0100594
Johannes Bergd2941df2016-10-20 08:52:50 +0200595 if (changed > 0) {
596 ieee80211_recalc_min_chandef(sdata);
Johannes Berg0af83d32012-12-27 18:55:36 +0100597 rate_control_rate_update(local, sband, sta, changed);
Johannes Bergd2941df2016-10-20 08:52:50 +0200598 }
Johannes Berg0af83d32012-12-27 18:55:36 +0100599}
Lorenzo Bianconib119ad62015-08-06 23:47:33 +0200600
601void ieee80211_get_vht_mask_from_cap(__le16 vht_cap,
602 u16 vht_mask[NL80211_VHT_NSS_MAX])
603{
604 int i;
605 u16 mask, cap = le16_to_cpu(vht_cap);
606
607 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
608 mask = (cap >> i * 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED;
609 switch (mask) {
610 case IEEE80211_VHT_MCS_SUPPORT_0_7:
611 vht_mask[i] = 0x00FF;
612 break;
613 case IEEE80211_VHT_MCS_SUPPORT_0_8:
614 vht_mask[i] = 0x01FF;
615 break;
616 case IEEE80211_VHT_MCS_SUPPORT_0_9:
617 vht_mask[i] = 0x03FF;
618 break;
619 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
620 default:
621 vht_mask[i] = 0;
622 break;
623 }
624 }
625}