[net-config] Suspend/Resume WLAN driver
[platform/core/connectivity/net-config.git] / src / wifi-state.c
index 1c671e9..237e2e0 100755 (executable)
  *
  */
 
-#include <aul.h>
 #include <vconf.h>
 #include <vconf-keys.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <eventsystem.h>
 
 #include "log.h"
 #include "util.h"
 static gboolean new_bss_found = FALSE;
 static guint network_noti_timer_id = 0;
 
-static enum netconfig_wifi_service_state
-       wifi_service_state = NETCONFIG_WIFI_UNKNOWN;
-static enum netconfig_wifi_tech_state
-       wifi_technology_state = NETCONFIG_WIFI_TECH_UNKNOWN;
+static wifi_service_state_e g_service_state = NETCONFIG_WIFI_UNKNOWN;
+static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
 
 static GSList *notifier_list = NULL;
 
+static guint network_connected_popup_timer_id = 0;
+static gboolean block_network_connected_popup = FALSE;
 
-static void __netconfig_pop_wifi_connected_poppup(const char *ssid)
+char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type)
 {
-       bundle *b = NULL;
-
-       if (ssid == NULL)
-               return;
-
-       b = bundle_create();
+       switch (wifi_service_state_type) {
+       case NETCONFIG_WIFI_UNKNOWN:
+               return "unknown";
+       case NETCONFIG_WIFI_IDLE:
+               return "idle";
+       case NETCONFIG_WIFI_ASSOCIATION:
+               return "association";
+       case NETCONFIG_WIFI_CONFIGURATION:
+               return "configuration";
+       case NETCONFIG_WIFI_CONNECTED:
+               return "connected";
+       case NETCONFIG_WIFI_FAILURE:
+               return "failure";
+       default:
+               ERR("Invalid wifi_service_state_e parameter");
+               break;
+       }
 
-       bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup");
-       bundle_add(b, "_SYSPOPUP_TYPE_", "notification");
-       bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected");
-       bundle_add(b, "_AP_NAME_", ssid);
+       return "Invalid parameter";
+}
 
-       DBG("Launch Wi-Fi connected alert network popup");
-       aul_launch_app("net.netpopup", b);
+char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type)
+{
+       switch (wifi_tech_state_type) {
+       case NETCONFIG_WIFI_TECH_UNKNOWN:
+               return "unknown";
+       case NETCONFIG_WIFI_TECH_OFF:
+               return "off";
+       case NETCONFIG_WIFI_TECH_WPS_ONLY:
+               return "wps only";
+       case NETCONFIG_WIFI_TECH_POWERED:
+               return "powered";
+       case NETCONFIG_WIFI_TECH_CONNECTED:
+               return "connected";
+       case NETCONFIG_WIFI_TECH_TETHERED:
+               return "tethered";
+       default:
+               ERR("Invalid wifi_tech_state_e parameter");
+               break;
+       }
 
-       bundle_free(b);
+       return "Invalid parameter";
 }
 
-static void __netconfig_wifi_state_connected_activation(void)
+static gboolean _block_network_connection_popup(gpointer data)
 {
-       /* Add activation of services when Wi-Fi is connected */
-       bundle *b = NULL;
-
-       b = bundle_create();
-       aul_launch_app("com.samsung.keepit-service-standby", b);
-       bundle_free(b);
+       block_network_connected_popup = FALSE;
+       netconfig_stop_timer(&network_connected_popup_timer_id);
+       return FALSE;
 }
 
-static void __netconfig_wifi_set_essid(void)
+static void __set_wifi_connected_essid(void)
 {
        const char *essid_name = NULL;
        const char *wifi_profile = netconfig_get_default_profile();
 
-       if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
+       if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
                return;
 
        if (wifi_profile == NULL ||
@@ -100,15 +119,46 @@ static void __netconfig_wifi_set_essid(void)
 
        netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name);
 
-       __netconfig_pop_wifi_connected_poppup(essid_name);
+       /* Block Network Connected popup for 3sec
+        * to avoid multiple popup's due to ready signals */
+       if (block_network_connected_popup == FALSE) {
+               block_network_connected_popup = TRUE;
+               netconfig_start_timer(3000, _block_network_connection_popup,
+                               NULL, &network_connected_popup_timer_id);
+               __netconfig_pop_wifi_connected_poppup(essid_name);
+       }
 }
 
