3.0 specific patch: classify mobile and the others to enable BT
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-adapter.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Girishashok Joshi <girish.joshi@samsung.com>
8  *               Chanyeol Park <chanyeol.park@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *              http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24 #include <vconf.h>
25 #include <vconf-keys.h>
26 #include <bundle.h>
27 #if 0
28 #include <eventsystem.h>
29 #endif
30
31 #include "bt-core-main.h"
32 #include "bt-core-adapter.h"
33 #include "bt-core-common.h"
34 #include "bt-core-dbus-handler.h"
35 #include "bt-core-noti-handler.h"
36
37 static bt_status_t adapter_status = BT_DEACTIVATED;
38 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
39 static gboolean is_recovery_mode = FALSE;
40
41 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
42 static int bt_le_status_before[BT_MODE_MAX] = { 0, };
43
44 static void __bt_core_set_status(bt_status_t status)
45 {
46         adapter_status = status;
47 }
48
49 bt_status_t _bt_core_get_status(void)
50 {
51         return adapter_status;
52 }
53
54 static void __bt_core_set_le_status(bt_le_status_t status)
55 {
56         adapter_le_status = status;
57 }
58
59 bt_le_status_t _bt_core_get_le_status(void)
60 {
61         return adapter_le_status;
62 }
63
64 int _bt_core_get_bt_status(bt_mode_e mode)
65 {
66         return bt_status_before[mode];
67 }
68
69 int _bt_core_get_bt_le_status(bt_mode_e mode)
70 {
71         return bt_le_status_before[mode];
72 }
73
74 void _bt_core_set_bt_status(bt_mode_e mode, int status)
75 {
76         bt_status_before[mode] = status;
77 }
78
79 void _bt_core_set_bt_le_status(bt_mode_e mode, int status)
80 {
81         bt_le_status_before[mode] = status;
82 }
83
84 gboolean _bt_core_is_recovery_mode(void)
85 {
86         return is_recovery_mode;
87 }
88
89 gboolean _bt_core_is_flight_mode_enabled(void)
90 {
91 #ifdef TIZEN_BT_FLIGHTMODE_ENABLED
92         int isFlightMode = 0;
93         int ret = -1;
94
95         ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
96         if (ret != 0) {
97                 BT_ERR("vconf_get_bool failed");
98         }
99         return isFlightMode;
100 #else
101         return FALSE;
102 #endif
103 }
104
105 static int __execute_command(const char *cmd, char *const arg_list[])
106 {
107         int pid;
108         int pid2;
109         int status = 0;
110         BT_DBG("+");
111
112         pid = fork();
113         switch (pid) {
114         case -1:
115                 BT_ERR("fork failed");
116                 return -1;
117
118         case 0:
119                 pid2 = fork();
120                 if (pid2 == -1) {
121                         BT_ERR("fork failed");
122                 } else if (pid2 == 0) {
123                         execv(cmd, arg_list);
124                         exit(256);
125                 }
126                 exit(0);
127                 break;
128
129         default:
130                 BT_DBG("parent : forked[%d]", pid);
131                 waitpid(pid, &status, 0);
132                 BT_DBG("child is terminated : %d", status);
133                 break;
134         }
135         BT_DBG("-");
136         return 0;
137 }
138
139 int _bt_enable_adapter(void)
140 {
141         int ret;
142         bt_status_t status;
143         bt_le_status_t le_status;
144
145         BT_INFO("");
146
147 #ifdef __TIZEN_MOBILE__
148         status = _bt_core_get_status();
149         if (status != BT_DEACTIVATED) {
150                 BT_ERR("Invalid state %d", status);
151                 return -1;
152         }
153
154         le_status = _bt_core_get_le_status();
155         if (le_status == BT_LE_ACTIVATED) {
156                 /* Turn on PSCAN, (ISCAN if needed) */
157                 /* Return with 0 for the Enabled response. */
158                 __bt_core_set_status(BT_ACTIVATED);
159                 BT_INFO("BR/EDR is enabled.");
160                 return 0;
161         }
162
163         __bt_core_set_status(BT_ACTIVATING);
164
165         ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
166         if (ret < 0) {
167                 BT_ERR("running script failed");
168                 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
169                 __bt_core_set_status(BT_DEACTIVATED);
170                 return -1;
171         }
172 #else
173         _bt_power_adapter(TRUE);
174 #endif
175
176         return 0;
177 }
178
179 int _bt_disable_adapter(void)
180 {
181         bt_status_t status;
182         bt_le_status_t le_status;
183
184         BT_INFO_C("Disable adapter");
185
186 #ifdef __TIZEN_MOBILE__
187         le_status = _bt_core_get_le_status();
188         BT_DBG("le_status : %d", le_status);
189         if (le_status == BT_LE_ACTIVATED) {
190                 /* Turn off PSCAN, (ISCAN if needed) */
191                 /* Return with 0 for the Disabled response. */
192                 __bt_core_set_status(BT_DEACTIVATED);
193                 BT_INFO("BR/EDR is disabled. now LE only mode");
194                 return 0;
195         }
196
197         status = _bt_core_get_status();
198         if (status == BT_ACTIVATING) {
199                 /* Forcely terminate */
200                 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
201                         BT_ERR("running script failed");
202                 }
203                 _bt_core_terminate();
204                 return 0;
205         } else if (status != BT_ACTIVATED) {
206                 BT_ERR("Invalid state %d", status);
207         }
208
209         __bt_core_set_status(BT_DEACTIVATING);
210
211         if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
212                 BT_ERR("running script failed");
213                 __bt_core_set_status( BT_ACTIVATED);
214                 return -1;
215         }
216 #else
217         _bt_power_adapter(FALSE);
218 #endif
219         return 0;
220 }
221
222 int _bt_enable_adapter_le(void)
223 {
224         BT_DBG("");
225 #ifdef __TIZEN_MOBILE__
226         int ret;
227         bt_status_t status;
228         bt_le_status_t le_status;
229         le_status = _bt_core_get_le_status();
230         retv_if(le_status != BT_LE_DEACTIVATED, -1);
231
232         status = _bt_core_get_status();
233         if (status == BT_DEACTIVATED) {
234                 __bt_core_set_le_status(BT_LE_ACTIVATING);
235                 BT_DBG("Activate BT");
236                 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
237                 if (ret < 0) {
238                         BT_ERR("running script failed");
239                         ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
240                         __bt_core_set_status(BT_DEACTIVATED);
241                         __bt_core_set_le_status(BT_LE_DEACTIVATED);
242                         return -1;
243                 }
244         } else {
245                 __bt_core_set_le_status(BT_LE_ACTIVATED);
246         }
247 #else
248         _bt_power_adapter(TRUE);
249 #endif
250         return 0;
251 }
252
253 int _bt_disable_adapter_le(void)
254 {
255         BT_DBG("+");
256
257 #ifdef __TIZEN_MOBILE__
258         bt_status_t status;
259         bt_le_status_t le_status;
260
261         le_status = _bt_core_get_le_status();
262         retv_if(le_status == BT_LE_DEACTIVATED, 0);
263         retv_if(le_status == BT_LE_DEACTIVATING, -1);
264
265         status = _bt_core_get_status();
266         BT_DBG("status : %d", status);
267
268         if (status == BT_DEACTIVATED) {
269                 __bt_core_set_le_status(BT_LE_DEACTIVATING);
270
271                 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
272                         BT_ERR("running script failed");
273                         __bt_core_set_le_status(BT_LE_ACTIVATED);
274                         return -1;
275                 }
276         }
277
278         __bt_core_set_le_status(BT_LE_DEACTIVATED);
279 #else
280         _bt_power_adapter(FALSE);
281 #endif
282
283         BT_DBG("-");
284         return 0;
285 }
286
287 int _bt_core_service_request_adapter(int service_function)
288 {
289         int ret = -1;
290
291         GArray *in_param1 = NULL;
292         GArray *in_param2 = NULL;
293         GArray *in_param3 = NULL;
294         GArray *in_param4 = NULL;
295         GArray *out_param = NULL;
296
297         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
298
299         ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
300                         in_param1, in_param2, in_param3, in_param4, &out_param);
301         if (ret < 0)
302                 BT_ERR("_bt_core_service_request_adapter() failed");
303
304         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
305
306         return ret;
307 }
308
309 static void __bt_core_update_status(void)
310 {
311         int bt_status = VCONFKEY_BT_STATUS_OFF;
312         int bt_le_status = 0;
313
314         if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
315                 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
316 #ifdef ENABLE_TIZEN_2_4
317         if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
318                 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
319 #endif
320
321         BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
322
323         if (bt_status == VCONFKEY_BT_STATUS_OFF)
324                 __bt_core_set_status(BT_DEACTIVATED);
325         else
326                 __bt_core_set_status(BT_ACTIVATED);
327
328         if (bt_le_status == 0)
329                 __bt_core_set_le_status(BT_LE_DEACTIVATED);
330         else
331                 __bt_core_set_le_status(BT_LE_ACTIVATED);
332 }
333
334 gboolean _bt_core_enable_adapter(void)
335 {
336         int ret;
337
338         _bt_set_flightmode_request(FALSE);
339         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
340                 BT_ERR("Set vconf failed");
341
342         ret = _bt_enable_adapter();
343         if (ret < 0)
344                 return FALSE;
345         else
346                 return TRUE;
347 }
348
349 gboolean _bt_core_disable_adapter(void)
350 {
351         int ret;
352
353         _bt_set_flightmode_request(FALSE);
354         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
355                 BT_ERR("Set vconf failed");
356
357         ret = _bt_disable_adapter();
358         if (ret < 0)
359                 return FALSE;
360         else
361                 return TRUE;
362 }
363
364 gboolean _bt_core_recover_adapter(void)
365 {
366         int ret;
367         int ret_le;
368
369         BT_INFO_C("Recover bt adapter");
370
371         _bt_set_flightmode_request(FALSE);
372         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
373                 BT_ERR("Set vconf failed");
374
375         is_recovery_mode = TRUE;
376
377         __bt_core_update_status();
378
379         if (_bt_core_get_status() == BT_ACTIVATED) {
380                 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
381                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
382         }
383         if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
384                 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
385                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
386         }
387
388         ret = _bt_disable_adapter();
389         if (ret < 0)
390                 BT_ERR("_bt_disable_adapter() failed");
391         ret_le = _bt_disable_adapter_le();
392         if (ret_le < 0)
393                 BT_ERR("_bt_disable_adapter_le() failed");
394
395         return TRUE;
396 }
397
398 gboolean _bt_core_enable_adapter_le(void)
399 {
400         int ret;
401
402         ret = _bt_enable_adapter_le();
403         if (ret < 0)
404                 return FALSE;
405         else
406                 return TRUE;
407 }
408
409 gboolean _bt_core_disable_adapter_le(void)
410 {
411         BT_DBG("+");
412
413         int ret;
414
415         ret = _bt_disable_adapter_le();
416         if (ret < 0)
417                 return FALSE;
418         else
419                 return TRUE;
420 }
421
422 gboolean __bt_core_reset_adapter(void)
423 {
424         /* Forcely terminate */
425         if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0) {
426                 BT_ERR("running script failed");
427         }
428         _bt_core_terminate();
429
430         return TRUE;
431 }
432
433 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
434 {
435         BT_DBG("+");
436
437         _bt_core_init_vconf_value();
438
439         return FALSE;
440 }
441
442 gboolean _bt_core_enable_core(void)
443 {
444         BT_DBG("+");
445
446         __bt_core_update_status();
447
448         g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
449
450         BT_DBG("-");
451         return TRUE;
452 }
453
454 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
455 {
456
457         char *cmd = NULL;
458         char *arg_list[3] = { NULL, NULL, NULL };
459
460         BT_DBG("Test item : %s", type);
461
462         if (g_strcmp0(type, "Enable_RF_Test") == 0) {
463                 cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
464                 arg_list[0] = "bt-edutm-on.sh";
465         } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
466                 cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
467                 arg_list[0] = "bt-edutm-off.sh";
468         } else if (g_strcmp0(type, "Slave_Mode") == 0) {
469                 cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
470                 arg_list[0] = "bt-mode-slave.sh";
471         } else if (g_strcmp0(type, "Master_Mode") == 0) {
472                 cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
473                 arg_list[0] = "bt-mode-master.sh";
474         } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
475                 cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
476                 arg_list[0] = "bt-set-ssp-debug-mode.sh";
477                 arg_list[1] = (char *)arg;
478         } else if (g_strcmp0(type, "RF_Channel") == 0) {
479                 cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
480                 arg_list[0] = "bt-enable-rf-channel.sh";
481                 arg_list[1] = (char *)arg;
482         } else {
483                 _bt_core_terminate();
484                 return FALSE;
485         }
486
487         BT_DBG("Run %s", cmd);
488         if (__execute_command(cmd, arg_list) < 0) {
489                 BT_ERR("running script failed");
490         }
491
492         _bt_core_terminate();
493         return TRUE;
494 }
495
496 static gboolean __bt_core_recovery_cb(gpointer data)
497 {
498         int ret = 0;
499         gboolean is_request_failed = FALSE;
500         static gboolean is_first_failure = TRUE;
501
502         BT_DBG("+");
503
504         if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
505                 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
506                 if (ret < 0)
507                         is_request_failed = TRUE;
508         }
509
510         if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
511                 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
512                 if (ret < 0)
513                         is_request_failed = TRUE;
514         }
515
516         if (is_request_failed == TRUE) {
517                 BT_ERR("Recovery is failed.");
518                 if (is_first_failure == TRUE) {
519                         g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
520                         is_first_failure = FALSE;
521                         return FALSE;
522                 } else {
523                         is_first_failure = TRUE;
524                         return FALSE;
525                 }
526         } else
527                 is_first_failure = TRUE;
528
529         if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
530                 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
531                 ret = _bt_enable_adapter();
532                 if (ret < 0)
533                         BT_ERR("_bt_enable_adapter() failed");
534         }
535         if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
536                 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
537                 ret = _bt_enable_adapter_le();
538                 if (ret < 0)
539                         BT_ERR("_bt_enable_adapter_le() failed");
540         }
541
542         is_recovery_mode = FALSE;
543
544         BT_DBG("-");
545
546         return FALSE;
547 }
548
549 static gboolean __bt_core_enable_timeout_cb(gpointer data)
550 {
551         bt_status_t adapter_status;
552         bt_le_status_t adapter_status_le;
553
554         BT_DBG("");
555
556         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
557                 BT_ERR("Set vconf failed");
558
559         adapter_status = _bt_core_get_status();
560         adapter_status_le = _bt_core_get_le_status();
561
562         if (adapter_status == BT_DEACTIVATED &&
563                         _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
564                 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
565                 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
566                 _bt_enable_adapter();
567         }
568
569         if (adapter_status_le == BT_LE_DEACTIVATED &&
570                         _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
571                 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
572                 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
573                 _bt_enable_adapter_le();
574         }
575
576         return FALSE;
577 }
578
579 static gboolean __bt_core_disable_timeout_cb(gpointer data)
580 {
581         bt_status_t adapter_status;
582         bt_le_status_t adapter_status_le;
583
584         BT_DBG("");
585
586         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
587                 BT_ERR("Set vconf failed");
588
589         adapter_status = _bt_core_get_status();
590         adapter_status_le = _bt_core_get_le_status();
591
592         if (adapter_status == BT_ACTIVATED) {
593                 int bt_status_before_mode = 0;
594
595                 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
596                         _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
597
598                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
599                 _bt_disable_adapter();
600         }
601
602         if (adapter_status_le == BT_LE_ACTIVATED) {
603                 int bt_le_status_before_mode = 0;
604
605 #ifdef ENABLE_TIZEN_2_4
606                 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
607                         _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
608 #endif
609
610                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
611                 _bt_disable_adapter_le();
612         }
613
614         return FALSE;
615 }
616 #if 0
617 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
618 {
619         int ret;
620         bundle *b = NULL;
621
622         b = bundle_create();
623
624         bundle_add_str(b, key, value);
625
626         ret = eventsystem_request_sending_system_event(event, b);
627
628         BT_DBG("request_sending_system_event result: %d", ret);
629
630         bundle_free(b);
631
632         return ret;
633 }
634 #endif
635 void _bt_core_adapter_added_cb(void)
636 {
637         bt_status_t status;
638         bt_le_status_t le_status;
639         gboolean flight_mode_status;
640
641         BT_DBG("");
642
643         status = _bt_core_get_status();
644         BT_DBG("status : %d", status);
645         le_status = _bt_core_get_le_status();
646         BT_DBG("le_status : %d", le_status);
647
648         if (status == BT_ACTIVATING)
649                 __bt_core_set_status(BT_ACTIVATED);
650         if (le_status == BT_LE_ACTIVATING)
651                 __bt_core_set_le_status(BT_LE_ACTIVATED);
652
653         flight_mode_status = _bt_core_is_flight_mode_enabled();
654
655         if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
656                 _bt_set_flightmode_request(FALSE);
657                 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
658                 return;
659         }
660         _bt_set_flightmode_request(FALSE);
661         _bt_core_terminate();
662 }
663
664 void _bt_core_adapter_removed_cb(void)
665 {
666         int flight_mode_value = 0;
667         int power_saving_mode = 0;
668         gboolean flight_mode_status;
669         static int timer_id = -1;
670
671         BT_DBG("");
672
673         __bt_core_set_status(BT_DEACTIVATED);
674         __bt_core_set_le_status(BT_LE_DEACTIVATED);
675         if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
676                 BT_ERR("Set vconf failed");
677 #ifdef ENABLE_TIZEN_2_4
678         if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
679                 BT_ERR("Set vconf failed");
680 #endif
681
682 #if 0
683         if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
684                                                 EVT_VAL_BT_OFF) != ES_R_OK)
685                 BT_ERR("Fail to set value");
686
687         if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
688                                                 EVT_VAL_BT_LE_OFF) != ES_R_OK)
689                 BT_ERR("Fail to set value");
690 #endif
691         if (is_recovery_mode == TRUE)
692         {
693                 if (timer_id < 0)
694                         timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
695                 return;
696         }
697
698         if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
699                 BT_ERR("Fail to get the flight_mode_deactivated value");
700
701         if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
702                 BT_ERR("Fail to get the ps_mode_deactivated value");
703
704         flight_mode_status = _bt_core_is_flight_mode_enabled();
705
706         if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
707                 _bt_set_flightmode_request(FALSE);
708                 if (timer_id < 0)
709                         timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
710                 return;
711         }
712         _bt_set_flightmode_request(FALSE);
713
714         if (flight_mode_value == 1 || power_saving_mode == 1){
715                 BT_DBG("Bt Core not terminated");
716                 return;
717         }
718
719         _bt_core_terminate();
720 }