#include <vconf.h>
#include <vconf-keys.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <eventsystem.h>
#include "log.h"
#include "util.h"
#include "netdbus.h"
+#include "setting.h"
#include "wifi-state.h"
#include "wifi-power.h"
+#include "wifi-scan.h"
#include "netsupplicant.h"
#include "network-state.h"
#include "wifi-indicator.h"
#include "network-statistics.h"
#include "wifi-background-scan.h"
+#define NETCONFIG_UPDATE_DEVICE_LIST_COUNT 3
+#define NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT 1 * 1000
#define NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT 15 * 1000
static gboolean new_bss_found = FALSE;
+
+static guint network_update_timer_cnt = 0;
+static guint network_update_timer_id = 0;
static guint network_noti_timer_id = 0;
-static wifi_service_state_e g_service_state = NETCONFIG_WIFI_UNKNOWN;
-static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
+static GSList *g_device_list = NULL;
+static GSList *g_notifier_list = NULL;
+
+static guint network_connected_popup_timer_id = 0;
+static gboolean block_network_connected_popup = FALSE;
-static GSList *notifier_list = NULL;
+static void __device_free_data(gpointer data)
+{
+ wifi_device_data_s *device_data = data;
+ g_free(device_data->interface_name);
+ g_free(device_data->mac_address);
+ g_free(device_data);
-static void __netconfig_pop_wifi_connected_poppup(const char *ssid)
+}
+
+static wifi_device_data_s *__device_get_data(const char *interface_name)
{
- bundle *b = NULL;
+ GSList *list = NULL;
- if (ssid == NULL)
- return;
+ for (list = g_device_list; list; list = list->next) {
+ wifi_device_data_s *device_data = list->data;
+ if (g_strcmp0(device_data->interface_name, interface_name) == 0)
+ return device_data;
+ }
- b = bundle_create();
+ return NULL;
+}
+
+static wifi_device_data_s *__device_get_data_by_macaddr(const char *macaddr)
+{
+ GSList *list = NULL;
- bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup");
- bundle_add(b, "_SYSPOPUP_TYPE_", "notification");
- bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected");
- bundle_add(b, "_AP_NAME_", ssid);
+ for (list = g_device_list; list; list = list->next) {
+ wifi_device_data_s *device_data = list->data;
+ if (g_ascii_strncasecmp(device_data->mac_address,
+ macaddr, MAC_ADDRESS_MAX_LEN) == 0)
+ return device_data;
+ }
+
+ return NULL;
+}
- DBG("Launch Wi-Fi connected alert network popup");
- syspopup_launch("net.netpopup", b);
+char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type)
+{
+ switch (wifi_service_state_type) {
+ case NETCONFIG_WIFI_UNKNOWN:
+ return "unknown";
+ case NETCONFIG_WIFI_IDLE:
+ return "idle";
+ case NETCONFIG_WIFI_ASSOCIATION:
+ return "association";
+ case NETCONFIG_WIFI_CONFIGURATION:
+ return "configuration";
+ case NETCONFIG_WIFI_CONNECTED:
+ return "connected";
+ case NETCONFIG_WIFI_FAILURE:
+ return "failure";
+ default:
+ ERR("Invalid wifi_service_state_e parameter");
+ break;
+ }
- bundle_free(b);
+ return "Invalid parameter";
+}
+
+char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type)
+{
+ switch (wifi_tech_state_type) {
+ case NETCONFIG_WIFI_TECH_UNKNOWN:
+ return "unknown";
+ case NETCONFIG_WIFI_TECH_OFF:
+ return "off";
+ case NETCONFIG_WIFI_TECH_WPS_ONLY:
+ return "wps only";
+ case NETCONFIG_WIFI_TECH_POWERED:
+ return "powered";
+ case NETCONFIG_WIFI_TECH_CONNECTED:
+ return "connected";
+ default:
+ ERR("Invalid wifi_tech_state_e parameter");
+ break;
+ }
+
+ return "Invalid parameter";
+}
+
+static gboolean _block_network_connection_popup(gpointer data)
+{
+ block_network_connected_popup = FALSE;
+ netconfig_stop_timer(&network_connected_popup_timer_id);
+ return FALSE;
}
static void __set_wifi_connected_essid(void)
{
const char *essid_name = NULL;
const char *wifi_profile = netconfig_get_default_profile();
+ const char *wifi_ifname = netconfig_get_default_ifname();
- if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
+ if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED)
return;
if (wifi_profile == NULL ||
return;
}
- netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name);
- __netconfig_pop_wifi_connected_poppup(essid_name);
+ netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name, TRUE);
+
+ /* Block Network Connected popup for 3sec
+ * to avoid multiple popup's due to ready signals */
+ if (block_network_connected_popup == FALSE) {
+ block_network_connected_popup = TRUE;
+ netconfig_start_timer(3000, _block_network_connection_popup,
+ NULL, &network_connected_popup_timer_id);
+ __netconfig_pop_wifi_connected_poppup(essid_name);
+ }
}
static void __unset_wifi_connected_essid(void)
{
- netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, "");
+ netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, "", TRUE);
}
static const char *__get_wifi_connected_essid(void)
{
const char *essid_name = NULL;
- const char *wifi_profile = NULL;
+ const char *wifi_profile = netconfig_get_default_profile();
+ const char *wifi_ifname = netconfig_get_default_ifname();
- if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
+ if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED)
return NULL;
- wifi_profile = netconfig_get_default_profile();
-
if (wifi_profile == NULL || netconfig_is_wifi_profile(wifi_profile) != TRUE) {
ERR("Can't get Wi-Fi profile");
return NULL;
g_variant_get(message, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
- if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE) {
+ if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE)
continue;
- }
g_variant_iter_free(next);
g_free(obj);
while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
gboolean value;
- if (g_str_equal(key, "Favorite") != TRUE) {
+ if (g_str_equal(key, "Favorite") != TRUE)
continue;
- }
value = g_variant_get_boolean(var);
if (value)
/* Add activation of services when Wi-Fi is connected */
}
-static void _wifi_state_changed(wifi_service_state_e state)
+static void _wifi_state_changed(const char *interface_name,
+ wifi_service_state_e state)
{
GSList *list;
+ const char *ifname;
+
+ for (list = g_notifier_list; list; ) {
+ wifi_state_notifier_s *notifier = list->data;
+ list = list->next;
- for (list = notifier_list; list; list = list->next) {
- wifi_state_notifier *notifier = list->data;
+ if (notifier->service) {
+ ifname = netconfig_get_ifname(notifier->service);
+ if (g_strcmp0(ifname, interface_name) != 0)
+ continue;
+ }
if (notifier->wifi_state_changed != NULL)
- notifier->wifi_state_changed(state, notifier->user_data);
+ notifier->wifi_state_changed(notifier->notifier,
+ notifier->service, state, notifier->user_data);
}
}
wifi_tech_state_e tech_state;
wifi_service_state_e service_state;
+ char *interface_name = data;
- tech_state = wifi_state_get_technology_state();
+ tech_state = wifi_state_get_technology_state(interface_name);
if (tech_state < NETCONFIG_WIFI_TECH_POWERED) {
DBG("Wi-Fi off or WPS only supported[%d]", tech_state);
goto cleanup;
}
- service_state = wifi_state_get_service_state();
+ service_state = wifi_state_get_service_state(interface_name);
if (service_state == NETCONFIG_WIFI_CONNECTED) {
DBG("Service state is connected");
goto cleanup;
goto cleanup;
}
- vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
+ netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) {
DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE");
goto cleanup;
}
- vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
- if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) {
+ netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
+ if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
goto cleanup;
- }
netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL);
g_variant_get(message, "(a(oa{sv}))", &iter);
while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
- if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE) {
+ if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE)
continue;
- }
if (__is_favorited(next) == TRUE) {
favorite_service = g_strdup(obj);
{
int value = -1;
- if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0) {
+ if (netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0)
return;
- }
- if (value == VCONFKEY_WIFI_QS_DISABLE) {
+ if (value == VCONFKEY_WIFI_QS_DISABLE)
netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
- }
}
static void _register_network_notification(void)
vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb);
}
-static void _set_power_save(gboolean power_save)
-{
- gboolean result;
- const char *if_path;
- GVariant *input_args = NULL;
- static gboolean old_state = TRUE;
- const gchar *args_disable = "POWERMODE 1";
- const gchar *args_enable = "POWERMODE 0";
- if (old_state == power_save)
- return;
-
- if_path = netconfig_wifi_get_supplicant_interface();
- if (if_path == NULL) {
- ERR("Fail to get wpa_supplicant DBus path");
- return;
- }
-
- if (power_save)
- input_args = g_variant_new_string(args_enable);
- else
- input_args = g_variant_new_string(args_disable);
-
- result = netconfig_supplicant_invoke_dbus_method_nonblock(
- SUPPLICANT_SERVICE,
- if_path,
- SUPPLICANT_INTERFACE ".Interface",
- "Driver",
- input_args,
- NULL);
- if (result == FALSE)
- ERR("Fail to set power save mode POWERMODE %d", power_save);
- else
- old_state = power_save;
-
- return;
-}
-
static void _set_power_lock(gboolean power_lock)
{
gint32 ret = 0;
"org.tizen.system.deviced.display",
lock_method,
params);
- if (reply == NULL){
+ if (reply == NULL) {
ERR("Failed to set_power_lock");
return;
}
- ret = g_variant_get_int32(reply);
- if (ret < 0)
- ERR("Failed to set power lock %s with ret %d",
+ if (g_variant_is_of_type(reply, G_VARIANT_TYPE_INT32)) {
+ ret = g_variant_get_int32(reply);
+ if (ret < 0)
+ ERR("Failed to set power lock %s with ret %d",
power_lock == TRUE ? "enable" : "disable", ret);
- else
- old_state = power_lock;
+ else
+ old_state = power_lock;
+ }
g_variant_unref(reply);
return;
}
-void wifi_state_emit_power_completed(gboolean power_on)
+void wifi_state_emit_power_completed(const char *interface_name, gboolean power_on)
{
if (power_on)
- wifi_emit_power_on_completed((Wifi *)get_wifi_object());
+ wifi_emit_power_on_completed((Wifi *)get_wifi_object(), interface_name);
else
- wifi_emit_power_off_completed((Wifi *)get_wifi_object());
+ wifi_emit_power_off_completed((Wifi *)get_wifi_object(), interface_name);
- DBG("Successfully sent signal [%s]",(power_on)?"powerOn":"powerOff");
+ DBG("Successfully sent signal [%s %s]",
+ interface_name, (power_on) ? "powerOn" : "powerOff");
}
-void wifi_state_emit_power_failed(void)
+void wifi_state_emit_power_failed(const char *interface_name)
{
- wifi_emit_power_operation_failed((Wifi *)get_wifi_object());
+ wifi_emit_power_operation_failed((Wifi *)get_wifi_object(), interface_name);
- DBG("Successfully sent signal [PowerOperationFailed]");
+ DBG("Successfully sent signal [%s PowerOperationFailed]", interface_name);
}
-void wifi_state_update_power_state(gboolean powered)
+static void __update_wifi_state(void)
+{
+ int wifi_state = VCONFKEY_WIFI_OFF;
+ int network_wifi_state = VCONFKEY_NETWORK_WIFI_OFF;
+ GSList *list = NULL;
+
+ for (list = g_device_list; list; list = list->next) {
+ wifi_device_data_s *device_data = list->data;
+ if (device_data->powered) {
+ if (wifi_state < VCONFKEY_WIFI_UNCONNECTED)
+ wifi_state = VCONFKEY_WIFI_UNCONNECTED;
+ if (network_wifi_state < VCONFKEY_NETWORK_WIFI_NOT_CONNECTED)
+ network_wifi_state = VCONFKEY_NETWORK_WIFI_NOT_CONNECTED;
+ }
+ if (device_data->connected) {
+ wifi_state = VCONFKEY_WIFI_CONNECTED;
+ network_wifi_state = VCONFKEY_NETWORK_WIFI_CONNECTED;
+ }
+ }
+
+ netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, wifi_state, TRUE);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, network_wifi_state, TRUE);
+}
+
+void wifi_state_update_power_state(const char *interface_name, gboolean powered)
{
wifi_tech_state_e tech_state;
* DO NOT update manually
* It includes Wi-Fi state configuration
*/
- tech_state = wifi_state_get_technology_state();
+ tech_state = wifi_state_get_technology_state(interface_name);
+ if (tech_state == NETCONFIG_WIFI_TECH_UNKNOWN)
+ wifi_state_update_device_list();
if (powered == TRUE) {
if (tech_state < NETCONFIG_WIFI_TECH_POWERED && netconfig_is_wifi_tethering_on() != TRUE) {
DBG("Wi-Fi turned on or waken up from power-save mode");
+ gchar *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+
+ if (mac_addr != NULL) {
+ if (strlen(mac_addr) == 0)
+ netconfig_set_mac_address_from_file();
+ g_free(mac_addr);
+ }
- wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
+ wifi_state_set_powered(interface_name, TRUE);
+ wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_POWERED);
- wifi_state_emit_power_completed(TRUE);
+ wifi_state_emit_power_completed(interface_name, TRUE);
+ netconfig_battery_start_wifi();
netconfig_wifi_device_picker_service_start();
- netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_UNCONNECTED);
- netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
+ __update_wifi_state();
- netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
+ netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
- netconfig_wifi_bgscan_stop();
- netconfig_wifi_bgscan_start(TRUE);
+ netconfig_wifi_bgscan_stop(interface_name);
+ netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN);
+ netconfig_wifi_bgscan_start(interface_name, TRUE);
/* Add callback to track change in notification setting */
_register_network_notification();
+
+ netconfig_setting_update_interface_for_last_powered(interface_name, TRUE);
}
} else if (tech_state > NETCONFIG_WIFI_TECH_OFF) {
DBG("Wi-Fi turned off or in power-save mode");
- wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY);
+ wifi_state_set_powered(interface_name, FALSE);
+ wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_WPS_ONLY);
netconfig_wifi_device_picker_service_stop();
- wifi_power_disable_technology_state_by_only_connman_signal();
- wifi_power_driver_and_supplicant(FALSE);
+ wifi_power_driver_and_supplicant(interface_name, FALSE);
- wifi_state_emit_power_completed(FALSE);
+ wifi_state_emit_power_completed(interface_name, FALSE);
+ netconfig_battery_end_wifi();
- netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF);
- netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
+ __update_wifi_state();
- netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF);
+ netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF);
- netconfig_wifi_set_bgscan_pause(FALSE);
- netconfig_wifi_bgscan_stop();
+ netconfig_wifi_bgscan_stop(interface_name);
+ netconfig_wifi_scan_set_scanning(interface_name, FALSE);
_set_bss_found(FALSE);
/* Inform net-popup to remove the wifi found notification */
netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
+ netconfig_send_notification_to_net_popup(NETCONFIG_DEL_IP_CONFLICT_NOTI, NULL);
_deregister_network_notification();
+
+ netconfig_setting_update_interface_for_last_powered(interface_name, FALSE);
}
}
return _get_connman_favorite_service();
}
-void wifi_start_timer_network_notification(void)
+void wifi_start_timer_network_notification(const char *interface_name)
{
#if defined TIZEN_WEARABLE
/* In case of wearable device, no need to notify available Wi-Fi APs */
- return ;
+ return;
#endif
- netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, _check_network_notification, NULL, &network_noti_timer_id);
+ netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT,
+ _check_network_notification, g_strdup(interface_name), &network_noti_timer_id);
}
-void wifi_state_notifier_register(wifi_state_notifier *notifier)
+void wifi_state_notifier_register(wifi_state_notifier_s *notifier)
{
DBG("register notifier");
- notifier_list = g_slist_append(notifier_list, notifier);
+ g_notifier_list = g_slist_append(g_notifier_list, notifier);
}
-void wifi_state_notifier_unregister(wifi_state_notifier *notifier)
+void wifi_state_notifier_unregister(wifi_state_notifier_s *notifier)
{
DBG("un-register notifier");
- notifier_list = g_slist_remove_all(notifier_list, notifier);
+ g_notifier_list = g_slist_remove_all(g_notifier_list, notifier);
}
void wifi_state_notifier_cleanup(void)
{
- g_slist_free_full(notifier_list, NULL);
+ g_slist_free_full(g_notifier_list, NULL);
}
void wifi_state_set_bss_found(gboolean found)
return new_bss_found;
}
-void wifi_state_set_service_state(wifi_service_state_e new_state)
+void __copy_device_statistics(wifi_device_data_s *dst_data, GSList *device_list)
+{
+ GSList *list;
+
+ for (list = device_list; list; list = list->next) {
+ wifi_device_data_s *org_data = list->data;
+ if (g_strcmp0(org_data->interface_name, dst_data->interface_name) == 0) {
+ dst_data->tx = org_data->tx;
+ dst_data->rx = org_data->rx;
+ dst_data->tx_diff = org_data->tx_diff;
+ dst_data->tx_diff = org_data->tx_diff;
+ return;
+ }
+ }
+}
+
+gboolean wifi_state_update_device_list(void)
+{
+ GVariant *message = NULL, *variant;
+ GVariantIter *iter, *next;
+ GSList *device_list = NULL;
+ const char *path;
+ gchar *key;
+ gboolean updated = FALSE;
+
+ message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
+ "GetTechnologies", NULL);
+ if (message == NULL) {
+ ERR("Failed to get technologies");
+ return updated;
+ }
+
+ DBG("Wi-Fi g_device_list: %p", g_device_list);
+
+ device_list = g_device_list;
+ g_device_list = NULL;
+
+ g_variant_get(message, "(a(oa{sv}))", &iter);
+ while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
+ if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
+ continue;
+
+ while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
+ if (g_strcmp0(key, "Device.List") == 0) {
+ GVariantIter *list_iter;
+ gchar *dev_key;
+ GVariant *dev_var;
+ const gchar *sdata;
+ wifi_device_data_s *device_data = NULL;
+
+ g_variant_get(variant, "a{sv}", &list_iter);
+ while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) {
+ if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) {
+ if (g_strcmp0(dev_key, "Ifname") == 0) {
+ device_data = g_try_malloc0(sizeof(wifi_device_data_s));
+ if (!device_data) {
+ g_variant_unref(dev_var);
+ break;
+ }
+
+ sdata = g_variant_get_string(dev_var, NULL);
+ device_data->interface_name = g_strdup(sdata);
+ g_device_list = g_slist_append(g_device_list, device_data);
+
+ updated = TRUE;
+
+ __copy_device_statistics(device_data, device_list);
+
+ } else if (g_strcmp0(dev_key, "MAC.Address") == 0) {
+ if (device_data) {
+ sdata = g_variant_get_string(dev_var, NULL);
+ device_data->mac_address = g_strdup(sdata);
+
+ DBG("Ifname[%s] MAC[%s] Powered[%d] Connected[%d]",
+ device_data->interface_name, device_data->mac_address,
+ device_data->powered, device_data->connected);
+ }
+ }
+ } else if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_BOOLEAN)) {
+ if (g_strcmp0(dev_key, "Powered") == 0) {
+ if (device_data) {
+ device_data->powered = g_variant_get_boolean(dev_var);
+
+ if (device_data->tech_state == NETCONFIG_WIFI_TECH_UNKNOWN)
+ device_data->tech_state = NETCONFIG_WIFI_TECH_OFF;
+
+ if (device_data->interface_name)
+ wifi_state_update_power_state(
+ device_data->interface_name, device_data->powered);
+
+ if (device_data->powered == TRUE)
+ device_data->tech_state = NETCONFIG_WIFI_TECH_POWERED;
+ else
+ device_data->tech_state = NETCONFIG_WIFI_TECH_OFF;
+ }
+ } else if (g_strcmp0(dev_key, "Connected") == 0) {
+ if (device_data) {
+ device_data->connected = g_variant_get_boolean(dev_var);
+ if (device_data->connected == TRUE)
+ device_data->tech_state = NETCONFIG_WIFI_TECH_CONNECTED;
+ }
+ }
+ }
+ }
+
+ g_variant_iter_free(list_iter);
+ }
+ }
+ }
+
+ g_variant_unref(message);
+
+ g_variant_iter_free(iter);
+
+ g_slist_free_full(device_list, __device_free_data);
+
+ if (network_update_timer_id && updated)
+ netconfig_stop_timer(&network_update_timer_id);
+
+ return updated;
+}
+
+GSList *wifi_state_get_device_list(void)
+{
+ return g_device_list;
+}
+
+static gboolean __state_update_device_list(gpointer data)
+{
+ if (wifi_state_update_device_list() == FALSE) {
+ if (network_update_timer_cnt <
+ NETCONFIG_UPDATE_DEVICE_LIST_COUNT) {
+ network_update_timer_cnt++;
+ return TRUE;
+ }
+ }
+
+ netconfig_stop_timer(&network_update_timer_id);
+ return FALSE;
+}
+
+void wifi_state_set_service_state(const char *interface_name,
+ const char *service, wifi_service_state_e new_state)
{
static gboolean dhcp_stage = FALSE;
- wifi_service_state_e old_state = g_service_state;
+ wifi_device_data_s *device_data = NULL;
+ wifi_service_state_e old_state = NETCONFIG_WIFI_UNKNOWN;
+
+ device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return;
+ old_state = device_data->service_state;
if (old_state == new_state)
return;
- g_service_state = new_state;
- DBG("Wi-Fi state %d ==> %d", old_state, new_state);
+ device_data->service_state = new_state;
+ DBG("Wi-Fi service state, old state[%s] ==> new state[%s]",
+ _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state));
- /* During DHCP, temporarily disable Wi-Fi power saving */
- if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_CONFIGURATION) {
+ /* From association, temporarily disable Wi-Fi power saving */
+ if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_ASSOCIATION) {
_set_power_lock(TRUE);
- _set_power_save(FALSE);
+ wifi_set_early_suspend(interface_name, FALSE);
dhcp_stage = TRUE;
- } else if (dhcp_stage == TRUE) {
+ } else if (dhcp_stage == TRUE && new_state != NETCONFIG_WIFI_CONFIGURATION) {
_set_power_lock(FALSE);
- _set_power_save(TRUE);
+ wifi_set_early_suspend(interface_name, TRUE);
dhcp_stage = FALSE;
}
if (new_state == NETCONFIG_WIFI_CONNECTED) {
netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
- netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED);
+ __update_wifi_state();
- netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED);
+ netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED);
__set_wifi_connected_essid();
- netconfig_wifi_indicator_start();
+ netconfig_wifi_indicator_start(interface_name, service);
} else if (old_state == NETCONFIG_WIFI_CONNECTED) {
netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
__unset_wifi_connected_essid();
- netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
+ __update_wifi_state();
- netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
+ netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
- netconfig_wifi_indicator_stop();
+ netconfig_wifi_indicator_stop(interface_name);
- netconfig_wifi_set_bgscan_pause(FALSE);
-
- netconfig_wifi_bgscan_stop();
- netconfig_wifi_bgscan_start(TRUE);
- } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE){
- //in ipv6 case disconnect/association -> association
+ netconfig_wifi_bgscan_stop(interface_name);
+ netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN);
+ netconfig_wifi_bgscan_start(interface_name, TRUE);
+ } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) {
+ /* in ipv6 case disconnect/association -> association */
DBG("reset the bg scan period");
- netconfig_wifi_set_bgscan_pause(FALSE);
- netconfig_wifi_bgscan_stop();
- netconfig_wifi_bgscan_start(TRUE);
+ netconfig_wifi_bgscan_stop(interface_name);
+ netconfig_wifi_bgscan_start(interface_name, TRUE);
+ } else if (old_state == NETCONFIG_WIFI_FAILURE && new_state == NETCONFIG_WIFI_IDLE) {
+ DBG("reset the bg scan period, in failure case");
+ netconfig_wifi_bgscan_stop(interface_name);
+ netconfig_wifi_bgscan_set_exp_interval(interface_name, SCAN_EXPONENTIAL_MIN);
+ netconfig_wifi_bgscan_start(interface_name, FALSE);
}
- _wifi_state_changed(new_state);
+ _wifi_state_changed(interface_name, new_state);
- if (new_state == NETCONFIG_WIFI_CONNECTED){
+ if (new_state == NETCONFIG_WIFI_CONNECTED)
_wifi_state_connected_activation();
-#if defined TIZEN_WEARABLE
- wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
-#endif
- }
}
-wifi_service_state_e wifi_state_get_service_state(void)
+wifi_service_state_e wifi_state_get_service_state(const char *interface_name)
{
- return g_service_state;
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return NETCONFIG_WIFI_UNKNOWN;
+
+ return device_data->service_state;
}
-void wifi_state_set_tech_state(wifi_tech_state_e new_state)
+void wifi_state_set_technology_state(const char *interface_name, wifi_tech_state_e new_state)
{
- wifi_tech_state_e old_state = g_tech_state;
+ wifi_device_data_s *device_data = NULL;
- if (old_state == new_state)
- return;
+ device_data = __device_get_data(interface_name);
+ if (device_data) {
+ if (device_data->tech_state == new_state)
+ return;
- g_tech_state = new_state;
+ DBG("Wi-Fi %s technology state, old state[%s] ==> new state[%s]", interface_name,
+ _convert_wifi_technology_state_to_string(device_data->tech_state),
+ _convert_wifi_technology_state_to_string(new_state));
- DBG("Wi-Fi technology state %d ==> %d", old_state, new_state);
+ device_data->tech_state = new_state;
+ }
}
-wifi_tech_state_e wifi_state_get_technology_state(void)
+wifi_tech_state_e wifi_state_get_technology_state(const char *interface_name)
{
- GVariant *message = NULL, *variant;
- GVariantIter *iter, *next;
- wifi_tech_state_e ret = NETCONFIG_WIFI_TECH_OFF;
- gboolean wifi_tech_powered = FALSE;
- gboolean wifi_tech_connected = FALSE;
- const char *path;
- gchar *key;
+ wifi_device_data_s *device_data = NULL;
- if (g_tech_state > NETCONFIG_WIFI_TECH_UNKNOWN)
- return g_tech_state;
+ device_data = __device_get_data(interface_name);
+ if (device_data) {
+ DBG("Wi-Fi %s technology state [%s]", interface_name,
+ _convert_wifi_technology_state_to_string(device_data->tech_state));
- message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
- CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
- "GetTechnologies", NULL);
- if (message == NULL) {
- ERR("Failed to get_technology_state");
- return NETCONFIG_WIFI_TECH_UNKNOWN;
+ return device_data->tech_state;
}
- g_variant_get(message, "(a(oa{sv}))", &iter);
- while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
- if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0) {
- continue;
- }
+ return NETCONFIG_WIFI_TECH_UNKNOWN;
+}
- while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
- const gchar *sdata = NULL;
- gboolean data;
-
- if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
- data = g_variant_get_boolean(variant);
- DBG("key-[%s] - %s", key, data ? "True" : "False");
-
- if (strcmp(key, "Powered") == 0 && data) {
- wifi_tech_powered = TRUE;
- } else if (strcmp(key, "Connected") == 0 && data) {
- wifi_tech_connected = TRUE;
- } else if (strcmp(key, "Tethering") == 0 && data) {
- // For further use
- }
- } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
- sdata = g_variant_get_string(variant, NULL);
- DBG("%s", sdata);
- }
- }
- g_variant_iter_free (next);
+void wifi_state_set_powered(const char *interface_name, gboolean powered)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+
+ if (device_data) {
+ device_data->powered = powered;
+ DBG("Wi-Fi %s [%s]", interface_name, powered ? "enabled" : "disabled");
}
+}
- g_variant_unref(message);
+gboolean wifi_state_get_powered(const char *interface_name)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return FALSE;
- g_variant_iter_free (iter);
+ return device_data->powered;
+}
- if (wifi_tech_powered == TRUE)
- ret = NETCONFIG_WIFI_TECH_POWERED;
+void wifi_state_set_connected(const char *interface_name, gboolean connected)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+
+ if (device_data) {
+ device_data->connected = connected;
+ DBG("Wi-Fi %s [%s]", interface_name, connected ? "connected" : "disconnected");
+ }
+}
+
+gboolean wifi_state_get_connected(const char *interface_name)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return FALSE;
+
+ return device_data->connected;
+}
+
+gboolean wifi_state_is_existed(const char *interface_name)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return FALSE;
+
+ return TRUE;
+}
+
+const char *wifi_state_get_interface_name(const char *mac_address)
+{
+ wifi_device_data_s *device_data = __device_get_data_by_macaddr(mac_address);
+ if (!device_data)
+ return NULL;
- if (wifi_tech_connected == TRUE)
- ret = NETCONFIG_WIFI_TECH_CONNECTED;
+ return device_data->interface_name;
+}
- g_tech_state = ret;
+const char *wifi_state_get_mac_address(const char *interface_name)
+{
+ wifi_device_data_s *device_data = __device_get_data(interface_name);
+ if (!device_data)
+ return NULL;
- return g_tech_state;
+ return device_data->mac_address;
}
void wifi_state_set_connected_essid(void)
{
__set_wifi_connected_essid();
-#if defined TIZEN_WEARABLE
- wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
-#endif
}
void wifi_state_get_connected_essid(gchar **essid)
*essid = g_strdup(__get_wifi_connected_essid());
}
-/* wifi_connection_state_e in CAPI
- *
- * WIFI_CONNECTION_STATE_FAILURE = -1
- * WIFI_CONNECTION_STATE_DISCONNECTED = 0
- * WIFI_CONNECTION_STATE_ASSOCIATION = 1
- * WIFI_CONNECTION_STATE_CONFIGURATION = 2
- * WIFI_CONNECTION_STATE_CONNECTED = 3
- */
-gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context)
+void wifi_state_initialize(void)
{
- g_return_val_if_fail(wifi != NULL, FALSE);
- wifi_service_state_e state = NETCONFIG_WIFI_UNKNOWN;
- gint wifi_state = 0;
- state = wifi_state_get_service_state();
-
- switch (state) {
- case NETCONFIG_WIFI_FAILURE:
- wifi_state = -1;
- break;
- case NETCONFIG_WIFI_UNKNOWN:
- case NETCONFIG_WIFI_IDLE:
- wifi_state = 0;
- break;
- case NETCONFIG_WIFI_ASSOCIATION:
- wifi_state = 1;
- break;
- case NETCONFIG_WIFI_CONFIGURATION:
- wifi_state = 2;
- break;
- case NETCONFIG_WIFI_CONNECTED:
- wifi_state = 3;
- break;
- default:
- wifi_state = 0;
- }
-
- g_dbus_method_invocation_return_value(context, g_variant_new("(i)", wifi_state));
+ if (wifi_state_update_device_list() == FALSE)
+ netconfig_start_timer(NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT,
+ __state_update_device_list, NULL, &network_update_timer_id);
+}
- return TRUE;
+void wifi_state_deinitialize(void)
+{
+ g_slist_free_full(g_device_list, __device_free_data);
}