-static void __netconfig_wifi_unset_essid(void)
+static void __unset_wifi_connected_essid(void)
 {
        netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, "");
 }
 
-static gboolean __netconfig_is_wifi_profile_available(void)
+static const char *__get_wifi_connected_essid(void)
+{
+       const char *essid_name = NULL;
+       const char *wifi_profile = NULL;
+
+       if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
+               return NULL;
+
+       wifi_profile = netconfig_get_default_profile();
+
+       if (wifi_profile == NULL || netconfig_is_wifi_profile(wifi_profile) != TRUE) {
+               ERR("Can't get Wi-Fi profile");
+               return NULL;
+       }
+
+       essid_name = netconfig_wifi_get_connected_essid(wifi_profile);
+       if (essid_name == NULL) {
+               ERR("Can't get Wi-Fi name");
+               return NULL;
+       }
+
+       return essid_name;
+}
+
+static gboolean __is_wifi_profile_available(void)
 {
        GVariant *message = NULL;
        GVariantIter *iter, *next;
@@ -124,9 +174,8 @@ static gboolean __netconfig_is_wifi_profile_available(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
-               if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE) {
+               if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE)
                        continue;
-               }
 
                g_variant_iter_free(next);
                g_free(obj);
@@ -140,7 +189,7 @@ static gboolean __netconfig_is_wifi_profile_available(void)
        return TRUE;
 }
 
-static gboolean __netconfig_wifi_is_favorited(GVariantIter *array)
+static gboolean __is_favorited(GVariantIter *array)
 {
        gboolean is_favorite = FALSE;
        gchar *key;
@@ -149,9 +198,8 @@ static gboolean __netconfig_wifi_is_favorited(GVariantIter *array)
        while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
                gboolean value;
 
-               if (g_str_equal(key, "Favorite") != TRUE) {
+               if (g_str_equal(key, "Favorite") != TRUE)
                        continue;
-               }
 
                value = g_variant_get_boolean(var);
                if (value)
@@ -164,7 +212,83 @@ static gboolean __netconfig_wifi_is_favorited(GVariantIter *array)
        return is_favorite;
 }
 
-static char *__netconfig_wifi_get_connman_favorite_service(void)
+static void _wifi_state_connected_activation(void)
+{
+       /* Add activation of services when Wi-Fi is connected */
+}
+
+static void _wifi_state_changed(wifi_service_state_e state)
+{
+       GSList *list;
+
+       for (list = notifier_list; list; list = list->next) {
+               wifi_state_notifier *notifier = list->data;
+
+               if (notifier->wifi_state_changed != NULL)
+                       notifier->wifi_state_changed(state, notifier->user_data);
+       }
+}
+
+static void _set_bss_found(gboolean found)
+{
+       if (found != new_bss_found)
+               new_bss_found = found;
+}
+
+static gboolean _check_network_notification(gpointer data)
+{
+       int qs_enable = 0, ug_state = 0;
+       static gboolean check_again = FALSE;
+
+       wifi_tech_state_e tech_state;
+       wifi_service_state_e service_state;
+
+       tech_state = wifi_state_get_technology_state();
+       if (tech_state < NETCONFIG_WIFI_TECH_POWERED) {
+               DBG("Wi-Fi off or WPS only supported[%d]", tech_state);
+               goto cleanup;
+       }
+
+       service_state = wifi_state_get_service_state();
+       if (service_state == NETCONFIG_WIFI_CONNECTED) {
+               DBG("Service state is connected");
+               goto cleanup;
+       } else if (service_state == NETCONFIG_WIFI_ASSOCIATION ||
+               service_state == NETCONFIG_WIFI_CONFIGURATION) {
+               DBG("Service state is connecting (check again : %d)", check_again);
+               if (!check_again) {
+                       check_again = TRUE;
+                       return TRUE;
+               } else
+                       check_again = FALSE;
+       }
+
+       if (__is_wifi_profile_available() == FALSE) {
+               netconfig_send_notification_to_net_popup(
+               NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
+               goto cleanup;
+       }
+
+       netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
+       if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) {
+               DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE");
+               goto cleanup;
+       }
+
+       netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
+       if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
+               goto cleanup;
+
+       netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL);
+
+       _set_bss_found(FALSE);
+
+cleanup:
+       netconfig_stop_timer(&network_noti_timer_id);
+       return FALSE;
+}
+
+static char *_get_connman_favorite_service(void)
 {
        char *favorite_service = NULL;
        GVariant *message = NULL;
@@ -181,11 +305,10 @@ static char *__netconfig_wifi_get_connman_favorite_service(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
-               if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE) {
+               if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE)
                        continue;
-               }
 
