495ecc04b8057f12931ea81e74cc6b9671cb96bf
[apps/native/ug-mobile-ap.git] / src / mh_func_onoff.c
1 /*
2 * ug-mobile-ap
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 <stdlib.h>
21 #include <glib.h>
22
23 #include "mh_func_onoff.h"
24 #include "mh_popup.h"
25 #include "mh_string.h"
26
27 static bool is_wifi_tethering_checkbox_popup_active = false;
28
29 void _update_tethering_enabling_item(mh_appdata_t *ad, tethering_type_e type, mh_state_e state)
30 {
31         switch(type) {
32         case TETHERING_TYPE_WIFI:
33                 _update_wifi_item(ad, MH_STATE_NONE);
34                 ad->is_wifi_teth_enabling = false;
35                 break;
36
37         case TETHERING_TYPE_BT:
38                 _update_bt_item(ad, MH_STATE_NONE);
39                 ad->is_bt_teth_enabling = false;
40                 break;
41
42         case TETHERING_TYPE_USB:
43                 _update_usb_item(ad, MH_STATE_NONE);
44                 ad->is_usb_teth_enabling = false;
45                 break;
46
47         default :
48                 ERR("invalid type \n");
49                 break;
50         }
51 }
52 void _wifi_tethering_checkbox_popup_status_set(bool value)
53 {
54         is_wifi_tethering_checkbox_popup_active = value;
55 }
56
57 bool _wifi_tethering_checkbox_popup_status_get(void)
58 {
59         return is_wifi_tethering_checkbox_popup_active;
60 }
61
62 int _get_vconf_usb_state()
63 {
64         int value = VCONFKEY_SYSMAN_USB_DISCONNECTED;
65
66         if (vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &value) < 0) {
67                 ERR("vconf_get_int is failed\n");
68                 return 0;
69         }
70         DBG("%s : %d\n", VCONFKEY_SYSMAN_USB_STATUS, value);
71
72         return value;
73 }
74
75 void _update_tethering_item(mh_appdata_t * ad, mh_state_e state)
76 {
77         ERR("type : %d state : %d\n", ad->type, state);
78         switch(ad->type)        {
79                 case TETHERING_TYPE_WIFI:
80                         _update_wifi_item(ad, state);
81                         break;
82                 case TETHERING_TYPE_BT:
83                         _update_bt_item(ad, state);
84                         break;
85                 case TETHERING_TYPE_USB:
86                         _update_usb_item(ad, state);
87                         break;
88                 default:
89                         break;
90         }
91 }
92
93 gboolean _ps_recheck_timeout_cb(gpointer data)
94 {
95         connection_cellular_state_e cellular_state = _get_cellular_state();
96         mh_appdata_t *ad = (mh_appdata_t *)data;
97         static int recheck_count = 0;
98
99         DBG("Re-Check cellular state (%d)\n", recheck_count);
100
101         if(cellular_state == CONNECTION_CELLULAR_STATE_FLIGHT_MODE) {
102                 _update_tethering_item(ad, MH_STATE_NONE);
103                 recheck_count = 0;
104                 return FALSE;
105         }
106
107         if (cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED ||
108                 cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
109                 if (ad->type == TETHERING_TYPE_WIFI) {
110                         if (_create_wifi_hotspot_on_popup(ad) < 0) {
111                                 ERR("__create_wifi_hotspot_on_popup fail\n");
112                                 _update_tethering_item(ad, MH_STATE_NONE);
113                                 recheck_count = 0;
114                                 return FALSE;
115                         }
116                 _send_signal_qp(QP_SIGNAL_PROGRESS_ON);
117                 } else if (ad->type == TETHERING_TYPE_BT && _create_bt_tethering_on_popup(ad) < 0) {
118                                 ERR("_create_bt_tethering_on_popup fail\n");
119                                 _update_tethering_item(ad, MH_STATE_NONE);
120                                 recheck_count = 0;
121                                 return FALSE;
122                 } else if (ad->type == TETHERING_TYPE_USB && _create_usb_tethering_on_popup(ad) < 0) {
123                                 ERR("__create_usb_hotspot_on_popup fail\n");
124                                 _update_tethering_item(ad, MH_STATE_NONE);
125                                 recheck_count = 0;
126                                 return FALSE;
127                 } else {
128                         ERR("Unknown tethering type \n");
129                         recheck_count = 0;
130                         return FALSE;
131                 }
132         } else {
133                 if(++recheck_count >= PS_RECHECK_COUNT_MAX) {
134                         DBG("Cellular network is not connected : %d\n", cellular_state);
135                         _update_tethering_item(ad, MH_STATE_NONE);
136                         _prepare_popup(MH_POPUP_NETWORK_OUT_OF_RANGE, STR_NO_DATA_SERVICE);
137                         _create_popup(ad);
138                         recheck_count = 0;
139                         return FALSE;
140                 }
141                 return TRUE;
142         }
143         recheck_count = 0;
144         return FALSE;
145 }
146
147 static bool __is_connected_wifi_net(mh_appdata_t *ad)
148 {
149         connection_wifi_state_e wifi_state = CONNECTION_WIFI_STATE_DEACTIVATED;
150         int ret;
151
152         ret = connection_get_wifi_state(ad->conn_handle, &wifi_state);
153         if (ret != CONNECTION_ERROR_NONE) {
154                 ERR("connection_get_wifi_state() is failed : %d\n");
155                 return false;
156         }
157
158         if (wifi_state != CONNECTION_WIFI_STATE_CONNECTED) {
159                 ERR("Wi-Fi network is not connected : %d\n", wifi_state);
160                 return false;
161         }
162
163         DBG("Wi-Fi network is connected\n");
164         return true;
165 }
166
167 static bool __is_connected_ethernet_net(mh_appdata_t *ad)
168 {
169         connection_ethernet_state_e ethernet_state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
170         int ret;
171
172         ret = connection_get_ethernet_state(ad->conn_handle, &ethernet_state);
173         if (ret != CONNECTION_ERROR_NONE) {
174                 ERR("connection_get_ethernet_state() is failed : %d\n");
175                 return false;
176         }
177
178         if (ethernet_state != CONNECTION_ETHERNET_STATE_CONNECTED) {
179                 ERR("Ethernet network is not connected : %d\n", ethernet_state);
180                 return false;
181         }
182
183         DBG("Ethernet network is connected\n");
184         return true;
185 }
186
187 static int __is_preconditions_handled(mh_appdata_t *ad)
188 {
189         DBG("+\n");
190
191         connection_cellular_state_e cellular_state = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
192         int dnet_state = 0;
193
194         /* check ethernet connection */
195         if (__is_connected_ethernet_net(ad)) {
196                 DBG("ethernet network is connected\n");
197                 return 1;
198         }
199
200         /*  check wifi connection */
201         if (ad->type != TETHERING_TYPE_WIFI) {
202                 if (__is_connected_wifi_net(ad)) {
203                         DBG("wifi network is connected\n");
204                         return 1;
205                 }
206         }
207
208         /* Check SIM state */
209         if (_get_sim_state() != VCONFKEY_TELEPHONY_SIM_INSERTED) {
210                 if(ad->type == TETHERING_TYPE_WIFI)
211                         _prepare_popup(MH_POPUP_NO_SIM, STR_INSERT_SIM_TO_USE_TETH);
212                 else
213                         _prepare_popup(MH_POPUP_NO_SIM, STR_CONN_MOBILE_DATA_TO_USE_TETH);
214
215                 _create_popup(ad);
216                 return -1;
217         }
218
219         /* Check cellular state */
220         cellular_state = _get_cellular_state();
221         DBG("cellular state is :  %d \n", cellular_state);
222         if (cellular_state == CONNECTION_CELLULAR_STATE_FLIGHT_MODE) {
223                 _prepare_popup(MH_POPUP_FLIGHT_MODE, STR_DISABLE_FLIGHT_MODE_MSG);
224                 _create_popup(ad);
225                 ERR("Flight mode is ON\n");
226                 return -1;
227         } else {
228                 if (vconf_get_bool(VCONFKEY_3G_ENABLE , &dnet_state) < 0) {
229                         ERR("vconf_get_bool is failed\n");
230                 } else if(dnet_state == 0) {
231                         DBG("Data Network is not connected");
232                         _prepare_popup(MH_POPUP_MOBILE_DATA_OFF, STR_NO_NET_CONN_MSG);
233                         _create_popup(ad);
234                         return 0;
235                 }
236                 if (cellular_state != CONNECTION_CELLULAR_STATE_CONNECTED &&
237                         cellular_state != CONNECTION_CELLULAR_STATE_AVAILABLE) {
238                         if(ad->ps_recheck_timer_id > 0) {
239                                 g_source_remove(ad->ps_recheck_timer_id);
240                                 ad->ps_recheck_timer_id = 0;
241                                 if (ad->is_wifi_teth_enabling == true && ad->type != TETHERING_TYPE_WIFI) {
242                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_WIFI, MH_STATE_NONE);
243                                 }
244                                 if (ad->is_bt_teth_enabling == true && ad->type != TETHERING_TYPE_BT) {
245                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_BT, MH_STATE_NONE);
246                                 }
247                                 if (ad->is_usb_teth_enabling == true && ad->type != TETHERING_TYPE_USB) {
248                                         _update_tethering_enabling_item(ad, TETHERING_TYPE_USB, MH_STATE_NONE);
249                                 }
250                         }
251                         ad->ps_recheck_timer_id = g_timeout_add(PS_RECHECK_INTERVAL, _ps_recheck_timeout_cb, (void*)ad);
252                         return 0;
253                 }
254         }
255
256         DBG("Cellular network is connected\n");
257         DBG("-\n");
258         return 1;
259 }
260
261 int _create_wifi_hotspot_on_popup(mh_appdata_t *ad)
262 {
263         char *fmt = NULL;
264         char *str = NULL;
265         bool wifi_state = false;
266         int value = 0;
267
268         wifi_is_activated(&wifi_state);
269         _set_vconf_prev_wifi_state(wifi_state);
270         value = _get_checkbox_status(TETHERING_TYPE_WIFI);
271         if (0 == value) {
272                 if (wifi_state == true || _is_wifi_direct_on() == true) {
273                         fmt = STR_TETH_ON_DESC_1;
274                 } else {
275                         fmt = STR_TETH_ON_DESC_2;
276                 }
277                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
278                 if (str == NULL) {
279                         ERR("memory allocation is failed\n");
280                         return -1;
281                 }
282                 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
283                 _wifi_tethering_checkbox_popup_status_set(true);
284                 _prepare_popup(MH_POPUP_WIFI_ON_CHECKBOX, str);
285                 g_free(str);
286                 _create_popup(ad);
287         } else {
288                 _prepare_popup_type(MH_POPUP_WIFI_ON_CHECKBOX);
289                 _teth_on(ad);
290         }
291         return 0;
292 }
293
294 int _create_bt_tethering_on_popup(mh_appdata_t *ad)
295 {
296         char *str;
297         int value = 0;
298         value = _get_checkbox_status(TETHERING_TYPE_BT);
299         if (0 == value) {
300                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
301                 if (str == NULL) {
302                         ERR("memory allocation is failed\n");
303                         return -1;
304                 }
305                 snprintf(str, MH_LABEL_LENGTH_MAX, STR_TETH_ON_DESC_2,
306                                 TETHERING_BT_MAX_CONNECTED_STA);
307                 _prepare_popup(MH_POPUP_BT_ON_CHECKBOX, str);
308                 g_free(str);
309                 _create_popup(ad);
310         } else {
311                 _prepare_popup_type(MH_POPUP_BT_ON_CHECKBOX);
312                 _teth_on(ad);
313         }
314         return 0;
315 }
316
317 int _create_usb_tethering_on_popup(mh_appdata_t *ad)
318 {
319         int value = 0;
320         char *str = NULL;
321         value = _get_checkbox_status(TETHERING_TYPE_USB);
322         DBG("%s : %d\n", VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, value);
323         if (0 == value) {
324                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
325                 if (str == NULL) {
326                         ERR("memory allocation is failed\n");
327                         return -1;
328                 }
329                 snprintf(str, MH_LABEL_LENGTH_MAX, "%s",
330                                 STR_TETH_ON_DESC_3);
331                 _prepare_popup(MH_POPUP_USB_ON_CHECKBOX, str);
332                 g_free(str);
333                 _create_popup(ad);
334         } else {
335                 _prepare_popup_type(MH_POPUP_USB_ON_CHECKBOX);
336                 _teth_on(ad);
337         }
338         return 0;
339 }
340
341 static void __disable_tethering_by_ind(mh_appdata_t *ad, tethering_disabled_cause_e cause)
342 {
343         if (ad == NULL) {
344                 ERR("Param is NULL\n");
345                 return;
346         }
347
348         DBG("cause : %d\n", cause);
349         switch (cause) {
350         case TETHERING_DISABLED_BY_WIFI_ON:
351                 break;
352
353         case TETHERING_DISABLED_BY_BT_OFF:
354                 break;
355
356         case TETHERING_DISABLED_BY_USB_DISCONNECTION:
357                 if (ad->is_bt_teth_enabling && ad->main.bt_item) {
358                         _update_bt_item(ad, MH_STATE_NONE);
359                         ad->is_bt_teth_enabling = false;
360                 }
361                 if (ad->is_wifi_teth_enabling && ad->main.wifi_item) {
362                         _update_wifi_item(ad, MH_STATE_NONE);
363                         ad->is_wifi_teth_enabling = false;
364                 }
365                 break;
366
367         case TETHERING_DISABLED_BY_FLIGHT_MODE:
368                 break;
369
370         case TETHERING_DISABLED_BY_TIMEOUT:
371                 break;
372
373         case TETHERING_DISABLED_BY_OTHERS:
374                 if (ad->main.wifi_item && _get_vconf_prev_wifi_state() == true) {
375                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
376                 }
377                 break;
378
379         case TETHERING_DISABLED_BY_LOW_BATTERY:
380                 break;
381
382         default:
383                 break;
384         }
385
386         return;
387 }
388
389 /* Wi-Fi callbacks */
390 static void __wifi_activated_cb(wifi_error_e result, void *user_data)
391 {
392         DBG("+\n");
393
394         return;
395 }
396
397 /* Tethering callbacks */
398 void _enabled_cb(tethering_error_e result, tethering_type_e type, bool is_requested, void *user_data)
399 {
400         DBG("+\n");
401         DBG("result : %d, type : %d, is_requested : %d\n", result, type, is_requested);
402
403         if (user_data == NULL) {
404                 ERR("user_data is NULL\n");
405                 return;
406         }
407
408         mh_appdata_t *ad = (mh_appdata_t *)user_data;
409
410         if (!is_requested) {
411                 if (ad->type == type && ad->popup) {
412                         DBG("This tethering type is already enabled\n");
413                         evas_object_del(ad->popup);
414                         ad->popup = NULL;
415                 }
416                 _update_main_view(ad, type);
417                 if (type == TETHERING_TYPE_RESERVED) {
418                         DBG("MobileAP is turned on\n");
419                         _prepare_popup(MH_POPUP_WIFI_AP_OFF, STR_WIFI_AP_CONTROLLED_ANOTHER_APP);
420                         _create_popup(ad);
421                 }
422                 return;
423         }
424
425         if (result != TETHERING_ERROR_NONE) {
426         }
427         _update_main_view(ad, type);
428
429         return;
430 }
431
432 void _disabled_cb(tethering_error_e result, tethering_type_e type, tethering_disabled_cause_e cause, void *user_data)
433 {
434         DBG("+\n");
435         DBG("result : %d, type : %d, cause : %d\n", result, type, cause);
436
437         if (user_data == NULL) {
438                 ERR("user_data is NULL\n");
439                 return;
440         }
441
442         mh_appdata_t *ad = (mh_appdata_t *)user_data;
443
444         if (cause != TETHERING_DISABLED_BY_REQUEST) {
445                 if (ad->type == type && ad->popup) {
446                         DBG("This tethering type is already disabled\n");
447                         evas_object_del(ad->popup);
448                         ad->popup = NULL;
449                 }
450                 __disable_tethering_by_ind(ad, cause);
451                 _update_main_view(ad, type);
452                 return;
453         }
454
455         if (result != TETHERING_ERROR_NONE) {
456                 _prepare_popup(MH_POPUP_TETH_ENABLING_FAILED, STR_UNABLE_TO_USE_TETH);
457                 _create_popup(ad);
458                 _update_main_view(ad, type);
459                 return;
460         }
461
462         if (ad->main.wifi_item && type == TETHERING_TYPE_WIFI && _get_vconf_prev_wifi_state() == true) {
463                 elm_object_item_disabled_set(ad->main.wifi_item, EINA_TRUE);
464         }
465
466         _update_main_view(ad, type);
467
468         return;
469 }
470
471 void _connection_changed_cb(tethering_client_h client, bool is_opened, void *user_data)
472 {
473         DBG("+\n");
474
475         if (user_data == NULL) {
476                 ERR("user_data is NULL\n");
477                 return;
478         }
479
480         mh_appdata_t *ad = (mh_appdata_t *)user_data;
481         char *mac_addr = NULL;
482
483         if (is_opened) {
484                 _append_list_client_handle(ad, client);
485
486 #ifdef TETHERING_DATA_USAGE_SUPPORT
487                 if (ad->is_foreground && _get_list_clients_count(ad) == 1) {
488                         _start_update_data_packet_usage(ad);
489                 }
490 #endif
491         } else {
492                 tethering_client_get_mac_address(client, &mac_addr);
493                 if (mac_addr) {
494                         _delete_list_client_handle(ad, mac_addr);
495                         free(mac_addr);
496                 }
497 #ifdef TETHERING_DATA_USAGE_SUPPORT
498                 if (ad->is_foreground && _get_list_clients_count(ad) == 0)
499                         _stop_update_data_packet_usage(ad);
500 #endif
501         }
502
503         ap_update_data_device(ad);
504
505         return;
506 }
507
508 void _wifi_state_changed_cb(wifi_device_state_e state, void *user_data)
509 {
510         if (user_data == NULL) {
511                 ERR("user_data is NULL\n");
512                 return;
513         }
514
515         DBG("+\n");
516
517         mh_appdata_t *ad= (mh_appdata_t *)user_data;
518         char *str = NULL;
519         char *fmt = NULL;
520         if (state == WIFI_DEVICE_STATE_ACTIVATED) {
521                 if (ad->main.wifi_item && elm_object_item_disabled_get(ad->main.wifi_item))
522                         elm_object_item_disabled_set(ad->main.wifi_item, EINA_FALSE);
523                 _set_vconf_prev_wifi_state(false);
524         } else if (state == WIFI_CONNECTION_STATE_DISCONNECTED){
525                 _set_vconf_prev_wifi_state(true);
526         }
527
528         if (ad->type == TETHERING_TYPE_WIFI && ad->popup && ad->popup_checkbox &&
529                         _wifi_tethering_checkbox_popup_status_get()) {
530                 evas_object_del(ad->popup_checkbox);
531                 ad->popup_checkbox = NULL;
532                 evas_object_del(ad->popup);
533                 ad->popup = NULL;
534                 if (state == WIFI_DEVICE_STATE_ACTIVATED) {
535                         fmt = STR_TETH_ON_DESC_1;
536                 } else {
537                         fmt = STR_TETH_ON_DESC_2;
538                 }
539                 str = g_malloc0(MH_LABEL_LENGTH_MAX);
540                 if (str == NULL) {
541                         ERR("memory allocation is failed\n");
542                         return;
543                 }
544                 snprintf(str, MH_LABEL_LENGTH_MAX, fmt, TETHERING_WIFI_MAX_CONNECTED_STA);
545                 _prepare_popup(MH_POPUP_WIFI_ON_CHECKBOX, str);
546                 g_free(str);
547                 _create_popup(ad);
548         }
549         DBG("-\n");
550 }
551
552 void _visibility_changed_cb(bool is_visible, void *user_data)
553 {
554         DBG("+\n");
555
556         if (user_data == NULL) {
557                 ERR("user_data is NULL\n");
558                 return;
559         }
560
561         mh_appdata_t *ad = (mh_appdata_t *)user_data;
562
563         if (ad->setup.visibility == is_visible)
564                 return;
565
566         ad->setup.visibility = is_visible;
567         ad->setup.visibility_new = is_visible;
568         if (ad->setup.hide_item)
569                 elm_genlist_item_update(ad->setup.hide_item);
570
571         DBG("-\n");
572
573         return;
574 }
575
576 void _security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
577 {
578         DBG("+\n");
579
580         if (user_data == NULL) {
581                 ERR("user_data is NULL\n");
582                 return;
583         }
584
585         mh_appdata_t *ad = (mh_appdata_t *)user_data;
586
587         if (ad->setup.security_type == changed_type)
588                 return;
589
590         ad->setup.security_type = changed_type;
591         ad->setup.security_type_new = changed_type;
592
593         if (ad->setup.security_item)
594                 elm_genlist_item_update(ad->setup.security_item);
595
596         DBG("-\n");
597
598         return;
599 }
600
601 void _passphrase_changed_cb(void *user_data)
602 {
603         DBG("+\n");
604
605         if (user_data == NULL) {
606                 ERR("user_data is NULL\n");
607                 return;
608         }
609
610         mh_appdata_t *ad = (mh_appdata_t *)user_data;
611         char *passphrase = NULL;
612         int ret;
613
614         ret = tethering_wifi_get_passphrase(ad->handle, &passphrase);
615         if (ret != TETHERING_ERROR_NONE) {
616                 ERR("tethering_wifi_get_passphrase failed ret = [0x%x]\n", ret);
617                 return;
618         }
619
620         if (!g_strcmp0(passphrase, ad->setup.wifi_passphrase)) {
621                 goto DONE;
622         }
623
624         g_strlcpy(ad->setup.wifi_passphrase, passphrase,
625                 sizeof(ad->setup.wifi_passphrase));
626
627         g_strlcpy(ad->setup.wifi_passphrase_new, passphrase,
628                 sizeof(ad->setup.wifi_passphrase_new));
629
630         if (ad->setup.pw_item)
631                 elm_genlist_item_update(ad->setup.pw_item);
632
633 DONE:
634         g_free(passphrase);
635         DBG("-\n");
636         return;
637 }
638
639 #ifdef TETHERING_DATA_USAGE_SUPPORT
640 void _data_usage_cb(tethering_error_e result, unsigned long long received_data, unsigned long long sent_data, void *user_data)
641 {
642         if (user_data == NULL) {
643                 ERR("user_data is NULL\n");
644                 return;
645         }
646
647         mh_appdata_t *ad = (mh_appdata_t *)user_data;
648
649         if (ad->data_statistics.pdp_total_sent != sent_data ||
650                         ad->data_statistics.pdp_total_receive != received_data) {
651                 ad->data_statistics.pdp_total_sent = sent_data;
652                 ad->data_statistics.pdp_total_receive = received_data;
653                 ap_update_data_packet_usage(ad);
654         }
655
656         ad->data_statistics.is_updated = true;
657
658         return;
659 }
660 #endif
661 /* End of Tethering callbacks */
662
663 int _handle_wifi_onoff_change(mh_appdata_t *ad)
664 {
665         __MOBILE_AP_FUNC_ENTER__;
666
667         int ret;
668         int connected_wifi_clients = 0;
669
670         /* Turn off WiFi hotspot */
671         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) {
672                 if (_get_no_of_connected_device(ad, &connected_wifi_clients,
673                                         TETHERING_TYPE_WIFI) == EINA_FALSE) {
674                         ERR("Getting the number of connected device is failed\n");
675                 }
676                 if (connected_wifi_clients > 0) {
677                         _prepare_popup(MH_POPUP_WIFI_OFF, STR_CLOSE_INTERNET_Q);
678                         _create_popup(ad);
679                 } else {
680                         ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
681                         if (ret != TETHERING_ERROR_NONE) {
682                                 ERR("wifi tethering off is failed : %d\n", ret);
683                                 return -1;
684                         }
685                         _send_signal_qp(QP_SIGNAL_PROGRESS_OFF);
686                 }
687                 return 0;
688         }
689
690         /* Turn on WiFi hotspot */
691         ret = __is_preconditions_handled(ad);
692         if (ret < 0)
693                 return -1;
694         else if (ret == 0)
695                 return 0;
696
697         if (_create_wifi_hotspot_on_popup(ad) < 0) {
698                 ERR("__create_wifi_hotspot_on_popup fail\n");
699                 return -1;
700         }
701
702         __MOBILE_AP_FUNC_EXIT__;
703
704         return 0;
705 }
706
707 int _handle_bt_onoff_change(mh_appdata_t *ad)
708 {
709         __MOBILE_AP_FUNC_ENTER__;
710
711         int ret;
712
713         /* Turn off Bluetooth tethering */
714         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_BT) {
715                 ret = tethering_disable(ad->handle, TETHERING_TYPE_BT);
716                 if (ret) {
717                         ERR("Error disable bt tethering [%d]\n", ret);
718                         return -1;
719                 }
720                 return 0;
721         }
722
723         /* Turn on Bluetooth tethering */
724         ret = __is_preconditions_handled(ad);
725         if (ret < 0)
726                 return -1;
727         else if (ret == 0)
728                 return 0;
729
730         if (_create_bt_tethering_on_popup(ad) < 0) {
731                 ERR("_create_bt_tethering_on_popup fail\n");
732                 return -1;
733         }
734
735         __MOBILE_AP_FUNC_EXIT__;
736
737         return 0;
738 }
739
740 int _handle_usb_onoff_change(mh_appdata_t *ad)
741 {
742         __MOBILE_AP_FUNC_ENTER__;
743
744         int ret;
745
746         /* Turn off USB tethering */
747         if (ad->main.hotspot_mode & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) {
748                 ret = tethering_disable(ad->handle, TETHERING_TYPE_USB);
749                 if (ret) {
750                         ERR("Error disable usb tethering : %d\n", ret);
751                         return -1;
752                 }
753                 return 0;
754         }
755
756         /* Turn on USB tethering */
757         ret = __is_preconditions_handled(ad);
758         if (ret < 0)
759                 return -1;
760         else if (ret == 0)
761                 return 0;
762
763         if (_create_usb_tethering_on_popup(ad) < 0) {
764                 ERR("_create_usb_tethering_on_popup fail\n");
765                 return -1;
766         }
767
768         __MOBILE_AP_FUNC_EXIT__;
769
770         return 0;
771 }
772
773 int _turn_on_wifi(void)
774 {
775         int ret;
776
777         ret = wifi_activate(__wifi_activated_cb, NULL);
778         if (ret != WIFI_ERROR_NONE) {
779                 ERR("wifi_activate() is failed : %d\n", ret);
780                 return -1;
781         }
782
783         return 0;
784 }
785
786 bool _is_wifi_direct_on(void)
787 {
788         int wifi_direct_state = 0;
789         int ret;
790
791         ret = vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
792         if (ret < 0) {
793                 ERR("vconf_get_int() is failed : %d\n", ret);
794                 return false;
795         }
796
797         return wifi_direct_state != 0 ? true : false;
798 }