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