Remove vconftool command to use buxton key
[platform/core/connectivity/net-config.git] / src / wifi-ssid-scan.c
old mode 100644 (file)
new mode 100755 (executable)
index 3f49101..390fe1b
@@ -1,7 +1,7 @@
 /*
  * Network Configuration Module
  *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include "wifi-ssid-scan.h"
 #include "wifi-background-scan.h"
 
-struct bss_info_t {
-       unsigned char ssid[32];
-       enum netconfig_wifi_security security;
-       dbus_bool_t privacy;
-       dbus_bool_t wps;
-};
+typedef enum {
+       WIFI_SECURITY_UNKNOWN = 0x00,
+       WIFI_SECURITY_NONE = 0x01,
+       WIFI_SECURITY_WEP = 0x02,
+       WIFI_SECURITY_PSK = 0x03,
+       WIFI_SECURITY_IEEE8021X = 0x04,
+} wifi_security_e;
+
+typedef struct {
+       unsigned char ssid[33];
+       wifi_security_e security;
+       gboolean privacy;
+       gboolean wps;
+} bss_info_t;
+
+static gboolean g_ssid_scan_state = FALSE;
+static GSList *bss_info_list = NULL;
+static guint ssid_scan_timer = 0;
+static char *g_ssid = NULL;
+
+static void __check_security(const char *str_keymgmt, bss_info_t *bss_info)
+{
+       INFO("keymgmt : %s", str_keymgmt);
 
-static gboolean wifi_ssid_scan_state = FALSE;
-static GSList *wifi_bss_info_list = NULL;
-static guint netconfig_wifi_ssid_scan_timer = 0;
+       if (g_strcmp0(str_keymgmt, "ieee8021x") == 0) {
+               bss_info->security = WIFI_SECURITY_IEEE8021X;
+       } else if (g_strcmp0(str_keymgmt, "wpa-psk") == 0) {
+               bss_info->security = WIFI_SECURITY_PSK;
+       } else if (g_strcmp0(str_keymgmt, "wpa-psk-sha256") == 0) {
+               bss_info->security = WIFI_SECURITY_PSK;
+       } else if (g_strcmp0(str_keymgmt, "wpa-ft-psk") == 0) {
+               bss_info->security = WIFI_SECURITY_PSK;
+       } else if (g_strcmp0(str_keymgmt, "wpa-ft-eap") == 0) {
+               bss_info->security = WIFI_SECURITY_IEEE8021X;
+       } else if (g_strcmp0(str_keymgmt, "wpa-eap") == 0) {
+               bss_info->security = WIFI_SECURITY_IEEE8021X;
+       } else if (g_strcmp0(str_keymgmt, "wpa-eap-sha256") == 0) {
+               bss_info->security = WIFI_SECURITY_IEEE8021X;
+       } else if (g_strcmp0(str_keymgmt, "wps") == 0) {
+               bss_info->wps = TRUE;
+       }
+}
 
-static gboolean __netconfig_wifi_ssid_scan_timeout(gpointer data)
+static gboolean __ssid_scan_timeout(gpointer data)
 {
-       netconfig_wifi_notify_ssid_scan_done();
+       wifi_ssid_scan_emit_scan_completed();
 
        return FALSE;
 }
 
-static void __netconfig_wifi_ssid_scan_started(void)
+static void _start_ssid_scan_timer(void)
 {
        INFO("Wi-Fi SSID scan started");
-       wifi_ssid_scan_state = TRUE;
+       g_ssid_scan_state = TRUE;
 
-       netconfig_start_timer_seconds(
-                       5,
-                       __netconfig_wifi_ssid_scan_timeout,
-                       NULL,
-                       &netconfig_wifi_ssid_scan_timer);
+       netconfig_start_timer_seconds(5, __ssid_scan_timeout, NULL, &ssid_scan_timer);
 }
 
-static void __netconfig_wifi_ssid_scan_finished(void)
+static void _stop_ssid_scan_timer(void)
 {
        INFO("Wi-Fi SSID scan finished");
-       wifi_ssid_scan_state = FALSE;
+       g_ssid_scan_state = FALSE;
 
-       netconfig_stop_timer(&netconfig_wifi_ssid_scan_timer);
+       netconfig_stop_timer(&ssid_scan_timer);
 }
 
-static gboolean __netconfig_wifi_invoke_ssid_scan(
-               const char *object_path, const char *ssid)
+static void _parse_keymgmt_message(GVariant *param, bss_info_t *bss_info)
 {
-       /* TODO: Revise following code */
-
-#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000)
-
-       DBusConnection *connection = NULL;
-       DBusMessage *message = NULL;
-       DBusMessage *reply = NULL;
-       DBusMessageIter iter, dict, entry;
-       DBusMessageIter value, array, array2;
-       DBusError error;
-       int MessageType = 0;
-       const char *key1 = "Type";
-       const char *val1 = "active";
-       const char *key2 = "SSIDs";
-
-       connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-       if (connection == NULL) {
-               ERR("Error!!! Failed to get system DBus");
-               goto error;
+       GVariantIter *iter1;
+       GVariant *var;
+       gchar *key;
+
+       g_variant_get(param, "a{sv}", &iter1);
+       while (g_variant_iter_loop(iter1, "{sv}", &key, &var)) {
+               if (g_strcmp0(key, "KeyMgmt") == 0) {//check this :iterate
+                       GVariantIter *iter2;
+                       g_variant_get(var, "as", &iter2);
+                       char *str;
+                       while (g_variant_iter_loop(iter2, "s", &str)) {
+                               if (str == NULL) {
+                                       break;
+                               }
+                               __check_security(str, bss_info);
+                       }
+                       g_variant_iter_free (iter2);
+               }
        }
 
-       message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
-                       object_path, SUPPLICANT_INTERFACE ".Interface", "Scan");
-       if (message == NULL) {
-               ERR("Error!!! DBus method call fail");
-               goto error;
-       }
+       g_variant_iter_free (iter1);
 
