blob: b36183452ea50d3d67e169de2bf8f5c841901ef4 [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 Shmidt8d520ff2011-05-09 14:06:53 -070018#include "hostapd.h"
19#include "ap_config.h"
20#include "ap_drv_ops.h"
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070021#include "acs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070022#include "ieee802_11.h"
23#include "beacon.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070024#include "hw_features.h"
25
26
27void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
28 size_t num_hw_features)
29{
30 size_t i;
31
32 if (hw_features == NULL)
33 return;
34
35 for (i = 0; i < num_hw_features; i++) {
36 os_free(hw_features[i].channels);
37 os_free(hw_features[i].rates);
38 }
39
40 os_free(hw_features);
41}
42
43
Dmitry Shmidt051af732013-10-22 13:52:46 -070044#ifndef CONFIG_NO_STDOUT_DEBUG
45static char * dfs_info(struct hostapd_channel_data *chan)
46{
47 static char info[256];
48 char *state;
49
50 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
51 case HOSTAPD_CHAN_DFS_UNKNOWN:
52 state = "unknown";
53 break;
54 case HOSTAPD_CHAN_DFS_USABLE:
55 state = "usable";
56 break;
57 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
58 state = "unavailable";
59 break;
60 case HOSTAPD_CHAN_DFS_AVAILABLE:
61 state = "available";
62 break;
63 default:
64 return "";
65 }
66 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
67 info[sizeof(info) - 1] = '\0';
68
69 return info;
70}
71#endif /* CONFIG_NO_STDOUT_DEBUG */
72
73
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074int hostapd_get_hw_features(struct hostapd_iface *iface)
75{
76 struct hostapd_data *hapd = iface->bss[0];
77 int ret = 0, i, j;
78 u16 num_modes, flags;
79 struct hostapd_hw_modes *modes;
80
81 if (hostapd_drv_none(hapd))
82 return -1;
83 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
84 if (modes == NULL) {
85 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
86 HOSTAPD_LEVEL_DEBUG,
87 "Fetching hardware channel/rate support not "
88 "supported.");
89 return -1;
90 }
91
92 iface->hw_flags = flags;
93
94 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
95 iface->hw_features = modes;
96 iface->num_hw_features = num_modes;
97
98 for (i = 0; i < num_modes; i++) {
99 struct hostapd_hw_modes *feature = &modes[i];
Dmitry Shmidt051af732013-10-22 13:52:46 -0700100 int dfs_enabled = hapd->iconf->ieee80211h &&
101 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 /* set flag for channels we can use in current regulatory
104 * domain */
105 for (j = 0; j < feature->num_channels; j++) {
Dmitry Shmidt051af732013-10-22 13:52:46 -0700106 int dfs = 0;
107
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 /*
109 * Disable all channels that are marked not to allow
Dmitry Shmidt051af732013-10-22 13:52:46 -0700110 * IBSS operation or active scanning.
111 * Use radar channels only if the driver supports DFS.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 */
Dmitry Shmidt051af732013-10-22 13:52:46 -0700113 if ((feature->channels[j].flag &
114 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
115 dfs = 1;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700116 } else if (((feature->channels[j].flag &
117 HOSTAPD_CHAN_RADAR) &&
118 !(iface->drv_flags &
119 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
120 (feature->channels[j].flag &
121 (HOSTAPD_CHAN_NO_IBSS |
122 HOSTAPD_CHAN_PASSIVE_SCAN))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700123 feature->channels[j].flag |=
124 HOSTAPD_CHAN_DISABLED;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700125 }
126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700127 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
128 continue;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
Dmitry Shmidt051af732013-10-22 13:52:46 -0700131 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132 feature->mode,
133 feature->channels[j].chan,
134 feature->channels[j].freq,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700135 feature->channels[j].max_tx_power,
136 dfs ? dfs_info(&feature->channels[j]) : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137 }
138 }
139
140 return ret;
141}
142
143
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800144int hostapd_prepare_rates(struct hostapd_iface *iface,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 struct hostapd_hw_modes *mode)
146{
147 int i, num_basic_rates = 0;
148 int basic_rates_a[] = { 60, 120, 240, -1 };
149 int basic_rates_b[] = { 10, 20, -1 };
150 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
151 int *basic_rates;
152
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800153 if (iface->conf->basic_rates)
154 basic_rates = iface->conf->basic_rates;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155 else switch (mode->mode) {
156 case HOSTAPD_MODE_IEEE80211A:
157 basic_rates = basic_rates_a;
158 break;
159 case HOSTAPD_MODE_IEEE80211B:
160 basic_rates = basic_rates_b;
161 break;
162 case HOSTAPD_MODE_IEEE80211G:
163 basic_rates = basic_rates_g;
164 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800165 case HOSTAPD_MODE_IEEE80211AD:
166 return 0; /* No basic rates for 11ad */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167 default:
168 return -1;
169 }
170
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800171 i = 0;
172 while (basic_rates[i] >= 0)
173 i++;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700174 if (i)
175 i++; /* -1 termination */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800176 os_free(iface->basic_rates);
177 iface->basic_rates = os_malloc(i * sizeof(int));
178 if (iface->basic_rates)
179 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181 os_free(iface->current_rates);
182 iface->num_rates = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800184 iface->current_rates =
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700185 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800186 if (!iface->current_rates) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700187 wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
188 "table.");
189 return -1;
190 }
191
192 for (i = 0; i < mode->num_rates; i++) {
193 struct hostapd_rate_data *rate;
194
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195 if (iface->conf->supported_rates &&
196 !hostapd_rate_found(iface->conf->supported_rates,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700197 mode->rates[i]))
198 continue;
199
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800200 rate = &iface->current_rates[iface->num_rates];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700201 rate->rate = mode->rates[i];
202 if (hostapd_rate_found(basic_rates, rate->rate)) {
203 rate->flags |= HOSTAPD_RATE_BASIC;
204 num_basic_rates++;
205 }
206 wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800207 iface->num_rates, rate->rate, rate->flags);
208 iface->num_rates++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209 }
210
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800211 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
212 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213 wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
214 "rate sets (%d,%d).",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800215 iface->num_rates, num_basic_rates);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216 return -1;
217 }
218
219 return 0;
220}
221
222
223#ifdef CONFIG_IEEE80211N
224static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
225{
226 int sec_chan, ok, j, first;
227 int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
228 184, 192 };
229 size_t k;
230
231 if (!iface->conf->secondary_channel)
232 return 1; /* HT40 not used */
233
234 sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
235 wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
236 "secondary channel: %d",
237 iface->conf->channel, sec_chan);
238
239 /* Verify that HT40 secondary channel is an allowed 20 MHz
240 * channel */
241 ok = 0;
242 for (j = 0; j < iface->current_mode->num_channels; j++) {
243 struct hostapd_channel_data *chan =
244 &iface->current_mode->channels[j];
245 if (!(chan->flag & HOSTAPD_CHAN_DISABLED) &&
246 chan->chan == sec_chan) {
247 ok = 1;
248 break;
249 }
250 }
251 if (!ok) {
252 wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
253 sec_chan);
254 return 0;
255 }
256
257 /*
258 * Verify that HT40 primary,secondary channel pair is allowed per
259 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
260 * 2.4 GHz rules allow all cases where the secondary channel fits into
261 * the list of allowed channels (already checked above).
262 */
263 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
264 return 1;
265
266 if (iface->conf->secondary_channel > 0)
267 first = iface->conf->channel;
268 else
269 first = sec_chan;
270
271 ok = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700272 for (k = 0; k < ARRAY_SIZE(allowed); k++) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 if (first == allowed[k]) {
274 ok = 1;
275 break;
276 }
277 }
278 if (!ok) {
279 wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
280 iface->conf->channel,
281 iface->conf->secondary_channel);
282 return 0;
283 }
284
285 return 1;
286}
287
288
289static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
290{
291 if (iface->conf->secondary_channel > 0) {
292 iface->conf->channel += 4;
293 iface->conf->secondary_channel = -1;
294 } else {
295 iface->conf->channel -= 4;
296 iface->conf->secondary_channel = 1;
297 }
298}
299
300
301static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
302 int *pri_chan, int *sec_chan)
303{
304 struct ieee80211_ht_operation *oper;
305 struct ieee802_11_elems elems;
306
307 *pri_chan = *sec_chan = 0;
308
309 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
310 if (elems.ht_operation &&
311 elems.ht_operation_len >= sizeof(*oper)) {
312 oper = (struct ieee80211_ht_operation *) elems.ht_operation;
Dmitry Shmidtf940fbd2014-04-10 10:23:13 -0700313 *pri_chan = oper->primary_chan;
314 if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 int sec = oper->ht_param &
316 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
317 if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
318 *sec_chan = *pri_chan + 4;
319 else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
320 *sec_chan = *pri_chan - 4;
321 }
322 }
323}
324
325
326static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
327 struct wpa_scan_results *scan_res)
328{
329 int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
330 int bss_pri_chan, bss_sec_chan;
331 size_t i;
332 int match;
333
334 pri_chan = iface->conf->channel;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700335 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
337 if (iface->conf->secondary_channel > 0)
338 sec_freq = pri_freq + 20;
339 else
340 sec_freq = pri_freq - 20;
341
342 /*
343 * Switch PRI/SEC channels if Beacons were detected on selected SEC
344 * channel, but not on selected PRI channel.
345 */
346 pri_bss = sec_bss = 0;
347 for (i = 0; i < scan_res->num; i++) {
348 struct wpa_scan_res *bss = scan_res->res[i];
349 if (bss->freq == pri_freq)
350 pri_bss++;
351 else if (bss->freq == sec_freq)
352 sec_bss++;
353 }
354 if (sec_bss && !pri_bss) {
355 wpa_printf(MSG_INFO, "Switch own primary and secondary "
356 "channel to get secondary channel with no Beacons "
357 "from other BSSes");
358 ieee80211n_switch_pri_sec(iface);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700359 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 }
361
362 /*
363 * Match PRI/SEC channel with any existing HT40 BSS on the same
364 * channels that we are about to use (if already mixed order in
365 * existing BSSes, use own preference).
366 */
367 match = 0;
368 for (i = 0; i < scan_res->num; i++) {
369 struct wpa_scan_res *bss = scan_res->res[i];
370 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
371 if (pri_chan == bss_pri_chan &&
372 sec_chan == bss_sec_chan) {
373 match = 1;
374 break;
375 }
376 }
377 if (!match) {
378 for (i = 0; i < scan_res->num; i++) {
379 struct wpa_scan_res *bss = scan_res->res[i];
380 ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
381 &bss_sec_chan);
382 if (pri_chan == bss_sec_chan &&
383 sec_chan == bss_pri_chan) {
384 wpa_printf(MSG_INFO, "Switch own primary and "
385 "secondary channel due to BSS "
386 "overlap with " MACSTR,
387 MAC2STR(bss->bssid));
388 ieee80211n_switch_pri_sec(iface);
389 break;
390 }
391 }
392 }
393
394 return 1;
395}
396
397
398static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
399 struct wpa_scan_results *scan_res)
400{
401 int pri_freq, sec_freq;
402 int affected_start, affected_end;
403 size_t i;
404
405 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
406 if (iface->conf->secondary_channel > 0)
407 sec_freq = pri_freq + 20;
408 else
409 sec_freq = pri_freq - 20;
410 affected_start = (pri_freq + sec_freq) / 2 - 25;
411 affected_end = (pri_freq + sec_freq) / 2 + 25;
412 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
413 affected_start, affected_end);
414 for (i = 0; i < scan_res->num; i++) {
415 struct wpa_scan_res *bss = scan_res->res[i];
416 int pri = bss->freq;
417 int sec = pri;
418 int sec_chan, pri_chan;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700419 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420
421 ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
422
423 if (sec_chan) {
424 if (sec_chan < pri_chan)
425 sec = pri - 20;
426 else
427 sec = pri + 20;
428 }
429
430 if ((pri < affected_start || pri > affected_end) &&
431 (sec < affected_start || sec > affected_end))
432 continue; /* not within affected channel range */
433
434 wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
435 " freq=%d pri=%d sec=%d",
436 MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
437
438 if (sec_chan) {
439 if (pri_freq != pri || sec_freq != sec) {
440 wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
441 "mismatch with BSS " MACSTR
442 " <%d,%d> (chan=%d%c) vs. <%d,%d>",
443 MAC2STR(bss->bssid),
444 pri, sec, pri_chan,
445 sec > pri ? '+' : '-',
446 pri_freq, sec_freq);
447 return 0;
448 }
449 }
450
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700451 ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
452 0);
453 if (elems.ht_capabilities &&
454 elems.ht_capabilities_len >=
455 sizeof(struct ieee80211_ht_capabilities)) {
456 struct ieee80211_ht_capabilities *ht_cap =
457 (struct ieee80211_ht_capabilities *)
458 elems.ht_capabilities;
459
460 if (le_to_host16(ht_cap->ht_capabilities_info) &
461 HT_CAP_INFO_40MHZ_INTOLERANT) {
462 wpa_printf(MSG_DEBUG,
463 "40 MHz Intolerant is set on channel %d in BSS "
464 MACSTR, pri, MAC2STR(bss->bssid));
465 return 0;
466 }
467 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 }
469
470 return 1;
471}
472
473
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474static void ieee80211n_check_scan(struct hostapd_iface *iface)
475{
476 struct wpa_scan_results *scan_res;
477 int oper40;
478 int res;
479
480 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
Dmitry Shmidt04949592012-07-19 12:16:46 -0700481 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482
483 iface->scan_cb = NULL;
484
485 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
486 if (scan_res == NULL) {
487 hostapd_setup_interface_complete(iface, 1);
488 return;
489 }
490
491 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
492 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
493 else
494 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
495 wpa_scan_results_free(scan_res);
496
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700497 iface->secondary_ch = iface->conf->secondary_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 if (!oper40) {
499 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
500 "channel pri=%d sec=%d based on overlapping BSSes",
501 iface->conf->channel,
502 iface->conf->channel +
503 iface->conf->secondary_channel * 4);
504 iface->conf->secondary_channel = 0;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700505 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
506 /*
507 * TODO: Could consider scheduling another scan to check
508 * if channel width can be changed if no coex reports
509 * are received from associating stations.
510 */
511 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 }
513
514 res = ieee80211n_allowed_ht40_channel_pair(iface);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700515 if (!res) {
516 iface->conf->secondary_channel = 0;
517 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
518 }
519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 hostapd_setup_interface_complete(iface, !res);
521}
522
523
Dmitry Shmidt04949592012-07-19 12:16:46 -0700524static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
525 struct wpa_driver_scan_params *params)
526{
527 /* Scan only the affected frequency range */
528 int pri_freq, sec_freq;
529 int affected_start, affected_end;
530 int i, pos;
531 struct hostapd_hw_modes *mode;
532
533 if (iface->current_mode == NULL)
534 return;
535
536 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
537 if (iface->conf->secondary_channel > 0)
538 sec_freq = pri_freq + 20;
539 else
540 sec_freq = pri_freq - 20;
541 affected_start = (pri_freq + sec_freq) / 2 - 25;
542 affected_end = (pri_freq + sec_freq) / 2 + 25;
543 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
544 affected_start, affected_end);
545
546 mode = iface->current_mode;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700547 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700548 if (params->freqs == NULL)
549 return;
550 pos = 0;
551
552 for (i = 0; i < mode->num_channels; i++) {
553 struct hostapd_channel_data *chan = &mode->channels[i];
554 if (chan->flag & HOSTAPD_CHAN_DISABLED)
555 continue;
556 if (chan->freq < affected_start ||
557 chan->freq > affected_end)
558 continue;
559 params->freqs[pos++] = chan->freq;
560 }
561}
562
563
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800564static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
565 struct wpa_driver_scan_params *params)
566{
567 /* Scan only the affected frequency range */
568 int pri_freq;
569 int affected_start, affected_end;
570 int i, pos;
571 struct hostapd_hw_modes *mode;
572
573 if (iface->current_mode == NULL)
574 return;
575
576 pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
577 if (iface->conf->secondary_channel > 0) {
578 affected_start = pri_freq - 10;
579 affected_end = pri_freq + 30;
580 } else {
581 affected_start = pri_freq - 30;
582 affected_end = pri_freq + 10;
583 }
584 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
585 affected_start, affected_end);
586
587 mode = iface->current_mode;
588 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
589 if (params->freqs == NULL)
590 return;
591 pos = 0;
592
593 for (i = 0; i < mode->num_channels; i++) {
594 struct hostapd_channel_data *chan = &mode->channels[i];
595 if (chan->flag & HOSTAPD_CHAN_DISABLED)
596 continue;
597 if (chan->freq < affected_start ||
598 chan->freq > affected_end)
599 continue;
600 params->freqs[pos++] = chan->freq;
601 }
602}
603
604
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700605static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
606{
607#define HT2040_COEX_SCAN_RETRY 15
608 struct hostapd_iface *iface = eloop_data;
609 struct wpa_driver_scan_params params;
610 int ret;
611
612 os_memset(&params, 0, sizeof(params));
613 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
614 ieee80211n_scan_channels_2g4(iface, &params);
615 else
616 ieee80211n_scan_channels_5g(iface, &params);
617
618 ret = hostapd_driver_scan(iface->bss[0], &params);
619 iface->num_ht40_scan_tries++;
620 os_free(params.freqs);
621
622 if (ret == -EBUSY &&
623 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
624 wpa_printf(MSG_ERROR,
625 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
626 ret, strerror(-ret), iface->num_ht40_scan_tries);
627 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
628 return;
629 }
630
631 if (ret == 0) {
632 iface->scan_cb = ieee80211n_check_scan;
633 return;
634 }
635
636 wpa_printf(MSG_DEBUG,
637 "Failed to request a scan in device, bringing up in HT20 mode");
638 iface->conf->secondary_channel = 0;
639 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
640 hostapd_setup_interface_complete(iface, 0);
641}
642
643
644void hostapd_stop_setup_timers(struct hostapd_iface *iface)
645{
646 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
647}
648
649
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
651{
652 struct wpa_driver_scan_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700653 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654
655 if (!iface->conf->secondary_channel)
656 return 0; /* HT40 not used */
657
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800658 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
660 "40 MHz channel");
661 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700662 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
663 ieee80211n_scan_channels_2g4(iface, &params);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800664 else
665 ieee80211n_scan_channels_5g(iface, &params);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700666
667 ret = hostapd_driver_scan(iface->bss[0], &params);
668 os_free(params.freqs);
669
670 if (ret == -EBUSY) {
671 wpa_printf(MSG_ERROR,
672 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
673 ret, strerror(-ret));
674 iface->num_ht40_scan_tries = 1;
675 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
676 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
677 return 1;
678 }
679
680 if (ret < 0) {
681 wpa_printf(MSG_ERROR,
682 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
683 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 return -1;
685 }
686
687 iface->scan_cb = ieee80211n_check_scan;
688 return 1;
689}
690
691
692static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
693{
694 u16 hw = iface->current_mode->ht_capab;
695 u16 conf = iface->conf->ht_capab;
696
697 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
698 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
699 wpa_printf(MSG_ERROR, "Driver does not support configured "
700 "HT capability [LDPC]");
701 return 0;
702 }
703
704 if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
705 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
706 wpa_printf(MSG_ERROR, "Driver does not support configured "
707 "HT capability [HT40*]");
708 return 0;
709 }
710
711 if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) &&
712 (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) {
713 wpa_printf(MSG_ERROR, "Driver does not support configured "
714 "HT capability [SMPS-*]");
715 return 0;
716 }
717
718 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
719 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
720 wpa_printf(MSG_ERROR, "Driver does not support configured "
721 "HT capability [GF]");
722 return 0;
723 }
724
725 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
726 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
727 wpa_printf(MSG_ERROR, "Driver does not support configured "
728 "HT capability [SHORT-GI-20]");
729 return 0;
730 }
731
732 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
733 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
734 wpa_printf(MSG_ERROR, "Driver does not support configured "
735 "HT capability [SHORT-GI-40]");
736 return 0;
737 }
738
739 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
740 wpa_printf(MSG_ERROR, "Driver does not support configured "
741 "HT capability [TX-STBC]");
742 return 0;
743 }
744
745 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
746 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
747 wpa_printf(MSG_ERROR, "Driver does not support configured "
748 "HT capability [RX-STBC*]");
749 return 0;
750 }
751
752 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
753 !(hw & HT_CAP_INFO_DELAYED_BA)) {
754 wpa_printf(MSG_ERROR, "Driver does not support configured "
755 "HT capability [DELAYED-BA]");
756 return 0;
757 }
758
759 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
760 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
761 wpa_printf(MSG_ERROR, "Driver does not support configured "
762 "HT capability [MAX-AMSDU-7935]");
763 return 0;
764 }
765
766 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
767 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
768 wpa_printf(MSG_ERROR, "Driver does not support configured "
769 "HT capability [DSSS_CCK-40]");
770 return 0;
771 }
772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
774 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
775 wpa_printf(MSG_ERROR, "Driver does not support configured "
776 "HT capability [LSIG-TXOP-PROT]");
777 return 0;
778 }
779
780 return 1;
781}
782
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700783
784#ifdef CONFIG_IEEE80211AC
785
786static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
787{
788 u32 req_cap = conf & cap;
789
790 /*
791 * Make sure we support all requested capabilities.
792 * NOTE: We assume that 'cap' represents a capability mask,
793 * not a discrete value.
794 */
795 if ((hw & req_cap) != req_cap) {
796 wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
797 name);
798 return 0;
799 }
800 return 1;
801}
802
803
804static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap,
805 const char *name)
806{
807 u32 hw_max = hw & cap;
808 u32 conf_val = conf & cap;
809
810 if (conf_val > hw_max) {
811 int offset = find_first_bit(cap);
812 wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
813 name, conf_val >> offset, hw_max >> offset);
814 return 0;
815 }
816 return 1;
817}
818
819
820static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
821{
822 u32 hw = iface->current_mode->vht_capab;
823 u32 conf = iface->conf->vht_capab;
824
825 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
826 hw, conf);
827
828#define VHT_CAP_CHECK(cap) \
829 do { \
830 if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
831 return 0; \
832 } while (0)
833
834#define VHT_CAP_CHECK_MAX(cap) \
835 do { \
836 if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \
837 return 0; \
838 } while (0)
839
840 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
841 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
842 VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
843 VHT_CAP_CHECK(VHT_CAP_RXLDPC);
844 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
845 VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
846 VHT_CAP_CHECK(VHT_CAP_TXSTBC);
847 VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
848 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
849 VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
850 VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
851 VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
852 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
853 VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
854 VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
855 VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800856 VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700857 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
858 VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
859 VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
860 VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
861
862#undef VHT_CAP_CHECK
863#undef VHT_CAP_CHECK_MAX
864
865 return 1;
866}
867#endif /* CONFIG_IEEE80211AC */
868
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869#endif /* CONFIG_IEEE80211N */
870
871
872int hostapd_check_ht_capab(struct hostapd_iface *iface)
873{
874#ifdef CONFIG_IEEE80211N
875 int ret;
876 if (!iface->conf->ieee80211n)
877 return 0;
878 if (!ieee80211n_supported_ht_capab(iface))
879 return -1;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700880#ifdef CONFIG_IEEE80211AC
881 if (!ieee80211ac_supported_vht_capab(iface))
882 return -1;
883#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884 ret = ieee80211n_check_40mhz(iface);
885 if (ret)
886 return ret;
887 if (!ieee80211n_allowed_ht40_channel_pair(iface))
888 return -1;
889#endif /* CONFIG_IEEE80211N */
890
891 return 0;
892}
893
894
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700895static int hostapd_is_usable_chan(struct hostapd_iface *iface,
896 int channel, int primary)
897{
898 int i;
899 struct hostapd_channel_data *chan;
900
901 for (i = 0; i < iface->current_mode->num_channels; i++) {
902 chan = &iface->current_mode->channels[i];
903 if (chan->chan != channel)
904 continue;
905
906 if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
907 return 1;
908
909 wpa_printf(MSG_DEBUG,
910 "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s",
911 primary ? "" : "Configured HT40 secondary ",
912 i, chan->chan, chan->flag,
913 chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "",
914 chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ?
915 " PASSIVE-SCAN" : "",
916 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
917 }
918
919 return 0;
920}
921
922
923static int hostapd_is_usable_chans(struct hostapd_iface *iface)
924{
925 if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
926 return 0;
927
928 if (!iface->conf->secondary_channel)
929 return 1;
930
931 return hostapd_is_usable_chan(iface, iface->conf->channel +
932 iface->conf->secondary_channel * 4, 0);
933}
934
935
936static enum hostapd_chan_status
937hostapd_check_chans(struct hostapd_iface *iface)
938{
939 if (iface->conf->channel) {
940 if (hostapd_is_usable_chans(iface))
941 return HOSTAPD_CHAN_VALID;
942 else
943 return HOSTAPD_CHAN_INVALID;
944 }
945
946 /*
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700947 * The user set channel=0 or channel=acs_survey
948 * which is used to trigger ACS.
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700949 */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700950
951 switch (acs_init(iface)) {
952 case HOSTAPD_CHAN_ACS:
953 return HOSTAPD_CHAN_ACS;
954 case HOSTAPD_CHAN_VALID:
955 case HOSTAPD_CHAN_INVALID:
956 default:
957 return HOSTAPD_CHAN_INVALID;
958 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700959}
960
961
962static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
963{
964 hostapd_logger(iface->bss[0], NULL,
965 HOSTAPD_MODULE_IEEE80211,
966 HOSTAPD_LEVEL_WARNING,
967 "Configured channel (%d) not found from the "
968 "channel list of current mode (%d) %s",
969 iface->conf->channel,
970 iface->current_mode->mode,
971 hostapd_hw_mode_txt(iface->current_mode->mode));
972 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
973 HOSTAPD_LEVEL_WARNING,
974 "Hardware does not support configured channel");
975}
976
977
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700978int hostapd_acs_completed(struct hostapd_iface *iface, int err)
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700979{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700980 int ret = -1;
981
982 if (err)
983 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700984
985 switch (hostapd_check_chans(iface)) {
986 case HOSTAPD_CHAN_VALID:
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800987 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
988 ACS_EVENT_COMPLETED "freq=%d channel=%d",
989 hostapd_hw_get_freq(iface->bss[0],
990 iface->conf->channel),
991 iface->conf->channel);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700992 break;
993 case HOSTAPD_CHAN_ACS:
994 wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800995 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700996 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -0700997 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700998 case HOSTAPD_CHAN_INVALID:
999 default:
1000 wpa_printf(MSG_ERROR, "ACS picked unusable channels");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001002 hostapd_notify_bad_chans(iface);
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001003 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001004 }
1005
1006 ret = hostapd_check_ht_capab(iface);
1007 if (ret < 0)
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001008 goto out;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001009 if (ret == 1) {
1010 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
1011 return 0;
1012 }
1013
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07001014 ret = 0;
1015out:
1016 return hostapd_setup_interface_complete(iface, ret);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001017}
1018
1019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020/**
1021 * hostapd_select_hw_mode - Select the hardware mode
1022 * @iface: Pointer to interface data.
Jouni Malinen87fd2792011-05-16 18:35:42 +03001023 * Returns: 0 on success, < 0 on failure
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001024 *
1025 * Sets up the hardware mode, channel, rates, and passive scanning
1026 * based on the configuration.
1027 */
1028int hostapd_select_hw_mode(struct hostapd_iface *iface)
1029{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001030 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031
1032 if (iface->num_hw_features < 1)
1033 return -1;
1034
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001035 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
1036 iface->conf->ieee80211n || iface->conf->ieee80211ac) &&
1037 iface->conf->channel == 14) {
1038 wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14");
1039 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1040 iface->conf->ieee80211n = 0;
1041 iface->conf->ieee80211ac = 0;
1042 }
1043
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044 iface->current_mode = NULL;
1045 for (i = 0; i < iface->num_hw_features; i++) {
1046 struct hostapd_hw_modes *mode = &iface->hw_features[i];
1047 if (mode->mode == iface->conf->hw_mode) {
1048 iface->current_mode = mode;
1049 break;
1050 }
1051 }
1052
1053 if (iface->current_mode == NULL) {
1054 wpa_printf(MSG_ERROR, "Hardware does not support configured "
1055 "mode");
1056 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1057 HOSTAPD_LEVEL_WARNING,
1058 "Hardware does not support configured mode "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001059 "(%d) (hw_mode in hostapd.conf)",
1060 (int) iface->conf->hw_mode);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001061 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 }
1063
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001064 switch (hostapd_check_chans(iface)) {
1065 case HOSTAPD_CHAN_VALID:
1066 return 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001067 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1068 return 1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001069 case HOSTAPD_CHAN_INVALID:
1070 default:
1071 hostapd_notify_bad_chans(iface);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001072 return -3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074}
1075
1076
1077const char * hostapd_hw_mode_txt(int mode)
1078{
1079 switch (mode) {
1080 case HOSTAPD_MODE_IEEE80211A:
1081 return "IEEE 802.11a";
1082 case HOSTAPD_MODE_IEEE80211B:
1083 return "IEEE 802.11b";
1084 case HOSTAPD_MODE_IEEE80211G:
1085 return "IEEE 802.11g";
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001086 case HOSTAPD_MODE_IEEE80211AD:
1087 return "IEEE 802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 default:
1089 return "UNKNOWN";
1090 }
1091}
1092
1093
1094int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1095{
1096 int i;
1097
1098 if (!hapd->iface->current_mode)
1099 return 0;
1100
1101 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1102 struct hostapd_channel_data *ch =
1103 &hapd->iface->current_mode->channels[i];
1104 if (ch->chan == chan)
1105 return ch->freq;
1106 }
1107
1108 return 0;
1109}
1110
1111
1112int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1113{
1114 int i;
1115
1116 if (!hapd->iface->current_mode)
1117 return 0;
1118
1119 for (i = 0; i < hapd->iface->current_mode->num_channels; i++) {
1120 struct hostapd_channel_data *ch =
1121 &hapd->iface->current_mode->channels[i];
1122 if (ch->freq == freq)
1123 return ch->chan;
1124 }
1125
1126 return 0;
1127}