2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <vconf-keys.h>
27 #include "wifi-state.h"
28 #include "wifi-power.h"
29 #include "wifi-scan.h"
30 #include "netsupplicant.h"
31 #include "network-state.h"
32 #include "wifi-indicator.h"
33 #include "network-statistics.h"
34 #include "wifi-background-scan.h"
36 #define NETCONFIG_UPDATE_DEVICE_LIST_COUNT 3
37 #define NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT 1 * 1000
38 #define NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT 15 * 1000
40 static gboolean new_bss_found = FALSE;
42 static guint network_update_timer_cnt = 0;
43 static guint network_update_timer_id = 0;
44 static guint network_noti_timer_id = 0;
46 static GSList *g_device_list = NULL;
47 static GSList *g_notifier_list = NULL;
49 static guint network_connected_popup_timer_id = 0;
50 static gboolean block_network_connected_popup = FALSE;
52 static void __device_free_data(gpointer data)
54 wifi_device_data_s *device_data = data;
56 g_free(device_data->interface_name);
57 g_free(device_data->mac_address);
62 static wifi_device_data_s *__device_get_data(const char *interface_name)
66 for (list = g_device_list; list; list = list->next) {
67 wifi_device_data_s *device_data = list->data;
68 if (g_strcmp0(device_data->interface_name, interface_name) == 0)
75 static wifi_device_data_s *__device_get_data_by_macaddr(const char *macaddr)
79 for (list = g_device_list; list; list = list->next) {
80 wifi_device_data_s *device_data = list->data;
81 if (g_ascii_strncasecmp(device_data->mac_address,
82 macaddr, MAC_ADDRESS_MAX_LEN) == 0)
89 char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type)
91 switch (wifi_service_state_type) {
92 case NETCONFIG_WIFI_UNKNOWN:
94 case NETCONFIG_WIFI_IDLE:
96 case NETCONFIG_WIFI_ASSOCIATION:
98 case NETCONFIG_WIFI_CONFIGURATION:
99 return "configuration";
100 case NETCONFIG_WIFI_CONNECTED:
102 case NETCONFIG_WIFI_FAILURE:
105 ERR("Invalid wifi_service_state_e parameter");
109 return "Invalid parameter";
112 char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type)
114 switch (wifi_tech_state_type) {
115 case NETCONFIG_WIFI_TECH_UNKNOWN:
117 case NETCONFIG_WIFI_TECH_OFF:
119 case NETCONFIG_WIFI_TECH_WPS_ONLY:
121 case NETCONFIG_WIFI_TECH_POWERED:
123 case NETCONFIG_WIFI_TECH_CONNECTED:
126 ERR("Invalid wifi_tech_state_e parameter");
130 return "Invalid parameter";
133 static gboolean _block_network_connection_popup(gpointer data)
135 block_network_connected_popup = FALSE;
136 netconfig_stop_timer(&network_connected_popup_timer_id);
140 static void __set_wifi_connected_essid(void)
142 const char *essid_name = NULL;
143 const char *wifi_profile = netconfig_get_default_profile();
144 const char *wifi_ifname = netconfig_get_default_ifname();
146 if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED)
149 if (wifi_profile == NULL ||
150 netconfig_is_wifi_profile(wifi_profile) != TRUE) {
151 ERR("Can't get Wi-Fi profile");
155 essid_name = netconfig_wifi_get_connected_essid(wifi_profile);
156 if (essid_name == NULL) {
157 ERR("Can't get Wi-Fi name");
161 netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name, TRUE);
163 /* Block Network Connected popup for 3sec
164 * to avoid multiple popup's due to ready signals */
165 if (block_network_connected_popup == FALSE) {
166 block_network_connected_popup = TRUE;
167 netconfig_start_timer(3000, _block_network_connection_popup,
168 NULL, &network_connected_popup_timer_id);
169 __netconfig_pop_wifi_connected_poppup(essid_name);
173 static void __unset_wifi_connected_essid(void)
175 netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, "", TRUE);
178 static const char *__get_wifi_connected_essid(void)
180 const char *essid_name = NULL;
181 const char *wifi_profile = netconfig_get_default_profile();
182 const char *wifi_ifname = netconfig_get_default_ifname();
184 if (wifi_state_get_service_state(wifi_ifname) != NETCONFIG_WIFI_CONNECTED)
187 if (wifi_profile == NULL || netconfig_is_wifi_profile(wifi_profile) != TRUE) {
188 ERR("Can't get Wi-Fi profile");
192 essid_name = netconfig_wifi_get_connected_essid(wifi_profile);
193 if (essid_name == NULL) {
194 ERR("Can't get Wi-Fi name");
201 static gboolean __is_wifi_profile_available(void)
203 GVariant *message = NULL;
204 GVariantIter *iter, *next;
207 message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
208 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
209 "GetServices", NULL);
210 if (message == NULL) {
211 ERR("Failed to get service list");
215 g_variant_get(message, "(a(oa{sv}))", &iter);
216 while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
217 if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE)
220 g_variant_iter_free(next);
225 g_variant_unref(message);
227 g_variant_iter_free(iter);
232 static gboolean __is_favorited(GVariantIter *array)
234 gboolean is_favorite = FALSE;
238 while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
241 if (g_str_equal(key, "Favorite") != TRUE)
244 value = g_variant_get_boolean(var);
248 g_variant_unref(var);
255 static void _wifi_state_connected_activation(void)
257 /* Add activation of services when Wi-Fi is connected */
260 static void _wifi_state_changed(const char *interface_name,
261 wifi_service_state_e state)
266 for (list = g_notifier_list; list; ) {
267 wifi_state_notifier_s *notifier = list->data;
270 if (notifier->service) {
271 ifname = netconfig_get_ifname(notifier->service);
272 if (g_strcmp0(ifname, interface_name) != 0)
276 if (notifier->wifi_state_changed != NULL)
277 notifier->wifi_state_changed(notifier->notifier,
278 notifier->service, state, notifier->user_data);
282 static void _set_bss_found(gboolean found)
284 if (found != new_bss_found)
285 new_bss_found = found;
288 static gboolean _check_network_notification(gpointer data)
290 int qs_enable = 0, ug_state = 0;
291 static gboolean check_again = FALSE;
293 wifi_tech_state_e tech_state;
294 wifi_service_state_e service_state;
295 char *interface_name = data;
297 tech_state = wifi_state_get_technology_state(interface_name);
298 if (tech_state < NETCONFIG_WIFI_TECH_POWERED) {
299 DBG("Wi-Fi off or WPS only supported[%d]", tech_state);
303 service_state = wifi_state_get_service_state(interface_name);
304 if (service_state == NETCONFIG_WIFI_CONNECTED) {
305 DBG("Service state is connected");
307 } else if (service_state == NETCONFIG_WIFI_ASSOCIATION ||
308 service_state == NETCONFIG_WIFI_CONFIGURATION) {
309 DBG("Service state is connecting (check again : %d)", check_again);
317 if (__is_wifi_profile_available() == FALSE) {
318 netconfig_send_notification_to_net_popup(
319 NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
323 netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
324 if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) {
325 DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE");
329 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
330 if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
333 netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL);
335 _set_bss_found(FALSE);
338 netconfig_stop_timer(&network_noti_timer_id);
342 static char *_get_connman_favorite_service(void)
344 char *favorite_service = NULL;
345 GVariant *message = NULL;
347 GVariantIter *iter, *next;
349 message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
350 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
351 "GetServices", NULL);
352 if (message == NULL) {
353 ERR("Failed to get service list");
357 g_variant_get(message, "(a(oa{sv}))", &iter);
358 while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
359 if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE)
362 if (__is_favorited(next) == TRUE) {
363 favorite_service = g_strdup(obj);
365 g_variant_iter_free(next);
370 g_variant_iter_free(iter);
371 g_variant_unref(message);
373 return favorite_service;
376 static void __notification_value_changed_cb(keynode_t *node, void *user_data)
380 if (netconfig_vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0)
383 if (value == VCONFKEY_WIFI_QS_DISABLE)
384 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
387 static void _register_network_notification(void)
389 #if defined TIZEN_WEARABLE
392 vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb, NULL);
395 static void _deregister_network_notification(void)
397 #if defined TIZEN_WEARABLE
400 vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb);
403 static void _set_power_lock(gboolean power_lock)
408 char state[] = "lcdoff";
409 char flag[] = "staycurstate";
410 char standby[] = "NULL";
412 char sleepmargin[] = "sleepmargin";
414 const char *lockstate = "lockstate";
415 const char *unlockstate = "unlockstate";
416 static gboolean old_state = FALSE;
417 const char *lock_method;
419 if (old_state == power_lock)
422 if (power_lock == TRUE) {
423 /* deviced power lock enable */
424 params = g_variant_new("(sssi)", state, flag, standby, timeout);
426 lock_method = lockstate;
428 /* deviced power lock disable */
429 params = g_variant_new("(ss)", state, sleepmargin);
431 lock_method = unlockstate;
434 reply = netconfig_invoke_dbus_method(
435 "org.tizen.system.deviced",
436 "/Org/Tizen/System/DeviceD/Display",
437 "org.tizen.system.deviced.display",
441 ERR("Failed to set_power_lock");
445 if (g_variant_is_of_type(reply, G_VARIANT_TYPE_INT32)) {
446 ret = g_variant_get_int32(reply);
448 ERR("Failed to set power lock %s with ret %d",
449 power_lock == TRUE ? "enable" : "disable", ret);
451 old_state = power_lock;
454 g_variant_unref(reply);
459 void wifi_state_emit_power_completed(const char *interface_name, gboolean power_on)
462 wifi_emit_power_on_completed((Wifi *)get_wifi_object(), interface_name);
464 wifi_emit_power_off_completed((Wifi *)get_wifi_object(), interface_name);
466 DBG("Successfully sent signal [%s %s]",
467 interface_name, (power_on) ? "powerOn" : "powerOff");
470 void wifi_state_emit_power_failed(const char *interface_name)
472 wifi_emit_power_operation_failed((Wifi *)get_wifi_object(), interface_name);
474 DBG("Successfully sent signal [%s PowerOperationFailed]", interface_name);
477 static void __update_wifi_state(void)
479 int wifi_state = VCONFKEY_WIFI_OFF;
480 int network_wifi_state = VCONFKEY_NETWORK_WIFI_OFF;
483 for (list = g_device_list; list; list = list->next) {
484 wifi_device_data_s *device_data = list->data;
485 if (device_data->powered) {
486 if (wifi_state < VCONFKEY_WIFI_UNCONNECTED)
487 wifi_state = VCONFKEY_WIFI_UNCONNECTED;
488 if (network_wifi_state < VCONFKEY_NETWORK_WIFI_NOT_CONNECTED)
489 network_wifi_state = VCONFKEY_NETWORK_WIFI_NOT_CONNECTED;
491 if (device_data->connected) {
492 wifi_state = VCONFKEY_WIFI_CONNECTED;
493 network_wifi_state = VCONFKEY_NETWORK_WIFI_CONNECTED;
497 netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, wifi_state, TRUE);
498 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, network_wifi_state, TRUE);
501 void wifi_state_update_power_state(const char *interface_name, gboolean powered)
503 wifi_tech_state_e tech_state;
505 /* It's automatically updated by signal-handler
506 * DO NOT update manually
507 * It includes Wi-Fi state configuration
509 tech_state = wifi_state_get_technology_state(interface_name);
511 if (powered == TRUE) {
512 if (tech_state < NETCONFIG_WIFI_TECH_POWERED && netconfig_is_wifi_tethering_on() != TRUE) {
513 DBG("Wi-Fi turned on or waken up from power-save mode");
515 wifi_state_set_powered(interface_name, TRUE);
516 wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_POWERED);
518 wifi_state_emit_power_completed(interface_name, TRUE);
519 netconfig_battery_start_wifi();
521 netconfig_wifi_device_picker_service_start();
523 __update_wifi_state();
525 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
527 netconfig_wifi_bgscan_stop(interface_name);
528 netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN);
529 netconfig_wifi_bgscan_start(interface_name, TRUE);
531 /* Add callback to track change in notification setting */
532 _register_network_notification();
534 netconfig_setting_update_interface_for_last_powered(interface_name, TRUE);
536 } else if (tech_state > NETCONFIG_WIFI_TECH_OFF) {
537 DBG("Wi-Fi turned off or in power-save mode");
539 wifi_state_set_powered(interface_name, FALSE);
540 wifi_state_set_technology_state(interface_name, NETCONFIG_WIFI_TECH_WPS_ONLY);
542 netconfig_wifi_device_picker_service_stop();
544 wifi_power_driver_and_supplicant(interface_name, FALSE);
546 wifi_state_emit_power_completed(interface_name, FALSE);
547 netconfig_battery_end_wifi();
549 __update_wifi_state();
551 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF);
553 netconfig_wifi_bgscan_stop(interface_name);
554 netconfig_wifi_scan_set_scanning(interface_name, FALSE);
556 _set_bss_found(FALSE);
558 /* Inform net-popup to remove the wifi found notification */
559 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
560 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
561 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_IP_CONFLICT_NOTI, NULL);
563 _deregister_network_notification();
565 netconfig_setting_update_interface_for_last_powered(interface_name, FALSE);
569 char *wifi_get_favorite_service(void)
571 return _get_connman_favorite_service();
574 void wifi_start_timer_network_notification(const char *interface_name)
576 #if defined TIZEN_WEARABLE
577 /* In case of wearable device, no need to notify available Wi-Fi APs */
580 netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT,
581 _check_network_notification, g_strdup(interface_name), &network_noti_timer_id);
584 void wifi_state_notifier_register(wifi_state_notifier_s *notifier)
586 DBG("register notifier");
588 g_notifier_list = g_slist_append(g_notifier_list, notifier);
591 void wifi_state_notifier_unregister(wifi_state_notifier_s *notifier)
593 DBG("un-register notifier");
595 g_notifier_list = g_slist_remove_all(g_notifier_list, notifier);
598 void wifi_state_notifier_cleanup(void)
600 g_slist_free_full(g_notifier_list, NULL);
603 void wifi_state_set_bss_found(gboolean found)
605 _set_bss_found(found);
608 gboolean wifi_state_is_bss_found(void)
610 return new_bss_found;
613 void __copy_device_statistics(wifi_device_data_s *dst_data, GSList *device_list)
617 for (list = device_list; list; list = list->next) {
618 wifi_device_data_s *org_data = list->data;
619 if (g_strcmp0(org_data->interface_name, dst_data->interface_name) == 0) {
620 dst_data->tx = org_data->tx;
621 dst_data->rx = org_data->rx;
622 dst_data->tx_diff = org_data->tx_diff;
623 dst_data->tx_diff = org_data->tx_diff;
629 gboolean wifi_state_update_device_list(void)
631 GVariant *message = NULL, *variant;
632 GVariantIter *iter, *next;
633 GSList *device_list = NULL;
636 gboolean updated = FALSE;
638 message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
639 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
640 "GetTechnologies", NULL);
641 if (message == NULL) {
642 ERR("Failed to get technologies");
646 device_list = g_device_list;
647 g_device_list = NULL;
649 g_variant_get(message, "(a(oa{sv}))", &iter);
650 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
651 if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
654 while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
655 if (g_strcmp0(key, "Device.List") == 0) {
656 GVariantIter *list_iter;
660 wifi_device_data_s *device_data = NULL;
662 g_variant_get(variant, "a{sv}", &list_iter);
663 while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) {
664 if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) {
665 if (g_strcmp0(dev_key, "Ifname") == 0) {
666 device_data = g_try_malloc0(sizeof(wifi_device_data_s));
668 g_variant_unref(dev_var);
672 sdata = g_variant_get_string(dev_var, NULL);
673 device_data->interface_name = g_strdup(sdata);
674 g_device_list = g_slist_append(g_device_list, device_data);
678 __copy_device_statistics(device_data, device_list);
680 } else if (g_strcmp0(dev_key, "MAC.Address") == 0) {
682 sdata = g_variant_get_string(dev_var, NULL);
683 device_data->mac_address = g_strdup(sdata);
685 DBG("Ifname[%s] MAC[%s] Powered[%d] Connected[%d]",
686 device_data->interface_name, device_data->mac_address,
687 device_data->powered, device_data->connected);
690 } else if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_BOOLEAN)) {
691 if (g_strcmp0(dev_key, "Powered") == 0) {
693 device_data->powered = g_variant_get_boolean(dev_var);
694 if (device_data->powered == TRUE)
695 device_data->tech_state = NETCONFIG_WIFI_TECH_POWERED;
697 device_data->tech_state = NETCONFIG_WIFI_TECH_OFF;
699 } else if (g_strcmp0(dev_key, "Connected") == 0) {
701 device_data->connected = g_variant_get_boolean(dev_var);
702 if (device_data->connected == TRUE)
703 device_data->tech_state = NETCONFIG_WIFI_TECH_CONNECTED;
709 g_variant_iter_free(list_iter);
714 g_variant_unref(message);
716 g_variant_iter_free(iter);
718 g_slist_free_full(device_list, __device_free_data);
723 GSList *wifi_state_get_device_list(void)
725 return g_device_list;
728 static gboolean __state_update_device_list(gpointer data)
730 if (wifi_state_update_device_list() == FALSE) {
731 if (network_update_timer_cnt <
732 NETCONFIG_UPDATE_DEVICE_LIST_COUNT) {
733 network_update_timer_cnt++;
738 netconfig_stop_timer(&network_update_timer_id);
742 void wifi_state_set_service_state(const char *interface_name,
743 const char *service, wifi_service_state_e new_state)
745 static gboolean dhcp_stage = FALSE;
746 wifi_device_data_s *device_data = NULL;
747 wifi_service_state_e old_state = NETCONFIG_WIFI_UNKNOWN;
749 device_data = __device_get_data(interface_name);
753 old_state = device_data->service_state;
754 if (old_state == new_state)
757 device_data->service_state = new_state;
758 DBG("Wi-Fi service state, old state[%s] ==> new state[%s]",
759 _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state));
761 /* From association, temporarily disable Wi-Fi power saving */
762 if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_ASSOCIATION) {
763 _set_power_lock(TRUE);
764 wifi_set_early_suspend(interface_name, FALSE);
766 } else if (dhcp_stage == TRUE && new_state != NETCONFIG_WIFI_CONFIGURATION) {
767 _set_power_lock(FALSE);
768 wifi_set_early_suspend(interface_name, TRUE);
772 if (new_state == NETCONFIG_WIFI_CONNECTED) {
773 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
775 __update_wifi_state();
777 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED);
779 __set_wifi_connected_essid();
781 netconfig_wifi_indicator_start(interface_name, service);
782 } else if (old_state == NETCONFIG_WIFI_CONNECTED) {
783 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
785 __unset_wifi_connected_essid();
787 __update_wifi_state();
789 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
791 netconfig_wifi_indicator_stop(interface_name);
793 netconfig_wifi_bgscan_stop(interface_name);
794 netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN);
795 netconfig_wifi_bgscan_start(interface_name, TRUE);
796 } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) {
797 /* in ipv6 case disconnect/association -> association */
798 DBG("reset the bg scan period");
800 netconfig_wifi_bgscan_stop(interface_name);
801 netconfig_wifi_bgscan_start(interface_name, TRUE);
804 _wifi_state_changed(interface_name, new_state);
806 if (new_state == NETCONFIG_WIFI_CONNECTED)
807 _wifi_state_connected_activation();
810 wifi_service_state_e wifi_state_get_service_state(const char *interface_name)
812 wifi_device_data_s *device_data = __device_get_data(interface_name);
814 return NETCONFIG_WIFI_UNKNOWN;
816 return device_data->service_state;
819 void wifi_state_set_technology_state(const char *interface_name, wifi_tech_state_e new_state)
821 wifi_device_data_s *device_data = NULL;
823 device_data = __device_get_data(interface_name);
825 if (device_data->tech_state == new_state)
828 DBG("Wi-Fi %s technology state, old state[%s] ==> new state[%s]", interface_name,
829 _convert_wifi_technology_state_to_string(device_data->tech_state),
830 _convert_wifi_technology_state_to_string(new_state));
832 device_data->tech_state = new_state;
836 wifi_tech_state_e wifi_state_get_technology_state(const char *interface_name)
838 wifi_device_data_s *device_data = NULL;
840 device_data = __device_get_data(interface_name);
842 DBG("Wi-Fi %s technology state [%s]", interface_name,
843 _convert_wifi_technology_state_to_string(device_data->tech_state));
845 return device_data->tech_state;
848 return NETCONFIG_WIFI_TECH_UNKNOWN;
851 void wifi_state_set_powered(const char *interface_name, gboolean powered)
853 wifi_device_data_s *device_data = __device_get_data(interface_name);
856 device_data->powered = powered;
857 DBG("Wi-Fi %s [%s]", interface_name, powered ? "enabled" : "disabled");
861 gboolean wifi_state_get_powered(const char *interface_name)
863 wifi_device_data_s *device_data = __device_get_data(interface_name);
867 return device_data->powered;
870 void wifi_state_set_connected(const char *interface_name, gboolean connected)
872 wifi_device_data_s *device_data = __device_get_data(interface_name);
875 device_data->connected = connected;
876 DBG("Wi-Fi %s [%s]", interface_name, connected ? "connected" : "disconnected");
880 gboolean wifi_state_get_connected(const char *interface_name)
882 wifi_device_data_s *device_data = __device_get_data(interface_name);
886 return device_data->connected;
889 gboolean wifi_state_is_existed(const char *interface_name)
891 wifi_device_data_s *device_data = __device_get_data(interface_name);
898 const char *wifi_state_get_interface_name(const char *mac_address)
900 wifi_device_data_s *device_data = __device_get_data_by_macaddr(mac_address);
904 return device_data->interface_name;
907 const char *wifi_state_get_mac_address(const char *interface_name)
909 wifi_device_data_s *device_data = __device_get_data(interface_name);
913 return device_data->mac_address;
916 void wifi_state_set_connected_essid(void)
918 __set_wifi_connected_essid();
921 void wifi_state_get_connected_essid(gchar **essid)
923 *essid = g_strdup(__get_wifi_connected_essid());
926 void wifi_state_initialize(void)
928 if (wifi_state_update_device_list() == FALSE)
929 netconfig_start_timer(NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT,
930 __state_update_device_list, NULL, &network_update_timer_id);
933 void wifi_state_deinitialize(void)
935 g_slist_free_full(g_device_list, __device_free_data);