#include "wifi-state.h"
#include "wifi-config.h"
#include "wifi-eap-config.h"
+#include "network-state.h"
#include "neterror.h"
#define CONNMAN_CONFIG_FIELD_TYPE "Type"
return str;
}
-static int __config_save(const char *ssid, GKeyFile *keyfile)
+static int __config_save(const char *mac_addr, GKeyFile *keyfile)
{
gchar *data = NULL;
gchar *config_file = NULL;
FILE *file = NULL;
int err = 0;
- config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, ssid);
+ config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, mac_addr);
if (config_file == NULL) {
err = -ENOMEM;
goto out;
return err;
}
-static int __config_delete(const char *ssid)
+static int __config_delete(const char *mac_addr, const char *ssid)
{
int err = 0;
gchar *group_name = NULL;
GKeyFile *keyfile = NULL;
GError *error = NULL;
- config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, ssid);
+ config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, mac_addr);
if (config_file == NULL)
return -ENOMEM;
ERR("Failed to remove %s", cert_path);
g_free(cert_path);
- dirname = g_strdup_printf("%s/%s", WIFI_CERT_STORAGEDIR, ssid);
+ dirname = g_strdup_printf("%s/%s_%s", WIFI_CERT_STORAGEDIR, mac_addr, ssid);
if (dirname != NULL) {
if (g_file_test(dirname, G_FILE_TEST_EXISTS) == TRUE)
if (g_file_test(dirname, G_FILE_TEST_IS_DIR) == TRUE)
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;
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);
}
- INFO("Successfully installed[%d]", length);
+ INFO("Successfully installed[%zd]", length);
g_free(buf);
if (remove(src) != 0)
return result;
}
-static gboolean __netconfig_create_config(GVariant *fields)
+static gboolean __netconfig_create_config(const char *profile, GVariant *fields)
{
GKeyFile *keyfile = NULL;
GVariantIter *iter;
gboolean updated = FALSE;
gchar *cert_file = NULL;
gchar *cert_path = NULL;
+ char mac_str[13] = { 0, };
int err = 0;
g_variant_get(fields, "a{ss}", &iter);
goto out;
}
+ memcpy(mac_str, &profile[strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX)], 12);
+ mac_str[12] = '\0';
+
/* Create unique service group name */
group_name = g_strdup_printf("service_%s", encoded_ssid);
if (group_name == NULL) {
g_strcmp0(field, CONNMAN_CONFIG_FIELD_EAP_METHOD) == 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)
g_key_file_set_string(keyfile, group_name, field, value);
} else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_CA_CERT_FILE) == 0 ||
cert_file = strrchr(value, '/');
if (cert_file == NULL) {
ERR("Failed to get cert file: %s", value);
+ g_free(field);
+ g_free(value);
goto out;
}
cert_file++;
- DBG("field: %s, value: %s", field, cert_file);
- dirname = g_strdup_printf("%s/%s",
- WIFI_CERT_STORAGEDIR, encoded_ssid);
+ dirname = g_strdup_printf("%s/%s_%s", WIFI_CERT_STORAGEDIR,
+ mac_str, encoded_ssid);
if (dirname == NULL) {
ERR("Failed to create dirname");
+ g_free(field);
+ g_free(value);
goto out;
}
if (g_file_test(dirname, G_FILE_TEST_IS_DIR) != TRUE) {
S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST) {
g_free(dirname);
+ g_free(field);
+ g_free(value);
goto out;
}
}
}
g_free(dirname);
- cert_path = g_strdup_printf("%s/%s/%s",
- WIFI_CERT_STORAGEDIR, encoded_ssid, cert_file);
+ cert_path = g_strdup_printf("%s/%s_%s/%s", WIFI_CERT_STORAGEDIR,
+ mac_str, encoded_ssid, cert_file);
if (cert_path == NULL) {
ERR("Failed to create cert path");
+ g_free(field);
+ g_free(value);
goto out;
}
if (__netconfig_copy_config(value, cert_path) != TRUE) {
ERR("Failed to read cert file %s", value);
g_free(cert_path);
+ g_free(field);
+ g_free(value);
goto out;
}
g_free(cert_path);
}
} else {
- DBG("field: %s, value: %s", field, value);
-
if (value != NULL)
g_key_file_set_string(keyfile, group_name, field, value);
}
}
- err = __config_save((const char *)encoded_ssid, keyfile);
+ err = __config_save(mac_str, keyfile);
if (err < 0)
- ERR("Failed to create configuration %s[%d]", encoded_ssid, err);
+ ERR("Failed to create configuration %s[%d]", mac_str, err);
else {
- DBG("Successfully created %s", encoded_ssid);
+ DBG("Successfully created %s", mac_str);
updated = TRUE;
}
return updated;
}
-static gboolean _delete_configuration(const gchar *profile)
+static gboolean _delete_configuration(const char *interface_name, const char *profile)
{
gboolean ret = FALSE;
gchar *config_id = NULL;
}
ERR("get config_id [%s] from [%s]", config_id, profile);
- ret = wifi_config_remove_configuration(config_id);
+ ret = wifi_config_remove_configuration(interface_name, config_id);
if (ret != TRUE)
ERR("Fail to wifi_config_remove_configuration [%s]", config_id);
char *ssid = NULL;
int ssid_len = 0;
int err = 0;
+ const char *interface_name = NULL;
+ char mac_str[13] = { 0, };
if (NULL == profile) {
ERR("Invalid profile name");
return FALSE;
}
- if (_delete_configuration(profile) != TRUE)
+ interface_name = netconfig_get_ifname(profile);
+ if (interface_name == NULL) {
+ ERR("Invalid profile name");
+ return FALSE;
+ }
+
+ if (_delete_configuration(interface_name, profile) != TRUE)
ERR("Fail to delete configuration [%s]", profile);
wifi_ident = strstr(profile, "wifi_");
}
g_strlcpy(ssid, essid, ssid_len + 1); /* include NULL-terminated */
- err = __config_delete((const char *)ssid);
+
+ memcpy(mac_str, &profile[strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX)], 12);
+ mac_str[12] = '\0';
+
+ err = __config_delete(mac_str, ssid);
if (err < 0) {
ERR("Failed to delete configuration %s[%d]", ssid, err);
g_free(ssid);
return TRUE;
}
-static void __netconfig_eap_state(
- wifi_service_state_e state, void *user_data);
-
-static wifi_state_notifier netconfig_eap_notifier = {
- .wifi_state_changed = __netconfig_eap_state,
- .user_data = NULL,
-};
-
-static void __netconfig_eap_state(
- wifi_service_state_e state, void *user_data)
+static void __netconfig_eap_state(wifi_state_notifier_s *notifier,
+ char *service, wifi_service_state_e state, void *user_data)
{
- const char *wifi_profile = (const char *)user_data;
+ if (notifier == NULL)
+ return;
- if (wifi_profile == NULL) {
- wifi_state_notifier_unregister(&netconfig_eap_notifier);
+ if (service == NULL) {
+ wifi_state_notifier_unregister(notifier);
+ g_free(notifier->service);
+ g_free(notifier->user_data);
+ g_free(notifier);
return;
}
return;
if (state == NETCONFIG_WIFI_FAILURE)
- __netconfig_delete_config(wifi_profile);
+ __netconfig_delete_config(service);
- g_free(netconfig_eap_notifier.user_data);
- netconfig_eap_notifier.user_data = NULL;
-
- wifi_state_notifier_unregister(&netconfig_eap_notifier);
+ wifi_state_notifier_unregister(notifier);
+ g_free(notifier->service);
+ g_free(notifier->user_data);
+ g_free(notifier);
}
gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
const gchar *service, GVariant *fields)
{
gboolean updated = FALSE;
- gboolean reply = FALSE;
gboolean result = FALSE;
+ wifi_state_notifier_s *state_notifier = NULL;
+ const char *interface_name = NULL;
- 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;
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService");
+ return TRUE;
+ }
+
+ interface_name = netconfig_get_ifname(service);
+ if (interface_name == NULL) {
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService");
+ return TRUE;
}
- updated = __netconfig_create_config(fields);
+ updated = __netconfig_create_config(service, fields);
if (updated == TRUE) {
wifi_complete_create_eap_config(wifi, context);
passphrase = (const char *)value;
}
- netconfig_wifi_set_agent_field_for_eap_network(
- name, identity, passphrase);
+ netconfig_wifi_set_agent_field_for_eap_network(interface_name,
+ name, identity, passphrase);
g_variant_iter_free(iter);
}
result = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
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;
-
- wifi_state_notifier_unregister(&netconfig_eap_notifier);
+ NULL, __netconfig_wifi_connect_reply,
+ g_strdup(interface_name));
+
+ state_notifier = g_try_malloc0(sizeof(wifi_state_notifier_s));
+ if (state_notifier) {
+ state_notifier->notifier = state_notifier;
+ state_notifier->service = g_strdup(service);
+ state_notifier->wifi_state_changed = __netconfig_eap_state;
+ wifi_state_notifier_register(state_notifier);
}
-
- netconfig_eap_notifier.user_data = g_strdup(service);
- 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);
+ __netconfig_delete_config(profile);
- gboolean ret = __netconfig_delete_config((const char *)profile);
+ wifi_complete_delete_eap_config(wifi, context);
- return ret;
+ return TRUE;
}