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