Merge "Add support for WPS(PBC & PIN) type connection in agent" into tizen
authortaesub.kim <taesub.kim@samsung.com>
Mon, 30 Dec 2013 10:03:22 +0000 (02:03 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Mon, 30 Dec 2013 10:03:22 +0000 (02:03 -0800)
include/wifi-agent.h
packaging/net-config.spec
src/wifi-agent.c

index b60a6f5..274a493 100644 (file)
@@ -26,20 +26,6 @@ extern "C" {
 
 #include "wifi.h"
 
-#define NETCONFIG_AGENT_FIELD_NAME "Name"
-#define NETCONFIG_AGENT_FIELD_PASSPHRASE "Passphrase"
-#define NETCONFIG_AGENT_FIELD_IDENTITY "Identity"
-
-typedef struct {
-       char *name;
-       char *ssid;
-       char *identity;
-       char *passphrase;
-       char *wpspin;
-       char *username;
-       char *password;
-} NetconfigWifiAgentFields;
-
 gboolean netconfig_agent_register(void);
 gboolean netconfig_agent_unregister(void);
 gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi,
index 46be348..5d867f6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       net-config
 Summary:    TIZEN Network Configuration Module
-Version:    0.1.90_22
+Version:    0.1.90_23
 Release:    1
 Group:      System/Network
 License:    Apache-2.0
index 84a1644..ba7d331 100644 (file)
 #include "wifi.h"
 #include "netdbus.h"
 
-static NetconfigWifiAgentFields agent;
+#define NETCONFIG_AGENT_FIELD_PASSPHRASE               "Passphrase"
+#define NETCONFIG_AGENT_FIELD_WPS                              "WPS"
+#define NETCONFIG_AGENT_FIELD_WPS_PBC                  "WPS_PBC"
+#define NETCONFIG_AGENT_FIELD_WPS_PIN                  "WPS_PIN"
 
-static void _netconfig_agent_clear_fields(void)
+struct netconfig_wifi_agent {
+       char *passphrase;
+       char *wps_pin;
+       gboolean wps_pbc;
+};
+
+static struct netconfig_wifi_agent agent;
+
+static void __netconfig_agent_clear_fields(void)
 {
-       DBG("_netconfig_agent_clear_fields");
+       DBG("__netconfig_agent_clear_fields");
 
        g_free(agent.passphrase);
-       g_free(agent.name);
-       g_free(agent.identity);
+       g_free(agent.wps_pin);
+
+       agent.passphrase = NULL;
+       agent.wps_pin = NULL;
+       agent.wps_pbc = FALSE;
 }
 
 gboolean netconfig_agent_register(void)
@@ -84,7 +98,7 @@ gboolean netconfig_agent_unregister(void)
        dbus_message_unref(reply);
 
        /* Clearing the agent fields */
-       _netconfig_agent_clear_fields();
+       __netconfig_agent_clear_fields();
 
        return TRUE;
 }
@@ -92,45 +106,36 @@ gboolean netconfig_agent_unregister(void)
 gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi,
                GHashTable *fields, GError **error)
 {
-       DBG("netconfig_iface_wifi_set_field");
-       g_return_val_if_fail(wifi != NULL, FALSE);
-
        GHashTableIter iter;
        gpointer field, value;
 
-       g_hash_table_iter_init(&iter, fields);
-       while (g_hash_table_iter_next(&iter, &field, &value)) {
-               DBG("Field - [%s]", field);
-               if (!strcmp(field, NETCONFIG_AGENT_FIELD_PASSPHRASE)) {
-                       if (NULL != agent.passphrase) {
-                               g_free(agent.passphrase);
-                       }
+       DBG("Set agent fields");
 
-                       if (NULL != value) {
-                               agent.passphrase = g_strdup(value);
-                               DBG("Set the agent field[%s] - [%s]", field,
-                                               agent.passphrase);
-                       }
-               } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_NAME)) {
-                       if (NULL != agent.name) {
-                               g_free(agent.name);
-                       }
+       g_return_val_if_fail(wifi != NULL, FALSE);
 
-                       if (NULL != value) {
-                               agent.name = g_strdup(value);
-                               DBG("Set the agent field[%s] - [%s]",
-                                               field, agent.name);
-                       }
-               } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_IDENTITY)) {
-                       if (NULL != agent.identity) {
-                               g_free(agent.identity);
-                       }
+       __netconfig_agent_clear_fields();
 
-                       if (NULL != value) {
-                               agent.identity = g_strdup(value);
-                               DBG("Set the agent field[%s] - [%s]",
-                                               field, agent.identity);
-                       }
+       g_hash_table_iter_init(&iter, fields);
+
+       while (g_hash_table_iter_next(&iter, &field, &value)) {
+               DBG("Field - [%s]", field);
+               if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0) {
+                       g_free(agent.passphrase);
+                       agent.passphrase = g_strdup(value);
+
+                       DBG("Field [%s] - []", field);
+               } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PBC) == 0) {
+                       agent.wps_pbc = FALSE;
+                       if (g_strcmp0(value, "enable") == 0)
+                               agent.wps_pbc = TRUE;
+
+                       DBG("Field [%s] - [%d]", field, agent.wps_pbc);
+               } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PIN) == 0) {
+                       g_free(agent.wps_pin);
+                       agent.wps_pbc = FALSE;
+                       agent.wps_pin = g_strdup(value);
+
+                       DBG("Field [%s] - []", field);
                }
        }
 
