Fix dlog format error
[platform/core/connectivity/net-config.git] / src / wifi-eap-config.c
old mode 100644 (file)
new mode 100755 (executable)
index 1103496..99d406b
@@ -27,6 +27,7 @@
 #include "netdbus.h"
 #include "wifi-agent.h"
 #include "wifi-state.h"
+#include "wifi-config.h"
 #include "wifi-eap-config.h"
 #include "neterror.h"
 
@@ -41,6 +42,7 @@
 #define CONNMAN_CONFIG_FIELD_CLIENT_CERT_FILE          "ClientCertFile"
 #define CONNMAN_CONFIG_FIELD_PVT_KEY_FILE                      "PrivateKeyFile"
 #define CONNMAN_CONFIG_FIELD_PVT_KEY_PASSPHRASE                "PrivateKeyPassphrase"
+#define CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE                      "KeymgmtType"
 
 static char *__get_encoded_ssid(const char *name)
 {
@@ -92,7 +94,7 @@ static int __config_save(const char *ssid, GKeyFile *keyfile)
 
        /* Do POSIX file operation to create and remove config files,
         * Do not use g_file_set_contents, it breaks inotify operations */
-       if (fputs(data, file) < 0) {
+       if (data && fputs(data, file) < 0) {
                ERR("Failed to write %s", config_file);
 
                err = -EIO;
@@ -194,7 +196,7 @@ static gboolean __netconfig_copy_config(const char *src, const char *dst)
 
        result = g_file_get_contents(src, &buf, &length, &error);
        if (result != TRUE) {
-               ERR("Failed to read %s[%s]", error->message);
+               ERR("Failed to read [%s]", error->message);
                g_error_free(error);
 
                return result;
@@ -202,7 +204,7 @@ static gboolean __netconfig_copy_config(const char *src, const char *dst)
 
        result = g_file_set_contents(dst, buf, length, &error);
        if (result != TRUE) {
-               ERR("Failed to write %s[%s]", error->message);
+               ERR("Failed to write [%s]", error->message);
                g_error_free(error);
        }
 
@@ -271,7 +273,8 @@ static gboolean __netconfig_create_config(GVariant *fields)
        while (g_variant_iter_loop(iter, "{ss}", &field, &value)) {
                if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0 ||
                                g_strcmp0(field, CONNMAN_CONFIG_FIELD_EAP_METHOD) == 0 ||
-                               g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) == 0) {
+                               g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) ||
+                               g_strcmp0(field, CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE) == 0) {
                        DBG("field: %s, value: %s", field, value);
 
                        if (value != NULL)
@@ -323,8 +326,7 @@ static gboolean __netconfig_create_config(GVariant *fields)
                                g_free(cert_path);
                        }
                } else {
-                       //DBG("field: %s, value:", field);
-                       DBG("Temporal field: %s, value: %s", field, value);
+                       DBG("field: %s, value: %s", field, value);
 
                        if (value != NULL)
                                g_key_file_set_string(keyfile, group_name, field, value);
@@ -345,18 +347,34 @@ out:
 
        g_variant_iter_free(iter);
 
-       if (field)
-               g_free(field);
-
-       if (value)
-               g_free(value);
-
        g_free(group_name);
        g_free(encoded_ssid);
 
        return updated;
 }
 
+static gboolean _delete_configuration(const gchar *profile)
+{
+       gboolean ret = FALSE;
+       gchar *config_id = NULL;
+
+       ret = wifi_config_get_config_id(profile, &config_id);
+       if (ret != TRUE) {
+               ERR("Fail to get config_id from [%s]", profile);
+               return ret;
+       }
+       ERR("get config_id [%s] from [%s]", config_id, profile);
+
+       ret = wifi_config_remove_configuration(config_id);
+       if (ret != TRUE)
+               ERR("Fail to wifi_config_remove_configuration [%s]", config_id);
+
+       if (config_id != NULL)
+               g_free(config_id);
+
+       return ret;
+}
+
 static gboolean __netconfig_delete_config(const char *profile)
 {
        char *wifi_ident = NULL;
@@ -371,6 +389,9 @@ static gboolean __netconfig_delete_config(const char *profile)
                return FALSE;
        }
 
+       if (_delete_configuration(profile) != TRUE)
+               ERR("Fail to delete configuration [%s]", profile);
+
        wifi_ident = strstr(profile, "wifi_");
        if (wifi_ident == NULL) {
                ERR("Invalid profile name");
@@ -409,20 +430,20 @@ static gboolean __netconfig_delete_config(const char *profile)
 }
 
 static void __netconfig_eap_state(
-               enum netconfig_wifi_service_state state, void *user_data);
+               wifi_service_state_e state, void *user_data);
 
-static struct netconfig_wifi_state_notifier netconfig_eap_notifier = {
-               .netconfig_wifi_state_changed = __netconfig_eap_state,
+static wifi_state_notifier netconfig_eap_notifier = {
+               .wifi_state_changed = __netconfig_eap_state,
                .user_data = NULL,
 };
 
 static void __netconfig_eap_state(
-               enum netconfig_wifi_service_state state, void *user_data)
+               wifi_service_state_e state, void *user_data)
 {
        const char *wifi_profile = (const char *)user_data;
 
        if (wifi_profile == NULL) {
-               netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier);
+               wifi_state_notifier_unregister(&netconfig_eap_notifier);
                return;
        }
 
@@ -435,23 +456,22 @@ static void __netconfig_eap_state(
        g_free(netconfig_eap_notifier.user_data);
        netconfig_eap_notifier.user_data = NULL;
 
-       netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier);
+       wifi_state_notifier_unregister(&netconfig_eap_notifier);
 }
 
 gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                const gchar *service, GVariant *fields)
 {
        gboolean updated = FALSE;
-       gboolean reply = FALSE;
        gboolean result = FALSE;
 
-       g_return_val_if_fail(wifi != NULL, FALSE);
+       g_return_val_if_fail(wifi != NULL, TRUE);
 
        DBG("Set agent fields for %s", service);
 
        if (netconfig_is_wifi_profile(service) != TRUE) {
                netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService");
-               return reply;
+               return TRUE;
        }
 
        updated = __netconfig_create_config(fields);
@@ -485,37 +505,36 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                }
 
                result = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
-                               service, CONNMAN_SERVICE_INTERFACE, "Connect", NULL, NULL);
+                               service, CONNMAN_SERVICE_INTERFACE, "Connect",
+                               NULL, __netconfig_wifi_connect_reply);
 
                if (netconfig_eap_notifier.user_data != NULL) {
                        g_free(netconfig_eap_notifier.user_data);
                        netconfig_eap_notifier.user_data = NULL;
 
-                       netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier);
+                       wifi_state_notifier_unregister(&netconfig_eap_notifier);
                }
 
                netconfig_eap_notifier.user_data = g_strdup(service);
-               netconfig_wifi_state_notifier_register(&netconfig_eap_notifier);
+               wifi_state_notifier_register(&netconfig_eap_notifier);
        } else {
                netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
        }
 
        if (result != TRUE)
                ERR("Fail to connect %s", service);
-       else
-               reply = TRUE;
 
-       return reply;
+       return TRUE;
 }
 
 gboolean handle_delete_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                const gchar *profile)
 {
-       g_return_val_if_fail(wifi != NULL, FALSE);
+       g_return_val_if_fail(wifi != NULL, TRUE);
 
        wifi_complete_delete_eap_config(wifi, context);
 
-       gboolean ret = __netconfig_delete_config((const char *)profile);
+       __netconfig_delete_config((const char *)profile);
 
-       return ret;
+       return TRUE;
 }