[PATCH 2/2] Fix beacon request with a given channel number

Baligh Gasmi gasmibal at gmail.com
Mon Feb 28 12:55:40 PST 2022


When receiving a beacon request to scan one single channel, with 80MHz
bandwidth, the freq for the 20MHz primary channels found are not correct.

This commit is about fix that by looking for the center freq channel
first, and then calculate the 20MHz channels freq.

test [OK]: rrm_beacon_req_active_scan_pri_channel

Signed-off-by: Baligh Gasmi <gasmibal at gmail.com>
---
 wpa_supplicant/op_classes.c       | 64 +++++++++++++++----------------
 wpa_supplicant/rrm.c              | 12 +++++-
 wpa_supplicant/wpa_supplicant_i.h |  3 +-
 3 files changed, 44 insertions(+), 35 deletions(-)

diff --git a/wpa_supplicant/op_classes.c b/wpa_supplicant/op_classes.c
index bd53c5cec..8a51f087c 100644
--- a/wpa_supplicant/op_classes.c
+++ b/wpa_supplicant/op_classes.c
@@ -47,10 +47,23 @@ static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode,
 }
 
 
-static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel,
-			    const u8 *center_channels, size_t num_chan)
+int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel,
+			    u8 op_class)
 {
 	size_t i;
+	size_t num_chan;
+	const u8 *center_channels;
+	const u8 center_channels_5ghz[] = { 42, 58, 106, 122, 138, 155, 171 };
+	const u8 center_channels_6ghz[] = { 7, 23, 39, 55, 71, 87, 103, 119,
+		135, 151, 167, 183, 199, 215 };
+
+	if (is_6ghz_op_class(op_class)) {
+		center_channels = center_channels_6ghz;
+		num_chan = ARRAY_SIZE(center_channels_6ghz);
+	} else {
+		center_channels = center_channels_5ghz;
+		num_chan = ARRAY_SIZE(center_channels_5ghz);
+	}
 
 	if (mode->mode != HOSTAPD_MODE_IEEE80211A)
 		return 0;
@@ -75,22 +88,8 @@ static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode,
 	u8 center_chan;
 	unsigned int i;
 	unsigned int no_ir = 0;
-	const u8 *center_channels;
-	size_t num_chan;
-	const u8 center_channels_5ghz[] = { 42, 58, 106, 122, 138, 155, 171 };
-	const u8 center_channels_6ghz[] = { 7, 23, 39, 55, 71, 87, 103, 119,
-					    135, 151, 167, 183, 199, 215 };
-
-	if (is_6ghz_op_class(op_class)) {
-		center_channels = center_channels_6ghz;
-		num_chan = ARRAY_SIZE(center_channels_6ghz);
-	} else {
-		center_channels = center_channels_5ghz;
-		num_chan = ARRAY_SIZE(center_channels_5ghz);
-	}
 
-	center_chan = get_center_80mhz(mode, channel, center_channels,
-				       num_chan);
+	center_chan = get_center_80mhz(mode, channel, op_class);
 	if (!center_chan)
 		return NOT_ALLOWED;
 
@@ -120,10 +119,22 @@ static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode,
 }
 
 
-static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel,
-			     const u8 *center_channels, size_t num_chan)
+int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel,
+			     u8 op_class)
 {
 	unsigned int i;
+	size_t num_chan;
+	const u8 *center_channels;
+	const u8 center_channels_5ghz[] = { 50, 114, 163 };
+	const u8 center_channels_6ghz[] = { 15, 47, 79, 111, 143, 175, 207 };
+
+	if (is_6ghz_op_class(op_class)) {
+		center_channels = center_channels_6ghz;
+		num_chan = ARRAY_SIZE(center_channels_6ghz);
+	} else {
+		center_channels = center_channels_5ghz;
+		num_chan = ARRAY_SIZE(center_channels_5ghz);
+	}
 
 	if (mode->mode != HOSTAPD_MODE_IEEE80211A)
 		return 0;
@@ -148,21 +159,8 @@ static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
 	u8 center_chan;
 	unsigned int i;
 	unsigned int no_ir = 0;
-	const u8 *center_channels;
-	size_t num_chan;
-	const u8 center_channels_5ghz[] = { 50, 114, 163 };
-	const u8 center_channels_6ghz[] = { 15, 47, 79, 111, 143, 175, 207 };
-
-	if (is_6ghz_op_class(op_class)) {
-		center_channels = center_channels_6ghz;
-		num_chan = ARRAY_SIZE(center_channels_6ghz);
-	} else {
-		center_channels = center_channels_5ghz;
-		num_chan = ARRAY_SIZE(center_channels_5ghz);
-	}
 
-	center_chan = get_center_160mhz(mode, channel, center_channels,
-					num_chan);
+	center_chan = get_center_160mhz(mode, channel, op_class);
 	if (!center_chan)
 		return NOT_ALLOWED;
 
diff --git a/wpa_supplicant/rrm.c b/wpa_supplicant/rrm.c
index cf107ebaf..3b68f0179 100644
--- a/wpa_supplicant/rrm.c
+++ b/wpa_supplicant/rrm.c
@@ -529,13 +529,23 @@ static int * wpas_add_channels(const struct oper_class_map *op,
 	next_freq = freqs;
 	for  (i = 0; i < num_chans; i++) {
 		u8 chan = channels ? channels[i] : op->min_chan + i * op->inc;
+		u8 center_freq_chan = chan;
 		enum chan_allowed res = verify_channel(mode, op->op_class, chan,
 						       op->bw);
 
 		if (res == NOT_ALLOWED || (res == NO_IR && active))
 			continue;
 
-		if (wpas_add_channel(op->op_class, chan, num_primary_channels,
+		/* in VHT/HT we need the center-freq-channel */
+		if (op->bw == BW80 || op->bw == BW80P80)
+			center_freq_chan = get_center_80mhz(mode, chan, op->op_class);
+		else if (op->bw == BW160)
+			center_freq_chan = get_center_160mhz(mode, chan, op->op_class);
+
+		/* if no valid result use given channel */
+		center_freq_chan = center_freq_chan?:chan;
+
+		if (wpas_add_channel(op->op_class, center_freq_chan, num_primary_channels,
 				     next_freq) < 0) {
 			os_free(freqs);
 			return NULL;
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 111aa0744..d8fa3dcd9 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -1706,7 +1706,8 @@ void wpas_update_mbo_connect_params(struct wpa_supplicant *wpa_s);
 enum chan_allowed {
 	NOT_ALLOWED, NO_IR, RADAR, ALLOWED
 };
-
+int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel, u8 op_class);
+int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel, u8 op_class);
 enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 op_class,
 				 u8 channel, u8 bw);
 size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s,
-- 
2.35.1




More information about the Hostap mailing list