@@ -141,53 +146,58 @@ gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi,
                gchar *service, GHashTable *fields,
                DBusGMethodInvocation *context)
 {
-       DBG("netconfig_iface_wifi_request_input");
-
-       g_return_val_if_fail(wifi != NULL, FALSE);
-
        GHashTableIter iter;
        gpointer field, value;
        GHashTable *out_table = NULL;
        GValue *ret_value = NULL;
 
+       g_return_val_if_fail(wifi != NULL, FALSE);
+
        if (NULL == service)
                return FALSE;
 
-       DBG("Service - [%s]", service);
+       DBG("Agent fields requested for service: %s", service);
 
-       out_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
-                       g_free);
+       out_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
        if (NULL == out_table)
                return FALSE;
 
        g_hash_table_iter_init(&iter, fields);
+
        while (g_hash_table_iter_next(&iter, &field, &value)) {
-               DBG("Field - [%s]", field);
-               if (!strcmp(field, NETCONFIG_AGENT_FIELD_PASSPHRASE)) {
-                       DBG("Adding the field-value in table");
+               if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0 &&
+                               agent.passphrase != NULL) {
                        ret_value = g_slice_new0(GValue);
+
                        g_value_init(ret_value, G_TYPE_STRING);
                        g_value_set_string(ret_value, agent.passphrase);
-                       g_hash_table_insert(out_table, g_strdup(field),
-                                       ret_value);
-               } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_NAME)) {
-                       DBG("Adding the field-value in table");
-                       ret_value = g_slice_new0(GValue);
-                       g_value_init(ret_value, G_TYPE_STRING);
-                       g_value_set_string(ret_value, agent.name);
-                       g_hash_table_insert(out_table, g_strdup(field),
-                                       ret_value);
-               } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_IDENTITY)) {
-                       DBG("Adding the field-value in table");
+                       g_hash_table_insert(out_table, g_strdup(field), ret_value);
+
+                       DBG("Setting [%s] - []", field);
+               } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS) == 0 &&
+                               (agent.wps_pbc == TRUE || agent.wps_pin != NULL)) {
                        ret_value = g_slice_new0(GValue);
+
                        g_value_init(ret_value, G_TYPE_STRING);
-                       g_value_set_string(ret_value, agent.identity);
-                       g_hash_table_insert(out_table, g_strdup(field),
-                                       ret_value);
+
+                       if (agent.wps_pbc == TRUE) {
+                               /* Sending empty string for WPS push button method */
+                               g_value_set_string(ret_value, "");
+
+                               DBG("Setting empty string for [%s]", field);
+                       } else if (agent.wps_pin != NULL) {
+                               g_value_set_string(ret_value, agent.wps_pin);
+
+                               DBG("Setting string [%s] - []", field);
+                       }
+
+                       g_hash_table_insert(out_table, g_strdup(field), ret_value);
                }
        }
 
        dbus_g_method_return(context, out_table);
 
+       __netconfig_agent_clear_fields();
+
        return TRUE;
 }