-               if (__netconfig_wifi_is_favorited(next) == TRUE) {
+               if (__is_favorited(next) == TRUE) {
                        favorite_service = g_strdup(obj);
                        g_free(obj);
                        g_variant_iter_free(next);
@@ -199,68 +322,34 @@ static char *__netconfig_wifi_get_connman_favorite_service(void)
        return favorite_service;
 }
 
-static void __netconfig_wifi_state_changed(
-               enum netconfig_wifi_service_state state)
+static void __notification_value_changed_cb(keynode_t *node, void *user_data)
 {
-       GSList *list;
-
-       for (list = notifier_list; list; list = list->next) {
-               struct netconfig_wifi_state_notifier *notifier = list->data;
+       int value = -1;
 
-               if (notifier->netconfig_wifi_state_changed != NULL)
-                       notifier->netconfig_wifi_state_changed(state, notifier->user_data);
-       }
-}
+       if (netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0)
+               return;
 
-void netconfig_wifi_set_bss_found(const gboolean found)
-{
-       if (found != new_bss_found)
-               new_bss_found = found;
+       if (value == VCONFKEY_WIFI_QS_DISABLE)
+               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
 }
 
-gboolean netconfig_wifi_is_bss_found(void)
+static void _register_network_notification(void)
 {
-       return new_bss_found;
+#if defined TIZEN_WEARABLE
+       return;
+#endif
+       vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb, NULL);
 }
 
-static void __netconfig_wifi_state_set_power_save(gboolean power_save)
+static void _deregister_network_notification(void)
 {
-       gboolean result;
-       const char *if_path;
-       GVariant *input_args = NULL;
-       static gboolean old_state = TRUE;
-       const gchar *args_disable = "POWERMODE 1";
-       const gchar *args_enable = "POWERMODE 0";
-       if (old_state == power_save)
-               return;
-
-       if_path = netconfig_wifi_get_supplicant_interface();
-       if (if_path == NULL) {
-               ERR("Fail to get wpa_supplicant DBus path");
+#if defined TIZEN_WEARABLE
                return;
-       }
-
-       if (power_save)
-               input_args = g_variant_new_string(args_enable);
-       else
-               input_args = g_variant_new_string(args_disable);
-
-       result = netconfig_supplicant_invoke_dbus_method_nonblock(
-                       SUPPLICANT_SERVICE,
-                       if_path,
-                       SUPPLICANT_INTERFACE ".Interface",
-                       "Driver",
-                       input_args,
-                       NULL);
-       if (result == FALSE)
-               ERR("Fail to set power save mode POWERMODE %d", power_save);
-       else
-               old_state = power_save;
-
-       return;
+#endif
+       vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb);
 }
 
-static void __netconfig_wifi_state_set_power_lock(gboolean power_lock)
+static void _set_power_lock(gboolean power_lock)
 {
        gint32 ret = 0;
        GVariant *reply;
@@ -297,43 +386,169 @@ static void __netconfig_wifi_state_set_power_lock(gboolean power_lock)
                        "org.tizen.system.deviced.display",
                        lock_method,
                        params);
