diff mbox series

Scan other networks first to unlock 5GHz bands on Intel cards

Message ID 5TLtkCSwaUx-RqmmGmjkvZYDuOoygMMyJo5CGL76zpDSc4DrPeUsskBfK_dfts8Uxl5Rk4BqrZD1L6uQKsSJWPSlNj__T7dHdz7zzVPo_J8=@protonmail.com
State Changes Requested
Headers show
Series Scan other networks first to unlock 5GHz bands on Intel cards | expand

Commit Message

Pedro Goncalves (developer account) July 17, 2024, 7:56 p.m. UTC
Subject: [PATCH] For intel Wi-Fi cards, force to scan other wireless networks so the drive is able to set the correct region - master

Signed-off-by: Pedro Goncalves <pgoncalves-developer@protonmail.com>
---

Comments

Jouni Malinen Aug. 3, 2024, 8:55 a.m. UTC | #1
On Wed, Jul 17, 2024 at 07:56:04PM +0000, Pedro Goncalves (developer account) wrote:
> Subject: [PATCH] For intel Wi-Fi cards, force to scan other wireless networks so the drive is able to set the correct region - master
> 
> Signed-off-by: Pedro Goncalves <pgoncalves-developer@protonmail.com>

This would need much more detailed commit message to justify why this is
needed and why this is appropriate behavior. How is this specific to
Intel cards? Why would an AP be allowed to operate on the 5 GHz band
based on just a single scan if it was not allowed to do so without that
scan?

> Index: src/ap/hostapd.h
> IDEA additional info:
> Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
> <+>UTF-8
> ===================================================================
> diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h

And this format is pretty strange and requires manual operations to
apply with 'git am'.
Taavi Eomäe Aug. 10, 2024, 9:50 a.m. UTC | #2
Hi,

Not the submitter of the patch, but I think this is needed because of 
Intel's Location Aware Regulatory (LAR). If a scan is not done 
beforehand, all 5GHz channels are marked as NO-IR.

This is incredibly inconvenient, but indeed a quirk with Intel cards. 
There's also an open Bugzilla ticket about it: 
https://bugzilla.kernel.org/show_bug.cgi?id=206469

It also has the nasty side-effect of making 6GHz APs practically 
impossible to start.

On 03/08/2024 11:55, Jouni Malinen wrote:
> On Wed, Jul 17, 2024 at 07:56:04PM +0000, Pedro Goncalves (developer account) wrote:
>> Subject: [PATCH] For intel Wi-Fi cards, force to scan other wireless networks so the drive is able to set the correct region - master
>>
>> Signed-off-by: Pedro Goncalves <pgoncalves-developer@protonmail.com>
> This would need much more detailed commit message to justify why this is
> needed and why this is appropriate behavior. How is this specific to
> Intel cards? Why would an AP be allowed to operate on the 5 GHz band
> based on just a single scan if it was not allowed to do so without that
> scan?
>
>> Index: src/ap/hostapd.h
>> IDEA additional info:
>> Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
>> <+>UTF-8
>> ===================================================================
>> diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h
> And this format is pretty strange and requires manual operations to
> apply with 'git am'.
>
diff mbox series

Patch

Subject: [PATCH] For intel Wi-Fi cards, force to scan other wireless networks so the drive is able to set the correct region - master

Signed-off-by: Pedro Goncalves <pgoncalves-developer@protonmail.com>
---
Index: src/ap/hostapd.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h
--- a/src/ap/hostapd.h	(revision e7172e26d3ebe962150a2e579e40d3a69e8f7304)
+++ b/src/ap/hostapd.h	(date 1721057509037)
@@ -746,6 +746,7 @@ 
 int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
 int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator);
+void hostapd_scan_results_updated(struct hostapd_iface *iface);
 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
 const char * hostapd_state_text(enum hostapd_iface_state s);
 int hostapd_csa_in_progress(struct hostapd_iface *iface);
