/*
* Network Configuration Module
*
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <stdio.h>
+#include <vconf.h>
+#include <stdlib.h>
#include <unistd.h>
+#include <vconf-keys.h>
-#include "wifi-agent.h"
#include "log.h"
+#include "util.h"
#include "wifi.h"
#include "netdbus.h"
-
-static NetconfigWifiAgentFields agent;
-
-static void _netconfig_agent_clear_fields(void)
+#include "wifi-agent.h"
+#include "wifi-state.h"
+#include "wifi-eap-config.h"
+#include "network-state.h"
+#include "network-accessibility.h"
+#include "wifi-key-encryption.h"
+
+#define NETCONFIG_AGENT_FIELD_NAME "Name"
+#define NETCONFIG_AGENT_FIELD_SSID "SSID"
+#define NETCONFIG_AGENT_FIELD_IDENTITY "Identity"
+#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"
+#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 {
+ GByteArray *ssid;
+ char *name;
+ char *identity;
+ char *passphrase;
+ char *wps_pin;
+#if defined TIZEN_CAPTIVE_PORTAL
+ char *username;
+ char *password;
+#endif
+ gboolean wps_pbc;
+};
+
+static struct netconfig_wifi_agent agent;
+
+static void __netconfig_agent_clear_fields(void)
{
- DBG("_netconfig_agent_clear_fields");
-
- g_free(agent.passphrase);
+ 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.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;
}
-gboolean netconfig_agent_register(void)
+int connman_register_agent(void)
{
- DBG("netconfig_agent_register");
-
- DBusMessage *reply = NULL;
- char param1[64] = "";
- char *param_array[] = {NULL, NULL};
-
- snprintf(param1, 64, "objpath:%s", NETCONFIG_WIFI_PATH);
- param_array[0] = param1;
+ GVariant *reply = NULL;
+ GVariant *params = NULL;
+ params = g_variant_new("(o)", NETCONFIG_WIFI_PATH);
reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
- "RegisterAgent", param_array);
+ "RegisterAgent", params);
if (reply == NULL) {
- ERR("Error! Request failed");
- return FALSE;
- }
+ ERR("Fail to register agent");
+ return FALSE;
+ } else
+ g_variant_unref(reply);
- dbus_message_unref(reply);
+ INFO("Registered to connman agent successfully");
return TRUE;
}
-gboolean netconfig_agent_unregister(void)
+int connman_unregister_agent(void)
{
- DBG("netconfig_agent_unregister");
+ gboolean reply = FALSE;
+ GVariant *param = NULL;
+ const char *path = NETCONFIG_WIFI_PATH;
- DBusMessage *reply = NULL;
- char param1[64] = "";
- char *param_array[] = {NULL, NULL};
+ param = g_variant_new("(o)", path);
- snprintf(param1, 64, "objpath:%s", NETCONFIG_WIFI_PATH);
- param_array[0] = param1;
+ DBG("ConnMan agent unregister");
- reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
+ reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
- "UnregisterAgent", param_array);
+ "UnregisterAgent", param, NULL);
- if (reply == NULL) {
- ERR("Error! Request failed");
+ if (reply != TRUE)
+ ERR("Fail to unregister agent");
+
+ /* Clearing the agent fields */
+ __netconfig_agent_clear_fields();
+
+ return reply;
+}
+
+gboolean netconfig_wifi_set_agent_field_for_eap_network(
+ const char *name, const char *identity, const char *passphrase)
+{
+ int name_len;
+
+ if (name == NULL)
return FALSE;
- }
- dbus_message_unref(reply);
+ __netconfig_agent_clear_fields();
- /* Clearing the agent fields */
- _netconfig_agent_clear_fields();
+ 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);
+
+ if (identity)
+ agent.identity = g_strdup(identity);
+
+ if (passphrase)
+ agent.passphrase = g_strdup(passphrase);
+
+ gchar *enc_data = NULL;
+ enc_data = _netconfig_encrypt_passphrase(agent.passphrase);
+
+ if (!enc_data) {
+ ERR("Failed to encrypt the passphrase");
+ } else {
+ g_free(agent.passphrase);
+ agent.passphrase = enc_data;
+ }
+
+ DBG("Successfully configured for EAP network");
return TRUE;
}
-gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi,
- GHashTable *fields, GError **error)
+gboolean handle_set_field(NetConnmanAgent *connman_agent,
+ GDBusMethodInvocation *context, const gchar *service, GVariant *fields)
{
- DBG("netconfig_iface_wifi_set_field");
- g_return_val_if_fail(wifi != NULL, FALSE);
+ GError *error = NULL;
+ GVariantIter *iter;
+ gpointer field;
+ GVariant *value;
+ gboolean updated = FALSE;
+ gboolean reply = FALSE;
+
+ g_return_val_if_fail(connman_agent != NULL, TRUE);
+
+ DBG("Set agent fields for %s", service);
+
+ if (netconfig_is_wifi_profile(service) != TRUE) {
+ 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;
+ }
+
+ __netconfig_agent_clear_fields();
+ 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));
+ updated = TRUE;
+
+ DBG("Field [%s] - []", field);
+
+ if (agent.passphrase == NULL)
+ continue;
- GHashTableIter iter;
- gpointer field, value;
+ if (netconfig_check_passphrase(service, agent.passphrase) == FALSE) {
+ ERR("Invalid passphrase");
+
+ g_free(agent.passphrase);
+ agent.passphrase = NULL;
+
+ updated = FALSE;
+ continue;
+ }
+
+ gchar *enc_data = NULL;
+ enc_data = _netconfig_encrypt_passphrase(agent.passphrase);
+
+ if (!enc_data) {
+ ERR("Failed to encrypt the passphrase");
+ continue;
+ }
- 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);
+ 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;
+ updated = TRUE;
- if (NULL != value) {
- agent.passphrase = g_strdup(value);
- DBG("Set the agent field[%s] - [%s]", field,
- agent.passphrase);
+ DBG("Field [%s] - [%d]", field, 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));
+ updated = TRUE;
+
+ DBG("Field [%s] - [%s]", field, 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));
+ updated = TRUE;
+
+ DBG("Field [%s] - [%s]", field, 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;
}
- } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_NAME)) {
- if (NULL != agent.name) {
- g_free(agent.name);
+
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) {
+ guint8 char_value;
+ GVariantIter *iter1;
+ GByteArray *array = g_byte_array_new();
+
+ g_variant_get(value, "ay", &iter1);
+ while (g_variant_iter_loop(iter1, "y", &char_value))
+ 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);
+ updated = TRUE;
+
+ DBG("Field [%s] - []", 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));
+ updated = TRUE;
- if (NULL != value) {
- agent.name = g_strdup(value);
- DBG("Set the agent field[%s] - [%s]",
- field, agent.name);
+ DBG("Field [%s] - [%s]", field, agent.identity);
}
- } else if (!strcmp(field, NETCONFIG_AGENT_FIELD_IDENTITY)) {
- if (NULL != agent.identity) {
- g_free(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)) {
+ agent.username = g_strdup(g_variant_get_string(value, NULL));
+ updated = TRUE;
+
+ DBG("Field [%s] - [%s]", field, agent.username);
}
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0) {
+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ agent.password = g_strdup(g_variant_get_string(value, NULL));
+ updated = TRUE;
- if (NULL != value) {
- agent.identity = g_strdup(value);
- DBG("Set the agent field[%s] - [%s]",
- field, agent.identity);
+ DBG("Field [%s] - [%s]", field, agent.password);
}
+#endif
}
}
+ 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 {
+ ERR("Fail to connect Wi-Fi");
+ __netconfig_agent_clear_fields();
+ 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);
+ }
+ } else {
+ 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);
+ }
+
+ 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;
}
-gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi,
- gchar *service, GHashTable *fields,
- DBusGMethodInvocation *context)
+gboolean handle_request_input(NetConnmanAgent *connman_agent,
+ GDBusMethodInvocation *context, const gchar *service, GVariant *fields)
{
- DBG("netconfig_iface_wifi_request_input");
-
- g_return_val_if_fail(wifi != NULL, FALSE);
+ GVariantIter *iter;
+ gchar *field = NULL;
+ GVariant *r_value = NULL;
+ GVariant *out_table = NULL;
+ gboolean updated = FALSE;
+ GVariantBuilder *builder = NULL;
- GHashTableIter iter;
- gpointer field, value;
- GHashTable *out_table = NULL;
- GValue *ret_value = NULL;
+ g_return_val_if_fail(connman_agent != NULL, TRUE);
if (NULL == service)
return FALSE;
- DBG("Service - [%s]", service);
+ DBG("Agent fields requested for service: %s", service);
+
+ 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) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSPHRASE,
+ g_variant_new_string(agent.passphrase));
+
+ updated = TRUE;
+ DBG("Setting [%s] - [%s]", field, 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) {
+ /* Sending empty string for WPS push button method */
+ 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));
+
+ updated = TRUE;
+ DBG("Setting string [%s] - [%s]", field, 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));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, agent.name);
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0 &&
+ 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]);
+
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_SSID, g_variant_builder_end(builder1));
+ if (builder1 != NULL)
+ 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));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, agent.identity);
+#if defined TIZEN_CAPTIVE_PORTAL
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_USERNAME) == 0 &&
+ agent.username != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_USERNAME, g_variant_new_string(agent.username));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, agent.username);
+ } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSWORD) == 0 &&
+ agent.password != NULL) {
+ g_variant_builder_add(builder, "{sv}", NETCONFIG_AGENT_FIELD_PASSWORD, g_variant_new_string(agent.password));
+
+ updated = TRUE;
+ DBG("Settings [%s] - [%s]", field, agent.password);
+#endif
+ }
+ }
+
+ out_table = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+
+ if (builder)
+ g_variant_builder_unref(builder);
+
+ g_variant_iter_free(iter);
+
+
+ if (NULL == out_table) {
+ net_connman_agent_complete_request_input(connman_agent, context, out_table);
+
+ return TRUE;
+ }
+
+ if (updated == TRUE)
+ g_dbus_method_invocation_return_value(context, out_table);
+ else {
+ GError *error = NULL;
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ "net.connman.Agent.Error.Canceled");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
+ }
+
+ __netconfig_agent_clear_fields();
+
+ return TRUE;
+}
+
+
+gboolean handle_report_error(NetConnmanAgent *connman_agent,
+ GDBusMethodInvocation *context, const gchar *service, const gchar *error)
+{
+ g_return_val_if_fail(connman_agent != NULL, TRUE);
+
+ net_connman_agent_complete_report_error(connman_agent, context);
+ DBG("Agent error for service[%s] - [%s]", service, error);
+
+ /* Do something when it failed to make a connection */
+
+ return TRUE;
+}
+
+#if defined TIZEN_CAPTIVE_PORTAL
+#if defined TIZEN_WEARABLE
+#define QUERY_FOR_INTERNET_INTERVAL 2
+#define TIMER_THRESHOLD 4
+#else
+#define QUERY_FOR_INTERNET_INTERVAL 20
+#define TIMER_THRESHOLD 120
+#endif
+
+static gboolean is_monitor_notifier_registered = FALSE;
+
+#if defined TIZEN_WEARABLE
+static gboolean is_portal_msg_shown = FALSE;
+#endif
+
+struct poll_timer_data {
+ guint time_elapsed;
+ guint timer_id;
+ void* data;
+};
+
+static struct poll_timer_data timer_data = {
+ QUERY_FOR_INTERNET_INTERVAL, 0, NULL};
+
+static gboolean __check_ignore_portal_list(const char * ssid)
+{
+ char def_str[1024];
+ int i = 0;
+ int ignore_ap_count = 0;
+
+ if (ssid == NULL)
+ return FALSE;
+
+ DBG("checking ssid [%s]", ssid);
+
+ DBG("csc string [%s]", def_str);
+ gchar ** ignore_ap_list = g_strsplit(def_str, ",", 0);
+ ignore_ap_count = g_strv_length(ignore_ap_list);
+ for (i = 0; i < ignore_ap_count; i++) {
+ DBG("[%d] - [%s]", i, ignore_ap_list[i]);
+ if (strncmp(ignore_ap_list[i], ssid, strlen(ssid)) == 0) {
+ g_strfreev(ignore_ap_list);
+ return TRUE;
+ }
+ }
+
+ g_strfreev(ignore_ap_list);
+ return FALSE;
+}
+
+static void __wifi_state_monitor(wifi_service_state_e state,
+ void *user_data);
+
+static wifi_state_notifier wifi_state_monitor_notifier = {
+ .wifi_state_changed = __wifi_state_monitor,
+ .user_data = NULL,
+};
+
+static void __wifi_state_monitor(wifi_service_state_e state,
+ void *user_data)
+{
+ DBG("Wi-Fi state: %x", state);
+
+ if (state == NETCONFIG_WIFI_CONNECTED)
+ return;
+
+ if (is_monitor_notifier_registered == TRUE) {
+ wifi_state_notifier_unregister(&wifi_state_monitor_notifier);
+ is_monitor_notifier_registered = FALSE;
+ }
+
+#if defined TIZEN_WEARABLE
+ is_portal_msg_shown = FALSE;
+#endif
+
+ /* suspend if Internet check activity in progress */
+ if (timer_data.timer_id == 0)
+ return;
- out_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- g_free);
- if (NULL == out_table)
+ netconfig_stop_timer(&timer_data.timer_id);
+ netconfig_stop_internet_check();
+
+ DBG("Stopped Internet accessibility check");
+}
+
+static gboolean __netconfig_wifi_portal_login_timeout(gpointer data)
+{
+ char *service_profile = NULL;
+ GVariant *reply = NULL;
+
+ DBG("");
+
+ struct poll_timer_data *timer = (struct poll_timer_data *)data;
+ if (timer == NULL)
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");
- 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");
- 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 (TRUE == netconfig_get_internet_status()) {
+ if (is_monitor_notifier_registered == TRUE) {
+ wifi_state_notifier_unregister(&wifi_state_monitor_notifier);
+ is_monitor_notifier_registered = FALSE;
+ }
+
+ DBG("Portal logged in successfully and update ConnMan state");
+ return FALSE; /* to stop the timer */
+ } else {
+ if (timer->time_elapsed >= TIMER_THRESHOLD) {
+ DBG("Login failed, update ConnMan");
+
+ if (is_monitor_notifier_registered == TRUE) {
+ wifi_state_notifier_unregister(&wifi_state_monitor_notifier);
+ is_monitor_notifier_registered = FALSE;
+ }
+
+ /* Disconnect and forget the AP */
+ 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,
+ service_profile, CONNMAN_SERVICE_INTERFACE, "Remove",
+ NULL);
+
+ if (reply != NULL)
+ g_variant_unref(reply);
+ else
+ ERR("Failed to forget the AP ");
+ }
+ } else {
+ if (NETCONFIG_WIFI_CONNECTED ==
+ wifi_state_get_service_state()) {
+ /* check Internet availability by sending and receiving data*/
+ netconfig_check_internet_accessibility();
+ /* Returning TRUE itself is enough to restart the timer */
+ timer->time_elapsed = timer->time_elapsed +
+ QUERY_FOR_INTERNET_INTERVAL;
+ return TRUE;
+ }
}
}
- dbus_g_method_return(context, out_table);
+ return FALSE;
+}
+
+static void __netconfig_wifi_portal_login_timer_start(struct poll_timer_data
+ *data)
+{
+ DBG("__netconfig_wifi_browser_start_timer...starting timer");
+
+ if (data == NULL)
+ return;
+
+ netconfig_stop_timer(&(data->timer_id));
+
+ /* Timer logic: After successful launch of browser, we would check for
+ * Internet status for every 20s until a threshold of 120s
+ */
+
+ data->time_elapsed = QUERY_FOR_INTERNET_INTERVAL;
+ netconfig_start_timer_seconds(QUERY_FOR_INTERNET_INTERVAL,
+ __netconfig_wifi_portal_login_timeout, data, &(data->timer_id));
+}
+#endif
+
+gboolean handle_request_browser(NetConnmanAgent *connman_agent,
+ GDBusMethodInvocation *context, const gchar *service, const gchar *url)
+{
+#if defined TIZEN_CAPTIVE_PORTAL
+ gboolean ignore_portal = FALSE;
+ const char * ssid = NULL;
+
+ g_return_val_if_fail(connman_agent != NULL, TRUE);
+
+ DBG("service[%s] - url[%s]", service, url);
+
+ ssid = netconfig_wifi_get_connected_essid(netconfig_get_default_profile());
+ if (ssid == NULL) {
+ ERR("Connected AP name is NULL!!");
+ net_connman_agent_complete_request_browser(connman_agent, context);
+ return TRUE;
+ }
+
+ ignore_portal = __check_ignore_portal_list(ssid);
+
+ if (ignore_portal == TRUE) {
+ net_connman_agent_complete_request_browser(connman_agent, context);
+ return TRUE;
+ }
+ /* Register for Wifi state change notifier*/
+ if (is_monitor_notifier_registered == FALSE) {
+ wifi_state_notifier_register(&wifi_state_monitor_notifier);
+ is_monitor_notifier_registered = TRUE;
+ }
+
+ netconfig_send_notification_to_net_popup(NETCONFIG_ADD_PORTAL_NOTI, ssid);
+
+ timer_data.time_elapsed = 0;
+ __netconfig_wifi_portal_login_timer_start(&timer_data);
+
+ net_connman_agent_complete_request_browser(connman_agent, context);
+ return TRUE;
+#else
+ GError *error = NULL;
+ error = g_error_new(G_DBUS_ERROR,
+ G_DBUS_ERROR_AUTH_FAILED,
+ CONNMAN_ERROR_INTERFACE ".NotSupported");
+
+ g_dbus_method_invocation_return_gerror(context, error);
+ g_clear_error(&error);
return TRUE;
+#endif
}