0c4f2232c4118bda625f740daea6adfc7039fb83
[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         status = _bt_core_get_status();
148         if (status != BT_DEACTIVATED) {
149                 BT_ERR("Invalid state %d", status);
150                 return -1;
151         }
152
153         le_status = _bt_core_get_le_status();
154         if (le_status == BT_LE_ACTIVATED) {
155                 /* Turn on PSCAN, (ISCAN if needed) */
156                 /* Return with 0 for the Enabled response. */
157                 __bt_core_set_status(BT_ACTIVATED);
158                 BT_INFO("BR/EDR is enabled.");
159                 return 0;
160         }
161
162         __bt_core_set_status(BT_ACTIVATING);
163
164         ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
165         if (ret < 0) {
166                 BT_ERR("running script failed");
167                 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
168                 __bt_core_set_status(BT_DEACTIVATED);
169                 return -1;
170         }
171
172         return 0;
173 }
174
175 int _bt_disable_adapter(void)
176 {
177         bt_status_t status;
178         bt_le_status_t le_status;
179
180         BT_INFO_C("Disable adapter");
181
182         le_status = _bt_core_get_le_status();
183         BT_DBG("le_status : %d", le_status);
184         if (le_status == BT_LE_ACTIVATED) {
185                 /* Turn off PSCAN, (ISCAN if needed) */
186                 /* Return with 0 for the Disabled response. */
187                 __bt_core_set_status(BT_DEACTIVATED);
188                 BT_INFO("BR/EDR is disabled. now LE only mode");
189                 return 0;
190         }
191
192         status = _bt_core_get_status();
193         if (status == BT_ACTIVATING) {
194                 /* Forcely terminate */
195                 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
196                         BT_ERR("running script failed");
197                 }
198                 _bt_core_terminate();
199                 return 0;
200         } else if (status != BT_ACTIVATED) {
201                 BT_ERR("Invalid state %d", status);
202         }
203
204         __bt_core_set_status(BT_DEACTIVATING);
205
206         if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
207                 BT_ERR("running script failed");
208                 __bt_core_set_status( BT_ACTIVATED);
209                 return -1;
210         }
211
212         return 0;
213 }
214
215 int _bt_enable_adapter_le(void)
216 {
217         BT_DBG("");
218
219         int ret;
220         bt_status_t status;
221         bt_le_status_t le_status;
222         le_status = _bt_core_get_le_status();
223         retv_if(le_status != BT_LE_DEACTIVATED, -1);
224
225         status = _bt_core_get_status();
226         if (status == BT_DEACTIVATED) {
227                 __bt_core_set_le_status(BT_LE_ACTIVATING);
228                 BT_DBG("Activate BT");
229                 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
230                 if (ret < 0) {
231                         BT_ERR("running script failed");
232                         ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
233                         __bt_core_set_status(BT_DEACTIVATED);
234                         __bt_core_set_le_status(BT_LE_DEACTIVATED);
235                         return -1;
236                 }
237         } else {
238                 __bt_core_set_le_status(BT_LE_ACTIVATED);
239         }
240         return 0;
241 }
242
243 int _bt_disable_adapter_le(void)
244 {
245         BT_DBG("+");
246
247         bt_status_t status;
248         bt_le_status_t le_status;
249
250         le_status = _bt_core_get_le_status();
251         retv_if(le_status == BT_LE_DEACTIVATED, 0);
252         retv_if(le_status == BT_LE_DEACTIVATING, -1);
253
254         status = _bt_core_get_status();
255         BT_DBG("status : %d", status);
256
257         if (status == BT_DEACTIVATED) {
258                 __bt_core_set_le_status(BT_LE_DEACTIVATING);
259
260                 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
261                         BT_ERR("running script failed");
262                         __bt_core_set_le_status(BT_LE_ACTIVATED);
263                         return -1;
264                 }
265         }
266
267         __bt_core_set_le_status(BT_LE_DEACTIVATED);
268
269         BT_DBG("-");
270         return 0;
271 }
272
273 int _bt_core_service_request_adapter(int service_function)
274 {
275         int ret = -1;
276
277         GArray *in_param1 = NULL;
278         GArray *in_param2 = NULL;
279         GArray *in_param3 = NULL;
280         GArray *in_param4 = NULL;
281         GArray *out_param = NULL;
282
283         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
284
285         ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
286                         in_param1, in_param2, in_param3, in_param4, &out_param);
287         if (ret < 0)
288                 BT_ERR("_bt_core_service_request_adapter() failed");
289
290         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
291
292         return ret;
293 }
294
295 static void __bt_core_update_status(void)
296 {
297         int bt_status = VCONFKEY_BT_STATUS_OFF;
298         int bt_le_status = 0;
299
300         if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
301                 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
302 #ifdef ENABLE_TIZEN_2_4
303         if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
304                 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
305 #endif
306
307         BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
308
309         if (bt_status == VCONFKEY_BT_STATUS_OFF)
310                 __bt_core_set_status(BT_DEACTIVATED);
311         else
312                 __bt_core_set_status(BT_ACTIVATED);
313
314         if (bt_le_status == 0)
315                 __bt_core_set_le_status(BT_LE_DEACTIVATED);
316         else
317                 __bt_core_set_le_status(BT_LE_ACTIVATED);
318 }
319
320 gboolean _bt_core_enable_adapter(void)
321 {
322         int ret;
323
324         _bt_set_flightmode_request(FALSE);
325         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
326                 BT_ERR("Set vconf failed");
327
328         ret = _bt_enable_adapter();
329         if (ret < 0)
330                 return FALSE;
331         else
332                 return TRUE;
333 }
334
335 gboolean _bt_core_disable_adapter(void)
336 {
337         int ret;
338
339         _bt_set_flightmode_request(FALSE);
340         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
341                 BT_ERR("Set vconf failed");
342
343         ret = _bt_disable_adapter();
344         if (ret < 0)
345                 return FALSE;
346         else
347                 return TRUE;
348 }
349
350 gboolean _bt_core_recover_adapter(void)
351 {
352         int ret;
353         int ret_le;
354
355         BT_INFO_C("Recover bt adapter");
356
357         _bt_set_flightmode_request(FALSE);
358         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
359                 BT_ERR("Set vconf failed");
360
361         is_recovery_mode = TRUE;
362
363         __bt_core_update_status();
364
365         if (_bt_core_get_status() == BT_ACTIVATED) {
366                 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
367                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
368         }
369         if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
370                 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
371                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
372         }
373
374         ret = _bt_disable_adapter();
375         if (ret < 0)
376                 BT_ERR("_bt_disable_adapter() failed");
377         ret_le = _bt_disable_adapter_le();
378         if (ret_le < 0)
379                 BT_ERR("_bt_disable_adapter_le() failed");
380
381         return TRUE;
382 }
383
384 gboolean _bt_core_enable_adapter_le(void)
385 {
386         int ret;
387
388         ret = _bt_enable_adapter_le();
389         if (ret < 0)
390                 return FALSE;
391         else
392                 return TRUE;
393 }
394
395 gboolean _bt_core_disable_adapter_le(void)
396 {
397         BT_DBG("+");
398
399         int ret;
400
401         ret = _bt_disable_adapter_le();
402         if (ret < 0)
403                 return FALSE;
404         else
405                 return TRUE;
406 }
407
408 gboolean __bt_core_reset_adapter(void)
409 {
410         /* Forcely terminate */
411         if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0) {
412                 BT_ERR("running script failed");
413         }
414         _bt_core_terminate();
415
416         return TRUE;
417 }
418
419 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
420 {
421         BT_DBG("+");
422
423         _bt_core_init_vconf_value();
424
425         return FALSE;
426 }
427
428 gboolean _bt_core_enable_core(void)
429 {
430         BT_DBG("+");
431
432         __bt_core_update_status();
433
434         g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
435
436         BT_DBG("-");
437         return TRUE;
438 }
439
440 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
441 {
442
443         char *cmd = NULL;
444         char *arg_list[3] = { NULL, NULL, NULL };
445
446         BT_DBG("Test item : %s", type);
447
448         if (g_strcmp0(type, "Enable_RF_Test") == 0) {
449                 cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
450                 arg_list[0] = "bt-edutm-on.sh";
451         } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
452                 cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
453                 arg_list[0] = "bt-edutm-off.sh";
454         } else if (g_strcmp0(type, "Slave_Mode") == 0) {
455                 cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
456                 arg_list[0] = "bt-mode-slave.sh";
457         } else if (g_strcmp0(type, "Master_Mode") == 0) {
458                 cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
459                 arg_list[0] = "bt-mode-master.sh";
460         } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
461                 cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
462                 arg_list[0] = "bt-set-ssp-debug-mode.sh";
463                 arg_list[1] = (char *)arg;
464         } else if (g_strcmp0(type, "RF_Channel") == 0) {
465                 cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
466                 arg_list[0] = "bt-enable-rf-channel.sh";
467                 arg_list[1] = (char *)arg;
468         } else {
469                 _bt_core_terminate();
470                 return FALSE;
471         }
472
473         BT_DBG("Run %s", cmd);
474         if (__execute_command(cmd, arg_list) < 0) {
475                 BT_ERR("running script failed");
476         }
477
478         _bt_core_terminate();
479         return TRUE;
480 }
481
482 static gboolean __bt_core_recovery_cb(gpointer data)
483 {
484         int ret = 0;
485         gboolean is_request_failed = FALSE;
486         static gboolean is_first_failure = TRUE;
487
488         BT_DBG("+");
489
490         if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
491                 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
492                 if (ret < 0)
493                         is_request_failed = TRUE;
494         }
495
496         if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
497                 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
498                 if (ret < 0)
499                         is_request_failed = TRUE;
500         }
501
502         if (is_request_failed == TRUE) {
503                 BT_ERR("Recovery is failed.");
504                 if (is_first_failure == TRUE) {
505                         g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
506                         is_first_failure = FALSE;
507                         return FALSE;
508                 } else {
509                         is_first_failure = TRUE;
510                         return FALSE;
511                 }
512         } else
513                 is_first_failure = TRUE;
514
515         if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
516                 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
517                 ret = _bt_enable_adapter();
518                 if (ret < 0)
519                         BT_ERR("_bt_enable_adapter() failed");
520         }
521         if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
522                 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
523                 ret = _bt_enable_adapter_le();
524                 if (ret < 0)
525                         BT_ERR("_bt_enable_adapter_le() failed");
526         }
527
528         is_recovery_mode = FALSE;
529
530         BT_DBG("-");
531
532         return FALSE;
533 }
534
535 static gboolean __bt_core_enable_timeout_cb(gpointer data)
536 {
537         bt_status_t adapter_status;
538         bt_le_status_t adapter_status_le;
539
540         BT_DBG("");
541
542         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
543                 BT_ERR("Set vconf failed");
544
545         adapter_status = _bt_core_get_status();
546         adapter_status_le = _bt_core_get_le_status();
547
548         if (adapter_status == BT_DEACTIVATED &&
549                         _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
550                 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
551                 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
552                 _bt_enable_adapter();
553         }
554
555         if (adapter_status_le == BT_LE_DEACTIVATED &&
556                         _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
557                 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
558                 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
559                 _bt_enable_adapter_le();
560         }
561
562         return FALSE;
563 }
564
565 static gboolean __bt_core_disable_timeout_cb(gpointer data)
566 {
567         bt_status_t adapter_status;
568         bt_le_status_t adapter_status_le;
569
570         BT_DBG("");
571
572         if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
573                 BT_ERR("Set vconf failed");
574
575         adapter_status = _bt_core_get_status();
576         adapter_status_le = _bt_core_get_le_status();
577
578         if (adapter_status == BT_ACTIVATED) {
579                 int bt_status_before_mode = 0;
580
581                 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
582                         _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
583
584                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
585                 _bt_disable_adapter();
586         }
587
588         if (adapter_status_le == BT_LE_ACTIVATED) {
589                 int bt_le_status_before_mode = 0;
590
591 #ifdef ENABLE_TIZEN_2_4
592                 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
593                         _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
594 #endif
595
596                 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
597                 _bt_disable_adapter_le();
598         }
599
600         return FALSE;
601 }
602 #if 0
603 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
604 {
605         int ret;
606         bundle *b = NULL;
607
608         b = bundle_create();
609
610         bundle_add_str(b, key, value);
611
612         ret = eventsystem_request_sending_system_event(event, b);
613
614         BT_DBG("request_sending_system_event result: %d", ret);
615
616         bundle_free(b);
617
618         return ret;
619 }
620 #endif
621 void _bt_core_adapter_added_cb(void)
622 {
623         bt_status_t status;
624         bt_le_status_t le_status;
625         gboolean flight_mode_status;
626
627         BT_DBG("");
628
629         status = _bt_core_get_status();
630         BT_DBG("status : %d", status);
631         le_status = _bt_core_get_le_status();
632         BT_DBG("le_status : %d", le_status);
633
634         if (status == BT_ACTIVATING)
635                 __bt_core_set_status(BT_ACTIVATED);
636         if (le_status == BT_LE_ACTIVATING)
637                 __bt_core_set_le_status(BT_LE_ACTIVATED);
638
639         flight_mode_status = _bt_core_is_flight_mode_enabled();
640
641         if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
642                 _bt_set_flightmode_request(FALSE);
643                 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
644                 return;
645         }
646         _bt_set_flightmode_request(FALSE);
647         _bt_core_terminate();
648 }
649
650 void _bt_core_adapter_removed_cb(void)
651 {
652         int flight_mode_value = 0;
653         int power_saving_mode = 0;
654         gboolean flight_mode_status;
655         static int timer_id = -1;
656
657         BT_DBG("");
658
659         __bt_core_set_status(BT_DEACTIVATED);
660         __bt_core_set_le_status(BT_LE_DEACTIVATED);
661         if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
662                 BT_ERR("Set vconf failed");
663 #ifdef ENABLE_TIZEN_2_4
664         if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
665                 BT_ERR("Set vconf failed");
666 #endif
667
668 #if 0
669         if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
670                                                 EVT_VAL_BT_OFF) != ES_R_OK)
671                 BT_ERR("Fail to set value");
672
673         if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
674                                                 EVT_VAL_BT_LE_OFF) != ES_R_OK)
675                 BT_ERR("Fail to set value");
676 #endif
677         if (is_recovery_mode == TRUE)
678         {
679                 if (timer_id < 0)
680                         timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
681                 return;
682         }
683
684         if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
685                 BT_ERR("Fail to get the flight_mode_deactivated value");
686
687         if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
688                 BT_ERR("Fail to get the ps_mode_deactivated value");
689
690         flight_mode_status = _bt_core_is_flight_mode_enabled();
691
692         if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
693                 _bt_set_flightmode_request(FALSE);
694                 if (timer_id < 0)
695                         timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
696                 return;
697         }
698         _bt_set_flightmode_request(FALSE);
699
700         if (flight_mode_value == 1 || power_saving_mode == 1){
701                 BT_DBG("Bt Core not terminated");
702                 return;
703         }
704
705         _bt_core_terminate();
706 }