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 program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
17 #include "utils/includes.h"
19 #include "utils/common.h"
20 #include "utils/eloop.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/ieee802_11_common.h"
23 #include "common/wpa_ctrl.h"
24 #include "drivers/driver.h"
26 #include "ap_config.h"
27 #include "ap_drv_ops.h"
29 #include "hw_features.h"
32 void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
33 size_t num_hw_features)
37 if (hw_features == NULL)
40 for (i = 0; i < num_hw_features; i++) {
41 os_free(hw_features[i].channels);
42 os_free(hw_features[i].rates);
49 #ifndef CONFIG_NO_STDOUT_DEBUG
50 static char * dfs_info(struct hostapd_channel_data *chan)
52 static char info[256];
55 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
56 case HOSTAPD_CHAN_DFS_UNKNOWN:
59 case HOSTAPD_CHAN_DFS_USABLE:
62 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
63 state = "unavailable";
65 case HOSTAPD_CHAN_DFS_AVAILABLE:
71 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
72 info[sizeof(info) - 1] = '\0';
76 #endif /* CONFIG_NO_STDOUT_DEBUG */
79 int hostapd_get_hw_features(struct hostapd_iface *iface)
81 struct hostapd_data *hapd = iface->bss[0];
84 struct hostapd_hw_modes *modes;
86 if (hostapd_drv_none(hapd))
88 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
90 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
92 "Fetching hardware channel/rate support not "
97 iface->hw_flags = flags;
99 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
100 iface->hw_features = modes;
101 iface->num_hw_features = num_modes;
103 for (i = 0; i < num_modes; i++) {
104 struct hostapd_hw_modes *feature = &modes[i];
105 int dfs_enabled = hapd->iconf->ieee80211h &&
106 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
108 /* set flag for channels we can use in current regulatory
110 for (j = 0; j < feature->num_channels; j++) {
114 * Disable all channels that are marked not to allow
115 * IBSS operation or active scanning.
116 * Use radar channels only if the driver supports DFS.
118 if ((feature->channels[j].flag &
119 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
121 } else if (feature->channels[j].flag &
122 (HOSTAPD_CHAN_NO_IBSS |
123 HOSTAPD_CHAN_PASSIVE_SCAN |
124 HOSTAPD_CHAN_RADAR)) {
125 feature->channels[j].flag |=
126 HOSTAPD_CHAN_DISABLED;
129 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
132 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
133 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
135 feature->channels[j].chan,
136 feature->channels[j].freq,
137 feature->channels[j].max_tx_power,
138 dfs ? dfs_info(&feature->channels[j]) : "");
146 int hostapd_prepare_rates(struct hostapd_iface *iface,
147 struct hostapd_hw_modes *mode)
149 int i, num_basic_rates = 0;
150 int basic_rates_a[] = { 60, 120, 240, -1 };
151 int basic_rates_b[] = { 10, 20, -1 };
152 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
155 if (iface->conf->basic_rates)
156 basic_rates = iface->conf->basic_rates;
157 else switch (mode->mode) {
158 case HOSTAPD_MODE_IEEE80211A:
159 basic_rates = basic_rates_a;
161 case HOSTAPD_MODE_IEEE80211B:
162 basic_rates = basic_rates_b;
164 case HOSTAPD_MODE_IEEE80211G:
165 basic_rates = basic_rates_g;
167 case HOSTAPD_MODE_IEEE80211AD:
168 return 0; /* No basic rates for 11ad */
174 while (basic_rates[i] >= 0)
177 i++; /* -1 termination */
178 os_free(iface->basic_rates);
179 iface->basic_rates = os_malloc(i * sizeof(int));
180 if (iface->basic_rates)
181 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
183 os_free(iface->current_rates);
184 iface->num_rates = 0;
186 iface->current_rates =
187 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
188 if (!iface->current_rates) {
189 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
194 for (i = 0; i < mode->num_rates; i++) {
195 struct hostapd_rate_data *rate;
197 if (iface->conf->supported_rates &&
198 !hostapd_rate_found(iface->conf->supported_rates,
202 rate = &iface->current_rates[iface->num_rates];
203 rate->rate = mode->rates[i];
204 if (hostapd_rate_found(basic_rates, rate->rate)) {
205 rate->flags |= HOSTAPD_RATE_BASIC;
208 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
209 iface->num_rates, rate->rate, rate->flags);
213 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
214 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
215 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
216 "rate sets (%d,%d).",
217 iface->num_rates, num_basic_rates);
225 #ifdef CONFIG_IEEE80211N
226 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
228 int sec_chan, ok, j, first;
229 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
233 if (!iface->conf->secondary_channel)
234 return 1; /* HT40 not used */
236 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
237 wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
238 "secondary channel: %d",
239 iface->conf->channel, sec_chan);
241 /* Verify that HT40 secondary channel is an allowed 20 MHz
244 for (j = 0; j < iface->current_mode->num_channels; j++) {
245 struct hostapd_channel_data *chan =
246 &iface->current_mode->channels[j];
247 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
248 chan->chan == sec_chan) {
254 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
260 * Verify that HT40 primary,secondary channel pair is allowed per
261 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
262 * 2.4 GHz rules allow all cases where the secondary channel fits into
263 * the list of allowed channels (already checked above).
265 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
268 if (iface->conf->secondary_channel > 0)
269 first = iface->conf->channel;
274 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
275 if (first == allowed[k]) {
281 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
282 iface->conf->channel,
283 iface->conf->secondary_channel);
291 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
293 if (iface->conf->secondary_channel > 0) {
294 iface->conf->channel += 4;
295 iface->conf->secondary_channel = -1;
297 iface->conf->channel -= 4;
298 iface->conf->secondary_channel = 1;
303 static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
304 int *pri_chan, int *sec_chan)
306 struct ieee80211_ht_operation *oper;
307 struct ieee802_11_elems elems;
309 *pri_chan = *sec_chan = 0;
311 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
312 if (elems.ht_operation &&
313 elems.ht_operation_len >= sizeof(*oper)) {
314 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
315 *pri_chan = oper->control_chan;
316 if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) {
317 int sec = oper->ht_param &
318 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
319 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
320 *sec_chan = *pri_chan + 4;
321 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
322 *sec_chan = *pri_chan - 4;
328 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
329 struct wpa_scan_results *scan_res)
331 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
332 int bss_pri_chan, bss_sec_chan;
336 pri_chan = iface->conf->channel;
337 sec_chan = iface->conf->secondary_channel * 4;
338 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
339 if (iface->conf->secondary_channel > 0)
340 sec_freq = pri_freq + 20;
342 sec_freq = pri_freq - 20;
345 * Switch PRI/SEC channels if Beacons were detected on selected SEC
346 * channel, but not on selected PRI channel.
348 pri_bss = sec_bss = 0;
349 for (i = 0; i < scan_res->num; i++) {
350 struct wpa_scan_res *bss = scan_res->res[i];
351 if (bss->freq == pri_freq)
353 else if (bss->freq == sec_freq)
356 if (sec_bss && !pri_bss) {
357 wpa_printf(MSG_INFO, "Switch own primary and secondary "
358 "channel to get secondary channel with no Beacons "
360 ieee80211n_switch_pri_sec(iface);
364 * Match PRI/SEC channel with any existing HT40 BSS on the same
365 * channels that we are about to use (if already mixed order in
366 * existing BSSes, use own preference).
369 for (i = 0; i < scan_res->num; i++) {
370 struct wpa_scan_res *bss = scan_res->res[i];
371 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
372 if (pri_chan == bss_pri_chan &&
373 sec_chan == bss_sec_chan) {
379 for (i = 0; i < scan_res->num; i++) {
380 struct wpa_scan_res *bss = scan_res->res[i];
381 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
383 if (pri_chan == bss_sec_chan &&
384 sec_chan == bss_pri_chan) {
385 wpa_printf(MSG_INFO, "Switch own primary and "
386 "secondary channel due to BSS "
387 "overlap with " MACSTR,
388 MAC2STR(bss->bssid));
389 ieee80211n_switch_pri_sec(iface);
399 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
400 struct wpa_scan_results *scan_res)
402 int pri_freq, sec_freq;
403 int affected_start, affected_end;
406 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
407 if (iface->conf->secondary_channel > 0)
408 sec_freq = pri_freq + 20;
410 sec_freq = pri_freq - 20;
411 affected_start = (pri_freq + sec_freq) / 2 - 25;
412 affected_end = (pri_freq + sec_freq) / 2 + 25;
413 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
414 affected_start, affected_end);
415 for (i = 0; i < scan_res->num; i++) {
416 struct wpa_scan_res *bss = scan_res->res[i];
419 int sec_chan, pri_chan;
421 ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
424 if (sec_chan < pri_chan)
430 if ((pri < affected_start || pri > affected_end) &&
431 (sec < affected_start || sec > affected_end))
432 continue; /* not within affected channel range */
434 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
435 " freq=%d pri=%d sec=%d",
436 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
439 if (pri_freq != pri || sec_freq != sec) {
440 wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
441 "mismatch with BSS " MACSTR
442 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
445 sec > pri ? '+' : '-',
451 /* TODO: 40 MHz intolerant */
458 static void ieee80211n_check_scan(struct hostapd_iface *iface)
460 struct wpa_scan_results *scan_res;
464 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
465 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
467 iface->scan_cb = NULL;
469 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
470 if (scan_res == NULL) {
471 hostapd_setup_interface_complete(iface, 1);
475 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
476 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
478 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
479 wpa_scan_results_free(scan_res);
482 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
483 "channel pri=%d sec=%d based on overlapping BSSes",
484 iface->conf->channel,
485 iface->conf->channel +
486 iface->conf->secondary_channel * 4);
487 iface->conf->secondary_channel = 0;
490 res = ieee80211n_allowed_ht40_channel_pair(iface);
491 hostapd_setup_interface_complete(iface, !res);
495 static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
496 struct wpa_driver_scan_params *params)
498 /* Scan only the affected frequency range */
499 int pri_freq, sec_freq;
500 int affected_start, affected_end;
502 struct hostapd_hw_modes *mode;
504 if (iface->current_mode == NULL)
507 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
508 if (iface->conf->secondary_channel > 0)
509 sec_freq = pri_freq + 20;
511 sec_freq = pri_freq - 20;
512 affected_start = (pri_freq + sec_freq) / 2 - 25;
513 affected_end = (pri_freq + sec_freq) / 2 + 25;
514 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
515 affected_start, affected_end);
517 mode = iface->current_mode;
518 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
519 if (params->freqs == NULL)
523 for (i = 0; i < mode->num_channels; i++) {
524 struct hostapd_channel_data *chan = &mode->channels[i];
525 if (chan->flag & HOSTAPD_CHAN_DISABLED)
527 if (chan->freq < affected_start ||
528 chan->freq > affected_end)
530 params->freqs[pos++] = chan->freq;
535 static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
537 struct wpa_driver_scan_params params;
539 if (!iface->conf->secondary_channel)
540 return 0; /* HT40 not used */
542 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
544 os_memset(¶ms, 0, sizeof(params));
545 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
546 ieee80211n_scan_channels_2g4(iface, ¶ms);
547 if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) {
548 wpa_printf(MSG_ERROR, "Failed to request a scan of "
549 "neighboring BSSes");
550 os_free(params.freqs);
553 os_free(params.freqs);
555 iface->scan_cb = ieee80211n_check_scan;
560 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
562 u16 hw = iface->current_mode->ht_capab;
563 u16 conf = iface->conf->ht_capab;
565 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
566 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
567 wpa_printf(MSG_ERROR, "Driver does not support configured "
568 "HT capability [LDPC]");
572 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
573 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
574 wpa_printf(MSG_ERROR, "Driver does not support configured "
575 "HT capability [HT40*]");
579 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
580 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
581 wpa_printf(MSG_ERROR, "Driver does not support configured "
582 "HT capability [SMPS-*]");
586 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
587 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
588 wpa_printf(MSG_ERROR, "Driver does not support configured "
589 "HT capability [GF]");
593 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
594 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
595 wpa_printf(MSG_ERROR, "Driver does not support configured "
596 "HT capability [SHORT-GI-20]");
600 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
601 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
602 wpa_printf(MSG_ERROR, "Driver does not support configured "
603 "HT capability [SHORT-GI-40]");
607 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
608 wpa_printf(MSG_ERROR, "Driver does not support configured "
609 "HT capability [TX-STBC]");
613 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
614 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
615 wpa_printf(MSG_ERROR, "Driver does not support configured "
616 "HT capability [RX-STBC*]");
620 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
621 !(hw & HT_CAP_INFO_DELAYED_BA)) {
622 wpa_printf(MSG_ERROR, "Driver does not support configured "
623 "HT capability [DELAYED-BA]");
627 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
628 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
629 wpa_printf(MSG_ERROR, "Driver does not support configured "
630 "HT capability [MAX-AMSDU-7935]");
634 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
635 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
636 wpa_printf(MSG_ERROR, "Driver does not support configured "
637 "HT capability [DSSS_CCK-40]");
641 if ((conf & HT_CAP_INFO_PSMP_SUPP) && !(hw & HT_CAP_INFO_PSMP_SUPP)) {
642 wpa_printf(MSG_ERROR, "Driver does not support configured "
643 "HT capability [PSMP]");
647 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
648 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
649 wpa_printf(MSG_ERROR, "Driver does not support configured "
650 "HT capability [LSIG-TXOP-PROT]");
658 #ifdef CONFIG_IEEE80211AC
660 static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
662 u32 req_cap = conf & cap;
665 * Make sure we support all requested capabilities.
666 * NOTE: We assume that 'cap' represents a capability mask,
667 * not a discrete value.
669 if ((hw & req_cap) != req_cap) {
670 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
678 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap,
681 u32 hw_max = hw & cap;
682 u32 conf_val = conf & cap;
684 if (conf_val > hw_max) {
685 int offset = find_first_bit(cap);
686 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
687 name, conf_val >> offset, hw_max >> offset);
694 static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
696 u32 hw = iface->current_mode->vht_capab;
697 u32 conf = iface->conf->vht_capab;
699 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
702 #define VHT_CAP_CHECK(cap) \
704 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
708 #define VHT_CAP_CHECK_MAX(cap) \
710 if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \
714 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
715 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
716 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
717 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
718 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
719 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
720 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
721 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
722 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
723 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
724 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
725 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
726 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
727 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
728 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
729 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
730 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT);
731 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
732 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
733 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
734 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
737 #undef VHT_CAP_CHECK_MAX
741 #endif /* CONFIG_IEEE80211AC */
743 #endif /* CONFIG_IEEE80211N */
746 int hostapd_check_ht_capab(struct hostapd_iface *iface)
748 #ifdef CONFIG_IEEE80211N
750 if (!iface->conf->ieee80211n)
752 if (!ieee80211n_supported_ht_capab(iface))
754 #ifdef CONFIG_IEEE80211AC
755 if (!ieee80211ac_supported_vht_capab(iface))
757 #endif /* CONFIG_IEEE80211AC */
758 ret = ieee80211n_check_40mhz(iface);
761 if (!ieee80211n_allowed_ht40_channel_pair(iface))
763 #endif /* CONFIG_IEEE80211N */
769 static int hostapd_is_usable_chan(struct hostapd_iface *iface,
770 int channel, int primary)
773 struct hostapd_channel_data *chan;
775 for (i = 0; i < iface->current_mode->num_channels; i++) {
776 chan = &iface->current_mode->channels[i];
777 if (chan->chan != channel)
780 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
783 wpa_printf(MSG_DEBUG,
784 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s",
785 primary ? "" : "Configured HT40 secondary ",
786 i, chan->chan, chan->flag,
787 chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "",
788 chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ?
789 " PASSIVE-SCAN" : "",
790 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
797 static int hostapd_is_usable_chans(struct hostapd_iface *iface)
799 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
802 if (!iface->conf->secondary_channel)
805 return hostapd_is_usable_chan(iface, iface->conf->channel +
806 iface->conf->secondary_channel * 4, 0);
810 static enum hostapd_chan_status
811 hostapd_check_chans(struct hostapd_iface *iface)
813 if (iface->conf->channel) {
814 if (hostapd_is_usable_chans(iface))
815 return HOSTAPD_CHAN_VALID;
817 return HOSTAPD_CHAN_INVALID;
821 * The user set channel=0 or channel=acs_survey
822 * which is used to trigger ACS.
825 switch (acs_init(iface)) {
826 case HOSTAPD_CHAN_ACS:
827 return HOSTAPD_CHAN_ACS;
828 case HOSTAPD_CHAN_VALID:
829 case HOSTAPD_CHAN_INVALID:
831 return HOSTAPD_CHAN_INVALID;
836 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
838 hostapd_logger(iface->bss[0], NULL,
839 HOSTAPD_MODULE_IEEE80211,
840 HOSTAPD_LEVEL_WARNING,
841 "Configured channel (%d) not found from the "
842 "channel list of current mode (%d) %s",
843 iface->conf->channel,
844 iface->current_mode->mode,
845 hostapd_hw_mode_txt(iface->current_mode->mode));
846 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
847 HOSTAPD_LEVEL_WARNING,
848 "Hardware does not support configured channel");
852 int hostapd_acs_completed(struct hostapd_iface *iface, int err)
859 switch (hostapd_check_chans(iface)) {
860 case HOSTAPD_CHAN_VALID:
861 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
862 ACS_EVENT_COMPLETED "freq=%d channel=%d",
863 hostapd_hw_get_freq(iface->bss[0],
864 iface->conf->channel),
865 iface->conf->channel);
867 case HOSTAPD_CHAN_ACS:
868 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
869 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
870 hostapd_notify_bad_chans(iface);
872 case HOSTAPD_CHAN_INVALID:
874 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
875 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
876 hostapd_notify_bad_chans(iface);
880 ret = hostapd_check_ht_capab(iface);
884 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
890 return hostapd_setup_interface_complete(iface, ret);
895 * hostapd_select_hw_mode - Select the hardware mode
896 * @iface: Pointer to interface data.
897 * Returns: 0 on success, < 0 on failure
899 * Sets up the hardware mode, channel, rates, and passive scanning
900 * based on the configuration.
902 int hostapd_select_hw_mode(struct hostapd_iface *iface)
906 if (iface->num_hw_features < 1)
909 iface->current_mode = NULL;
910 for (i = 0; i < iface->num_hw_features; i++) {
911 struct hostapd_hw_modes *mode = &iface->hw_features[i];
912 if (mode->mode == iface->conf->hw_mode) {
913 iface->current_mode = mode;
918 if (iface->current_mode == NULL) {
919 wpa_printf(MSG_ERROR, "Hardware does not support configured "
921 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
922 HOSTAPD_LEVEL_WARNING,
923 "Hardware does not support configured mode "
924 "(%d) (hw_mode in hostapd.conf)",
925 (int) iface->conf->hw_mode);
929 switch (hostapd_check_chans(iface)) {
930 case HOSTAPD_CHAN_VALID:
932 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
934 case HOSTAPD_CHAN_INVALID:
936 hostapd_notify_bad_chans(iface);
944 const char * hostapd_hw_mode_txt(int mode)
947 case HOSTAPD_MODE_IEEE80211A:
948 return "IEEE 802.11a";
949 case HOSTAPD_MODE_IEEE80211B:
950 return "IEEE 802.11b";
951 case HOSTAPD_MODE_IEEE80211G:
952 return "IEEE 802.11g";
953 case HOSTAPD_MODE_IEEE80211AD:
954 return "IEEE 802.11ad";
961 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
965 if (!hapd->iface->current_mode)
968 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
969 struct hostapd_channel_data *ch =
970 &hapd->iface->current_mode->channels[i];
971 if (ch->chan == chan)
979 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
983 if (!hapd->iface->current_mode)
986 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
987 struct hostapd_channel_data *ch =
988 &hapd->iface->current_mode->channels[i];
989 if (ch->freq == freq)