-       if (reply == NULL){
+       if (reply == NULL) {
                ERR("Failed to set_power_lock");
                return;
        }
 
-       ret = g_variant_get_int32(reply);
-       if (ret < 0)
-               ERR("Failed to set power lock %s with ret %d",
+       if (g_variant_is_of_type(reply, G_VARIANT_TYPE_INT32)) {
+               ret = g_variant_get_int32(reply);
+               if (ret < 0)
+                       ERR("Failed to set power lock %s with ret %d",
                                power_lock == TRUE ? "enable" : "disable", ret);
-       else
-               old_state = power_lock;
+               else
+                       old_state = power_lock;
+       }
+
+       g_variant_unref(reply);
 
        return;
 }
 
-void netconfig_wifi_state_set_service_state(
-               enum netconfig_wifi_service_state new_state)
+void wifi_state_emit_power_completed(gboolean power_on)
+{
+       if (power_on)
+               wifi_emit_power_on_completed((Wifi *)get_wifi_object());
+       else
+               wifi_emit_power_off_completed((Wifi *)get_wifi_object());
+
+       DBG("Successfully sent signal [%s]", (power_on) ? "powerOn" : "powerOff");
+}
+
+void wifi_state_emit_power_failed(void)
+{
+       wifi_emit_power_operation_failed((Wifi *)get_wifi_object());
+
+       DBG("Successfully sent signal [PowerOperationFailed]");
+}
+
+void wifi_state_update_power_state(gboolean powered)
+{
+       wifi_tech_state_e tech_state;
+
+       /* It's automatically updated by signal-handler
+        * DO NOT update manually
+        * It includes Wi-Fi state configuration
+        */
+       tech_state = wifi_state_get_technology_state();
+
+       if (powered == TRUE) {
+               if (tech_state < NETCONFIG_WIFI_TECH_POWERED && netconfig_is_wifi_tethering_on() != TRUE) {
+                       DBG("Wi-Fi turned on or waken up from power-save mode");
+
+                       wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
+
+                       wifi_state_emit_power_completed(TRUE);
+
+                       netconfig_wifi_device_picker_service_start();
+
+                       netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_UNCONNECTED);
+                       netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
+                       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
+
+                       netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
+
+                       netconfig_wifi_bgscan_stop();
+                       netconfig_wifi_bgscan_set_interval(SCAN_EXPONENTIAL_MIN);
+                       netconfig_wifi_bgscan_start(TRUE);
+
+                       /* Add callback to track change in notification setting */
+                       _register_network_notification();
+               }
+       } else if (tech_state > NETCONFIG_WIFI_TECH_OFF) {
+               DBG("Wi-Fi turned off or in power-save mode");
+
+               wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY);
+
+               netconfig_wifi_device_picker_service_stop();
+
+               wifi_power_disable_technology_state_by_only_connman_signal();
+               wifi_power_driver_and_supplicant(FALSE);
+
+               wifi_state_emit_power_completed(FALSE);
+
+               netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF);
+               netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
+               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
+
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF);
+
+               netconfig_wifi_bgscan_stop();
+
+               _set_bss_found(FALSE);
+
+               /* Inform net-popup to remove the wifi found notification */
+               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
+               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
+               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_IP_CONFLICT_NOTI, NULL);
+
+               _deregister_network_notification();
+       }
+}
+
+char *wifi_get_favorite_service(void)
+{
+       return _get_connman_favorite_service();
+}
+
+void wifi_start_timer_network_notification(void)
+{
+#if defined TIZEN_WEARABLE
+               /* In case of wearable device, no need to notify available Wi-Fi APs */
+               return ;
+#endif
+       netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, _check_network_notification, NULL, &network_noti_timer_id);
+}
+
+void wifi_state_notifier_register(wifi_state_notifier *notifier)
+{
+       DBG("register notifier");
+
+       notifier_list = g_slist_append(notifier_list, notifier);
+}
+
+void wifi_state_notifier_unregister(wifi_state_notifier *notifier)
+{
+       DBG("un-register notifier");
+
+       notifier_list = g_slist_remove_all(notifier_list, notifier);
+}
+
+void wifi_state_notifier_cleanup(void)
+{
+       g_slist_free_full(notifier_list, NULL);
+}
+
+void wifi_state_set_bss_found(gboolean found)
+{
+       _set_bss_found(found);
+}
+
+gboolean wifi_state_is_bss_found(void)
+{
+       return new_bss_found;
+}
+
+void wifi_state_set_service_state(wifi_service_state_e new_state)
 {
        static gboolean dhcp_stage = FALSE;
-       enum netconfig_wifi_service_state old_state = wifi_service_state;
+       wifi_service_state_e old_state = g_service_state;
 
        if (old_state == new_state)
                return;
 
-       wifi_service_state = new_state;
-       DBG("Wi-Fi state %d ==> %d", old_state, new_state);
+       g_service_state = new_state;
+       DBG("Wi-Fi service state, old state[%s] ==> new state[%s]",
+               _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state));
 
