+ if (NULL == profile) {
+ ERR("Invalid profile name");
+ 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");
+ return FALSE;
+ }
+
+ essid = strchr(wifi_ident + 5, '_');
+ if (essid == NULL) {
+ ERR("Invalid profile name");
+ return FALSE;
+ }
+
+ essid++;
+ mode = strchr(essid, '_');
+
+ ssid_len = mode - essid;
+
+ ssid = g_try_malloc0(ssid_len + 1);
+ if (ssid == NULL) {
+ ERR("Memory allocation failed");
+ return FALSE;
+ }
+
+ g_strlcpy(ssid, essid, ssid_len + 1); /* include NULL-terminated */
+ err = __config_delete((const char *)ssid);
+ if (err < 0) {
+ ERR("Failed to delete configuration %s[%d]", ssid, err);
+ g_free(ssid);
+ return FALSE;
+ }
+
+ DBG("Successfully deleted %s with length %d", ssid, ssid_len);
+
+ 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)
+{
+ const char *wifi_profile = (const char *)user_data;
+
+ if (wifi_profile == NULL) {
+ wifi_state_notifier_unregister(&netconfig_eap_notifier);
+ return;
+ }
+
+ if (state != NETCONFIG_WIFI_CONNECTED && state != NETCONFIG_WIFI_FAILURE)
+ return;
+
+ if (state == NETCONFIG_WIFI_FAILURE)
+ __netconfig_delete_config(wifi_profile);
+
+ g_free(netconfig_eap_notifier.user_data);
+ netconfig_eap_notifier.user_data = NULL;
+
+ 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 result = 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 TRUE;
+ }
+
+ updated = __netconfig_create_config(fields);
+ if (updated == TRUE) {
+ wifi_complete_create_eap_config(wifi, context);
+
+ if (g_strstr_len(service, strlen(service), "_hidden_") != NULL) {
+ GVariantIter *iter;
+ char *field, *value;
+ const char *name = NULL;
+ const char *identity = NULL;
+ const char *passphrase = NULL;
+
+ g_variant_get(fields, "a{ss}", &iter);
+
+ while (g_variant_iter_loop(iter, "{ss}", &field, &value)) {
+ if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_NAME) == 0)
+ name = (const char *)value;
+ else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0)
+ name = (const char *)value;
+ else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_IDENTITY) == 0)
+ identity = (const char *)value;
+ else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_PASSPHRASE) == 0)
+ passphrase = (const char *)value;
+ }
+
+ netconfig_wifi_set_agent_field_for_eap_network(
+ name, identity, passphrase);
+
+ g_variant_iter_free(iter);