From 3ef6fac5f724ba66b948289d015864c640c1c580 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Wed, 16 Sep 2020 23:11:10 +0530 Subject: [PATCH] Maintain list for active wifi interfaces Change-Id: I6a0f60f54f2fcfa1ef641fecea32334a522ebe06 Signed-off-by: Nishant Chaprana --- packaging/net-config.spec | 2 +- src/wifi-firmware.c | 119 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 105 insertions(+), 16 deletions(-) diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 7ec90a7..d0d46f4 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.2.1 +Version: 1.2.2 Release: 3 Group: System/Network License: Apache-2.0 diff --git a/src/wifi-firmware.c b/src/wifi-firmware.c index 284973c..3908ad0 100755 --- a/src/wifi-firmware.c +++ b/src/wifi-firmware.c @@ -38,6 +38,88 @@ #define TEMP_BUFFER_LEN 100 #define WIFI_MAC_ADD_PATH "/sys/class/net/wlan0/address" +typedef struct { + char *interface_name; + enum netconfig_wifi_firmware type; +} wifi_driver_s; + +static GSList *wifi_driver_list; + +static void __netconfig_wifi_driver_free(gpointer data) +{ + wifi_driver_s *driver = (wifi_driver_s *) data; + + DBG("Remove wifi driver [%d:%s]", driver->type, driver->interface_name); + + g_free(driver->interface_name); + g_free(driver); +} + +static gint __netconfig_cmp_wifi_driver(gconstpointer a, gconstpointer b) +{ + wifi_driver_s *drv_a = (wifi_driver_s *)a; + wifi_driver_s *drv_b = (wifi_driver_s *)b; + + if (g_strcmp0(drv_a->interface_name, drv_b->interface_name)) + return -1; + + return 0; +} + +static GSList * __netconfig_is_wifi_driver_in_list( + enum netconfig_wifi_firmware type, const char *interface_name) +{ + wifi_driver_s driver = { .type = type, .interface_name = (char *)interface_name }; + GSList *found = g_slist_find_custom(wifi_driver_list, &driver, + __netconfig_cmp_wifi_driver); + + return found; +} + +static gboolean __netconfig_add_wifi_driver_to_list( + enum netconfig_wifi_firmware type, const char *interface_name) +{ + GSList *found; + wifi_driver_s *driver; + + found = __netconfig_is_wifi_driver_in_list(type, interface_name); + if (found) + return FALSE; + + driver = g_try_new0(wifi_driver_s, 1); + if (!driver) { + ERR("g_try_new0 failed!!!"); + return FALSE; + } + + driver->interface_name = g_strdup(interface_name); + if (!driver->interface_name) { + ERR("g_strdup failed!!!"); + g_free(driver); + return FALSE; + } + + driver->type = type; + + wifi_driver_list = g_slist_prepend(wifi_driver_list, driver); + return TRUE; +} + +static gboolean __netconfig_remove_wifi_driver_from_list( + enum netconfig_wifi_firmware type, const char *interface_name) +{ + GSList *found; + + found = __netconfig_is_wifi_driver_in_list(type, interface_name); + if (!found) + return FALSE; + + __netconfig_wifi_driver_free(found->data); + wifi_driver_list = g_slist_delete_link(wifi_driver_list, found); + + return TRUE; +} + static int __netconfig_sta_firmware_start(const char *interface_name) { int rv = 0; @@ -284,31 +366,38 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, const char *interface_name, gboolean enable) { int err; - static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF; - enum netconfig_wifi_firmware alias = type; - DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type, - enable == TRUE ? "enable" : "disable"); + DBG("Wi-Fi firmware (type: %d %s) for %s", type, enable == TRUE ? "enable" : "disable", + interface_name ? interface_name : ""); + + GSList *found = __netconfig_is_wifi_driver_in_list(type, interface_name); if (enable == FALSE) { - if (current_driver == NETCONFIG_WIFI_OFF) { + wifi_driver_s *driver; + + if (!found) return -EALREADY; - } else if (current_driver == alias) { - err = __netconfig_wifi_firmware_stop(type, interface_name); - if (err < 0 && err != -EALREADY) - return err; + driver = (wifi_driver_s *) found->data; - current_driver = NETCONFIG_WIFI_OFF; + if (type != driver->type) + return -EIO; + err = __netconfig_wifi_firmware_stop(type, interface_name); + if (err < 0 && err != -EALREADY) return err; - } - return -EIO; + __netconfig_remove_wifi_driver_from_list(type, interface_name); + + return err; } - if (current_driver > NETCONFIG_WIFI_OFF) { - if (current_driver == alias) + if (found) { + wifi_driver_s *driver = (wifi_driver_s *) found->data; + + DBG("Wi-Fi interface (%s) already in use", interface_name); + + if (type == driver->type) return -EALREADY; return -EIO; @@ -318,7 +407,7 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, if (err < 0) DBG("Failed to execute script file"); else - current_driver = alias; + __netconfig_add_wifi_driver_to_list(type, interface_name); if (__netconfig_set_rps_cpus(interface_name) < 0) DBG("Failed to set rps_cpus"); -- 2.7.4