4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/ieee80211.h>
10 #include <linux/export.h>
11 #include <net/mac80211.h>
12 #include "ieee80211_i.h"
16 static void __check_vhtcap_disable(struct ieee80211_sub_if_data
*sdata
,
17 struct ieee80211_sta_vht_cap
*vht_cap
,
20 __le32 le_flag
= cpu_to_le32(flag
);
22 if (sdata
->u
.mgd
.vht_capa_mask
.vht_cap_info
& le_flag
&&
23 !(sdata
->u
.mgd
.vht_capa
.vht_cap_info
& le_flag
))
24 vht_cap
->cap
&= ~flag
;
27 void ieee80211_apply_vhtcap_overrides(struct ieee80211_sub_if_data
*sdata
,
28 struct ieee80211_sta_vht_cap
*vht_cap
)
31 u16 rxmcs_mask
, rxmcs_cap
, rxmcs_n
, txmcs_mask
, txmcs_cap
, txmcs_n
;
33 if (!vht_cap
->vht_supported
)
36 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
39 __check_vhtcap_disable(sdata
, vht_cap
,
40 IEEE80211_VHT_CAP_RXLDPC
);
41 __check_vhtcap_disable(sdata
, vht_cap
,
42 IEEE80211_VHT_CAP_SHORT_GI_80
);
43 __check_vhtcap_disable(sdata
, vht_cap
,
44 IEEE80211_VHT_CAP_SHORT_GI_160
);
45 __check_vhtcap_disable(sdata
, vht_cap
,
46 IEEE80211_VHT_CAP_TXSTBC
);
47 __check_vhtcap_disable(sdata
, vht_cap
,
48 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
);
49 __check_vhtcap_disable(sdata
, vht_cap
,
50 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
);
51 __check_vhtcap_disable(sdata
, vht_cap
,
52 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
);
53 __check_vhtcap_disable(sdata
, vht_cap
,
54 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
);
56 /* Allow user to decrease AMPDU length exponent */
57 if (sdata
->u
.mgd
.vht_capa_mask
.vht_cap_info
&
58 cpu_to_le32(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
)) {
61 n
= le32_to_cpu(sdata
->u
.mgd
.vht_capa
.vht_cap_info
) &
62 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
63 n
>>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
64 cap
= vht_cap
->cap
& IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
65 cap
>>= IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
69 ~IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
71 n
<< IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
75 /* Allow the user to decrease MCSes */
77 le16_to_cpu(sdata
->u
.mgd
.vht_capa_mask
.supp_mcs
.rx_mcs_map
);
78 rxmcs_n
= le16_to_cpu(sdata
->u
.mgd
.vht_capa
.supp_mcs
.rx_mcs_map
);
79 rxmcs_n
&= rxmcs_mask
;
80 rxmcs_cap
= le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
83 le16_to_cpu(sdata
->u
.mgd
.vht_capa_mask
.supp_mcs
.tx_mcs_map
);
84 txmcs_n
= le16_to_cpu(sdata
->u
.mgd
.vht_capa
.supp_mcs
.tx_mcs_map
);
85 txmcs_n
&= txmcs_mask
;
86 txmcs_cap
= le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
87 for (i
= 0; i
< 8; i
++) {
90 m
= (rxmcs_mask
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
91 n
= (rxmcs_n
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
92 c
= (rxmcs_cap
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
94 if (m
&& ((c
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
&& n
< c
) ||
95 n
== IEEE80211_VHT_MCS_NOT_SUPPORTED
)) {
96 rxmcs_cap
&= ~(3 << 2*i
);
97 rxmcs_cap
|= (rxmcs_n
& (3 << 2*i
));
100 m
= (txmcs_mask
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
101 n
= (txmcs_n
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
102 c
= (txmcs_cap
>> 2*i
) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
104 if (m
&& ((c
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
&& n
< c
) ||
105 n
== IEEE80211_VHT_MCS_NOT_SUPPORTED
)) {
106 txmcs_cap
&= ~(3 << 2*i
);
107 txmcs_cap
|= (txmcs_n
& (3 << 2*i
));
110 vht_cap
->vht_mcs
.rx_mcs_map
= cpu_to_le16(rxmcs_cap
);
111 vht_cap
->vht_mcs
.tx_mcs_map
= cpu_to_le16(txmcs_cap
);
115 ieee80211_vht_cap_ie_to_sta_vht_cap(struct ieee80211_sub_if_data
*sdata
,
116 struct ieee80211_supported_band
*sband
,
117 const struct ieee80211_vht_cap
*vht_cap_ie
,
118 struct sta_info
*sta
)
120 struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->sta
.vht_cap
;
121 struct ieee80211_sta_vht_cap own_cap
;
124 memset(vht_cap
, 0, sizeof(*vht_cap
));
126 if (!sta
->sta
.ht_cap
.ht_supported
)
129 if (!vht_cap_ie
|| !sband
->vht_cap
.vht_supported
)
132 /* A VHT STA must support 40 MHz */
133 if (!(sta
->sta
.ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
136 vht_cap
->vht_supported
= true;
138 own_cap
= sband
->vht_cap
;
140 * If user has specified capability overrides, take care
141 * of that if the station we're setting up is the AP that
142 * we advertised a restricted capability set to. Override
143 * our own capabilities and then use those below.
145 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
146 !test_sta_flag(sta
, WLAN_STA_TDLS_PEER
))
147 ieee80211_apply_vhtcap_overrides(sdata
, &own_cap
);
149 /* take some capabilities as-is */
150 cap_info
= le32_to_cpu(vht_cap_ie
->vht_cap_info
);
151 vht_cap
->cap
= cap_info
;
152 vht_cap
->cap
&= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895
|
153 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991
|
154 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
155 IEEE80211_VHT_CAP_RXLDPC
|
156 IEEE80211_VHT_CAP_VHT_TXOP_PS
|
157 IEEE80211_VHT_CAP_HTC_VHT
|
158 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
|
159 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB
|
160 IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB
|
161 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN
|
162 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN
;
164 /* and some based on our own capabilities */
165 switch (own_cap
.cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) {
166 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
:
167 vht_cap
->cap
|= cap_info
&
168 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
170 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
:
171 vht_cap
->cap
|= cap_info
&
172 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
179 /* symmetric capabilities */
180 vht_cap
->cap
|= cap_info
& own_cap
.cap
&
181 (IEEE80211_VHT_CAP_SHORT_GI_80
|
182 IEEE80211_VHT_CAP_SHORT_GI_160
);
185 if (own_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
)
186 vht_cap
->cap
|= cap_info
&
187 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
|
188 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK
);
190 if (own_cap
.cap
& IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)
191 vht_cap
->cap
|= cap_info
&
192 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
193 IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
);
195 if (own_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)
196 vht_cap
->cap
|= cap_info
&
197 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
199 if (own_cap
.cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
)
200 vht_cap
->cap
|= cap_info
&
201 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
;
203 if (own_cap
.cap
& IEEE80211_VHT_CAP_TXSTBC
)
204 vht_cap
->cap
|= cap_info
& IEEE80211_VHT_CAP_RXSTBC_MASK
;
206 if (own_cap
.cap
& IEEE80211_VHT_CAP_RXSTBC_MASK
)
207 vht_cap
->cap
|= cap_info
& IEEE80211_VHT_CAP_TXSTBC
;
209 /* Copy peer MCS info, the driver might need them. */
210 memcpy(&vht_cap
->vht_mcs
, &vht_cap_ie
->supp_mcs
,
211 sizeof(struct ieee80211_vht_mcs_info
));
213 /* but also restrict MCSes */
214 for (i
= 0; i
< 8; i
++) {
215 u16 own_rx
, own_tx
, peer_rx
, peer_tx
;
217 own_rx
= le16_to_cpu(own_cap
.vht_mcs
.rx_mcs_map
);
218 own_rx
= (own_rx
>> i
* 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
220 own_tx
= le16_to_cpu(own_cap
.vht_mcs
.tx_mcs_map
);
221 own_tx
= (own_tx
>> i
* 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
223 peer_rx
= le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
224 peer_rx
= (peer_rx
>> i
* 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
226 peer_tx
= le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
227 peer_tx
= (peer_tx
>> i
* 2) & IEEE80211_VHT_MCS_NOT_SUPPORTED
;
229 if (peer_tx
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) {
230 if (own_rx
== IEEE80211_VHT_MCS_NOT_SUPPORTED
)
231 peer_tx
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
232 else if (own_rx
< peer_tx
)
236 if (peer_rx
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) {
237 if (own_tx
== IEEE80211_VHT_MCS_NOT_SUPPORTED
)
238 peer_rx
= IEEE80211_VHT_MCS_NOT_SUPPORTED
;
239 else if (own_tx
< peer_rx
)
243 vht_cap
->vht_mcs
.rx_mcs_map
&=
244 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED
<< i
* 2);
245 vht_cap
->vht_mcs
.rx_mcs_map
|= cpu_to_le16(peer_rx
<< i
* 2);
247 vht_cap
->vht_mcs
.tx_mcs_map
&=
248 ~cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED
<< i
* 2);
249 vht_cap
->vht_mcs
.tx_mcs_map
|= cpu_to_le16(peer_tx
<< i
* 2);
252 /* finally set up the bandwidth */
253 switch (vht_cap
->cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) {
254 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
:
255 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
:
256 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_160
;
259 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_80
;
262 sta
->sta
.bandwidth
= ieee80211_sta_cur_vht_bw(sta
);
265 enum ieee80211_sta_rx_bandwidth
ieee80211_sta_cur_vht_bw(struct sta_info
*sta
)
267 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
268 u32 cap
= sta
->sta
.vht_cap
.cap
;
269 enum ieee80211_sta_rx_bandwidth bw
;
271 if (!sta
->sta
.vht_cap
.vht_supported
) {
272 bw
= sta
->sta
.ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
?
273 IEEE80211_STA_RX_BW_40
: IEEE80211_STA_RX_BW_20
;
277 switch (sdata
->vif
.bss_conf
.chandef
.width
) {
281 case NL80211_CHAN_WIDTH_20_NOHT
:
282 case NL80211_CHAN_WIDTH_20
:
283 case NL80211_CHAN_WIDTH_40
:
284 bw
= sta
->sta
.ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
?
285 IEEE80211_STA_RX_BW_40
: IEEE80211_STA_RX_BW_20
;
287 case NL80211_CHAN_WIDTH_160
:
288 if ((cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) ==
289 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
) {
290 bw
= IEEE80211_STA_RX_BW_160
;
294 case NL80211_CHAN_WIDTH_80P80
:
295 if ((cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
) ==
296 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
) {
297 bw
= IEEE80211_STA_RX_BW_160
;
301 case NL80211_CHAN_WIDTH_80
:
302 bw
= IEEE80211_STA_RX_BW_80
;
306 if (bw
> sta
->cur_max_bandwidth
)
307 bw
= sta
->cur_max_bandwidth
;
311 void ieee80211_sta_set_rx_nss(struct sta_info
*sta
)
313 u8 ht_rx_nss
= 0, vht_rx_nss
= 0;
315 /* if we received a notification already don't overwrite it */
319 if (sta
->sta
.ht_cap
.ht_supported
) {
320 if (sta
->sta
.ht_cap
.mcs
.rx_mask
[0])
322 if (sta
->sta
.ht_cap
.mcs
.rx_mask
[1])
324 if (sta
->sta
.ht_cap
.mcs
.rx_mask
[2])
326 if (sta
->sta
.ht_cap
.mcs
.rx_mask
[3])
328 /* FIXME: consider rx_highest? */
331 if (sta
->sta
.vht_cap
.vht_supported
) {
335 rx_mcs_map
= le16_to_cpu(sta
->sta
.vht_cap
.vht_mcs
.rx_mcs_map
);
337 for (i
= 7; i
>= 0; i
--) {
338 u8 mcs
= (rx_mcs_map
>> (2 * i
)) & 3;
340 if (mcs
!= IEEE80211_VHT_MCS_NOT_SUPPORTED
) {
345 /* FIXME: consider rx_highest? */
348 ht_rx_nss
= max(ht_rx_nss
, vht_rx_nss
);
349 sta
->sta
.rx_nss
= max_t(u8
, 1, ht_rx_nss
);
352 void ieee80211_vht_handle_opmode(struct ieee80211_sub_if_data
*sdata
,
353 struct sta_info
*sta
, u8 opmode
,
354 enum ieee80211_band band
, bool nss_only
)
356 struct ieee80211_local
*local
= sdata
->local
;
357 struct ieee80211_supported_band
*sband
;
358 enum ieee80211_sta_rx_bandwidth new_bw
;
362 sband
= local
->hw
.wiphy
->bands
[band
];
364 /* ignore - no support for BF yet */
365 if (opmode
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)
368 nss
= opmode
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
369 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
372 if (sta
->sta
.rx_nss
!= nss
) {
373 sta
->sta
.rx_nss
= nss
;
374 changed
|= IEEE80211_RC_NSS_CHANGED
;
380 switch (opmode
& IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK
) {
381 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ
:
382 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_20
;
384 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ
:
385 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_40
;
387 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ
:
388 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_80
;
390 case IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ
:
391 sta
->cur_max_bandwidth
= IEEE80211_STA_RX_BW_160
;
395 new_bw
= ieee80211_sta_cur_vht_bw(sta
);
396 if (new_bw
!= sta
->sta
.bandwidth
) {
397 sta
->sta
.bandwidth
= new_bw
;
398 changed
|= IEEE80211_RC_BW_CHANGED
;
403 rate_control_rate_update(local
, sband
, sta
, changed
);