2 * hostapd / Hardware feature query and different modes
3 * Copyright 2002-2003, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
11 #include "utils/includes.h"
13 #include "utils/common.h"
14 #include "utils/eloop.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
19 #include "ap_config.h"
20 #include "ap_drv_ops.h"
22 #include "hw_features.h"
25 void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
26 size_t num_hw_features)
30 if (hw_features == NULL)
33 for (i = 0; i < num_hw_features; i++) {
34 os_free(hw_features[i].channels);
35 os_free(hw_features[i].rates);
42 #ifndef CONFIG_NO_STDOUT_DEBUG
43 static char * dfs_info(struct hostapd_channel_data *chan)
45 static char info[256];
48 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
49 case HOSTAPD_CHAN_DFS_UNKNOWN:
52 case HOSTAPD_CHAN_DFS_USABLE:
55 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
56 state = "unavailable";
58 case HOSTAPD_CHAN_DFS_AVAILABLE:
64 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
65 info[sizeof(info) - 1] = '\0';
69 #endif /* CONFIG_NO_STDOUT_DEBUG */
72 int hostapd_get_hw_features(struct hostapd_iface *iface)
74 struct hostapd_data *hapd = iface->bss[0];
77 struct hostapd_hw_modes *modes;
79 if (hostapd_drv_none(hapd))
81 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
83 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
85 "Fetching hardware channel/rate support not "
90 iface->hw_flags = flags;
92 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
93 iface->hw_features = modes;
94 iface->num_hw_features = num_modes;
96 for (i = 0; i < num_modes; i++) {
97 struct hostapd_hw_modes *feature = &modes[i];
98 int dfs_enabled = hapd->iconf->ieee80211h &&
99 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
101 /* set flag for channels we can use in current regulatory
103 for (j = 0; j < feature->num_channels; j++) {
107 * Disable all channels that are marked not to allow
108 * IBSS operation or active scanning.
109 * Use radar channels only if the driver supports DFS.
111 if ((feature->channels[j].flag &
112 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
114 } else if (((feature->channels[j].flag &
115 HOSTAPD_CHAN_RADAR) &&
117 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
118 (feature->channels[j].flag &
119 (HOSTAPD_CHAN_NO_IBSS |
120 HOSTAPD_CHAN_PASSIVE_SCAN))) {
121 feature->channels[j].flag |=
122 HOSTAPD_CHAN_DISABLED;
125 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
128 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
129 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
131 feature->channels[j].chan,
132 feature->channels[j].freq,
133 feature->channels[j].max_tx_power,
134 dfs ? dfs_info(&feature->channels[j]) : "");
142 int hostapd_prepare_rates(struct hostapd_iface *iface,
143 struct hostapd_hw_modes *mode)
145 int i, num_basic_rates = 0;
146 int basic_rates_a[] = { 60, 120, 240, -1 };
147 int basic_rates_b[] = { 10, 20, -1 };
148 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
151 if (iface->conf->basic_rates)
152 basic_rates = iface->conf->basic_rates;
153 else switch (mode->mode) {
154 case HOSTAPD_MODE_IEEE80211A:
155 basic_rates = basic_rates_a;
157 case HOSTAPD_MODE_IEEE80211B:
158 basic_rates = basic_rates_b;
160 case HOSTAPD_MODE_IEEE80211G:
161 basic_rates = basic_rates_g;
163 case HOSTAPD_MODE_IEEE80211AD:
164 return 0; /* No basic rates for 11ad */
170 while (basic_rates[i] >= 0)
173 i++; /* -1 termination */
174 os_free(iface->basic_rates);
175 iface->basic_rates = os_malloc(i * sizeof(int));
176 if (iface->basic_rates)
177 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
179 os_free(iface->current_rates);
180 iface->num_rates = 0;
182 iface->current_rates =
183 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
184 if (!iface->current_rates) {
185 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
190 for (i = 0; i < mode->num_rates; i++) {
191 struct hostapd_rate_data *rate;
193 if (iface->conf->supported_rates &&
194 !hostapd_rate_found(iface->conf->supported_rates,
198 rate = &iface->current_rates[iface->num_rates];
199 rate->rate = mode->rates[i];
200 if (hostapd_rate_found(basic_rates, rate->rate)) {
201 rate->flags |= HOSTAPD_RATE_BASIC;
204 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
205 iface->num_rates, rate->rate, rate->flags);
209 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
210 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
211 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
212 "rate sets (%d,%d).",
213 iface->num_rates, num_basic_rates);
221 #ifdef CONFIG_IEEE80211N
222 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
224 int sec_chan, ok, j, first;
225 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
229 if (!iface->conf->secondary_channel)
230 return 1; /* HT40 not used */
232 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
233 wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
234 "secondary channel: %d",
235 iface->conf->channel, sec_chan);
237 /* Verify that HT40 secondary channel is an allowed 20 MHz
240 for (j = 0; j < iface->current_mode->num_channels; j++) {
241 struct hostapd_channel_data *chan =
242 &iface->current_mode->channels[j];
243 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
244 chan->chan == sec_chan) {
250 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
256 * Verify that HT40 primary,secondary channel pair is allowed per
257 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
258 * 2.4 GHz rules allow all cases where the secondary channel fits into
259 * the list of allowed channels (already checked above).
261 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
264 if (iface->conf->secondary_channel > 0)
265 first = iface->conf->channel;
270 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
271 if (first == allowed[k]) {
277 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
278 iface->conf->channel,
279 iface->conf->secondary_channel);
287 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
289 if (iface->conf->secondary_channel > 0) {
290 iface->conf->channel += 4;
291 iface->conf->secondary_channel = -1;
293 iface->conf->channel -= 4;
294 iface->conf->secondary_channel = 1;
299 static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
300 int *pri_chan, int *sec_chan)
302 struct ieee80211_ht_operation *oper;
303 struct ieee802_11_elems elems;
305 *pri_chan = *sec_chan = 0;
307 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
308 if (elems.ht_operation &&
309 elems.ht_operation_len >= sizeof(*oper)) {
310 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
311 *pri_chan = oper->primary_chan;
312 if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
313 int sec = oper->ht_param &
314 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
315 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
316 *sec_chan = *pri_chan + 4;
317 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
318 *sec_chan = *pri_chan - 4;
324 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
325 struct wpa_scan_results *scan_res)
327 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
328 int bss_pri_chan, bss_sec_chan;
332 pri_chan = iface->conf->channel;
333 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
334 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
335 if (iface->conf->secondary_channel > 0)
336 sec_freq = pri_freq + 20;
338 sec_freq = pri_freq - 20;
341 * Switch PRI/SEC channels if Beacons were detected on selected SEC
342 * channel, but not on selected PRI channel.
344 pri_bss = sec_bss = 0;
345 for (i = 0; i < scan_res->num; i++) {
346 struct wpa_scan_res *bss = scan_res->res[i];
347 if (bss->freq == pri_freq)
349 else if (bss->freq == sec_freq)
352 if (sec_bss && !pri_bss) {
353 wpa_printf(MSG_INFO, "Switch own primary and secondary "
354 "channel to get secondary channel with no Beacons "
356 ieee80211n_switch_pri_sec(iface);
361 * Match PRI/SEC channel with any existing HT40 BSS on the same
362 * channels that we are about to use (if already mixed order in
363 * existing BSSes, use own preference).
366 for (i = 0; i < scan_res->num; i++) {
367 struct wpa_scan_res *bss = scan_res->res[i];
368 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
369 if (pri_chan == bss_pri_chan &&
370 sec_chan == bss_sec_chan) {
376 for (i = 0; i < scan_res->num; i++) {
377 struct wpa_scan_res *bss = scan_res->res[i];
378 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
380 if (pri_chan == bss_sec_chan &&
381 sec_chan == bss_pri_chan) {
382 wpa_printf(MSG_INFO, "Switch own primary and "
383 "secondary channel due to BSS "
384 "overlap with " MACSTR,
385 MAC2STR(bss->bssid));
386 ieee80211n_switch_pri_sec(iface);
396 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
397 struct wpa_scan_results *scan_res)
399 int pri_freq, sec_freq;
400 int affected_start, affected_end;
403 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
404 if (iface->conf->secondary_channel > 0)
405 sec_freq = pri_freq + 20;
407 sec_freq = pri_freq - 20;
408 affected_start = (pri_freq + sec_freq) / 2 - 25;
409 affected_end = (pri_freq + sec_freq) / 2 + 25;
410 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
411 affected_start, affected_end);
412 for (i = 0; i < scan_res->num; i++) {
413 struct wpa_scan_res *bss = scan_res->res[i];
416 int sec_chan, pri_chan;
418 ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
421 if (sec_chan < pri_chan)
427 if ((pri < affected_start || pri > affected_end) &&
428 (sec < affected_start || sec > affected_end))
429 continue; /* not within affected channel range */
431 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
432 " freq=%d pri=%d sec=%d",
433 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
436 if (pri_freq != pri || sec_freq != sec) {
437 wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
438 "mismatch with BSS " MACSTR
439 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
442 sec > pri ? '+' : '-',
448 /* TODO: 40 MHz intolerant */
455 static void ieee80211n_check_scan(struct hostapd_iface *iface)
457 struct wpa_scan_results *scan_res;
461 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
462 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
464 iface->scan_cb = NULL;
466 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
467 if (scan_res == NULL) {
468 hostapd_setup_interface_complete(iface, 1);
472 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
473 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
475 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
476 wpa_scan_results_free(scan_res);
479 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
480 "channel pri=%d sec=%d based on overlapping BSSes",
481 iface->conf->channel,
482 iface->conf->channel +
483 iface->conf->secondary_channel * 4);
484 iface->conf->secondary_channel = 0;
487 res = ieee80211n_allowed_ht40_channel_pair(iface);
488 hostapd_setup_interface_complete(iface, !res);
492 static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
493 struct wpa_driver_scan_params *params)
495 /* Scan only the affected frequency range */
496 int pri_freq, sec_freq;
497 int affected_start, affected_end;
499 struct hostapd_hw_modes *mode;
501 if (iface->current_mode == NULL)
504 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
505 if (iface->conf->secondary_channel > 0)
506 sec_freq = pri_freq + 20;
508 sec_freq = pri_freq - 20;
509 affected_start = (pri_freq + sec_freq) / 2 - 25;
510 affected_end = (pri_freq + sec_freq) / 2 + 25;
511 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
512 affected_start, affected_end);
514 mode = iface->current_mode;
515 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
516 if (params->freqs == NULL)
520 for (i = 0; i < mode->num_channels; i++) {
521 struct hostapd_channel_data *chan = &mode->channels[i];
522 if (chan->flag & HOSTAPD_CHAN_DISABLED)
524 if (chan->freq < affected_start ||
525 chan->freq > affected_end)
527 params->freqs[pos++] = chan->freq;
532 static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
533 struct wpa_driver_scan_params *params)
535 /* Scan only the affected frequency range */
537 int affected_start, affected_end;
539 struct hostapd_hw_modes *mode;
541 if (iface->current_mode == NULL)
544 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
545 if (iface->conf->secondary_channel > 0) {
546 affected_start = pri_freq - 10;
547 affected_end = pri_freq + 30;
549 affected_start = pri_freq - 30;
550 affected_end = pri_freq + 10;
552 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
553 affected_start, affected_end);
555 mode = iface->current_mode;
556 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
557 if (params->freqs == NULL)
561 for (i = 0; i < mode->num_channels; i++) {
562 struct hostapd_channel_data *chan = &mode->channels[i];
563 if (chan->flag & HOSTAPD_CHAN_DISABLED)
565 if (chan->freq < affected_start ||
566 chan->freq > affected_end)
568 params->freqs[pos++] = chan->freq;
573 static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
575 struct wpa_driver_scan_params params;
577 if (!iface->conf->secondary_channel)
578 return 0; /* HT40 not used */
580 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
581 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
583 os_memset(¶ms, 0, sizeof(params));
584 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
585 ieee80211n_scan_channels_2g4(iface, ¶ms);
587 ieee80211n_scan_channels_5g(iface, ¶ms);
588 if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) {
589 wpa_printf(MSG_ERROR, "Failed to request a scan of "
590 "neighboring BSSes");
591 os_free(params.freqs);
594 os_free(params.freqs);
596 iface->scan_cb = ieee80211n_check_scan;
601 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
603 u16 hw = iface->current_mode->ht_capab;
604 u16 conf = iface->conf->ht_capab;
606 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
607 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
608 wpa_printf(MSG_ERROR, "Driver does not support configured "
609 "HT capability [LDPC]");
613 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
614 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
615 wpa_printf(MSG_ERROR, "Driver does not support configured "
616 "HT capability [HT40*]");
620 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
621 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
622 wpa_printf(MSG_ERROR, "Driver does not support configured "
623 "HT capability [SMPS-*]");
627 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
628 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
629 wpa_printf(MSG_ERROR, "Driver does not support configured "
630 "HT capability [GF]");
634 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
635 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
636 wpa_printf(MSG_ERROR, "Driver does not support configured "
637 "HT capability [SHORT-GI-20]");
641 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
642 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
643 wpa_printf(MSG_ERROR, "Driver does not support configured "
644 "HT capability [SHORT-GI-40]");
648 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
649 wpa_printf(MSG_ERROR, "Driver does not support configured "
650 "HT capability [TX-STBC]");
654 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
655 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
656 wpa_printf(MSG_ERROR, "Driver does not support configured "
657 "HT capability [RX-STBC*]");
661 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
662 !(hw & HT_CAP_INFO_DELAYED_BA)) {
663 wpa_printf(MSG_ERROR, "Driver does not support configured "
664 "HT capability [DELAYED-BA]");
668 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
669 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
670 wpa_printf(MSG_ERROR, "Driver does not support configured "
671 "HT capability [MAX-AMSDU-7935]");
675 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
676 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
677 wpa_printf(MSG_ERROR, "Driver does not support configured "
678 "HT capability [DSSS_CCK-40]");
682 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
683 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
684 wpa_printf(MSG_ERROR, "Driver does not support configured "
685 "HT capability [LSIG-TXOP-PROT]");
693 #ifdef CONFIG_IEEE80211AC
695 static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
697 u32 req_cap = conf & cap;
700 * Make sure we support all requested capabilities.
701 * NOTE: We assume that 'cap' represents a capability mask,
702 * not a discrete value.
704 if ((hw & req_cap) != req_cap) {
705 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
713 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap,
716 u32 hw_max = hw & cap;
717 u32 conf_val = conf & cap;
719 if (conf_val > hw_max) {
720 int offset = find_first_bit(cap);
721 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
722 name, conf_val >> offset, hw_max >> offset);
729 static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
731 u32 hw = iface->current_mode->vht_capab;
732 u32 conf = iface->conf->vht_capab;
734 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
737 #define VHT_CAP_CHECK(cap) \
739 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
743 #define VHT_CAP_CHECK_MAX(cap) \
745 if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \
749 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
750 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
751 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
752 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
753 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
754 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
755 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
756 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
757 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
758 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
759 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
760 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
761 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
762 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
763 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
764 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
765 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
766 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
767 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
768 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
769 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
772 #undef VHT_CAP_CHECK_MAX
776 #endif /* CONFIG_IEEE80211AC */
778 #endif /* CONFIG_IEEE80211N */
781 int hostapd_check_ht_capab(struct hostapd_iface *iface)
783 #ifdef CONFIG_IEEE80211N
785 if (!iface->conf->ieee80211n)
787 if (!ieee80211n_supported_ht_capab(iface))
789 #ifdef CONFIG_IEEE80211AC
790 if (!ieee80211ac_supported_vht_capab(iface))
792 #endif /* CONFIG_IEEE80211AC */
793 ret = ieee80211n_check_40mhz(iface);
796 if (!ieee80211n_allowed_ht40_channel_pair(iface))
798 #endif /* CONFIG_IEEE80211N */
804 static int hostapd_is_usable_chan(struct hostapd_iface *iface,
805 int channel, int primary)
808 struct hostapd_channel_data *chan;
810 for (i = 0; i < iface->current_mode->num_channels; i++) {
811 chan = &iface->current_mode->channels[i];
812 if (chan->chan != channel)
815 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
818 wpa_printf(MSG_DEBUG,
819 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s",
820 primary ? "" : "Configured HT40 secondary ",
821 i, chan->chan, chan->flag,
822 chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "",
823 chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ?
824 " PASSIVE-SCAN" : "",
825 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
832 static int hostapd_is_usable_chans(struct hostapd_iface *iface)
834 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
837 if (!iface->conf->secondary_channel)
840 return hostapd_is_usable_chan(iface, iface->conf->channel +
841 iface->conf->secondary_channel * 4, 0);
845 static enum hostapd_chan_status
846 hostapd_check_chans(struct hostapd_iface *iface)
848 if (iface->conf->channel) {
849 if (hostapd_is_usable_chans(iface))
850 return HOSTAPD_CHAN_VALID;
852 return HOSTAPD_CHAN_INVALID;
856 * The user set channel=0 or channel=acs_survey
857 * which is used to trigger ACS.
860 switch (acs_init(iface)) {
861 case HOSTAPD_CHAN_ACS:
862 return HOSTAPD_CHAN_ACS;
863 case HOSTAPD_CHAN_VALID:
864 case HOSTAPD_CHAN_INVALID:
866 return HOSTAPD_CHAN_INVALID;
871 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
873 hostapd_logger(iface->bss[0], NULL,
874 HOSTAPD_MODULE_IEEE80211,
875 HOSTAPD_LEVEL_WARNING,
876 "Configured channel (%d) not found from the "
877 "channel list of current mode (%d) %s",
878 iface->conf->channel,
879 iface->current_mode->mode,
880 hostapd_hw_mode_txt(iface->current_mode->mode));
881 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
882 HOSTAPD_LEVEL_WARNING,
883 "Hardware does not support configured channel");
887 int hostapd_acs_completed(struct hostapd_iface *iface, int err)
894 switch (hostapd_check_chans(iface)) {
895 case HOSTAPD_CHAN_VALID:
896 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
897 ACS_EVENT_COMPLETED "freq=%d channel=%d",
898 hostapd_hw_get_freq(iface->bss[0],
899 iface->conf->channel),
900 iface->conf->channel);
902 case HOSTAPD_CHAN_ACS:
903 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
904 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
905 hostapd_notify_bad_chans(iface);
907 case HOSTAPD_CHAN_INVALID:
909 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
910 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
911 hostapd_notify_bad_chans(iface);
915 ret = hostapd_check_ht_capab(iface);
919 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
925 return hostapd_setup_interface_complete(iface, ret);
930 * hostapd_select_hw_mode - Select the hardware mode
931 * @iface: Pointer to interface data.
932 * Returns: 0 on success, < 0 on failure
934 * Sets up the hardware mode, channel, rates, and passive scanning
935 * based on the configuration.
937 int hostapd_select_hw_mode(struct hostapd_iface *iface)
941 if (iface->num_hw_features < 1)
944 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
945 iface->conf->ieee80211n || iface->conf->ieee80211ac) &&
946 iface->conf->channel == 14) {
947 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14");
948 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
949 iface->conf->ieee80211n = 0;
950 iface->conf->ieee80211ac = 0;
953 iface->current_mode = NULL;
954 for (i = 0; i < iface->num_hw_features; i++) {
955 struct hostapd_hw_modes *mode = &iface->hw_features[i];
956 if (mode->mode == iface->conf->hw_mode) {
957 iface->current_mode = mode;
962 if (iface->current_mode == NULL) {
963 wpa_printf(MSG_ERROR, "Hardware does not support configured "
965 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
966 HOSTAPD_LEVEL_WARNING,
967 "Hardware does not support configured mode "
968 "(%d) (hw_mode in hostapd.conf)",
969 (int) iface->conf->hw_mode);
973 switch (hostapd_check_chans(iface)) {
974 case HOSTAPD_CHAN_VALID:
976 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
978 case HOSTAPD_CHAN_INVALID:
980 hostapd_notify_bad_chans(iface);
986 const char * hostapd_hw_mode_txt(int mode)
989 case HOSTAPD_MODE_IEEE80211A:
990 return "IEEE 802.11a";
991 case HOSTAPD_MODE_IEEE80211B:
992 return "IEEE 802.11b";
993 case HOSTAPD_MODE_IEEE80211G:
994 return "IEEE 802.11g";
995 case HOSTAPD_MODE_IEEE80211AD:
996 return "IEEE 802.11ad";
1003 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1007 if (!hapd->iface->current_mode)
1010 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1011 struct hostapd_channel_data *ch =
1012 &hapd->iface->current_mode->channels[i];
1013 if (ch->chan == chan)
1021 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1025 if (!hapd->iface->current_mode)
1028 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1029 struct hostapd_channel_data *ch =
1030 &hapd->iface->current_mode->channels[i];
1031 if (ch->freq == freq)