blob: ba10752ebd7e0f2ed718987fcde0eb2720e797a4 [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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082
83 if (hostapd_drv_none(hapd))
84 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070085 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags,
86 &dfs_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087 if (modes == NULL) {
88 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
89 HOSTAPD_LEVEL_DEBUG,
90 "Fetching hardware channel/rate support not "
91 "supported.");
92 return -1;
93 }
94
95 iface->hw_flags = flags;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070096 iface->dfs_domain = dfs_domain;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097
98 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
99 iface->hw_features = modes;
100 iface->num_hw_features = num_modes;
101
102 for (i = 0; i < num_modes; i++) {
103 struct hostapd_hw_modes *feature = &modes[i];
Dmitry Shmidt051af732013-10-22 13:52:46 -0700104 int dfs_enabled = hapd->iconf->ieee80211h &&
105 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107 /* set flag for channels we can use in current regulatory
108 * domain */
109 for (j = 0; j < feature->num_channels; j++) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700110 int dfs = 0;
111
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 /*
113 * Disable all channels that are marked not to allow
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800114 * to initiate radiation (a.k.a. passive scan and no
115 * IBSS).
Dmitry Shmidt051af732013-10-22 13:52:46 -0700116 * Use radar channels only if the driver supports DFS.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700117 */
Dmitry Shmidt051af732013-10-22 13:52:46 -0700118 if ((feature->channels[j].flag &
119 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
120 dfs = 1;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700121 } else if (((feature->channels[j].flag &
122 HOSTAPD_CHAN_RADAR) &&
123 !(iface->drv_flags &
124 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
125 (feature->channels[j].flag &
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800126 HOSTAPD_CHAN_NO_IR)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700127 feature->channels[j].flag |=
128 HOSTAPD_CHAN_DISABLED;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700129 }
130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
132 continue;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
Dmitry Shmidt051af732013-10-22 13:52:46 -0700135 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136 feature->mode,
137 feature->channels[j].chan,
138 feature->channels[j].freq,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700139 feature->channels[j].max_tx_power,
140 dfs ? dfs_info(&feature->channels[j]) : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141 }
142 }
143
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800144 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145}
146
147
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800148int hostapd_prepare_rates(struct hostapd_iface *iface,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700149 struct hostapd_hw_modes *mode)
150{
151 int i, num_basic_rates = 0;
152 int basic_rates_a[] = { 60, 120, 240, -1 };
153 int basic_rates_b[] = { 10, 20, -1 };
154 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
155 int *basic_rates;
156
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800157 if (iface->conf->basic_rates)
158 basic_rates = iface->conf->basic_rates;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 else switch (mode->mode) {
160 case HOSTAPD_MODE_IEEE80211A:
161 basic_rates = basic_rates_a;
162 break;
163 case HOSTAPD_MODE_IEEE80211B:
164 basic_rates = basic_rates_b;
165 break;
166 case HOSTAPD_MODE_IEEE80211G:
167 basic_rates = basic_rates_g;
168 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800169 case HOSTAPD_MODE_IEEE80211AD:
170 return 0; /* No basic rates for 11ad */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 default:
172 return -1;
173 }
174
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800175 i = 0;
176 while (basic_rates[i] >= 0)
177 i++;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700178 if (i)
179 i++; /* -1 termination */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800180 os_free(iface->basic_rates);
181 iface->basic_rates = os_malloc(i * sizeof(int));
182 if (iface->basic_rates)
183 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800185 os_free(iface->current_rates);
186 iface->num_rates = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700187
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800188 iface->current_rates =
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800190 if (!iface->current_rates) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
192 "table.");
193 return -1;
194 }
195
196 for (i = 0; i < mode->num_rates; i++) {
197 struct hostapd_rate_data *rate;
198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800199 if (iface->conf->supported_rates &&
200 !hostapd_rate_found(iface->conf->supported_rates,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700201 mode->rates[i]))
202 continue;
203
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800204 rate = &iface->current_rates[iface->num_rates];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 rate->rate = mode->rates[i];
206 if (hostapd_rate_found(basic_rates, rate->rate)) {
207 rate->flags |= HOSTAPD_RATE_BASIC;
208 num_basic_rates++;
209 }
210 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800211 iface->num_rates, rate->rate, rate->flags);
212 iface->num_rates++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213 }
214
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800215 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
216 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
218 "rate sets (%d,%d).",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800219 iface->num_rates, num_basic_rates);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 return -1;
221 }
222
223 return 0;
224}
225
226
227#ifdef CONFIG_IEEE80211N
228static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
229{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800230 int pri_freq, sec_freq;
231 struct hostapd_channel_data *p_chan, *s_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800233 pri_freq = iface->freq;
234 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800236 if (!iface->current_mode)
237 return 0;
238
239 p_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq, NULL,
240 iface->hw_features,
241 iface->num_hw_features);
242
243 s_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq, NULL,
244 iface->hw_features,
245 iface->num_hw_features);
246
247 return allowed_ht40_channel_pair(iface->current_mode->mode,
248 p_chan, s_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249}
250
251
252static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
253{
254 if (iface->conf->secondary_channel > 0) {
255 iface->conf->channel += 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800256 iface->freq += 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 iface->conf->secondary_channel = -1;
258 } else {
259 iface->conf->channel -= 4;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800260 iface->freq -= 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261 iface->conf->secondary_channel = 1;
262 }
263}
264
265
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700266static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
267 struct wpa_scan_results *scan_res)
268{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800269 unsigned int pri_freq, sec_freq;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800270 int res;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800271 struct hostapd_channel_data *pri_chan, *sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800273 pri_freq = iface->freq;
274 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800276 if (!iface->current_mode)
277 return 0;
278 pri_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq,
279 NULL, iface->hw_features,
280 iface->num_hw_features);
281 sec_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq,
282 NULL, iface->hw_features,
283 iface->num_hw_features);
284
285 res = check_40mhz_5g(scan_res, pri_chan, sec_chan);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800286
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800287 if (res == 2) {
288 if (iface->conf->no_pri_sec_switch) {
289 wpa_printf(MSG_DEBUG,
290 "Cannot switch PRI/SEC channels due to local constraint");
291 } else {
292 ieee80211n_switch_pri_sec(iface);
293 }
294 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800296 return !!res;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -0700297}
298
299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
301 struct wpa_scan_results *scan_res)
302{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800303 int pri_chan, sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800305 pri_chan = iface->conf->channel;
306 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800308 return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
309 sec_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310}
311
312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313static void ieee80211n_check_scan(struct hostapd_iface *iface)
314{
315 struct wpa_scan_results *scan_res;
316 int oper40;
317 int res;
318
319 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
Dmitry Shmidt04949592012-07-19 12:16:46 -0700320 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321
322 iface->scan_cb = NULL;
323
324 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
325 if (scan_res == NULL) {
326 hostapd_setup_interface_complete(iface, 1);
327 return;
328 }
329
330 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
331 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
332 else
333 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
334 wpa_scan_results_free(scan_res);
335
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700336 iface->secondary_ch = iface->conf->secondary_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 if (!oper40) {
338 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
339 "channel pri=%d sec=%d based on overlapping BSSes",
340 iface->conf->channel,
341 iface->conf->channel +
342 iface->conf->secondary_channel * 4);
343 iface->conf->secondary_channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700344 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
345 /*
346 * TODO: Could consider scheduling another scan to check
347 * if channel width can be changed if no coex reports
348 * are received from associating stations.
349 */
350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 }
352
353 res = ieee80211n_allowed_ht40_channel_pair(iface);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700354 if (!res) {
355 iface->conf->secondary_channel = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700356 hostapd_set_oper_centr_freq_seg0_idx(iface->conf, 0);
357 hostapd_set_oper_centr_freq_seg1_idx(iface->conf, 0);
358 hostapd_set_oper_chwidth(iface->conf, CHANWIDTH_USE_HT);
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800359 res = 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700360 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
361 }
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 hostapd_setup_interface_complete(iface, !res);
364}
365
366
Dmitry Shmidt04949592012-07-19 12:16:46 -0700367static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
368 struct wpa_driver_scan_params *params)
369{
370 /* Scan only the affected frequency range */
371 int pri_freq, sec_freq;
372 int affected_start, affected_end;
373 int i, pos;
374 struct hostapd_hw_modes *mode;
375
376 if (iface->current_mode == NULL)
377 return;
378
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800379 pri_freq = iface->freq;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700380 if (iface->conf->secondary_channel > 0)
381 sec_freq = pri_freq + 20;
382 else
383 sec_freq = pri_freq - 20;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700384 /*
385 * Note: Need to find the PRI channel also in cases where the affected
386 * channel is the SEC channel of a 40 MHz BSS, so need to include the
387 * scanning coverage here to be 40 MHz from the center frequency.
388 */
389 affected_start = (pri_freq + sec_freq) / 2 - 40;
390 affected_end = (pri_freq + sec_freq) / 2 + 40;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700391 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
392 affected_start, affected_end);
393
394 mode = iface->current_mode;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700395 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700396 if (params->freqs == NULL)
397 return;
398 pos = 0;
399
400 for (i = 0; i < mode->num_channels; i++) {
401 struct hostapd_channel_data *chan = &mode->channels[i];
402 if (chan->flag & HOSTAPD_CHAN_DISABLED)
403 continue;
404 if (chan->freq < affected_start ||
405 chan->freq > affected_end)
406 continue;
407 params->freqs[pos++] = chan->freq;
408 }
409}
410
411
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800412static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
413 struct wpa_driver_scan_params *params)
414{
415 /* Scan only the affected frequency range */
416 int pri_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 Shmidtcce06662013-11-04 18:44:24 -0800425 if (iface->conf->secondary_channel > 0) {
426 affected_start = pri_freq - 10;
427 affected_end = pri_freq + 30;
428 } else {
429 affected_start = pri_freq - 30;
430 affected_end = pri_freq + 10;
431 }
432 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
433 affected_start, affected_end);
434
435 mode = iface->current_mode;
436 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
437 if (params->freqs == NULL)
438 return;
439 pos = 0;
440
441 for (i = 0; i < mode->num_channels; i++) {
442 struct hostapd_channel_data *chan = &mode->channels[i];
443 if (chan->flag & HOSTAPD_CHAN_DISABLED)
444 continue;
445 if (chan->freq < affected_start ||
446 chan->freq > affected_end)
447 continue;
448 params->freqs[pos++] = chan->freq;
449 }
450}
451
452
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700453static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
454{
455#define HT2040_COEX_SCAN_RETRY 15
456 struct hostapd_iface *iface = eloop_data;
457 struct wpa_driver_scan_params params;
458 int ret;
459
460 os_memset(&params, 0, sizeof(params));
461 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
462 ieee80211n_scan_channels_2g4(iface, &params);
463 else
464 ieee80211n_scan_channels_5g(iface, &params);
465
466 ret = hostapd_driver_scan(iface->bss[0], &params);
467 iface->num_ht40_scan_tries++;
468 os_free(params.freqs);
469
470 if (ret == -EBUSY &&
471 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
472 wpa_printf(MSG_ERROR,
473 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
474 ret, strerror(-ret), iface->num_ht40_scan_tries);
475 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
476 return;
477 }
478
479 if (ret == 0) {
480 iface->scan_cb = ieee80211n_check_scan;
481 return;
482 }
483
484 wpa_printf(MSG_DEBUG,
485 "Failed to request a scan in device, bringing up in HT20 mode");
486 iface->conf->secondary_channel = 0;
487 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
488 hostapd_setup_interface_complete(iface, 0);
489}
490
491
492void hostapd_stop_setup_timers(struct hostapd_iface *iface)
493{
494 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
495}
496
497
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
499{
500 struct wpa_driver_scan_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700501 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800503 /* Check that HT40 is used and PRI / SEC switch is allowed */
504 if (!iface->conf->secondary_channel || iface->conf->no_pri_sec_switch)
505 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800507 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
509 "40 MHz channel");
510 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700511 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
512 ieee80211n_scan_channels_2g4(iface, &params);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800513 else
514 ieee80211n_scan_channels_5g(iface, &params);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700515
516 ret = hostapd_driver_scan(iface->bss[0], &params);
517 os_free(params.freqs);
518
519 if (ret == -EBUSY) {
520 wpa_printf(MSG_ERROR,
521 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
522 ret, strerror(-ret));
523 iface->num_ht40_scan_tries = 1;
524 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
525 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
526 return 1;
527 }
528
529 if (ret < 0) {
530 wpa_printf(MSG_ERROR,
531 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
532 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533 return -1;
534 }
535
536 iface->scan_cb = ieee80211n_check_scan;
537 return 1;
538}
539
540
541static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
542{
543 u16 hw = iface->current_mode->ht_capab;
544 u16 conf = iface->conf->ht_capab;
545
546 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
547 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
548 wpa_printf(MSG_ERROR, "Driver does not support configured "
549 "HT capability [LDPC]");
550 return 0;
551 }
552
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700553 /*
554 * Driver ACS chosen channel may not be HT40 due to internal driver
555 * restrictions.
556 */
557 if (!iface->conf->acs && (conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
559 wpa_printf(MSG_ERROR, "Driver does not support configured "
560 "HT capability [HT40*]");
561 return 0;
562 }
563
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800564 switch (conf & HT_CAP_INFO_SMPS_MASK) {
565 case HT_CAP_INFO_SMPS_STATIC:
566 if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_STATIC)) {
567 wpa_printf(MSG_ERROR,
568 "Driver does not support configured HT capability [SMPS-STATIC]");
569 return 0;
570 }
571 break;
572 case HT_CAP_INFO_SMPS_DYNAMIC:
573 if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_DYNAMIC)) {
574 wpa_printf(MSG_ERROR,
575 "Driver does not support configured HT capability [SMPS-DYNAMIC]");
576 return 0;
577 }
578 break;
579 case HT_CAP_INFO_SMPS_DISABLED:
580 default:
581 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582 }
583
584 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
585 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
586 wpa_printf(MSG_ERROR, "Driver does not support configured "
587 "HT capability [GF]");
588 return 0;
589 }
590
591 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
592 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
593 wpa_printf(MSG_ERROR, "Driver does not support configured "
594 "HT capability [SHORT-GI-20]");
595 return 0;
596 }
597
598 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
599 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
600 wpa_printf(MSG_ERROR, "Driver does not support configured "
601 "HT capability [SHORT-GI-40]");
602 return 0;
603 }
604
605 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
606 wpa_printf(MSG_ERROR, "Driver does not support configured "
607 "HT capability [TX-STBC]");
608 return 0;
609 }
610
611 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
612 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
613 wpa_printf(MSG_ERROR, "Driver does not support configured "
614 "HT capability [RX-STBC*]");
615 return 0;
616 }
617
618 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
619 !(hw & HT_CAP_INFO_DELAYED_BA)) {
620 wpa_printf(MSG_ERROR, "Driver does not support configured "
621 "HT capability [DELAYED-BA]");
622 return 0;
623 }
624
625 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
626 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
627 wpa_printf(MSG_ERROR, "Driver does not support configured "
628 "HT capability [MAX-AMSDU-7935]");
629 return 0;
630 }
631
632 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
633 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
634 wpa_printf(MSG_ERROR, "Driver does not support configured "
635 "HT capability [DSSS_CCK-40]");
636 return 0;
637 }
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
640 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
641 wpa_printf(MSG_ERROR, "Driver does not support configured "
642 "HT capability [LSIG-TXOP-PROT]");
643 return 0;
644 }
645
646 return 1;
647}
648
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700649
650#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700651static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
652{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800653 struct hostapd_hw_modes *mode = iface->current_mode;
654 u32 hw = mode->vht_capab;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700655 u32 conf = iface->conf->vht_capab;
656
657 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
658 hw, conf);
659
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800660 if (mode->mode == HOSTAPD_MODE_IEEE80211G &&
661 iface->conf->bss[0]->vendor_vht &&
662 mode->vht_capab == 0 && iface->hw_features) {
663 int i;
664
665 for (i = 0; i < iface->num_hw_features; i++) {
666 if (iface->hw_features[i].mode ==
667 HOSTAPD_MODE_IEEE80211A) {
668 mode = &iface->hw_features[i];
669 hw = mode->vht_capab;
670 wpa_printf(MSG_DEBUG,
671 "update hw vht capab based on 5 GHz band: 0x%x",
672 hw);
673 break;
674 }
675 }
676 }
677
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800678 return ieee80211ac_cap_check(hw, conf);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700679}
680#endif /* CONFIG_IEEE80211AC */
681
Hai Shalom81f62d82019-07-22 12:10:00 -0700682
683#ifdef CONFIG_IEEE80211AX
684static int ieee80211ax_supported_he_capab(struct hostapd_iface *iface)
685{
686 return 1;
687}
688#endif /* CONFIG_IEEE80211AX */
689
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690#endif /* CONFIG_IEEE80211N */
691
692
693int hostapd_check_ht_capab(struct hostapd_iface *iface)
694{
695#ifdef CONFIG_IEEE80211N
696 int ret;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800697
698 if (is_6ghz_freq(iface->freq))
699 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 if (!iface->conf->ieee80211n)
701 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800702
703 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211B &&
704 iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G &&
705 (iface->conf->ht_capab & HT_CAP_INFO_DSSS_CCK40MHZ)) {
706 wpa_printf(MSG_DEBUG,
707 "Disable HT capability [DSSS_CCK-40] on 5 GHz band");
708 iface->conf->ht_capab &= ~HT_CAP_INFO_DSSS_CCK40MHZ;
709 }
710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 if (!ieee80211n_supported_ht_capab(iface))
712 return -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700713#ifdef CONFIG_IEEE80211AX
714 if (iface->conf->ieee80211ax &&
715 !ieee80211ax_supported_he_capab(iface))
716 return -1;
717#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700718#ifdef CONFIG_IEEE80211AC
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800719 if (iface->conf->ieee80211ac &&
720 !ieee80211ac_supported_vht_capab(iface))
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700721 return -1;
722#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 ret = ieee80211n_check_40mhz(iface);
724 if (ret)
725 return ret;
726 if (!ieee80211n_allowed_ht40_channel_pair(iface))
727 return -1;
728#endif /* CONFIG_IEEE80211N */
729
730 return 0;
731}
732
733
Hai Shalomc3565922019-10-28 11:58:20 -0700734int hostapd_check_edmg_capab(struct hostapd_iface *iface)
735{
736 struct hostapd_hw_modes *mode = iface->hw_features;
737 struct ieee80211_edmg_config edmg;
738
739 if (!iface->conf->enable_edmg)
740 return 0;
741
742 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
743 iface->conf->edmg_channel,
744 iface->conf->channel,
745 &edmg);
746
747 if (mode->edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg))
748 return 0;
749
750 wpa_printf(MSG_WARNING, "Requested EDMG configuration is not valid");
751 wpa_printf(MSG_INFO, "EDMG capab: channels 0x%x, bw_config %d",
752 mode->edmg.channels, mode->edmg.bw_config);
753 wpa_printf(MSG_INFO,
754 "Requested EDMG configuration: channels 0x%x, bw_config %d",
755 edmg.channels, edmg.bw_config);
756 return -1;
757}
758
759
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700760static int hostapd_is_usable_chan(struct hostapd_iface *iface,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800761 int frequency, int primary)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700762{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700763 struct hostapd_channel_data *chan;
764
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700765 if (!iface->current_mode)
766 return 0;
767
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800768 chan = hw_get_channel_freq(iface->current_mode->mode, frequency, NULL,
769 iface->hw_features, iface->num_hw_features);
Hai Shalom74f70d42019-02-11 14:42:39 -0800770 if (!chan)
771 return 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700772
Hai Shalom74f70d42019-02-11 14:42:39 -0800773 if ((primary && chan_pri_allowed(chan)) ||
774 (!primary && !(chan->flag & HOSTAPD_CHAN_DISABLED)))
775 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700776
Hai Shalom74f70d42019-02-11 14:42:39 -0800777 wpa_printf(MSG_INFO,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800778 "Frequency %d (%s) not allowed for AP mode, flags: 0x%x%s%s",
779 frequency, primary ? "primary" : "secondary",
Hai Shalom74f70d42019-02-11 14:42:39 -0800780 chan->flag,
781 chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
782 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700783 return 0;
784}
785
786
Hai Shalomc3565922019-10-28 11:58:20 -0700787static int hostapd_is_usable_edmg(struct hostapd_iface *iface)
788{
789 int i, contiguous = 0;
790 int num_of_enabled = 0;
791 int max_contiguous = 0;
792 struct ieee80211_edmg_config edmg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800793 struct hostapd_channel_data *pri_chan;
Hai Shalomc3565922019-10-28 11:58:20 -0700794
795 if (!iface->conf->enable_edmg)
796 return 1;
797
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800798 if (!iface->current_mode)
799 return 0;
800 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
801 iface->freq, NULL,
802 iface->hw_features,
803 iface->num_hw_features);
Hai Shalomc3565922019-10-28 11:58:20 -0700804 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
805 iface->conf->edmg_channel,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800806 pri_chan->chan,
Hai Shalomc3565922019-10-28 11:58:20 -0700807 &edmg);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800808 if (!(edmg.channels & BIT(pri_chan->chan - 1)))
Hai Shalomc3565922019-10-28 11:58:20 -0700809 return 0;
810
811 /* 60 GHz channels 1..6 */
812 for (i = 0; i < 6; i++) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800813 int freq = 56160 + 2160 * i;
814
Hai Shalomc3565922019-10-28 11:58:20 -0700815 if (edmg.channels & BIT(i)) {
816 contiguous++;
817 num_of_enabled++;
818 } else {
819 contiguous = 0;
820 continue;
821 }
822
823 /* P802.11ay defines that the total number of subfields
824 * set to one does not exceed 4.
825 */
826 if (num_of_enabled > 4)
827 return 0;
828
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800829 if (!hostapd_is_usable_chan(iface, freq, 1))
Hai Shalomc3565922019-10-28 11:58:20 -0700830 return 0;
831
832 if (contiguous > max_contiguous)
833 max_contiguous = contiguous;
834 }
835
836 /* Check if the EDMG configuration is valid under the limitations
837 * of P802.11ay.
838 */
839 /* check bw_config against contiguous EDMG channels */
840 switch (edmg.bw_config) {
841 case EDMG_BW_CONFIG_4:
842 if (!max_contiguous)
843 return 0;
844 break;
845 case EDMG_BW_CONFIG_5:
846 if (max_contiguous < 2)
847 return 0;
848 break;
849 default:
850 return 0;
851 }
852
853 return 1;
854}
855
856
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700857static int hostapd_is_usable_chans(struct hostapd_iface *iface)
858{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800859 int secondary_freq;
Hai Shalom74f70d42019-02-11 14:42:39 -0800860 struct hostapd_channel_data *pri_chan;
861
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800862 if (!iface->current_mode)
Hai Shalom74f70d42019-02-11 14:42:39 -0800863 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800864 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
865 iface->freq, NULL,
866 iface->hw_features,
867 iface->num_hw_features);
868 if (!pri_chan) {
869 wpa_printf(MSG_ERROR, "Primary frequency not present");
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700870 return 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800871 }
872 if (!hostapd_is_usable_chan(iface, pri_chan->freq, 1)) {
873 wpa_printf(MSG_ERROR, "Primary frequency not allowed");
874 return 0;
875 }
Hai Shalomc3565922019-10-28 11:58:20 -0700876 if (!hostapd_is_usable_edmg(iface))
877 return 0;
878
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700879 if (!iface->conf->secondary_channel)
880 return 1;
881
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700882 if (!iface->conf->ht40_plus_minus_allowed)
883 return hostapd_is_usable_chan(
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800884 iface,
885 iface->freq + iface->conf->secondary_channel * 20, 0);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700886
887 /* Both HT40+ and HT40- are set, pick a valid secondary channel */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800888 secondary_freq = iface->freq + 20;
889 if (hostapd_is_usable_chan(iface, secondary_freq, 0) &&
Hai Shalom74f70d42019-02-11 14:42:39 -0800890 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700891 iface->conf->secondary_channel = 1;
892 return 1;
893 }
894
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800895 secondary_freq = iface->freq - 20;
896 if (hostapd_is_usable_chan(iface, secondary_freq, 0) &&
Hai Shalom74f70d42019-02-11 14:42:39 -0800897 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700898 iface->conf->secondary_channel = -1;
899 return 1;
900 }
901
902 return 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700903}
904
905
906static enum hostapd_chan_status
907hostapd_check_chans(struct hostapd_iface *iface)
908{
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800909 if (iface->freq) {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700910 if (hostapd_is_usable_chans(iface))
911 return HOSTAPD_CHAN_VALID;
912 else
913 return HOSTAPD_CHAN_INVALID;
914 }
915
916 /*
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700917 * The user set channel=0 or channel=acs_survey
918 * which is used to trigger ACS.
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700919 */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700920
921 switch (acs_init(iface)) {
922 case HOSTAPD_CHAN_ACS:
923 return HOSTAPD_CHAN_ACS;
924 case HOSTAPD_CHAN_VALID:
925 case HOSTAPD_CHAN_INVALID:
926 default:
927 return HOSTAPD_CHAN_INVALID;
928 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700929}
930
931
932static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
933{
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700934 if (!iface->current_mode) {
935 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
936 HOSTAPD_LEVEL_WARNING,
937 "Hardware does not support configured mode");
938 return;
939 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700940 hostapd_logger(iface->bss[0], NULL,
941 HOSTAPD_MODULE_IEEE80211,
942 HOSTAPD_LEVEL_WARNING,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800943 "Configured channel (%d) or frequency (%d) not found from the channel list of the current mode (%d) %s",
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700944 iface->conf->channel,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800945 iface->freq,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700946 iface->current_mode->mode,
947 hostapd_hw_mode_txt(iface->current_mode->mode));
948 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
949 HOSTAPD_LEVEL_WARNING,
950 "Hardware does not support configured channel");
951}
952
953
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700954int hostapd_acs_completed(struct hostapd_iface *iface, int err)
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700955{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700956 int ret = -1;
957
958 if (err)
959 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700960
961 switch (hostapd_check_chans(iface)) {
962 case HOSTAPD_CHAN_VALID:
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800963 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
964 ACS_EVENT_COMPLETED "freq=%d channel=%d",
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800965 iface->freq, iface->conf->channel);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700966 break;
967 case HOSTAPD_CHAN_ACS:
968 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800969 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700970 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700971 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700972 case HOSTAPD_CHAN_INVALID:
973 default:
974 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800975 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700976 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700977 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700978 }
979
980 ret = hostapd_check_ht_capab(iface);
981 if (ret < 0)
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700982 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700983 if (ret == 1) {
984 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
985 return 0;
986 }
987
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700988 ret = 0;
989out:
990 return hostapd_setup_interface_complete(iface, ret);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700991}
992
993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994/**
995 * hostapd_select_hw_mode - Select the hardware mode
996 * @iface: Pointer to interface data.
Jouni Malinen87fd2792011-05-16 18:35:42 +0300997 * Returns: 0 on success, < 0 on failure
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998 *
999 * Sets up the hardware mode, channel, rates, and passive scanning
1000 * based on the configuration.
1001 */
1002int hostapd_select_hw_mode(struct hostapd_iface *iface)
1003{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001004 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005
1006 if (iface->num_hw_features < 1)
1007 return -1;
1008
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001009 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
Hai Shalom81f62d82019-07-22 12:10:00 -07001010 iface->conf->ieee80211n || iface->conf->ieee80211ac ||
1011 iface->conf->ieee80211ax) &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001012 iface->conf->channel == 14) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001013 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT/HE on channel 14");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001014 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1015 iface->conf->ieee80211n = 0;
1016 iface->conf->ieee80211ac = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -07001017 iface->conf->ieee80211ax = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001018 }
1019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020 iface->current_mode = NULL;
1021 for (i = 0; i < iface->num_hw_features; i++) {
1022 struct hostapd_hw_modes *mode = &iface->hw_features[i];
1023 if (mode->mode == iface->conf->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001024 if (iface->freq > 0 &&
1025 !hw_get_chan(mode->mode, iface->freq,
1026 iface->hw_features,
1027 iface->num_hw_features))
Hai Shalomc3565922019-10-28 11:58:20 -07001028 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029 iface->current_mode = mode;
1030 break;
1031 }
1032 }
1033
1034 if (iface->current_mode == NULL) {
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001035 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) ||
1036 !(iface->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY))
1037 {
1038 wpa_printf(MSG_ERROR,
1039 "Hardware does not support configured mode");
1040 hostapd_logger(iface->bss[0], NULL,
1041 HOSTAPD_MODULE_IEEE80211,
1042 HOSTAPD_LEVEL_WARNING,
1043 "Hardware does not support configured mode (%d) (hw_mode in hostapd.conf)",
1044 (int) iface->conf->hw_mode);
1045 return -2;
1046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 }
1048
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001049 switch (hostapd_check_chans(iface)) {
1050 case HOSTAPD_CHAN_VALID:
1051 return 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001052 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1053 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001054 case HOSTAPD_CHAN_INVALID:
1055 default:
1056 hostapd_notify_bad_chans(iface);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001057 return -3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059}
1060
1061
1062const char * hostapd_hw_mode_txt(int mode)
1063{
1064 switch (mode) {
1065 case HOSTAPD_MODE_IEEE80211A:
1066 return "IEEE 802.11a";
1067 case HOSTAPD_MODE_IEEE80211B:
1068 return "IEEE 802.11b";
1069 case HOSTAPD_MODE_IEEE80211G:
1070 return "IEEE 802.11g";
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001071 case HOSTAPD_MODE_IEEE80211AD:
1072 return "IEEE 802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 default:
1074 return "UNKNOWN";
1075 }
1076}
1077
1078
1079int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1080{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001081 return hw_get_freq(hapd->iface->current_mode, chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082}
1083
1084
1085int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1086{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001087 int i, channel;
1088 struct hostapd_hw_modes *mode;
1089
Hai Shalom1dc4d202019-04-29 16:22:27 -07001090 if (hapd->iface->current_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001091 channel = hw_get_chan(hapd->iface->current_mode->mode, freq,
1092 hapd->iface->hw_features,
1093 hapd->iface->num_hw_features);
Hai Shalom1dc4d202019-04-29 16:22:27 -07001094 if (channel)
1095 return channel;
1096 }
1097
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001098 /* Check other available modes since the channel list for the current
1099 * mode did not include the specified frequency. */
Hai Shalom1dc4d202019-04-29 16:22:27 -07001100 if (!hapd->iface->hw_features)
1101 return 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001102 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1103 mode = &hapd->iface->hw_features[i];
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001104 channel = hw_get_chan(mode->mode, freq,
1105 hapd->iface->hw_features,
1106 hapd->iface->num_hw_features);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001107 if (channel)
1108 return channel;
1109 }
1110 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111}