-       dbus_message_iter_init_append(message, &iter);
-       dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+       return;
+}
 
-       dbus_message_iter_open_container(&dict,
-                       DBUS_TYPE_DICT_ENTRY, NULL, &entry);
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key1);
+static gboolean _request_ssid_scan(const char *object_path, const char *ssid)
+{
+       /* TODO: Revise following code */
 
-       dbus_message_iter_open_container(&entry,
-                       DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &val1);
+#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000)
+       GDBusConnection *connection = NULL;
+       GVariant *reply = NULL;
+       GVariant *params = NULL;
+       GError *error = NULL;
+       GVariantBuilder *builder1 = NULL;
+       GVariantBuilder *builder2 = NULL;
+       GVariantBuilder *builder3 = NULL;
+       const gchar *key1 = "Type";
+       const gchar *val1 = "active";
+       const gchar *key2 = "SSIDs";
+       int i = 0;
+
+       connection = netdbus_get_connection();
+       if (connection == NULL) {
+               DBG("Failed to get GDBusconnection");
+               return FALSE;
+       }
 
-       dbus_message_iter_close_container(&entry, &value);
-       dbus_message_iter_close_container(&dict, &entry);
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
+       g_variant_builder_add(builder1, "{sv}", key1, g_variant_new_string(val1));
 
-       dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key2);
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE ("aay"));
+       builder3 = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
 
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                       DBUS_TYPE_ARRAY_AS_STRING
-                       DBUS_TYPE_ARRAY_AS_STRING
-                       DBUS_TYPE_BYTE_AS_STRING,
-                       &value);
-       dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
-                       DBUS_TYPE_ARRAY_AS_STRING
-                       DBUS_TYPE_BYTE_AS_STRING,
-                       &array);
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &array2);
+       for (i = 0; i < strlen(ssid); i++) {
+               g_variant_builder_add (builder3, "y", ssid[i]);
+       }
 
-       dbus_message_iter_append_fixed_array(&array2, DBUS_TYPE_BYTE, &ssid, strlen(ssid));
+       g_variant_builder_add(builder2, "@ay", g_variant_builder_end(builder3));
+       g_variant_builder_add(builder1, "{sv}", key2, g_variant_builder_end(builder2));
 
-       dbus_message_iter_close_container(&array, &array2);
-       dbus_message_iter_close_container(&value, &array);
-       dbus_message_iter_close_container(&entry, &value);
-       dbus_message_iter_close_container(&dict, &entry);
-       dbus_message_iter_close_container(&iter, &dict);
+       params = g_variant_new("(@a{sv})", g_variant_builder_end(builder1));
 
-       dbus_error_init(&error);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
+       g_variant_builder_unref(builder3);
 
