[PATCH] Do not start sched_scan without enabled networks

Thibaud Dufour thibaud.dufour at gmail.com
Mon Nov 30 06:10:09 PST 2026


From: Thibaud Dufour <thibaud.dufour at rtone.fr>

When a scan requested by an external program, such as ConnMan through
the D-Bus Scan() method, finds no suitable network,
wpas_select_network_from_last_scan() asks for a sched_scan, and only
falls back to wpa_supplicant_req_new_scan() if that request fails.

wpa_supplicant_req_sched_scan() does not check that there is a network
to look for. Once normal_scans reaches 3, it starts a sched_scan with an
empty SSID list and moves the interface to WPA_SCANNING, while the
normal scan path stops in wpa_supplicant_scan() with "No enabled
networks - do not scan" and leaves the interface in WPA_INACTIVE.

ConnMan keeps its own network list and does not add any network to
wpa_supplicant until it connects, so this happens after every scan it
requests, from the fourth one on:

  mlan0: No suitable network found
  mlan0: State: INACTIVE -> SCANNING
  mlan0: Beginning of SSID list
  mlan0: Starting sched scan after 0 seconds (no timeout)
  mlan0: nl80211: sched_scan request
  ...
  mlan0: Restart scanning after unexpected sched_scan stop event
  mlan0: Setting scan request: 1.000000 sec
  mlan0: No enabled networks - do not scan
  mlan0: State: SCANNING -> INACTIVE

This sched_scan cannot find anything, keeps the radio busy for nothing,
and reports the interface as scanning. On an NXP IW612 (mlan driver),
a Scan() request sent to ConnMan during that time does not reach
wpa_supplicant and gets no reply: every other "connmanctl scan wifi"
hangs.

Apply the same condition as wpa_supplicant_scan() in
wpa_supplicant_req_sched_scan(): with no enabled network and a normal
scan request, do not start a sched_scan. The caller then falls back to
wpa_supplicant_req_new_scan(), which already returns early without
enabled networks and leaves the interface in WPA_INACTIVE. A manual
scan request, for instance from autoscan, still starts a sched_scan as
before.

With this change, the same sequence gives:

  mlan0: No suitable network found
  mlan0: No enabled networks - do not start sched_scan
  mlan0: Short-circuit new scan request since there are no enabled networks
  mlan0: State: INACTIVE -> INACTIVE

and repeated "connmanctl scan wifi" all complete.

Signed-off-by: Thibaud Dufour <thibaud.dufour at rtone.fr>
---
 wpa_supplicant/scan.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index f02d8cbcd..d157a991d 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -1723,6 +1723,18 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
 	if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload)
 		return -1;
 
+	/*
+	 * Without any enabled network, a sched_scan cannot find anything to
+	 * connect to. Let the caller fall back to a normal scan request,
+	 * which is skipped in this case as well.
+	 */
+	if (!wpa_supplicant_enabled_networks(wpa_s) &&
+	    wpa_s->scan_req == NORMAL_SCAN_REQ) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"No enabled networks - do not start sched_scan");
+		return -1;
+	}
+
 	wpa_s->sched_scan_stop_req = 0;
 
 	if (wpa_s->sched_scanning) {
-- 
2.56.1




More information about the Hostap mailing list