-       /* During DHCP, temporarily disable Wi-Fi power saving */
-       if ((old_state < NETCONFIG_WIFI_ASSOCIATION ||
-                       old_state == NETCONFIG_WIFI_FAILURE) &&
-                       new_state == NETCONFIG_WIFI_CONFIGURATION) {
-               __netconfig_wifi_state_set_power_lock(TRUE);
-               __netconfig_wifi_state_set_power_save(FALSE);
+       /* From association, temporarily disable Wi-Fi power saving */
+       if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_ASSOCIATION) {
+               _set_power_lock(TRUE);
+               wifi_set_early_suspend(FALSE);
                dhcp_stage = TRUE;
-       } else if (dhcp_stage == TRUE) {
-               __netconfig_wifi_state_set_power_lock(FALSE);
-               __netconfig_wifi_state_set_power_save(TRUE);
+       } else if (dhcp_stage == TRUE && new_state != NETCONFIG_WIFI_CONFIGURATION) {
+               _set_power_lock(FALSE);
+               wifi_set_early_suspend(TRUE);
                dhcp_stage = FALSE;
        }
 
@@ -341,82 +556,72 @@ void netconfig_wifi_state_set_service_state(
                netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
 
                netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED);
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE,
-                                                                       VCONFKEY_NETWORK_WIFI_CONNECTED);
+               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED);
 
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED);
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED);
 
-               __netconfig_wifi_set_essid();
+               __set_wifi_connected_essid();
 
                netconfig_wifi_indicator_start();
        } else if (old_state == NETCONFIG_WIFI_CONNECTED) {
                netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
 
-               __netconfig_wifi_unset_essid();
+               __unset_wifi_connected_essid();
 
                netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE,
-                                                                       VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
+               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
 
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
 
                netconfig_wifi_indicator_stop();
 
-               netconfig_wifi_set_bgscan_pause(FALSE);
-
                netconfig_wifi_bgscan_stop();
+               netconfig_wifi_bgscan_set_interval(SCAN_EXPONENTIAL_MIN);
                netconfig_wifi_bgscan_start(TRUE);
-       } else if ( (old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED)
-                                       && new_state == NETCONFIG_WIFI_IDLE){
-               //in ipv6 case disconnect/association -> association
+       } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) {
+               /* in ipv6 case disconnect/association -> association */
                DBG("reset the bg scan period");
-               netconfig_wifi_set_bgscan_pause(FALSE);
 
                netconfig_wifi_bgscan_stop();
                netconfig_wifi_bgscan_start(TRUE);
        }
 
-       __netconfig_wifi_state_changed(new_state);
+       _wifi_state_changed(new_state);
 
-       if (new_state == NETCONFIG_WIFI_CONNECTED){
-               __netconfig_wifi_state_connected_activation();
-#if defined TIZEN_WEARABLE
-               wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
-#endif
-       }
+       if (new_state == NETCONFIG_WIFI_CONNECTED)
+               _wifi_state_connected_activation();
 }
 
-enum netconfig_wifi_service_state
-netconfig_wifi_state_get_service_state(void)
+wifi_service_state_e wifi_state_get_service_state(void)
 {
-       return wifi_service_state;
+       return g_service_state;
 }
 
-void netconfig_wifi_state_set_technology_state(
-               enum netconfig_wifi_tech_state new_state)
+void wifi_state_set_tech_state(wifi_tech_state_e new_state)
 {
-       enum netconfig_wifi_tech_state old_state = wifi_technology_state;
+       wifi_tech_state_e old_state = g_tech_state;
 
        if (old_state == new_state)
                return;
 
-       wifi_technology_state = new_state;
+       g_tech_state = new_state;
 
-       DBG("Wi-Fi technology state %d ==> %d", old_state, new_state);
+       DBG("Wi-Fi technology state, old state[%s] ==> new state[%s]",
+               _convert_wifi_technology_state_to_string(old_state), _convert_wifi_technology_state_to_string(new_state));
 }
 
-enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void)
+wifi_tech_state_e wifi_state_get_technology_state(void)
 {
        GVariant *message = NULL, *variant;
        GVariantIter *iter, *next;
-       enum netconfig_wifi_tech_state ret = NETCONFIG_WIFI_TECH_OFF;
+       wifi_tech_state_e ret = NETCONFIG_WIFI_TECH_OFF;
        gboolean wifi_tech_powered = FALSE;
        gboolean wifi_tech_connected = FALSE;
        const char *path;
        gchar *key;
 
-       if (wifi_technology_state > NETCONFIG_WIFI_TECH_UNKNOWN)
-               return wifi_technology_state;
+       if (g_tech_state > NETCONFIG_WIFI_TECH_UNKNOWN)
+               return g_tech_state;
 
        message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
                        CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
@@ -428,9 +633,8 @@ enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
-               if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0) {
+               if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
                        continue;
-               }
 
                while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
                        const gchar *sdata = NULL;
@@ -440,24 +644,23 @@ enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void)
                                data = g_variant_get_boolean(variant);
                                DBG("key-[%s] - %s", key, data ? "True" : "False");
 
-                               if (strcmp(key, "Powered") == 0 && data) {
+                               if (strcmp(key, "Powered") == 0 && data)
                                        wifi_tech_powered = TRUE;
-                               } else if (strcmp(key, "Connected") == 0 && data) {
+                               else if (strcmp(key, "Connected") == 0 && data)
                                        wifi_tech_connected = TRUE;
-                               } else if (strcmp(key, "Tethering") == 0 && data) {
-                                       // For further use
-                               }
+                               /* For further use
+                               else if (strcmp(key, "Tethering") == 0 && data) {
+                               } */
                        } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
                                sdata = g_variant_get_string(variant, NULL);
                                DBG("%s", sdata);
                        }
                }
-               g_variant_iter_free (next);
        }
 
        g_variant_unref(message);
 
-       g_variant_iter_free (iter);
+       g_variant_iter_free(iter);
 
        if (wifi_tech_powered == TRUE)
                ret = NETCONFIG_WIFI_TECH_POWERED;
@@ -465,218 +668,101 @@ enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void)
        if (wifi_tech_connected == TRUE)
                ret = NETCONFIG_WIFI_TECH_CONNECTED;
 
-       wifi_technology_state = ret;
-
-       return wifi_technology_state;
-}
-
-void netconfig_wifi_notify_power_failed(void)
-{
-       wifi_emit_power_operation_failed((Wifi *)get_netconfig_wifi_object());
-
-       DBG("Successfully sent signal [PowerOperationFailed]");
-}
-
-void netconfig_wifi_notify_power_completed(gboolean power_on)
-{
-       if (power_on)
-               wifi_emit_power_on_completed((Wifi *)get_netconfig_wifi_object());
-       else
-               wifi_emit_power_off_completed((Wifi *)get_netconfig_wifi_object());
+       g_tech_state = ret;
 
-       DBG("Successfully sent signal [%s]",(power_on)?"powerOn":"powerOff");
+       return g_tech_state;
 }
 
-static void __netconfig_notification_value_changed_cb(
-               keynode_t *node, void *user_data)
+gboolean wifi_state_is_technology_available(void)
 {
-       int value = -1;
+       GVariant *message = NULL;
+       GVariantIter *iter, *next;
+       const char *path;
+       gboolean ret = FALSE;
 
-       if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0) {
-               return;
+       message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
+                       CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
+                       "GetTechnologies", NULL);
+       if (message == NULL) {
+               ERR("Failed to get_technology_state");
+               return FALSE;
        }
 
-       if (value == VCONFKEY_WIFI_QS_DISABLE) {
-               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI,
-                               NULL);
+       g_variant_get(message, "(a(oa{sv}))", &iter);
+       while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
+               if (path != NULL && g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == 0)
+                       ret = TRUE;
        }
-}
 