-       reply = dbus_connection_send_with_reply_and_block(connection, message,
-                       NETCONFIG_DBUS_REPLY_TIMEOUT, &error);
+       reply = g_dbus_connection_call_sync(
+                       connection,
+                       SUPPLICANT_SERVICE,
+                       object_path,
+                       SUPPLICANT_INTERFACE ".Interface",
+                       "Scan",
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       NETCONFIG_DBUS_REPLY_TIMEOUT,
+                       netdbus_get_cancellable(),
+                       &error);
 
        if (reply == NULL) {
-               if (dbus_error_is_set(&error) == TRUE) {
+               if (error != NULL) {
                        ERR("Error!!! dbus_connection_send_with_reply_and_block() failed. "
-                                       "DBus error [%s: %s]", error.name, error.message);
-
-                       dbus_error_free(&error);
-                       return FALSE;
+                                       "DBus error [%d: %s]", error->code, error->message);
+                       g_error_free(error);
                } else
                        ERR("Error!!! Failed to get properties");
 
-               goto error;
+               return FALSE;
        }
 
-       MessageType = dbus_message_get_type(reply);
-       if (MessageType == DBUS_MESSAGE_TYPE_ERROR) {
-               const char *err_msg = dbus_message_get_error_name(reply);
-               ERR("Error!!! Error message received %s", err_msg);
-               goto error;
+       if (g_ssid != NULL) {
+               g_free(g_ssid);
        }
 
-       dbus_message_unref(message);
-       dbus_message_unref(reply);
-       dbus_connection_unref(connection);
+       g_ssid = g_strdup(ssid);
 
-       return TRUE;
-
-error:
-       if (message != NULL)
-               dbus_message_unref(message);
+       g_variant_unref(reply);
 
-       if (reply != NULL)
-               dbus_message_unref(reply);
-
-       if (connection != NULL)
-               dbus_connection_unref(connection);
-
-       return FALSE;
+       return TRUE;
 }
 
-static void __netconfig_wifi_notify_ssid_scan_done(void)
+static void _emit_ssid_scan_completed(void)
 {
-       DBusMessage *signal;
-       DBusConnection *connection = NULL;
-       DBusMessageIter dict, type, array, value;
-       DBusError error;
-       char *prop_ssid = "ssid";
-       char *prop_security = "security";
-       const char *sig_name = "SpecificScanCompleted";
-
-       dbus_error_init(&error);
-
-       connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (connection == NULL) {
-               /* TODO: If this occurs then UG should be informed abt SCAN fail. CHECK THIS. */
-               ERR("Error!!! Failed to get system DBus, error [%s]", error.message);
-               dbus_error_free(&error);
-
-               g_slist_free_full(wifi_bss_info_list, g_free);
-               wifi_bss_info_list = NULL;
-
-               return;
+       GVariantBuilder *builder = NULL;
+       GSList* list = NULL;
+       const char *prop_ssid = "ssid";
+       const char *prop_security = "security";
+       const char *prop_wps = "wps";
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
+       for (list = bss_info_list; list != NULL; list = list->next) {
+               bss_info_t *bss_info = (bss_info_t *)list->data;
+               if (bss_info && g_strcmp0((char *)bss_info->ssid, g_ssid) == 0) {
+                       const gchar *ssid = (char *)bss_info->ssid;
+                       wifi_security_e security = bss_info->security;
+                       gboolean wps = bss_info->wps;
+                       DBG("BSS found; SSID:%s security:%d WPS:%d", ssid, security, wps);
+                       g_variant_builder_add(builder, "{sv}", prop_ssid, g_variant_new_string(ssid));
+                       g_variant_builder_add(builder, "{sv}", prop_security, g_variant_new_int32(security));
+                       /* WPS */
+                       g_variant_builder_add(builder, "{sv}", prop_wps, g_variant_new_boolean(wps));
+               }
        }
 
-       signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, sig_name);
-       if (signal == NULL) {
-               /* TODO: If this occurs then UG should be informed abt SCAN fail. CHECK THIS. */
-               dbus_connection_unref(connection);
+       wifi_emit_specific_scan_completed((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
 
-               g_slist_free_full(wifi_bss_info_list, g_free);
-               wifi_bss_info_list = NULL;
+       if (builder)
+               g_variant_builder_unref(builder);
 
-               return;
+       if (bss_info_list != NULL) {
+               g_slist_free_full(bss_info_list, g_free);
+               bss_info_list = NULL;
        }
 
-       dbus_message_iter_init_append(signal, &array);
-       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, "{sv}", &dict);
-       GSList* list = wifi_bss_info_list;
-       while (list) {
-               struct bss_info_t *bss_info = (struct bss_info_t *)g_slist_nth_data(list, 0);
-
-               if (bss_info) {
-                       char *ssid = (char *)&(bss_info->ssid[0]);
-                       dbus_int16_t security = bss_info->security;
-                       DBG("Bss found. SSID: %s; Sec mode: %d;", ssid, security);
-
-                       /* Lets pack the SSID */
-                       dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type);
-                       dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_ssid);
-                       dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
-
-                       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &ssid);
-                       dbus_message_iter_close_container(&type, &value);
-                       dbus_message_iter_close_container(&dict, &type);
-
-                       /* Lets pack the Security */
-                       dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type);
-                       dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_security);
-                       dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &value);
-
-                       dbus_message_iter_append_basic(&value, DBUS_TYPE_INT16, &security);
-                       dbus_message_iter_close_container(&type, &value);
-                       dbus_message_iter_close_container(&dict, &type);
-               }
-               list = g_slist_next(list);
+       if (g_ssid != NULL) {
+               g_free(g_ssid);
+               g_ssid = NULL;
        }
 
