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_TIMEOUT 1 * 1000
37 #define NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT 15 * 1000
39 static gboolean new_bss_found = FALSE;
41 static guint network_update_timer_id = 0;
42 static guint network_noti_timer_id = 0;
44 static GSList *g_device_list = NULL;
45 static GSList *g_notifier_list = NULL;
47 static guint network_connected_popup_timer_id = 0;
48 static gboolean block_network_connected_popup = FALSE;
50 static void __device_free_data(gpointer data)
52 wifi_device_data_s *device_data = data;
54 g_free(device_data->interface_name);
55 g_free(device_data->mac_address);
60 static wifi_device_data_s *__device_get_data(const char *interface_name)
64 for (list = g_device_list; list; list = list->next) {
65 wifi_device_data_s *device_data = list->data;
66 if (g_strcmp0(device_data->interface_name, interface_name) == 0)
73 static wifi_device_data_s *__device_get_data_by_macaddr(const char *macaddr)
77 for (list = g_device_list; list; list = list->next) {
78 wifi_device_data_s *device_data = list->data;
79 if (g_ascii_strncasecmp(device_data->mac_address,
80 macaddr, MAC_ADDRESS_MAX_LEN) == 0)
87 char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type)
89 switch (wifi_service_state_type) {
90 case NETCONFIG_WIFI_UNKNOWN:
92 case NETCONFIG_WIFI_IDLE:
94 case NETCONFIG_WIFI_ASSOCIATION:
96 case NETCONFIG_WIFI_CONFIGURATION:
97 return "configuration";
98 case NETCONFIG_WIFI_CONNECTED:
100 case NETCONFIG_WIFI_FAILURE:
103 ERR("Invalid wifi_service_state_e parameter");
107 return "Invalid parameter";
110 char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type)
112 switch (wifi_tech_state_type) {
113 case NETCONFIG_WIFI_TECH_UNKNOWN:
115 case NETCONFIG_WIFI_TECH_OFF:
117 case NETCONFIG_WIFI_TECH_WPS_ONLY:
119 case NETCONFIG_WIFI_TECH_POWERED:
121 case NETCONFIG_WIFI_TECH_CONNECTED:
123 case NETCONFIG_WIFI_TECH_TETHERED:
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);
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, "");
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);
498 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, network_wifi_state);
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 gboolean wifi_state_update_device_list(void)
615 GVariant *message = NULL, *variant;
616 GVariantIter *iter, *next;
619 gboolean updated = FALSE;
621 message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
622 CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
623 "GetTechnologies", NULL);
624 if (message == NULL) {
625 ERR("Failed to get technologies");
629 g_slist_free_full(g_device_list, __device_free_data);
630 g_device_list = NULL;
632 g_variant_get(message, "(a(oa{sv}))", &iter);
633 while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
634 if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0)
637 while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
638 if (g_strcmp0(key, "Device.List") == 0) {
639 GVariantIter *list_iter;
643 wifi_device_data_s *device_data = NULL;
645 g_variant_get(variant, "a{sv}", &list_iter);
646 while(g_variant_iter_loop(list_iter, "{sv}", &dev_key, &dev_var)) {
647 if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_STRING)) {
648 if (g_strcmp0(dev_key, "Ifname") == 0) {
649 device_data = g_try_malloc0(sizeof(wifi_device_data_s));
651 g_variant_unref(dev_var);
655 sdata = g_variant_get_string(dev_var, NULL);
656 device_data->interface_name = g_strdup(sdata);
657 g_device_list = g_slist_append(g_device_list, device_data);
661 } else if (g_strcmp0(dev_key, "MAC.Address") == 0) {
663 sdata = g_variant_get_string(dev_var, NULL);
664 device_data->mac_address = g_strdup(sdata);
666 DBG("Ifname[%s] MAC[%s] Powered[%d] Connected[%d]",
667 device_data->interface_name, device_data->mac_address,
668 device_data->powered, device_data->connected);
671 } else if (g_variant_is_of_type(dev_var, G_VARIANT_TYPE_BOOLEAN)) {
672 if (g_strcmp0(dev_key, "Powered") == 0) {
674 device_data->powered = g_variant_get_boolean(dev_var);
675 if (device_data->powered == TRUE)
676 device_data->tech_state = NETCONFIG_WIFI_TECH_POWERED;
678 device_data->tech_state = NETCONFIG_WIFI_TECH_OFF;
680 } else if (g_strcmp0(dev_key, "Connected") == 0) {
682 device_data->connected = g_variant_get_boolean(dev_var);
683 if (device_data->connected == TRUE)
684 device_data->tech_state = NETCONFIG_WIFI_TECH_CONNECTED;
690 g_variant_iter_free(list_iter);
695 g_variant_unref(message);
697 g_variant_iter_free(iter);
702 GSList *wifi_state_get_device_list(void)
704 return g_device_list;
707 static gboolean __state_update_device_list(gpointer data)
709 if (wifi_state_update_device_list() == FALSE)
712 netconfig_stop_timer(&network_update_timer_id);
716 void wifi_state_set_service_state(const char *interface_name, wifi_service_state_e new_state)
718 static gboolean dhcp_stage = FALSE;
719 wifi_device_data_s *device_data = NULL;
720 wifi_service_state_e old_state = NETCONFIG_WIFI_UNKNOWN;
722 device_data = __device_get_data(interface_name);
726 old_state = device_data->service_state;
727 if (old_state == new_state)
730 device_data->service_state = new_state;
731 DBG("Wi-Fi service state, old state[%s] ==> new state[%s]",
732 _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state));
734 /* From association, temporarily disable Wi-Fi power saving */
735 if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_ASSOCIATION) {
736 _set_power_lock(TRUE);
737 wifi_set_early_suspend(interface_name, FALSE);
739 } else if (dhcp_stage == TRUE && new_state != NETCONFIG_WIFI_CONFIGURATION) {
740 _set_power_lock(FALSE);
741 wifi_set_early_suspend(interface_name, TRUE);
745 if (new_state == NETCONFIG_WIFI_CONNECTED) {
746 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
748 __update_wifi_state();
750 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED);
752 __set_wifi_connected_essid();
754 netconfig_wifi_indicator_start(interface_name);
755 } else if (old_state == NETCONFIG_WIFI_CONNECTED) {
756 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
758 __unset_wifi_connected_essid();
760 __update_wifi_state();
762 netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
764 netconfig_wifi_indicator_stop(interface_name);
766 netconfig_wifi_bgscan_stop(interface_name);
767 netconfig_wifi_bgscan_set_interval(interface_name, SCAN_EXPONENTIAL_MIN);
768 netconfig_wifi_bgscan_start(interface_name, TRUE);
769 } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE) {
770 /* in ipv6 case disconnect/association -> association */
771 DBG("reset the bg scan period");
773 netconfig_wifi_bgscan_stop(interface_name);
774 netconfig_wifi_bgscan_start(interface_name, TRUE);
777 _wifi_state_changed(interface_name, new_state);
779 if (new_state == NETCONFIG_WIFI_CONNECTED)
780 _wifi_state_connected_activation();
783 wifi_service_state_e wifi_state_get_service_state(const char *interface_name)
785 wifi_device_data_s *device_data = __device_get_data(interface_name);
787 return NETCONFIG_WIFI_UNKNOWN;
789 return device_data->service_state;
792 void wifi_state_set_technology_state(const char *interface_name, wifi_tech_state_e new_state)
794 wifi_device_data_s *device_data = NULL;
796 device_data = __device_get_data(interface_name);
798 if (device_data->tech_state == new_state)
801 DBG("Wi-Fi %s technology state, old state[%s] ==> new state[%s]", interface_name,
802 _convert_wifi_technology_state_to_string(device_data->tech_state),
803 _convert_wifi_technology_state_to_string(new_state));
805 device_data->tech_state = new_state;
809 wifi_tech_state_e wifi_state_get_technology_state(const char *interface_name)
811 wifi_device_data_s *device_data = NULL;
813 device_data = __device_get_data(interface_name);
815 DBG("Wi-Fi %s technology state [%s]", interface_name,
816 _convert_wifi_technology_state_to_string(device_data->tech_state));
818 return device_data->tech_state;
821 return NETCONFIG_WIFI_TECH_UNKNOWN;
824 void wifi_state_set_powered(const char *interface_name, gboolean powered)
826 wifi_device_data_s *device_data = __device_get_data(interface_name);
829 device_data->powered = powered;
830 DBG("Wi-Fi %s [%s]", interface_name, powered ? "enabled" : "disabled");
834 gboolean wifi_state_get_powered(const char *interface_name)
836 wifi_device_data_s *device_data = __device_get_data(interface_name);
840 return device_data->powered;
843 void wifi_state_set_connected(const char *interface_name, gboolean connected)
845 wifi_device_data_s *device_data = __device_get_data(interface_name);
848 device_data->connected = connected;
849 DBG("Wi-Fi %s [%s]", interface_name, connected ? "connected" : "disconnected");
853 gboolean wifi_state_get_connected(const char *interface_name)
855 wifi_device_data_s *device_data = __device_get_data(interface_name);
859 return device_data->connected;
862 gboolean wifi_state_is_existed(const char *interface_name)
864 wifi_device_data_s *device_data = __device_get_data(interface_name);
871 const char *wifi_state_get_interface_name(const char *mac_address)
873 wifi_device_data_s *device_data = __device_get_data_by_macaddr(mac_address);
877 return device_data->interface_name;
880 const char *wifi_state_get_mac_address(const char *interface_name)
882 wifi_device_data_s *device_data = __device_get_data(interface_name);
886 return device_data->mac_address;
889 void wifi_state_set_connected_essid(void)
891 __set_wifi_connected_essid();
894 void wifi_state_get_connected_essid(gchar **essid)
896 *essid = g_strdup(__get_wifi_connected_essid());
899 void wifi_state_initialize(void)
901 if (wifi_state_update_device_list() == FALSE)
902 netconfig_start_timer(NETCONFIG_UPDATE_DEVICE_LIST_TIMEOUT,
903 __state_update_device_list, NULL, &network_update_timer_id);
906 void wifi_state_deinitialize(void)
908 g_slist_free_full(g_device_list, __device_free_data);