[PATCH] Add an option to set secondary channel in hostapd conf

Orr Mazor orrmazor at gmail.com
Thu Feb 25 09:06:17 EST 2021


Usefull in case we want to specify the secondary channel
or in case we want to be on 20mghz with 40mghz capabilities.

It is possible in chan_switch to set secondary channel,
however it was not possible to do so when hostapd start.
This commit adds this option.

Signed-off-by: Orr Mazor <orr.mazor at tandemg.com>
---
 hostapd/config_file.c | 9 +++++++--
 hostapd/hostapd.conf  | 8 ++++++++
 src/ap/ap_config.h    | 1 +
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 64704fb3d..4079fa5d5 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -1067,11 +1067,13 @@ static int hostapd_config_ht_capab(struct hostapd_config *conf,
 		conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
 	if (os_strstr(capab, "[HT40-]")) {
 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
-		conf->secondary_channel = -1;
+		if (!conf->secondary_channel_set)
+			conf->secondary_channel = -1;
 	}
 	if (os_strstr(capab, "[HT40+]")) {
 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
-		conf->secondary_channel = 1;
+		if (!conf->secondary_channel_set)
+			conf->secondary_channel = 1;
 	}
 	if (os_strstr(capab, "[HT40+]") && os_strstr(capab, "[HT40-]")) {
 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
@@ -3447,6 +3449,9 @@ static int hostapd_config_fill(struct hostapd_config *conf,
 				   line);
 			return 1;
 		}
+	} else if (os_strcmp(buf, "secondary_channel") == 0) {
+		conf->secondary_channel = atoi(pos);
+		conf->secondary_channel_set = 1;
 	} else if (os_strcmp(buf, "require_ht") == 0) {
 		conf->require_ht = atoi(pos);
 	} else if (os_strcmp(buf, "obss_interval") == 0) {
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index a3d28efed..769a06356 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -625,6 +625,14 @@ wmm_ac_vo_acm=0
 # Require stations to support HT PHY (reject association if they do not)
 #require_ht=1
 
+# secondary_channel: Set secondary channel offset manually
+# can be set to 1, 0 or -1
+# 1 - means the secondary channel will be 20mghz above primary channel
+# 0 - means the secondary channel is same as primary channel
+# -1 - means the secondary channel will be 20mghz below primary channel
+# (if not set here will be set automatically)
+#secondary_channel=0
+
 # If set non-zero, require stations to perform scans of overlapping
 # channels to test for stations which would be affected by 40 MHz traffic.
 # This parameter sets the interval in seconds between these scans. Setting this
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index 88200c688..6fa26a5a9 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -995,6 +995,7 @@ struct hostapd_config {
 	u16 ht_capab;
 	int ieee80211n;
 	int secondary_channel;
+	unsigned int secondary_channel_set:1;
 	int no_pri_sec_switch;
 	int require_ht;
 	int obss_interval;
-- 
2.17.1




More information about the Hostap mailing list