From 5ef9277d0bd441943966c43d5b15f7a17605c011 Mon Sep 17 00:00:00 2001 From: Alan Young Date: Thu, 11 Nov 2021 16:40:05 +0000 Subject: [PATCH] ACS/DFS: Support min_tx_power configuration If min_tx_power is specified (default 0 dBm, i.e., no constraint), ACS and DFS will not consider channels whose available max_tx_power is less than the configured value. This may be useful to exclude SRD (Short Range Device) channels which may be limited to 13.9 dBm (25 mW) in some regulatory domains. Signed-off-by: Alan Young --- hostapd/config_file.c | 10 ++++++++++ hostapd/hostapd.conf | 4 ++++ src/ap/acs.c | 9 +++++++++ src/ap/ap_config.h | 1 + src/ap/ap_drv_ops.c | 3 ++- src/ap/dfs.c | 3 +++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index daf3f37ad..b14728d1b 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -3193,6 +3193,16 @@ static int hostapd_config_fill(struct hostapd_config *conf, conf->acs_freq_list_present = 1; } else if (os_strcmp(buf, "acs_exclude_6ghz_non_psc") == 0) { conf->acs_exclude_6ghz_non_psc = atoi(pos); + } else if (os_strcmp(buf, "min_tx_power") == 0) { + int val = atoi(pos); + + if (val < 0 || val > 255) { + wpa_printf(MSG_ERROR, + "Line %d: invalid min_tx_power %d (expected 0..255)", + line, val); + return 1; + } + conf->min_tx_power = val; } else if (os_strcmp(buf, "beacon_int") == 0) { int val = atoi(pos); /* MIB defines range as 1..65535, but very small values diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf index 67d4cefb9..3c2019f73 100644 --- a/hostapd/hostapd.conf +++ b/hostapd/hostapd.conf @@ -225,6 +225,10 @@ channel=1 # Default behavior is to include all PSC and non-PSC channels. #acs_exclude_6ghz_non_psc=1 +# Set minimum permitted max TX power (in dBm) for ACS and DFS channel selection. +# (default 0, i.e., not constraint) +#min_tx_power=20 + # Beacon interval in kus (1.024 ms) (default: 100; range 15..65535) beacon_int=100 diff --git a/src/ap/acs.c b/src/ap/acs.c index 46429f265..0030edc2a 100644 --- a/src/ap/acs.c +++ b/src/ap/acs.c @@ -546,6 +546,9 @@ static void acs_survey_mode_interference_factor( if (!is_in_freqlist(iface, chan)) continue; + if (chan->max_tx_power < iface->conf->min_tx_power) + continue; + wpa_printf(MSG_DEBUG, "ACS: Survey analysis for channel %d (%d MHz)", chan->chan, chan->freq); @@ -673,6 +676,9 @@ acs_find_ideal_chan_mode(struct hostapd_iface *iface, if (!is_in_freqlist(iface, chan)) continue; + if (chan->max_tx_power < iface->conf->min_tx_power) + continue; + if (!chan_bw_allowed(chan, bw, 1, 1)) { wpa_printf(MSG_DEBUG, "ACS: Channel %d: BW %u is not supported", @@ -1047,6 +1053,9 @@ static int * acs_request_scan_add_freqs(struct hostapd_iface *iface, if (!is_in_freqlist(iface, chan)) continue; + if (chan->max_tx_power < iface->conf->min_tx_power) + continue; + *freq++ = chan->freq; } diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h index b8f791e56..20e2afe24 100644 --- a/src/ap/ap_config.h +++ b/src/ap/ap_config.h @@ -953,6 +953,7 @@ struct hostapd_config { struct wpa_freq_range_list acs_freq_list; u8 acs_freq_list_present; int acs_exclude_dfs; + u8 min_tx_power; enum hostapd_hw_mode hw_mode; /* HOSTAPD_MODE_IEEE80211A, .. */ int acs_exclude_6ghz_non_psc; enum { diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c index d1642d7df..e91773666 100644 --- a/src/ap/ap_drv_ops.c +++ b/src/ap/ap_drv_ops.c @@ -888,7 +888,8 @@ static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd, continue; if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && !(hapd->iface->conf->acs_exclude_dfs && - (chan->flag & HOSTAPD_CHAN_RADAR))) + (chan->flag & HOSTAPD_CHAN_RADAR)) && + !(chan->max_tx_power < hapd->iface->conf->min_tx_power)) int_array_add_unique(freq_list, chan->freq); } } diff --git a/src/ap/dfs.c b/src/ap/dfs.c index 03c99b175..5c99ecfd0 100644 --- a/src/ap/dfs.c +++ b/src/ap/dfs.c @@ -246,6 +246,9 @@ static int dfs_find_channel(struct hostapd_iface *iface, continue; } + if (chan->max_tx_power < iface->conf->min_tx_power) + continue; + if (ret_chan && idx == channel_idx) { wpa_printf(MSG_DEBUG, "Selected channel %d (%d)", chan->freq, chan->chan);