xref: /freebsd/contrib/wpa/src/common/hw_features_common.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
15b9c547cSRui Paulo /*
25b9c547cSRui Paulo  * Common hostapd/wpa_supplicant HW features
35b9c547cSRui Paulo  * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
45b9c547cSRui Paulo  * Copyright (c) 2015, Qualcomm Atheros, Inc.
55b9c547cSRui Paulo  *
65b9c547cSRui Paulo  * This software may be distributed under the terms of the BSD license.
75b9c547cSRui Paulo  * See README for more details.
85b9c547cSRui Paulo  */
95b9c547cSRui Paulo 
105b9c547cSRui Paulo #include "includes.h"
115b9c547cSRui Paulo 
125b9c547cSRui Paulo #include "common.h"
135b9c547cSRui Paulo #include "defs.h"
145b9c547cSRui Paulo #include "ieee802_11_defs.h"
155b9c547cSRui Paulo #include "ieee802_11_common.h"
165b9c547cSRui Paulo #include "hw_features_common.h"
175b9c547cSRui Paulo 
185b9c547cSRui Paulo 
hw_get_channel_chan(struct hostapd_hw_modes * mode,int chan,int * freq)195b9c547cSRui Paulo struct hostapd_channel_data * hw_get_channel_chan(struct hostapd_hw_modes *mode,
205b9c547cSRui Paulo 						  int chan, int *freq)
215b9c547cSRui Paulo {
225b9c547cSRui Paulo 	int i;
235b9c547cSRui Paulo 
245b9c547cSRui Paulo 	if (freq)
255b9c547cSRui Paulo 		*freq = 0;
265b9c547cSRui Paulo 
275b9c547cSRui Paulo 	if (!mode)
285b9c547cSRui Paulo 		return NULL;
295b9c547cSRui Paulo 
305b9c547cSRui Paulo 	for (i = 0; i < mode->num_channels; i++) {
315b9c547cSRui Paulo 		struct hostapd_channel_data *ch = &mode->channels[i];
325b9c547cSRui Paulo 		if (ch->chan == chan) {
335b9c547cSRui Paulo 			if (freq)
345b9c547cSRui Paulo 				*freq = ch->freq;
355b9c547cSRui Paulo 			return ch;
365b9c547cSRui Paulo 		}
375b9c547cSRui Paulo 	}
385b9c547cSRui Paulo 
395b9c547cSRui Paulo 	return NULL;
405b9c547cSRui Paulo }
415b9c547cSRui Paulo 
425b9c547cSRui Paulo 
43c1d255d3SCy Schubert struct hostapd_channel_data *
hw_mode_get_channel(struct hostapd_hw_modes * mode,int freq,int * chan)44c1d255d3SCy Schubert hw_mode_get_channel(struct hostapd_hw_modes *mode, int freq, int *chan)
455b9c547cSRui Paulo {
465b9c547cSRui Paulo 	int i;
475b9c547cSRui Paulo 
485b9c547cSRui Paulo 	for (i = 0; i < mode->num_channels; i++) {
495b9c547cSRui Paulo 		struct hostapd_channel_data *ch = &mode->channels[i];
50c1d255d3SCy Schubert 
515b9c547cSRui Paulo 		if (ch->freq == freq) {
525b9c547cSRui Paulo 			if (chan)
535b9c547cSRui Paulo 				*chan = ch->chan;
545b9c547cSRui Paulo 			return ch;
555b9c547cSRui Paulo 		}
565b9c547cSRui Paulo 	}
575b9c547cSRui Paulo 
585b9c547cSRui Paulo 	return NULL;
595b9c547cSRui Paulo }
605b9c547cSRui Paulo 
615b9c547cSRui Paulo 
62c1d255d3SCy Schubert struct hostapd_channel_data *
hw_get_channel_freq(enum hostapd_hw_mode mode,int freq,int * chan,struct hostapd_hw_modes * hw_features,int num_hw_features)63c1d255d3SCy Schubert hw_get_channel_freq(enum hostapd_hw_mode mode, int freq, int *chan,
64c1d255d3SCy Schubert 		    struct hostapd_hw_modes *hw_features, int num_hw_features)
65c1d255d3SCy Schubert {
66c1d255d3SCy Schubert 	struct hostapd_channel_data *chan_data;
67c1d255d3SCy Schubert 	int i;
68c1d255d3SCy Schubert 
69c1d255d3SCy Schubert 	if (chan)
70c1d255d3SCy Schubert 		*chan = 0;
71c1d255d3SCy Schubert 
72c1d255d3SCy Schubert 	if (!hw_features)
73c1d255d3SCy Schubert 		return NULL;
74c1d255d3SCy Schubert 
75c1d255d3SCy Schubert 	for (i = 0; i < num_hw_features; i++) {
76c1d255d3SCy Schubert 		struct hostapd_hw_modes *curr_mode = &hw_features[i];
77c1d255d3SCy Schubert 
78c1d255d3SCy Schubert 		if (curr_mode->mode != mode)
79c1d255d3SCy Schubert 			continue;
80c1d255d3SCy Schubert 
81c1d255d3SCy Schubert 		chan_data = hw_mode_get_channel(curr_mode, freq, chan);
82c1d255d3SCy Schubert 		if (chan_data)
83c1d255d3SCy Schubert 			return chan_data;
84c1d255d3SCy Schubert 	}
85c1d255d3SCy Schubert 
86c1d255d3SCy Schubert 	return NULL;
87c1d255d3SCy Schubert }
88c1d255d3SCy Schubert 
89c1d255d3SCy Schubert 
hw_get_freq(struct hostapd_hw_modes * mode,int chan)905b9c547cSRui Paulo int hw_get_freq(struct hostapd_hw_modes *mode, int chan)
915b9c547cSRui Paulo {
925b9c547cSRui Paulo 	int freq;
935b9c547cSRui Paulo 
945b9c547cSRui Paulo 	hw_get_channel_chan(mode, chan, &freq);
955b9c547cSRui Paulo 
965b9c547cSRui Paulo 	return freq;
975b9c547cSRui Paulo }
985b9c547cSRui Paulo 
995b9c547cSRui Paulo 
hw_get_chan(enum hostapd_hw_mode mode,int freq,struct hostapd_hw_modes * hw_features,int num_hw_features)100c1d255d3SCy Schubert int hw_get_chan(enum hostapd_hw_mode mode, int freq,
101c1d255d3SCy Schubert 		struct hostapd_hw_modes *hw_features, int num_hw_features)
1025b9c547cSRui Paulo {
1035b9c547cSRui Paulo 	int chan;
1045b9c547cSRui Paulo 
105c1d255d3SCy Schubert 	hw_get_channel_freq(mode, freq, &chan, hw_features, num_hw_features);
1065b9c547cSRui Paulo 
1075b9c547cSRui Paulo 	return chan;
1085b9c547cSRui Paulo }
1095b9c547cSRui Paulo 
1105b9c547cSRui Paulo 
allowed_ht40_channel_pair(enum hostapd_hw_mode mode,struct hostapd_channel_data * p_chan,struct hostapd_channel_data * s_chan)111c1d255d3SCy Schubert int allowed_ht40_channel_pair(enum hostapd_hw_mode mode,
112c1d255d3SCy Schubert 			      struct hostapd_channel_data *p_chan,
113c1d255d3SCy Schubert 			      struct hostapd_channel_data *s_chan)
1145b9c547cSRui Paulo {
1154bc52338SCy Schubert 	int ok, first;
116325151a3SRui Paulo 	int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
1174b72b91aSCy Schubert 			  149, 157, 165, 173, 184, 192 };
1185b9c547cSRui Paulo 	size_t k;
119c1d255d3SCy Schubert 	int ht40_plus, pri_chan, sec_chan;
1205b9c547cSRui Paulo 
121c1d255d3SCy Schubert 	if (!p_chan || !s_chan)
1224bc52338SCy Schubert 		return 0;
123c1d255d3SCy Schubert 	pri_chan = p_chan->chan;
124c1d255d3SCy Schubert 	sec_chan = s_chan->chan;
125c1d255d3SCy Schubert 
126c1d255d3SCy Schubert 	ht40_plus = pri_chan < sec_chan;
1274bc52338SCy Schubert 
1284bc52338SCy Schubert 	if (pri_chan == sec_chan || !sec_chan) {
1294bc52338SCy Schubert 		if (chan_pri_allowed(p_chan))
1305b9c547cSRui Paulo 			return 1; /* HT40 not used */
1315b9c547cSRui Paulo 
1324bc52338SCy Schubert 		wpa_printf(MSG_ERROR, "Channel %d is not allowed as primary",
1334bc52338SCy Schubert 			   pri_chan);
1344bc52338SCy Schubert 		return 0;
1354bc52338SCy Schubert 	}
1364bc52338SCy Schubert 
1375b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG,
138c1d255d3SCy Schubert 		   "HT40: control channel: %d (%d MHz), secondary channel: %d (%d MHz)",
139c1d255d3SCy Schubert 		   pri_chan, p_chan->freq, sec_chan, s_chan->freq);
1405b9c547cSRui Paulo 
1415b9c547cSRui Paulo 	/* Verify that HT40 secondary channel is an allowed 20 MHz
1425b9c547cSRui Paulo 	 * channel */
1434bc52338SCy Schubert 	if ((s_chan->flag & HOSTAPD_CHAN_DISABLED) ||
1444bc52338SCy Schubert 	    (ht40_plus && !(p_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P)) ||
1454bc52338SCy Schubert 	    (!ht40_plus && !(p_chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40M))) {
1465b9c547cSRui Paulo 		wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
1475b9c547cSRui Paulo 			   sec_chan);
1485b9c547cSRui Paulo 		return 0;
1495b9c547cSRui Paulo 	}
1505b9c547cSRui Paulo 
1515b9c547cSRui Paulo 	/*
1525b9c547cSRui Paulo 	 * Verify that HT40 primary,secondary channel pair is allowed per
1535b9c547cSRui Paulo 	 * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
1545b9c547cSRui Paulo 	 * 2.4 GHz rules allow all cases where the secondary channel fits into
1555b9c547cSRui Paulo 	 * the list of allowed channels (already checked above).
1565b9c547cSRui Paulo 	 */
157c1d255d3SCy Schubert 	if (mode != HOSTAPD_MODE_IEEE80211A)
1585b9c547cSRui Paulo 		return 1;
1595b9c547cSRui Paulo 
1605b9c547cSRui Paulo 	first = pri_chan < sec_chan ? pri_chan : sec_chan;
1615b9c547cSRui Paulo 
1625b9c547cSRui Paulo 	ok = 0;
1635b9c547cSRui Paulo 	for (k = 0; k < ARRAY_SIZE(allowed); k++) {
1645b9c547cSRui Paulo 		if (first == allowed[k]) {
1655b9c547cSRui Paulo 			ok = 1;
1665b9c547cSRui Paulo 			break;
1675b9c547cSRui Paulo 		}
1685b9c547cSRui Paulo 	}
1695b9c547cSRui Paulo 	if (!ok) {
1705b9c547cSRui Paulo 		wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
1715b9c547cSRui Paulo 			   pri_chan, sec_chan);
1725b9c547cSRui Paulo 		return 0;
1735b9c547cSRui Paulo 	}
1745b9c547cSRui Paulo 
1755b9c547cSRui Paulo 	return 1;
1765b9c547cSRui Paulo }
1775b9c547cSRui Paulo 
1785b9c547cSRui Paulo 
get_pri_sec_chan(struct wpa_scan_res * bss,int * pri_chan,int * sec_chan)1795b9c547cSRui Paulo void get_pri_sec_chan(struct wpa_scan_res *bss, int *pri_chan, int *sec_chan)
1805b9c547cSRui Paulo {
1815b9c547cSRui Paulo 	struct ieee80211_ht_operation *oper;
1825b9c547cSRui Paulo 	struct ieee802_11_elems elems;
1835b9c547cSRui Paulo 
1845b9c547cSRui Paulo 	*pri_chan = *sec_chan = 0;
1855b9c547cSRui Paulo 
186*a90b9d01SCy Schubert 	if (ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0) !=
187*a90b9d01SCy Schubert 	    ParseFailed && elems.ht_operation) {
1885b9c547cSRui Paulo 		oper = (struct ieee80211_ht_operation *) elems.ht_operation;
1895b9c547cSRui Paulo 		*pri_chan = oper->primary_chan;
1905b9c547cSRui Paulo 		if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
1915b9c547cSRui Paulo 			int sec = oper->ht_param &
1925b9c547cSRui Paulo 				HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
1935b9c547cSRui Paulo 			if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
1945b9c547cSRui Paulo 				*sec_chan = *pri_chan + 4;
1955b9c547cSRui Paulo 			else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
1965b9c547cSRui Paulo 				*sec_chan = *pri_chan - 4;
1975b9c547cSRui Paulo 		}
1985b9c547cSRui Paulo 	}
1995b9c547cSRui Paulo }
2005b9c547cSRui Paulo 
2015b9c547cSRui Paulo 
check_40mhz_5g(struct wpa_scan_results * scan_res,struct hostapd_channel_data * pri_chan,struct hostapd_channel_data * sec_chan)202c1d255d3SCy Schubert int check_40mhz_5g(struct wpa_scan_results *scan_res,
203c1d255d3SCy Schubert 		   struct hostapd_channel_data *pri_chan,
204c1d255d3SCy Schubert 		   struct hostapd_channel_data *sec_chan)
2055b9c547cSRui Paulo {
206c1d255d3SCy Schubert 	int pri_bss, sec_bss;
2075b9c547cSRui Paulo 	int bss_pri_chan, bss_sec_chan;
2085b9c547cSRui Paulo 	size_t i;
2095b9c547cSRui Paulo 	int match;
2105b9c547cSRui Paulo 
211c1d255d3SCy Schubert 	if (!scan_res || !pri_chan || !sec_chan ||
212c1d255d3SCy Schubert 	    pri_chan->freq == sec_chan->freq)
2135b9c547cSRui Paulo 		return 0;
2145b9c547cSRui Paulo 
2155b9c547cSRui Paulo 	/*
2165b9c547cSRui Paulo 	 * Switch PRI/SEC channels if Beacons were detected on selected SEC
2175b9c547cSRui Paulo 	 * channel, but not on selected PRI channel.
2185b9c547cSRui Paulo 	 */
2195b9c547cSRui Paulo 	pri_bss = sec_bss = 0;
2205b9c547cSRui Paulo 	for (i = 0; i < scan_res->num; i++) {
2215b9c547cSRui Paulo 		struct wpa_scan_res *bss = scan_res->res[i];
222c1d255d3SCy Schubert 		if (bss->freq == pri_chan->freq)
2235b9c547cSRui Paulo 			pri_bss++;
224c1d255d3SCy Schubert 		else if (bss->freq == sec_chan->freq)
2255b9c547cSRui Paulo 			sec_bss++;
2265b9c547cSRui Paulo 	}
2275b9c547cSRui Paulo 	if (sec_bss && !pri_bss) {
2285b9c547cSRui Paulo 		wpa_printf(MSG_INFO,
2295b9c547cSRui Paulo 			   "Switch own primary and secondary channel to get secondary channel with no Beacons from other BSSes");
2305b9c547cSRui Paulo 		return 2;
2315b9c547cSRui Paulo 	}
2325b9c547cSRui Paulo 
2335b9c547cSRui Paulo 	/*
2345b9c547cSRui Paulo 	 * Match PRI/SEC channel with any existing HT40 BSS on the same
2355b9c547cSRui Paulo 	 * channels that we are about to use (if already mixed order in
2365b9c547cSRui Paulo 	 * existing BSSes, use own preference).
2375b9c547cSRui Paulo 	 */
2385b9c547cSRui Paulo 	match = 0;
2395b9c547cSRui Paulo 	for (i = 0; i < scan_res->num; i++) {
2405b9c547cSRui Paulo 		struct wpa_scan_res *bss = scan_res->res[i];
2415b9c547cSRui Paulo 		get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
242c1d255d3SCy Schubert 		if (pri_chan->chan == bss_pri_chan &&
243c1d255d3SCy Schubert 		    sec_chan->chan == bss_sec_chan) {
2445b9c547cSRui Paulo 			match = 1;
2455b9c547cSRui Paulo 			break;
2465b9c547cSRui Paulo 		}
2475b9c547cSRui Paulo 	}
2485b9c547cSRui Paulo 	if (!match) {
2495b9c547cSRui Paulo 		for (i = 0; i < scan_res->num; i++) {
2505b9c547cSRui Paulo 			struct wpa_scan_res *bss = scan_res->res[i];
2515b9c547cSRui Paulo 			get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
252c1d255d3SCy Schubert 			if (pri_chan->chan == bss_sec_chan &&
253c1d255d3SCy Schubert 			    sec_chan->chan == bss_pri_chan) {
2545b9c547cSRui Paulo 				wpa_printf(MSG_INFO, "Switch own primary and "
2555b9c547cSRui Paulo 					   "secondary channel due to BSS "
2565b9c547cSRui Paulo 					   "overlap with " MACSTR,
2575b9c547cSRui Paulo 					   MAC2STR(bss->bssid));
2585b9c547cSRui Paulo 				return 2;
2595b9c547cSRui Paulo 			}
2605b9c547cSRui Paulo 		}
2615b9c547cSRui Paulo 	}
2625b9c547cSRui Paulo 
2635b9c547cSRui Paulo 	return 1;
2645b9c547cSRui Paulo }
2655b9c547cSRui Paulo 
2665b9c547cSRui Paulo 
check_20mhz_bss(struct wpa_scan_res * bss,int pri_freq,int start,int end)267325151a3SRui Paulo static int check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq, int start,
268325151a3SRui Paulo 			   int end)
2695b9c547cSRui Paulo {
2705b9c547cSRui Paulo 	struct ieee802_11_elems elems;
2715b9c547cSRui Paulo 	struct ieee80211_ht_operation *oper;
2725b9c547cSRui Paulo 
2735b9c547cSRui Paulo 	if (bss->freq < start || bss->freq > end || bss->freq == pri_freq)
2745b9c547cSRui Paulo 		return 0;
2755b9c547cSRui Paulo 
276*a90b9d01SCy Schubert 	if (ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0) ==
277*a90b9d01SCy Schubert 	    ParseFailed)
278*a90b9d01SCy Schubert 		return 0;
279*a90b9d01SCy Schubert 
2805b9c547cSRui Paulo 	if (!elems.ht_capabilities) {
2815b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "Found overlapping legacy BSS: "
2825b9c547cSRui Paulo 			   MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
2835b9c547cSRui Paulo 		return 1;
2845b9c547cSRui Paulo 	}
2855b9c547cSRui Paulo 
286325151a3SRui Paulo 	if (elems.ht_operation) {
2875b9c547cSRui Paulo 		oper = (struct ieee80211_ht_operation *) elems.ht_operation;
2885b9c547cSRui Paulo 		if (oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)
2895b9c547cSRui Paulo 			return 0;
2905b9c547cSRui Paulo 
2915b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "Found overlapping 20 MHz HT BSS: "
2925b9c547cSRui Paulo 			   MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
2935b9c547cSRui Paulo 		return 1;
2945b9c547cSRui Paulo 	}
2955b9c547cSRui Paulo 	return 0;
2965b9c547cSRui Paulo }
2975b9c547cSRui Paulo 
2985b9c547cSRui Paulo 
check_40mhz_2g4(struct hostapd_hw_modes * mode,struct wpa_scan_results * scan_res,int pri_chan,int sec_chan)29932a95656SCy Schubert int check_40mhz_2g4(struct hostapd_hw_modes *mode,
30032a95656SCy Schubert 		    struct wpa_scan_results *scan_res, int pri_chan,
30132a95656SCy Schubert 		    int sec_chan)
3025b9c547cSRui Paulo {
30332a95656SCy Schubert 	int pri_freq, sec_freq;
3045b9c547cSRui Paulo 	int affected_start, affected_end;
30532a95656SCy Schubert 	size_t i;
3065b9c547cSRui Paulo 
30732a95656SCy Schubert 	if (!mode || !scan_res || !pri_chan || !sec_chan ||
30832a95656SCy Schubert 	    pri_chan == sec_chan)
30932a95656SCy Schubert 		return 0;
31032a95656SCy Schubert 
31132a95656SCy Schubert 	pri_freq = hw_get_freq(mode, pri_chan);
31232a95656SCy Schubert 	sec_freq = hw_get_freq(mode, sec_chan);
3135b9c547cSRui Paulo 
3145b9c547cSRui Paulo 	affected_start = (pri_freq + sec_freq) / 2 - 25;
3155b9c547cSRui Paulo 	affected_end = (pri_freq + sec_freq) / 2 + 25;
31632a95656SCy Schubert 	wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
31732a95656SCy Schubert 		   affected_start, affected_end);
31832a95656SCy Schubert 	for (i = 0; i < scan_res->num; i++) {
31932a95656SCy Schubert 		struct wpa_scan_res *bss = scan_res->res[i];
32032a95656SCy Schubert 		int pri = bss->freq;
32132a95656SCy Schubert 		int sec = pri;
32232a95656SCy Schubert 		struct ieee802_11_elems elems;
3235b9c547cSRui Paulo 
3245b9c547cSRui Paulo 		/* Check for overlapping 20 MHz BSS */
32532a95656SCy Schubert 		if (check_20mhz_bss(bss, pri_freq, affected_start,
32632a95656SCy Schubert 				    affected_end)) {
32732a95656SCy Schubert 			wpa_printf(MSG_DEBUG,
32832a95656SCy Schubert 				   "Overlapping 20 MHz BSS is found");
32932a95656SCy Schubert 			return 0;
3305b9c547cSRui Paulo 		}
3315b9c547cSRui Paulo 
3325b9c547cSRui Paulo 		get_pri_sec_chan(bss, &pri_chan, &sec_chan);
3335b9c547cSRui Paulo 
3345b9c547cSRui Paulo 		if (sec_chan) {
3355b9c547cSRui Paulo 			if (sec_chan < pri_chan)
3365b9c547cSRui Paulo 				sec = pri - 20;
3375b9c547cSRui Paulo 			else
3385b9c547cSRui Paulo 				sec = pri + 20;
3395b9c547cSRui Paulo 		}
3405b9c547cSRui Paulo 
3415b9c547cSRui Paulo 		if ((pri < affected_start || pri > affected_end) &&
3425b9c547cSRui Paulo 		    (sec < affected_start || sec > affected_end))
34332a95656SCy Schubert 			continue; /* not within affected channel range */
3445b9c547cSRui Paulo 
3455b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
3465b9c547cSRui Paulo 			   " freq=%d pri=%d sec=%d",
3475b9c547cSRui Paulo 			   MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
3485b9c547cSRui Paulo 
3495b9c547cSRui Paulo 		if (sec_chan) {
3505b9c547cSRui Paulo 			if (pri_freq != pri || sec_freq != sec) {
3515b9c547cSRui Paulo 				wpa_printf(MSG_DEBUG,
3525b9c547cSRui Paulo 					   "40 MHz pri/sec mismatch with BSS "
3535b9c547cSRui Paulo 					   MACSTR
3545b9c547cSRui Paulo 					   " <%d,%d> (chan=%d%c) vs. <%d,%d>",
3555b9c547cSRui Paulo 					   MAC2STR(bss->bssid),
3565b9c547cSRui Paulo 					   pri, sec, pri_chan,
3575b9c547cSRui Paulo 					   sec > pri ? '+' : '-',
3585b9c547cSRui Paulo 					   pri_freq, sec_freq);
35932a95656SCy Schubert 				return 0;
3605b9c547cSRui Paulo 			}
3615b9c547cSRui Paulo 		}
3625b9c547cSRui Paulo 
363*a90b9d01SCy Schubert 		if (ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len,
364*a90b9d01SCy Schubert 					   &elems, 0) != ParseFailed &&
365*a90b9d01SCy Schubert 		    elems.ht_capabilities) {
3665b9c547cSRui Paulo 			struct ieee80211_ht_capabilities *ht_cap =
3675b9c547cSRui Paulo 				(struct ieee80211_ht_capabilities *)
3685b9c547cSRui Paulo 				elems.ht_capabilities;
3695b9c547cSRui Paulo 
3705b9c547cSRui Paulo 			if (le_to_host16(ht_cap->ht_capabilities_info) &
3715b9c547cSRui Paulo 			    HT_CAP_INFO_40MHZ_INTOLERANT) {
3725b9c547cSRui Paulo 				wpa_printf(MSG_DEBUG,
3735b9c547cSRui Paulo 					   "40 MHz Intolerant is set on channel %d in BSS "
3745b9c547cSRui Paulo 					   MACSTR, pri, MAC2STR(bss->bssid));
3755b9c547cSRui Paulo 				return 0;
3765b9c547cSRui Paulo 			}
37732a95656SCy Schubert 		}
3785b9c547cSRui Paulo 	}
3795b9c547cSRui Paulo 
3805b9c547cSRui Paulo 	return 1;
3815b9c547cSRui Paulo }
3825b9c547cSRui Paulo 
3835b9c547cSRui Paulo 
punct_update_legacy_bw_80(u8 bitmap,u8 pri_chan,u8 * seg0)384*a90b9d01SCy Schubert static void punct_update_legacy_bw_80(u8 bitmap, u8 pri_chan, u8 *seg0)
385*a90b9d01SCy Schubert {
386*a90b9d01SCy Schubert 	u8 first_chan = *seg0 - 6, sec_chan;
387*a90b9d01SCy Schubert 
388*a90b9d01SCy Schubert 	switch (bitmap) {
389*a90b9d01SCy Schubert 	case 0x6:
390*a90b9d01SCy Schubert 		*seg0 = 0;
391*a90b9d01SCy Schubert 		return;
392*a90b9d01SCy Schubert 	case 0x8:
393*a90b9d01SCy Schubert 	case 0x4:
394*a90b9d01SCy Schubert 	case 0x2:
395*a90b9d01SCy Schubert 	case 0x1:
396*a90b9d01SCy Schubert 	case 0xC:
397*a90b9d01SCy Schubert 	case 0x3:
398*a90b9d01SCy Schubert 		if (pri_chan < *seg0)
399*a90b9d01SCy Schubert 			*seg0 -= 4;
400*a90b9d01SCy Schubert 		else
401*a90b9d01SCy Schubert 			*seg0 += 4;
402*a90b9d01SCy Schubert 		break;
403*a90b9d01SCy Schubert 	}
404*a90b9d01SCy Schubert 
405*a90b9d01SCy Schubert 	if (pri_chan < *seg0)
406*a90b9d01SCy Schubert 		sec_chan = pri_chan + 4;
407*a90b9d01SCy Schubert 	else
408*a90b9d01SCy Schubert 		sec_chan = pri_chan - 4;
409*a90b9d01SCy Schubert 
410*a90b9d01SCy Schubert 	if (bitmap & BIT((sec_chan - first_chan) / 4))
411*a90b9d01SCy Schubert 		*seg0 = 0;
412*a90b9d01SCy Schubert }
413*a90b9d01SCy Schubert 
414*a90b9d01SCy Schubert 
punct_update_legacy_bw_160(u8 bitmap,u8 pri,enum oper_chan_width * width,u8 * seg0)415*a90b9d01SCy Schubert static void punct_update_legacy_bw_160(u8 bitmap, u8 pri,
416*a90b9d01SCy Schubert 				       enum oper_chan_width *width, u8 *seg0)
417*a90b9d01SCy Schubert {
418*a90b9d01SCy Schubert 	if (pri < *seg0) {
419*a90b9d01SCy Schubert 		*seg0 -= 8;
420*a90b9d01SCy Schubert 		if (bitmap & 0x0F) {
421*a90b9d01SCy Schubert 			*width = 0;
422*a90b9d01SCy Schubert 			punct_update_legacy_bw_80(bitmap & 0xF, pri, seg0);
423*a90b9d01SCy Schubert 		}
424*a90b9d01SCy Schubert 	} else {
425*a90b9d01SCy Schubert 		*seg0 += 8;
426*a90b9d01SCy Schubert 		if (bitmap & 0xF0) {
427*a90b9d01SCy Schubert 			*width = 0;
428*a90b9d01SCy Schubert 			punct_update_legacy_bw_80((bitmap & 0xF0) >> 4, pri,
429*a90b9d01SCy Schubert 						  seg0);
430*a90b9d01SCy Schubert 		}
431*a90b9d01SCy Schubert 	}
432*a90b9d01SCy Schubert }
433*a90b9d01SCy Schubert 
434*a90b9d01SCy Schubert 
punct_update_legacy_bw(u16 bitmap,u8 pri,enum oper_chan_width * width,u8 * seg0,u8 * seg1)435*a90b9d01SCy Schubert void punct_update_legacy_bw(u16 bitmap, u8 pri, enum oper_chan_width *width,
436*a90b9d01SCy Schubert 			    u8 *seg0, u8 *seg1)
437*a90b9d01SCy Schubert {
438*a90b9d01SCy Schubert 	if (*width == CONF_OPER_CHWIDTH_80MHZ && (bitmap & 0xF)) {
439*a90b9d01SCy Schubert 		*width = CONF_OPER_CHWIDTH_USE_HT;
440*a90b9d01SCy Schubert 		punct_update_legacy_bw_80(bitmap & 0xF, pri, seg0);
441*a90b9d01SCy Schubert 	}
442*a90b9d01SCy Schubert 
443*a90b9d01SCy Schubert 	if (*width == CONF_OPER_CHWIDTH_160MHZ && (bitmap & 0xFF)) {
444*a90b9d01SCy Schubert 		*width = CONF_OPER_CHWIDTH_80MHZ;
445*a90b9d01SCy Schubert 		*seg1 = 0;
446*a90b9d01SCy Schubert 		punct_update_legacy_bw_160(bitmap & 0xFF, pri, width, seg0);
447*a90b9d01SCy Schubert 	}
448*a90b9d01SCy Schubert 
449*a90b9d01SCy Schubert 	/* TODO: 320 MHz */
450*a90b9d01SCy Schubert }
451*a90b9d01SCy Schubert 
452*a90b9d01SCy Schubert 
hostapd_set_freq_params(struct hostapd_freq_params * data,enum hostapd_hw_mode mode,int freq,int channel,int enable_edmg,u8 edmg_channel,int ht_enabled,int vht_enabled,int he_enabled,bool eht_enabled,int sec_channel_offset,enum oper_chan_width oper_chwidth,int center_segment0,int center_segment1,u32 vht_caps,struct he_capabilities * he_cap,struct eht_capabilities * eht_cap,u16 punct_bitmap)4535b9c547cSRui Paulo int hostapd_set_freq_params(struct hostapd_freq_params *data,
4545b9c547cSRui Paulo 			    enum hostapd_hw_mode mode,
455c1d255d3SCy Schubert 			    int freq, int channel, int enable_edmg,
456c1d255d3SCy Schubert 			    u8 edmg_channel, int ht_enabled,
457206b73d0SCy Schubert 			    int vht_enabled, int he_enabled,
458*a90b9d01SCy Schubert 			    bool eht_enabled, int sec_channel_offset,
459*a90b9d01SCy Schubert 			    enum oper_chan_width oper_chwidth,
460*a90b9d01SCy Schubert 			    int center_segment0,
461206b73d0SCy Schubert 			    int center_segment1, u32 vht_caps,
462*a90b9d01SCy Schubert 			    struct he_capabilities *he_cap,
463*a90b9d01SCy Schubert 			    struct eht_capabilities *eht_cap,
464*a90b9d01SCy Schubert 			    u16 punct_bitmap)
4655b9c547cSRui Paulo {
466*a90b9d01SCy Schubert 	enum oper_chan_width oper_chwidth_legacy;
467*a90b9d01SCy Schubert 	u8 seg0_legacy, seg1_legacy;
468*a90b9d01SCy Schubert 
4694b72b91aSCy Schubert 	if (!he_cap || !he_cap->he_supported)
470206b73d0SCy Schubert 		he_enabled = 0;
471*a90b9d01SCy Schubert 	if (!eht_cap || !eht_cap->eht_supported)
472*a90b9d01SCy Schubert 		eht_enabled = 0;
4735b9c547cSRui Paulo 	os_memset(data, 0, sizeof(*data));
4745b9c547cSRui Paulo 	data->mode = mode;
4755b9c547cSRui Paulo 	data->freq = freq;
4765b9c547cSRui Paulo 	data->channel = channel;
4775b9c547cSRui Paulo 	data->ht_enabled = ht_enabled;
4785b9c547cSRui Paulo 	data->vht_enabled = vht_enabled;
479206b73d0SCy Schubert 	data->he_enabled = he_enabled;
480*a90b9d01SCy Schubert 	data->eht_enabled = eht_enabled;
4815b9c547cSRui Paulo 	data->sec_channel_offset = sec_channel_offset;
4825b9c547cSRui Paulo 	data->center_freq1 = freq + sec_channel_offset * 10;
4835b9c547cSRui Paulo 	data->center_freq2 = 0;
484*a90b9d01SCy Schubert 	if (oper_chwidth == CONF_OPER_CHWIDTH_80MHZ)
4854b72b91aSCy Schubert 		data->bandwidth = 80;
486*a90b9d01SCy Schubert 	else if (oper_chwidth == CONF_OPER_CHWIDTH_160MHZ ||
487*a90b9d01SCy Schubert 		 oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
4884b72b91aSCy Schubert 		data->bandwidth = 160;
489*a90b9d01SCy Schubert 	else if (oper_chwidth == CONF_OPER_CHWIDTH_320MHZ)
490*a90b9d01SCy Schubert 		data->bandwidth = 320;
4914b72b91aSCy Schubert 	else if (sec_channel_offset)
4924b72b91aSCy Schubert 		data->bandwidth = 40;
4934b72b91aSCy Schubert 	else
4944b72b91aSCy Schubert 		data->bandwidth = 20;
4954b72b91aSCy Schubert 
4965b9c547cSRui Paulo 
497c1d255d3SCy Schubert 	hostapd_encode_edmg_chan(enable_edmg, edmg_channel, channel,
498c1d255d3SCy Schubert 				 &data->edmg);
499c1d255d3SCy Schubert 
500c1d255d3SCy Schubert 	if (is_6ghz_freq(freq)) {
501*a90b9d01SCy Schubert 		if (!data->he_enabled && !data->eht_enabled) {
502c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
503*a90b9d01SCy Schubert 				   "Can't set 6 GHz mode - HE or EHT aren't enabled");
5045b9c547cSRui Paulo 			return -1;
505c1d255d3SCy Schubert 		}
506c1d255d3SCy Schubert 
507c1d255d3SCy Schubert 		if (center_idx_to_bw_6ghz(channel) < 0) {
508c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
509c1d255d3SCy Schubert 				   "Invalid control channel for 6 GHz band");
510c1d255d3SCy Schubert 			return -1;
511c1d255d3SCy Schubert 		}
512c1d255d3SCy Schubert 
513c1d255d3SCy Schubert 		if (!center_segment0) {
514c1d255d3SCy Schubert 			if (center_segment1) {
515c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
516c1d255d3SCy Schubert 					   "Segment 0 center frequency isn't set");
517c1d255d3SCy Schubert 				return -1;
518c1d255d3SCy Schubert 			}
5194b72b91aSCy Schubert 			if (!sec_channel_offset)
520c1d255d3SCy Schubert 				data->center_freq1 = data->freq;
521c1d255d3SCy Schubert 		} else {
522c1d255d3SCy Schubert 			int freq1, freq2 = 0;
523c1d255d3SCy Schubert 			int bw = center_idx_to_bw_6ghz(center_segment0);
524*a90b9d01SCy Schubert 			int opclass;
525c1d255d3SCy Schubert 
526c1d255d3SCy Schubert 			if (bw < 0) {
527c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
528c1d255d3SCy Schubert 					   "Invalid center frequency index for 6 GHz");
529c1d255d3SCy Schubert 				return -1;
530c1d255d3SCy Schubert 			}
531c1d255d3SCy Schubert 
532*a90b9d01SCy Schubert 			/* The 6 GHz channel 2 uses a different operating class
533*a90b9d01SCy Schubert 			 */
534*a90b9d01SCy Schubert 			opclass = center_segment0 == 2 ? 136 : 131;
535*a90b9d01SCy Schubert 			freq1 = ieee80211_chan_to_freq(NULL, opclass,
536c1d255d3SCy Schubert 						       center_segment0);
537c1d255d3SCy Schubert 			if (freq1 < 0) {
538c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
539c1d255d3SCy Schubert 					   "Invalid segment 0 center frequency for 6 GHz");
540c1d255d3SCy Schubert 				return -1;
541c1d255d3SCy Schubert 			}
542c1d255d3SCy Schubert 
543c1d255d3SCy Schubert 			if (center_segment1) {
544c1d255d3SCy Schubert 				if (center_idx_to_bw_6ghz(center_segment1) != 2 ||
545c1d255d3SCy Schubert 				    bw != 2) {
546c1d255d3SCy Schubert 					wpa_printf(MSG_ERROR,
547c1d255d3SCy Schubert 						   "6 GHz 80+80 MHz configuration doesn't use valid 80 MHz channels");
548c1d255d3SCy Schubert 					return -1;
549c1d255d3SCy Schubert 				}
550c1d255d3SCy Schubert 
551c1d255d3SCy Schubert 				freq2 = ieee80211_chan_to_freq(NULL, 131,
552c1d255d3SCy Schubert 							       center_segment1);
553c1d255d3SCy Schubert 				if (freq2 < 0) {
554c1d255d3SCy Schubert 					wpa_printf(MSG_ERROR,
555c1d255d3SCy Schubert 						   "Invalid segment 1 center frequency for UHB");
556c1d255d3SCy Schubert 					return -1;
557c1d255d3SCy Schubert 				}
558c1d255d3SCy Schubert 			}
559c1d255d3SCy Schubert 
560c1d255d3SCy Schubert 			data->bandwidth = (1 << (u8) bw) * 20;
561c1d255d3SCy Schubert 			data->center_freq1 = freq1;
562c1d255d3SCy Schubert 			data->center_freq2 = freq2;
563c1d255d3SCy Schubert 		}
564c1d255d3SCy Schubert 		data->ht_enabled = 0;
565c1d255d3SCy Schubert 		data->vht_enabled = 0;
566c1d255d3SCy Schubert 
567c1d255d3SCy Schubert 		return 0;
568c1d255d3SCy Schubert 	}
569c1d255d3SCy Schubert 
570*a90b9d01SCy Schubert 	if (data->eht_enabled) switch (oper_chwidth) {
571*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_320MHZ:
572*a90b9d01SCy Schubert 		if (!(eht_cap->phy_cap[EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_IDX] &
573*a90b9d01SCy Schubert 		      EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_MASK)) {
574*a90b9d01SCy Schubert 			wpa_printf(MSG_ERROR,
575*a90b9d01SCy Schubert 				   "320 MHz channel width is not supported in 5 or 6 GHz");
576*a90b9d01SCy Schubert 			return -1;
577*a90b9d01SCy Schubert 		}
578*a90b9d01SCy Schubert 		break;
579*a90b9d01SCy Schubert 	default:
580*a90b9d01SCy Schubert 		break;
581*a90b9d01SCy Schubert 	}
582*a90b9d01SCy Schubert 
583*a90b9d01SCy Schubert 	if (data->he_enabled || data->eht_enabled) switch (oper_chwidth) {
584*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_USE_HT:
5854b72b91aSCy Schubert 		if (sec_channel_offset == 0)
5864b72b91aSCy Schubert 			break;
5874b72b91aSCy Schubert 
5884b72b91aSCy Schubert 		if (mode == HOSTAPD_MODE_IEEE80211G) {
589*a90b9d01SCy Schubert 			if (he_cap &&
590*a90b9d01SCy Schubert 			    !(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
591c1d255d3SCy Schubert 			      HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_IN_2G)) {
592c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
593c1d255d3SCy Schubert 					   "40 MHz channel width is not supported in 2.4 GHz");
594c1d255d3SCy Schubert 				return -1;
595c1d255d3SCy Schubert 			}
596c1d255d3SCy Schubert 			break;
597c1d255d3SCy Schubert 		}
598c1d255d3SCy Schubert 		/* fall through */
599*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80MHZ:
600c1d255d3SCy Schubert 		if (mode == HOSTAPD_MODE_IEEE80211A) {
601*a90b9d01SCy Schubert 			if (he_cap &&
602*a90b9d01SCy Schubert 			    !(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
603c1d255d3SCy Schubert 			      HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) {
604c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
605c1d255d3SCy Schubert 					   "40/80 MHz channel width is not supported in 5/6 GHz");
606c1d255d3SCy Schubert 				return -1;
607c1d255d3SCy Schubert 			}
608c1d255d3SCy Schubert 		}
609c1d255d3SCy Schubert 		break;
610*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80P80MHZ:
611*a90b9d01SCy Schubert 		if (he_cap &&
612*a90b9d01SCy Schubert 		    !(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
613c1d255d3SCy Schubert 		      HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G)) {
614c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
615c1d255d3SCy Schubert 				   "80+80 MHz channel width is not supported in 5/6 GHz");
616c1d255d3SCy Schubert 			return -1;
617c1d255d3SCy Schubert 		}
618c1d255d3SCy Schubert 		break;
619*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_160MHZ:
620*a90b9d01SCy Schubert 		if (he_cap &&
621*a90b9d01SCy Schubert 		    !(he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
622c1d255d3SCy Schubert 		      HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) {
623c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
624c1d255d3SCy Schubert 				   "160 MHz channel width is not supported in 5 / 6GHz");
625c1d255d3SCy Schubert 			return -1;
626c1d255d3SCy Schubert 		}
627c1d255d3SCy Schubert 		break;
628*a90b9d01SCy Schubert 	default:
6295b9c547cSRui Paulo 		break;
630*a90b9d01SCy Schubert 	} else if (data->vht_enabled) switch (oper_chwidth) {
631*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_USE_HT:
632*a90b9d01SCy Schubert 		break;
633*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80P80MHZ:
6345b9c547cSRui Paulo 		if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) {
6355b9c547cSRui Paulo 			wpa_printf(MSG_ERROR,
6365b9c547cSRui Paulo 				   "80+80 channel width is not supported!");
6375b9c547cSRui Paulo 			return -1;
6385b9c547cSRui Paulo 		}
639c1d255d3SCy Schubert 		/* fall through */
640*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80MHZ:
641c1d255d3SCy Schubert 		break;
642*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_160MHZ:
643c1d255d3SCy Schubert 		if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
644c1d255d3SCy Schubert 				  VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
645c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
646c1d255d3SCy Schubert 				   "160 MHz channel width is not supported!");
6475b9c547cSRui Paulo 			return -1;
648c1d255d3SCy Schubert 		}
649c1d255d3SCy Schubert 		break;
650*a90b9d01SCy Schubert 	default:
651*a90b9d01SCy Schubert 		break;
652c1d255d3SCy Schubert 	}
653c1d255d3SCy Schubert 
654*a90b9d01SCy Schubert 	oper_chwidth_legacy = oper_chwidth;
655*a90b9d01SCy Schubert 	seg0_legacy = center_segment0;
656*a90b9d01SCy Schubert 	seg1_legacy = center_segment1;
657*a90b9d01SCy Schubert 	if (punct_bitmap)
658*a90b9d01SCy Schubert 		punct_update_legacy_bw(punct_bitmap, channel,
659*a90b9d01SCy Schubert 				       &oper_chwidth_legacy,
660*a90b9d01SCy Schubert 				       &seg0_legacy, &seg1_legacy);
661*a90b9d01SCy Schubert 
662*a90b9d01SCy Schubert 	if (data->eht_enabled || data->he_enabled ||
663*a90b9d01SCy Schubert 	    data->vht_enabled) switch (oper_chwidth) {
664*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_USE_HT:
665c1d255d3SCy Schubert 		if (center_segment1 ||
666c1d255d3SCy Schubert 		    (center_segment0 != 0 &&
667c1d255d3SCy Schubert 		     5000 + center_segment0 * 5 != data->center_freq1 &&
668c1d255d3SCy Schubert 		     2407 + center_segment0 * 5 != data->center_freq1)) {
669c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
670c1d255d3SCy Schubert 				   "20/40 MHz: center segment 0 (=%d) and center freq 1 (=%d) not in sync",
671c1d255d3SCy Schubert 				   center_segment0, data->center_freq1);
672c1d255d3SCy Schubert 			return -1;
673c1d255d3SCy Schubert 		}
674c1d255d3SCy Schubert 		break;
675*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80P80MHZ:
676c1d255d3SCy Schubert 		if (center_segment1 == center_segment0 + 4 ||
677c1d255d3SCy Schubert 		    center_segment1 == center_segment0 - 4) {
678c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
679c1d255d3SCy Schubert 				   "80+80 MHz: center segment 1 only 20 MHz apart");
680c1d255d3SCy Schubert 			return -1;
681c1d255d3SCy Schubert 		}
6825b9c547cSRui Paulo 		data->center_freq2 = 5000 + center_segment1 * 5;
6835b9c547cSRui Paulo 		/* fall through */
684*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_80MHZ:
6855b9c547cSRui Paulo 		data->bandwidth = 80;
686*a90b9d01SCy Schubert 		if (!sec_channel_offset &&
687*a90b9d01SCy Schubert 		    oper_chwidth_legacy != CONF_OPER_CHWIDTH_USE_HT) {
688c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
689c1d255d3SCy Schubert 				   "80/80+80 MHz: no second channel offset");
6905b9c547cSRui Paulo 			return -1;
691c1d255d3SCy Schubert 		}
692*a90b9d01SCy Schubert 		if (oper_chwidth == CONF_OPER_CHWIDTH_80MHZ &&
693*a90b9d01SCy Schubert 		    center_segment1) {
694c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
695c1d255d3SCy Schubert 				   "80 MHz: center segment 1 configured");
696c1d255d3SCy Schubert 			return -1;
697c1d255d3SCy Schubert 		}
698*a90b9d01SCy Schubert 		if (oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ &&
699*a90b9d01SCy Schubert 		    !center_segment1) {
700c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
701c1d255d3SCy Schubert 				   "80+80 MHz: center segment 1 not configured");
702c1d255d3SCy Schubert 			return -1;
703c1d255d3SCy Schubert 		}
704325151a3SRui Paulo 		if (!center_segment0) {
705325151a3SRui Paulo 			if (channel <= 48)
706325151a3SRui Paulo 				center_segment0 = 42;
707325151a3SRui Paulo 			else if (channel <= 64)
708325151a3SRui Paulo 				center_segment0 = 58;
709325151a3SRui Paulo 			else if (channel <= 112)
710325151a3SRui Paulo 				center_segment0 = 106;
711325151a3SRui Paulo 			else if (channel <= 128)
712325151a3SRui Paulo 				center_segment0 = 122;
713325151a3SRui Paulo 			else if (channel <= 144)
714325151a3SRui Paulo 				center_segment0 = 138;
715325151a3SRui Paulo 			else if (channel <= 161)
716325151a3SRui Paulo 				center_segment0 = 155;
717c1d255d3SCy Schubert 			else if (channel <= 177)
718c1d255d3SCy Schubert 				center_segment0 = 171;
7195b9c547cSRui Paulo 			data->center_freq1 = 5000 + center_segment0 * 5;
720325151a3SRui Paulo 		} else {
721325151a3SRui Paulo 			/*
722325151a3SRui Paulo 			 * Note: HT/VHT config and params are coupled. Check if
723325151a3SRui Paulo 			 * HT40 channel band is in VHT80 Pri channel band
724325151a3SRui Paulo 			 * configuration.
725325151a3SRui Paulo 			 */
726325151a3SRui Paulo 			if (center_segment0 == channel + 6 ||
727325151a3SRui Paulo 			    center_segment0 == channel + 2 ||
728325151a3SRui Paulo 			    center_segment0 == channel - 2 ||
729325151a3SRui Paulo 			    center_segment0 == channel - 6)
730325151a3SRui Paulo 				data->center_freq1 = 5000 + center_segment0 * 5;
731c1d255d3SCy Schubert 			else {
732c1d255d3SCy Schubert 				wpa_printf(MSG_ERROR,
733c1d255d3SCy Schubert 					   "Wrong coupling between HT and VHT/HE channel setting");
734325151a3SRui Paulo 				return -1;
735325151a3SRui Paulo 			}
736c1d255d3SCy Schubert 		}
7375b9c547cSRui Paulo 		break;
738*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_160MHZ:
7395b9c547cSRui Paulo 		data->bandwidth = 160;
740c1d255d3SCy Schubert 		if (center_segment1) {
7415b9c547cSRui Paulo 			wpa_printf(MSG_ERROR,
742c1d255d3SCy Schubert 				   "160 MHz: center segment 1 should not be set");
7435b9c547cSRui Paulo 			return -1;
7445b9c547cSRui Paulo 		}
745*a90b9d01SCy Schubert 		if (!sec_channel_offset &&
746*a90b9d01SCy Schubert 		    oper_chwidth_legacy != CONF_OPER_CHWIDTH_USE_HT) {
747c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
748c1d255d3SCy Schubert 				   "160 MHz: second channel offset not set");
7495b9c547cSRui Paulo 			return -1;
750c1d255d3SCy Schubert 		}
751325151a3SRui Paulo 		/*
752325151a3SRui Paulo 		 * Note: HT/VHT config and params are coupled. Check if
753325151a3SRui Paulo 		 * HT40 channel band is in VHT160 channel band configuration.
754325151a3SRui Paulo 		 */
755325151a3SRui Paulo 		if (center_segment0 == channel + 14 ||
756325151a3SRui Paulo 		    center_segment0 == channel + 10 ||
757325151a3SRui Paulo 		    center_segment0 == channel + 6 ||
758325151a3SRui Paulo 		    center_segment0 == channel + 2 ||
759325151a3SRui Paulo 		    center_segment0 == channel - 2 ||
760325151a3SRui Paulo 		    center_segment0 == channel - 6 ||
761325151a3SRui Paulo 		    center_segment0 == channel - 10 ||
762325151a3SRui Paulo 		    center_segment0 == channel - 14)
7635b9c547cSRui Paulo 			data->center_freq1 = 5000 + center_segment0 * 5;
764c1d255d3SCy Schubert 		else {
765c1d255d3SCy Schubert 			wpa_printf(MSG_ERROR,
766c1d255d3SCy Schubert 				   "160 MHz: HT40 channel band is not in 160 MHz band");
767325151a3SRui Paulo 			return -1;
768c1d255d3SCy Schubert 		}
7695b9c547cSRui Paulo 		break;
770*a90b9d01SCy Schubert 	case CONF_OPER_CHWIDTH_320MHZ:
771*a90b9d01SCy Schubert 		data->bandwidth = 320;
772*a90b9d01SCy Schubert 		if (!data->eht_enabled || !is_6ghz_freq(freq)) {
773*a90b9d01SCy Schubert 			wpa_printf(MSG_ERROR,
774*a90b9d01SCy Schubert 				   "320 MHz: EHT not enabled or not a 6 GHz channel");
775*a90b9d01SCy Schubert 			return -1;
776*a90b9d01SCy Schubert 		}
777*a90b9d01SCy Schubert 		if (center_segment1) {
778*a90b9d01SCy Schubert 			wpa_printf(MSG_ERROR,
779*a90b9d01SCy Schubert 				   "320 MHz: center segment 1 should not be set");
780*a90b9d01SCy Schubert 			return -1;
781*a90b9d01SCy Schubert 		}
782*a90b9d01SCy Schubert 		if (center_segment0 == channel + 30 ||
783*a90b9d01SCy Schubert 		    center_segment0 == channel + 26 ||
784*a90b9d01SCy Schubert 		    center_segment0 == channel + 22 ||
785*a90b9d01SCy Schubert 		    center_segment0 == channel + 18 ||
786*a90b9d01SCy Schubert 		    center_segment0 == channel + 14 ||
787*a90b9d01SCy Schubert 		    center_segment0 == channel + 10 ||
788*a90b9d01SCy Schubert 		    center_segment0 == channel + 6 ||
789*a90b9d01SCy Schubert 		    center_segment0 == channel + 2 ||
790*a90b9d01SCy Schubert 		    center_segment0 == channel - 2 ||
791*a90b9d01SCy Schubert 		    center_segment0 == channel - 6 ||
792*a90b9d01SCy Schubert 		    center_segment0 == channel - 10 ||
793*a90b9d01SCy Schubert 		    center_segment0 == channel - 14 ||
794*a90b9d01SCy Schubert 		    center_segment0 == channel - 18 ||
795*a90b9d01SCy Schubert 		    center_segment0 == channel - 22 ||
796*a90b9d01SCy Schubert 		    center_segment0 == channel - 26 ||
797*a90b9d01SCy Schubert 		    center_segment0 == channel - 30)
798*a90b9d01SCy Schubert 			data->center_freq1 = 5000 + center_segment0 * 5;
799*a90b9d01SCy Schubert 		else {
800*a90b9d01SCy Schubert 			wpa_printf(MSG_ERROR,
801*a90b9d01SCy Schubert 				   "320 MHz: wrong center segment 0");
802*a90b9d01SCy Schubert 			return -1;
803*a90b9d01SCy Schubert 		}
804*a90b9d01SCy Schubert 		break;
805*a90b9d01SCy Schubert 	default:
806*a90b9d01SCy Schubert 		break;
8075b9c547cSRui Paulo 	}
8085b9c547cSRui Paulo 
8095b9c547cSRui Paulo 	return 0;
8105b9c547cSRui Paulo }
81185732ac8SCy Schubert 
81285732ac8SCy Schubert 
set_disable_ht40(struct ieee80211_ht_capabilities * htcaps,int disabled)81385732ac8SCy Schubert void set_disable_ht40(struct ieee80211_ht_capabilities *htcaps,
81485732ac8SCy Schubert 		      int disabled)
81585732ac8SCy Schubert {
81685732ac8SCy Schubert 	/* Masking these out disables HT40 */
81785732ac8SCy Schubert 	le16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
81885732ac8SCy Schubert 				HT_CAP_INFO_SHORT_GI40MHZ);
81985732ac8SCy Schubert 
82085732ac8SCy Schubert 	if (disabled)
82185732ac8SCy Schubert 		htcaps->ht_capabilities_info &= ~msk;
82285732ac8SCy Schubert 	else
82385732ac8SCy Schubert 		htcaps->ht_capabilities_info |= msk;
82485732ac8SCy Schubert }
82585732ac8SCy Schubert 
82685732ac8SCy Schubert 
82785732ac8SCy Schubert #ifdef CONFIG_IEEE80211AC
82885732ac8SCy Schubert 
_ieee80211ac_cap_check(u32 hw,u32 conf,u32 cap,const char * name)82985732ac8SCy Schubert static int _ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap,
83085732ac8SCy Schubert 				  const char *name)
83185732ac8SCy Schubert {
83285732ac8SCy Schubert 	u32 req_cap = conf & cap;
83385732ac8SCy Schubert 
83485732ac8SCy Schubert 	/*
83585732ac8SCy Schubert 	 * Make sure we support all requested capabilities.
83685732ac8SCy Schubert 	 * NOTE: We assume that 'cap' represents a capability mask,
83785732ac8SCy Schubert 	 * not a discrete value.
83885732ac8SCy Schubert 	 */
83985732ac8SCy Schubert 	if ((hw & req_cap) != req_cap) {
84085732ac8SCy Schubert 		wpa_printf(MSG_ERROR,
84185732ac8SCy Schubert 			   "Driver does not support configured VHT capability [%s]",
84285732ac8SCy Schubert 			   name);
84385732ac8SCy Schubert 		return 0;
84485732ac8SCy Schubert 	}
84585732ac8SCy Schubert 	return 1;
84685732ac8SCy Schubert }
84785732ac8SCy Schubert 
84885732ac8SCy Schubert 
ieee80211ac_cap_check_max(u32 hw,u32 conf,u32 mask,unsigned int shift,const char * name)84985732ac8SCy Schubert static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask,
85085732ac8SCy Schubert 				     unsigned int shift,
85185732ac8SCy Schubert 				     const char *name)
85285732ac8SCy Schubert {
85385732ac8SCy Schubert 	u32 hw_max = hw & mask;
85485732ac8SCy Schubert 	u32 conf_val = conf & mask;
85585732ac8SCy Schubert 
85685732ac8SCy Schubert 	if (conf_val > hw_max) {
85785732ac8SCy Schubert 		wpa_printf(MSG_ERROR,
85885732ac8SCy Schubert 			   "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
85985732ac8SCy Schubert 			   name, conf_val >> shift, hw_max >> shift);
86085732ac8SCy Schubert 		return 0;
86185732ac8SCy Schubert 	}
86285732ac8SCy Schubert 	return 1;
86385732ac8SCy Schubert }
86485732ac8SCy Schubert 
86585732ac8SCy Schubert 
ieee80211ac_cap_check(u32 hw,u32 conf)86685732ac8SCy Schubert int ieee80211ac_cap_check(u32 hw, u32 conf)
86785732ac8SCy Schubert {
86885732ac8SCy Schubert #define VHT_CAP_CHECK(cap) \
86985732ac8SCy Schubert 	do { \
87085732ac8SCy Schubert 		if (!_ieee80211ac_cap_check(hw, conf, cap, #cap)) \
87185732ac8SCy Schubert 			return 0; \
87285732ac8SCy Schubert 	} while (0)
87385732ac8SCy Schubert 
87485732ac8SCy Schubert #define VHT_CAP_CHECK_MAX(cap) \
87585732ac8SCy Schubert 	do { \
87685732ac8SCy Schubert 		if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
87785732ac8SCy Schubert 					       #cap)) \
87885732ac8SCy Schubert 			return 0; \
87985732ac8SCy Schubert 	} while (0)
88085732ac8SCy Schubert 
88185732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
88285732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_SUPP_CHAN_WIDTH_MASK);
88385732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_RXLDPC);
88485732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
88585732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
88685732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_TXSTBC);
88785732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
88885732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
88985732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
89085732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
89185732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
89285732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
89385732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
89485732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
89585732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
89685732ac8SCy Schubert 	VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
89785732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
89885732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
89985732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
90085732ac8SCy Schubert 	VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
90185732ac8SCy Schubert 
90285732ac8SCy Schubert #undef VHT_CAP_CHECK
90385732ac8SCy Schubert #undef VHT_CAP_CHECK_MAX
90485732ac8SCy Schubert 
90585732ac8SCy Schubert 	return 1;
90685732ac8SCy Schubert }
90785732ac8SCy Schubert 
90885732ac8SCy Schubert #endif /* CONFIG_IEEE80211AC */
9094bc52338SCy Schubert 
9104bc52338SCy Schubert 
num_chan_to_bw(int num_chans)9114bc52338SCy Schubert u32 num_chan_to_bw(int num_chans)
9124bc52338SCy Schubert {
9134bc52338SCy Schubert 	switch (num_chans) {
9144bc52338SCy Schubert 	case 2:
9154bc52338SCy Schubert 	case 4:
9164bc52338SCy Schubert 	case 8:
917*a90b9d01SCy Schubert 	case 16:
9184bc52338SCy Schubert 		return num_chans * 20;
9194bc52338SCy Schubert 	default:
9204bc52338SCy Schubert 		return 20;
9214bc52338SCy Schubert 	}
9224bc52338SCy Schubert }
9234bc52338SCy Schubert 
9244bc52338SCy Schubert 
9254bc52338SCy Schubert /* check if BW is applicable for channel */
chan_bw_allowed(const struct hostapd_channel_data * chan,u32 bw,int ht40_plus,int pri)9264bc52338SCy Schubert int chan_bw_allowed(const struct hostapd_channel_data *chan, u32 bw,
9274bc52338SCy Schubert 		    int ht40_plus, int pri)
9284bc52338SCy Schubert {
9294bc52338SCy Schubert 	u32 bw_mask;
9304bc52338SCy Schubert 
9314bc52338SCy Schubert 	switch (bw) {
9324bc52338SCy Schubert 	case 20:
9334bc52338SCy Schubert 		bw_mask = HOSTAPD_CHAN_WIDTH_20;
9344bc52338SCy Schubert 		break;
9354bc52338SCy Schubert 	case 40:
9364bc52338SCy Schubert 		/* HT 40 MHz support declared only for primary channel,
9374bc52338SCy Schubert 		 * just skip 40 MHz secondary checking */
9384bc52338SCy Schubert 		if (pri && ht40_plus)
9394bc52338SCy Schubert 			bw_mask = HOSTAPD_CHAN_WIDTH_40P;
9404bc52338SCy Schubert 		else if (pri && !ht40_plus)
9414bc52338SCy Schubert 			bw_mask = HOSTAPD_CHAN_WIDTH_40M;
9424bc52338SCy Schubert 		else
9434bc52338SCy Schubert 			bw_mask = 0;
9444bc52338SCy Schubert 		break;
9454bc52338SCy Schubert 	case 80:
9464bc52338SCy Schubert 		bw_mask = HOSTAPD_CHAN_WIDTH_80;
9474bc52338SCy Schubert 		break;
9484bc52338SCy Schubert 	case 160:
9494bc52338SCy Schubert 		bw_mask = HOSTAPD_CHAN_WIDTH_160;
9504bc52338SCy Schubert 		break;
951*a90b9d01SCy Schubert 	case 320:
952*a90b9d01SCy Schubert 		bw_mask = HOSTAPD_CHAN_WIDTH_320;
953*a90b9d01SCy Schubert 		break;
9544bc52338SCy Schubert 	default:
9554bc52338SCy Schubert 		bw_mask = 0;
9564bc52338SCy Schubert 		break;
9574bc52338SCy Schubert 	}
9584bc52338SCy Schubert 
9594bc52338SCy Schubert 	return (chan->allowed_bw & bw_mask) == bw_mask;
9604bc52338SCy Schubert }
9614bc52338SCy Schubert 
9624bc52338SCy Schubert 
9634bc52338SCy Schubert /* check if channel is allowed to be used as primary */
chan_pri_allowed(const struct hostapd_channel_data * chan)9644bc52338SCy Schubert int chan_pri_allowed(const struct hostapd_channel_data *chan)
9654bc52338SCy Schubert {
9664bc52338SCy Schubert 	return !(chan->flag & HOSTAPD_CHAN_DISABLED) &&
9674bc52338SCy Schubert 		(chan->allowed_bw & HOSTAPD_CHAN_WIDTH_20);
9684bc52338SCy Schubert }
969*a90b9d01SCy Schubert 
970*a90b9d01SCy Schubert 
971*a90b9d01SCy Schubert /* IEEE P802.11be/D3.0, Table 36-30 - Definition of the Punctured Channel
972*a90b9d01SCy Schubert  * Information field in the U-SIG for an EHT MU PPDU using non-OFDMA
973*a90b9d01SCy Schubert  * transmissions */
974*a90b9d01SCy Schubert static const u16 punct_bitmap_80[] = { 0xF, 0xE, 0xD, 0xB, 0x7 };
975*a90b9d01SCy Schubert static const u16 punct_bitmap_160[] = {
976*a90b9d01SCy Schubert 	0xFF, 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF,
977*a90b9d01SCy Schubert 	0x7F, 0xFC, 0xF3, 0xCF, 0x3F
978*a90b9d01SCy Schubert };
979*a90b9d01SCy Schubert static const u16 punct_bitmap_320[] = {
980*a90b9d01SCy Schubert 	0xFFFF, 0xFFFC, 0xFFF3, 0xFFCF, 0xFF3F, 0xFCFF, 0xF3FF, 0xCFFF,
981*a90b9d01SCy Schubert 	0x3FFF, 0xFFF0, 0xFF0F, 0xF0FF, 0x0FFF, 0xFFC0, 0xFF30, 0xFCF0,
982*a90b9d01SCy Schubert 	0xF3F0, 0xCFF0, 0x3FF0, 0x0FFC, 0x0FF3, 0x0FCF, 0x0F3F, 0x0CFF,
983*a90b9d01SCy Schubert 	0x03FF
984*a90b9d01SCy Schubert };
985*a90b9d01SCy Schubert 
986*a90b9d01SCy Schubert 
is_punct_bitmap_valid(u16 bw,u16 pri_ch_bit_pos,u16 punct_bitmap)987*a90b9d01SCy Schubert bool is_punct_bitmap_valid(u16 bw, u16 pri_ch_bit_pos, u16 punct_bitmap)
988*a90b9d01SCy Schubert {
989*a90b9d01SCy Schubert 	u8 i, count;
990*a90b9d01SCy Schubert 	u16 bitmap;
991*a90b9d01SCy Schubert 	const u16 *valid_bitmaps;
992*a90b9d01SCy Schubert 
993*a90b9d01SCy Schubert 	if (!punct_bitmap) /* All channels active */
994*a90b9d01SCy Schubert 		return true;
995*a90b9d01SCy Schubert 
996*a90b9d01SCy Schubert 	bitmap = ~punct_bitmap;
997*a90b9d01SCy Schubert 
998*a90b9d01SCy Schubert 	switch (bw) {
999*a90b9d01SCy Schubert 	case 80:
1000*a90b9d01SCy Schubert 		bitmap &= 0xF;
1001*a90b9d01SCy Schubert 		valid_bitmaps = punct_bitmap_80;
1002*a90b9d01SCy Schubert 		count = ARRAY_SIZE(punct_bitmap_80);
1003*a90b9d01SCy Schubert 		break;
1004*a90b9d01SCy Schubert 
1005*a90b9d01SCy Schubert 	case 160:
1006*a90b9d01SCy Schubert 		bitmap &= 0xFF;
1007*a90b9d01SCy Schubert 		valid_bitmaps = punct_bitmap_160;
1008*a90b9d01SCy Schubert 		count = ARRAY_SIZE(punct_bitmap_160);
1009*a90b9d01SCy Schubert 		break;
1010*a90b9d01SCy Schubert 
1011*a90b9d01SCy Schubert 	case 320:
1012*a90b9d01SCy Schubert 		bitmap &= 0xFFFF;
1013*a90b9d01SCy Schubert 		valid_bitmaps = punct_bitmap_320;
1014*a90b9d01SCy Schubert 		count = ARRAY_SIZE(punct_bitmap_320);
1015*a90b9d01SCy Schubert 		break;
1016*a90b9d01SCy Schubert 
1017*a90b9d01SCy Schubert 	default:
1018*a90b9d01SCy Schubert 		return false;
1019*a90b9d01SCy Schubert 	}
1020*a90b9d01SCy Schubert 
1021*a90b9d01SCy Schubert 	if (!bitmap) /* No channel active */
1022*a90b9d01SCy Schubert 		return false;
1023*a90b9d01SCy Schubert 
1024*a90b9d01SCy Schubert 	if (!(bitmap & BIT(pri_ch_bit_pos))) {
1025*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "Primary channel cannot be punctured");
1026*a90b9d01SCy Schubert 		return false;
1027*a90b9d01SCy Schubert 	}
1028*a90b9d01SCy Schubert 
1029*a90b9d01SCy Schubert 	for (i = 0; i < count; i++) {
1030*a90b9d01SCy Schubert 		if (valid_bitmaps[i] == bitmap)
1031*a90b9d01SCy Schubert 			return true;
1032*a90b9d01SCy Schubert 	}
1033*a90b9d01SCy Schubert 
1034*a90b9d01SCy Schubert 	return false;
1035*a90b9d01SCy Schubert }
1036