Removed build warnings
[platform/core/connectivity/net-config.git] / src / wifi-state.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <vconf.h>
21 #include <vconf-keys.h>
22 #include <bundle.h>
23 #include <bundle_internal.h>
24 #include <eventsystem.h>
25 #include <syspopup_caller.h>
26
27 #include "log.h"
28 #include "util.h"
29 #include "netdbus.h"
30 #include "wifi-state.h"
31 #include "wifi-power.h"
32 #include "netsupplicant.h"
33 #include "network-state.h"
34 #include "wifi-indicator.h"
35 #include "network-statistics.h"
36 #include "wifi-background-scan.h"
37
38 #define NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT  15 * 1000
39
40 static gboolean new_bss_found = FALSE;
41 static guint network_noti_timer_id = 0;
42
43 static wifi_service_state_e g_service_state = NETCONFIG_WIFI_UNKNOWN;
44 static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
45
46 static GSList *notifier_list = NULL;
47
48
49 static void __netconfig_pop_wifi_connected_poppup(const char *ssid)
50 {
51         bundle *b = NULL;
52
53         if (ssid == NULL)
54                 return;
55
56         b = bundle_create();
57
58         bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup");
59         bundle_add(b, "_SYSPOPUP_TYPE_", "notification");
60         bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected");
61         bundle_add(b, "_AP_NAME_", ssid);
62
63         DBG("Launch Wi-Fi connected alert network popup");
64         syspopup_launch("net.netpopup", b);
65
66         bundle_free(b);
67 }
68
69 static void __set_wifi_connected_essid(void)
70 {
71         const char *essid_name = NULL;
72         const char *wifi_profile = netconfig_get_default_profile();
73
74         if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
75                 return;
76
77         if (wifi_profile == NULL ||
78                         netconfig_is_wifi_profile(wifi_profile) != TRUE) {
79                 ERR("Can't get Wi-Fi profile");
80                 return;
81         }
82
83         essid_name = netconfig_wifi_get_connected_essid(wifi_profile);
84         if (essid_name == NULL) {
85                 ERR("Can't get Wi-Fi name");
86                 return;
87         }
88
89         netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name);
90         __netconfig_pop_wifi_connected_poppup(essid_name);
91 }
92
93 static void __unset_wifi_connected_essid(void)
94 {
95         netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, "");
96 }
97
98 static const char *__get_wifi_connected_essid(void)
99 {
100         const char *essid_name = NULL;
101         const char *wifi_profile = NULL;
102
103         if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
104                 return NULL;
105
106         wifi_profile = netconfig_get_default_profile();
107
108         if (wifi_profile == NULL || netconfig_is_wifi_profile(wifi_profile) != TRUE) {
109                 ERR("Can't get Wi-Fi profile");
110                 return NULL;
111         }
112
113         essid_name = netconfig_wifi_get_connected_essid(wifi_profile);
114         if (essid_name == NULL) {
115                 ERR("Can't get Wi-Fi name");
116                 return NULL;
117         }
118
119         return essid_name;
120 }
121
122 static gboolean __is_wifi_profile_available(void)
123 {
124         GVariant *message = NULL;
125         GVariantIter *iter, *next;
126         gchar *obj;
127
128         message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
129                         CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
130                         "GetServices", NULL);
131         if (message == NULL) {
132                 ERR("Failed to get service list");
133                 return FALSE;
134         }
135
136         g_variant_get(message, "(a(oa{sv}))", &iter);
137         while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
138                 if (obj == NULL || netconfig_is_wifi_profile((const gchar*)obj) == FALSE) {
139                         continue;
140                 }
141
142                 g_variant_iter_free(next);
143                 g_free(obj);
144                 break;
145         }
146
147         g_variant_unref(message);
148
149         g_variant_iter_free(iter);
150
151         return TRUE;
152 }
153
154 static gboolean __is_favorited(GVariantIter *array)
155 {
156         gboolean is_favorite = FALSE;
157         gchar *key;
158         GVariant *var;
159
160         while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
161                 gboolean value;
162
163                 if (g_str_equal(key, "Favorite") != TRUE) {
164                         continue;
165                 }
166
167                 value = g_variant_get_boolean(var);
168                 if (value)
169                         is_favorite = TRUE;
170                 g_free(key);
171                 g_variant_unref(var);
172                 break;
173         }
174
175         return is_favorite;
176 }
177
178 static void _wifi_state_connected_activation(void)
179 {
180         /* Add activation of services when Wi-Fi is connected */
181 }
182
183 static void _wifi_state_changed(wifi_service_state_e state)
184 {
185         GSList *list;
186
187         for (list = notifier_list; list; list = list->next) {
188                 wifi_state_notifier *notifier = list->data;
189
190                 if (notifier->wifi_state_changed != NULL)
191                         notifier->wifi_state_changed(state, notifier->user_data);
192         }
193 }
194
195 static void _set_bss_found(gboolean found)
196 {
197         if (found != new_bss_found)
198                 new_bss_found = found;
199 }
200
201 static gboolean _check_network_notification(gpointer data)
202 {
203         int qs_enable = 0, ug_state = 0;
204         static gboolean check_again = FALSE;
205
206         wifi_tech_state_e tech_state;
207         wifi_service_state_e service_state;
208
209         tech_state = wifi_state_get_technology_state();
210         if (tech_state < NETCONFIG_WIFI_TECH_POWERED) {
211                 DBG("Wi-Fi off or WPS only supported[%d]", tech_state);
212                 goto cleanup;
213         }
214
215         service_state = wifi_state_get_service_state();
216         if (service_state == NETCONFIG_WIFI_CONNECTED) {
217                 DBG("Service state is connected");
218                 goto cleanup;
219         } else if (service_state == NETCONFIG_WIFI_ASSOCIATION ||
220                 service_state == NETCONFIG_WIFI_CONFIGURATION) {
221                 DBG("Service state is connecting (check again : %d)", check_again);
222                 if (!check_again) {
223                         check_again = TRUE;
224                         return TRUE;
225                 } else
226                         check_again = FALSE;
227         }
228
229         if (__is_wifi_profile_available() == FALSE) {
230                 netconfig_send_notification_to_net_popup(
231                 NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
232                 goto cleanup;
233         }
234
235         vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable);
236         if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) {
237                 DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE");
238                 goto cleanup;
239         }
240
241         vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state);
242         if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) {
243                 goto cleanup;
244         }
245
246         netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL);
247
248         _set_bss_found(FALSE);
249
250 cleanup:
251         netconfig_stop_timer(&network_noti_timer_id);
252         return FALSE;
253 }
254
255 static char *_get_connman_favorite_service(void)
256 {
257         char *favorite_service = NULL;
258         GVariant *message = NULL;
259         gchar *obj;
260         GVariantIter *iter, *next;
261
262         message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
263                         CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
264                         "GetServices", NULL);
265         if (message == NULL) {
266                 ERR("Failed to get service list");
267                 return NULL;
268         }
269
270         g_variant_get(message, "(a(oa{sv}))", &iter);
271         while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
272                 if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE) {
273                         continue;
274                 }
275
276                 if (__is_favorited(next) == TRUE) {
277                         favorite_service = g_strdup(obj);
278                         g_free(obj);
279                         g_variant_iter_free(next);
280                         break;
281                 }
282         }
283
284         g_variant_iter_free(iter);
285         g_variant_unref(message);
286
287         return favorite_service;
288 }
289
290 static void __notification_value_changed_cb(keynode_t *node, void *user_data)
291 {
292         int value = -1;
293
294         if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &value) < 0) {
295                 return;
296         }
297
298         if (value == VCONFKEY_WIFI_QS_DISABLE) {
299                 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
300         }
301 }
302
303 static void _register_network_notification(void)
304 {
305 #if defined TIZEN_WEARABLE
306         return;
307 #endif
308         vconf_notify_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb, NULL);
309 }
310
311 static void _deregister_network_notification(void)
312 {
313 #if defined TIZEN_WEARABLE
314                 return;
315 #endif
316         vconf_ignore_key_changed(VCONFKEY_WIFI_ENABLE_QS, __notification_value_changed_cb);
317 }
318
319 static void _set_power_save(gboolean power_save)
320 {
321         gboolean result;
322         const char *if_path;
323         GVariant *input_args = NULL;
324         static gboolean old_state = TRUE;
325         const gchar *args_disable = "POWERMODE 1";
326         const gchar *args_enable = "POWERMODE 0";
327         if (old_state == power_save)
328                 return;
329
330         if_path = netconfig_wifi_get_supplicant_interface();
331         if (if_path == NULL) {
332                 ERR("Fail to get wpa_supplicant DBus path");
333                 return;
334         }
335
336         if (power_save)
337                 input_args = g_variant_new_string(args_enable);
338         else
339                 input_args = g_variant_new_string(args_disable);
340
341         result = netconfig_supplicant_invoke_dbus_method_nonblock(
342                         SUPPLICANT_SERVICE,
343                         if_path,
344                         SUPPLICANT_INTERFACE ".Interface",
345                         "Driver",
346                         input_args,
347                         NULL);
348         if (result == FALSE)
349                 ERR("Fail to set power save mode POWERMODE %d", power_save);
350         else
351                 old_state = power_save;
352
353         return;
354 }
355
356 static void _set_power_lock(gboolean power_lock)
357 {
358         gint32 ret = 0;
359         GVariant *reply;
360         GVariant *params;
361         char state[] = "lcdoff";
362         char flag[] = "staycurstate";
363         char standby[] = "NULL";
364         int timeout = 0;
365         char sleepmargin[] = "sleepmargin";
366
367         const char *lockstate = "lockstate";
368         const char *unlockstate = "unlockstate";
369         static gboolean old_state = FALSE;
370         const char *lock_method;
371
372         if (old_state == power_lock)
373                 return;
374
375         if (power_lock == TRUE) {
376                 /* deviced power lock enable */
377                 params = g_variant_new("(sssi)", state, flag, standby, timeout);
378
379                 lock_method = lockstate;
380         } else {
381                 /* deviced power lock disable */
382                 params = g_variant_new("(ss)", state, sleepmargin);
383
384                 lock_method = unlockstate;
385         }
386
387         reply = netconfig_invoke_dbus_method(
388                         "org.tizen.system.deviced",
389                         "/Org/Tizen/System/DeviceD/Display",
390                         "org.tizen.system.deviced.display",
391                         lock_method,
392                         params);
393         if (reply == NULL){
394                 ERR("Failed to set_power_lock");
395                 return;
396         }
397
398         ret = g_variant_get_int32(reply);
399         if (ret < 0)
400                 ERR("Failed to set power lock %s with ret %d",
401                                 power_lock == TRUE ? "enable" : "disable", ret);
402         else
403                 old_state = power_lock;
404
405         g_variant_unref(reply);
406
407         return;
408 }
409
410 void wifi_state_emit_power_completed(gboolean power_on)
411 {
412         if (power_on)
413                 wifi_emit_power_on_completed((Wifi *)get_wifi_object());
414         else
415                 wifi_emit_power_off_completed((Wifi *)get_wifi_object());
416
417         DBG("Successfully sent signal [%s]",(power_on)?"powerOn":"powerOff");
418 }
419
420 void wifi_state_emit_power_failed(void)
421 {
422         wifi_emit_power_operation_failed((Wifi *)get_wifi_object());
423
424         DBG("Successfully sent signal [PowerOperationFailed]");
425 }
426
427 void wifi_state_update_power_state(gboolean powered)
428 {
429         wifi_tech_state_e tech_state;
430
431         /* It's automatically updated by signal-handler
432          * DO NOT update manually
433          * It includes Wi-Fi state configuration
434          */
435         tech_state = wifi_state_get_technology_state();
436
437         if (powered == TRUE) {
438                 if (tech_state < NETCONFIG_WIFI_TECH_POWERED && netconfig_is_wifi_tethering_on() != TRUE) {
439                         DBG("Wi-Fi turned on or waken up from power-save mode");
440
441                         wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
442
443                         wifi_state_emit_power_completed(TRUE);
444
445                         netconfig_wifi_device_picker_service_start();
446
447                         netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_UNCONNECTED);
448                         netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
449                         netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
450
451                         netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
452
453                         netconfig_wifi_bgscan_stop();
454                         netconfig_wifi_bgscan_start(TRUE);
455
456                         /* Add callback to track change in notification setting */
457                         _register_network_notification();
458                 }
459         } else if (tech_state > NETCONFIG_WIFI_TECH_OFF) {
460                 DBG("Wi-Fi turned off or in power-save mode");
461
462                 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_WPS_ONLY);
463
464                 netconfig_wifi_device_picker_service_stop();
465
466                 wifi_power_disable_technology_state_by_only_connman_signal();
467                 wifi_power_driver_and_supplicant(FALSE);
468
469                 wifi_state_emit_power_completed(FALSE);
470
471                 netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF);
472                 netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
473                 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
474
475                 netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF);
476
477                 netconfig_wifi_set_bgscan_pause(FALSE);
478                 netconfig_wifi_bgscan_stop();
479
480                 _set_bss_found(FALSE);
481
482                 /* Inform net-popup to remove the wifi found notification */
483                 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
484                 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
485
486                 _deregister_network_notification();
487         }
488 }
489
490 char *wifi_get_favorite_service(void)
491 {
492         return _get_connman_favorite_service();
493 }
494
495 void wifi_start_timer_network_notification(void)
496 {
497 #if defined TIZEN_WEARABLE
498                 /* In case of wearable device, no need to notify available Wi-Fi APs */
499                 return ;
500 #endif
501         netconfig_start_timer(NETCONFIG_NETWORK_NOTIFICATION_TIMEOUT, _check_network_notification, NULL, &network_noti_timer_id);
502 }
503
504 void wifi_state_notifier_register(wifi_state_notifier *notifier)
505 {
506         DBG("register notifier");
507
508         notifier_list = g_slist_append(notifier_list, notifier);
509 }
510
511 void wifi_state_notifier_unregister(wifi_state_notifier *notifier)
512 {
513         DBG("un-register notifier");
514
515         notifier_list = g_slist_remove_all(notifier_list, notifier);
516 }
517
518 void wifi_state_notifier_cleanup(void)
519 {
520         g_slist_free_full(notifier_list, NULL);
521 }
522
523 void wifi_state_set_bss_found(gboolean found)
524 {
525         _set_bss_found(found);
526 }
527
528 gboolean wifi_state_is_bss_found(void)
529 {
530         return new_bss_found;
531 }
532
533 void wifi_state_set_service_state(wifi_service_state_e new_state)
534 {
535         static gboolean dhcp_stage = FALSE;
536         wifi_service_state_e old_state = g_service_state;
537
538         if (old_state == new_state)
539                 return;
540
541         g_service_state = new_state;
542         DBG("Wi-Fi state %d ==> %d", old_state, new_state);
543
544         /* During DHCP, temporarily disable Wi-Fi power saving */
545         if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_CONFIGURATION) {
546                 _set_power_lock(TRUE);
547                 _set_power_save(FALSE);
548                 dhcp_stage = TRUE;
549         } else if (dhcp_stage == TRUE) {
550                 _set_power_lock(FALSE);
551                 _set_power_save(TRUE);
552                 dhcp_stage = FALSE;
553         }
554
555         if (new_state == NETCONFIG_WIFI_CONNECTED) {
556                 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL);
557
558                 netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED);
559                 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED);
560
561                 netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED);
562
563                 __set_wifi_connected_essid();
564
565                 netconfig_wifi_indicator_start();
566         } else if (old_state == NETCONFIG_WIFI_CONNECTED) {
567                 netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL);
568
569                 __unset_wifi_connected_essid();
570
571                 netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
572                 netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
573
574                 netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
575
576                 netconfig_wifi_indicator_stop();
577
578                 netconfig_wifi_set_bgscan_pause(FALSE);
579
580                 netconfig_wifi_bgscan_stop();
581                 netconfig_wifi_bgscan_start(TRUE);
582         } else if ((old_state > NETCONFIG_WIFI_IDLE && old_state < NETCONFIG_WIFI_CONNECTED) && new_state == NETCONFIG_WIFI_IDLE){
583                 //in ipv6 case disconnect/association -> association
584                 DBG("reset the bg scan period");
585                 netconfig_wifi_set_bgscan_pause(FALSE);
586
587                 netconfig_wifi_bgscan_stop();
588                 netconfig_wifi_bgscan_start(TRUE);
589         }
590
591         _wifi_state_changed(new_state);
592
593         if (new_state == NETCONFIG_WIFI_CONNECTED){
594                 _wifi_state_connected_activation();
595 #if defined TIZEN_WEARABLE
596                 wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
597 #endif
598         }
599 }
600
601 wifi_service_state_e wifi_state_get_service_state(void)
602 {
603         return g_service_state;
604 }
605
606 void wifi_state_set_tech_state(wifi_tech_state_e new_state)
607 {
608         wifi_tech_state_e old_state = g_tech_state;
609
610         if (old_state == new_state)
611                 return;
612
613         g_tech_state = new_state;
614
615         DBG("Wi-Fi technology state %d ==> %d", old_state, new_state);
616 }
617
618 wifi_tech_state_e wifi_state_get_technology_state(void)
619 {
620         GVariant *message = NULL, *variant;
621         GVariantIter *iter, *next;
622         wifi_tech_state_e ret = NETCONFIG_WIFI_TECH_OFF;
623         gboolean wifi_tech_powered = FALSE;
624         gboolean wifi_tech_connected = FALSE;
625         const char *path;
626         gchar *key;
627
628         if (g_tech_state > NETCONFIG_WIFI_TECH_UNKNOWN)
629                 return g_tech_state;
630
631         message = netconfig_invoke_dbus_method(CONNMAN_SERVICE,
632                         CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE,
633                         "GetTechnologies", NULL);
634         if (message == NULL) {
635                 ERR("Failed to get_technology_state");
636                 return NETCONFIG_WIFI_TECH_UNKNOWN;
637         }
638
639         g_variant_get(message, "(a(oa{sv}))", &iter);
640         while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
641                 if (path == NULL || g_strcmp0(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) != 0) {
642                         continue;
643                 }
644
645                 while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
646                         const gchar *sdata = NULL;
647                         gboolean data;
648
649                         if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
650                                 data = g_variant_get_boolean(variant);
651                                 DBG("key-[%s] - %s", key, data ? "True" : "False");
652
653                                 if (strcmp(key, "Powered") == 0 && data) {
654                                         wifi_tech_powered = TRUE;
655                                 } else if (strcmp(key, "Connected") == 0 && data) {
656                                         wifi_tech_connected = TRUE;
657                                 } else if (strcmp(key, "Tethering") == 0 && data) {
658                                         // For further use
659                                 }
660                         } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
661                                 sdata = g_variant_get_string(variant, NULL);
662                                 DBG("%s", sdata);
663                         }
664                 }
665                 g_variant_iter_free (next);
666         }
667
668         g_variant_unref(message);
669
670         g_variant_iter_free (iter);
671
672         if (wifi_tech_powered == TRUE)
673                 ret = NETCONFIG_WIFI_TECH_POWERED;
674
675         if (wifi_tech_connected == TRUE)
676                 ret = NETCONFIG_WIFI_TECH_CONNECTED;
677
678         g_tech_state = ret;
679
680         return g_tech_state;
681 }
682
683 void wifi_state_set_connected_essid(void)
684 {
685         __set_wifi_connected_essid();
686 #if defined TIZEN_WEARABLE
687         wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
688 #endif
689 }
690
691 void wifi_state_get_connected_essid(gchar **essid)
692 {
693         *essid = g_strdup(__get_wifi_connected_essid());
694 }
695
696 /*      wifi_connection_state_e in CAPI
697  *
698  *      WIFI_CONNECTION_STATE_FAILURE           = -1
699  *      WIFI_CONNECTION_STATE_DISCONNECTED      = 0
700  *      WIFI_CONNECTION_STATE_ASSOCIATION       = 1
701  *      WIFI_CONNECTION_STATE_CONFIGURATION     = 2
702  *      WIFI_CONNECTION_STATE_CONNECTED         = 3
703  */
704 /*      connection_wifi_state_e in CAPI
705  *
706  *      CONNECTION_WIFI_STATE_DEACTIVATED       = 0
707  *      CONNECTION_WIFI_STATE_DISCONNECTED      = 1
708  *      CONNECTION_WIFI_STATE_CONNECTED         = 2
709  */
710 gboolean handle_get_wifi_state(Wifi *wifi, GDBusMethodInvocation *context)
711 {
712         g_return_val_if_fail(wifi != NULL, FALSE);
713         GVariant *param = NULL;
714         wifi_tech_state_e tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
715         wifi_service_state_e service_state = NETCONFIG_WIFI_UNKNOWN;
716         tech_state = wifi_state_get_technology_state();
717         service_state = wifi_state_get_service_state();
718
719         if(tech_state == NETCONFIG_WIFI_TECH_UNKNOWN) {
720                 param = g_variant_new("(s)", "unknown");
721         } else if(tech_state == NETCONFIG_WIFI_TECH_OFF ||
722                 tech_state == NETCONFIG_WIFI_TECH_WPS_ONLY) {
723                 param = g_variant_new("(s)", "deactivated");
724         } else {
725                 switch (service_state) {
726                 case NETCONFIG_WIFI_FAILURE:
727                         param = g_variant_new("(s)", "failure");
728                         break;
729                 case NETCONFIG_WIFI_ASSOCIATION:
730                         param = g_variant_new("(s)", "association");
731                         break;
732                 case NETCONFIG_WIFI_CONFIGURATION:
733                         param = g_variant_new("(s)", "configuration");
734                         break;
735                 case NETCONFIG_WIFI_CONNECTED:
736                         param = g_variant_new("(s)", "connected");
737                         break;
738                 case NETCONFIG_WIFI_UNKNOWN:
739                 case NETCONFIG_WIFI_IDLE:
740                 default:
741                         param = g_variant_new("(s)", "disconnected");
742                 }
743         }
744
745         g_dbus_method_invocation_return_value(context, param);
746
747         return TRUE;
748 }