blob: 596f2f020a72088efca3ab689ba75cfd9b29be90 [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 Ravi88611412024-06-28 17:34:56 +0000110 is_6ghz = mode == HOSTAPD_MODE_IEEE80211A &&
111 iface->current_mode->num_channels > 0 &&
112 is_6ghz_freq(iface->current_mode->channels[0].freq);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000113 iface->current_mode = NULL;
114 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
116 iface->hw_features = modes;
117 iface->num_hw_features = num_modes;
118
119 for (i = 0; i < num_modes; i++) {
120 struct hostapd_hw_modes *feature = &modes[i];
Dmitry Shmidt051af732013-10-22 13:52:46 -0700121 int dfs_enabled = hapd->iconf->ieee80211h &&
122 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
123
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000124 /* Restore orignal mode if possible */
125 if (orig_mode_valid && feature->mode == mode &&
126 feature->num_channels > 0 &&
127 is_6ghz == is_6ghz_freq(feature->channels[0].freq))
128 iface->current_mode = feature;
129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 /* set flag for channels we can use in current regulatory
131 * domain */
132 for (j = 0; j < feature->num_channels; j++) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700133 int dfs = 0;
134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700135 /*
136 * Disable all channels that are marked not to allow
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800137 * to initiate radiation (a.k.a. passive scan and no
138 * IBSS).
Dmitry Shmidt051af732013-10-22 13:52:46 -0700139 * Use radar channels only if the driver supports DFS.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 */
Dmitry Shmidt051af732013-10-22 13:52:46 -0700141 if ((feature->channels[j].flag &
142 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
143 dfs = 1;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700144 } else if (((feature->channels[j].flag &
145 HOSTAPD_CHAN_RADAR) &&
146 !(iface->drv_flags &
147 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
148 (feature->channels[j].flag &
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800149 HOSTAPD_CHAN_NO_IR)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150 feature->channels[j].flag |=
151 HOSTAPD_CHAN_DISABLED;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700152 }
153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
155 continue;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
Dmitry Shmidt051af732013-10-22 13:52:46 -0700158 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 feature->mode,
160 feature->channels[j].chan,
161 feature->channels[j].freq,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700162 feature->channels[j].max_tx_power,
163 dfs ? dfs_info(&feature->channels[j]) : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700164 }
165 }
166
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000167 if (orig_mode_valid && !iface->current_mode) {
168 wpa_printf(MSG_ERROR,
169 "%s: Could not update iface->current_mode",
170 __func__);
171 }
172
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800173 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174}
175
176
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177int hostapd_prepare_rates(struct hostapd_iface *iface,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 struct hostapd_hw_modes *mode)
179{
180 int i, num_basic_rates = 0;
181 int basic_rates_a[] = { 60, 120, 240, -1 };
182 int basic_rates_b[] = { 10, 20, -1 };
183 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
184 int *basic_rates;
185
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800186 if (iface->conf->basic_rates)
187 basic_rates = iface->conf->basic_rates;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188 else switch (mode->mode) {
189 case HOSTAPD_MODE_IEEE80211A:
190 basic_rates = basic_rates_a;
191 break;
192 case HOSTAPD_MODE_IEEE80211B:
193 basic_rates = basic_rates_b;
194 break;
195 case HOSTAPD_MODE_IEEE80211G:
196 basic_rates = basic_rates_g;
197 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800198 case HOSTAPD_MODE_IEEE80211AD:
199 return 0; /* No basic rates for 11ad */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200 default:
201 return -1;
202 }
203
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800204 i = 0;
205 while (basic_rates[i] >= 0)
206 i++;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700207 if (i)
208 i++; /* -1 termination */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800209 os_free(iface->basic_rates);
210 iface->basic_rates = os_malloc(i * sizeof(int));
211 if (iface->basic_rates)
212 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800214 os_free(iface->current_rates);
215 iface->num_rates = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800217 iface->current_rates =
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700218 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800219 if (!iface->current_rates) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
221 "table.");
222 return -1;
223 }
224
225 for (i = 0; i < mode->num_rates; i++) {
226 struct hostapd_rate_data *rate;
227
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800228 if (iface->conf->supported_rates &&
229 !hostapd_rate_found(iface->conf->supported_rates,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 mode->rates[i]))
231 continue;
232
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800233 rate = &iface->current_rates[iface->num_rates];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234 rate->rate = mode->rates[i];
235 if (hostapd_rate_found(basic_rates, rate->rate)) {
236 rate->flags |= HOSTAPD_RATE_BASIC;
237 num_basic_rates++;
238 }
239 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800240 iface->num_rates, rate->rate, rate->flags);
241 iface->num_rates++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 }
243
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800244 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
245 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700246 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
247 "rate sets (%d,%d).",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800248 iface->num_rates, num_basic_rates);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249 return -1;
250 }
251
252 return 0;
253}
254
255
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700256static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
257{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800258 int pri_freq, sec_freq;
259 struct hostapd_channel_data *p_chan, *s_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800261 pri_freq = iface->freq;
262 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800264 if (!iface->current_mode)
265 return 0;
266
267 p_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq, NULL,
268 iface->hw_features,
269 iface->num_hw_features);
270
271 s_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq, NULL,
272 iface->hw_features,
273 iface->num_hw_features);
274
275 return allowed_ht40_channel_pair(iface->current_mode->mode,
276 p_chan, s_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277}
278
279
280static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
281{
282 if (iface->conf->secondary_channel > 0) {
283 iface->conf->channel += 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800284 iface->freq += 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 iface->conf->secondary_channel = -1;
286 } else {
287 iface->conf->channel -= 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800288 iface->freq -= 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 iface->conf->secondary_channel = 1;
290 }
291}
292
293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
295 struct wpa_scan_results *scan_res)
296{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800297 unsigned int pri_freq, sec_freq;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800298 int res;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800299 struct hostapd_channel_data *pri_chan, *sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800301 pri_freq = iface->freq;
302 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800304 if (!iface->current_mode)
305 return 0;
306 pri_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq,
307 NULL, iface->hw_features,
308 iface->num_hw_features);
309 sec_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq,
310 NULL, iface->hw_features,
311 iface->num_hw_features);
312
313 res = check_40mhz_5g(scan_res, pri_chan, sec_chan);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800314
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800315 if (res == 2) {
316 if (iface->conf->no_pri_sec_switch) {
317 wpa_printf(MSG_DEBUG,
318 "Cannot switch PRI/SEC channels due to local constraint");
319 } else {
320 ieee80211n_switch_pri_sec(iface);
321 }
322 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800324 return !!res;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -0700325}
326
327
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
329 struct wpa_scan_results *scan_res)
330{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800331 int pri_chan, sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800333 pri_chan = iface->conf->channel;
334 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800336 return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
337 sec_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338}
339
340
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341static void ieee80211n_check_scan(struct hostapd_iface *iface)
342{
343 struct wpa_scan_results *scan_res;
344 int oper40;
Hai Shalom60840252021-02-19 19:02:11 -0800345 int res = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346
347 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
Dmitry Shmidt04949592012-07-19 12:16:46 -0700348 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349
350 iface->scan_cb = NULL;
351
352 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
353 if (scan_res == NULL) {
354 hostapd_setup_interface_complete(iface, 1);
355 return;
356 }
357
358 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
359 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
360 else
361 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
362 wpa_scan_results_free(scan_res);
363
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700364 iface->secondary_ch = iface->conf->secondary_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365 if (!oper40) {
366 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
367 "channel pri=%d sec=%d based on overlapping BSSes",
368 iface->conf->channel,
369 iface->conf->channel +
370 iface->conf->secondary_channel * 4);
371 iface->conf->secondary_channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700372 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
373 /*
374 * TODO: Could consider scheduling another scan to check
375 * if channel width can be changed if no coex reports
376 * are received from associating stations.
377 */
378 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379 }
380
Hai Shalom60840252021-02-19 19:02:11 -0800381#ifdef CONFIG_IEEE80211AX
382 if (iface->conf->secondary_channel &&
383 iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
384 iface->conf->ieee80211ax) {
385 struct he_capabilities *he_cap;
386
387 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
388 if (!(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
389 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_IN_2G)) {
390 wpa_printf(MSG_DEBUG,
391 "HE: 40 MHz channel width is not supported in 2.4 GHz; clear secondary channel configuration");
392 iface->conf->secondary_channel = 0;
393 }
394 }
395#endif /* CONFIG_IEEE80211AX */
396
397 if (iface->conf->secondary_channel)
398 res = ieee80211n_allowed_ht40_channel_pair(iface);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700399 if (!res) {
400 iface->conf->secondary_channel = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700401 hostapd_set_oper_centr_freq_seg0_idx(iface->conf, 0);
402 hostapd_set_oper_centr_freq_seg1_idx(iface->conf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +0000403 hostapd_set_oper_chwidth(iface->conf, CONF_OPER_CHWIDTH_USE_HT);
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800404 res = 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700405 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
406 }
407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 hostapd_setup_interface_complete(iface, !res);
409}
410
411
Dmitry Shmidt04949592012-07-19 12:16:46 -0700412static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
413 struct wpa_driver_scan_params *params)
414{
415 /* Scan only the affected frequency range */
416 int pri_freq, sec_freq;
417 int affected_start, affected_end;
418 int i, pos;
419 struct hostapd_hw_modes *mode;
420
421 if (iface->current_mode == NULL)
422 return;
423
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800424 pri_freq = iface->freq;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700425 if (iface->conf->secondary_channel > 0)
426 sec_freq = pri_freq + 20;
427 else
428 sec_freq = pri_freq - 20;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700429 /*
430 * Note: Need to find the PRI channel also in cases where the affected
431 * channel is the SEC channel of a 40 MHz BSS, so need to include the
432 * scanning coverage here to be 40 MHz from the center frequency.
433 */
434 affected_start = (pri_freq + sec_freq) / 2 - 40;
435 affected_end = (pri_freq + sec_freq) / 2 + 40;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700436 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
437 affected_start, affected_end);
438
439 mode = iface->current_mode;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700440 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700441 if (params->freqs == NULL)
442 return;
443 pos = 0;
444
445 for (i = 0; i < mode->num_channels; i++) {
446 struct hostapd_channel_data *chan = &mode->channels[i];
447 if (chan->flag & HOSTAPD_CHAN_DISABLED)
448 continue;
449 if (chan->freq < affected_start ||
450 chan->freq > affected_end)
451 continue;
452 params->freqs[pos++] = chan->freq;
453 }
454}
455
456
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800457static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
458 struct wpa_driver_scan_params *params)
459{
460 /* Scan only the affected frequency range */
461 int pri_freq;
462 int affected_start, affected_end;
463 int i, pos;
464 struct hostapd_hw_modes *mode;
465
466 if (iface->current_mode == NULL)
467 return;
468
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800469 pri_freq = iface->freq;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800470 if (iface->conf->secondary_channel > 0) {
471 affected_start = pri_freq - 10;
472 affected_end = pri_freq + 30;
473 } else {
474 affected_start = pri_freq - 30;
475 affected_end = pri_freq + 10;
476 }
477 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
478 affected_start, affected_end);
479
480 mode = iface->current_mode;
481 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
482 if (params->freqs == NULL)
483 return;
484 pos = 0;
485
486 for (i = 0; i < mode->num_channels; i++) {
487 struct hostapd_channel_data *chan = &mode->channels[i];
488 if (chan->flag & HOSTAPD_CHAN_DISABLED)
489 continue;
490 if (chan->freq < affected_start ||
491 chan->freq > affected_end)
492 continue;
493 params->freqs[pos++] = chan->freq;
494 }
495}
496
497
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700498static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
499{
500#define HT2040_COEX_SCAN_RETRY 15
501 struct hostapd_iface *iface = eloop_data;
502 struct wpa_driver_scan_params params;
503 int ret;
504
505 os_memset(&params, 0, sizeof(params));
506 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
507 ieee80211n_scan_channels_2g4(iface, &params);
508 else
509 ieee80211n_scan_channels_5g(iface, &params);
510
511 ret = hostapd_driver_scan(iface->bss[0], &params);
512 iface->num_ht40_scan_tries++;
513 os_free(params.freqs);
514
515 if (ret == -EBUSY &&
516 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
517 wpa_printf(MSG_ERROR,
518 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
519 ret, strerror(-ret), iface->num_ht40_scan_tries);
520 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
521 return;
522 }
523
524 if (ret == 0) {
525 iface->scan_cb = ieee80211n_check_scan;
526 return;
527 }
528
529 wpa_printf(MSG_DEBUG,
530 "Failed to request a scan in device, bringing up in HT20 mode");
531 iface->conf->secondary_channel = 0;
532 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
533 hostapd_setup_interface_complete(iface, 0);
534}
535
536
537void hostapd_stop_setup_timers(struct hostapd_iface *iface)
538{
539 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
540}
541
542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
544{
545 struct wpa_driver_scan_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700546 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800548 /* Check that HT40 is used and PRI / SEC switch is allowed */
549 if (!iface->conf->secondary_channel || iface->conf->no_pri_sec_switch)
550 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800552 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
554 "40 MHz channel");
555 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700556 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
557 ieee80211n_scan_channels_2g4(iface, &params);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800558 else
559 ieee80211n_scan_channels_5g(iface, &params);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700560
561 ret = hostapd_driver_scan(iface->bss[0], &params);
562 os_free(params.freqs);
563
564 if (ret == -EBUSY) {
565 wpa_printf(MSG_ERROR,
566 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
567 ret, strerror(-ret));
568 iface->num_ht40_scan_tries = 1;
569 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
570 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
571 return 1;
572 }
573
574 if (ret < 0) {
575 wpa_printf(MSG_ERROR,
576 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
577 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 return -1;
579 }
580
581 iface->scan_cb = ieee80211n_check_scan;
582 return 1;
583}
584
585
586static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
587{
588 u16 hw = iface->current_mode->ht_capab;
589 u16 conf = iface->conf->ht_capab;
590
591 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
592 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
593 wpa_printf(MSG_ERROR, "Driver does not support configured "
594 "HT capability [LDPC]");
595 return 0;
596 }
597
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700598 /*
599 * Driver ACS chosen channel may not be HT40 due to internal driver
600 * restrictions.
601 */
602 if (!iface->conf->acs && (conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
604 wpa_printf(MSG_ERROR, "Driver does not support configured "
605 "HT capability [HT40*]");
606 return 0;
607 }
608
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
610 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
611 wpa_printf(MSG_ERROR, "Driver does not support configured "
612 "HT capability [GF]");
613 return 0;
614 }
615
616 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
617 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
618 wpa_printf(MSG_ERROR, "Driver does not support configured "
619 "HT capability [SHORT-GI-20]");
620 return 0;
621 }
622
623 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
624 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
625 wpa_printf(MSG_ERROR, "Driver does not support configured "
626 "HT capability [SHORT-GI-40]");
627 return 0;
628 }
629
630 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
631 wpa_printf(MSG_ERROR, "Driver does not support configured "
632 "HT capability [TX-STBC]");
633 return 0;
634 }
635
636 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
637 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
638 wpa_printf(MSG_ERROR, "Driver does not support configured "
639 "HT capability [RX-STBC*]");
640 return 0;
641 }
642
643 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
644 !(hw & HT_CAP_INFO_DELAYED_BA)) {
645 wpa_printf(MSG_ERROR, "Driver does not support configured "
646 "HT capability [DELAYED-BA]");
647 return 0;
648 }
649
650 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
651 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
652 wpa_printf(MSG_ERROR, "Driver does not support configured "
653 "HT capability [MAX-AMSDU-7935]");
654 return 0;
655 }
656
657 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
658 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
659 wpa_printf(MSG_ERROR, "Driver does not support configured "
660 "HT capability [DSSS_CCK-40]");
661 return 0;
662 }
663
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
665 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
666 wpa_printf(MSG_ERROR, "Driver does not support configured "
667 "HT capability [LSIG-TXOP-PROT]");
668 return 0;
669 }
670
671 return 1;
672}
673
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700674
675#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700676static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
677{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800678 struct hostapd_hw_modes *mode = iface->current_mode;
679 u32 hw = mode->vht_capab;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700680 u32 conf = iface->conf->vht_capab;
681
682 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
683 hw, conf);
684
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800685 if (mode->mode == HOSTAPD_MODE_IEEE80211G &&
686 iface->conf->bss[0]->vendor_vht &&
687 mode->vht_capab == 0 && iface->hw_features) {
688 int i;
689
690 for (i = 0; i < iface->num_hw_features; i++) {
691 if (iface->hw_features[i].mode ==
692 HOSTAPD_MODE_IEEE80211A) {
693 mode = &iface->hw_features[i];
694 hw = mode->vht_capab;
695 wpa_printf(MSG_DEBUG,
696 "update hw vht capab based on 5 GHz band: 0x%x",
697 hw);
698 break;
699 }
700 }
701 }
702
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800703 return ieee80211ac_cap_check(hw, conf);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700704}
705#endif /* CONFIG_IEEE80211AC */
706
Hai Shalom81f62d82019-07-22 12:10:00 -0700707
708#ifdef CONFIG_IEEE80211AX
709static int ieee80211ax_supported_he_capab(struct hostapd_iface *iface)
710{
711 return 1;
712}
713#endif /* CONFIG_IEEE80211AX */
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715
716int hostapd_check_ht_capab(struct hostapd_iface *iface)
717{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 int ret;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800719
720 if (is_6ghz_freq(iface->freq))
721 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 if (!iface->conf->ieee80211n)
723 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800724
725 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211B &&
726 iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G &&
727 (iface->conf->ht_capab & HT_CAP_INFO_DSSS_CCK40MHZ)) {
728 wpa_printf(MSG_DEBUG,
729 "Disable HT capability [DSSS_CCK-40] on 5 GHz band");
730 iface->conf->ht_capab &= ~HT_CAP_INFO_DSSS_CCK40MHZ;
731 }
732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 if (!ieee80211n_supported_ht_capab(iface))
734 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700735#ifdef CONFIG_IEEE80211AX
736 if (iface->conf->ieee80211ax &&
737 !ieee80211ax_supported_he_capab(iface))
738 return -1;
739#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700740#ifdef CONFIG_IEEE80211AC
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800741 if (iface->conf->ieee80211ac &&
742 !ieee80211ac_supported_vht_capab(iface))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700743 return -1;
744#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 ret = ieee80211n_check_40mhz(iface);
746 if (ret)
747 return ret;
748 if (!ieee80211n_allowed_ht40_channel_pair(iface))
749 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750
751 return 0;
752}
753
754
Hai Shalomc3565922019-10-28 11:58:20 -0700755int hostapd_check_edmg_capab(struct hostapd_iface *iface)
756{
757 struct hostapd_hw_modes *mode = iface->hw_features;
758 struct ieee80211_edmg_config edmg;
759
760 if (!iface->conf->enable_edmg)
761 return 0;
762
763 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
764 iface->conf->edmg_channel,
765 iface->conf->channel,
766 &edmg);
767
768 if (mode->edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg))
769 return 0;
770
771 wpa_printf(MSG_WARNING, "Requested EDMG configuration is not valid");
772 wpa_printf(MSG_INFO, "EDMG capab: channels 0x%x, bw_config %d",
773 mode->edmg.channels, mode->edmg.bw_config);
774 wpa_printf(MSG_INFO,
775 "Requested EDMG configuration: channels 0x%x, bw_config %d",
776 edmg.channels, edmg.bw_config);
777 return -1;
778}
779
780
Hai Shalom60840252021-02-19 19:02:11 -0800781int hostapd_check_he_6ghz_capab(struct hostapd_iface *iface)
782{
783#ifdef CONFIG_IEEE80211AX
784 struct he_capabilities *he_cap;
785 u16 hw;
786
787 if (!iface->current_mode || !is_6ghz_freq(iface->freq))
788 return 0;
789
790 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
791 hw = he_cap->he_6ghz_capa;
792 if (iface->conf->he_6ghz_max_mpdu >
793 ((hw & HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_MASK) >>
794 HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_SHIFT)) {
795 wpa_printf(MSG_ERROR,
796 "The driver does not support the configured HE 6 GHz Max MPDU length");
797 return -1;
798 }
799
800 if (iface->conf->he_6ghz_max_ampdu_len_exp >
801 ((hw & HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_MASK) >>
802 HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_SHIFT)) {
803 wpa_printf(MSG_ERROR,
804 "The driver does not support the configured HE 6 GHz Max AMPDU Length Exponent");
805 return -1;
806 }
807
808 if (iface->conf->he_6ghz_rx_ant_pat &&
809 !(hw & HE_6GHZ_BAND_CAP_RX_ANTPAT_CONS)) {
810 wpa_printf(MSG_ERROR,
811 "The driver does not support the configured HE 6 GHz Rx Antenna Pattern");
812 return -1;
813 }
814
815 if (iface->conf->he_6ghz_tx_ant_pat &&
816 !(hw & HE_6GHZ_BAND_CAP_TX_ANTPAT_CONS)) {
817 wpa_printf(MSG_ERROR,
818 "The driver does not support the configured HE 6 GHz Tx Antenna Pattern");
819 return -1;
820 }
821#endif /* CONFIG_IEEE80211AX */
822 return 0;
823}
824
825
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000826/* Returns:
827 * 1 = usable
828 * 0 = not usable
829 * -1 = not currently usable due to 6 GHz NO-IR
830 */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700831static int hostapd_is_usable_chan(struct hostapd_iface *iface,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800832 int frequency, int primary)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700833{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700834 struct hostapd_channel_data *chan;
835
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700836 if (!iface->current_mode)
837 return 0;
838
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800839 chan = hw_get_channel_freq(iface->current_mode->mode, frequency, NULL,
840 iface->hw_features, iface->num_hw_features);
Hai Shalom74f70d42019-02-11 14:42:39 -0800841 if (!chan)
842 return 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700843
Hai Shalom74f70d42019-02-11 14:42:39 -0800844 if ((primary && chan_pri_allowed(chan)) ||
845 (!primary && !(chan->flag & HOSTAPD_CHAN_DISABLED)))
846 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700847
Hai Shalom74f70d42019-02-11 14:42:39 -0800848 wpa_printf(MSG_INFO,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800849 "Frequency %d (%s) not allowed for AP mode, flags: 0x%x%s%s",
850 frequency, primary ? "primary" : "secondary",
Hai Shalom74f70d42019-02-11 14:42:39 -0800851 chan->flag,
852 chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
853 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000854
855 if (is_6ghz_freq(chan->freq) && (chan->flag & HOSTAPD_CHAN_NO_IR))
856 return -1;
857
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700858 return 0;
859}
860
861
Hai Shalomc3565922019-10-28 11:58:20 -0700862static int hostapd_is_usable_edmg(struct hostapd_iface *iface)
863{
864 int i, contiguous = 0;
865 int num_of_enabled = 0;
866 int max_contiguous = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000867 int err;
Hai Shalomc3565922019-10-28 11:58:20 -0700868 struct ieee80211_edmg_config edmg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800869 struct hostapd_channel_data *pri_chan;
Hai Shalomc3565922019-10-28 11:58:20 -0700870
871 if (!iface->conf->enable_edmg)
872 return 1;
873
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800874 if (!iface->current_mode)
875 return 0;
876 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
877 iface->freq, NULL,
878 iface->hw_features,
879 iface->num_hw_features);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800880 if (!pri_chan)
881 return 0;
Hai Shalomc3565922019-10-28 11:58:20 -0700882 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
883 iface->conf->edmg_channel,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800884 pri_chan->chan,
Hai Shalomc3565922019-10-28 11:58:20 -0700885 &edmg);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800886 if (!(edmg.channels & BIT(pri_chan->chan - 1)))
Hai Shalomc3565922019-10-28 11:58:20 -0700887 return 0;
888
889 /* 60 GHz channels 1..6 */
890 for (i = 0; i < 6; i++) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700891 int freq = 56160 + 2160 * (i + 1);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800892
Hai Shalomc3565922019-10-28 11:58:20 -0700893 if (edmg.channels & BIT(i)) {
894 contiguous++;
895 num_of_enabled++;
896 } else {
897 contiguous = 0;
898 continue;
899 }
900
901 /* P802.11ay defines that the total number of subfields
902 * set to one does not exceed 4.
903 */
904 if (num_of_enabled > 4)
905 return 0;
906
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000907 err = hostapd_is_usable_chan(iface, freq, 1);
908 if (err <= 0)
909 return err;
Hai Shalomc3565922019-10-28 11:58:20 -0700910
911 if (contiguous > max_contiguous)
912 max_contiguous = contiguous;
913 }
914
915 /* Check if the EDMG configuration is valid under the limitations
916 * of P802.11ay.
917 */
918 /* check bw_config against contiguous EDMG channels */
919 switch (edmg.bw_config) {
920 case EDMG_BW_CONFIG_4:
921 if (!max_contiguous)
922 return 0;
923 break;
924 case EDMG_BW_CONFIG_5:
925 if (max_contiguous < 2)
926 return 0;
927 break;
928 default:
929 return 0;
930 }
931
932 return 1;
933}
934
935
Sunil Ravi036cec52023-03-29 11:35:17 -0700936static bool hostapd_is_usable_punct_bitmap(struct hostapd_iface *iface)
937{
938#ifdef CONFIG_IEEE80211BE
939 struct hostapd_config *conf = iface->conf;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000940 u16 bw;
941 u8 start_chan;
Sunil Ravi036cec52023-03-29 11:35:17 -0700942
943 if (!conf->punct_bitmap)
944 return true;
945
946 if (!conf->ieee80211be) {
947 wpa_printf(MSG_ERROR,
948 "Currently RU puncturing is supported only if ieee80211be is enabled");
949 return false;
950 }
951
952 if (iface->freq >= 2412 && iface->freq <= 2484) {
953 wpa_printf(MSG_ERROR,
954 "RU puncturing not supported in 2.4 GHz");
955 return false;
956 }
957
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000958 /*
959 * In the 6 GHz band, eht_oper_chwidth is ignored. Use operating class
960 * to determine channel width.
961 */
962 if (conf->op_class == 137) {
963 bw = 320;
964 start_chan = conf->eht_oper_centr_freq_seg0_idx - 30;
965 } else {
966 switch (conf->eht_oper_chwidth) {
967 case 0:
968 wpa_printf(MSG_ERROR,
969 "RU puncturing is supported only in 80 MHz and 160 MHz");
970 return false;
971 case 1:
972 bw = 80;
973 start_chan = conf->eht_oper_centr_freq_seg0_idx - 6;
974 break;
975 case 2:
976 bw = 160;
977 start_chan = conf->eht_oper_centr_freq_seg0_idx - 14;
978 break;
979 default:
980 return false;
981 }
Sunil Ravi036cec52023-03-29 11:35:17 -0700982 }
983
984 if (!is_punct_bitmap_valid(bw, (conf->channel - start_chan) / 4,
985 conf->punct_bitmap)) {
986 wpa_printf(MSG_ERROR, "Invalid puncturing bitmap");
987 return false;
988 }
989#endif /* CONFIG_IEEE80211BE */
990
991 return true;
992}
993
994
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000995/* Returns:
996 * 1 = usable
997 * 0 = not usable
998 * -1 = not currently usable due to 6 GHz NO-IR
999 */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001000static int hostapd_is_usable_chans(struct hostapd_iface *iface)
1001{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001002 int secondary_freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001003 struct hostapd_channel_data *pri_chan;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001004 int err, err2;
Hai Shalom74f70d42019-02-11 14:42:39 -08001005
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001006 if (!iface->current_mode)
Hai Shalom74f70d42019-02-11 14:42:39 -08001007 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001008 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
1009 iface->freq, NULL,
1010 iface->hw_features,
1011 iface->num_hw_features);
1012 if (!pri_chan) {
1013 wpa_printf(MSG_ERROR, "Primary frequency not present");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001014 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001015 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001016
1017 err = hostapd_is_usable_chan(iface, pri_chan->freq, 1);
1018 if (err <= 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001019 wpa_printf(MSG_ERROR, "Primary frequency not allowed");
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001020 return err;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001021 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001022 err = hostapd_is_usable_edmg(iface);
1023 if (err <= 0)
1024 return err;
Hai Shalomc3565922019-10-28 11:58:20 -07001025
Sunil Ravi036cec52023-03-29 11:35:17 -07001026 if (!hostapd_is_usable_punct_bitmap(iface))
1027 return 0;
1028
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001029 if (!iface->conf->secondary_channel)
1030 return 1;
1031
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001032 err = hostapd_is_usable_chan(iface, iface->freq +
1033 iface->conf->secondary_channel * 20, 0);
1034 if (err > 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08001035 if (iface->conf->secondary_channel == 1 &&
1036 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P))
1037 return 1;
1038 if (iface->conf->secondary_channel == -1 &&
1039 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M))
1040 return 1;
1041 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001042 if (!iface->conf->ht40_plus_minus_allowed)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001043 return err;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001044
1045 /* Both HT40+ and HT40- are set, pick a valid secondary channel */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001046 secondary_freq = iface->freq + 20;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001047 err2 = hostapd_is_usable_chan(iface, secondary_freq, 0);
1048 if (err2 > 0 && (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001049 iface->conf->secondary_channel = 1;
1050 return 1;
1051 }
1052
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001053 secondary_freq = iface->freq - 20;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001054 err2 = hostapd_is_usable_chan(iface, secondary_freq, 0);
1055 if (err2 > 0 && (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001056 iface->conf->secondary_channel = -1;
1057 return 1;
1058 }
1059
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001060 return err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001061}
1062
1063
Sunil Ravi640215c2023-06-28 23:08:09 +00001064static bool skip_mode(struct hostapd_iface *iface,
1065 struct hostapd_hw_modes *mode)
1066{
1067 int chan;
1068
1069 if (iface->freq > 0 && !hw_mode_get_channel(mode, iface->freq, &chan))
1070 return true;
1071
1072 if (is_6ghz_op_class(iface->conf->op_class) && iface->freq == 0 &&
Sunil Ravi88611412024-06-28 17:34:56 +00001073 (mode->mode != HOSTAPD_MODE_IEEE80211A ||
1074 mode->num_channels == 0 ||
1075 !is_6ghz_freq(mode->channels[0].freq)))
Sunil Ravi640215c2023-06-28 23:08:09 +00001076 return true;
1077
1078 return false;
1079}
1080
1081
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001082int hostapd_determine_mode(struct hostapd_iface *iface)
Hai Shalomfdcde762020-04-02 11:19:20 -07001083{
1084 int i;
1085 enum hostapd_hw_mode target_mode;
1086
1087 if (iface->current_mode ||
1088 iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001089 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001090
1091 if (iface->freq < 4000)
1092 target_mode = HOSTAPD_MODE_IEEE80211G;
1093 else if (iface->freq > 50000)
1094 target_mode = HOSTAPD_MODE_IEEE80211AD;
1095 else
1096 target_mode = HOSTAPD_MODE_IEEE80211A;
1097
1098 for (i = 0; i < iface->num_hw_features; i++) {
1099 struct hostapd_hw_modes *mode;
1100
1101 mode = &iface->hw_features[i];
1102 if (mode->mode == target_mode) {
Sunil Ravi640215c2023-06-28 23:08:09 +00001103 if (skip_mode(iface, mode))
1104 continue;
1105
Hai Shalomfdcde762020-04-02 11:19:20 -07001106 iface->current_mode = mode;
1107 iface->conf->hw_mode = mode->mode;
1108 break;
1109 }
1110 }
1111
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001112 if (!iface->current_mode) {
1113 wpa_printf(MSG_ERROR, "ACS/CSA: Cannot decide mode");
1114 return -1;
1115 }
1116 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07001117}
1118
1119
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001120static enum hostapd_chan_status
1121hostapd_check_chans(struct hostapd_iface *iface)
1122{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001123 if (iface->freq) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001124 int err;
1125
Hai Shalomfdcde762020-04-02 11:19:20 -07001126 hostapd_determine_mode(iface);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001127
1128 err = hostapd_is_usable_chans(iface);
1129 if (err <= 0) {
1130 if (!err)
1131 return HOSTAPD_CHAN_INVALID;
1132 return HOSTAPD_CHAN_INVALID_NO_IR;
1133 }
1134 return HOSTAPD_CHAN_VALID;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001135 }
1136
1137 /*
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001138 * The user set channel=0 or channel=acs_survey
1139 * which is used to trigger ACS.
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001140 */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001141
1142 switch (acs_init(iface)) {
1143 case HOSTAPD_CHAN_ACS:
1144 return HOSTAPD_CHAN_ACS;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001145 case HOSTAPD_CHAN_INVALID_NO_IR:
1146 return HOSTAPD_CHAN_INVALID_NO_IR;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001147 case HOSTAPD_CHAN_VALID:
1148 case HOSTAPD_CHAN_INVALID:
1149 default:
1150 return HOSTAPD_CHAN_INVALID;
1151 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001152}
1153
1154
1155static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
1156{
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001157 if (!iface->current_mode) {
1158 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1159 HOSTAPD_LEVEL_WARNING,
1160 "Hardware does not support configured mode");
1161 return;
1162 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001163 hostapd_logger(iface->bss[0], NULL,
1164 HOSTAPD_MODULE_IEEE80211,
1165 HOSTAPD_LEVEL_WARNING,
Hai Shalom60840252021-02-19 19:02:11 -08001166 "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 -07001167 iface->conf->channel,
Hai Shalom60840252021-02-19 19:02:11 -08001168 iface->freq, iface->conf->secondary_channel,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001169 iface->current_mode->mode,
1170 hostapd_hw_mode_txt(iface->current_mode->mode));
1171 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1172 HOSTAPD_LEVEL_WARNING,
1173 "Hardware does not support configured channel");
1174}
1175
1176
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001177int hostapd_acs_completed(struct hostapd_iface *iface, int err)
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001178{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001179 int ret = -1;
1180
1181 if (err)
1182 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001183
1184 switch (hostapd_check_chans(iface)) {
1185 case HOSTAPD_CHAN_VALID:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001186 iface->is_no_ir = false;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001187 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
1188 ACS_EVENT_COMPLETED "freq=%d channel=%d",
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001189 iface->freq, iface->conf->channel);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001190 break;
1191 case HOSTAPD_CHAN_ACS:
1192 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001193 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001194 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001195 goto out;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001196 case HOSTAPD_CHAN_INVALID_NO_IR:
1197 iface->is_no_ir = true;
1198 /* fall through */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001199 case HOSTAPD_CHAN_INVALID:
1200 default:
1201 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
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;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001205 }
1206
1207 ret = hostapd_check_ht_capab(iface);
1208 if (ret < 0)
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001209 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001210 if (ret == 1) {
1211 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
1212 return 0;
1213 }
1214
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001215 ret = 0;
1216out:
1217 return hostapd_setup_interface_complete(iface, ret);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001218}
1219
1220
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221/**
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001222 * hostapd_csa_update_hwmode - Update hardware mode
1223 * @iface: Pointer to interface data.
1224 * Returns: 0 on success, < 0 on failure
1225 *
1226 * Update hardware mode when the operating channel changed because of CSA.
1227 */
1228int hostapd_csa_update_hwmode(struct hostapd_iface *iface)
1229{
1230 if (!iface || !iface->conf)
1231 return -1;
1232
1233 iface->current_mode = NULL;
1234 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211ANY;
1235
1236 return hostapd_determine_mode(iface);
1237}
1238
1239
1240/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241 * hostapd_select_hw_mode - Select the hardware mode
1242 * @iface: Pointer to interface data.
Jouni Malinen87fd2792011-05-16 18:35:42 +03001243 * Returns: 0 on success, < 0 on failure
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 *
1245 * Sets up the hardware mode, channel, rates, and passive scanning
1246 * based on the configuration.
1247 */
1248int hostapd_select_hw_mode(struct hostapd_iface *iface)
1249{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001250 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251
1252 if (iface->num_hw_features < 1)
1253 return -1;
1254
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001255 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
Hai Shalom81f62d82019-07-22 12:10:00 -07001256 iface->conf->ieee80211n || iface->conf->ieee80211ac ||
Sunil8cd6f4d2022-06-28 18:40:46 +00001257 iface->conf->ieee80211ax || iface->conf->ieee80211be) &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001258 iface->conf->channel == 14) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001259 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT/HE/EHT on channel 14");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001260 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1261 iface->conf->ieee80211n = 0;
1262 iface->conf->ieee80211ac = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -07001263 iface->conf->ieee80211ax = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00001264 iface->conf->ieee80211be = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001265 }
1266
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 iface->current_mode = NULL;
1268 for (i = 0; i < iface->num_hw_features; i++) {
1269 struct hostapd_hw_modes *mode = &iface->hw_features[i];
Hai Shalom60840252021-02-19 19:02:11 -08001270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271 if (mode->mode == iface->conf->hw_mode) {
Sunil Ravi640215c2023-06-28 23:08:09 +00001272 if (skip_mode(iface, mode))
Hai Shalomc3565922019-10-28 11:58:20 -07001273 continue;
Hai Shalom60840252021-02-19 19:02:11 -08001274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001275 iface->current_mode = mode;
1276 break;
1277 }
1278 }
1279
1280 if (iface->current_mode == NULL) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001281 if ((iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1282 (iface->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY)) {
1283 wpa_printf(MSG_DEBUG,
1284 "Using offloaded hw_mode=any ACS");
1285 } else if (!(iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1286 iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211ANY) {
1287 wpa_printf(MSG_DEBUG,
1288 "Using internal ACS for hw_mode=any");
1289 } else {
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001290 wpa_printf(MSG_ERROR,
1291 "Hardware does not support configured mode");
1292 hostapd_logger(iface->bss[0], NULL,
1293 HOSTAPD_MODULE_IEEE80211,
1294 HOSTAPD_LEVEL_WARNING,
1295 "Hardware does not support configured mode (%d) (hw_mode in hostapd.conf)",
1296 (int) iface->conf->hw_mode);
1297 return -2;
1298 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001299 }
1300
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001301 switch (hostapd_check_chans(iface)) {
1302 case HOSTAPD_CHAN_VALID:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001303 iface->is_no_ir = false;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001304 return 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001305 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1306 return 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001307 case HOSTAPD_CHAN_INVALID_NO_IR:
1308 iface->is_no_ir = true;
1309 /* fall through */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001310 case HOSTAPD_CHAN_INVALID:
1311 default:
1312 hostapd_notify_bad_chans(iface);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001313 return -3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315}
1316
1317
1318const char * hostapd_hw_mode_txt(int mode)
1319{
1320 switch (mode) {
1321 case HOSTAPD_MODE_IEEE80211A:
1322 return "IEEE 802.11a";
1323 case HOSTAPD_MODE_IEEE80211B:
1324 return "IEEE 802.11b";
1325 case HOSTAPD_MODE_IEEE80211G:
1326 return "IEEE 802.11g";
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001327 case HOSTAPD_MODE_IEEE80211AD:
1328 return "IEEE 802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 default:
1330 return "UNKNOWN";
1331 }
1332}
1333
1334
1335int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1336{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001337 return hw_get_freq(hapd->iface->current_mode, chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338}
1339
1340
1341int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1342{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001343 int i, channel;
1344 struct hostapd_hw_modes *mode;
1345
Hai Shalom1dc4d202019-04-29 16:22:27 -07001346 if (hapd->iface->current_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001347 channel = hw_get_chan(hapd->iface->current_mode->mode, freq,
1348 hapd->iface->hw_features,
1349 hapd->iface->num_hw_features);
Hai Shalom1dc4d202019-04-29 16:22:27 -07001350 if (channel)
1351 return channel;
1352 }
1353
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001354 /* Check other available modes since the channel list for the current
1355 * mode did not include the specified frequency. */
Hai Shalom1dc4d202019-04-29 16:22:27 -07001356 if (!hapd->iface->hw_features)
1357 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001358 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1359 mode = &hapd->iface->hw_features[i];
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001360 channel = hw_get_chan(mode->mode, freq,
1361 hapd->iface->hw_features,
1362 hapd->iface->num_hw_features);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001363 if (channel)
1364 return channel;
1365 }
1366 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367}
Hai Shalomfdcde762020-04-02 11:19:20 -07001368
1369
1370int hostapd_hw_skip_mode(struct hostapd_iface *iface,
1371 struct hostapd_hw_modes *mode)
1372{
1373 int i;
1374
1375 if (iface->current_mode)
1376 return mode != iface->current_mode;
1377 if (mode->mode != HOSTAPD_MODE_IEEE80211B)
1378 return 0;
1379 for (i = 0; i < iface->num_hw_features; i++) {
1380 if (iface->hw_features[i].mode == HOSTAPD_MODE_IEEE80211G)
1381 return 1;
1382 }
1383 return 0;
1384}