From 94044c74417bee7d7ad70280a2d5863e95c9c359 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 5 Feb 2021 16:34:04 +0100 Subject: [PATCH] wifi: auto-activate devices as soon as the first scan finishes Currently if we detect that a scan finished in _scan_notify_is_scanning(), we call immediately _scan_kickoff() (which might start a new scan) and then we check again whether the device can autoactivate or whether to remove the wifi-scan pending action. This means that if the scan takes long enough, when _scan_notify_is_scanning() is called, it is already time to start another scan and the device activation will be delayed. It will be delayed until the scan duration becomes shorter than the exponentially-growing periodic scan interval. Fix this by delaying the next scan immediately after a scan result. Co-authored-by: Thomas Haller https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/574 (cherry picked from commit 16d649ea92a1c481a59395d8672224e9e40563a3) --- src/devices/wifi/nm-device-wifi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 980916dde3..454a9049ad 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1744,6 +1744,23 @@ _scan_kickoff(NMDeviceWifi *self) return; } + if (priv->scan_last_complete_msec + 200 > now_msec) { + gint32 timeout_msec = priv->scan_last_complete_msec + 200 - now_msec; + + /* after a scan just completed, it is ratelimited for another 200 msec. This is in + * addition to our rate limiting above (where scanning can take longer than our rate limit + * duration). + * + * This gives the device a chance to autoconnect. Also, if a scanning just completed, + * we want to back off a bit before starting again. */ + _LOGT_scan("kickoff: don't scan (rate limited for another %d.%03d sec after previous scan)", + timeout_msec / 1000, + timeout_msec % 1000); + nm_clear_g_source(&priv->scan_kickoff_timeout_id); + priv->scan_kickoff_timeout_id = g_timeout_add(timeout_msec, _scan_kickoff_timeout_cb, self); + return; + } + if (priv->scan_explicit_requested) { if (!priv->scan_explicit_allowed) { _LOGT_scan("kickoff: don't scan (explicit scan requested but not allowed)");