Index: src/ap/hostapd.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
--- a/src/ap/hostapd.c	(revision e7172e26d3ebe962150a2e579e40d3a69e8f7304)
+++ b/src/ap/hostapd.c	(date 1721241666773)
@@ -1992,11 +1992,15 @@ 
 					   NULL);
 		return;
 	}
+}
 
-	if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
+
+void hostapd_scan_results_updated(struct hostapd_iface *iface)
+{
+	if (!iface->wait_channel_update)
 		return;
 
-	wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
+	wpa_printf(MSG_DEBUG, "Scan results updated - continue setup");
 	eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
 	setup_interface2(iface);
 }
@@ -2064,7 +2068,8 @@ 
 		if (os_strncmp(previous_country, country, 2) != 0) {
 			wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
 			iface->wait_channel_update = 1;
-			eloop_register_timeout(5, 0,
+			int timeout = hostapd_scan_region_before_setting_channel(iface, NULL) ? 10 : 5;
+			eloop_register_timeout(timeout, 0,
 					       channel_list_update_timeout,
 					       iface, NULL);
 			return 0;
Index: src/ap/hw_features.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/ap/hw_features.h b/src/ap/hw_features.h
--- a/src/ap/hw_features.h	(revision e7172e26d3ebe962150a2e579e40d3a69e8f7304)
+++ b/src/ap/hw_features.h	(date 1721057961231)
@@ -21,6 +21,7 @@ 
 const char * hostapd_hw_mode_txt(int mode);
 int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan);
 int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq);
+int hostapd_scan_region_before_setting_channel(struct hostapd_iface *iface, void *ctx);
 int hostapd_check_ht_capab(struct hostapd_iface *iface);
 int hostapd_check_edmg_capab(struct hostapd_iface *iface);
 int hostapd_check_he_6ghz_capab(struct hostapd_iface *iface);
Index: src/ap/hw_features.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c
--- a/src/ap/hw_features.c	(revision e7172e26d3ebe962150a2e579e40d3a69e8f7304)
+++ b/src/ap/hw_features.c	(date 1721241733664)
@@ -42,6 +42,14 @@ 
 }
 
 
+static void ieee80211n_region_scan_complete(struct hostapd_iface *iface)
+{
+	iface->scan_cb = NULL;
+	wpa_printf(MSG_DEBUG, "Region scan completed");
+	hostapd_scan_results_updated(iface);
+}
+
+
 #ifndef CONFIG_NO_STDOUT_DEBUG
 static char * dfs_info(struct hostapd_channel_data *chan)
 {
@@ -85,6 +93,10 @@ 
 
 	if (hostapd_drv_none(hapd))
 		return -1;
+
+	if (iface->scan_cb == ieee80211n_region_scan_complete)
+		return -1;
+
 	modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags,
 					    &dfs_domain);
 	if (modes == NULL) {
@@ -539,6 +551,34 @@ 
 }
 
 
+int hostapd_scan_region_before_setting_channel(struct hostapd_iface *iface, void *ctx)
+{
+	struct wpa_driver_scan_params params;
+	int ret;
+
+	if (iface->scan_cb == ieee80211n_region_scan_complete)
+		return 0;
+
+	if (iface->conf->hw_mode_set && iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211A)
+		ieee80211n_scan_channels_5g(iface, &params);
+	else
+		ieee80211n_scan_channels_2g4(iface, &params);
+
+	os_memset(&params, 0, sizeof(params));
+	ret = hostapd_driver_scan(iface->bss[0], &params);
+    if (ret == -EBUSY) {
+        wpa_printf(MSG_ERROR,
+                   "Failed to request a scan of neighboring BSSes ret=%d (%s)!",
+                   ret, strerror(-ret));
+		return 0;
+    }
+    if (ret == 0)
+	    iface->scan_cb = ieee80211n_region_scan_complete;
+
+	return 1;
+}
+
+
 void hostapd_stop_setup_timers(struct hostapd_iface *iface)
 {
 	eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);