2 * hostapd / IEEE 802.11ac VHT
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of BSD license
8 * See README and COPYING for more details.
11 #include "utils/includes.h"
13 #include "utils/common.h"
14 #include "common/ieee802_11_defs.h"
16 #include "ap_config.h"
19 #include "ieee802_11.h"
22 u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
24 struct ieee80211_vht_capabilities *cap;
25 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
31 if (mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->conf->vendor_vht &&
32 mode->vht_capab == 0 && hapd->iface->hw_features) {
35 for (i = 0; i < hapd->iface->num_hw_features; i++) {
36 if (hapd->iface->hw_features[i].mode ==
37 HOSTAPD_MODE_IEEE80211A) {
38 mode = &hapd->iface->hw_features[i];
44 *pos++ = WLAN_EID_VHT_CAP;
45 *pos++ = sizeof(*cap);
47 cap = (struct ieee80211_vht_capabilities *) pos;
48 os_memset(cap, 0, sizeof(*cap));
49 cap->vht_capabilities_info = host_to_le32(
50 hapd->iface->conf->vht_capab);
52 /* Supported MCS set comes from hw */
53 os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
61 u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
63 struct ieee80211_vht_operation *oper;
66 *pos++ = WLAN_EID_VHT_OPERATION;
67 *pos++ = sizeof(*oper);
69 oper = (struct ieee80211_vht_operation *) pos;
70 os_memset(oper, 0, sizeof(*oper));
73 * center freq = 5 GHz + (5 * index)
74 * So index 42 gives center freq 5.210 GHz
75 * which is channel 42 in 5G band
77 oper->vht_op_info_chan_center_freq_seg0_idx =
78 hapd->iconf->vht_oper_centr_freq_seg0_idx;
79 oper->vht_op_info_chan_center_freq_seg1_idx =
80 hapd->iconf->vht_oper_centr_freq_seg1_idx;
82 oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
84 /* VHT Basic MCS set comes from hw */
85 /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
86 oper->vht_basic_mcs_set = host_to_le16(0xfffc);
93 static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
94 const u8 *sta_vht_capab)
96 const struct ieee80211_vht_capabilities *vht_cap;
97 struct ieee80211_vht_capabilities ap_vht_cap;
98 u16 sta_rx_mcs_set, ap_tx_mcs_set;
105 * Disable VHT caps for STAs for which there is not even a single
106 * allowed MCS in any supported number of streams, i.e., STA is
107 * advertising 3 (not supported) as VHT MCS rates for all supported
110 os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
111 sizeof(ap_vht_cap.vht_supported_mcs_set));
112 vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
114 /* AP Tx MCS map vs. STA Rx MCS map */
115 sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
116 ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
118 for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
119 if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
122 if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
128 wpa_printf(MSG_DEBUG,
129 "No matching VHT MCS found between AP TX and STA RX");
134 u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid)
136 u8 bw, chan1, chan2 = 0;
139 if (!hapd->cs_freq_params.channel ||
140 !hapd->cs_freq_params.vht_enabled)
143 /* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80 */
144 switch (hapd->cs_freq_params.bandwidth) {
149 /* check if it's 80+80 */
150 if (!hapd->cs_freq_params.center_freq2)
159 /* not valid VHT bandwidth or not in CSA */
163 freq1 = hapd->cs_freq_params.center_freq1 ?
164 hapd->cs_freq_params.center_freq1 :
165 hapd->cs_freq_params.freq;
166 if (ieee80211_freq_to_chan(freq1, &chan1) !=
167 HOSTAPD_MODE_IEEE80211A)
170 if (hapd->cs_freq_params.center_freq2 &&
171 ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2,
172 &chan2) != HOSTAPD_MODE_IEEE80211A)
175 *eid++ = WLAN_EID_VHT_CHANNEL_SWITCH_WRAPPER;
176 *eid++ = 5; /* Length of Channel Switch Wrapper */
177 *eid++ = WLAN_EID_VHT_WIDE_BW_CHSWITCH;
178 *eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */
179 *eid++ = bw; /* New Channel Width */
180 *eid++ = chan1; /* New Channel Center Frequency Segment 0 */
181 *eid++ = chan2; /* New Channel Center Frequency Segment 1 */
187 u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
190 /* Disable VHT caps for STAs associated to no-VHT BSSes. */
192 hapd->conf->disable_11ac ||
193 !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
194 sta->flags &= ~WLAN_STA_VHT;
195 os_free(sta->vht_capabilities);
196 sta->vht_capabilities = NULL;
197 return WLAN_STATUS_SUCCESS;
200 if (sta->vht_capabilities == NULL) {
201 sta->vht_capabilities =
202 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
203 if (sta->vht_capabilities == NULL)
204 return WLAN_STATUS_UNSPECIFIED_FAILURE;
207 sta->flags |= WLAN_STA_VHT;
208 os_memcpy(sta->vht_capabilities, vht_capab,
209 sizeof(struct ieee80211_vht_capabilities));
211 return WLAN_STATUS_SUCCESS;
215 u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
216 const u8 *ie, size_t len)
219 unsigned int vht_capab_len;
221 if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
222 hapd->conf->disable_11ac)
225 /* The VHT Capabilities element embedded in vendor VHT */
227 if (vht_capab[0] != WLAN_EID_VHT_CAP)
229 vht_capab_len = vht_capab[1];
230 if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
231 (int) vht_capab_len > ie + len - vht_capab - 2)
235 if (sta->vht_capabilities == NULL) {
236 sta->vht_capabilities =
237 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
238 if (sta->vht_capabilities == NULL)
239 return WLAN_STATUS_UNSPECIFIED_FAILURE;
242 sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
243 os_memcpy(sta->vht_capabilities, vht_capab,
244 sizeof(struct ieee80211_vht_capabilities));
245 return WLAN_STATUS_SUCCESS;
248 sta->flags &= ~WLAN_STA_VENDOR_VHT;
249 return WLAN_STATUS_SUCCESS;
253 u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
257 if (!hapd->iface->current_mode)
260 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
261 *pos++ = (5 + /* The Vendor OUI, type and subtype */
262 2 + sizeof(struct ieee80211_vht_capabilities) +
263 2 + sizeof(struct ieee80211_vht_operation));
265 WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
267 *pos++ = VENDOR_VHT_SUBTYPE;
268 pos = hostapd_eid_vht_capabilities(hapd, pos);
269 pos = hostapd_eid_vht_operation(hapd, pos);
275 u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
276 const u8 *vht_oper_notif)
278 if (!vht_oper_notif) {
279 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
280 return WLAN_STATUS_SUCCESS;
283 sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
284 sta->vht_opmode = *vht_oper_notif;
285 return WLAN_STATUS_SUCCESS;
289 void hostapd_get_vht_capab(struct hostapd_data *hapd,
290 struct ieee80211_vht_capabilities *vht_cap,
291 struct ieee80211_vht_capabilities *neg_vht_cap)
293 u32 cap, own_cap, sym_caps;
297 os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
299 cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
300 own_cap = hapd->iconf->vht_capab;
302 /* mask out symmetric VHT capabilities we don't support */
303 sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
304 cap &= ~sym_caps | (own_cap & sym_caps);
306 /* mask out beamformer/beamformee caps if not supported */
307 if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
308 cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
309 VHT_CAP_BEAMFORMEE_STS_MAX);
311 if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
312 cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
313 VHT_CAP_SOUNDING_DIMENSION_MAX);
315 if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
316 cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
318 if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
319 cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
321 /* mask channel widths we don't support */
322 switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
323 case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
325 case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
326 if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
327 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
328 cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
332 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
336 if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
337 cap &= ~VHT_CAP_SHORT_GI_160;
340 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
341 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
343 if (!(own_cap & VHT_CAP_RXSTBC_MASK))
344 cap &= ~VHT_CAP_TXSTBC;
345 if (!(own_cap & VHT_CAP_TXSTBC))
346 cap &= ~VHT_CAP_RXSTBC_MASK;
348 neg_vht_cap->vht_capabilities_info = host_to_le32(cap);