From 88f6519d3e01a4f1b116824a7a9cc7fe8fad510f Mon Sep 17 00:00:00 2001 From: Danny Jeongseok Seo Date: Thu, 19 Jul 2012 13:29:04 +0900 Subject: [PATCH] Revise Wi-Fi state management and signal filter handler --- debian/changelog | 9 +++++++ include/dbus.h | 15 ++++++----- packaging/net-config.spec | 2 +- src/dbus.c | 33 +++++++++++------------ src/signal-handler.c | 57 ++++++++++++++++++++------------------- src/wifi-state.c | 13 +++++---- 6 files changed, 69 insertions(+), 60 deletions(-) diff --git a/debian/changelog b/debian/changelog index ffbb126..536e7cf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +net-config (0.1.79) unstable; urgency=low + + * Revise net-config signal filter handler + * Revise Wi-Fi state management + * Git: slp/pkgs/n/net-config + * Tag: net-config_0.1.79 + + -- Danny Jeongseok Seo Wed, 09 May 2012 11:41:09 +0900 + net-config (0.1.78) unstable; urgency=low * Revise ConnMan profile prefix to fit ConnMan 0.78 diff --git a/include/dbus.h b/include/dbus.h index 68396ad..cf6a559 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -30,18 +30,21 @@ extern "C" { #include #include -#define CONNMAN_SERVICE "net.connman" -#define CONNMAN_PATH "/net/connman" +#define CONNMAN_SERVICE "net.connman" +#define CONNMAN_PATH "/net/connman" -#define SUPPLICANT_SERVICE "fi.w1.wpa_supplicant1" -#define SUPPLICANT_INTERFACE "fi.w1.wpa_supplicant1" -#define SUPPLICANT_PATH "/fi/w1/wpa_supplicant1" +#define SUPPLICANT_SERVICE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_INTERFACE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_PATH "/fi/w1/wpa_supplicant1" #define SUPPLICANT_GLOBAL_INTERFACE "org.freedesktop.DBus.Properties" #define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" #define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" #define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology" #define CONNMAN_MANAGER_PATH "/" + +#define CONNMAN_WIFI_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/wifi_" +#define CONNMAN_WIFI_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/wifi" #define DBUS_PATH_MAX_BUFLEN 512 #define DBUS_STATE_MAX_BUFLEN 64 @@ -56,7 +59,7 @@ struct dbus_input_arguments { void *data; }; -int netconfig_extract_service_state(DBusMessage *message, char **essid); +char *netconfig_wifi_get_connected_service_name(DBusMessage *message); int netconfig_extract_services_profile(DBusMessage *message, char **essid); DBusMessage *netconfig_invoke_dbus_method(const char *dest, DBusConnection *connection, const char *path, const char *interface_name, const char *method); diff --git a/packaging/net-config.spec b/packaging/net-config.spec index d605975..3c0b6ef 100644 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -2,7 +2,7 @@ Name: net-config Summary: TIZEN Network Configuration Module -Version: 0.1.78 +Version: 0.1.79 Release: 1 Group: System/Network License: Apache License Version 2.0 diff --git a/src/dbus.c b/src/dbus.c index cb952b3..7055061 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -543,9 +543,10 @@ DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest, return reply; } -int netconfig_extract_service_state(DBusMessage *message, char **essid) +char *netconfig_wifi_get_connected_service_name(DBusMessage *message) { - int state = -1; + int is_connected = 0; + char *essid_name = NULL; DBusMessageIter iter, array; dbus_message_iter_init(message, &iter); @@ -558,41 +559,37 @@ int netconfig_extract_service_state(DBusMessage *message, char **essid) dbus_message_iter_recurse(&array, &entry); dbus_message_iter_get_basic(&entry, &key); - if (strcmp(key, "State") == 0 && state - 1) { + if (g_str_equal(key, "State") == TRUE && is_connected == 0) { dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &string); if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&string, &key); - if (strcmp(key, "ready") == 0 || strcmp(key, "online") == 0) { - state = 1; - continue; - } - - return -1; + if (g_str_equal(key, "ready") == TRUE || g_str_equal(key, "online") == TRUE) + is_connected = 1; } - } else if (strcmp(key, "Name") == 0 && state == 1) { + } else if (g_str_equal(key, "Name") == TRUE) { dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &string); if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&string, &key); - if (*essid != NULL) - return -1; - - *essid = malloc(sizeof(char)*128); - strcpy(*essid, key); - - return 0; + essid_name = (char *)g_strdup(key); } } dbus_message_iter_next(&array); } - return -1; + if (is_connected == 1 && essid_name != NULL) + return essid_name; + + if (essid_name != NULL) + g_free(essid_name); + + return NULL; } int netconfig_extract_services_profile(DBusMessage *message, char **profile) diff --git a/src/signal-handler.c b/src/signal-handler.c index 6fe9f24..66e5453 100644 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -57,7 +57,7 @@ static int __netconfig_get_state(DBusMessage *msg, char *state) goto done; dbus_message_iter_get_basic(&iter, &key_name); - if (strcmp(key_name, "State") != 0) + if (g_str_equal(key_name, "State") != TRUE) goto done; dbus_message_iter_next(&iter); @@ -143,7 +143,6 @@ static void __netconfig_wifi_technology_state_signal_handler( static void netconfig_wifi_set_essid(const char *active_profile) { int err; - int state = -1; char *essid_name = NULL; DBusConnection *connection = NULL; DBusMessage *message = NULL; @@ -177,10 +176,10 @@ static void netconfig_wifi_set_essid(const char *active_profile) goto done; } - state = netconfig_extract_service_state(message, &essid_name); + essid_name = netconfig_wifi_get_connected_service_name(message); - if (state < 0) { - ERR("state is not ready"); + if (essid_name == NULL) { + ERR("Wi-Fi is not connected"); goto done; } @@ -189,10 +188,10 @@ static void netconfig_wifi_set_essid(const char *active_profile) ERR("Can't set essid [%d]", err); } -done: g_free(essid_name); essid_name = NULL; +done: dbus_message_unref(message); dbus_connection_unref(connection); @@ -212,14 +211,15 @@ static void __netconfig_wifi_service_state_signal_handler(DBusMessage *msg, cons return; if (__netconfig_get_state(msg, state) == NETCONFIG_NO_ERROR) { - int value = 0; + int wifi_state = 0; DBG("Signaled profile [%s] ==> state %s", profile, state); - vconf_get_int(VCONFKEY_WIFI_STATE, &value); + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + DBG("Current Wi-Fi state: %d", wifi_state); - if (strcmp(state, "ready") == 0 || strcmp(state, "online") == 0) { - if (value > VCONFKEY_WIFI_OFF && value != VCONFKEY_WIFI_CONNECTED) { + if (g_str_equal(state, "ready") == TRUE || g_str_equal(state, "online") == TRUE) { + if (wifi_state > VCONFKEY_WIFI_OFF && wifi_state != VCONFKEY_WIFI_CONNECTED) { INFO("Wifi connected"); @@ -234,26 +234,25 @@ static void __netconfig_wifi_service_state_signal_handler(DBusMessage *msg, cons g_strlcpy(current_profile, profile, sizeof(current_profile)); } - } else if (strcmp(state, "failure") == 0 || strcmp(state, "disconnect") == 0 || strcmp(state, "idle") == 0) { - if (value > VCONFKEY_WIFI_UNCONNECTED) { + } else if (g_str_equal(state, "failure") == TRUE || g_str_equal(state, "disconnect") == TRUE || g_str_equal(state, "idle") == TRUE) { + if (wifi_state > VCONFKEY_WIFI_UNCONNECTED) { INFO("Wifi [%s] Disconnected", profile); DBG("Current profile is %s", current_profile); - if ((strcmp(profile, current_profile)) == 0) { + if ((g_str_equal(profile, current_profile)) == TRUE) if ((vconf_set_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED)) < 0) ERR("Error!!! vconf_set_int failed"); + } - netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); - netconfig_wifi_unset_essid(); + netconfig_wifi_unset_essid(); - netconfig_wifi_indicator_stop(); + netconfig_wifi_indicator_stop(); - memset(current_profile, 0, sizeof(current_profile)); - } - } - } else if (strcmp(state, "association") == 0 || strcmp(state, "configuration") == 0) { + memset(current_profile, 0, sizeof(current_profile)); + } else if (g_str_equal(state, "association") == TRUE || g_str_equal(state, "configuration") == TRUE) { netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTING); } } else @@ -279,15 +278,16 @@ static DBusHandlerResult __netconfig_signal_filter_handler( } else if (dbus_message_is_signal(msg, CONNMAN_TECHNOLOGY_INTERFACE, CONNMAN_SIGNAL_PROPERTY_CHANGED)) { char *property = NULL; - char *tech_path = NULL; + char *technology_path = NULL; sigvalue = __netconfig_get_property(msg, &property); if (sigvalue == NULL) return DBUS_HANDLER_RESULT_HANDLED; - tech_path = (char *)dbus_message_get_path(msg); + technology_path = (char *)dbus_message_get_path(msg); + INFO("technology object path: %s", technology_path); - if (strstr(tech_path, "/wifi") != NULL) { + if (g_str_has_prefix(technology_path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) { __netconfig_wifi_technology_state_signal_handler((const char *)sigvalue, (const char *)property); return DBUS_HANDLER_RESULT_HANDLED; } @@ -300,13 +300,14 @@ static DBusHandlerResult __netconfig_signal_filter_handler( if (sigvalue == NULL) return DBUS_HANDLER_RESULT_HANDLED; - if (strcmp(sigvalue, "State") == 0) { - char *profile = NULL; + if (g_str_equal(sigvalue, "State") == TRUE) { + char *service_profile = NULL; - profile = (char *)dbus_message_get_path(msg); + service_profile = (char *)dbus_message_get_path(msg); + INFO("service profile: %s", service_profile); - if (strstr(profile, "wifi_") != NULL) { - __netconfig_wifi_service_state_signal_handler(msg, profile); + if (g_str_has_prefix(service_profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE) { + __netconfig_wifi_service_state_signal_handler(msg, service_profile); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } } diff --git a/src/wifi-state.c b/src/wifi-state.c index 2e23378..d1db0fa 100644 --- a/src/wifi-state.c +++ b/src/wifi-state.c @@ -40,7 +40,6 @@ void netconfig_wifi_state_set_service_state( static GSList *__netconfig_wifi_state_get_service_profiles(DBusMessage *message) { - char *wifi_service_prefix = CONNMAN_PATH "/service/wifi_"; GSList *service_profiles = NULL; DBusMessageIter iter, dict; @@ -72,7 +71,7 @@ static GSList *__netconfig_wifi_state_get_service_profiles(DBusMessage *message) while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) { dbus_message_iter_get_basic(&value, &object_path); - if (g_str_has_prefix(object_path, wifi_service_prefix) == TRUE) + if (g_str_has_prefix(object_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE) service_profiles = g_slist_append(service_profiles, g_strdup(object_path)); dbus_message_iter_next(&value); @@ -256,8 +255,8 @@ gchar *netconfig_wifi_get_technology_state(void) dbus_message_iter_recurse(&dict, &key_iter); dbus_message_iter_get_basic(&key_iter, &key); - if (strcmp(key, "AvailableTechnologies") == 0 || - strcmp(key, "EnabledTechnologies") == 0) { + if (g_str_equal(key, "AvailableTechnologies") == TRUE || + g_str_equal(key, "EnabledTechnologies") == TRUE) { dbus_message_iter_next(&key_iter); dbus_message_iter_recurse(&key_iter, &sub_iter1); @@ -269,10 +268,10 @@ gchar *netconfig_wifi_get_technology_state(void) while (dbus_message_iter_get_arg_type(&sub_iter2) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&sub_iter2, &tech_name); - if (tech_name != NULL && strcmp(tech_name, "wifi") == 0) { - if (strcmp(key, "AvailableTechnologies") == 0) + if (tech_name != NULL && g_str_equal(tech_name, "wifi") == TRUE) { + if (g_str_equal(key, "AvailableTechnologies") == TRUE) wifi_tech_available = TRUE; - else if (strcmp(key, "EnabledTechnologies") == 0) + else if (g_str_equal(key, "EnabledTechnologies") == TRUE) wifi_tech_enabled = TRUE; } -- 2.34.1