Merge "Revise background scan routine" into tizen
[platform/core/connectivity/net-config.git] / src / signal-handler.c
index a7a132f..e3ee51f 100755 (executable)
@@ -18,6 +18,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <vconf.h>
 #include <vconf-keys.h>
@@ -27,6 +28,7 @@
 #include "netdbus.h"
 #include "neterror.h"
 #include "wifi-wps.h"
+#include "wifi-bssid-scan.h"
 #include "wifi-agent.h"
 #include "wifi-power.h"
 #include "wifi-state.h"
@@ -34,7 +36,6 @@
 #include "network-state.h"
 #include "cellular-state.h"
 #include "signal-handler.h"
-#include "wifi-ssid-scan.h"
 #include "wifi-background-scan.h"
 #include "wifi-tdls.h"
 
@@ -106,17 +107,17 @@ static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary, const gch
        g_variant_iter_init(&iter, dictionary);
        while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
                if (g_strcmp0(key, "Address") == 0)  {
-                       value = g_variant_get_string(var, NULL);
+                       g_variant_get(var, "&s", &value);
                        char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
 
                        DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip, value);
                        if (g_strcmp0(old_ip, value) != 0) {
-                               if (value == NULL)
-                                       vconf_set_str(VCONFKEY_NETWORK_IP, "");
-                               else
+                               if (value != NULL)
                                        vconf_set_str(VCONFKEY_NETWORK_IP, value);
+                               else if (old_ip != NULL && strlen(old_ip) > 0)
+                                       vconf_set_str(VCONFKEY_NETWORK_IP, "");
                        }
-                       g_free(old_ip);
+                       free(old_ip);
                }
        }
 }
@@ -131,17 +132,17 @@ static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary, const gch
        g_variant_iter_init(&iter, dictionary);
        while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
                if (g_strcmp0(key, "Address") == 0)  {
-                       value = g_variant_get_string(var, NULL);
-                       char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP);
+                       g_variant_get(var, "&s", &value);
+                       char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
 
                        DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6, value);
                        if (g_strcmp0(old_ip6, value) != 0) {
-                               if (value == NULL)
-                                       vconf_set_str(VCONFKEY_NETWORK_IP6, "");
-                               else
+                               if (value != NULL)
                                        vconf_set_str(VCONFKEY_NETWORK_IP6, value);
+                               else if (old_ip6 != NULL && strlen(old_ip6) > 0)
+                                       vconf_set_str(VCONFKEY_NETWORK_IP6, "");
                        }
-                       g_free(old_ip6);
+                       free(old_ip6);
                }
        }
 }
@@ -486,8 +487,8 @@ static void _supplicant_interface_removed(GDBusConnection *conn,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
        DBG("Interface removed handling!");
-       if (netconfig_wifi_is_wps_enabled() == TRUE)
-               netconfig_wifi_wps_signal_scanaborted();
+       if (netconfig_wifi_is_bssid_scan_started() == TRUE)
+               netconfig_wifi_bssid_signal_scanaborted();
 
        return;
 }
@@ -496,7 +497,6 @@ static void _supplicant_properties_changed(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
-       DBG("Properties changed handling!");
        gchar *key;
        GVariantIter *iter;
        GVariant *variant;
@@ -509,8 +509,11 @@ static void _supplicant_properties_changed(GDBusConnection *conn,
        while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
                if (g_strcmp0(key, "Scanning") == 0) {
                        scanning = g_variant_get_boolean(variant);
+                       DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
                        if (scanning == TRUE)
                                netconfig_wifi_set_scanning(TRUE);
+                       else
+                               netconfig_wifi_set_scanning(FALSE);
 
                        g_variant_unref(variant);
                        g_free(key);
@@ -528,10 +531,7 @@ static void _supplicant_bss_added(GDBusConnection *conn,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
        DBG("BSS added handling!");
-       if (wifi_ssid_scan_get_state() == TRUE)
-               wifi_ssid_scan_add_bss(param);
-       else
-               wifi_state_set_bss_found(TRUE);
+       wifi_state_set_bss_found(TRUE);
 
        return;
 }
@@ -543,18 +543,13 @@ static void _supplicant_scan_done(GDBusConnection *conn,
        DBG("Scan Done handling!");
        netconfig_wifi_set_scanning(FALSE);
 
-       if (netconfig_wifi_is_wps_enabled() == TRUE) {
-               netconfig_wifi_wps_signal_scandone();
+       if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
+               netconfig_wifi_bssid_signal_scandone();
                if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
                        return;
        }
 
-       if (netconfig_wifi_get_bgscan_state() != TRUE) {
-               if (wifi_ssid_scan_get_state() == TRUE)
-                       wifi_ssid_scan_emit_scan_completed();
-               else
-                       wifi_ssid_scan(NULL);
-       } else {
+       if (netconfig_wifi_get_bgscan_state() == TRUE) {
                if (wifi_state_get_technology_state() >=
                                NETCONFIG_WIFI_TECH_POWERED)
                        netconfig_wifi_bgscan_start(FALSE);
@@ -595,8 +590,8 @@ static void _supplicant_tdls_connected(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
-       ERR("Received TDLS Connected Signal");
-       netconfig_wifi_tlds_connected_event(param);
+       DBG("Received TDLS Connected Signal");
+       netconfig_wifi_tdls_connected_event(param);
 
        return;
 }
@@ -605,8 +600,8 @@ static void _supplicant_tdls_disconnected(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
-       ERR("Received TDLS Disconnected Signal");
-       netconfig_wifi_tlds_disconnected_event(param);
+       DBG("Received TDLS Disconnected Signal");
+       netconfig_wifi_tdls_disconnected_event(param);
 
        return;
 }
@@ -615,7 +610,8 @@ static void _supplicant_tdls_peer_found(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
 {
-       ERR("Received TDLS Peer Found Signal");
+       DBG("Received TDLS Peer Found Signal");
+       netconfig_wifi_tdls_peer_found_event(param);
        return;
 }
 
@@ -690,7 +686,7 @@ static void _supplicant_wifi_wps_event(GVariant *param)
 
        g_variant_get(param, "(sa{sv})", &name, &iter);
        INFO("Event Result: %s", name);
-       if (g_strcmp0(name, "failed") == 0) {
+       if (g_strcmp0(name, "fail") == 0) {
                while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
                        if (key == NULL)
                                goto error;