-       dbus_message_iter_close_container(&array, &dict);
+       INFO("SpecificScanCompleted");
 
-       dbus_error_init(&error);
-       dbus_connection_send(connection, signal, NULL);
-
-       dbus_message_unref(signal);
-       dbus_connection_unref(connection);
-
-       g_slist_free_full(wifi_bss_info_list, g_free);
-       wifi_bss_info_list = NULL;
-
-       INFO("(%s)", sig_name);
-}
-
-static void __netconfig_wifi_check_security(const char *str_keymgmt, struct bss_info_t *bss_data)
-{
-       INFO("keymgmt : %s", str_keymgmt);
-
-       if (strcmp(str_keymgmt, "ieee8021x") == 0) {
-               bss_data->security = WIFI_SECURITY_IEEE8021X;
-       } else if (strcmp(str_keymgmt, "wpa-psk") == 0) {
-               bss_data->security = WIFI_SECURITY_PSK;
-       } else if (strcmp(str_keymgmt, "wpa-psk-sha256") == 0) {
-               bss_data->security = WIFI_SECURITY_PSK;
-       } else if (strcmp(str_keymgmt, "wpa-ft-psk") == 0) {
-               bss_data->security = WIFI_SECURITY_PSK;
-       } else if (strcmp(str_keymgmt, "wpa-ft-eap") == 0) {
-               bss_data->security = WIFI_SECURITY_IEEE8021X;
-       } else if (strcmp(str_keymgmt, "wpa-eap") == 0) {
-               bss_data->security = WIFI_SECURITY_IEEE8021X;
-       } else if (strcmp(str_keymgmt, "wpa-eap-sha256") == 0) {
-               bss_data->security = WIFI_SECURITY_IEEE8021X;
-       } else if (strcmp(str_keymgmt, "wps") == 0) {
-               bss_data->wps = TRUE;
-       }
+       return;
 }
 
-static void __netconfig_wifi_parse_keymgmt_message(DBusMessageIter *iter, struct bss_info_t *bss_data)
+gboolean wifi_ssid_scan(const char *ssid)
 {
-       DBusMessageIter dict, entry, array, value;
-       const char *key;
+       const char *if_path;
+       static char *scan_ssid = NULL;
 
-       if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
-               return;
+       netconfig_wifi_bgscan_stop();
 
-       dbus_message_iter_recurse(iter, &dict);
-       while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
-               dbus_message_iter_recurse(&dict, &entry);
+       if (ssid != NULL) {
+               if (scan_ssid != NULL) {
+                       g_free(scan_ssid);
+               }
+               scan_ssid = g_strdup(ssid);
+       }
 
-               if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
-                       return;
+       if (scan_ssid == NULL)
+               goto error;
 
-               dbus_message_iter_get_basic(&entry, &key);
-               if (g_strcmp0(key, "KeyMgmt") == 0) {
-                       dbus_message_iter_next(&entry);
+       if_path = netconfig_wifi_get_supplicant_interface();
+       if (if_path == NULL) {
+               DBG("Fail to get wpa_supplicant DBus path");
+               goto error;
+       }
 
-                       if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
-                               return;
+       if (netconfig_wifi_get_scanning() == TRUE) {
+               DBG("Wi-Fi scan in progress, %s scan will be delayed", scan_ssid);
+               g_free(scan_ssid);
+               return TRUE;
+       }
 
-                       dbus_message_iter_recurse(&entry, &array);
-                       if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
-                               return;
+       if (bss_info_list) {
+               g_slist_free_full(bss_info_list, g_free);
+               bss_info_list = NULL;
+       }
 
-                       dbus_message_iter_recurse(&array, &value);
-                       while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
-                               const char *str = NULL;
+       INFO("Start Wi-Fi scan with %s(%d)", scan_ssid, strlen(scan_ssid));
+       if (_request_ssid_scan(if_path, (const char *)scan_ssid) == TRUE) {
+               _start_ssid_scan_timer();
+               g_free(scan_ssid);
+               scan_ssid = NULL;
+               return TRUE;
+       }
 
-                               dbus_message_iter_get_basic(&value, &str);
-                               if (str == NULL)
-                                       return;
+error:
+       if (scan_ssid != NULL) {
+               g_free(scan_ssid);
+               scan_ssid = NULL;
+       }
 
-                               __netconfig_wifi_check_security(str, bss_data);
-                               dbus_message_iter_next(&value);
-                       }
-               }
+       netconfig_wifi_bgscan_start(FALSE);
 
