From 4dd1ff7b66dc503274b1a78afb161a1f89c66dc4 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Thu, 23 Sep 2021 17:52:09 +0530 Subject: [PATCH] Handle supplicant kill event. Change-Id: If977a24c7ed8f67f4560aab6816b3c34a6739ba4 Signed-off-by: Niraj Kumar Goit --- include/wifi-power.h | 1 + src/signal-handler.c | 17 ++++++++++++++++- src/wifi-power.c | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/wifi-power.h b/include/wifi-power.h index d190f14..77a4ae5 100755 --- a/include/wifi-power.h +++ b/include/wifi-power.h @@ -48,6 +48,7 @@ gboolean handle_remove_p2p_driver(Wifi *wifi, GDBusMethodInvocation *context); void __netconfig_set_ether_macaddr(); int __execute_supplicant(gboolean enable); +void __mark_supplicant_stopped(void); #ifdef __cplusplus } diff --git a/src/signal-handler.c b/src/signal-handler.c index 8e214a2..1e45908 100755 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -85,7 +85,7 @@ #define SIGNAL_NAME_OWNER_CHANGED "NameOwnerChanged" #define MAX_SIG_LEN 64 -#define TOTAL_CONN_SIGNALS 6 +#define TOTAL_CONN_SIGNALS 7 #define MAX_SOCKET_OPEN_RETRY 5 typedef enum { @@ -680,6 +680,9 @@ static void _dbus_name_changed_cb(GDBusConnection *conn, /* If clatd is terminated unexpectedly, reset and enable clat service. */ if (NETCONFIG_CELLULAR_ONLINE == cellular_state_get_service_state()) netconfig_clatd_reset(); + } else if (g_strcmp0(name, SUPPLICANT_SERVICE) == 0 && *new == '\0') { + DBG("Supplicant destroyed: name %s, old %s, new %s", name, old, new); + __mark_supplicant_stopped(); } g_free(name); g_free(old); @@ -1541,6 +1544,18 @@ void register_gdbus_signal(void) NULL, NULL); + conn_subscription_ids[6] = g_dbus_connection_signal_subscribe( + connection, + DBUS_SERVICE_DBUS, + DBUS_INTERFACE_DBUS, + SIGNAL_NAME_OWNER_CHANGED, + NULL, + SUPPLICANT_SERVICE, + G_DBUS_SIGNAL_FLAGS_NONE, + _dbus_name_changed_cb, + NULL, + NULL); + INFO("Successfully register clat DBus signal filters"); for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) { diff --git a/src/wifi-power.c b/src/wifi-power.c index c6f12fc..fe8f48c 100755 --- a/src/wifi-power.c +++ b/src/wifi-power.c @@ -72,6 +72,7 @@ typedef struct { static gboolean wifi_firmware_recovery_mode = FALSE; static int airplane_mode = 0; +gboolean is_supplicant_running = FALSE; static gboolean __is_wifi_restricted(void) { @@ -125,6 +126,11 @@ static void __technology_reply(GObject *source_object, GAsyncResult *res, gpoint g_free(interface_name); } +void __mark_supplicant_stopped(void) +{ + is_supplicant_running = FALSE; +} + int __execute_supplicant(gboolean enable) { /* @@ -138,9 +144,8 @@ int __execute_supplicant(gboolean enable) char *const args_disable[] = { "/usr/bin/wpa_supp.sh", "stop", NULL }; #endif char *const envs[] = { NULL }; - static gboolean enabled = FALSE; - if (enabled == enable) + if (is_supplicant_running == enable) return -EALREADY; if (enable == TRUE) @@ -155,7 +160,7 @@ int __execute_supplicant(gboolean enable) DBG("wpa_supplicant %s", enable == TRUE ? "started" : "stopped"); if (enable) - enabled = enable; + is_supplicant_running = enable; return 0; } -- 2.7.4