blob: 360706684f8414740864f520c199c06fda28398d [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;
81
82 if (hostapd_drv_none(hapd))
83 return -1;
84 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
85 if (modes == NULL) {
86 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
87 HOSTAPD_LEVEL_DEBUG,
88 "Fetching hardware channel/rate support not "
89 "supported.");
90 return -1;
91 }
92
93 iface->hw_flags = flags;
94
95 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
96 iface->hw_features = modes;
97 iface->num_hw_features = num_modes;
98
99 for (i = 0; i < num_modes; i++) {
100 struct hostapd_hw_modes *feature = &modes[i];
Dmitry Shmidt051af732013-10-22 13:52:46 -0700101 int dfs_enabled = hapd->iconf->ieee80211h &&
102 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 /* set flag for channels we can use in current regulatory
105 * domain */
106 for (j = 0; j < feature->num_channels; j++) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700107 int dfs = 0;
108
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 /*
110 * Disable all channels that are marked not to allow
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800111 * to initiate radiation (a.k.a. passive scan and no
112 * IBSS).
Dmitry Shmidt051af732013-10-22 13:52:46 -0700113 * Use radar channels only if the driver supports DFS.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 */
Dmitry Shmidt051af732013-10-22 13:52:46 -0700115 if ((feature->channels[j].flag &
116 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
117 dfs = 1;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700118 } else if (((feature->channels[j].flag &
119 HOSTAPD_CHAN_RADAR) &&
120 !(iface->drv_flags &
121 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
122 (feature->channels[j].flag &
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800123 HOSTAPD_CHAN_NO_IR)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700124 feature->channels[j].flag |=
125 HOSTAPD_CHAN_DISABLED;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700126 }
127
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
129 continue;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
Dmitry Shmidt051af732013-10-22 13:52:46 -0700132 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133 feature->mode,
134 feature->channels[j].chan,
135 feature->channels[j].freq,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700136 feature->channels[j].max_tx_power,
137 dfs ? dfs_info(&feature->channels[j]) : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138 }
139 }
140
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800141 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142}
143
144
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800145int hostapd_prepare_rates(struct hostapd_iface *iface,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146 struct hostapd_hw_modes *mode)
147{
148 int i, num_basic_rates = 0;
149 int basic_rates_a[] = { 60, 120, 240, -1 };
150 int basic_rates_b[] = { 10, 20, -1 };
151 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
152 int *basic_rates;
153
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800154 if (iface->conf->basic_rates)
155 basic_rates = iface->conf->basic_rates;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156 else switch (mode->mode) {
157 case HOSTAPD_MODE_IEEE80211A:
158 basic_rates = basic_rates_a;
159 break;
160 case HOSTAPD_MODE_IEEE80211B:
161 basic_rates = basic_rates_b;
162 break;
163 case HOSTAPD_MODE_IEEE80211G:
164 basic_rates = basic_rates_g;
165 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800166 case HOSTAPD_MODE_IEEE80211AD:
167 return 0; /* No basic rates for 11ad */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168 default:
169 return -1;
170 }
171
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800172 i = 0;
173 while (basic_rates[i] >= 0)
174 i++;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700175 if (i)
176 i++; /* -1 termination */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177 os_free(iface->basic_rates);
178 iface->basic_rates = os_malloc(i * sizeof(int));
179 if (iface->basic_rates)
180 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800182 os_free(iface->current_rates);
183 iface->num_rates = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800185 iface->current_rates =
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700186 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800187 if (!iface->current_rates) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
189 "table.");
190 return -1;
191 }
192
193 for (i = 0; i < mode->num_rates; i++) {
194 struct hostapd_rate_data *rate;
195
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800196 if (iface->conf->supported_rates &&
197 !hostapd_rate_found(iface->conf->supported_rates,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 mode->rates[i]))
199 continue;
200
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800201 rate = &iface->current_rates[iface->num_rates];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 rate->rate = mode->rates[i];
203 if (hostapd_rate_found(basic_rates, rate->rate)) {
204 rate->flags |= HOSTAPD_RATE_BASIC;
205 num_basic_rates++;
206 }
207 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800208 iface->num_rates, rate->rate, rate->flags);
209 iface->num_rates++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700210 }
211
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800212 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
213 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
215 "rate sets (%d,%d).",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800216 iface->num_rates, num_basic_rates);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 return -1;
218 }
219
220 return 0;
221}
222
223
224#ifdef CONFIG_IEEE80211N
225static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
226{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800227 int pri_chan, sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228
229 if (!iface->conf->secondary_channel)
230 return 1; /* HT40 not used */
231
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800232 pri_chan = iface->conf->channel;
233 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800235 return allowed_ht40_channel_pair(iface->current_mode, pri_chan,
236 sec_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237}
238
239
240static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
241{
242 if (iface->conf->secondary_channel > 0) {
243 iface->conf->channel += 4;
244 iface->conf->secondary_channel = -1;
245 } else {
246 iface->conf->channel -= 4;
247 iface->conf->secondary_channel = 1;
248 }
249}
250
251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
253 struct wpa_scan_results *scan_res)
254{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800255 int pri_chan, sec_chan;
256 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257
258 pri_chan = iface->conf->channel;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700259 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800261 res = check_40mhz_5g(iface->current_mode, scan_res, pri_chan, sec_chan);
262
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800263 if (res == 2) {
264 if (iface->conf->no_pri_sec_switch) {
265 wpa_printf(MSG_DEBUG,
266 "Cannot switch PRI/SEC channels due to local constraint");
267 } else {
268 ieee80211n_switch_pri_sec(iface);
269 }
270 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800272 return !!res;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -0700273}
274
275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
277 struct wpa_scan_results *scan_res)
278{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800279 int pri_chan, sec_chan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800281 pri_chan = iface->conf->channel;
282 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800284 return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
285 sec_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286}
287
288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289static void ieee80211n_check_scan(struct hostapd_iface *iface)
290{
291 struct wpa_scan_results *scan_res;
292 int oper40;
293 int res;
294
295 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
Dmitry Shmidt04949592012-07-19 12:16:46 -0700296 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297
298 iface->scan_cb = NULL;
299
300 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
301 if (scan_res == NULL) {
302 hostapd_setup_interface_complete(iface, 1);
303 return;
304 }
305
306 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
307 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
308 else
309 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
310 wpa_scan_results_free(scan_res);
311
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700312 iface->secondary_ch = iface->conf->secondary_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 if (!oper40) {
314 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
315 "channel pri=%d sec=%d based on overlapping BSSes",
316 iface->conf->channel,
317 iface->conf->channel +
318 iface->conf->secondary_channel * 4);
319 iface->conf->secondary_channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700320 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
321 /*
322 * TODO: Could consider scheduling another scan to check
323 * if channel width can be changed if no coex reports
324 * are received from associating stations.
325 */
326 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 }
328
329 res = ieee80211n_allowed_ht40_channel_pair(iface);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700330 if (!res) {
331 iface->conf->secondary_channel = 0;
332 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
333 }
334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 hostapd_setup_interface_complete(iface, !res);
336}
337
338
Dmitry Shmidt04949592012-07-19 12:16:46 -0700339static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
340 struct wpa_driver_scan_params *params)
341{
342 /* Scan only the affected frequency range */
343 int pri_freq, sec_freq;
344 int affected_start, affected_end;
345 int i, pos;
346 struct hostapd_hw_modes *mode;
347
348 if (iface->current_mode == NULL)
349 return;
350
351 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
352 if (iface->conf->secondary_channel > 0)
353 sec_freq = pri_freq + 20;
354 else
355 sec_freq = pri_freq - 20;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700356 /*
357 * Note: Need to find the PRI channel also in cases where the affected
358 * channel is the SEC channel of a 40 MHz BSS, so need to include the
359 * scanning coverage here to be 40 MHz from the center frequency.
360 */
361 affected_start = (pri_freq + sec_freq) / 2 - 40;
362 affected_end = (pri_freq + sec_freq) / 2 + 40;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700363 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
364 affected_start, affected_end);
365
366 mode = iface->current_mode;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700367 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700368 if (params->freqs == NULL)
369 return;
370 pos = 0;
371
372 for (i = 0; i < mode->num_channels; i++) {
373 struct hostapd_channel_data *chan = &mode->channels[i];
374 if (chan->flag & HOSTAPD_CHAN_DISABLED)
375 continue;
376 if (chan->freq < affected_start ||
377 chan->freq > affected_end)
378 continue;
379 params->freqs[pos++] = chan->freq;
380 }
381}
382
383
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800384static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
385 struct wpa_driver_scan_params *params)
386{
387 /* Scan only the affected frequency range */
388 int pri_freq;
389 int affected_start, affected_end;
390 int i, pos;
391 struct hostapd_hw_modes *mode;
392
393 if (iface->current_mode == NULL)
394 return;
395
396 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
397 if (iface->conf->secondary_channel > 0) {
398 affected_start = pri_freq - 10;
399 affected_end = pri_freq + 30;
400 } else {
401 affected_start = pri_freq - 30;
402 affected_end = pri_freq + 10;
403 }
404 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
405 affected_start, affected_end);
406
407 mode = iface->current_mode;
408 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
409 if (params->freqs == NULL)
410 return;
411 pos = 0;
412
413 for (i = 0; i < mode->num_channels; i++) {
414 struct hostapd_channel_data *chan = &mode->channels[i];
415 if (chan->flag & HOSTAPD_CHAN_DISABLED)
416 continue;
417 if (chan->freq < affected_start ||
418 chan->freq > affected_end)
419 continue;
420 params->freqs[pos++] = chan->freq;
421 }
422}
423
424
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700425static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
426{
427#define HT2040_COEX_SCAN_RETRY 15
428 struct hostapd_iface *iface = eloop_data;
429 struct wpa_driver_scan_params params;
430 int ret;
431
432 os_memset(&params, 0, sizeof(params));
433 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
434 ieee80211n_scan_channels_2g4(iface, &params);
435 else
436 ieee80211n_scan_channels_5g(iface, &params);
437
438 ret = hostapd_driver_scan(iface->bss[0], &params);
439 iface->num_ht40_scan_tries++;
440 os_free(params.freqs);
441
442 if (ret == -EBUSY &&
443 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
444 wpa_printf(MSG_ERROR,
445 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
446 ret, strerror(-ret), iface->num_ht40_scan_tries);
447 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
448 return;
449 }
450
451 if (ret == 0) {
452 iface->scan_cb = ieee80211n_check_scan;
453 return;
454 }
455
456 wpa_printf(MSG_DEBUG,
457 "Failed to request a scan in device, bringing up in HT20 mode");
458 iface->conf->secondary_channel = 0;
459 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
460 hostapd_setup_interface_complete(iface, 0);
461}
462
463
464void hostapd_stop_setup_timers(struct hostapd_iface *iface)
465{
466 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
467}
468
469
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
471{
472 struct wpa_driver_scan_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700473 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800475 /* Check that HT40 is used and PRI / SEC switch is allowed */
476 if (!iface->conf->secondary_channel || iface->conf->no_pri_sec_switch)
477 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800479 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
481 "40 MHz channel");
482 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700483 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
484 ieee80211n_scan_channels_2g4(iface, &params);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800485 else
486 ieee80211n_scan_channels_5g(iface, &params);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700487
488 ret = hostapd_driver_scan(iface->bss[0], &params);
489 os_free(params.freqs);
490
491 if (ret == -EBUSY) {
492 wpa_printf(MSG_ERROR,
493 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
494 ret, strerror(-ret));
495 iface->num_ht40_scan_tries = 1;
496 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
497 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
498 return 1;
499 }
500
501 if (ret < 0) {
502 wpa_printf(MSG_ERROR,
503 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
504 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505 return -1;
506 }
507
508 iface->scan_cb = ieee80211n_check_scan;
509 return 1;
510}
511
512
513static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
514{
515 u16 hw = iface->current_mode->ht_capab;
516 u16 conf = iface->conf->ht_capab;
517
518 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
519 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
520 wpa_printf(MSG_ERROR, "Driver does not support configured "
521 "HT capability [LDPC]");
522 return 0;
523 }
524
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700525 /*
526 * Driver ACS chosen channel may not be HT40 due to internal driver
527 * restrictions.
528 */
529 if (!iface->conf->acs && (conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
531 wpa_printf(MSG_ERROR, "Driver does not support configured "
532 "HT capability [HT40*]");
533 return 0;
534 }
535
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800536 switch (conf & HT_CAP_INFO_SMPS_MASK) {
537 case HT_CAP_INFO_SMPS_STATIC:
538 if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_STATIC)) {
539 wpa_printf(MSG_ERROR,
540 "Driver does not support configured HT capability [SMPS-STATIC]");
541 return 0;
542 }
543 break;
544 case HT_CAP_INFO_SMPS_DYNAMIC:
545 if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_DYNAMIC)) {
546 wpa_printf(MSG_ERROR,
547 "Driver does not support configured HT capability [SMPS-DYNAMIC]");
548 return 0;
549 }
550 break;
551 case HT_CAP_INFO_SMPS_DISABLED:
552 default:
553 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 }
555
556 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
557 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
558 wpa_printf(MSG_ERROR, "Driver does not support configured "
559 "HT capability [GF]");
560 return 0;
561 }
562
563 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
564 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
565 wpa_printf(MSG_ERROR, "Driver does not support configured "
566 "HT capability [SHORT-GI-20]");
567 return 0;
568 }
569
570 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
571 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
572 wpa_printf(MSG_ERROR, "Driver does not support configured "
573 "HT capability [SHORT-GI-40]");
574 return 0;
575 }
576
577 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
578 wpa_printf(MSG_ERROR, "Driver does not support configured "
579 "HT capability [TX-STBC]");
580 return 0;
581 }
582
583 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
584 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
585 wpa_printf(MSG_ERROR, "Driver does not support configured "
586 "HT capability [RX-STBC*]");
587 return 0;
588 }
589
590 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
591 !(hw & HT_CAP_INFO_DELAYED_BA)) {
592 wpa_printf(MSG_ERROR, "Driver does not support configured "
593 "HT capability [DELAYED-BA]");
594 return 0;
595 }
596
597 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
598 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
599 wpa_printf(MSG_ERROR, "Driver does not support configured "
600 "HT capability [MAX-AMSDU-7935]");
601 return 0;
602 }
603
604 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
605 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
606 wpa_printf(MSG_ERROR, "Driver does not support configured "
607 "HT capability [DSSS_CCK-40]");
608 return 0;
609 }
610
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
612 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
613 wpa_printf(MSG_ERROR, "Driver does not support configured "
614 "HT capability [LSIG-TXOP-PROT]");
615 return 0;
616 }
617
618 return 1;
619}
620
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700621
622#ifdef CONFIG_IEEE80211AC
623
624static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
625{
626 u32 req_cap = conf & cap;
627
628 /*
629 * Make sure we support all requested capabilities.
630 * NOTE: We assume that 'cap' represents a capability mask,
631 * not a discrete value.
632 */
633 if ((hw & req_cap) != req_cap) {
634 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
635 name);
636 return 0;
637 }
638 return 1;
639}
640
641
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800642static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask,
643 unsigned int shift,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700644 const char *name)
645{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800646 u32 hw_max = hw & mask;
647 u32 conf_val = conf & mask;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700648
649 if (conf_val > hw_max) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700650 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800651 name, conf_val >> shift, hw_max >> shift);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700652 return 0;
653 }
654 return 1;
655}
656
657
658static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
659{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800660 struct hostapd_hw_modes *mode = iface->current_mode;
661 u32 hw = mode->vht_capab;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700662 u32 conf = iface->conf->vht_capab;
663
664 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
665 hw, conf);
666
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800667 if (mode->mode == HOSTAPD_MODE_IEEE80211G &&
668 iface->conf->bss[0]->vendor_vht &&
669 mode->vht_capab == 0 && iface->hw_features) {
670 int i;
671
672 for (i = 0; i < iface->num_hw_features; i++) {
673 if (iface->hw_features[i].mode ==
674 HOSTAPD_MODE_IEEE80211A) {
675 mode = &iface->hw_features[i];
676 hw = mode->vht_capab;
677 wpa_printf(MSG_DEBUG,
678 "update hw vht capab based on 5 GHz band: 0x%x",
679 hw);
680 break;
681 }
682 }
683 }
684
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700685#define VHT_CAP_CHECK(cap) \
686 do { \
687 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
688 return 0; \
689 } while (0)
690
691#define VHT_CAP_CHECK_MAX(cap) \
692 do { \
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800693 if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
694 #cap)) \
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700695 return 0; \
696 } while (0)
697
698 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
699 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
700 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
701 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
702 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
703 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
704 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
705 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
706 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
707 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
708 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
709 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
710 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
711 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
712 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
713 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800714 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700715 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
716 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
717 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
718 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
719
720#undef VHT_CAP_CHECK
721#undef VHT_CAP_CHECK_MAX
722
723 return 1;
724}
725#endif /* CONFIG_IEEE80211AC */
726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727#endif /* CONFIG_IEEE80211N */
728
729
730int hostapd_check_ht_capab(struct hostapd_iface *iface)
731{
732#ifdef CONFIG_IEEE80211N
733 int ret;
734 if (!iface->conf->ieee80211n)
735 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800736
737 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211B &&
738 iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G &&
739 (iface->conf->ht_capab & HT_CAP_INFO_DSSS_CCK40MHZ)) {
740 wpa_printf(MSG_DEBUG,
741 "Disable HT capability [DSSS_CCK-40] on 5 GHz band");
742 iface->conf->ht_capab &= ~HT_CAP_INFO_DSSS_CCK40MHZ;
743 }
744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 if (!ieee80211n_supported_ht_capab(iface))
746 return -1;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700747#ifdef CONFIG_IEEE80211AC
748 if (!ieee80211ac_supported_vht_capab(iface))
749 return -1;
750#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751 ret = ieee80211n_check_40mhz(iface);
752 if (ret)
753 return ret;
754 if (!ieee80211n_allowed_ht40_channel_pair(iface))
755 return -1;
756#endif /* CONFIG_IEEE80211N */
757
758 return 0;
759}
760
761
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700762static int hostapd_is_usable_chan(struct hostapd_iface *iface,
763 int channel, int primary)
764{
765 int i;
766 struct hostapd_channel_data *chan;
767
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700768 if (!iface->current_mode)
769 return 0;
770
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700771 for (i = 0; i < iface->current_mode->num_channels; i++) {
772 chan = &iface->current_mode->channels[i];
773 if (chan->chan != channel)
774 continue;
775
776 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
777 return 1;
778
779 wpa_printf(MSG_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800780 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s",
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700781 primary ? "" : "Configured HT40 secondary ",
782 i, chan->chan, chan->flag,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800783 chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700784 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
785 }
786
787 return 0;
788}
789
790
791static int hostapd_is_usable_chans(struct hostapd_iface *iface)
792{
793 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
794 return 0;
795
796 if (!iface->conf->secondary_channel)
797 return 1;
798
799 return hostapd_is_usable_chan(iface, iface->conf->channel +
800 iface->conf->secondary_channel * 4, 0);
801}
802
803
804static enum hostapd_chan_status
805hostapd_check_chans(struct hostapd_iface *iface)
806{
807 if (iface->conf->channel) {
808 if (hostapd_is_usable_chans(iface))
809 return HOSTAPD_CHAN_VALID;
810 else
811 return HOSTAPD_CHAN_INVALID;
812 }
813
814 /*
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700815 * The user set channel=0 or channel=acs_survey
816 * which is used to trigger ACS.
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700817 */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700818
819 switch (acs_init(iface)) {
820 case HOSTAPD_CHAN_ACS:
821 return HOSTAPD_CHAN_ACS;
822 case HOSTAPD_CHAN_VALID:
823 case HOSTAPD_CHAN_INVALID:
824 default:
825 return HOSTAPD_CHAN_INVALID;
826 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700827}
828
829
830static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
831{
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700832 if (!iface->current_mode) {
833 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
834 HOSTAPD_LEVEL_WARNING,
835 "Hardware does not support configured mode");
836 return;
837 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700838 hostapd_logger(iface->bss[0], NULL,
839 HOSTAPD_MODULE_IEEE80211,
840 HOSTAPD_LEVEL_WARNING,
841 "Configured channel (%d) not found from the "
842 "channel list of current mode (%d) %s",
843 iface->conf->channel,
844 iface->current_mode->mode,
845 hostapd_hw_mode_txt(iface->current_mode->mode));
846 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
847 HOSTAPD_LEVEL_WARNING,
848 "Hardware does not support configured channel");
849}
850
851
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700852int hostapd_acs_completed(struct hostapd_iface *iface, int err)
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700853{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700854 int ret = -1;
855
856 if (err)
857 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700858
859 switch (hostapd_check_chans(iface)) {
860 case HOSTAPD_CHAN_VALID:
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800861 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
862 ACS_EVENT_COMPLETED "freq=%d channel=%d",
863 hostapd_hw_get_freq(iface->bss[0],
864 iface->conf->channel),
865 iface->conf->channel);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700866 break;
867 case HOSTAPD_CHAN_ACS:
868 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800869 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700870 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700871 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700872 case HOSTAPD_CHAN_INVALID:
873 default:
874 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800875 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700876 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700877 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700878 }
879
880 ret = hostapd_check_ht_capab(iface);
881 if (ret < 0)
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700882 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700883 if (ret == 1) {
884 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
885 return 0;
886 }
887
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700888 ret = 0;
889out:
890 return hostapd_setup_interface_complete(iface, ret);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700891}
892
893
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894/**
895 * hostapd_select_hw_mode - Select the hardware mode
896 * @iface: Pointer to interface data.
Jouni Malinen87fd2792011-05-16 18:35:42 +0300897 * Returns: 0 on success, < 0 on failure
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 *
899 * Sets up the hardware mode, channel, rates, and passive scanning
900 * based on the configuration.
901 */
902int hostapd_select_hw_mode(struct hostapd_iface *iface)
903{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700904 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905
906 if (iface->num_hw_features < 1)
907 return -1;
908
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800909 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
910 iface->conf->ieee80211n || iface->conf->ieee80211ac) &&
911 iface->conf->channel == 14) {
912 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14");
913 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
914 iface->conf->ieee80211n = 0;
915 iface->conf->ieee80211ac = 0;
916 }
917
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 iface->current_mode = NULL;
919 for (i = 0; i < iface->num_hw_features; i++) {
920 struct hostapd_hw_modes *mode = &iface->hw_features[i];
921 if (mode->mode == iface->conf->hw_mode) {
922 iface->current_mode = mode;
923 break;
924 }
925 }
926
927 if (iface->current_mode == NULL) {
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700928 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) ||
929 !(iface->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY))
930 {
931 wpa_printf(MSG_ERROR,
932 "Hardware does not support configured mode");
933 hostapd_logger(iface->bss[0], NULL,
934 HOSTAPD_MODULE_IEEE80211,
935 HOSTAPD_LEVEL_WARNING,
936 "Hardware does not support configured mode (%d) (hw_mode in hostapd.conf)",
937 (int) iface->conf->hw_mode);
938 return -2;
939 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 }
941
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700942 switch (hostapd_check_chans(iface)) {
943 case HOSTAPD_CHAN_VALID:
944 return 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700945 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
946 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700947 case HOSTAPD_CHAN_INVALID:
948 default:
949 hostapd_notify_bad_chans(iface);
Jouni Malinen87fd2792011-05-16 18:35:42 +0300950 return -3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952}
953
954
955const char * hostapd_hw_mode_txt(int mode)
956{
957 switch (mode) {
958 case HOSTAPD_MODE_IEEE80211A:
959 return "IEEE 802.11a";
960 case HOSTAPD_MODE_IEEE80211B:
961 return "IEEE 802.11b";
962 case HOSTAPD_MODE_IEEE80211G:
963 return "IEEE 802.11g";
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800964 case HOSTAPD_MODE_IEEE80211AD:
965 return "IEEE 802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 default:
967 return "UNKNOWN";
968 }
969}
970
971
972int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
973{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800974 return hw_get_freq(hapd->iface->current_mode, chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975}
976
977
978int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
979{
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800980 return hw_get_chan(hapd->iface->current_mode, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981}