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