1 /*
2 * hostapd / IEEE 802.11ac VHT
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of BSD license
7 *
8 * See README and COPYING for more details.
9 */
10
11 #include "utils/includes.h"
12
13 #include "utils/common.h"
14 #include "common/ieee802_11_defs.h"
15 #include "hostapd.h"
16 #include "ap_config.h"
17 #include "sta_info.h"
18 #include "beacon.h"
19 #include "ieee802_11.h"
20 #include "dfs.h"
21
22
hostapd_eid_vht_capabilities(struct hostapd_data * hapd,u8 * eid,u32 nsts)23 u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid, u32 nsts)
24 {
25 struct ieee80211_vht_capabilities *cap;
26 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
27 u8 *pos = eid;
28
29 if (!mode || is_6ghz_op_class(hapd->iconf->op_class))
30 return eid;
31
32 if (mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->conf->vendor_vht &&
33 mode->vht_capab == 0 && hapd->iface->hw_features) {
34 int i;
35
36 for (i = 0; i < hapd->iface->num_hw_features; i++) {
37 if (hapd->iface->hw_features[i].mode ==
38 HOSTAPD_MODE_IEEE80211A) {
39 mode = &hapd->iface->hw_features[i];
40 break;
41 }
42 }
43 }
44
45 *pos++ = WLAN_EID_VHT_CAP;
46 *pos++ = sizeof(*cap);
47
48 cap = (struct ieee80211_vht_capabilities *) pos;
49 os_memset(cap, 0, sizeof(*cap));
50 cap->vht_capabilities_info = host_to_le32(
51 hapd->iface->conf->vht_capab);
52
53 if (nsts != 0) {
54 u32 hapd_nsts;
55
56 hapd_nsts = le_to_host32(cap->vht_capabilities_info);
57 hapd_nsts = (hapd_nsts >> VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
58 cap->vht_capabilities_info &=
59 ~(host_to_le32(hapd_nsts <<
60 VHT_CAP_BEAMFORMEE_STS_OFFSET));
61 cap->vht_capabilities_info |=
62 host_to_le32(nsts << VHT_CAP_BEAMFORMEE_STS_OFFSET);
63 }
64
65 /* Supported MCS set comes from hw */
66 os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
67
68 pos += sizeof(*cap);
69
70 return pos;
71 }
72
73
hostapd_eid_vht_operation(struct hostapd_data * hapd,u8 * eid)74 u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
75 {
76 struct ieee80211_vht_operation *oper;
77 u8 *pos = eid;
78 enum oper_chan_width oper_chwidth =
79 hostapd_get_oper_chwidth(hapd->iconf);
80 u8 seg0 = hapd->iconf->vht_oper_centr_freq_seg0_idx;
81 u8 seg1 = hapd->iconf->vht_oper_centr_freq_seg1_idx;
82
83 if (is_6ghz_op_class(hapd->iconf->op_class))
84 return eid;
85
86 *pos++ = WLAN_EID_VHT_OPERATION;
87 *pos++ = sizeof(*oper);
88
89 oper = (struct ieee80211_vht_operation *) pos;
90 os_memset(oper, 0, sizeof(*oper));
91
92 #ifdef CONFIG_IEEE80211BE
93 if (hapd->iconf->punct_bitmap) {
94 punct_update_legacy_bw(hapd->iconf->punct_bitmap,
95 hapd->iconf->channel,
96 &oper_chwidth, &seg0, &seg1);
97 }
98 #endif /* CONFIG_IEEE80211BE */
99
100 /*
101 * center freq = 5 GHz + (5 * index)
102 * So index 42 gives center freq 5.210 GHz
103 * which is channel 42 in 5G band
104 */
105 oper->vht_op_info_chan_center_freq_seg0_idx = seg0;
106 oper->vht_op_info_chan_center_freq_seg1_idx = seg1;
107
108 oper->vht_op_info_chwidth = oper_chwidth;
109 if (oper_chwidth == CONF_OPER_CHWIDTH_160MHZ) {
110 /*
111 * Convert 160 MHz channel width to new style as interop
112 * workaround.
113 */
114 oper->vht_op_info_chwidth = CHANWIDTH_80MHZ;
115 oper->vht_op_info_chan_center_freq_seg1_idx =
116 oper->vht_op_info_chan_center_freq_seg0_idx;
117 if (hapd->iconf->channel <
118 hapd->iconf->vht_oper_centr_freq_seg0_idx)
119 oper->vht_op_info_chan_center_freq_seg0_idx -= 8;
120 else
121 oper->vht_op_info_chan_center_freq_seg0_idx += 8;
122 } else if (oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ) {
123 /*
124 * Convert 80+80 MHz channel width to new style as interop
125 * workaround.
126 */
127 oper->vht_op_info_chwidth = CHANWIDTH_80MHZ;
128 }
129
130 /* VHT Basic MCS set comes from hw */
131 /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
132 oper->vht_basic_mcs_set = host_to_le16(0xfffc);
133 pos += sizeof(*oper);
134
135 return pos;
136 }
137
138
check_valid_vht_mcs(struct hostapd_hw_modes * mode,const u8 * sta_vht_capab)139 static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
140 const u8 *sta_vht_capab)
141 {
142 const struct ieee80211_vht_capabilities *vht_cap;
143 struct ieee80211_vht_capabilities ap_vht_cap;
144 u16 sta_rx_mcs_set, ap_tx_mcs_set;
145 int i;
146
147 if (!mode)
148 return 1;
149
150 /*
151 * Disable VHT caps for STAs for which there is not even a single
152 * allowed MCS in any supported number of streams, i.e., STA is
153 * advertising 3 (not supported) as VHT MCS rates for all supported
154 * stream cases.
155 */
156 os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
157 sizeof(ap_vht_cap.vht_supported_mcs_set));
158 vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
159
160 /* AP Tx MCS map vs. STA Rx MCS map */
161 sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
162 ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
163
164 for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
165 if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
166 continue;
167
168 if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
169 continue;
170
171 return 1;
172 }
173
174 wpa_printf(MSG_DEBUG,
175 "No matching VHT MCS found between AP TX and STA RX");
176 return 0;
177 }
178
179
copy_sta_vht_capab(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_capab)180 u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
181 const u8 *vht_capab)
182 {
183 /* Disable VHT caps for STAs associated to no-VHT BSSes. */
184 if (!vht_capab || !(sta->flags & WLAN_STA_WMM) ||
185 !hapd->iconf->ieee80211ac || hapd->conf->disable_11ac ||
186 !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
187 sta->flags &= ~WLAN_STA_VHT;
188 os_free(sta->vht_capabilities);
189 sta->vht_capabilities = NULL;
190 return WLAN_STATUS_SUCCESS;
191 }
192
193 if (sta->vht_capabilities == NULL) {
194 sta->vht_capabilities =
195 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
196 if (sta->vht_capabilities == NULL)
197 return WLAN_STATUS_UNSPECIFIED_FAILURE;
198 }
199
200 sta->flags |= WLAN_STA_VHT;
201 os_memcpy(sta->vht_capabilities, vht_capab,
202 sizeof(struct ieee80211_vht_capabilities));
203
204 return WLAN_STATUS_SUCCESS;
205 }
206
207
copy_sta_vht_oper(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_oper)208 u16 copy_sta_vht_oper(struct hostapd_data *hapd, struct sta_info *sta,
209 const u8 *vht_oper)
210 {
211 if (!vht_oper) {
212 os_free(sta->vht_operation);
213 sta->vht_operation = NULL;
214 return WLAN_STATUS_SUCCESS;
215 }
216
217 if (!sta->vht_operation) {
218 sta->vht_operation =
219 os_zalloc(sizeof(struct ieee80211_vht_operation));
220 if (!sta->vht_operation)
221 return WLAN_STATUS_UNSPECIFIED_FAILURE;
222 }
223
224 os_memcpy(sta->vht_operation, vht_oper,
225 sizeof(struct ieee80211_vht_operation));
226
227 return WLAN_STATUS_SUCCESS;
228 }
229
230
copy_sta_vendor_vht(struct hostapd_data * hapd,struct sta_info * sta,const u8 * ie,size_t len)231 u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
232 const u8 *ie, size_t len)
233 {
234 const u8 *vht_capab;
235 unsigned int vht_capab_len;
236
237 if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
238 hapd->conf->disable_11ac)
239 goto no_capab;
240
241 /* The VHT Capabilities element embedded in vendor VHT */
242 vht_capab = ie + 5;
243 if (vht_capab[0] != WLAN_EID_VHT_CAP)
244 goto no_capab;
245 vht_capab_len = vht_capab[1];
246 if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
247 (int) vht_capab_len > ie + len - vht_capab - 2)
248 goto no_capab;
249 vht_capab += 2;
250
251 if (sta->vht_capabilities == NULL) {
252 sta->vht_capabilities =
253 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
254 if (sta->vht_capabilities == NULL)
255 return WLAN_STATUS_UNSPECIFIED_FAILURE;
256 }
257
258 sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
259 os_memcpy(sta->vht_capabilities, vht_capab,
260 sizeof(struct ieee80211_vht_capabilities));
261 return WLAN_STATUS_SUCCESS;
262
263 no_capab:
264 sta->flags &= ~WLAN_STA_VENDOR_VHT;
265 return WLAN_STATUS_SUCCESS;
266 }
267
268
hostapd_eid_vendor_vht(struct hostapd_data * hapd,u8 * eid)269 u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
270 {
271 u8 *pos = eid;
272
273 /* Vendor VHT is applicable only to 2.4 GHz */
274 if (!hapd->iface->current_mode ||
275 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
276 return eid;
277
278 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
279 *pos++ = (5 + /* The Vendor OUI, type and subtype */
280 2 + sizeof(struct ieee80211_vht_capabilities) +
281 2 + sizeof(struct ieee80211_vht_operation));
282
283 WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
284 pos += 4;
285 *pos++ = VENDOR_VHT_SUBTYPE;
286 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
287 pos = hostapd_eid_vht_operation(hapd, pos);
288
289 return pos;
290 }
291
292
set_sta_vht_opmode(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_oper_notif)293 u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
294 const u8 *vht_oper_notif)
295 {
296 if (!vht_oper_notif) {
297 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
298 return WLAN_STATUS_SUCCESS;
299 }
300
301 sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
302 sta->vht_opmode = *vht_oper_notif;
303 return WLAN_STATUS_SUCCESS;
304 }
305
306
hostapd_get_vht_capab(struct hostapd_data * hapd,struct ieee80211_vht_capabilities * vht_cap,struct ieee80211_vht_capabilities * neg_vht_cap)307 void hostapd_get_vht_capab(struct hostapd_data *hapd,
308 struct ieee80211_vht_capabilities *vht_cap,
309 struct ieee80211_vht_capabilities *neg_vht_cap)
310 {
311 u32 cap, own_cap, sym_caps;
312
313 if (vht_cap == NULL)
314 return;
315 os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
316
317 cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
318 own_cap = hapd->iconf->vht_capab;
319
320 /* mask out symmetric VHT capabilities we don't support */
321 sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
322 cap &= ~sym_caps | (own_cap & sym_caps);
323
324 /* mask out beamformer/beamformee caps if not supported */
325 if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
326 cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
327 VHT_CAP_BEAMFORMEE_STS_MAX);
328
329 if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
330 cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
331 VHT_CAP_SOUNDING_DIMENSION_MAX);
332
333 if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
334 cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
335
336 if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
337 cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
338
339 /* mask channel widths we don't support */
340 switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
341 case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
342 break;
343 case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
344 if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
345 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
346 cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
347 }
348 break;
349 default:
350 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
351 break;
352 }
353
354 if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
355 cap &= ~VHT_CAP_SHORT_GI_160;
356
357 /*
358 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
359 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
360 */
361 if (!(own_cap & VHT_CAP_RXSTBC_MASK))
362 cap &= ~VHT_CAP_TXSTBC;
363 if (!(own_cap & VHT_CAP_TXSTBC))
364 cap &= ~VHT_CAP_RXSTBC_MASK;
365
366 neg_vht_cap->vht_capabilities_info = host_to_le32(cap);
367 }
368