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, u32 nsts)
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);
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);
65 /* Supported MCS set comes from hw */
66 os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
74 u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
76 struct ieee80211_vht_operation *oper;
79 *pos++ = WLAN_EID_VHT_OPERATION;
80 *pos++ = sizeof(*oper);
82 oper = (struct ieee80211_vht_operation *) pos;
83 os_memset(oper, 0, sizeof(*oper));
86 * center freq = 5 GHz + (5 * index)
87 * So index 42 gives center freq 5.210 GHz
88 * which is channel 42 in 5G band
90 oper->vht_op_info_chan_center_freq_seg0_idx =
91 hapd->iconf->vht_oper_centr_freq_seg0_idx;
92 oper->vht_op_info_chan_center_freq_seg1_idx =
93 hapd->iconf->vht_oper_centr_freq_seg1_idx;
95 oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
96 if (hapd->iconf->vht_oper_chwidth == 2) {
98 * Convert 160 MHz channel width to new style as interop
101 oper->vht_op_info_chwidth = 1;
102 oper->vht_op_info_chan_center_freq_seg1_idx =
103 oper->vht_op_info_chan_center_freq_seg0_idx;
104 if (hapd->iconf->channel <
105 hapd->iconf->vht_oper_centr_freq_seg0_idx)
106 oper->vht_op_info_chan_center_freq_seg0_idx -= 8;
108 oper->vht_op_info_chan_center_freq_seg0_idx += 8;
109 } else if (hapd->iconf->vht_oper_chwidth == 3) {
111 * Convert 80+80 MHz channel width to new style as interop
114 oper->vht_op_info_chwidth = 1;
117 /* VHT Basic MCS set comes from hw */
118 /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
119 oper->vht_basic_mcs_set = host_to_le16(0xfffc);
120 pos += sizeof(*oper);
126 static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
127 const u8 *sta_vht_capab)
129 const struct ieee80211_vht_capabilities *vht_cap;
130 struct ieee80211_vht_capabilities ap_vht_cap;
131 u16 sta_rx_mcs_set, ap_tx_mcs_set;
138 * Disable VHT caps for STAs for which there is not even a single
139 * allowed MCS in any supported number of streams, i.e., STA is
140 * advertising 3 (not supported) as VHT MCS rates for all supported
143 os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
144 sizeof(ap_vht_cap.vht_supported_mcs_set));
145 vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
147 /* AP Tx MCS map vs. STA Rx MCS map */
148 sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
149 ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
151 for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
152 if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
155 if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
161 wpa_printf(MSG_DEBUG,
162 "No matching VHT MCS found between AP TX and STA RX");
167 u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid)
169 u8 bw, chan1, chan2 = 0;
172 if (!hapd->cs_freq_params.channel ||
173 !hapd->cs_freq_params.vht_enabled)
176 /* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80 */
177 switch (hapd->cs_freq_params.bandwidth) {
182 /* check if it's 80+80 */
183 if (!hapd->cs_freq_params.center_freq2)
192 /* not valid VHT bandwidth or not in CSA */
196 freq1 = hapd->cs_freq_params.center_freq1 ?
197 hapd->cs_freq_params.center_freq1 :
198 hapd->cs_freq_params.freq;
199 if (ieee80211_freq_to_chan(freq1, &chan1) !=
200 HOSTAPD_MODE_IEEE80211A)
203 if (hapd->cs_freq_params.center_freq2 &&
204 ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2,
205 &chan2) != HOSTAPD_MODE_IEEE80211A)
208 *eid++ = WLAN_EID_VHT_CHANNEL_SWITCH_WRAPPER;
209 *eid++ = 5; /* Length of Channel Switch Wrapper */
210 *eid++ = WLAN_EID_VHT_WIDE_BW_CHSWITCH;
211 *eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */
212 *eid++ = bw; /* New Channel Width */
213 *eid++ = chan1; /* New Channel Center Frequency Segment 0 */
214 *eid++ = chan2; /* New Channel Center Frequency Segment 1 */
220 u8 * hostapd_eid_txpower_envelope(struct hostapd_data *hapd, u8 *eid)
222 struct hostapd_iface *iface = hapd->iface;
223 struct hostapd_config *iconf = iface->conf;
224 struct hostapd_hw_modes *mode = iface->current_mode;
225 struct hostapd_channel_data *chan;
227 u8 channel, tx_pwr_count, local_pwr_constraint;
234 if (ieee80211_freq_to_chan(iface->freq, &channel) == NUM_HOSTAPD_MODES)
237 for (i = 0; i < mode->num_channels; i++) {
238 if (mode->channels[i].freq == iface->freq)
241 if (i == mode->num_channels)
244 switch (iface->conf->vht_oper_chwidth) {
245 case CHANWIDTH_USE_HT:
246 if (iconf->secondary_channel == 0) {
247 /* Max Transmit Power count = 0 (20 MHz) */
250 /* Max Transmit Power count = 1 (20, 40 MHz) */
254 case CHANWIDTH_80MHZ:
255 /* Max Transmit Power count = 2 (20, 40, and 80 MHz) */
258 case CHANWIDTH_80P80MHZ:
259 case CHANWIDTH_160MHZ:
260 /* Max Transmit Power count = 3 (20, 40, 80, 160/80+80 MHz) */
268 * Below local_pwr_constraint logic is referred from
269 * hostapd_eid_pwr_constraint.
271 * Check if DFS is required by regulatory.
273 dfs = hostapd_is_dfs_required(hapd->iface);
278 * In order to meet regulations when TPC is not implemented using
279 * a transmit power that is below the legal maximum (including any
280 * mitigation factor) should help. In this case, indicate 3 dB below
281 * maximum allowed transmit power.
283 if (hapd->iconf->local_pwr_constraint == -1)
284 local_pwr_constraint = (dfs == 0) ? 0 : 3;
286 local_pwr_constraint = hapd->iconf->local_pwr_constraint;
289 * A STA that is not an AP shall use a transmit power less than or
290 * equal to the local maximum transmit power level for the channel.
291 * The local maximum transmit power can be calculated from the formula:
292 * local max TX pwr = max TX pwr - local pwr constraint
293 * Where max TX pwr is maximum transmit power level specified for
294 * channel in Country element and local pwr constraint is specified
295 * for channel in this Power Constraint element.
297 chan = &mode->channels[i];
298 max_tx_power = chan->max_tx_power - local_pwr_constraint;
301 * Local Maximum Transmit power is encoded as two's complement
302 * with a 0.5 dB step.
304 max_tx_power *= 2; /* in 0.5 dB steps */
305 if (max_tx_power > 127) {
306 /* 63.5 has special meaning of 63.5 dBm or higher */
309 if (max_tx_power < -128)
311 if (max_tx_power < 0)
312 tx_pwr = 0x80 + max_tx_power + 128;
314 tx_pwr = max_tx_power;
316 *eid++ = WLAN_EID_VHT_TRANSMIT_POWER_ENVELOPE;
317 *eid++ = 2 + tx_pwr_count;
320 * Max Transmit Power count and
321 * Max Transmit Power units = 0 (EIRP)
323 *eid++ = tx_pwr_count;
325 for (i = 0; i <= tx_pwr_count; i++)
332 u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
335 /* Disable VHT caps for STAs associated to no-VHT BSSes. */
337 !hapd->iconf->ieee80211ac || hapd->conf->disable_11ac ||
338 !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
339 sta->flags &= ~WLAN_STA_VHT;
340 os_free(sta->vht_capabilities);
341 sta->vht_capabilities = NULL;
342 return WLAN_STATUS_SUCCESS;
345 if (sta->vht_capabilities == NULL) {
346 sta->vht_capabilities =
347 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
348 if (sta->vht_capabilities == NULL)
349 return WLAN_STATUS_UNSPECIFIED_FAILURE;
352 sta->flags |= WLAN_STA_VHT;
353 os_memcpy(sta->vht_capabilities, vht_capab,
354 sizeof(struct ieee80211_vht_capabilities));
356 return WLAN_STATUS_SUCCESS;
360 u16 copy_sta_vht_oper(struct hostapd_data *hapd, struct sta_info *sta,
364 os_free(sta->vht_operation);
365 sta->vht_operation = NULL;
366 return WLAN_STATUS_SUCCESS;
369 if (!sta->vht_operation) {
371 os_zalloc(sizeof(struct ieee80211_vht_operation));
372 if (!sta->vht_operation)
373 return WLAN_STATUS_UNSPECIFIED_FAILURE;
376 os_memcpy(sta->vht_operation, vht_oper,
377 sizeof(struct ieee80211_vht_operation));
379 return WLAN_STATUS_SUCCESS;
383 u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
384 const u8 *ie, size_t len)
387 unsigned int vht_capab_len;
389 if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
390 hapd->conf->disable_11ac)
393 /* The VHT Capabilities element embedded in vendor VHT */
395 if (vht_capab[0] != WLAN_EID_VHT_CAP)
397 vht_capab_len = vht_capab[1];
398 if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
399 (int) vht_capab_len > ie + len - vht_capab - 2)
403 if (sta->vht_capabilities == NULL) {
404 sta->vht_capabilities =
405 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
406 if (sta->vht_capabilities == NULL)
407 return WLAN_STATUS_UNSPECIFIED_FAILURE;
410 sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
411 os_memcpy(sta->vht_capabilities, vht_capab,
412 sizeof(struct ieee80211_vht_capabilities));
413 return WLAN_STATUS_SUCCESS;
416 sta->flags &= ~WLAN_STA_VENDOR_VHT;
417 return WLAN_STATUS_SUCCESS;
421 u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
425 if (!hapd->iface->current_mode)
428 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
429 *pos++ = (5 + /* The Vendor OUI, type and subtype */
430 2 + sizeof(struct ieee80211_vht_capabilities) +
431 2 + sizeof(struct ieee80211_vht_operation));
433 WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
435 *pos++ = VENDOR_VHT_SUBTYPE;
436 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
437 pos = hostapd_eid_vht_operation(hapd, pos);
443 u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
444 const u8 *vht_oper_notif)
446 if (!vht_oper_notif) {
447 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
448 return WLAN_STATUS_SUCCESS;
451 sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
452 sta->vht_opmode = *vht_oper_notif;
453 return WLAN_STATUS_SUCCESS;
457 void hostapd_get_vht_capab(struct hostapd_data *hapd,
458 struct ieee80211_vht_capabilities *vht_cap,
459 struct ieee80211_vht_capabilities *neg_vht_cap)
461 u32 cap, own_cap, sym_caps;
465 os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
467 cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
468 own_cap = hapd->iconf->vht_capab;
470 /* mask out symmetric VHT capabilities we don't support */
471 sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
472 cap &= ~sym_caps | (own_cap & sym_caps);
474 /* mask out beamformer/beamformee caps if not supported */
475 if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
476 cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
477 VHT_CAP_BEAMFORMEE_STS_MAX);
479 if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
480 cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
481 VHT_CAP_SOUNDING_DIMENSION_MAX);
483 if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
484 cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
486 if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
487 cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
489 /* mask channel widths we don't support */
490 switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
491 case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
493 case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
494 if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
495 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
496 cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
500 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
504 if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
505 cap &= ~VHT_CAP_SHORT_GI_160;
508 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
509 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
511 if (!(own_cap & VHT_CAP_RXSTBC_MASK))
512 cap &= ~VHT_CAP_TXSTBC;
513 if (!(own_cap & VHT_CAP_TXSTBC))
514 cap &= ~VHT_CAP_RXSTBC_MASK;
516 neg_vht_cap->vht_capabilities_info = host_to_le32(cap);