-               dbus_message_iter_next(&dict);
-       }
+       return FALSE;
 }
 
-gboolean netconfig_wifi_get_ssid_scan_state(void)
+gboolean wifi_ssid_scan_get_state(void)
 {
-       return wifi_ssid_scan_state;
+       return g_ssid_scan_state;
 }
 
-void netconfig_wifi_notify_ssid_scan_done(void)
+void wifi_ssid_scan_emit_scan_completed(void)
 {
-       if (netconfig_wifi_get_ssid_scan_state() != TRUE)
+       if (g_ssid_scan_state != TRUE)
                return;
 
-       __netconfig_wifi_ssid_scan_finished();
-
-       __netconfig_wifi_notify_ssid_scan_done();
-
-       netconfig_wifi_bgscan_start();
+       _stop_ssid_scan_timer();
+       _emit_ssid_scan_completed();
 }
 
-void netconfig_wifi_bss_added(DBusMessage *message)
+void wifi_ssid_scan_add_bss(GVariant *message)
 {
-       DBusMessageIter iter, dict, entry;
-       DBusMessageIter value, array;
-       const char *key;
-       struct bss_info_t *bss_info;
+       GVariantIter *iter;
+       GVariant *value;
+       gchar *path = NULL;
+       gchar *key;
+       bss_info_t *bss_info;
 
-       if (netconfig_wifi_get_ssid_scan_state() != TRUE)
+       if (g_ssid_scan_state != TRUE)
                return;
 
        INFO("NEW BSS added");
 
-       if (!dbus_message_iter_init(message, &iter)) {
+       if (message == NULL) {
                DBG("Message does not have parameters");
                return;
        }
 
-       dbus_message_iter_next(&iter);
+       if (path != NULL)
+               INFO("Object path of BSS added is %s",path);
 
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
-               DBG("Invalid message type");
+       bss_info = g_try_new0(bss_info_t, 1);
+       if (bss_info == NULL)
                return;
-       }
-
-       bss_info = g_try_new0(struct bss_info_t, 1);
-       if (bss_info == NULL) {
-               DBG("Out of memory");
-               return;
-       }
-
-       dbus_message_iter_recurse(&iter, &dict);
-       while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
-               dbus_message_iter_recurse(&dict, &entry);
-
-               if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
-                       goto error;
-
-               dbus_message_iter_get_basic(&entry, &key);
-               if (key == NULL)
-                       goto error;
-
-               dbus_message_iter_next(&entry);
-               if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
-                       goto error;
-
-               dbus_message_iter_recurse(&entry, &value);
 
+       g_variant_get(message, "(oa{sv})", &path, &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
                if (g_strcmp0(key, "SSID") == 0) {
-                       unsigned char *ssid;
-                       int ssid_len;
-
-                       dbus_message_iter_recurse(&value, &array);
-                       dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
-
-                       if (ssid_len > 0 && ssid_len < 33)
+                       const guchar *ssid;
+                       gsize ssid_len;
+                       ssid = g_variant_get_fixed_array(value, &ssid_len, sizeof(guchar));
+                       if (ssid != NULL && ssid_len > 0 && ssid_len < 33)
                                memcpy(bss_info->ssid, ssid, ssid_len);
                        else
                                memset(bss_info->ssid, 0, sizeof(bss_info->ssid));
                } else if (g_strcmp0(key, "Privacy") == 0) {
-                       dbus_bool_t privacy = FALSE;
-
-                       dbus_message_iter_get_basic(&value, &privacy);
+                       gboolean privacy = FALSE;
+                       privacy = g_variant_get_boolean(value);
                        bss_info->privacy = privacy;
                } else if ((g_strcmp0(key, "RSN") == 0) || (g_strcmp0(key, "WPA") == 0)) {
-
-                       __netconfig_wifi_parse_keymgmt_message(&value, bss_info);
+                       _parse_keymgmt_message(value, bss_info);
                } else if (g_strcmp0(key, "IEs") == 0) {
-                       unsigned char *ie;
-                       int ie_len;
-
-                       dbus_message_iter_recurse(&value, &array);
-                       dbus_message_iter_get_fixed_array(&array, &ie, &ie_len);
+                       const guchar *ie;
+                       gsize ie_len;
+                       ie = g_variant_get_fixed_array(value, &ie_len, sizeof(guchar));
+                       DBG("The IE : %s",ie);
                }
-
-               dbus_message_iter_next(&dict);
        }
 
-       if (bss_info->ssid[0] == 0)
-               goto error;
+       g_variant_iter_free(iter);
+       if (path)
+               g_free(path);
+
+       if (bss_info->ssid[0] == '\0') {
+               g_free(bss_info);
+               return;
+       }
 
        if (bss_info->security == WIFI_SECURITY_UNKNOWN) {
                if (bss_info->privacy == TRUE)
@@ -428,69 +370,24 @@ void netconfig_wifi_bss_added(DBusMessage *message)
                        bss_info->security = WIFI_SECURITY_NONE;
        }
 
-       wifi_bss_info_list = g_slist_append(wifi_bss_info_list, bss_info);
-       return;
-
-error:
-       g_free(bss_info);
+       bss_info_list = g_slist_append(bss_info_list, bss_info);
 }
 
