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"
23 u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
25 struct ieee80211_vht_capabilities *cap;
26 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
32 if (mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->conf->vendor_vht &&
33 mode->vht_capab == 0 && hapd->iface->hw_features) {
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];
45 *pos++ = WLAN_EID_VHT_CAP;
46 *pos++ = sizeof(*cap);
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);
53 /* Supported MCS set comes from hw */
54 os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
62 u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
64 struct ieee80211_vht_operation *oper;
67 *pos++ = WLAN_EID_VHT_OPERATION;
68 *pos++ = sizeof(*oper);
70 oper = (struct ieee80211_vht_operation *) pos;
71 os_memset(oper, 0, sizeof(*oper));
74 * center freq = 5 GHz + (5 * index)
75 * So index 42 gives center freq 5.210 GHz
76 * which is channel 42 in 5G band
78 oper->vht_op_info_chan_center_freq_seg0_idx =
79 hapd->iconf->vht_oper_centr_freq_seg0_idx;
80 oper->vht_op_info_chan_center_freq_seg1_idx =
81 hapd->iconf->vht_oper_centr_freq_seg1_idx;
83 oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
84 if (hapd->iconf->vht_oper_chwidth == 2) {
86 * Convert 160 MHz channel width to new style as interop
89 oper->vht_op_info_chwidth = 1;
90 oper->vht_op_info_chan_center_freq_seg1_idx =
91 oper->vht_op_info_chan_center_freq_seg0_idx;
92 if (hapd->iconf->channel <
93 hapd->iconf->vht_oper_centr_freq_seg0_idx)
94 oper->vht_op_info_chan_center_freq_seg0_idx -= 8;
96 oper->vht_op_info_chan_center_freq_seg0_idx += 8;
97 } else if (hapd->iconf->vht_oper_chwidth == 3) {
99 * Convert 80+80 MHz channel width to new style as interop
102 oper->vht_op_info_chwidth = 1;
105 /* VHT Basic MCS set comes from hw */
106 /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
107 oper->vht_basic_mcs_set = host_to_le16(0xfffc);
108 pos += sizeof(*oper);
114 static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
115 const u8 *sta_vht_capab)
117 const struct ieee80211_vht_capabilities *vht_cap;
118 struct ieee80211_vht_capabilities ap_vht_cap;
119 u16 sta_rx_mcs_set, ap_tx_mcs_set;
126 * Disable VHT caps for STAs for which there is not even a single
127 * allowed MCS in any supported number of streams, i.e., STA is
128 * advertising 3 (not supported) as VHT MCS rates for all supported
131 os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
132 sizeof(ap_vht_cap.vht_supported_mcs_set));
133 vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
135 /* AP Tx MCS map vs. STA Rx MCS map */
136 sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
137 ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
139 for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
140 if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
143 if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
149 wpa_printf(MSG_DEBUG,
150 "No matching VHT MCS found between AP TX and STA RX");
155 u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid)
157 u8 bw, chan1, chan2 = 0;
160 if (!hapd->cs_freq_params.channel ||
161 !hapd->cs_freq_params.vht_enabled)
164 /* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80 */
165 switch (hapd->cs_freq_params.bandwidth) {
170 /* check if it's 80+80 */
171 if (!hapd->cs_freq_params.center_freq2)
180 /* not valid VHT bandwidth or not in CSA */
184 freq1 = hapd->cs_freq_params.center_freq1 ?
185 hapd->cs_freq_params.center_freq1 :
186 hapd->cs_freq_params.freq;
187 if (ieee80211_freq_to_chan(freq1, &chan1) !=
188 HOSTAPD_MODE_IEEE80211A)
191 if (hapd->cs_freq_params.center_freq2 &&
192 ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2,
193 &chan2) != HOSTAPD_MODE_IEEE80211A)
196 *eid++ = WLAN_EID_VHT_CHANNEL_SWITCH_WRAPPER;
197 *eid++ = 5; /* Length of Channel Switch Wrapper */
198 *eid++ = WLAN_EID_VHT_WIDE_BW_CHSWITCH;
199 *eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */
200 *eid++ = bw; /* New Channel Width */
201 *eid++ = chan1; /* New Channel Center Frequency Segment 0 */
202 *eid++ = chan2; /* New Channel Center Frequency Segment 1 */
208 u8 * hostapd_eid_txpower_envelope(struct hostapd_data *hapd, u8 *eid)
210 struct hostapd_iface *iface = hapd->iface;
211 struct hostapd_config *iconf = iface->conf;
212 struct hostapd_hw_modes *mode = iface->current_mode;
213 struct hostapd_channel_data *chan;
215 u8 channel, tx_pwr_count, local_pwr_constraint;
222 if (ieee80211_freq_to_chan(iface->freq, &channel) == NUM_HOSTAPD_MODES)
225 for (i = 0; i < mode->num_channels; i++) {
226 if (mode->channels[i].freq == iface->freq)
229 if (i == mode->num_channels)
232 switch (iface->conf->vht_oper_chwidth) {
233 case VHT_CHANWIDTH_USE_HT:
234 if (iconf->secondary_channel == 0) {
235 /* Max Transmit Power count = 0 (20 MHz) */
238 /* Max Transmit Power count = 1 (20, 40 MHz) */
242 case VHT_CHANWIDTH_80MHZ:
243 /* Max Transmit Power count = 2 (20, 40, and 80 MHz) */
246 case VHT_CHANWIDTH_80P80MHZ:
247 case VHT_CHANWIDTH_160MHZ:
248 /* Max Transmit Power count = 3 (20, 40, 80, 160/80+80 MHz) */
256 * Below local_pwr_constraint logic is referred from
257 * hostapd_eid_pwr_constraint.
259 * Check if DFS is required by regulatory.
261 dfs = hostapd_is_dfs_required(hapd->iface);
266 * In order to meet regulations when TPC is not implemented using
267 * a transmit power that is below the legal maximum (including any
268 * mitigation factor) should help. In this case, indicate 3 dB below
269 * maximum allowed transmit power.
271 if (hapd->iconf->local_pwr_constraint == -1)
272 local_pwr_constraint = (dfs == 0) ? 0 : 3;
274 local_pwr_constraint = hapd->iconf->local_pwr_constraint;
277 * A STA that is not an AP shall use a transmit power less than or
278 * equal to the local maximum transmit power level for the channel.
279 * The local maximum transmit power can be calculated from the formula:
280 * local max TX pwr = max TX pwr - local pwr constraint
281 * Where max TX pwr is maximum transmit power level specified for
282 * channel in Country element and local pwr constraint is specified
283 * for channel in this Power Constraint element.
285 chan = &mode->channels[i];
286 max_tx_power = chan->max_tx_power - local_pwr_constraint;
289 * Local Maximum Transmit power is encoded as two's complement
290 * with a 0.5 dB step.
292 max_tx_power *= 2; /* in 0.5 dB steps */
293 if (max_tx_power > 127) {
294 /* 63.5 has special meaning of 63.5 dBm or higher */
297 if (max_tx_power < -128)
299 if (max_tx_power < 0)
300 tx_pwr = 0x80 + max_tx_power + 128;
302 tx_pwr = max_tx_power;
304 *eid++ = WLAN_EID_VHT_TRANSMIT_POWER_ENVELOPE;
305 *eid++ = 2 + tx_pwr_count;
308 * Max Transmit Power count and
309 * Max Transmit Power units = 0 (EIRP)
311 *eid++ = tx_pwr_count;
313 for (i = 0; i <= tx_pwr_count; i++)
320 u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
323 /* Disable VHT caps for STAs associated to no-VHT BSSes. */
325 hapd->conf->disable_11ac ||
326 !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
327 sta->flags &= ~WLAN_STA_VHT;
328 os_free(sta->vht_capabilities);
329 sta->vht_capabilities = NULL;
330 return WLAN_STATUS_SUCCESS;
333 if (sta->vht_capabilities == NULL) {
334 sta->vht_capabilities =
335 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
336 if (sta->vht_capabilities == NULL)
337 return WLAN_STATUS_UNSPECIFIED_FAILURE;
340 sta->flags |= WLAN_STA_VHT;
341 os_memcpy(sta->vht_capabilities, vht_capab,
342 sizeof(struct ieee80211_vht_capabilities));
344 return WLAN_STATUS_SUCCESS;
348 u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
349 const u8 *ie, size_t len)
352 unsigned int vht_capab_len;
354 if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
355 hapd->conf->disable_11ac)
358 /* The VHT Capabilities element embedded in vendor VHT */
360 if (vht_capab[0] != WLAN_EID_VHT_CAP)
362 vht_capab_len = vht_capab[1];
363 if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
364 (int) vht_capab_len > ie + len - vht_capab - 2)
368 if (sta->vht_capabilities == NULL) {
369 sta->vht_capabilities =
370 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
371 if (sta->vht_capabilities == NULL)
372 return WLAN_STATUS_UNSPECIFIED_FAILURE;
375 sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
376 os_memcpy(sta->vht_capabilities, vht_capab,
377 sizeof(struct ieee80211_vht_capabilities));
378 return WLAN_STATUS_SUCCESS;
381 sta->flags &= ~WLAN_STA_VENDOR_VHT;
382 return WLAN_STATUS_SUCCESS;
386 u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
390 if (!hapd->iface->current_mode)
393 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
394 *pos++ = (5 + /* The Vendor OUI, type and subtype */
395 2 + sizeof(struct ieee80211_vht_capabilities) +
396 2 + sizeof(struct ieee80211_vht_operation));
398 WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
400 *pos++ = VENDOR_VHT_SUBTYPE;
401 pos = hostapd_eid_vht_capabilities(hapd, pos);
402 pos = hostapd_eid_vht_operation(hapd, pos);
408 u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
409 const u8 *vht_oper_notif)
411 if (!vht_oper_notif) {
412 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
413 return WLAN_STATUS_SUCCESS;
416 sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
417 sta->vht_opmode = *vht_oper_notif;
418 return WLAN_STATUS_SUCCESS;
422 void hostapd_get_vht_capab(struct hostapd_data *hapd,
423 struct ieee80211_vht_capabilities *vht_cap,
424 struct ieee80211_vht_capabilities *neg_vht_cap)
426 u32 cap, own_cap, sym_caps;
430 os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
432 cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
433 own_cap = hapd->iconf->vht_capab;
435 /* mask out symmetric VHT capabilities we don't support */
436 sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
437 cap &= ~sym_caps | (own_cap & sym_caps);
439 /* mask out beamformer/beamformee caps if not supported */
440 if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
441 cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
442 VHT_CAP_BEAMFORMEE_STS_MAX);
444 if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
445 cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
446 VHT_CAP_SOUNDING_DIMENSION_MAX);
448 if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
449 cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
451 if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
452 cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
454 /* mask channel widths we don't support */
455 switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
456 case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
458 case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
459 if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
460 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
461 cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
465 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
469 if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
470 cap &= ~VHT_CAP_SHORT_GI_160;
473 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
474 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
476 if (!(own_cap & VHT_CAP_RXSTBC_MASK))
477 cap &= ~VHT_CAP_TXSTBC;
478 if (!(own_cap & VHT_CAP_TXSTBC))
479 cap &= ~VHT_CAP_RXSTBC_MASK;
481 neg_vht_cap->vht_capabilities_info = host_to_le32(cap);