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 "ieee802_11.h"
24 #include "hw_features.h"
27 void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
28 size_t num_hw_features)
32 if (hw_features == NULL)
35 for (i = 0; i < num_hw_features; i++) {
36 os_free(hw_features[i].channels);
37 os_free(hw_features[i].rates);
44 #ifndef CONFIG_NO_STDOUT_DEBUG
45 static char * dfs_info(struct hostapd_channel_data *chan)
47 static char info[256];
50 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
51 case HOSTAPD_CHAN_DFS_UNKNOWN:
54 case HOSTAPD_CHAN_DFS_USABLE:
57 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
58 state = "unavailable";
60 case HOSTAPD_CHAN_DFS_AVAILABLE:
66 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
67 info[sizeof(info) - 1] = '\0';
71 #endif /* CONFIG_NO_STDOUT_DEBUG */
74 int hostapd_get_hw_features(struct hostapd_iface *iface)
76 struct hostapd_data *hapd = iface->bss[0];
79 struct hostapd_hw_modes *modes;
81 if (hostapd_drv_none(hapd))
83 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
85 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
87 "Fetching hardware channel/rate support not "
92 iface->hw_flags = flags;
94 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
95 iface->hw_features = modes;
96 iface->num_hw_features = num_modes;
98 for (i = 0; i < num_modes; i++) {
99 struct hostapd_hw_modes *feature = &modes[i];
100 int dfs_enabled = hapd->iconf->ieee80211h &&
101 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
103 /* set flag for channels we can use in current regulatory
105 for (j = 0; j < feature->num_channels; j++) {
109 * Disable all channels that are marked not to allow
110 * IBSS operation or active scanning.
111 * Use radar channels only if the driver supports DFS.
113 if ((feature->channels[j].flag &
114 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
116 } else if (((feature->channels[j].flag &
117 HOSTAPD_CHAN_RADAR) &&
119 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
120 (feature->channels[j].flag &
121 (HOSTAPD_CHAN_NO_IBSS |
122 HOSTAPD_CHAN_PASSIVE_SCAN))) {
123 feature->channels[j].flag |=
124 HOSTAPD_CHAN_DISABLED;
127 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
130 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
131 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
133 feature->channels[j].chan,
134 feature->channels[j].freq,
135 feature->channels[j].max_tx_power,
136 dfs ? dfs_info(&feature->channels[j]) : "");
144 int hostapd_prepare_rates(struct hostapd_iface *iface,
145 struct hostapd_hw_modes *mode)
147 int i, num_basic_rates = 0;
148 int basic_rates_a[] = { 60, 120, 240, -1 };
149 int basic_rates_b[] = { 10, 20, -1 };
150 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
153 if (iface->conf->basic_rates)
154 basic_rates = iface->conf->basic_rates;
155 else switch (mode->mode) {
156 case HOSTAPD_MODE_IEEE80211A:
157 basic_rates = basic_rates_a;
159 case HOSTAPD_MODE_IEEE80211B:
160 basic_rates = basic_rates_b;
162 case HOSTAPD_MODE_IEEE80211G:
163 basic_rates = basic_rates_g;
165 case HOSTAPD_MODE_IEEE80211AD:
166 return 0; /* No basic rates for 11ad */
172 while (basic_rates[i] >= 0)
175 i++; /* -1 termination */
176 os_free(iface->basic_rates);
177 iface->basic_rates = os_malloc(i * sizeof(int));
178 if (iface->basic_rates)
179 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
181 os_free(iface->current_rates);
182 iface->num_rates = 0;
184 iface->current_rates =
185 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
186 if (!iface->current_rates) {
187 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
192 for (i = 0; i < mode->num_rates; i++) {
193 struct hostapd_rate_data *rate;
195 if (iface->conf->supported_rates &&
196 !hostapd_rate_found(iface->conf->supported_rates,
200 rate = &iface->current_rates[iface->num_rates];
201 rate->rate = mode->rates[i];
202 if (hostapd_rate_found(basic_rates, rate->rate)) {
203 rate->flags |= HOSTAPD_RATE_BASIC;
206 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
207 iface->num_rates, rate->rate, rate->flags);
211 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
212 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
213 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
214 "rate sets (%d,%d).",
215 iface->num_rates, num_basic_rates);
223 #ifdef CONFIG_IEEE80211N
224 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
226 int sec_chan, ok, j, first;
227 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
231 if (!iface->conf->secondary_channel)
232 return 1; /* HT40 not used */
234 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
235 wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
236 "secondary channel: %d",
237 iface->conf->channel, sec_chan);
239 /* Verify that HT40 secondary channel is an allowed 20 MHz
242 for (j = 0; j < iface->current_mode->num_channels; j++) {
243 struct hostapd_channel_data *chan =
244 &iface->current_mode->channels[j];
245 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
246 chan->chan == sec_chan) {
252 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
258 * Verify that HT40 primary,secondary channel pair is allowed per
259 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
260 * 2.4 GHz rules allow all cases where the secondary channel fits into
261 * the list of allowed channels (already checked above).
263 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
266 if (iface->conf->secondary_channel > 0)
267 first = iface->conf->channel;
272 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
273 if (first == allowed[k]) {
279 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
280 iface->conf->channel,
281 iface->conf->secondary_channel);
289 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
291 if (iface->conf->secondary_channel > 0) {
292 iface->conf->channel += 4;
293 iface->conf->secondary_channel = -1;
295 iface->conf->channel -= 4;
296 iface->conf->secondary_channel = 1;
301 static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
302 int *pri_chan, int *sec_chan)
304 struct ieee80211_ht_operation *oper;
305 struct ieee802_11_elems elems;
307 *pri_chan = *sec_chan = 0;
309 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
310 if (elems.ht_operation &&
311 elems.ht_operation_len >= sizeof(*oper)) {
312 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
313 *pri_chan = oper->primary_chan;
314 if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
315 int sec = oper->ht_param &
316 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
317 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
318 *sec_chan = *pri_chan + 4;
319 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
320 *sec_chan = *pri_chan - 4;
326 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
327 struct wpa_scan_results *scan_res)
329 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
330 int bss_pri_chan, bss_sec_chan;
334 pri_chan = iface->conf->channel;
335 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
336 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
337 if (iface->conf->secondary_channel > 0)
338 sec_freq = pri_freq + 20;
340 sec_freq = pri_freq - 20;
343 * Switch PRI/SEC channels if Beacons were detected on selected SEC
344 * channel, but not on selected PRI channel.
346 pri_bss = sec_bss = 0;
347 for (i = 0; i < scan_res->num; i++) {
348 struct wpa_scan_res *bss = scan_res->res[i];
349 if (bss->freq == pri_freq)
351 else if (bss->freq == sec_freq)
354 if (sec_bss && !pri_bss) {
355 wpa_printf(MSG_INFO, "Switch own primary and secondary "
356 "channel to get secondary channel with no Beacons "
358 ieee80211n_switch_pri_sec(iface);
363 * Match PRI/SEC channel with any existing HT40 BSS on the same
364 * channels that we are about to use (if already mixed order in
365 * existing BSSes, use own preference).
368 for (i = 0; i < scan_res->num; i++) {
369 struct wpa_scan_res *bss = scan_res->res[i];
370 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
371 if (pri_chan == bss_pri_chan &&
372 sec_chan == bss_sec_chan) {
378 for (i = 0; i < scan_res->num; i++) {
379 struct wpa_scan_res *bss = scan_res->res[i];
380 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
382 if (pri_chan == bss_sec_chan &&
383 sec_chan == bss_pri_chan) {
384 wpa_printf(MSG_INFO, "Switch own primary and "
385 "secondary channel due to BSS "
386 "overlap with " MACSTR,
387 MAC2STR(bss->bssid));
388 ieee80211n_switch_pri_sec(iface);
398 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
399 struct wpa_scan_results *scan_res)
401 int pri_freq, sec_freq;
402 int affected_start, affected_end;
405 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
406 if (iface->conf->secondary_channel > 0)
407 sec_freq = pri_freq + 20;
409 sec_freq = pri_freq - 20;
410 affected_start = (pri_freq + sec_freq) / 2 - 25;
411 affected_end = (pri_freq + sec_freq) / 2 + 25;
412 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
413 affected_start, affected_end);
414 for (i = 0; i < scan_res->num; i++) {
415 struct wpa_scan_res *bss = scan_res->res[i];
418 int sec_chan, pri_chan;
419 struct ieee802_11_elems elems;
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 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
453 if (elems.ht_capabilities &&
454 elems.ht_capabilities_len >=
455 sizeof(struct ieee80211_ht_capabilities)) {
456 struct ieee80211_ht_capabilities *ht_cap =
457 (struct ieee80211_ht_capabilities *)
458 elems.ht_capabilities;
460 if (le_to_host16(ht_cap->ht_capabilities_info) &
461 HT_CAP_INFO_40MHZ_INTOLERANT) {
462 wpa_printf(MSG_DEBUG,
463 "40 MHz Intolerant is set on channel %d in BSS "
464 MACSTR, pri, MAC2STR(bss->bssid));
474 static void ieee80211n_check_scan(struct hostapd_iface *iface)
476 struct wpa_scan_results *scan_res;
480 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
481 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
483 iface->scan_cb = NULL;
485 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
486 if (scan_res == NULL) {
487 hostapd_setup_interface_complete(iface, 1);
491 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
492 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
494 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
495 wpa_scan_results_free(scan_res);
497 iface->secondary_ch = iface->conf->secondary_channel;
499 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
500 "channel pri=%d sec=%d based on overlapping BSSes",
501 iface->conf->channel,
502 iface->conf->channel +
503 iface->conf->secondary_channel * 4);
504 iface->conf->secondary_channel = 0;
505 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
507 * TODO: Could consider scheduling another scan to check
508 * if channel width can be changed if no coex reports
509 * are received from associating stations.
514 res = ieee80211n_allowed_ht40_channel_pair(iface);
516 iface->conf->secondary_channel = 0;
517 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
520 hostapd_setup_interface_complete(iface, !res);
524 static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
525 struct wpa_driver_scan_params *params)
527 /* Scan only the affected frequency range */
528 int pri_freq, sec_freq;
529 int affected_start, affected_end;
531 struct hostapd_hw_modes *mode;
533 if (iface->current_mode == NULL)
536 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
537 if (iface->conf->secondary_channel > 0)
538 sec_freq = pri_freq + 20;
540 sec_freq = pri_freq - 20;
541 affected_start = (pri_freq + sec_freq) / 2 - 25;
542 affected_end = (pri_freq + sec_freq) / 2 + 25;
543 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
544 affected_start, affected_end);
546 mode = iface->current_mode;
547 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
548 if (params->freqs == NULL)
552 for (i = 0; i < mode->num_channels; i++) {
553 struct hostapd_channel_data *chan = &mode->channels[i];
554 if (chan->flag & HOSTAPD_CHAN_DISABLED)
556 if (chan->freq < affected_start ||
557 chan->freq > affected_end)
559 params->freqs[pos++] = chan->freq;
564 static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
565 struct wpa_driver_scan_params *params)
567 /* Scan only the affected frequency range */
569 int affected_start, affected_end;
571 struct hostapd_hw_modes *mode;
573 if (iface->current_mode == NULL)
576 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
577 if (iface->conf->secondary_channel > 0) {
578 affected_start = pri_freq - 10;
579 affected_end = pri_freq + 30;
581 affected_start = pri_freq - 30;
582 affected_end = pri_freq + 10;
584 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
585 affected_start, affected_end);
587 mode = iface->current_mode;
588 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
589 if (params->freqs == NULL)
593 for (i = 0; i < mode->num_channels; i++) {
594 struct hostapd_channel_data *chan = &mode->channels[i];
595 if (chan->flag & HOSTAPD_CHAN_DISABLED)
597 if (chan->freq < affected_start ||
598 chan->freq > affected_end)
600 params->freqs[pos++] = chan->freq;
605 static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
607 struct wpa_driver_scan_params params;
609 if (!iface->conf->secondary_channel)
610 return 0; /* HT40 not used */
612 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
613 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
615 os_memset(¶ms, 0, sizeof(params));
616 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
617 ieee80211n_scan_channels_2g4(iface, ¶ms);
619 ieee80211n_scan_channels_5g(iface, ¶ms);
620 if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) {
621 wpa_printf(MSG_ERROR, "Failed to request a scan of "
622 "neighboring BSSes");
623 os_free(params.freqs);
626 os_free(params.freqs);
628 iface->scan_cb = ieee80211n_check_scan;
633 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
635 u16 hw = iface->current_mode->ht_capab;
636 u16 conf = iface->conf->ht_capab;
638 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
639 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
640 wpa_printf(MSG_ERROR, "Driver does not support configured "
641 "HT capability [LDPC]");
645 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
646 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
647 wpa_printf(MSG_ERROR, "Driver does not support configured "
648 "HT capability [HT40*]");
652 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
653 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
654 wpa_printf(MSG_ERROR, "Driver does not support configured "
655 "HT capability [SMPS-*]");
659 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
660 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
661 wpa_printf(MSG_ERROR, "Driver does not support configured "
662 "HT capability [GF]");
666 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
667 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
668 wpa_printf(MSG_ERROR, "Driver does not support configured "
669 "HT capability [SHORT-GI-20]");
673 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
674 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
675 wpa_printf(MSG_ERROR, "Driver does not support configured "
676 "HT capability [SHORT-GI-40]");
680 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
681 wpa_printf(MSG_ERROR, "Driver does not support configured "
682 "HT capability [TX-STBC]");
686 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
687 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
688 wpa_printf(MSG_ERROR, "Driver does not support configured "
689 "HT capability [RX-STBC*]");
693 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
694 !(hw & HT_CAP_INFO_DELAYED_BA)) {
695 wpa_printf(MSG_ERROR, "Driver does not support configured "
696 "HT capability [DELAYED-BA]");
700 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
701 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
702 wpa_printf(MSG_ERROR, "Driver does not support configured "
703 "HT capability [MAX-AMSDU-7935]");
707 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
708 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
709 wpa_printf(MSG_ERROR, "Driver does not support configured "
710 "HT capability [DSSS_CCK-40]");
714 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
715 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
716 wpa_printf(MSG_ERROR, "Driver does not support configured "
717 "HT capability [LSIG-TXOP-PROT]");
725 #ifdef CONFIG_IEEE80211AC
727 static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
729 u32 req_cap = conf & cap;
732 * Make sure we support all requested capabilities.
733 * NOTE: We assume that 'cap' represents a capability mask,
734 * not a discrete value.
736 if ((hw & req_cap) != req_cap) {
737 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
745 static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap,
748 u32 hw_max = hw & cap;
749 u32 conf_val = conf & cap;
751 if (conf_val > hw_max) {
752 int offset = find_first_bit(cap);
753 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
754 name, conf_val >> offset, hw_max >> offset);
761 static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
763 u32 hw = iface->current_mode->vht_capab;
764 u32 conf = iface->conf->vht_capab;
766 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
769 #define VHT_CAP_CHECK(cap) \
771 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
775 #define VHT_CAP_CHECK_MAX(cap) \
777 if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \
781 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
782 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
783 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
784 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
785 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
786 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
787 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
788 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
789 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
790 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
791 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
792 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
793 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
794 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
795 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
796 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
797 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
798 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
799 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
800 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
801 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
804 #undef VHT_CAP_CHECK_MAX
808 #endif /* CONFIG_IEEE80211AC */
810 #endif /* CONFIG_IEEE80211N */
813 int hostapd_check_ht_capab(struct hostapd_iface *iface)
815 #ifdef CONFIG_IEEE80211N
817 if (!iface->conf->ieee80211n)
819 if (!ieee80211n_supported_ht_capab(iface))
821 #ifdef CONFIG_IEEE80211AC
822 if (!ieee80211ac_supported_vht_capab(iface))
824 #endif /* CONFIG_IEEE80211AC */
825 ret = ieee80211n_check_40mhz(iface);
828 if (!ieee80211n_allowed_ht40_channel_pair(iface))
830 #endif /* CONFIG_IEEE80211N */
836 static int hostapd_is_usable_chan(struct hostapd_iface *iface,
837 int channel, int primary)
840 struct hostapd_channel_data *chan;
842 for (i = 0; i < iface->current_mode->num_channels; i++) {
843 chan = &iface->current_mode->channels[i];
844 if (chan->chan != channel)
847 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
850 wpa_printf(MSG_DEBUG,
851 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s",
852 primary ? "" : "Configured HT40 secondary ",
853 i, chan->chan, chan->flag,
854 chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "",
855 chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ?
856 " PASSIVE-SCAN" : "",
857 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
864 static int hostapd_is_usable_chans(struct hostapd_iface *iface)
866 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
869 if (!iface->conf->secondary_channel)
872 return hostapd_is_usable_chan(iface, iface->conf->channel +
873 iface->conf->secondary_channel * 4, 0);
877 static enum hostapd_chan_status
878 hostapd_check_chans(struct hostapd_iface *iface)
880 if (iface->conf->channel) {
881 if (hostapd_is_usable_chans(iface))
882 return HOSTAPD_CHAN_VALID;
884 return HOSTAPD_CHAN_INVALID;
888 * The user set channel=0 or channel=acs_survey
889 * which is used to trigger ACS.
892 switch (acs_init(iface)) {
893 case HOSTAPD_CHAN_ACS:
894 return HOSTAPD_CHAN_ACS;
895 case HOSTAPD_CHAN_VALID:
896 case HOSTAPD_CHAN_INVALID:
898 return HOSTAPD_CHAN_INVALID;
903 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
905 hostapd_logger(iface->bss[0], NULL,
906 HOSTAPD_MODULE_IEEE80211,
907 HOSTAPD_LEVEL_WARNING,
908 "Configured channel (%d) not found from the "
909 "channel list of current mode (%d) %s",
910 iface->conf->channel,
911 iface->current_mode->mode,
912 hostapd_hw_mode_txt(iface->current_mode->mode));
913 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
914 HOSTAPD_LEVEL_WARNING,
915 "Hardware does not support configured channel");
919 int hostapd_acs_completed(struct hostapd_iface *iface, int err)
926 switch (hostapd_check_chans(iface)) {
927 case HOSTAPD_CHAN_VALID:
928 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
929 ACS_EVENT_COMPLETED "freq=%d channel=%d",
930 hostapd_hw_get_freq(iface->bss[0],
931 iface->conf->channel),
932 iface->conf->channel);
934 case HOSTAPD_CHAN_ACS:
935 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
936 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
937 hostapd_notify_bad_chans(iface);
939 case HOSTAPD_CHAN_INVALID:
941 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
942 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
943 hostapd_notify_bad_chans(iface);
947 ret = hostapd_check_ht_capab(iface);
951 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
957 return hostapd_setup_interface_complete(iface, ret);
962 * hostapd_select_hw_mode - Select the hardware mode
963 * @iface: Pointer to interface data.
964 * Returns: 0 on success, < 0 on failure
966 * Sets up the hardware mode, channel, rates, and passive scanning
967 * based on the configuration.
969 int hostapd_select_hw_mode(struct hostapd_iface *iface)
973 if (iface->num_hw_features < 1)
976 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
977 iface->conf->ieee80211n || iface->conf->ieee80211ac) &&
978 iface->conf->channel == 14) {
979 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14");
980 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
981 iface->conf->ieee80211n = 0;
982 iface->conf->ieee80211ac = 0;
985 iface->current_mode = NULL;
986 for (i = 0; i < iface->num_hw_features; i++) {
987 struct hostapd_hw_modes *mode = &iface->hw_features[i];
988 if (mode->mode == iface->conf->hw_mode) {
989 iface->current_mode = mode;
994 if (iface->current_mode == NULL) {
995 wpa_printf(MSG_ERROR, "Hardware does not support configured "
997 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
998 HOSTAPD_LEVEL_WARNING,
999 "Hardware does not support configured mode "
1000 "(%d) (hw_mode in hostapd.conf)",
1001 (int) iface->conf->hw_mode);
1005 switch (hostapd_check_chans(iface)) {
1006 case HOSTAPD_CHAN_VALID:
1008 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1010 case HOSTAPD_CHAN_INVALID:
1012 hostapd_notify_bad_chans(iface);
1018 const char * hostapd_hw_mode_txt(int mode)
1021 case HOSTAPD_MODE_IEEE80211A:
1022 return "IEEE 802.11a";
1023 case HOSTAPD_MODE_IEEE80211B:
1024 return "IEEE 802.11b";
1025 case HOSTAPD_MODE_IEEE80211G:
1026 return "IEEE 802.11g";
1027 case HOSTAPD_MODE_IEEE80211AD:
1028 return "IEEE 802.11ad";
1035 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1039 if (!hapd->iface->current_mode)
1042 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1043 struct hostapd_channel_data *ch =
1044 &hapd->iface->current_mode->channels[i];
1045 if (ch->chan == chan)
1053 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1057 if (!hapd->iface->current_mode)
1060 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1061 struct hostapd_channel_data *ch =
1062 &hapd->iface->current_mode->channels[i];
1063 if (ch->freq == freq)