-static void __netconfig_register_network_notification(void)
-{
-#if defined TIZEN_WEARABLE
-       return;
-#endif
-       vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS,
-                       __netconfig_notification_value_changed_cb, NULL);
-}
+       g_variant_unref(message);
+       g_variant_iter_free(iter);
 
-static void __netconfig_deregister_network_notification(void)
-{
-#if defined TIZEN_WEARABLE
-               return;
-#endif
-       vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS,
-                       __netconfig_notification_value_changed_cb);
+       DBG("Wi-Fi technology is %s", ret ? "available" : "unavailable");
+       return ret;
 }
 
-void netconfig_wifi_update_power_state(gboolean powered)
+void wifi_state_set_connected_essid(void)
 {
-       enum netconfig_wifi_tech_state wifi_tech_state;
-
-       /* It's automatically updated by signal-handler
-        * DO NOT update manually
-        * It includes Wi-Fi state configuration
-        */
-       wifi_tech_state = netconfig_wifi_state_get_technology_state();
-
-       if (powered == TRUE) {
-               if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED &&
-                                               netconfig_is_wifi_tethering_on() != TRUE) {
-                       DBG("Wi-Fi turned on or waken up from power-save mode");
-
-                       netconfig_wifi_state_set_technology_state(
-                                                                               NETCONFIG_WIFI_TECH_POWERED);
-
-                       netconfig_wifi_notify_power_completed(TRUE);
-
-                       netconfig_wifi_device_picker_service_start();
-
-                       netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE,
-                                                                               VCONFKEY_WIFI_UNCONNECTED);
-                       netconfig_set_vconf_int(VCONFKEY_WIFI_STATE,
-                                                                               VCONFKEY_WIFI_UNCONNECTED);
-                       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE,
-                                                                               VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
-
-                       netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
-
-                       netconfig_wifi_bgscan_stop();
-                       netconfig_wifi_bgscan_start(TRUE);
-
-                       /* Add callback to track change in notification setting */
-                       __netconfig_register_network_notification();
-               }
-       } else if (wifi_tech_state > NETCONFIG_WIFI_TECH_OFF) {
-               DBG("Wi-Fi turned off or in power-save mode");
-
-               netconfig_wifi_state_set_technology_state(
-                                                                               NETCONFIG_WIFI_TECH_WPS_ONLY);
-
-               netconfig_wifi_device_picker_service_stop();
-
-               netconfig_wifi_disable_technology_state_by_only_connman_signal();
-               netconfig_wifi_driver_and_supplicant(FALSE);
-
-               netconfig_wifi_notify_power_completed(FALSE);
-
-               netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF);
-               netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE,
-                                                                               VCONFKEY_NETWORK_WIFI_OFF);
-
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF);
-
-               netconfig_wifi_set_bgscan_pause(FALSE);
-               netconfig_wifi_bgscan_stop();
-
-               netconfig_wifi_set_bss_found(FALSE);
-
-               /* Inform net-popup to remove the wifi found notification */
-               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
-               netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
-
-               __netconfig_deregister_network_notification();
-
-       }
+       __set_wifi_connected_essid();
 }
 
-char *netconfig_wifi_get_favorite_service(void)
+void wifi_state_get_connected_essid(gchar **essid)
 {
-       return __netconfig_wifi_get_connman_favorite_service();
+       *essid = g_strdup(__get_wifi_connected_essid());
 }
 