-gboolean netconfig_wifi_ssid_scan(const char *ssid)
+gboolean handle_request_specific_scan(Wifi *wifi,
+               GDBusMethodInvocation *context, const gchar *ssid)
 {
-       char object_path[DBUS_PATH_MAX_BUFLEN] = { 0, };
-       char *path_ptr = &object_path[0];
-       static char *scan_ssid = NULL;
-
-       netconfig_wifi_bgscan_stop();
-
-       if (ssid != NULL) {
-               g_free(scan_ssid);
-               scan_ssid = g_strdup(ssid);
-       }
-
-       if (scan_ssid == NULL) {
-               netconfig_wifi_bgscan_start();
-               return FALSE;
-       }
-
-       if (netconfig_wifi_get_scanning() == TRUE) {
-               DBG("Wi-Fi scan is in progress! SSID %s scan will be delayed",
-                               scan_ssid);
-               return FALSE;
-       }
-
-       INFO("Start SSID Scan with %s", scan_ssid);
-
-       if (wifi_bss_info_list) {
-               g_slist_free_full(wifi_bss_info_list, g_free);
-               wifi_bss_info_list = NULL;
-       }
+       gboolean result = FALSE;
 
-       if (netconfig_wifi_get_supplicant_interface(&path_ptr) != TRUE) {
-               DBG("Fail to get wpa_supplicant DBus path");
-               return FALSE;
-       }
-
-       if (__netconfig_wifi_invoke_ssid_scan(
-                       (const char *)object_path, (const char *)scan_ssid) == TRUE) {
-               __netconfig_wifi_ssid_scan_started();
-
-               g_free(scan_ssid);
-               scan_ssid = NULL;
-
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
-gboolean netconfig_iface_wifi_request_specific_scan(NetconfigWifi *wifi,
-               gchar *ssid, GError **error)
-{
        g_return_val_if_fail(wifi != NULL, FALSE);
        g_return_val_if_fail(ssid != NULL, FALSE);
 
-       netconfig_wifi_ssid_scan((const char *)ssid);
+       result = wifi_ssid_scan((const char *)ssid);
 
-       return TRUE;
+       if (result != TRUE) {
+               netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailSpecificScan");
+       } else {
+               wifi_complete_request_wps_scan(wifi, context);
+       }
+
+       return result;
 }