1 /*
2 * hostapd / Hardware feature query and different modes
3 * Copyright 2002-2003, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
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"
17 #include "common/wpa_ctrl.h"
18 #include "common/hw_features_common.h"
19 #include "hostapd.h"
20 #include "ap_config.h"
21 #include "ap_drv_ops.h"
22 #include "acs.h"
23 #include "ieee802_11.h"
24 #include "beacon.h"
25 #include "hw_features.h"
26 #ifdef LOS_WPA_PATCH
27 #include "wifi_api.h"
28 #endif /* LOS_WPA_PATCH */
29
hostapd_free_hw_features(struct hostapd_hw_modes * hw_features,size_t num_hw_features)30 void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
31 size_t num_hw_features)
32 {
33 size_t i;
34
35 if (hw_features == NULL)
36 return;
37
38 for (i = 0; i < num_hw_features; i++) {
39 os_free(hw_features[i].channels);
40 os_free(hw_features[i].rates);
41 }
42
43 os_free(hw_features);
44 }
45
46
47 #ifndef CONFIG_NO_STDOUT_DEBUG
dfs_info(struct hostapd_channel_data * chan)48 static char * dfs_info(struct hostapd_channel_data *chan)
49 {
50 static char info[256];
51 char *state;
52
53 switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
54 case HOSTAPD_CHAN_DFS_UNKNOWN:
55 state = "unknown";
56 break;
57 case HOSTAPD_CHAN_DFS_USABLE:
58 state = "usable";
59 break;
60 case HOSTAPD_CHAN_DFS_UNAVAILABLE:
61 state = "unavailable";
62 break;
63 case HOSTAPD_CHAN_DFS_AVAILABLE:
64 state = "available";
65 break;
66 default:
67 return "";
68 }
69 os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
70 info[sizeof(info) - 1] = '\0';
71
72 return info;
73 }
74 #endif /* CONFIG_NO_STDOUT_DEBUG */
75
76
hostapd_get_hw_features(struct hostapd_iface * iface)77 int hostapd_get_hw_features(struct hostapd_iface *iface)
78 {
79 struct hostapd_data *hapd = iface->bss[0];
80 int i, j;
81 u16 num_modes, flags;
82 struct hostapd_hw_modes *modes;
83 #ifndef EXT_CODE_CROP
84 u8 dfs_domain;
85 #endif /* EXT_CODE_CROP */
86 #ifndef LOS_CONFIG_EXT_DRIVER_NOT_SUPPORT
87 if (hostapd_drv_none(hapd))
88 return -1;
89 #endif /* LOS_CONFIG_EXT_DRIVER_NOT_SUPPORT */
90 #ifndef EXT_CODE_CROP
91 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags,
92 &dfs_domain);
93 #else
94 modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
95 #endif /* EXT_CODE_CROP */
96 if (modes == NULL) {
97 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
98 HOSTAPD_LEVEL_DEBUG,
99 "Fetching hardware channel/rate support not "
100 "supported.");
101 return -1;
102 }
103
104 #ifndef EXT_CODE_CROP
105 iface->hw_flags = flags;
106 iface->dfs_domain = dfs_domain;
107 #endif /* EXT_CODE_CROP */
108
109 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
110 iface->hw_features = modes;
111 iface->num_hw_features = num_modes;
112
113 for (i = 0; i < num_modes; i++) {
114 struct hostapd_hw_modes *feature = &modes[i];
115 #ifndef EXT_CODE_CROP
116 int dfs_enabled = hapd->iconf->ieee80211h &&
117 (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
118 #endif
119 /* set flag for channels we can use in current regulatory
120 * domain */
121 for (j = 0; j < feature->num_channels; j++) {
122 #ifndef EXT_CODE_CROP
123 int dfs = 0;
124 #endif
125 /*
126 * Disable all channels that are marked not to allow
127 * to initiate radiation (a.k.a. passive scan and no
128 * IBSS).
129 * Use radar channels only if the driver supports DFS.
130 */
131 #ifndef EXT_CODE_CROP
132 if ((feature->channels[j].flag &
133 HOSTAPD_CHAN_RADAR) && dfs_enabled) {
134 dfs = 1;
135 } else
136 #endif
137 if (((feature->channels[j].flag &
138 HOSTAPD_CHAN_RADAR) &&
139 !(iface->drv_flags &
140 WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
141 (feature->channels[j].flag &
142 HOSTAPD_CHAN_NO_IR)) {
143 feature->channels[j].flag |=
144 HOSTAPD_CHAN_DISABLED;
145 }
146
147 if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
148 continue;
149 #ifndef EXT_CODE_CROP
150 wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
151 "chan=%d freq=%d MHz max_tx_power=%d dBm%s",
152 feature->mode,
153 feature->channels[j].chan,
154 feature->channels[j].freq,
155 feature->channels[j].max_tx_power,
156 dfs ? dfs_info(&feature->channels[j]) : "");
157 #else
158 wpa_msgdump_log3(MSG_MSGDUMP, "Allowed channel: mode=%d "
159 "chan=%d freq=%d MHz",
160 feature->mode,
161 feature->channels[j].chan,
162 feature->channels[j].freq);
163 #endif /* EXT_CODE_CROP */
164 }
165 }
166
167 return 0;
168 }
169
170
hostapd_prepare_rates(struct hostapd_iface * iface,struct hostapd_hw_modes * mode)171 int hostapd_prepare_rates(struct hostapd_iface *iface,
172 struct hostapd_hw_modes *mode)
173 {
174 int i, num_basic_rates = 0;
175 #ifndef EXT_CODE_CROP
176 int basic_rates_a[] = { 60, 120, 240, -1 };
177 #endif /* EXT_CODE_CROP */
178 int basic_rates_b[] = { 10, 20, -1 };
179 int basic_rates_g[] = { 10, 20, 55, 110, -1 };
180 int *basic_rates;
181
182 if (iface->conf->basic_rates)
183 basic_rates = iface->conf->basic_rates;
184 else switch (mode->mode) {
185 #ifndef EXT_CODE_CROP
186 case HOSTAPD_MODE_IEEE80211A:
187 basic_rates = basic_rates_a;
188 break;
189 #endif /* EXT_CODE_CROP */
190 case HOSTAPD_MODE_IEEE80211B:
191 basic_rates = basic_rates_b;
192 break;
193 case HOSTAPD_MODE_IEEE80211G:
194 basic_rates = basic_rates_g;
195 break;
196 #ifndef EXT_CODE_CROP
197 case HOSTAPD_MODE_IEEE80211AD:
198 return 0; /* No basic rates for 11ad */
199 #endif /* EXT_CODE_CROP */
200 default:
201 return -1;
202 }
203
204 i = 0;
205 while (basic_rates[i] >= 0)
206 i++;
207 if (i)
208 i++; /* -1 termination */
209 os_free(iface->basic_rates);
210 iface->basic_rates = os_malloc(i * sizeof(int));
211 if (iface->basic_rates)
212 os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
213
214 os_free(iface->current_rates);
215 iface->num_rates = 0;
216
217 iface->current_rates =
218 os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
219 if (!iface->current_rates) {
220 wpa_error_log0(MSG_ERROR, "Failed to allocate memory for rate "
221 "table.");
222 return -1;
223 }
224
225 for (i = 0; i < mode->num_rates; i++) {
226 struct hostapd_rate_data *rate;
227
228 if (iface->conf->supported_rates &&
229 !hostapd_rate_found(iface->conf->supported_rates,
230 mode->rates[i]))
231 continue;
232
233 rate = &iface->current_rates[iface->num_rates];
234 rate->rate = mode->rates[i];
235 if (hostapd_rate_found(basic_rates, rate->rate)) {
236 rate->flags |= HOSTAPD_RATE_BASIC;
237 num_basic_rates++;
238 }
239 wpa_warning_log3(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
240 iface->num_rates, rate->rate, rate->flags);
241 iface->num_rates++;
242 }
243
244 if ((iface->num_rates == 0 || num_basic_rates == 0) &&
245 #ifndef EXT_CODE_CROP
246 (!iface->conf->ieee80211n || !iface->conf->require_ht)) {
247 #else
248 (!iface->conf->ieee80211n)) {
249 #endif /* EXT_CODE_CROP */
250 wpa_error_log2(MSG_ERROR, "No rates remaining in supported/basic "
251 "rate sets (%d,%d).",
252 iface->num_rates, num_basic_rates);
253 return -1;
254 }
255
256 return 0;
257 }
258
259
260 #ifndef EXT_CODE_CROP
261 static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
262 {
263 int pri_freq, sec_freq;
264 struct hostapd_channel_data *p_chan, *s_chan;
265
266 pri_freq = iface->freq;
267 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
268
269 if (!iface->current_mode)
270 return 0;
271
272 p_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq, NULL,
273 iface->hw_features,
274 iface->num_hw_features);
275
276 s_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq, NULL,
277 iface->hw_features,
278 iface->num_hw_features);
279
280 return allowed_ht40_channel_pair(iface->current_mode->mode,
281 p_chan, s_chan);
282 }
283
284
285 static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
286 {
287 if (iface->conf->secondary_channel > 0) {
288 iface->conf->channel += 4;
289 iface->freq += 20;
290 iface->conf->secondary_channel = -1;
291 } else {
292 iface->conf->channel -= 4;
293 iface->freq -= 20;
294 iface->conf->secondary_channel = 1;
295 }
296 }
297
298
299 static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
300 struct wpa_scan_results *scan_res)
301 {
302 unsigned int pri_freq, sec_freq;
303 int res;
304 struct hostapd_channel_data *pri_chan, *sec_chan;
305
306 pri_freq = iface->freq;
307 sec_freq = pri_freq + iface->conf->secondary_channel * 20;
308
309 if (!iface->current_mode)
310 return 0;
311 pri_chan = hw_get_channel_freq(iface->current_mode->mode, pri_freq,
312 NULL, iface->hw_features,
313 iface->num_hw_features);
314 sec_chan = hw_get_channel_freq(iface->current_mode->mode, sec_freq,
315 NULL, iface->hw_features,
316 iface->num_hw_features);
317
318 res = check_40mhz_5g(scan_res, pri_chan, sec_chan);
319
320 if (res == 2) {
321 if (iface->conf->no_pri_sec_switch) {
322 wpa_printf(MSG_DEBUG,
323 "Cannot switch PRI/SEC channels due to local constraint");
324 } else {
325 ieee80211n_switch_pri_sec(iface);
326 }
327 }
328
329 return !!res;
330 }
331
332
333 static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
334 struct wpa_scan_results *scan_res)
335 {
336 int pri_chan, sec_chan;
337
338 pri_chan = iface->conf->channel;
339 sec_chan = pri_chan + iface->conf->secondary_channel * 4;
340
341 return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan,
342 sec_chan);
343 }
344
345
346 static void ieee80211n_check_scan(struct hostapd_iface *iface)
347 {
348 struct wpa_scan_results *scan_res;
349 int oper40;
350 int res = 0;
351
352 /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
353 * allowed per IEEE Std 802.11-2012, 10.15.3.2 */
354
355 iface->scan_cb = NULL;
356
357 scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
358 if (scan_res == NULL) {
359 hostapd_setup_interface_complete(iface, 1);
360 return;
361 }
362
363 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
364 oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
365 else
366 oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
367 wpa_scan_results_free(scan_res);
368
369 iface->secondary_ch = iface->conf->secondary_channel;
370 if (!oper40) {
371 wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
372 "channel pri=%d sec=%d based on overlapping BSSes",
373 iface->conf->channel,
374 iface->conf->channel +
375 iface->conf->secondary_channel * 4);
376 iface->conf->secondary_channel = 0;
377 if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
378 /*
379 * TODO: Could consider scheduling another scan to check
380 * if channel width can be changed if no coex reports
381 * are received from associating stations.
382 */
383 }
384 }
385
386 #ifdef CONFIG_IEEE80211AX
387 if (iface->conf->secondary_channel &&
388 iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
389 iface->conf->ieee80211ax) {
390 struct he_capabilities *he_cap;
391
392 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
393 if (!(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
394 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_IN_2G)) {
395 wpa_printf(MSG_DEBUG,
396 "HE: 40 MHz channel width is not supported in 2.4 GHz; clear secondary channel configuration");
397 iface->conf->secondary_channel = 0;
398 }
399 }
400 #endif /* CONFIG_IEEE80211AX */
401
402 if (iface->conf->secondary_channel)
403 res = ieee80211n_allowed_ht40_channel_pair(iface);
404 if (!res) {
405 iface->conf->secondary_channel = 0;
406 hostapd_set_oper_centr_freq_seg0_idx(iface->conf, 0);
407 hostapd_set_oper_centr_freq_seg1_idx(iface->conf, 0);
408 hostapd_set_oper_chwidth(iface->conf, CHANWIDTH_USE_HT);
409 res = 1;
410 wpa_printf(MSG_INFO, "Fallback to 20 MHz");
411 }
412
413 hostapd_setup_interface_complete(iface, !res);
414 }
415
416
417 static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
418 struct wpa_driver_scan_params *params)
419 {
420 /* Scan only the affected frequency range */
421 int pri_freq, sec_freq;
422 int affected_start, affected_end;
423 int i, pos;
424 struct hostapd_hw_modes *mode;
425
426 if (iface->current_mode == NULL)
427 return;
428
429 pri_freq = iface->freq;
430 if (iface->conf->secondary_channel > 0)
431 sec_freq = pri_freq + 20;
432 else
433 sec_freq = pri_freq - 20;
434 /*
435 * Note: Need to find the PRI channel also in cases where the affected
436 * channel is the SEC channel of a 40 MHz BSS, so need to include the
437 * scanning coverage here to be 40 MHz from the center frequency.
438 */
439 affected_start = (pri_freq + sec_freq) / 2 - 40;
440 affected_end = (pri_freq + sec_freq) / 2 + 40;
441 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
442 affected_start, affected_end);
443
444 mode = iface->current_mode;
445 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
446 if (params->freqs == NULL)
447 return;
448 pos = 0;
449
450 for (i = 0; i < mode->num_channels; i++) {
451 struct hostapd_channel_data *chan = &mode->channels[i];
452 if (chan->flag & HOSTAPD_CHAN_DISABLED)
453 continue;
454 if (chan->freq < affected_start ||
455 chan->freq > affected_end)
456 continue;
457 params->freqs[pos++] = chan->freq;
458 }
459 }
460
461
462 static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
463 struct wpa_driver_scan_params *params)
464 {
465 /* Scan only the affected frequency range */
466 int pri_freq;
467 int affected_start, affected_end;
468 int i, pos;
469 struct hostapd_hw_modes *mode;
470
471 if (iface->current_mode == NULL)
472 return;
473
474 pri_freq = iface->freq;
475 if (iface->conf->secondary_channel > 0) {
476 affected_start = pri_freq - 10;
477 affected_end = pri_freq + 30;
478 } else {
479 affected_start = pri_freq - 30;
480 affected_end = pri_freq + 10;
481 }
482 wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
483 affected_start, affected_end);
484
485 mode = iface->current_mode;
486 params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
487 if (params->freqs == NULL)
488 return;
489 pos = 0;
490
491 for (i = 0; i < mode->num_channels; i++) {
492 struct hostapd_channel_data *chan = &mode->channels[i];
493 if (chan->flag & HOSTAPD_CHAN_DISABLED)
494 continue;
495 if (chan->freq < affected_start ||
496 chan->freq > affected_end)
497 continue;
498 params->freqs[pos++] = chan->freq;
499 }
500 }
501
502
503 static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
504 {
505 #define HT2040_COEX_SCAN_RETRY 15
506 struct hostapd_iface *iface = eloop_data;
507 struct wpa_driver_scan_params params;
508 int ret;
509
510 os_memset(¶ms, 0, sizeof(params));
511 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
512 ieee80211n_scan_channels_2g4(iface, ¶ms);
513 else
514 ieee80211n_scan_channels_5g(iface, ¶ms);
515
516 ret = hostapd_driver_scan(iface->bss[0], ¶ms);
517 iface->num_ht40_scan_tries++;
518 os_free(params.freqs);
519
520 if (ret == -EBUSY &&
521 iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
522 wpa_printf(MSG_ERROR,
523 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
524 ret, strerror(-ret), iface->num_ht40_scan_tries);
525 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
526 return;
527 }
528
529 if (ret == 0) {
530 iface->scan_cb = ieee80211n_check_scan;
531 return;
532 }
533
534 wpa_printf(MSG_DEBUG,
535 "Failed to request a scan in device, bringing up in HT20 mode");
536 iface->conf->secondary_channel = 0;
537 iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
538 hostapd_setup_interface_complete(iface, 0);
539 }
540
541
542 void hostapd_stop_setup_timers(struct hostapd_iface *iface)
543 {
544 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
545 }
546
547
548 static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
549 {
550 struct wpa_driver_scan_params params;
551 int ret;
552
553 /* Check that HT40 is used and PRI / SEC switch is allowed */
554 if (!iface->conf->secondary_channel || iface->conf->no_pri_sec_switch)
555 return 0;
556
557 hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
558 wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
559 "40 MHz channel");
560 os_memset(¶ms, 0, sizeof(params));
561 if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
562 ieee80211n_scan_channels_2g4(iface, ¶ms);
563 else
564 ieee80211n_scan_channels_5g(iface, ¶ms);
565
566 ret = hostapd_driver_scan(iface->bss[0], ¶ms);
567 os_free(params.freqs);
568
569 if (ret == -EBUSY) {
570 wpa_printf(MSG_ERROR,
571 "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
572 ret, strerror(-ret));
573 iface->num_ht40_scan_tries = 1;
574 eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
575 eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
576 return 1;
577 }
578
579 if (ret < 0) {
580 wpa_printf(MSG_ERROR,
581 "Failed to request a scan of neighboring BSSes ret=%d (%s)",
582 ret, strerror(-ret));
583 return -1;
584 }
585
586 iface->scan_cb = ieee80211n_check_scan;
587 return 1;
588 }
589 #endif /* EXT_CODE_CROP */
590
591 static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
592 {
593 u16 hw = iface->current_mode->ht_capab;
594 u16 conf = iface->conf->ht_capab;
595
596 #ifndef EXT_CODE_CROP
597 if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
598 !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
599 wpa_printf(MSG_ERROR, "Driver does not support configured "
600 "HT capability [LDPC]");
601 return 0;
602 }
603 #ifdef CONFIG_ACS
604 /*
605 * Driver ACS chosen channel may not be HT40 due to internal driver
606 * restrictions.
607 */
608 if (!iface->conf->acs && (conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
609 !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
610 wpa_printf(MSG_ERROR, "Driver does not support configured "
611 "HT capability [HT40*]");
612 return 0;
613 }
614 #endif /* CONFIG_ACS */
615
616 if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
617 !(hw & HT_CAP_INFO_GREEN_FIELD)) {
618 wpa_printf(MSG_ERROR, "Driver does not support configured "
619 "HT capability [GF]");
620 return 0;
621 }
622 #endif /* EXT_CODE_CROP */
623
624 if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
625 !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
626 wpa_error_log0(MSG_ERROR, "Driver does not support configured "
627 "HT capability [SHORT-GI-20]");
628 return 0;
629 }
630 #ifndef EXT_CODE_CROP
631 if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
632 !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
633 wpa_printf(MSG_ERROR, "Driver does not support configured "
634 "HT capability [SHORT-GI-40]");
635 return 0;
636 }
637 #endif /* EXT_CODE_CROP */
638 if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
639 wpa_error_log0(MSG_ERROR, "Driver does not support configured "
640 "HT capability [TX-STBC]");
641 return 0;
642 }
643
644 if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
645 (hw & HT_CAP_INFO_RX_STBC_MASK)) {
646 wpa_error_log0(MSG_ERROR, "Driver does not support configured "
647 "HT capability [RX-STBC*]");
648 return 0;
649 }
650 #ifndef EXT_CODE_CROP
651 if ((conf & HT_CAP_INFO_DELAYED_BA) &&
652 !(hw & HT_CAP_INFO_DELAYED_BA)) {
653 wpa_printf(MSG_ERROR, "Driver does not support configured "
654 "HT capability [DELAYED-BA]");
655 return 0;
656 }
657 #endif /* EXT_CODE_CROP */
658
659 if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
660 !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
661 wpa_error_log0(MSG_ERROR, "Driver does not support configured "
662 "HT capability [MAX-AMSDU-7935]");
663 return 0;
664 }
665
666 #ifndef EXT_CODE_CROP
667 if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
668 !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
669 wpa_printf(MSG_ERROR, "Driver does not support configured "
670 "HT capability [DSSS_CCK-40]");
671 return 0;
672 }
673
674 if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
675 !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
676 wpa_printf(MSG_ERROR, "Driver does not support configured "
677 "HT capability [LSIG-TXOP-PROT]");
678 return 0;
679 }
680 #endif /* EXT_CODE_CROP */
681
682 return 1;
683 }
684
685
686 #ifdef CONFIG_IEEE80211AC
687 static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
688 {
689 struct hostapd_hw_modes *mode = iface->current_mode;
690 u32 hw = mode->vht_capab;
691 u32 conf = iface->conf->vht_capab;
692
693 wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
694 hw, conf);
695
696 if (mode->mode == HOSTAPD_MODE_IEEE80211G &&
697 iface->conf->bss[0]->vendor_vht &&
698 mode->vht_capab == 0 && iface->hw_features) {
699 int i;
700
701 for (i = 0; i < iface->num_hw_features; i++) {
702 if (iface->hw_features[i].mode ==
703 HOSTAPD_MODE_IEEE80211A) {
704 mode = &iface->hw_features[i];
705 hw = mode->vht_capab;
706 wpa_printf(MSG_DEBUG,
707 "update hw vht capab based on 5 GHz band: 0x%x",
708 hw);
709 break;
710 }
711 }
712 }
713
714 return ieee80211ac_cap_check(hw, conf);
715 }
716 #endif /* CONFIG_IEEE80211AC */
717
718
719 #ifdef CONFIG_IEEE80211AX
720 static int ieee80211ax_supported_he_capab(struct hostapd_iface *iface)
721 {
722 return 1;
723 }
724 #endif /* CONFIG_IEEE80211AX */
725
726
727 int hostapd_check_ht_capab(struct hostapd_iface *iface)
728 {
729 int ret;
730
731 if (is_6ghz_freq(iface->freq))
732 return 0;
733 if (!iface->conf->ieee80211n)
734 return 0;
735 #ifndef EXT_CODE_CROP
736 if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211B &&
737 iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G &&
738 (iface->conf->ht_capab & HT_CAP_INFO_DSSS_CCK40MHZ)) {
739 wpa_printf(MSG_DEBUG,
740 "Disable HT capability [DSSS_CCK-40] on 5 GHz band");
741 iface->conf->ht_capab &= ~HT_CAP_INFO_DSSS_CCK40MHZ;
742 }
743 #endif /* EXT_CODE_CROP */
744
745 if (!ieee80211n_supported_ht_capab(iface))
746 return -1;
747 #ifdef CONFIG_IEEE80211AX
748 if (iface->conf->ieee80211ax &&
749 !ieee80211ax_supported_he_capab(iface))
750 return -1;
751 #endif /* CONFIG_IEEE80211AX */
752 #ifdef CONFIG_IEEE80211AC
753 if (iface->conf->ieee80211ac &&
754 !ieee80211ac_supported_vht_capab(iface))
755 return -1;
756 #endif /* CONFIG_IEEE80211AC */
757 #ifndef LOS_HOSTAPD_HT_CONFIG_CROP
758 ret = ieee80211n_check_40mhz(iface);
759 if (ret)
760 return ret;
761 if (!ieee80211n_allowed_ht40_channel_pair(iface))
762 return -1;
763 #endif /* LOS_HOSTAPD_HT_CONFIG_CROP */
764 return 0;
765 }
766
767
768 int hostapd_check_edmg_capab(struct hostapd_iface *iface)
769 {
770 struct hostapd_hw_modes *mode = iface->hw_features;
771 struct ieee80211_edmg_config edmg;
772
773 if (!iface->conf->enable_edmg)
774 return 0;
775
776 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
777 iface->conf->edmg_channel,
778 iface->conf->channel,
779 &edmg);
780
781 if (mode->edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg))
782 return 0;
783
784 wpa_printf(MSG_WARNING, "Requested EDMG configuration is not valid");
785 wpa_printf(MSG_INFO, "EDMG capab: channels 0x%x, bw_config %d",
786 mode->edmg.channels, mode->edmg.bw_config);
787 wpa_printf(MSG_INFO,
788 "Requested EDMG configuration: channels 0x%x, bw_config %d",
789 edmg.channels, edmg.bw_config);
790 return -1;
791 }
792
793
794 int hostapd_check_he_6ghz_capab(struct hostapd_iface *iface)
795 {
796 #ifdef CONFIG_IEEE80211AX
797 struct he_capabilities *he_cap;
798 u16 hw;
799
800 if (!iface->current_mode || !is_6ghz_freq(iface->freq))
801 return 0;
802
803 he_cap = &iface->current_mode->he_capab[IEEE80211_MODE_AP];
804 hw = he_cap->he_6ghz_capa;
805 if (iface->conf->he_6ghz_max_mpdu >
806 ((hw & HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_MASK) >>
807 HE_6GHZ_BAND_CAP_MAX_MPDU_LEN_SHIFT)) {
808 wpa_printf(MSG_ERROR,
809 "The driver does not support the configured HE 6 GHz Max MPDU length");
810 return -1;
811 }
812
813 if (iface->conf->he_6ghz_max_ampdu_len_exp >
814 ((hw & HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_MASK) >>
815 HE_6GHZ_BAND_CAP_MAX_AMPDU_LEN_EXP_SHIFT)) {
816 wpa_printf(MSG_ERROR,
817 "The driver does not support the configured HE 6 GHz Max AMPDU Length Exponent");
818 return -1;
819 }
820
821 if (iface->conf->he_6ghz_rx_ant_pat &&
822 !(hw & HE_6GHZ_BAND_CAP_RX_ANTPAT_CONS)) {
823 wpa_printf(MSG_ERROR,
824 "The driver does not support the configured HE 6 GHz Rx Antenna Pattern");
825 return -1;
826 }
827
828 if (iface->conf->he_6ghz_tx_ant_pat &&
829 !(hw & HE_6GHZ_BAND_CAP_TX_ANTPAT_CONS)) {
830 wpa_printf(MSG_ERROR,
831 "The driver does not support the configured HE 6 GHz Tx Antenna Pattern");
832 return -1;
833 }
834 #endif /* CONFIG_IEEE80211AX */
835 return 0;
836 }
837
838
839 static int hostapd_is_usable_chan(struct hostapd_iface *iface,
840 int frequency, int primary)
841 {
842 struct hostapd_channel_data *chan;
843
844 if (!iface->current_mode)
845 return 0;
846
847 chan = hw_get_channel_freq(iface->current_mode->mode, frequency, NULL,
848 iface->hw_features, iface->num_hw_features);
849 if (!chan)
850 return 0;
851
852 #if !defined(EXT_CODE_CROP) || defined(CONFIG_ACS)
853 if ((primary && chan_pri_allowed(chan)) ||
854 (!primary && !(chan->flag & HOSTAPD_CHAN_DISABLED)))
855 return 1;
856 #endif /* !defined(EXT_CODE_CROP) || defined(CONFIG_ACS) */
857
858 wpa_printf(MSG_INFO,
859 "Frequency %d (%s) not allowed for AP mode, flags: 0x%x%s%s",
860 frequency, primary ? "primary" : "secondary",
861 chan->flag,
862 chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
863 chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
864 return 0;
865 }
866
867
868 static int hostapd_is_usable_edmg(struct hostapd_iface *iface)
869 {
870 int i, contiguous = 0;
871 int num_of_enabled = 0;
872 int max_contiguous = 0;
873 struct ieee80211_edmg_config edmg;
874 struct hostapd_channel_data *pri_chan;
875
876 if (!iface->conf->enable_edmg)
877 return 1;
878
879 if (!iface->current_mode)
880 return 0;
881 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
882 iface->freq, NULL,
883 iface->hw_features,
884 iface->num_hw_features);
885 if (!pri_chan)
886 return 0;
887 hostapd_encode_edmg_chan(iface->conf->enable_edmg,
888 iface->conf->edmg_channel,
889 pri_chan->chan,
890 &edmg);
891 if (!(edmg.channels & BIT(pri_chan->chan - 1)))
892 return 0;
893
894 /* 60 GHz channels 1..6 */
895 for (i = 0; i < 6; i++) {
896 int freq = 56160 + 2160 * (i + 1);
897
898 if (edmg.channels & BIT(i)) {
899 contiguous++;
900 num_of_enabled++;
901 } else {
902 contiguous = 0;
903 continue;
904 }
905
906 /* P802.11ay defines that the total number of subfields
907 * set to one does not exceed 4.
908 */
909 if (num_of_enabled > 4)
910 return 0;
911
912 if (!hostapd_is_usable_chan(iface, freq, 1))
913 return 0;
914
915 if (contiguous > max_contiguous)
916 max_contiguous = contiguous;
917 }
918
919 /* Check if the EDMG configuration is valid under the limitations
920 * of P802.11ay.
921 */
922 /* check bw_config against contiguous EDMG channels */
923 switch (edmg.bw_config) {
924 case EDMG_BW_CONFIG_4:
925 if (!max_contiguous)
926 return 0;
927 break;
928 case EDMG_BW_CONFIG_5:
929 if (max_contiguous < 2)
930 return 0;
931 break;
932 default:
933 return 0;
934 }
935
936 return 1;
937 }
938
939
940 static int hostapd_is_usable_chans(struct hostapd_iface *iface)
941 {
942 int secondary_freq;
943 struct hostapd_channel_data *pri_chan;
944
945 if (!iface->current_mode)
946 return 0;
947 pri_chan = hw_get_channel_freq(iface->current_mode->mode,
948 iface->freq, NULL,
949 iface->hw_features,
950 iface->num_hw_features);
951 if (!pri_chan) {
952 wpa_printf(MSG_ERROR, "Primary frequency not present");
953 return 0;
954 }
955 #if !defined(EXT_CODE_CROP) || defined(CONFIG_ACS)
956 if (!hostapd_is_usable_chan(iface, pri_chan->freq, 1)) {
957 wpa_printf(MSG_ERROR, "Primary frequency not allowed");
958 return 0;
959 }
960 #endif /* EXT_CODE_CROP || CONFIG_ACS */
961 if (!hostapd_is_usable_edmg(iface))
962 return 0;
963 #ifndef EXT_CODE_CROP
964 if (!iface->conf->secondary_channel)
965 return 1;
966
967 if (hostapd_is_usable_chan(iface, iface->freq +
968 iface->conf->secondary_channel * 20, 0)) {
969 if (iface->conf->secondary_channel == 1 &&
970 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P))
971 return 1;
972 if (iface->conf->secondary_channel == -1 &&
973 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M))
974 return 1;
975 }
976 if (!iface->conf->ht40_plus_minus_allowed)
977 return 0;
978
979 /* Both HT40+ and HT40- are set, pick a valid secondary channel */
980 secondary_freq = iface->freq + 20;
981 if (hostapd_is_usable_chan(iface, secondary_freq, 0) &&
982 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) {
983 iface->conf->secondary_channel = 1;
984 return 1;
985 }
986
987 secondary_freq = iface->freq - 20;
988 if (hostapd_is_usable_chan(iface, secondary_freq, 0) &&
989 (pri_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M)) {
990 iface->conf->secondary_channel = -1;
991 return 1;
992 }
993
994 return 0;
995 #else
996 return 1;
997 #endif /* EXT_CODE_CROP */
998 }
999
1000
1001 static void hostapd_determine_mode(struct hostapd_iface *iface)
1002 {
1003 int i;
1004 enum hostapd_hw_mode target_mode;
1005
1006 if (iface->current_mode ||
1007 iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY)
1008 return;
1009
1010 if (iface->freq < 4000)
1011 target_mode = HOSTAPD_MODE_IEEE80211G;
1012 else if (iface->freq > 50000)
1013 target_mode = HOSTAPD_MODE_IEEE80211AD;
1014 else
1015 target_mode = HOSTAPD_MODE_IEEE80211A;
1016
1017 for (i = 0; i < iface->num_hw_features; i++) {
1018 struct hostapd_hw_modes *mode;
1019
1020 mode = &iface->hw_features[i];
1021 if (mode->mode == target_mode) {
1022 iface->current_mode = mode;
1023 iface->conf->hw_mode = mode->mode;
1024 break;
1025 }
1026 }
1027
1028 if (!iface->current_mode)
1029 wpa_printf(MSG_ERROR, "ACS: Cannot decide mode");
1030 }
1031
1032
1033 static enum hostapd_chan_status
1034 hostapd_check_chans(struct hostapd_iface *iface)
1035 {
1036 if (iface->freq) {
1037 hostapd_determine_mode(iface);
1038 if (hostapd_is_usable_chans(iface))
1039 return HOSTAPD_CHAN_VALID;
1040 #ifndef EXT_CODE_CROP
1041 else
1042 return HOSTAPD_CHAN_INVALID;
1043 #endif /* EXT_CODE_CROP */
1044 }
1045
1046 #if !defined(EXT_CODE_CROP) || defined(CONFIG_ACS)
1047 /*
1048 * The user set channel=0 or channel=acs_survey
1049 * which is used to trigger ACS.
1050 */
1051
1052 switch (acs_init(iface)) {
1053 case HOSTAPD_CHAN_ACS:
1054 return HOSTAPD_CHAN_ACS;
1055 case HOSTAPD_CHAN_VALID:
1056 case HOSTAPD_CHAN_INVALID:
1057 default:
1058 return HOSTAPD_CHAN_INVALID;
1059 }
1060 #else
1061 return HOSTAPD_CHAN_INVALID;
1062 #endif /* EXT_CODE_CROP */
1063 }
1064
1065
1066 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
1067 {
1068 if (!iface->current_mode) {
1069 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1070 HOSTAPD_LEVEL_WARNING,
1071 "Hardware does not support configured mode");
1072 return;
1073 }
1074 hostapd_logger(iface->bss[0], NULL,
1075 HOSTAPD_MODULE_IEEE80211,
1076 HOSTAPD_LEVEL_WARNING,
1077 "Configured channel (%d) or frequency (%d) (secondary_channel=%d) not found from the channel list of the current mode (%d) %s",
1078 iface->conf->channel,
1079 iface->freq, iface->conf->secondary_channel,
1080 iface->current_mode->mode,
1081 hostapd_hw_mode_txt(iface->current_mode->mode));
1082 hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
1083 HOSTAPD_LEVEL_WARNING,
1084 "Hardware does not support configured channel");
1085 }
1086
1087
1088 int hostapd_acs_completed(struct hostapd_iface *iface, int err)
1089 {
1090 int ret = -1;
1091
1092 if (err)
1093 goto out;
1094
1095 switch (hostapd_check_chans(iface)) {
1096 case HOSTAPD_CHAN_VALID:
1097 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO,
1098 ACS_EVENT_COMPLETED "freq=%d channel=%d",
1099 iface->freq, iface->conf->channel);
1100 break;
1101 case HOSTAPD_CHAN_ACS:
1102 wpa_error_log0(MSG_ERROR, "ACS error - reported complete, but no result available");
1103 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
1104 hostapd_notify_bad_chans(iface);
1105 goto out;
1106 case HOSTAPD_CHAN_INVALID:
1107 default:
1108 wpa_error_log0(MSG_ERROR, "ACS picked unusable channels");
1109 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
1110 hostapd_notify_bad_chans(iface);
1111 goto out;
1112 }
1113
1114 ret = hostapd_check_ht_capab(iface);
1115 if (ret < 0)
1116 goto out;
1117 if (ret == 1) {
1118 wpa_warning_log0(MSG_DEBUG, "Interface initialization will be completed in a callback");
1119 return 0;
1120 }
1121
1122 ret = 0;
1123 out:
1124 return hostapd_setup_interface_complete(iface, ret);
1125 }
1126
1127
1128 /**
1129 * hostapd_select_hw_mode - Select the hardware mode
1130 * @iface: Pointer to interface data.
1131 * Returns: 0 on success, < 0 on failure
1132 *
1133 * Sets up the hardware mode, channel, rates, and passive scanning
1134 * based on the configuration.
1135 */
1136 int hostapd_select_hw_mode(struct hostapd_iface *iface)
1137 {
1138 int i;
1139
1140 if (iface->num_hw_features < 1)
1141 return -1;
1142 #ifdef LOS_WPA_PATCH
1143 if (g_ap_opt_set.hw_mode != WIFI_MODE_UNDEFINE) {
1144 if (g_ap_opt_set.hw_mode == WIFI_MODE_11B) {
1145 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1146 iface->conf->ieee80211n = 0;
1147 } else if (g_ap_opt_set.hw_mode == WIFI_MODE_11B_G) {
1148 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1149 iface->conf->ieee80211n = 0;
1150 } else if (g_ap_opt_set.hw_mode == WIFI_MODE_11B_G_N) {
1151 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
1152 iface->conf->ieee80211n = 1;
1153 }
1154 }
1155 #endif /* LOS_WPA_PATCH */
1156
1157 if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
1158 #ifndef EXT_CODE_CROP
1159 iface->conf->ieee80211n || iface->conf->ieee80211ac ||
1160 iface->conf->ieee80211ax) &&
1161 #else
1162 iface->conf->ieee80211n ) &&
1163 #endif /* EXT_CODE_CROP */
1164 iface->conf->channel == 14) {
1165 wpa_warning_log0(MSG_INFO, "Enable OFDM/HT/VHT/HE on channel 14");
1166 #ifndef EXT_CODE_CROP
1167 iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
1168 iface->conf->ieee80211n = 0;
1169 iface->conf->ieee80211ac = 0;
1170 iface->conf->ieee80211ax = 0;
1171 #endif /* EXT_CODE_CROP */
1172 }
1173
1174 iface->current_mode = NULL;
1175 for (i = 0; i < iface->num_hw_features; i++) {
1176 struct hostapd_hw_modes *mode = &iface->hw_features[i];
1177 int chan;
1178
1179 if (mode->mode == iface->conf->hw_mode) {
1180 if (iface->freq > 0 &&
1181 !hw_mode_get_channel(mode, iface->freq, &chan))
1182 continue;
1183
1184 iface->current_mode = mode;
1185 break;
1186 }
1187 }
1188
1189 if (iface->current_mode == NULL) {
1190 if ((iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1191 (iface->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_HW_MODE_ANY)) {
1192 wpa_printf(MSG_DEBUG,
1193 "Using offloaded hw_mode=any ACS");
1194 } else if (!(iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
1195 iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211ANY) {
1196 wpa_printf(MSG_DEBUG,
1197 "Using internal ACS for hw_mode=any");
1198 } else {
1199 wpa_printf(MSG_ERROR,
1200 "Hardware does not support configured mode");
1201 hostapd_logger(iface->bss[0], NULL,
1202 HOSTAPD_MODULE_IEEE80211,
1203 HOSTAPD_LEVEL_WARNING,
1204 "Hardware does not support configured mode (%d) (hw_mode in hostapd.conf)",
1205 (int) iface->conf->hw_mode);
1206 return -2;
1207 }
1208 }
1209
1210 switch (hostapd_check_chans(iface)) {
1211 case HOSTAPD_CHAN_VALID:
1212 return 0;
1213 case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
1214 return 1;
1215 case HOSTAPD_CHAN_INVALID:
1216 default:
1217 hostapd_notify_bad_chans(iface);
1218 return -3;
1219 }
1220 }
1221
1222
1223 const char * hostapd_hw_mode_txt(int mode)
1224 {
1225 switch (mode) {
1226 #ifndef EXT_CODE_CROP
1227 case HOSTAPD_MODE_IEEE80211A:
1228 return "IEEE 802.11a";
1229 #endif /* EXT_CODE_CROP */
1230 case HOSTAPD_MODE_IEEE80211B:
1231 return "IEEE 802.11b";
1232 case HOSTAPD_MODE_IEEE80211G:
1233 return "IEEE 802.11g";
1234 #ifndef EXT_CODE_CROP
1235 case HOSTAPD_MODE_IEEE80211AD:
1236 return "IEEE 802.11ad";
1237 #endif /* EXT_CODE_CROP */
1238 default:
1239 return "UNKNOWN";
1240 }
1241 }
1242
1243
1244 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
1245 {
1246 return hw_get_freq(hapd->iface->current_mode, chan);
1247 }
1248
1249
1250 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
1251 {
1252 int i, channel;
1253 struct hostapd_hw_modes *mode;
1254
1255 if (hapd->iface->current_mode) {
1256 channel = hw_get_chan(hapd->iface->current_mode->mode, freq,
1257 hapd->iface->hw_features,
1258 hapd->iface->num_hw_features);
1259 if (channel)
1260 return channel;
1261 }
1262
1263 /* Check other available modes since the channel list for the current
1264 * mode did not include the specified frequency. */
1265 if (!hapd->iface->hw_features)
1266 return 0;
1267 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1268 mode = &hapd->iface->hw_features[i];
1269 channel = hw_get_chan(mode->mode, freq,
1270 hapd->iface->hw_features,
1271 hapd->iface->num_hw_features);
1272 if (channel)
1273 return channel;
1274 }
1275 return 0;
1276 }
1277
1278
1279 int hostapd_hw_skip_mode(struct hostapd_iface *iface,
1280 struct hostapd_hw_modes *mode)
1281 {
1282 int i;
1283
1284 if (iface->current_mode)
1285 return mode != iface->current_mode;
1286 if (mode->mode != HOSTAPD_MODE_IEEE80211B)
1287 return 0;
1288 for (i = 0; i < iface->num_hw_features; i++) {
1289 if (iface->hw_features[i].mode == HOSTAPD_MODE_IEEE80211G)
1290 return 1;
1291 }
1292 return 0;
1293 }
1294