-static gboolean __netconfig_wifi_check_network_notification(gpointer data)
+/*     wifi_connection_state_e in CAPI
+ *
+ *     WIFI_CONNECTION_STATE_FAILURE           = -1
+ *     WIFI_CONNECTION_STATE_DISCONNECTED      = 0
+ *     WIFI_CONNECTION_STATE_ASSOCIATION       = 1
+ *     WIFI_CONNECTION_STATE_CONFIGURATION     = 2
+ *     WIFI_CONNECTION_STATE_CONNECTED         = 3
+ */
+/*     connection_wifi_state_e in CAPI
+ *
+ *     CONNECTION_WIFI_STATE_DEACTIVATED       = 0
+ *     CONNECTION_WIFI_STATE_DISCONNECTED      = 1
+ *     CONNECTION_WIFI_STATE_CONNECTED         = 2
+ */
+gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context)
 {
-       int qs_enable = 0, ug_state = 0;
-       static gboolean check_again = FALSE;
-
-       enum netconfig_wifi_tech_state wifi_tech_state;
-       enum netconfig_wifi_service_state wifi_service_state;
-
-       wifi_tech_state = netconfig_wifi_state_get_technology_state();
-       if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) {
-               DBG("Wi-Fi off or WPS only supported[%d]", wifi_tech_state);
-               goto cleanup;
-       }
-
-       wifi_service_state = netconfig_wifi_state_get_service_state();
-       if (wifi_service_state == NETCONFIG_WIFI_CONNECTED) {
-               DBG("Service state is connected");
-               goto cleanup;
-       } else if (wifi_service_state == NETCONFIG_WIFI_ASSOCIATION ||
-               wifi_service_state == NETCONFIG_WIFI_CONFIGURATION) {
-               DBG("Service state is connecting (check again : %d)", check_again);
-               if (!check_again) {
-                       check_again = TRUE;
-                       return TRUE;
-               } else
-                       check_again = FALSE;
-       }
-
-       if (__netconfig_is_wifi_profile_available() == FALSE) {
-               netconfig_send_notification_to_net_popup(
-               NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
-               goto cleanup;
-       }
-
-       vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
-       if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) {
-               DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE");
-               goto cleanup;
-       }
-
-       vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
-       if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) {
-               goto cleanup;
+       g_return_val_if_fail(wifi != NULL, TRUE);
+       GVariant *param = NULL;
+       wifi_tech_state_e tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
+       wifi_service_state_e service_state = NETCONFIG_WIFI_UNKNOWN;
+       tech_state = wifi_state_get_technology_state();
+       service_state = wifi_state_get_service_state();
+
+       if (tech_state == NETCONFIG_WIFI_TECH_UNKNOWN)
+               param = g_variant_new("(s)", "unknown");
+       else if (tech_state == NETCONFIG_WIFI_TECH_OFF ||
+               tech_state == NETCONFIG_WIFI_TECH_WPS_ONLY)
+               param = g_variant_new("(s)", "deactivated");
+       else if (tech_state == NETCONFIG_WIFI_TECH_CONNECTED)
+               param = g_variant_new("(s)", "connected");
+       else {
+               switch (service_state) {
+               case NETCONFIG_WIFI_FAILURE:
+                       param = g_variant_new("(s)", "failure");
+                       break;
+               case NETCONFIG_WIFI_ASSOCIATION:
+                       param = g_variant_new("(s)", "association");
+                       break;
+               case NETCONFIG_WIFI_CONFIGURATION:
+                       param = g_variant_new("(s)", "configuration");
+                       break;
+               case NETCONFIG_WIFI_CONNECTED:
+                       param = g_variant_new("(s)", "connected");
+                       break;
+               case NETCONFIG_WIFI_UNKNOWN:
+               case NETCONFIG_WIFI_IDLE:
+               default:
+                       param = g_variant_new("(s)", "disconnected");
+               }
        }
 
-       netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL);
-
-       netconfig_wifi_set_bss_found(FALSE);
+       g_dbus_method_invocation_return_value(context, param);
 
-cleanup:
-       netconfig_stop_timer(&network_noti_timer_id);
-       return FALSE;
-}
-
-void netconfig_wifi_start_timer_network_notification(void)
-{
-#if defined TIZEN_WEARABLE
-               /* In case of wearable device, no need to notify available Wi-Fi APs */
-               return ;
-#endif
-       netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT,
-               __netconfig_wifi_check_network_notification, NULL, &network_noti_timer_id);
-}
-
-void netconfig_wifi_state_notifier_cleanup(void)
-{
-       g_slist_free_full(notifier_list, NULL);
-}
-
-void netconfig_wifi_state_notifier_register(
-               struct netconfig_wifi_state_notifier *notifier)
-{
-       DBG("register notifier");
-
-       notifier_list = g_slist_append(notifier_list, notifier);
-}
-
-void netconfig_wifi_state_notifier_unregister(
-               struct netconfig_wifi_state_notifier *notifier)
-{
-       DBG("un-register notifier");
-
-       notifier_list = g_slist_remove_all(notifier_list, notifier);
+       return TRUE;
 }