#define NETCONFIG_AGENT_FIELD_WPS "WPS"
#define NETCONFIG_AGENT_FIELD_WPS_PBC "WPS_PBC"
#define NETCONFIG_AGENT_FIELD_WPS_PIN "WPS_PIN"
+#if defined TIZEN_CAPTIVE_PORTAL
+#define NETCONFIG_AGENT_FIELD_USERNAME "Username"
+#define NETCONFIG_AGENT_FIELD_PASSWORD "Password"
+#endif
#define NETCONFIG_AGENT_ERR_CONNECT_FAILED "connect-failed"
-struct netconfig_wifi_agent {
+typedef struct {
+ char *interface_name;
GByteArray *ssid;
char *name;
char *identity;
char *passphrase;
char *wps_pin;
+#if defined TIZEN_CAPTIVE_PORTAL
+ char *username;
+ char *password;
+#endif
gboolean wps_pbc;
-};
+} netconfig_wifi_agent_s;
-static struct netconfig_wifi_agent agent;
+static GSList *g_agent_list = NULL;
-static void __netconfig_agent_clear_fields(void)
+static void __agent_clear_fields(netconfig_wifi_agent_s *agent)
{
- if (agent.ssid)
- g_byte_array_free(agent.ssid, TRUE);
- g_free(agent.name);
- g_free(agent.identity);
- g_free(agent.passphrase);
- g_free(agent.wps_pin);
-
- agent.ssid = NULL;
- agent.name = NULL;
- agent.identity = NULL;
- agent.passphrase = NULL;
- agent.wps_pin = NULL;
- agent.wps_pbc = FALSE;
+ if (!agent)
+ return;
+
+ g_free(agent->interface_name);
+ if (agent->ssid)
+ g_byte_array_free(agent->ssid, TRUE);
+ g_free(agent->name);
+ g_free(agent->identity);
+ g_free(agent->passphrase);
+ g_free(agent->wps_pin);
+#if defined TIZEN_CAPTIVE_PORTAL
+ g_free(agent->username);
+ g_free(agent->password);
+#endif
+
+ agent->interface_name = NULL;
+ agent->ssid = NULL;
+ agent->name = NULL;
+ agent->identity = NULL;
+ agent->passphrase = NULL;
+ agent->wps_pin = NULL;
+#if defined TIZEN_CAPTIVE_PORTAL
+ agent->username = NULL;
+ agent->password = NULL;
+#endif
+ agent->wps_pbc = FALSE;
+}
+
+static void __agent_free_data(gpointer data)
+{
+ netconfig_wifi_agent_s *agent = data;
+
+ __agent_clear_fields(agent);
+ g_free(agent);
+}
+
+static netconfig_wifi_agent_s *__agent_get_data(const char *interface_name)
+{
+ GSList *list = NULL;
+
+ for (list = g_agent_list; list; list = list->next) {
+ netconfig_wifi_agent_s *wifi_agent = list->data;
+ if (g_strcmp0(wifi_agent->interface_name, interface_name) == 0)
+ return wifi_agent;
+ }
+
+ return NULL;
}
int connman_register_agent(void)
reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
- "UnregisterAgent", param, NULL);
+ "UnregisterAgent", param, NULL, NULL);
if (reply != TRUE)
ERR("Fail to unregister agent");
/* Clearing the agent fields */
- __netconfig_agent_clear_fields();
+ g_slist_free_full(g_agent_list, __agent_free_data);
return reply;
}
-gboolean netconfig_wifi_set_agent_field_for_eap_network(
- const char *name, const char *identity, const char *passphrase)
+gboolean netconfig_wifi_set_agent_field_for_eap_network(const char *interface_name,
+ const char *name, const char *identity, const char *passphrase)
{
int name_len;
+ netconfig_wifi_agent_s *wifi_agent = NULL;
if (name == NULL)
return FALSE;
- __netconfig_agent_clear_fields();
+ wifi_agent = __agent_get_data(interface_name);
+ if (wifi_agent == NULL)
+ return FALSE;
+
+ __agent_clear_fields(wifi_agent);
name_len = strlen(name);
- agent.ssid = g_byte_array_sized_new(name_len);
- agent.ssid->len = name_len;
- memcpy(agent.ssid->data, name, name_len + 1);
+ wifi_agent->ssid = g_byte_array_sized_new(name_len);
+ wifi_agent->ssid->len = name_len;
+ memcpy(wifi_agent->ssid->data, name, name_len + 1);
if (identity)
- agent.identity = g_strdup(identity);
+ wifi_agent->identity = g_strdup(identity);
if (passphrase)
- agent.passphrase = g_strdup(passphrase);
+ wifi_agent->passphrase = g_strdup(passphrase);
gchar *enc_data = NULL;
- enc_data = _netconfig_encrypt_passphrase(agent.passphrase);
+ enc_data = _netconfig_encrypt_passphrase(wifi_agent->passphrase);
if (!enc_data) {
ERR("Failed to encrypt the passphrase");
} else {
- g_free(agent.passphrase);
- agent.passphrase = enc_data;
+ g_free(wifi_agent->passphrase);
+ wifi_agent->passphrase = enc_data;
}
DBG("Successfully configured for EAP network");
GVariant *value;
gboolean updated = FALSE;
gboolean reply = FALSE;
+ const char *interface_name = NULL;
+ netconfig_wifi_agent_s *wifi_agent = NULL;
g_return_val_if_fail(connman_agent != NULL, TRUE);
return TRUE;
}
- __netconfig_agent_clear_fields();
+ interface_name = netconfig_get_ifname(service);
+ if (interface_name == NULL) {
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ CONNMAN_ERROR_INTERFACE ".InvalidService");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
+
+ return TRUE;
+ }
+
+ wifi_agent = __agent_get_data(interface_name);
+ if (wifi_agent == NULL) {
+ wifi_agent = g_try_malloc0(sizeof(netconfig_wifi_agent_s));
+ if (wifi_agent == NULL) {
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ CONNMAN_ERROR_INTERFACE ".OutOfMemory");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
+
+ return TRUE;
+ }
+
+ g_agent_list = g_slist_append(g_agent_list, wifi_agent);
+ }
+
+ __agent_clear_fields(wifi_agent);
+ wifi_agent->interface_name = g_strdup(interface_name);
+
g_variant_get(fields, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- agent.passphrase = g_strdup(g_variant_get_string(value, NULL));
+ wifi_agent->passphrase = g_strdup(g_variant_get_string(value, NULL));
updated = TRUE;
- DBG("Field [%s] - []", field);
+ DBG("Field [%s] - []", (gchar *)field);
- if (agent.passphrase == NULL)
+ if (wifi_agent->passphrase == NULL)
continue;
- if (netconfig_check_passphrase(service, agent.passphrase) == FALSE) {
+ if (netconfig_check_passphrase(service, wifi_agent->passphrase) == FALSE) {
ERR("Invalid passphrase");
- g_free(agent.passphrase);
- agent.passphrase = NULL;
+ g_free(wifi_agent->passphrase);
+ wifi_agent->passphrase = NULL;
updated = FALSE;
continue;
}
gchar *enc_data = NULL;
- enc_data = _netconfig_encrypt_passphrase(agent.passphrase);
+ enc_data = _netconfig_encrypt_passphrase(wifi_agent->passphrase);
if (!enc_data) {
ERR("Failed to encrypt the passphrase");
continue;
}
- g_free(agent.passphrase);
- agent.passphrase = enc_data;
+ g_free(wifi_agent->passphrase);
+ wifi_agent->passphrase = enc_data;
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PBC) == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING) &&
g_strcmp0(g_variant_get_string(value, NULL), "enable") == 0) {
- agent.wps_pbc = TRUE;
+ wifi_agent->wps_pbc = TRUE;
updated = TRUE;
- DBG("Field [%s] - [%d]", field, agent.wps_pbc);
+ DBG("Field [%s] - [%d]", (gchar *)field, wifi_agent->wps_pbc);
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PIN) == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- agent.wps_pin = g_strdup(g_variant_get_string(value, NULL));
+ wifi_agent->wps_pin = g_strdup(g_variant_get_string(value, NULL));
updated = TRUE;
- DBG("Field [%s] - []", field);
+ DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->wps_pin);
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- agent.name = g_strdup(g_variant_get_string(value, NULL));
+ wifi_agent->name = g_strdup(g_variant_get_string(value, NULL));
updated = TRUE;
- DBG("Field [%s] - []", field);
+ DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->name);
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0) {
- if (agent.ssid != NULL) {
- g_byte_array_free(agent.ssid, TRUE);
- agent.ssid = NULL;
+ if (wifi_agent->ssid != NULL) {
+ g_byte_array_free(wifi_agent->ssid, TRUE);
+ wifi_agent->ssid = NULL;
}
if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) {
g_byte_array_append(array, &char_value, 1);
g_variant_iter_free(iter1);
if (array != NULL && (array->len > 0)) {
- agent.ssid = g_byte_array_sized_new(array->len);
- agent.ssid->len = array->len;
- memcpy(agent.ssid->data, array->data, array->len);
+ wifi_agent->ssid = g_byte_array_sized_new(array->len);
+ wifi_agent->ssid->len = array->len;
+ memcpy(wifi_agent->ssid->data, array->data, array->len);
updated = TRUE;
- DBG("Field [%s] - []", field);
+ DBG("Field [%s] - []", (gchar *)field);
}
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0) {
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- agent.identity = g_strdup(g_variant_get_string(value, NULL));
+ wifi_agent->identity = g_strdup(g_variant_get_string(value, NULL));
updated = TRUE;
- DBG("Field [%s] - []", field);
+ DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->identity);
}
+#if defined TIZEN_CAPTIVE_PORTAL
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_USERNAME) == 0) {
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ wifi_agent->username = g_strdup(g_variant_get_string(value, NULL));
+ updated = TRUE;
+
+ DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->username);
+ }
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0) {
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ wifi_agent->password = g_strdup(g_variant_get_string(value, NULL));
+ updated = TRUE;
+
+ DBG("Field [%s] - [%s]", (gchar *)field, wifi_agent->password);
+ }
+#endif
}
}
+ g_variant_iter_free(iter);
+
if (updated == TRUE) {
reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
service, CONNMAN_SERVICE_INTERFACE, "Connect",
- NULL, __netconfig_wifi_connect_reply);
- if (reply == TRUE) {
- g_dbus_method_invocation_return_value(context, NULL);
- } else {
+ NULL, __netconfig_wifi_connect_reply,
+ g_strdup(interface_name));
+ if (reply != TRUE) {
ERR("Fail to connect Wi-Fi");
- __netconfig_agent_clear_fields();
+ __agent_clear_fields(wifi_agent);
error = g_error_new(G_DBUS_ERROR,
G_DBUS_ERROR_AUTH_FAILED,
CONNMAN_ERROR_INTERFACE ".InvalidArguments");
g_dbus_method_invocation_return_gerror(context, error);
g_clear_error(&error);
+ return TRUE;
}
} else {
+ ERR("Fail to connect Wi-Fi");
+ __agent_clear_fields(wifi_agent);
+
error = g_error_new(G_DBUS_ERROR,
G_DBUS_ERROR_AUTH_FAILED,
CONNMAN_ERROR_INTERFACE ".InvalidArguments");
g_dbus_method_invocation_return_gerror(context, error);
g_clear_error(&error);
+ return TRUE;
}
- if (reply != TRUE) {
- ERR("Fail to connect Wi-Fi");
- __netconfig_agent_clear_fields();
- }
- g_variant_iter_free(iter);
-
net_connman_agent_complete_set_field(connman_agent, context);
return TRUE;
}
GVariant *out_table = NULL;
gboolean updated = FALSE;
GVariantBuilder *builder = NULL;
+ GError *error = NULL;
+ const char *interface_name = NULL;
+ netconfig_wifi_agent_s *wifi_agent = NULL;
g_return_val_if_fail(connman_agent != NULL, TRUE);
if (NULL == service)
- return FALSE;
+ return TRUE;
DBG("Agent fields requested for service: %s", service);
+ interface_name = netconfig_get_ifname(service);
+ if (interface_name == NULL) {
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ CONNMAN_ERROR_INTERFACE ".InvalidService");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
+
+ return TRUE;
+ }
+
+ wifi_agent = __agent_get_data(interface_name);
+ if (wifi_agent == NULL) {
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ CONNMAN_ERROR_INTERFACE ".InvalidService");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
+
+ return TRUE;
+ }
+
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
g_variant_get(fields, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &field, &r_value)) {
if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0 &&
- agent.passphrase != NULL) {
+ wifi_agent->passphrase != NULL) {
g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSPHRASE,
- g_variant_new_string(agent.passphrase));
+ g_variant_new_string(wifi_agent->passphrase));
updated = TRUE;
- DBG("Setting [%s] - []", field);
+ DBG("Setting [%s] - [%s]", field, wifi_agent->passphrase);
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS) == 0 &&
- (agent.wps_pbc == TRUE || agent.wps_pin != NULL)) {
- if (agent.wps_pbc == TRUE) {
+ (wifi_agent->wps_pbc == TRUE || wifi_agent->wps_pin != NULL)) {
+ if (wifi_agent->wps_pbc == TRUE) {
/* Sending empty string for WPS push button method */
- g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, g_variant_new_string(""));
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS,
+ g_variant_new_string(""));
updated = TRUE;
DBG("Setting empty string for [%s]", field);
- } else if (agent.wps_pin != NULL) {
- g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS, g_variant_new_string(agent.wps_pin));
+ } else if (wifi_agent->wps_pin != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_WPS,
+ g_variant_new_string(wifi_agent->wps_pin));
updated = TRUE;
- DBG("Setting string [%s] - []", field);
+ DBG("Setting string [%s] - [%s]", field, wifi_agent->wps_pin);
}
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0 &&
- agent.name != NULL) {
- g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_NAME, g_variant_new_string(agent.name));
+ wifi_agent->name != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_NAME,
+ g_variant_new_string(wifi_agent->name));
updated = TRUE;
- DBG("Settings [%s] - []", field);
+ DBG("Settings [%s] - [%s]", field, wifi_agent->name);
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0 &&
- agent.ssid != NULL) {
+ wifi_agent->ssid != NULL) {
int i = 0;
GVariantBuilder *builder1 = NULL;
builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- for (i = 0; i < (agent.ssid->len); i++)
- g_variant_builder_add(builder1, "y", agent.ssid->data[i]);
+ for (i = 0; i < (wifi_agent->ssid->len); i++)
+ g_variant_builder_add(builder1, "y", wifi_agent->ssid->data[i]);
+
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_SSID,
+ g_variant_builder_end(builder1));
- g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_SSID, g_variant_builder_end(builder1));
- if (builder1 != NULL)
- g_variant_builder_unref(builder1);
+ g_variant_builder_unref(builder1);
updated = TRUE;
DBG("Settings [%s] - []", field);
} else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0 &&
- agent.identity != NULL) {
- g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_IDENTITY, g_variant_new_string(agent.identity));
+ wifi_agent->identity != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_IDENTITY,
+ g_variant_new_string(wifi_agent->identity));
updated = TRUE;
- DBG("Settings [%s] - []", field);
+ DBG("Settings [%s] - [%s]", field, wifi_agent->identity);
+#if defined TIZEN_CAPTIVE_PORTAL
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_USERNAME) == 0 &&
+ wifi_agent->username != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_USERNAME,
+ g_variant_new_string(wifi_agent->username));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, wifi_agent->username);
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0 &&
+ wifi_agent->password != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSWORD,
+ g_variant_new_string(wifi_agent->password));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, wifi_agent->password);
+#endif
}
}
out_table = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
- if (builder)
- g_variant_builder_unref(builder);
+ g_variant_builder_unref(builder);
g_variant_iter_free(iter);
g_clear_error(&error);
}
- __netconfig_agent_clear_fields();
+ __agent_clear_fields(wifi_agent);
return TRUE;
}
return FALSE;
}
-static void __wifi_state_monitor(wifi_service_state_e state,
- void *user_data);
+static void __wifi_state_monitor(wifi_state_notifier_s *notifier,
+ char *service, wifi_service_state_e state, void *user_data);
-static wifi_state_notifier wifi_state_monitor_notifier = {
+static wifi_state_notifier_s wifi_state_monitor_notifier = {
+ .notifier = NULL,
+ .service = NULL,
.wifi_state_changed = __wifi_state_monitor,
.user_data = NULL,
};
-static void __wifi_state_monitor(wifi_service_state_e state,
- void *user_data)
+static void __wifi_state_monitor(wifi_state_notifier_s *notifier,
+ char *service, wifi_service_state_e state, void *user_data)
{
DBG("Wi-Fi state: %x", state);
}
/* Disconnect and forget the AP */
- service_profile = (char*) netconfig_get_default_profile();
+ service_profile = (char *)netconfig_get_default_profile();
if (service_profile && netconfig_is_wifi_profile(service_profile)) {
/* Now forget the AP*/
reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
ERR("Failed to forget the AP ");
}
} else {
- if (NETCONFIG_WIFI_CONNECTED ==
- wifi_state_get_service_state()) {
+ if (wifi_state_get_service_state(netconfig_get_default_ifname())
+ == NETCONFIG_WIFI_CONNECTED) {
/* check Internet availability by sending and receiving data*/
netconfig_check_internet_accessibility();
/* Returning TRUE itself is enough to restart the timer */