From 62657365f896108da7bb22d6b0a767337a9624f1 Mon Sep 17 00:00:00 2001 From: Sunil Dutt Date: Tue, 19 Jan 2021 18:30:32 +0530 Subject: [PATCH] Add a configuration to disconnect on deinit if WoWLAN is enabled Commit 02c21c02d09f ("wpa_supplicant: Do not disconnect on deinit if WoWLAN is enabled") prevents the disconnection on deinit if the driver indicates that WoWLAN is enabled. This is not the expected behavior in some earlier use cases where the wpa_supplicant process is left running when going to sleep and killing of the wpa_supplicant process is used only when there is an expectation of Wi-Fi connection being disabled. To support the use cases which require the WLAN to disconnect on deinit even if WoWLAN is enabled, introduce a configuration parameter wowlan_disconnect_on_deinit. This is set to 0 by default thereby not impacting the functionality in the above mentioned commit. Setting it to 1 restores the old behavior before the commit identified above. Signed-off-by: Jouni Malinen --- wpa_supplicant/config.c | 1 + wpa_supplicant/config.h | 9 +++++++++ wpa_supplicant/config_file.c | 3 +++ wpa_supplicant/wpa_supplicant.c | 8 ++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 0aa92a28c..4c1e42260 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -5148,6 +5148,7 @@ static const struct global_parse_data global_fields[] = { { INT_RANGE(disable_btm, 0, 1), CFG_CHANGED_DISABLE_BTM }, { INT_RANGE(extended_key_id, 0, 1), 0 }, #endif /* CONFIG_WNM */ + { INT_RANGE(wowlan_disconnect_on_deinit, 0, 1), 0}, }; #undef FUNC diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index d128cd9bf..611b99318 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -1599,6 +1599,15 @@ struct wpa_config { * 1 = use Extended Key ID when possible */ int extended_key_id; + + /** + * wowlan_disconnect_on_deinit - Trigger disconnect on wpa_supplicant + * interface deinit even if the driver has enabled WoWLAN. + * + * 0 = Do not disconnect + * 1 = Trigger disconnection + */ + int wowlan_disconnect_on_deinit; }; diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c index cb04a78a2..9ddd9ecfd 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -1620,6 +1620,9 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config) if (config->extended_key_id != DEFAULT_EXTENDED_KEY_ID) fprintf(f, "extended_key_id=%d\n", config->extended_key_id); + if (config->wowlan_disconnect_on_deinit) + fprintf(f, "wowlan_disconnect_on_deinit=%d\n", + config->wowlan_disconnect_on_deinit); } #endif /* CONFIG_NO_CONFIG_WRITE */ diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index c3e747260..9f474fd0d 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -6669,8 +6669,12 @@ static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s, wpa_s->disconnected = 1; if (wpa_s->drv_priv) { - /* Don't deauthenticate if WoWLAN is enabled */ - if (!wpa_drv_get_wowlan(wpa_s)) { + /* + * Don't deauthenticate if WoWLAN is enable and not explicitly + * been configured to disconnect. + */ + if (!wpa_drv_get_wowlan(wpa_s) || + wpa_s->conf->wowlan_disconnect_on_deinit) { wpa_supplicant_deauthenticate( wpa_s, WLAN_REASON_DEAUTH_LEAVING);