blob: c4556603d3daa366978c5d68aebcddb9a7871fbf [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Hardware feature query and different modes
3 * Copyright 2002-2003, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
Dmitry Shmidt04949592012-07-19 12:16:46 -07005 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006 *
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009 */
10
11#include "utils/includes.h"
12
13#include "utils/common.h"
14#include "utils/eloop.h"
15#include "common/ieee802_11_defs.h"
16#include "common/ieee802_11_common.h"
Dmitry Shmidtcce06662013-11-04 18:44:24 -080017#include "common/wpa_ctrl.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080018#include "common/hw_features_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "hostapd.h"
20#include "ap_config.h"
21#include "ap_drv_ops.h"
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070022#include "acs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070023#include "ieee802_11.h"
24#include "beacon.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "hw_features.h"
26
27
28void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
29 size_t num_hw_features)
30{
31 size_t i;
32
33 if (hw_features == NULL)
34 return;
35
36 for (i = 0; i < num_hw_features; i++) {
37 os_free(hw_features[i].channels);
38 os_free(hw_features[i].rates);
39 }
40
41 os_free(hw_features);
42}
43
44
Dmitry Shmidt051af732013-10-22 13:52:46 -070045#ifndef CONFIG_NO_STDOUT_DEBUG
46static char * dfs_info(struct hostapd_channel_data *chan)
47{
48 static char info[256];
49 char *state;
50
51 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
52 case HOSTAPD_CHAN_DFS_UNKNOWN:
53 state = "unknown";
54 break;
55 case HOSTAPD_CHAN_DFS_USABLE:
56 state = "usable";
57 break;
58 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
59 state = "unavailable";
60 break;
61 case HOSTAPD_CHAN_DFS_AVAILABLE:
62 state = "available";
63 break;
64 default:
65 return "";
66 }
67 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
68 info[sizeof(info) - 1] = '\0';
69
70 return info;
71}
72#endif /* CONFIG_NO_STDOUT_DEBUG */
73
74
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075int hostapd_get_hw_features(struct hostapd_iface *iface)
76{
77 struct hostapd_data *hapd = iface->bss[0];
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080078 int i, j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 u16 num_modes, flags;
80 struct hostapd_hw_modes *modes;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070081 u8 dfs_domain;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000082 enum hostapd_hw_mode mode = HOSTAPD_MODE_IEEE80211ANY;
83 bool is_6ghz = false;
84 bool orig_mode_valid = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085
86 if (hostapd_drv_none(hapd))
87 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070088 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags,
89 &dfs_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090 if (modes == NULL) {
91 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
92 HOSTAPD_LEVEL_DEBUG,
93 "Fetching hardware channel/rate support not "
94 "supported.");
95 return -1;
96 }
97
98 iface->hw_flags = flags;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070099 iface->dfs_domain = dfs_domain;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000101 if (iface->current_mode) {
102 /*
103 * Received driver event CHANNEL_LIST_CHANGED when the current
104 * hw mode is valid. Clear iface->current_mode temporarily as
105 * the mode instance will be replaced with a new instance and
106 * the current pointer would be pointing to freed memory.
107 */
108 orig_mode_valid = true;
109 mode = iface->current_mode->mode;
Sunil Ravi99c035e2024-07-12 01:42:03 +0000110 is_6ghz = iface->current_mode->is_6ghz;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000111 iface->current_mode = NULL;
112 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
114 iface->hw_features = modes;
115 iface->num_hw_features = num_modes;
116
117 for (i = 0; i < num_modes; i++) {
118 struct hostapd_hw_modes *feature = &modes[i];
Dmitry Shmidt051af732013-10-22 13:52:46 -0700119 int dfs_enabled = hapd->iconf->ieee80211h &&
120 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
121
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000122 /* Restore orignal mode if possible */
123 if (orig_mode_valid && feature->mode == mode &&
124 feature->num_channels > 0 &&
125 is_6ghz == is_6ghz_freq(feature->channels[0].freq))
126 iface->current_mode = feature;
127
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 /* set flag for channels we can use in current regulatory
129 * domain */
130 for (j = 0; j < feature->num_channels; j++) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700131 int dfs = 0;
132
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133 /*
134 * Disable all channels that are marked not to allow
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800135 * to initiate radiation (a.k.a. passive scan and no
136 * IBSS).
Dmitry Shmidt051af732013-10-22 13:52:46 -0700137 * Use radar channels only if the driver supports DFS.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138 */
Dmitry Shmidt051af732013-10-22 13:52:46 -0700139 if ((feature->channels[j].flag &
140 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
141 dfs = 1;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700142 } else if (((feature->channels[j].flag &
143 HOSTAPD_CHAN_RADAR) &&
144 !(iface->drv_flags &
145 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
146 (feature->channels[j].flag &
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800147 HOSTAPD_CHAN_NO_IR)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148 feature->channels[j].flag |=
149 HOSTAPD_CHAN_DISABLED;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700150 }
151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700152 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
153 continue;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700154
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
Dmitry Shmidt051af732013-10-22 13:52:46 -0700156 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157 feature->mode,
158 feature->channels[j].chan,
159 feature->channels[j].freq,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700160 feature->channels[j].max_tx_power,
161 dfs ? dfs_info(&feature->channels[j]) : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 }
163 }
164
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000165 if (orig_mode_valid && !iface->current_mode) {
166 wpa_printf(MSG_ERROR,
167 "%s: Could not update iface->current_mode",
168 __func__);
169 }
170
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800171 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172}
173
174
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800175int hostapd_prepare_rates(struct hostapd_iface *iface,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700176 struct hostapd_hw_modes *mode)
177{
178 int i, num_basic_rates = 0;
179 int basic_rates_a[] = { 60, 120, 240, -1 };
180 int basic_rates_b[] = { 10, 20, -1 };
181 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
182 int *basic_rates;
183
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800184 if (iface->conf->basic_rates)
185 basic_rates = iface->conf->basic_rates;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186 else switch (mode->mode) {
187 case HOSTAPD_MODE_IEEE80211A:
188 basic_rates = basic_rates_a;
189 break;
190 case HOSTAPD_MODE_IEEE80211B:
191 basic_rates = basic_rates_b;
192 break;
193 case HOSTAPD_MODE_IEEE80211G:
194 basic_rates = basic_rates_g;
195 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800196 case HOSTAPD_MODE_IEEE80211AD:
197 return 0; /* No basic rates for 11ad */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 default:
199 return -1;
200 }
201
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800202 i = 0;
203 while (basic_rates[i] >= 0)
204 i++;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700205 if (i)
206 i++; /* -1 termination */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800207 os_free(iface->basic_rates);
208 iface->basic_rates = os_malloc(i * sizeof(int));
209 if (iface->basic_rates)
210 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800212 os_free(iface->current_rates);
213 iface->num_rates = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800215 iface->current_rates =
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700216 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800217 if (!iface->current_rates) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
219 "table.");
220 return -1;
221 }
222
223 for (i = 0; i < mode->num_rates; i++) {
224 struct hostapd_rate_data *rate;
225
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800226 if (iface->conf->supported_rates &&
227 !hostapd_rate_found(iface->conf->supported_rates,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 mode->rates[i]))
229 continue;
230
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800231 rate = &iface->current_rates[iface->num_rates];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232 rate->rate = mode->rates[i];
233 if (hostapd_rate_found(basic_rates, rate->rate)) {
234 rate->flags |= HOSTAPD_RATE_BASIC;
235 num_basic_rates++;
236 }
237 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800238 iface->num_rates, rate->rate, rate->flags);
239 iface->num_rates++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240 }
241
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800242 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
243 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
245 "rate sets (%d,%d).",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800246 iface->num_rates, num_basic_rates);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 return -1;
248 }
249
250 return 0;
251}
252
253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
255{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800256 int pri_freq, sec_freq;
257 struct hostapd_channel_data *p_chan, *s_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800259 pri_freq = iface->freq;
260 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800262 if (!iface->current_mode)
263 return 0;
264
265 p_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq, NULL,
266 iface->hw_features,
267 iface->num_hw_features);
268
269 s_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq, NULL,
270 iface->hw_features,
271 iface->num_hw_features);
272
273 return allowed_ht40_channel_pair(iface->current_mode->mode,
274 p_chan, s_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275}
276
277
278static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
279{
280 if (iface->conf->secondary_channel > 0) {
281 iface->conf->channel += 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800282 iface->freq += 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 iface->conf->secondary_channel = -1;
284 } else {
285 iface->conf->channel -= 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800286 iface->freq -= 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700287 iface->conf->secondary_channel = 1;
288 }
289}
290
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
293 struct wpa_scan_results *scan_res)
294{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800295 unsigned int pri_freq, sec_freq;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800296 int res;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800297 struct hostapd_channel_data *pri_chan, *sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800299 pri_freq = iface->freq;
300 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800302 if (!iface->current_mode)
303 return 0;
304 pri_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq,
305 NULL, iface->hw_features,
306 iface->num_hw_features);
307 sec_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq,
308 NULL, iface->hw_features,
309 iface->num_hw_features);
310
311 res = check_40mhz_5g(scan_res, pri_chan, sec_chan);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800312
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800313 if (res == 2) {
314 if (iface->conf->no_pri_sec_switch) {
315 wpa_printf(MSG_DEBUG,
316 "Cannot switch PRI/SEC channels due to local constraint");
317 } else {
318 ieee80211n_switch_pri_sec(iface);
319 }
320 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800322 return !!res;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -0700323}
324
325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
327 struct wpa_scan_results *scan_res)
328{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800329 int pri_chan, sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800331 pri_chan = iface->conf->channel;
332 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800334 return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
335 sec_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336}
337
338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339static void ieee80211n_check_scan(struct hostapd_iface *iface)
340{
341 struct wpa_scan_results *scan_res;
342 int oper40;
Hai Shalom60840252021-02-19 19:02:11 -0800343 int res = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344
345 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
Dmitry Shmidt04949592012-07-19 12:16:46 -0700346 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347
348 iface->scan_cb = NULL;
349
350 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
351 if (scan_res == NULL) {
352 hostapd_setup_interface_complete(iface, 1);
353 return;
354 }
355
356 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
357 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
358 else
359 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
360 wpa_scan_results_free(scan_res);
361
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700362 iface->secondary_ch = iface->conf->secondary_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 if (!oper40) {
364 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
365 "channel pri=%d sec=%d based on overlapping BSSes",
366 iface->conf->channel,
367 iface->conf->channel +
368 iface->conf->secondary_channel * 4);
369 iface->conf->secondary_channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700370 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
371 /*
372 * TODO: Could consider scheduling another scan to check
373 * if channel width can be changed if no coex reports
374 * are received from associating stations.
375 */
376 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 }
378
Hai Shalom60840252021-02-19 19:02:11 -0800379#ifdef CONFIG_IEEE80211AX
380 if (iface->conf->secondary_channel &&
381 iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
382 iface->conf->ieee80211ax) {
383 struct he_capabilities *he_cap;
384
385 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
386 if (!(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
387 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_IN_2G)) {
388 wpa_printf(MSG_DEBUG,
389 "HE: 40 MHz channel width is not supported in 2.4 GHz; clear secondary channel configuration");
390 iface->conf->secondary_channel = 0;
391 }
392 }
393#endif /* CONFIG_IEEE80211AX */
394
395 if (iface->conf->secondary_channel)
396 res = ieee80211n_allowed_ht40_channel_pair(iface);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700397 if (!res) {
398 iface->conf->secondary_channel = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700399 hostapd_set_oper_centr_freq_seg0_idx(iface->conf, 0);
400 hostapd_set_oper_centr_freq_seg1_idx(iface->conf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +0000401 hostapd_set_oper_chwidth(iface->conf, CONF_OPER_CHWIDTH_USE_HT);
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800402 res = 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700403 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
404 }
405
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406 hostapd_setup_interface_complete(iface, !res);
407}
408
409
Dmitry Shmidt04949592012-07-19 12:16:46 -0700410static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
411 struct wpa_driver_scan_params *params)
412{
413 /* Scan only the affected frequency range */
414 int pri_freq, sec_freq;
415 int affected_start, affected_end;
416 int i, pos;
417 struct hostapd_hw_modes *mode;
418
419 if (iface->current_mode == NULL)
420 return;
421
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800422 pri_freq = iface->freq;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700423 if (iface->conf->secondary_channel > 0)
424 sec_freq = pri_freq + 20;
425 else
426 sec_freq = pri_freq - 20;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700427 /*
428 * Note: Need to find the PRI channel also in cases where the affected
429 * channel is the SEC channel of a 40 MHz BSS, so need to include the
430 * scanning coverage here to be 40 MHz from the center frequency.
431 */
432 affected_start = (pri_freq + sec_freq) / 2 - 40;
433 affected_end = (pri_freq + sec_freq) / 2 + 40;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700434 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
435 affected_start, affected_end);
436
437 mode = iface->current_mode;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700438 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700439 if (params->freqs == NULL)
440 return;
441 pos = 0;
442
443 for (i = 0; i < mode->num_channels; i++) {
444 struct hostapd_channel_data *chan = &mode->channels[i];
445 if (chan->flag & HOSTAPD_CHAN_DISABLED)
446 continue;
447 if (chan->freq < affected_start ||
448 chan->freq > affected_end)
449 continue;
450 params->freqs[pos++] = chan->freq;
451 }
452}
453
454
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800455static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
456 struct wpa_driver_scan_params *params)
457{
458 /* Scan only the affected frequency range */
459 int pri_freq;
460 int affected_start, affected_end;
461 int i, pos;
462 struct hostapd_hw_modes *mode;
463
464 if (iface->current_mode == NULL)
465 return;
466
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800467 pri_freq = iface->freq;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800468 if (iface->conf->secondary_channel > 0) {
469 affected_start = pri_freq - 10;
470 affected_end = pri_freq + 30;
471 } else {
472 affected_start = pri_freq - 30;
473 affected_end = pri_freq + 10;
474 }
475 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
476 affected_start, affected_end);
477
478 mode = iface->current_mode;
479 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
480 if (params->freqs == NULL)
481 return;
482 pos = 0;
483
484 for (i = 0; i < mode->num_channels; i++) {
485 struct hostapd_channel_data *chan = &mode->channels[i];
486 if (chan->flag & HOSTAPD_CHAN_DISABLED)
487 continue;
488 if (chan->freq < affected_start ||
489 chan->freq > affected_end)
490 continue;
491 params->freqs[pos++] = chan->freq;
492 }
493}
494
495
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700496static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
497{
498#define HT2040_COEX_SCAN_RETRY 15
499 struct hostapd_iface *iface = eloop_data;
500 struct wpa_driver_scan_params params;
501 int ret;
502
503 os_memset(&params, 0, sizeof(params));
504 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
505 ieee80211n_scan_channels_2g4(iface, &params);
506 else
507 ieee80211n_scan_channels_5g(iface, &params);
508
Sunil Ravi99c035e2024-07-12 01:42:03 +0000509 params.link_id = -1;
510#ifdef CONFIG_IEEE80211BE
511 if (iface->bss[0]->conf->mld_ap)
512 params.link_id = iface->bss[0]->mld_link_id;
513#endif /* CONFIG_IEEE80211BE */
514
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700515 ret = hostapd_driver_scan(iface->bss[0], &params);
516 iface->num_ht40_scan_tries++;
517 os_free(params.freqs);
518
519 if (ret == -EBUSY &&
520 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
521 wpa_printf(MSG_ERROR,
522 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
523 ret, strerror(-ret), iface->num_ht40_scan_tries);
524 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
525 return;
526 }
527
528 if (ret == 0) {
529 iface->scan_cb = ieee80211n_check_scan;
Sunil Ravi99c035e2024-07-12 01:42:03 +0000530 iface->bss[0]->scan_cookie = params.scan_cookie;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700531 return;
532 }
533
534 wpa_printf(MSG_DEBUG,
535 "Failed to request a scan in device, bringing up in HT20 mode");
536 iface->conf->secondary_channel = 0;
537 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
538 hostapd_setup_interface_complete(iface, 0);
539}
540
541
542void hostapd_stop_setup_timers(struct hostapd_iface *iface)
543{
544 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
545}
546
547
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
549{
550 struct wpa_driver_scan_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700551 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800553 /* Check that HT40 is used and PRI / SEC switch is allowed */
554 if (!iface->conf->secondary_channel || iface->conf->no_pri_sec_switch)
555 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800557 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
559 "40 MHz channel");
560 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700561 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
562 ieee80211n_scan_channels_2g4(iface, &params);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800563 else
564 ieee80211n_scan_channels_5g(iface, &params);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700565
Sunil Ravi99c035e2024-07-12 01:42:03 +0000566 params.link_id = -1;
567#ifdef CONFIG_IEEE80211BE
568 if (iface->bss[0]->conf->mld_ap)
569 params.link_id = iface->bss[0]->mld_link_id;
570#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700571 ret = hostapd_driver_scan(iface->bss[0], &params);
572 os_free(params.freqs);
573
574 if (ret == -EBUSY) {
575 wpa_printf(MSG_ERROR,
576 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
577 ret, strerror(-ret));
578 iface->num_ht40_scan_tries = 1;
579 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
580 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
581 return 1;
582 }
583
584 if (ret < 0) {
585 wpa_printf(MSG_ERROR,
586 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
587 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 return -1;
589 }
590
591 iface->scan_cb = ieee80211n_check_scan;
Sunil Ravi99c035e2024-07-12 01:42:03 +0000592 iface->bss[0]->scan_cookie = params.scan_cookie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593 return 1;
594}
595
596
597static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
598{
599 u16 hw = iface->current_mode->ht_capab;
600 u16 conf = iface->conf->ht_capab;
601
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]");
606 return 0;
607 }
608
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700609 /*
610 * Driver ACS chosen channel may not be HT40 due to internal driver
611 * restrictions.
612 */
613 if (!iface->conf->acs && (conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
615 wpa_printf(MSG_ERROR, "Driver does not support configured "
616 "HT capability [HT40*]");
617 return 0;
618 }
619
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
621 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
622 wpa_printf(MSG_ERROR, "Driver does not support configured "
623 "HT capability [GF]");
624 return 0;
625 }
626
627 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
628 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
629 wpa_printf(MSG_ERROR, "Driver does not support configured "
630 "HT capability [SHORT-GI-20]");
631 return 0;
632 }
633
634 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
635 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
636 wpa_printf(MSG_ERROR, "Driver does not support configured "
637 "HT capability [SHORT-GI-40]");
638 return 0;
639 }
640
641 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
642 wpa_printf(MSG_ERROR, "Driver does not support configured "
643 "HT capability [TX-STBC]");
644 return 0;
645 }
646
647 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
648 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
649 wpa_printf(MSG_ERROR, "Driver does not support configured "
650 "HT capability [RX-STBC*]");
651 return 0;
652 }
653
654 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
655 !(hw & HT_CAP_INFO_DELAYED_BA)) {
656 wpa_printf(MSG_ERROR, "Driver does not support configured "
657 "HT capability [DELAYED-BA]");
658 return 0;
659 }
660
661 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
662 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
663 wpa_printf(MSG_ERROR, "Driver does not support configured "
664 "HT capability [MAX-AMSDU-7935]");
665 return 0;
666 }
667
668 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
669 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
670 wpa_printf(MSG_ERROR, "Driver does not support configured "
671 "HT capability [DSSS_CCK-40]");
672 return 0;
673 }
674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
676 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
677 wpa_printf(MSG_ERROR, "Driver does not support configured "
678 "HT capability [LSIG-TXOP-PROT]");
679 return 0;
680 }
681
682 return 1;
683}
684
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700685
686#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700687static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
688{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800689 struct hostapd_hw_modes *mode = iface->current_mode;
690 u32 hw = mode->vht_capab;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700691 u32 conf = iface->conf->vht_capab;
692
693 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
694 hw, conf);
695
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800696 if (mode->mode == HOSTAPD_MODE_IEEE80211G &&
697 iface->conf->bss[0]->vendor_vht &&
698 mode->vht_capab == 0 && iface->hw_features) {
699 int i;
700
701 for (i = 0; i < iface->num_hw_features; i++) {
702 if (iface->hw_features[i].mode ==
703 HOSTAPD_MODE_IEEE80211A) {
704 mode = &iface->hw_features[i];
705 hw = mode->vht_capab;
706 wpa_printf(MSG_DEBUG,
707 "update hw vht capab based on 5 GHz band: 0x%x",
708 hw);
709 break;
710 }
711 }
712 }
713
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800714 return ieee80211ac_cap_check(hw, conf);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700715}
716#endif /* CONFIG_IEEE80211AC */
717
Hai Shalom81f62d82019-07-22 12:10:00 -0700718
719#ifdef CONFIG_IEEE80211AX
720static int ieee80211ax_supported_he_capab(struct hostapd_iface *iface)
721{
722 return 1;
723}
724#endif /* CONFIG_IEEE80211AX */
725
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726
727int hostapd_check_ht_capab(struct hostapd_iface *iface)
728{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 int ret;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800730
731 if (is_6ghz_freq(iface->freq))
732 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 if (!iface->conf->ieee80211n)
734 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800735
736 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211B &&
737 iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G &&
738 (iface->conf->ht_capab & HT_CAP_INFO_DSSS_CCK40MHZ)) {
739 wpa_printf(MSG_DEBUG,
740 "Disable HT capability [DSSS_CCK-40] on 5 GHz band");
741 iface->conf->ht_capab &= ~HT_CAP_INFO_DSSS_CCK40MHZ;
742 }
743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 if (!ieee80211n_supported_ht_capab(iface))
745 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700746#ifdef CONFIG_IEEE80211AX
747 if (iface->conf->ieee80211ax &&
748 !ieee80211ax_supported_he_capab(iface))
749 return -1;
750#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700751#ifdef CONFIG_IEEE80211AC
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800752 if (iface->conf->ieee80211ac &&
753 !ieee80211ac_supported_vht_capab(iface))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700754 return -1;
755#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700756 ret = ieee80211n_check_40mhz(iface);
757 if (ret)
758 return ret;
759 if (!ieee80211n_allowed_ht40_channel_pair(iface))
760 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761
762 return 0;
763}
764
765
Hai Shalomc3565922019-10-28 11:58:20 -0700766int hostapd_check_edmg_capab(struct hostapd_iface *iface)
767{
768 struct hostapd_hw_modes *mode = iface->hw_features;
769 struct ieee80211_edmg_config edmg;
770
771 if (!iface->conf->enable_edmg)
772 return 0;
773
774 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
775 iface->conf->edmg_channel,
776 iface->conf->channel,
777 &edmg);
778
779 if (mode->edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg))
780 return 0;
781
782 wpa_printf(MSG_WARNING, "Requested EDMG configuration is not valid");
783 wpa_printf(MSG_INFO, "EDMG capab: channels 0x%x, bw_config %d",
784 mode->edmg.channels, mode->edmg.bw_config);
785 wpa_printf(MSG_INFO,
786 "Requested EDMG configuration: channels 0x%x, bw_config %d",
787 edmg.channels, edmg.bw_config);
788 return -1;
789}
790
791
Hai Shalom60840252021-02-19 19:02:11 -0800792int hostapd_check_he_6ghz_capab(struct hostapd_iface *iface)
793{
794#ifdef CONFIG_IEEE80211AX
795 struct he_capabilities *he_cap;
796 u16 hw;
797
798 if (!iface->current_mode || !is_6ghz_freq(iface->freq))
799 return 0;
800
801 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
802 hw = he_cap->he_6ghz_capa;
803 if (iface->conf->he_6ghz_max_mpdu >
804 ((hw & HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_MASK) >>
805 HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_SHIFT)) {
806 wpa_printf(MSG_ERROR,
807 "The driver does not support the configured HE 6 GHz Max MPDU length");
808 return -1;
809 }
810
811 if (iface->conf->he_6ghz_max_ampdu_len_exp >
812 ((hw & HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_MASK) >>
813 HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_SHIFT)) {
814 wpa_printf(MSG_ERROR,
815 "The driver does not support the configured HE 6 GHz Max AMPDU Length Exponent");
816 return -1;
817 }
818
819 if (iface->conf->he_6ghz_rx_ant_pat &&
820 !(hw & HE_6GHZ_BAND_CAP_RX_ANTPAT_CONS)) {
821 wpa_printf(MSG_ERROR,
822 "The driver does not support the configured HE 6 GHz Rx Antenna Pattern");
823 return -1;
824 }
825
826 if (iface->conf->he_6ghz_tx_ant_pat &&
827 !(hw & HE_6GHZ_BAND_CAP_TX_ANTPAT_CONS)) {
828 wpa_printf(MSG_ERROR,
829 "The driver does not support the configured HE 6 GHz Tx Antenna Pattern");
830 return -1;
831 }
832#endif /* CONFIG_IEEE80211AX */
833 return 0;
834}
835
836
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000837/* Returns:
838 * 1 = usable
839 * 0 = not usable
840 * -1 = not currently usable due to 6 GHz NO-IR
841 */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700842static int hostapd_is_usable_chan(struct hostapd_iface *iface,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800843 int frequency, int primary)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700844{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700845 struct hostapd_channel_data *chan;
846
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700847 if (!iface->current_mode)
848 return 0;
849
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800850 chan = hw_get_channel_freq(iface->current_mode->mode, frequency, NULL,
851 iface->hw_features, iface->num_hw_features);
Hai Shalom74f70d42019-02-11 14:42:39 -0800852 if (!chan)
853 return 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700854
Hai Shalom74f70d42019-02-11 14:42:39 -0800855 if ((primary && chan_pri_allowed(chan)) ||
856 (!primary && !(chan->flag & HOSTAPD_CHAN_DISABLED)))
857 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700858
Hai Shalom74f70d42019-02-11 14:42:39 -0800859 wpa_printf(MSG_INFO,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800860 "Frequency %d (%s) not allowed for AP mode, flags: 0x%x%s%s",
861 frequency, primary ? "primary" : "secondary",
Hai Shalom74f70d42019-02-11 14:42:39 -0800862 chan->flag,
863 chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
864 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000865
866 if (is_6ghz_freq(chan->freq) && (chan->flag & HOSTAPD_CHAN_NO_IR))
867 return -1;
868
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700869 return 0;
870}
871
872
Hai Shalomc3565922019-10-28 11:58:20 -0700873static int hostapd_is_usable_edmg(struct hostapd_iface *iface)
874{
875 int i, contiguous = 0;
876 int num_of_enabled = 0;
877 int max_contiguous = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000878 int err;
Hai Shalomc3565922019-10-28 11:58:20 -0700879 struct ieee80211_edmg_config edmg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800880 struct hostapd_channel_data *pri_chan;
Hai Shalomc3565922019-10-28 11:58:20 -0700881
882 if (!iface->conf->enable_edmg)
883 return 1;
884
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800885 if (!iface->current_mode)
886 return 0;
887 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
888 iface->freq, NULL,
889 iface->hw_features,
890 iface->num_hw_features);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800891 if (!pri_chan)
892 return 0;
Hai Shalomc3565922019-10-28 11:58:20 -0700893 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
894 iface->conf->edmg_channel,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800895 pri_chan->chan,
Hai Shalomc3565922019-10-28 11:58:20 -0700896 &edmg);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800897 if (!(edmg.channels & BIT(pri_chan->chan - 1)))
Hai Shalomc3565922019-10-28 11:58:20 -0700898 return 0;
899
900 /* 60 GHz channels 1..6 */
901 for (i = 0; i < 6; i++) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700902 int freq = 56160 + 2160 * (i + 1);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800903
Hai Shalomc3565922019-10-28 11:58:20 -0700904 if (edmg.channels & BIT(i)) {
905 contiguous++;
906 num_of_enabled++;
907 } else {
908 contiguous = 0;
909 continue;
910 }
911
912 /* P802.11ay defines that the total number of subfields
913 * set to one does not exceed 4.
914 */
915 if (num_of_enabled > 4)
916 return 0;
917
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000918 err = hostapd_is_usable_chan(iface, freq, 1);
919 if (err <= 0)
920 return err;
Hai Shalomc3565922019-10-28 11:58:20 -0700921
922 if (contiguous > max_contiguous)
923 max_contiguous = contiguous;
924 }
925
926 /* Check if the EDMG configuration is valid under the limitations
927 * of P802.11ay.
928 */
929 /* check bw_config against contiguous EDMG channels */
930 switch (edmg.bw_config) {
931 case EDMG_BW_CONFIG_4:
932 if (!max_contiguous)
933 return 0;
934 break;
935 case EDMG_BW_CONFIG_5:
936 if (max_contiguous < 2)
937 return 0;
938 break;
939 default:
940 return 0;
941 }
942
943 return 1;
944}
945
946
Sunil Ravi036cec52023-03-29 11:35:17 -0700947static bool hostapd_is_usable_punct_bitmap(struct hostapd_iface *iface)
948{
949#ifdef CONFIG_IEEE80211BE
950 struct hostapd_config *conf = iface->conf;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000951 u16 bw;
952 u8 start_chan;
Sunil Ravi036cec52023-03-29 11:35:17 -0700953
954 if (!conf->punct_bitmap)
955 return true;
956
957 if (!conf->ieee80211be) {
958 wpa_printf(MSG_ERROR,
959 "Currently RU puncturing is supported only if ieee80211be is enabled");
960 return false;
961 }
962
963 if (iface->freq >= 2412 && iface->freq <= 2484) {
964 wpa_printf(MSG_ERROR,
965 "RU puncturing not supported in 2.4 GHz");
966 return false;
967 }
968
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000969 /*
970 * In the 6 GHz band, eht_oper_chwidth is ignored. Use operating class
971 * to determine channel width.
972 */
973 if (conf->op_class == 137) {
974 bw = 320;
975 start_chan = conf->eht_oper_centr_freq_seg0_idx - 30;
976 } else {
977 switch (conf->eht_oper_chwidth) {
978 case 0:
979 wpa_printf(MSG_ERROR,
980 "RU puncturing is supported only in 80 MHz and 160 MHz");
981 return false;
982 case 1:
983 bw = 80;
984 start_chan = conf->eht_oper_centr_freq_seg0_idx - 6;
985 break;
986 case 2:
987 bw = 160;
988 start_chan = conf->eht_oper_centr_freq_seg0_idx - 14;
989 break;
990 default:
991 return false;
992 }
Sunil Ravi036cec52023-03-29 11:35:17 -0700993 }
994
995 if (!is_punct_bitmap_valid(bw, (conf->channel - start_chan) / 4,
996 conf->punct_bitmap)) {
997 wpa_printf(MSG_ERROR, "Invalid puncturing bitmap");
998 return false;
999 }
1000#endif /* CONFIG_IEEE80211BE */
1001
1002 return true;
1003}
1004
1005
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001006/* Returns:
1007 * 1 = usable
1008 * 0 = not usable
1009 * -1 = not currently usable due to 6 GHz NO-IR
1010 */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001011static int hostapd_is_usable_chans(struct hostapd_iface *iface)
1012{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001013 int secondary_freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001014 struct hostapd_channel_data *pri_chan;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001015 int err, err2;
Hai Shalom74f70d42019-02-11 14:42:39 -08001016
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001017 if (!iface->current_mode)
Hai Shalom74f70d42019-02-11 14:42:39 -08001018 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001019 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
1020 iface->freq, NULL,
1021 iface->hw_features,
1022 iface->num_hw_features);
1023 if (!pri_chan) {
1024 wpa_printf(MSG_ERROR, "Primary frequency not present");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001025 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001026 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001027
1028 err = hostapd_is_usable_chan(iface, pri_chan->freq, 1);
1029 if (err <= 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001030 wpa_printf(MSG_ERROR, "Primary frequency not allowed");
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001031 return err;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001032 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001033 err = hostapd_is_usable_edmg(iface);
1034 if (err <= 0)
1035 return err;
Hai Shalomc3565922019-10-28 11:58:20 -07001036
Sunil Ravi036cec52023-03-29 11:35:17 -07001037 if (!hostapd_is_usable_punct_bitmap(iface))
1038 return 0;
1039
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001040 if (!iface->conf->secondary_channel)
1041 return 1;
1042
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001043 err = hostapd_is_usable_chan(iface, iface->freq +
1044 iface->conf->secondary_channel * 20, 0);
1045 if (err > 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08001046 if (iface->conf->secondary_channel == 1 &&
1047 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P))
1048 return 1;
1049 if (iface->conf->secondary_channel == -1 &&
1050 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M))
1051 return 1;
1052 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001053 if (!iface->conf->ht40_plus_minus_allowed)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001054 return err;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001055
1056 /* Both HT40+ and HT40- are set, pick a valid secondary channel */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001057 secondary_freq = iface->freq + 20;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001058 err2 = hostapd_is_usable_chan(iface, secondary_freq, 0);
1059 if (err2 > 0 && (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001060 iface->conf->secondary_channel = 1;
1061 return 1;
1062 }
1063
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001064 secondary_freq = iface->freq - 20;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001065 err2 = hostapd_is_usable_chan(iface, secondary_freq, 0);
1066 if (err2 > 0 && (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001067 iface->conf->secondary_channel = -1;
1068 return 1;
1069 }
1070
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001071 return err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001072}
1073
1074
Sunil Ravi640215c2023-06-28 23:08:09 +00001075static bool skip_mode(struct hostapd_iface *iface,
1076 struct hostapd_hw_modes *mode)
1077{
1078 int chan;
1079
1080 if (iface->freq > 0 && !hw_mode_get_channel(mode, iface->freq, &chan))
1081 return true;
1082
1083 if (is_6ghz_op_class(iface->conf->op_class) && iface->freq == 0 &&
Sunil Ravi99c035e2024-07-12 01:42:03 +00001084 !mode->is_6ghz)
Sunil Ravi640215c2023-06-28 23:08:09 +00001085 return true;
1086
1087 return false;
1088}
1089
1090
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001091int hostapd_determine_mode(struct hostapd_iface *iface)
Hai Shalomfdcde762020-04-02 11:19:20 -07001092{
1093 int i;
1094 enum hostapd_hw_mode target_mode;
1095
1096 if (iface->current_mode ||
1097 iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001098 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001099
1100 if (iface->freq < 4000)
1101 target_mode = HOSTAPD_MODE_IEEE80211G;
1102 else if (iface->freq > 50000)
1103 target_mode = HOSTAPD_MODE_IEEE80211AD;
1104 else
1105 target_mode = HOSTAPD_MODE_IEEE80211A;
1106
1107 for (i = 0; i < iface->num_hw_features; i++) {
1108 struct hostapd_hw_modes *mode;
1109
1110 mode = &iface->hw_features[i];
1111 if (mode->mode == target_mode) {
Sunil Ravi640215c2023-06-28 23:08:09 +00001112 if (skip_mode(iface, mode))
1113 continue;
1114
Hai Shalomfdcde762020-04-02 11:19:20 -07001115 iface->current_mode = mode;
1116 iface->conf->hw_mode = mode->mode;
1117 break;
1118 }
1119 }
1120
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001121 if (!iface->current_mode) {
1122 wpa_printf(MSG_ERROR, "ACS/CSA: Cannot decide mode");
1123 return -1;
1124 }
1125 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001126}
1127
1128
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001129static enum hostapd_chan_status
1130hostapd_check_chans(struct hostapd_iface *iface)
1131{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001132 if (iface->freq) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001133 int err;
1134
Hai Shalomfdcde762020-04-02 11:19:20 -07001135 hostapd_determine_mode(iface);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001136
1137 err = hostapd_is_usable_chans(iface);
1138 if (err <= 0) {
1139 if (!err)
1140 return HOSTAPD_CHAN_INVALID;
1141 return HOSTAPD_CHAN_INVALID_NO_IR;
1142 }
1143 return HOSTAPD_CHAN_VALID;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001144 }
1145
1146 /*
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001147 * The user set channel=0 or channel=acs_survey
1148 * which is used to trigger ACS.
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001149 */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001150
1151 switch (acs_init(iface)) {
1152 case HOSTAPD_CHAN_ACS:
1153 return HOSTAPD_CHAN_ACS;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001154 case HOSTAPD_CHAN_INVALID_NO_IR:
1155 return HOSTAPD_CHAN_INVALID_NO_IR;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001156 case HOSTAPD_CHAN_VALID:
1157 case HOSTAPD_CHAN_INVALID:
1158 default:
1159 return HOSTAPD_CHAN_INVALID;
1160 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001161}
1162
1163
1164static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
1165{
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001166 if (!iface->current_mode) {
1167 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1168 HOSTAPD_LEVEL_WARNING,
1169 "Hardware does not support configured mode");
1170 return;
1171 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001172 hostapd_logger(iface->bss[0], NULL,
1173 HOSTAPD_MODULE_IEEE80211,
1174 HOSTAPD_LEVEL_WARNING,
Hai Shalom60840252021-02-19 19:02:11 -08001175 "Configured channel (%d) or frequency (%d) (secondary_channel=%d) not found from the channel list of the current mode (%d) %s",
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001176 iface->conf->channel,
Hai Shalom60840252021-02-19 19:02:11 -08001177 iface->freq, iface->conf->secondary_channel,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001178 iface->current_mode->mode,
1179 hostapd_hw_mode_txt(iface->current_mode->mode));
1180 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1181 HOSTAPD_LEVEL_WARNING,
1182 "Hardware does not support configured channel");
1183}
1184
1185
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001186int hostapd_acs_completed(struct hostapd_iface *iface, int err)
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001187{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001188 int ret = -1;
1189
1190 if (err)
1191 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001192
1193 switch (hostapd_check_chans(iface)) {
1194 case HOSTAPD_CHAN_VALID:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001195 iface->is_no_ir = false;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001196 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
1197 ACS_EVENT_COMPLETED "freq=%d channel=%d",
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001198 iface->freq, iface->conf->channel);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001199 break;
1200 case HOSTAPD_CHAN_ACS:
1201 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001202 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001203 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001204 goto out;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001205 case HOSTAPD_CHAN_INVALID_NO_IR:
1206 iface->is_no_ir = true;
1207 /* fall through */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001208 case HOSTAPD_CHAN_INVALID:
1209 default:
1210 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001211 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001212 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001213 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001214 }
1215
1216 ret = hostapd_check_ht_capab(iface);
1217 if (ret < 0)
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001218 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001219 if (ret == 1) {
1220 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
1221 return 0;
1222 }
1223
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001224 ret = 0;
1225out:
1226 return hostapd_setup_interface_complete(iface, ret);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001227}
1228
1229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230/**
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001231 * hostapd_csa_update_hwmode - Update hardware mode
1232 * @iface: Pointer to interface data.
1233 * Returns: 0 on success, < 0 on failure
1234 *
1235 * Update hardware mode when the operating channel changed because of CSA.
1236 */
1237int hostapd_csa_update_hwmode(struct hostapd_iface *iface)
1238{
1239 if (!iface || !iface->conf)
1240 return -1;
1241
1242 iface->current_mode = NULL;
1243 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
1244
1245 return hostapd_determine_mode(iface);
1246}
1247
1248
1249/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 * hostapd_select_hw_mode - Select the hardware mode
1251 * @iface: Pointer to interface data.
Jouni Malinen87fd2792011-05-16 18:35:42 +03001252 * Returns: 0 on success, < 0 on failure
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001253 *
1254 * Sets up the hardware mode, channel, rates, and passive scanning
1255 * based on the configuration.
1256 */
1257int hostapd_select_hw_mode(struct hostapd_iface *iface)
1258{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001259 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260
1261 if (iface->num_hw_features < 1)
1262 return -1;
1263
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001264 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
Hai Shalom81f62d82019-07-22 12:10:00 -07001265 iface->conf->ieee80211n || iface->conf->ieee80211ac ||
Sunil8cd6f4d2022-06-28 18:40:46 +00001266 iface->conf->ieee80211ax || iface->conf->ieee80211be) &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001267 iface->conf->channel == 14) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001268 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT/HE/EHT on channel 14");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001269 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1270 iface->conf->ieee80211n = 0;
1271 iface->conf->ieee80211ac = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -07001272 iface->conf->ieee80211ax = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00001273 iface->conf->ieee80211be = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001274 }
1275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276 iface->current_mode = NULL;
1277 for (i = 0; i < iface->num_hw_features; i++) {
1278 struct hostapd_hw_modes *mode = &iface->hw_features[i];
Hai Shalom60840252021-02-19 19:02:11 -08001279
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001280 if (mode->mode == iface->conf->hw_mode) {
Sunil Ravi640215c2023-06-28 23:08:09 +00001281 if (skip_mode(iface, mode))
Hai Shalomc3565922019-10-28 11:58:20 -07001282 continue;
Hai Shalom60840252021-02-19 19:02:11 -08001283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001284 iface->current_mode = mode;
1285 break;
1286 }
1287 }
1288
1289 if (iface->current_mode == NULL) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001290 if ((iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1291 (iface->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY)) {
1292 wpa_printf(MSG_DEBUG,
1293 "Using offloaded hw_mode=any ACS");
1294 } else if (!(iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1295 iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211ANY) {
1296 wpa_printf(MSG_DEBUG,
1297 "Using internal ACS for hw_mode=any");
1298 } else {
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001299 wpa_printf(MSG_ERROR,
1300 "Hardware does not support configured mode");
1301 hostapd_logger(iface->bss[0], NULL,
1302 HOSTAPD_MODULE_IEEE80211,
1303 HOSTAPD_LEVEL_WARNING,
1304 "Hardware does not support configured mode (%d) (hw_mode in hostapd.conf)",
1305 (int) iface->conf->hw_mode);
1306 return -2;
1307 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 }
1309
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001310 switch (hostapd_check_chans(iface)) {
1311 case HOSTAPD_CHAN_VALID:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001312 iface->is_no_ir = false;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001313 return 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001314 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1315 return 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001316 case HOSTAPD_CHAN_INVALID_NO_IR:
1317 iface->is_no_ir = true;
1318 /* fall through */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001319 case HOSTAPD_CHAN_INVALID:
1320 default:
1321 hostapd_notify_bad_chans(iface);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001322 return -3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001323 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324}
1325
1326
1327const char * hostapd_hw_mode_txt(int mode)
1328{
1329 switch (mode) {
1330 case HOSTAPD_MODE_IEEE80211A:
1331 return "IEEE 802.11a";
1332 case HOSTAPD_MODE_IEEE80211B:
1333 return "IEEE 802.11b";
1334 case HOSTAPD_MODE_IEEE80211G:
1335 return "IEEE 802.11g";
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001336 case HOSTAPD_MODE_IEEE80211AD:
1337 return "IEEE 802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 default:
1339 return "UNKNOWN";
1340 }
1341}
1342
1343
1344int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1345{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001346 return hw_get_freq(hapd->iface->current_mode, chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001347}
1348
1349
1350int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1351{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001352 int i, channel;
1353 struct hostapd_hw_modes *mode;
1354
Hai Shalom1dc4d202019-04-29 16:22:27 -07001355 if (hapd->iface->current_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001356 channel = hw_get_chan(hapd->iface->current_mode->mode, freq,
1357 hapd->iface->hw_features,
1358 hapd->iface->num_hw_features);
Hai Shalom1dc4d202019-04-29 16:22:27 -07001359 if (channel)
1360 return channel;
1361 }
1362
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001363 /* Check other available modes since the channel list for the current
1364 * mode did not include the specified frequency. */
Hai Shalom1dc4d202019-04-29 16:22:27 -07001365 if (!hapd->iface->hw_features)
1366 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001367 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1368 mode = &hapd->iface->hw_features[i];
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001369 channel = hw_get_chan(mode->mode, freq,
1370 hapd->iface->hw_features,
1371 hapd->iface->num_hw_features);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001372 if (channel)
1373 return channel;
1374 }
1375 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376}
Hai Shalomfdcde762020-04-02 11:19:20 -07001377
1378
1379int hostapd_hw_skip_mode(struct hostapd_iface *iface,
1380 struct hostapd_hw_modes *mode)
1381{
1382 int i;
1383
1384 if (iface->current_mode)
1385 return mode != iface->current_mode;
1386 if (mode->mode != HOSTAPD_MODE_IEEE80211B)
1387 return 0;
1388 for (i = 0; i < iface->num_hw_features; i++) {
1389 if (iface->hw_features[i].mode == HOSTAPD_MODE_IEEE80211G)
1390 return 1;
1391 }
1392 return 0;
1393}