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_NO_IBSS |
116 HOSTAPD_CHAN_PASSIVE_SCAN |
117 HOSTAPD_CHAN_RADAR)) {
118 feature->channels[j].flag |=
119 HOSTAPD_CHAN_DISABLED;
122 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
125 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
126 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
128 feature->channels[j].chan,
129 feature->channels[j].freq,
130 feature->channels[j].max_tx_power,
131 dfs ? dfs_info(&feature->channels[j]) : "");
139 int hostapd_prepare_rates(struct hostapd_iface *iface,
140 struct hostapd_hw_modes *mode)
142 int i, num_basic_rates = 0;
143 int basic_rates_a[] = { 60, 120, 240, -1 };
144 int basic_rates_b[] = { 10, 20, -1 };
145 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
148 if (iface->conf->basic_rates)
149 basic_rates = iface->conf->basic_rates;
150 else switch (mode->mode) {
151 case HOSTAPD_MODE_IEEE80211A:
152 basic_rates = basic_rates_a;
154 case HOSTAPD_MODE_IEEE80211B:
155 basic_rates = basic_rates_b;
157 case HOSTAPD_MODE_IEEE80211G:
158 basic_rates = basic_rates_g;
160 case HOSTAPD_MODE_IEEE80211AD:
161 return 0; /* No basic rates for 11ad */
167 while (basic_rates[i] >= 0)
170 i++; /* -1 termination */
171 os_free(iface->basic_rates);
172 iface->basic_rates = os_malloc(i * sizeof(int));
173 if (iface->basic_rates)
174 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
176 os_free(iface->current_rates);
177 iface->num_rates = 0;
179 iface->current_rates =
180 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
181 if (!iface->current_rates) {
182 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
187 for (i = 0; i < mode->num_rates; i++) {
188 struct hostapd_rate_data *rate;
190 if (iface->conf->supported_rates &&
191 !hostapd_rate_found(iface->conf->supported_rates,
195 rate = &iface->current_rates[iface->num_rates];
196 rate->rate = mode->rates[i];
197 if (hostapd_rate_found(basic_rates, rate->rate)) {
198 rate->flags |= HOSTAPD_RATE_BASIC;
201 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
202 iface->num_rates, rate->rate, rate->flags);
206 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
207 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
208 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
209 "rate sets (%d,%d).",
210 iface->num_rates, num_basic_rates);
218 #ifdef CONFIG_IEEE80211N
219 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
221 int sec_chan, ok, j, first;
222 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
226 if (!iface->conf->secondary_channel)
227 return 1; /* HT40 not used */
229 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
230 wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
231 "secondary channel: %d",
232 iface->conf->channel, sec_chan);
234 /* Verify that HT40 secondary channel is an allowed 20 MHz
237 for (j = 0; j < iface->current_mode->num_channels; j++) {
238 struct hostapd_channel_data *chan =
239 &iface->current_mode->channels[j];
240 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
241 chan->chan == sec_chan) {
247 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
253 * Verify that HT40 primary,secondary channel pair is allowed per
254 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
255 * 2.4 GHz rules allow all cases where the secondary channel fits into
256 * the list of allowed channels (already checked above).
258 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
261 if (iface->conf->secondary_channel > 0)
262 first = iface->conf->channel;
267 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
268 if (first == allowed[k]) {
274 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
275 iface->conf->channel,
276 iface->conf->secondary_channel);
284 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
286 if (iface->conf->secondary_channel > 0) {
287 iface->conf->channel += 4;
288 iface->conf->secondary_channel = -1;
290 iface->conf->channel -= 4;
291 iface->conf->secondary_channel = 1;
296 static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
297 int *pri_chan, int *sec_chan)
299 struct ieee80211_ht_operation *oper;
300 struct ieee802_11_elems elems;
302 *pri_chan = *sec_chan = 0;
304 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
305 if (elems.ht_operation &&
306 elems.ht_operation_len >= sizeof(*oper)) {
307 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
308 *pri_chan = oper->control_chan;
309 if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) {
310 int sec = oper->ht_param &
311 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
312 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
313 *sec_chan = *pri_chan + 4;
314 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
315 *sec_chan = *pri_chan - 4;
321 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
322 struct wpa_scan_results *scan_res)
324 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
325 int bss_pri_chan, bss_sec_chan;
329 pri_chan = iface->conf->channel;
330 sec_chan = iface->conf->secondary_channel * 4;
331 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
332 if (iface->conf->secondary_channel > 0)
333 sec_freq = pri_freq + 20;
335 sec_freq = pri_freq - 20;
338 * Switch PRI/SEC channels if Beacons were detected on selected SEC
339 * channel, but not on selected PRI channel.
341 pri_bss = sec_bss = 0;
342 for (i = 0; i < scan_res->num; i++) {
343 struct wpa_scan_res *bss = scan_res->res[i];
344 if (bss->freq == pri_freq)
346 else if (bss->freq == sec_freq)
349 if (sec_bss && !pri_bss) {
350 wpa_printf(MSG_INFO, "Switch own primary and secondary "
351 "channel to get secondary channel with no Beacons "
353 ieee80211n_switch_pri_sec(iface);
357 * Match PRI/SEC channel with any existing HT40 BSS on the same
358 * channels that we are about to use (if already mixed order in
359 * existing BSSes, use own preference).
362 for (i = 0; i < scan_res->num; i++) {
363 struct wpa_scan_res *bss = scan_res->res[i];
364 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
365 if (pri_chan == bss_pri_chan &&
366 sec_chan == bss_sec_chan) {
372 for (i = 0; i < scan_res->num; i++) {
373 struct wpa_scan_res *bss = scan_res->res[i];
374 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
376 if (pri_chan == bss_sec_chan &&
377 sec_chan == bss_pri_chan) {
378 wpa_printf(MSG_INFO, "Switch own primary and "
379 "secondary channel due to BSS "
380 "overlap with " MACSTR,
381 MAC2STR(bss->bssid));
382 ieee80211n_switch_pri_sec(iface);
392 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
393 struct wpa_scan_results *scan_res)
395 int pri_freq, sec_freq;
396 int affected_start, affected_end;
399 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
400 if (iface->conf->secondary_channel > 0)
401 sec_freq = pri_freq + 20;
403 sec_freq = pri_freq - 20;
404 affected_start = (pri_freq + sec_freq) / 2 - 25;
405 affected_end = (pri_freq + sec_freq) / 2 + 25;
406 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
407 affected_start, affected_end);
408 for (i = 0; i < scan_res->num; i++) {
409 struct wpa_scan_res *bss = scan_res->res[i];
412 int sec_chan, pri_chan;
414 ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
417 if (sec_chan < pri_chan)
423 if ((pri < affected_start || pri > affected_end) &&
424 (sec < affected_start || sec > affected_end))
425 continue; /* not within affected channel range */
427 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
428 " freq=%d pri=%d sec=%d",
429 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
432 if (pri_freq != pri || sec_freq != sec) {
433 wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
434 "mismatch with BSS " MACSTR
435 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
438 sec > pri ? '+' : '-',
444 /* TODO: 40 MHz intolerant */
451 static void ieee80211n_check_scan(struct hostapd_iface *iface)
453 struct wpa_scan_results *scan_res;
457 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
458 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
460 iface->scan_cb = NULL;
462 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
463 if (scan_res == NULL) {
464 hostapd_setup_interface_complete(iface, 1);
468 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
469 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
471 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
472 wpa_scan_results_free(scan_res);
475 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
476 "channel pri=%d sec=%d based on overlapping BSSes",
477 iface->conf->channel,
478 iface->conf->channel +
479 iface->conf->secondary_channel * 4);
480 iface->conf->secondary_channel = 0;
483 res = ieee80211n_allowed_ht40_channel_pair(iface);
484 hostapd_setup_interface_complete(iface, !res);
488 static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
489 struct wpa_driver_scan_params *params)
491 /* Scan only the affected frequency range */
492 int pri_freq, sec_freq;
493 int affected_start, affected_end;
495 struct hostapd_hw_modes *mode;
497 if (iface->current_mode == NULL)
500 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
501 if (iface->conf->secondary_channel > 0)
502 sec_freq = pri_freq + 20;
504 sec_freq = pri_freq - 20;
505 affected_start = (pri_freq + sec_freq) / 2 - 25;
506 affected_end = (pri_freq + sec_freq) / 2 + 25;
507 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
508 affected_start, affected_end);
510 mode = iface->current_mode;
511 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
512 if (params->freqs == NULL)
516 for (i = 0; i < mode->num_channels; i++) {
517 struct hostapd_channel_data *chan = &mode->channels[i];
518 if (chan->flag & HOSTAPD_CHAN_DISABLED)
520 if (chan->freq < affected_start ||
521 chan->freq > affected_end)
523 params->freqs[pos++] = chan->freq;
528 static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
529 struct wpa_driver_scan_params *params)
531 /* Scan only the affected frequency range */
533 int affected_start, affected_end;
535 struct hostapd_hw_modes *mode;
537 if (iface->current_mode == NULL)
540 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
541 if (iface->conf->secondary_channel > 0) {
542 affected_start = pri_freq - 10;
543 affected_end = pri_freq + 30;
545 affected_start = pri_freq - 30;
546 affected_end = pri_freq + 10;
548 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
549 affected_start, affected_end);
551 mode = iface->current_mode;
552 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
553 if (params->freqs == NULL)
557 for (i = 0; i < mode->num_channels; i++) {
558 struct hostapd_channel_data *chan = &mode->channels[i];
559 if (chan->flag & HOSTAPD_CHAN_DISABLED)
561 if (chan->freq < affected_start ||
562 chan->freq > affected_end)
564 params->freqs[pos++] = chan->freq;
569 static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
571 struct wpa_driver_scan_params params;
573 if (!iface->conf->secondary_channel)
574 return 0; /* HT40 not used */
576 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
577 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
579 os_memset(¶ms, 0, sizeof(params));
580 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
581 ieee80211n_scan_channels_2g4(iface, ¶ms);
583 ieee80211n_scan_channels_5g(iface, ¶ms);
584 if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) {
585 wpa_printf(MSG_ERROR, "Failed to request a scan of "
586 "neighboring BSSes");
587 os_free(params.freqs);
590 os_free(params.freqs);
592 iface->scan_cb = ieee80211n_check_scan;
597 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
599 u16 hw = iface->current_mode->ht_capab;
600 u16 conf = iface->conf->ht_capab;
602 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
603 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
604 wpa_printf(MSG_ERROR, "Driver does not support configured "
605 "HT capability [LDPC]");
609 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
610 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
611 wpa_printf(MSG_ERROR, "Driver does not support configured "
612 "HT capability [HT40*]");
616 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
617 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
618 wpa_printf(MSG_ERROR, "Driver does not support configured "
619 "HT capability [SMPS-*]");
623 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
624 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
625 wpa_printf(MSG_ERROR, "Driver does not support configured "
626 "HT capability [GF]");
630 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
631 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
632 wpa_printf(MSG_ERROR, "Driver does not support configured "
633 "HT capability [SHORT-GI-20]");
637 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
638 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
639 wpa_printf(MSG_ERROR, "Driver does not support configured "
640 "HT capability [SHORT-GI-40]");
644 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
645 wpa_printf(MSG_ERROR, "Driver does not support configured "
646 "HT capability [TX-STBC]");
650 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
651 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
652 wpa_printf(MSG_ERROR, "Driver does not support configured "
653 "HT capability [RX-STBC*]");
657 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
658 !(hw & HT_CAP_INFO_DELAYED_BA)) {
659 wpa_printf(MSG_ERROR, "Driver does not support configured "
660 "HT capability [DELAYED-BA]");
664 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
665 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
666 wpa_printf(MSG_ERROR, "Driver does not support configured "
667 "HT capability [MAX-AMSDU-7935]");
671 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
672 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
673 wpa_printf(MSG_ERROR, "Driver does not support configured "
674 "HT capability [DSSS_CCK-40]");
678 if ((conf & HT_CAP_INFO_PSMP_SUPP) && !(hw & HT_CAP_INFO_PSMP_SUPP)) {
679 wpa_printf(MSG_ERROR, "Driver does not support configured "
680 "HT capability [PSMP]");
684 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
685 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
686 wpa_printf(MSG_ERROR, "Driver does not support configured "
687 "HT capability [LSIG-TXOP-PROT]");
695 #ifdef CONFIG_IEEE80211AC
697 static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
699 u32 req_cap = conf & cap;
702 * Make sure we support all requested capabilities.
703 * NOTE: We assume that 'cap' represents a capability mask,
704 * not a discrete value.
706 if ((hw & req_cap) != req_cap) {
707 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
715 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap,
718 u32 hw_max = hw & cap;
719 u32 conf_val = conf & cap;
721 if (conf_val > hw_max) {
722 int offset = find_first_bit(cap);
723 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
724 name, conf_val >> offset, hw_max >> offset);
731 static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
733 u32 hw = iface->current_mode->vht_capab;
734 u32 conf = iface->conf->vht_capab;
736 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
739 #define VHT_CAP_CHECK(cap) \
741 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
745 #define VHT_CAP_CHECK_MAX(cap) \
747 if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \
751 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
752 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
753 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
754 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
755 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
756 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
757 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
758 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
759 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
760 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
761 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
762 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
763 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
764 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
765 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
766 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
767 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT);
768 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
769 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
770 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
771 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
774 #undef VHT_CAP_CHECK_MAX
778 #endif /* CONFIG_IEEE80211AC */
780 #endif /* CONFIG_IEEE80211N */
783 int hostapd_check_ht_capab(struct hostapd_iface *iface)
785 #ifdef CONFIG_IEEE80211N
787 if (!iface->conf->ieee80211n)
789 if (!ieee80211n_supported_ht_capab(iface))
791 #ifdef CONFIG_IEEE80211AC
792 if (!ieee80211ac_supported_vht_capab(iface))
794 #endif /* CONFIG_IEEE80211AC */
795 ret = ieee80211n_check_40mhz(iface);
798 if (!ieee80211n_allowed_ht40_channel_pair(iface))
800 #endif /* CONFIG_IEEE80211N */
806 static int hostapd_is_usable_chan(struct hostapd_iface *iface,
807 int channel, int primary)
810 struct hostapd_channel_data *chan;
812 for (i = 0; i < iface->current_mode->num_channels; i++) {
813 chan = &iface->current_mode->channels[i];
814 if (chan->chan != channel)
817 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
820 wpa_printf(MSG_DEBUG,
821 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s",
822 primary ? "" : "Configured HT40 secondary ",
823 i, chan->chan, chan->flag,
824 chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "",
825 chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ?
826 " PASSIVE-SCAN" : "",
827 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
834 static int hostapd_is_usable_chans(struct hostapd_iface *iface)
836 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
839 if (!iface->conf->secondary_channel)
842 return hostapd_is_usable_chan(iface, iface->conf->channel +
843 iface->conf->secondary_channel * 4, 0);
847 static enum hostapd_chan_status
848 hostapd_check_chans(struct hostapd_iface *iface)
850 if (iface->conf->channel) {
851 if (hostapd_is_usable_chans(iface))
852 return HOSTAPD_CHAN_VALID;
854 return HOSTAPD_CHAN_INVALID;
858 * The user set channel=0 or channel=acs_survey
859 * which is used to trigger ACS.
862 switch (acs_init(iface)) {
863 case HOSTAPD_CHAN_ACS:
864 return HOSTAPD_CHAN_ACS;
865 case HOSTAPD_CHAN_VALID:
866 case HOSTAPD_CHAN_INVALID:
868 return HOSTAPD_CHAN_INVALID;
873 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
875 hostapd_logger(iface->bss[0], NULL,
876 HOSTAPD_MODULE_IEEE80211,
877 HOSTAPD_LEVEL_WARNING,
878 "Configured channel (%d) not found from the "
879 "channel list of current mode (%d) %s",
880 iface->conf->channel,
881 iface->current_mode->mode,
882 hostapd_hw_mode_txt(iface->current_mode->mode));
883 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
884 HOSTAPD_LEVEL_WARNING,
885 "Hardware does not support configured channel");
889 int hostapd_acs_completed(struct hostapd_iface *iface, int err)
896 switch (hostapd_check_chans(iface)) {
897 case HOSTAPD_CHAN_VALID:
898 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
899 ACS_EVENT_COMPLETED "freq=%d channel=%d",
900 hostapd_hw_get_freq(iface->bss[0],
901 iface->conf->channel),
902 iface->conf->channel);
904 case HOSTAPD_CHAN_ACS:
905 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
906 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
907 hostapd_notify_bad_chans(iface);
909 case HOSTAPD_CHAN_INVALID:
911 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
912 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
913 hostapd_notify_bad_chans(iface);
917 ret = hostapd_check_ht_capab(iface);
921 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
927 return hostapd_setup_interface_complete(iface, ret);
932 * hostapd_select_hw_mode - Select the hardware mode
933 * @iface: Pointer to interface data.
934 * Returns: 0 on success, < 0 on failure
936 * Sets up the hardware mode, channel, rates, and passive scanning
937 * based on the configuration.
939 int hostapd_select_hw_mode(struct hostapd_iface *iface)
943 if (iface->num_hw_features < 1)
946 iface->current_mode = NULL;
947 for (i = 0; i < iface->num_hw_features; i++) {
948 struct hostapd_hw_modes *mode = &iface->hw_features[i];
949 if (mode->mode == iface->conf->hw_mode) {
950 iface->current_mode = mode;
955 if (iface->current_mode == NULL) {
956 wpa_printf(MSG_ERROR, "Hardware does not support configured "
958 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
959 HOSTAPD_LEVEL_WARNING,
960 "Hardware does not support configured mode "
961 "(%d) (hw_mode in hostapd.conf)",
962 (int) iface->conf->hw_mode);
966 switch (hostapd_check_chans(iface)) {
967 case HOSTAPD_CHAN_VALID:
969 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
971 case HOSTAPD_CHAN_INVALID:
973 hostapd_notify_bad_chans(iface);
981 const char * hostapd_hw_mode_txt(int mode)
984 case HOSTAPD_MODE_IEEE80211A:
985 return "IEEE 802.11a";
986 case HOSTAPD_MODE_IEEE80211B:
987 return "IEEE 802.11b";
988 case HOSTAPD_MODE_IEEE80211G:
989 return "IEEE 802.11g";
990 case HOSTAPD_MODE_IEEE80211AD:
991 return "IEEE 802.11ad";
998 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1002 if (!hapd->iface->current_mode)
1005 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1006 struct hostapd_channel_data *ch =
1007 &hapd->iface->current_mode->channels[i];
1008 if (ch->chan == chan)
1016 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1020 if (!hapd->iface->current_mode)
1023 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1024 struct hostapd_channel_data *ch =
1025 &hapd->iface->current_mode->channels[i];
1026 if (ch->freq == freq)