OSDN Git Service

am f29a2fb..e07ad10 from mirror-m-wireless-internal-release
[android-x86/system-bt.git] / btif / src / btif_core.c
1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 The Android Open Source Project
4  *  Copyright (C) 2009-2012 Broadcom Corporation
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 /************************************************************************************
21  *
22  *  Filename:      btif_core.c
23  *
24  *  Description:   Contains core functionality related to interfacing between
25  *                 Bluetooth HAL and BTE core stack.
26  *
27  ***********************************************************************************/
28
29 #include <ctype.h>
30 #include <cutils/properties.h>
31 #include <dirent.h>
32 #include <fcntl.h>
33 #include <hardware/bluetooth.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38
39 #define LOG_TAG "bt_btif_core"
40 #include "btcore/include/bdaddr.h"
41
42 #include "bdaddr.h"
43 #include "bt_utils.h"
44 #include "bta_api.h"
45 #include "bte.h"
46 #include "btif_api.h"
47 #include "btif_av.h"
48 #include "btif_config.h"
49 #include "btif_pan.h"
50 #include "btif_profile_queue.h"
51 #include "btif_config.h"
52 #include "btif_sock.h"
53 #include "btif_storage.h"
54 #include "btif_util.h"
55 #include "btu.h"
56 #include "device/include/controller.h"
57 #include "osi/include/fixed_queue.h"
58 #include "osi/include/future.h"
59 #include "gki.h"
60 #include "osi/include/osi.h"
61 #include "osi/include/log.h"
62 #include "stack_manager.h"
63 #include "osi/include/thread.h"
64
65 /************************************************************************************
66 **  Constants & Macros
67 ************************************************************************************/
68
69 #ifndef BTE_DID_CONF_FILE
70 #define BTE_DID_CONF_FILE "/etc/bluetooth/bt_did.conf"
71 #endif
72
73 /************************************************************************************
74 **  Local type definitions
75 ************************************************************************************/
76
77 /* These type definitions are used when passing data from the HAL to BTIF context
78 *  in the downstream path for the adapter and remote_device property APIs */
79
80 typedef struct {
81   bt_bdaddr_t bd_addr;
82   bt_property_type_t type;
83 } btif_storage_read_t;
84
85 typedef struct {
86   bt_bdaddr_t bd_addr;
87   bt_property_t prop;
88 } btif_storage_write_t;
89
90 typedef union {
91   btif_storage_read_t read_req;
92   btif_storage_write_t write_req;
93 } btif_storage_req_t;
94
95 typedef enum {
96     BTIF_CORE_STATE_DISABLED = 0,
97     BTIF_CORE_STATE_ENABLING,
98     BTIF_CORE_STATE_ENABLED,
99     BTIF_CORE_STATE_DISABLING
100 } btif_core_state_t;
101
102 /************************************************************************************
103 **  Static variables
104 ************************************************************************************/
105
106 bt_bdaddr_t btif_local_bd_addr;
107
108 static tBTA_SERVICE_MASK btif_enabled_services = 0;
109
110 /*
111 * This variable should be set to 1, if the Bluedroid+BTIF libraries are to
112 * function in DUT mode.
113 *
114 * To set this, the btif_init_bluetooth needs to be called with argument as 1
115 */
116 static UINT8 btif_dut_mode = 0;
117
118 static thread_t *bt_jni_workqueue_thread;
119 static const char *BT_JNI_WORKQUEUE_NAME = "bt_jni_workqueue";
120
121 /************************************************************************************
122 **  Static functions
123 ************************************************************************************/
124 static void btif_jni_associate(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
125 static void btif_jni_disassociate(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
126
127 /* sends message to btif task */
128 static void btif_sendmsg(void *p_msg);
129
130 /************************************************************************************
131 **  Externs
132 ************************************************************************************/
133 extern fixed_queue_t *btu_hci_msg_queue;
134
135 extern void bte_load_did_conf(const char *p_path);
136
137 /** TODO: Move these to _common.h */
138 void bte_main_boot_entry(void);
139 void bte_main_disable(void);
140 void bte_main_shutdown(void);
141 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
142 void bte_main_enable_lpm(BOOLEAN enable);
143 #endif
144 void bte_main_postload_cfg(void);
145 void btif_dm_execute_service_request(UINT16 event, char *p_param);
146 #ifdef BTIF_DM_OOB_TEST
147 void btif_dm_load_local_oob(void);
148 #endif
149 void bte_main_config_hci_logging(BOOLEAN enable, BOOLEAN bt_disabled);
150
151 /*******************************************************************************
152 **
153 ** Function         btif_context_switched
154 **
155 ** Description      Callback used to execute transferred context callback
156 **
157 **                  p_msg : message to be executed in btif context
158 **
159 ** Returns          void
160 **
161 *******************************************************************************/
162
163 static void btif_context_switched(void *p_msg)
164 {
165
166     BTIF_TRACE_VERBOSE("btif_context_switched");
167
168     tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
169
170     /* each callback knows how to parse the data */
171     if (p->p_cb)
172         p->p_cb(p->event, p->p_param);
173 }
174
175
176 /*******************************************************************************
177 **
178 ** Function         btif_transfer_context
179 **
180 ** Description      This function switches context to btif task
181 **
182 **                  p_cback   : callback used to process message in btif context
183 **                  event     : event id of message
184 **                  p_params  : parameter area passed to callback (copied)
185 **                  param_len : length of parameter area
186 **                  p_copy_cback : If set this function will be invoked for deep copy
187 **
188 ** Returns          void
189 **
190 *******************************************************************************/
191
192 bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
193 {
194     tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
195
196     BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
197
198     /* allocate and send message that will be executed in btif context */
199     if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
200     {
201         p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
202         p_msg->p_cb = p_cback;
203
204         p_msg->event = event;                         /* callback event */
205
206         /* check if caller has provided a copy callback to do the deep copy */
207         if (p_copy_cback)
208         {
209             p_copy_cback(event, p_msg->p_param, p_params);
210         }
211         else if (p_params)
212         {
213             memcpy(p_msg->p_param, p_params, param_len);  /* callback parameter data */
214         }
215
216         btif_sendmsg(p_msg);
217         return BT_STATUS_SUCCESS;
218     }
219     else
220     {
221         /* let caller deal with a failed allocation */
222         return BT_STATUS_NOMEM;
223     }
224 }
225
226 /*******************************************************************************
227 **
228 ** Function         btif_is_dut_mode
229 **
230 ** Description      checks if BTIF is currently in DUT mode
231 **
232 ** Returns          1 if test mode, otherwize 0
233 **
234 *******************************************************************************/
235
236 UINT8 btif_is_dut_mode(void)
237 {
238     return (btif_dut_mode == 1);
239 }
240
241 /*******************************************************************************
242 **
243 ** Function         btif_is_enabled
244 **
245 ** Description      checks if main adapter is fully enabled
246 **
247 ** Returns          1 if fully enabled, otherwize 0
248 **
249 *******************************************************************************/
250
251 int btif_is_enabled(void)
252 {
253     return ((!btif_is_dut_mode()) && (stack_manager_get_interface()->get_stack_is_running()));
254 }
255
256 void btif_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param) {
257   BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
258 #if (BLE_INCLUDED == TRUE)
259   btif_dm_load_ble_local_keys();
260 #endif
261   BTA_EnableBluetooth(bte_dm_evt);
262 }
263
264 void btif_init_fail(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param) {
265   BTIF_TRACE_DEBUG("btif_task: hardware init failed");
266   bte_main_disable();
267   btif_queue_release();
268   bte_main_shutdown();
269   btif_dut_mode = 0;
270
271   future_ready(stack_manager_get_hack_future(), FUTURE_FAIL);
272 }
273
274 /*******************************************************************************
275 **
276 ** Function         btif_task
277 **
278 ** Description      BTIF task handler managing all messages being passed
279 **                  Bluetooth HAL and BTA.
280 **
281 ** Returns          void
282 **
283 *******************************************************************************/
284 static void bt_jni_msg_ready(void *context) {
285   BT_HDR *p_msg = (BT_HDR *)context;
286
287   BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
288
289   switch (p_msg->event) {
290     case BT_EVT_CONTEXT_SWITCH_EVT:
291       btif_context_switched(p_msg);
292       break;
293     default:
294       BTIF_TRACE_ERROR("unhandled btif event (%d)", p_msg->event & BT_EVT_MASK);
295       break;
296   }
297   GKI_freebuf(p_msg);
298 }
299
300 /*******************************************************************************
301 **
302 ** Function         btif_sendmsg
303 **
304 ** Description      Sends msg to BTIF task
305 **
306 ** Returns          void
307 **
308 *******************************************************************************/
309
310 void btif_sendmsg(void *p_msg)
311 {
312     thread_post(bt_jni_workqueue_thread, bt_jni_msg_ready, p_msg);
313 }
314
315 void btif_thread_post(thread_fn func, void *context) {
316     thread_post(bt_jni_workqueue_thread, func, context);
317 }
318
319 static void btif_fetch_local_bdaddr(bt_bdaddr_t *local_addr)
320 {
321     char val[256];
322     uint8_t valid_bda = FALSE;
323     int val_size = 0;
324     const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0};
325
326     /* Get local bdaddr storage path from property */
327     if (property_get(PROPERTY_BT_BDADDR_PATH, val, NULL))
328     {
329         int addr_fd;
330
331         BTIF_TRACE_DEBUG("local bdaddr is stored in %s", val);
332
333         if ((addr_fd = open(val, O_RDONLY)) != -1)
334         {
335             memset(val, 0, sizeof(val));
336             read(addr_fd, val, FACTORY_BT_BDADDR_STORAGE_LEN);
337             string_to_bdaddr(val, local_addr);
338             /* If this is not a reserved/special bda, then use it */
339             if (memcmp(local_addr->address, null_bdaddr, BD_ADDR_LEN) != 0)
340             {
341                 valid_bda = TRUE;
342                 BTIF_TRACE_DEBUG("Got Factory BDA %02X:%02X:%02X:%02X:%02X:%02X",
343                     local_addr->address[0], local_addr->address[1], local_addr->address[2],
344                     local_addr->address[3], local_addr->address[4], local_addr->address[5]);
345             }
346
347             close(addr_fd);
348         }
349     }
350
351     if(!valid_bda)
352     {
353         val_size = sizeof(val);
354         if(btif_config_get_str("Adapter", "Address", val, &val_size))
355         {
356             string_to_bdaddr(val, local_addr);
357             BTIF_TRACE_DEBUG("local bdaddr from bt_config.xml is  %s", val);
358             return;
359         }
360      }
361
362     /* No factory BDADDR found. Look for previously generated random BDA */
363     if ((!valid_bda) && \
364         (property_get(PERSIST_BDADDR_PROPERTY, val, NULL)))
365     {
366         string_to_bdaddr(val, local_addr);
367         valid_bda = TRUE;
368         BTIF_TRACE_DEBUG("Got prior random BDA %02X:%02X:%02X:%02X:%02X:%02X",
369             local_addr->address[0], local_addr->address[1], local_addr->address[2],
370             local_addr->address[3], local_addr->address[4], local_addr->address[5]);
371     }
372
373     /* Generate new BDA if necessary */
374     if (!valid_bda)
375     {
376         bdstr_t bdstr;
377         /* Seed the random number generator */
378         srand((unsigned int) (time(0)));
379
380         /* No autogen BDA. Generate one now. */
381         local_addr->address[0] = 0x22;
382         local_addr->address[1] = 0x22;
383         local_addr->address[2] = (uint8_t) ((rand() >> 8) & 0xFF);
384         local_addr->address[3] = (uint8_t) ((rand() >> 8) & 0xFF);
385         local_addr->address[4] = (uint8_t) ((rand() >> 8) & 0xFF);
386         local_addr->address[5] = (uint8_t) ((rand() >> 8) & 0xFF);
387
388         /* Convert to ascii, and store as a persistent property */
389         bdaddr_to_string(local_addr, bdstr, sizeof(bdstr));
390
391         BTIF_TRACE_DEBUG("No preset BDA. Generating BDA: %s for prop %s",
392              (char*)bdstr, PERSIST_BDADDR_PROPERTY);
393
394         if (property_set(PERSIST_BDADDR_PROPERTY, (char*)bdstr) < 0)
395             BTIF_TRACE_ERROR("Failed to set random BDA in prop %s",PERSIST_BDADDR_PROPERTY);
396     }
397
398     //save the bd address to config file
399     bdstr_t bdstr;
400     bdaddr_to_string(local_addr, bdstr, sizeof(bdstr));
401     val_size = sizeof(val);
402     if (btif_config_get_str("Adapter", "Address", val, &val_size))
403     {
404         if (strcmp(bdstr, val) ==0)
405         {
406             // BDA is already present in the config file.
407             return;
408         }
409     }
410     btif_config_set_str("Adapter", "Address", bdstr);
411 }
412
413 /*******************************************************************************
414 **
415 ** Function         btif_init_bluetooth
416 **
417 ** Description      Creates BTIF task and prepares BT scheduler for startup
418 **
419 ** Returns          bt_status_t
420 **
421 *******************************************************************************/
422 bt_status_t btif_init_bluetooth() {
423   bte_main_boot_entry();
424
425   /* As part of the init, fetch the local BD ADDR */
426   memset(&btif_local_bd_addr, 0, sizeof(bt_bdaddr_t));
427   btif_fetch_local_bdaddr(&btif_local_bd_addr);
428
429   bt_jni_workqueue_thread = thread_new(BT_JNI_WORKQUEUE_NAME);
430   if (bt_jni_workqueue_thread == NULL) {
431     LOG_ERROR("%s Unable to create thread %s", __func__, BT_JNI_WORKQUEUE_NAME);
432     goto error_exit;
433   }
434
435   // Associate this workqueue thread with jni.
436   btif_transfer_context(btif_jni_associate, 0, NULL, 0, NULL);
437
438   return BT_STATUS_SUCCESS;
439
440 error_exit:;
441      thread_free(bt_jni_workqueue_thread);
442
443      bt_jni_workqueue_thread = NULL;
444
445      return BT_STATUS_FAIL;
446 }
447
448 /*******************************************************************************
449 **
450 ** Function         btif_enable_bluetooth_evt
451 **
452 ** Description      Event indicating bluetooth enable is completed
453 **                  Notifies HAL user with updated adapter state
454 **
455 ** Returns          void
456 **
457 *******************************************************************************/
458
459 void btif_enable_bluetooth_evt(tBTA_STATUS status)
460 {
461     const controller_t *controller = controller_get_interface();
462     bdstr_t bdstr;
463     bdaddr_to_string(controller->get_address(), bdstr, sizeof(bdstr));
464
465     BTIF_TRACE_DEBUG("%s: status %d, local bd [%s]", __FUNCTION__, status, bdstr);
466
467     if (bdcmp(btif_local_bd_addr.address, controller->get_address()->address))
468     {
469         // TODO(zachoverflow): this whole code path seems like a bad time waiting to happen
470         // We open the vendor library using the old address.
471         bdstr_t old_address;
472         bt_property_t prop;
473
474         bdaddr_to_string(&btif_local_bd_addr, old_address, sizeof(old_address));
475
476         /**
477          * The Controller's BDADDR does not match to the BTIF's initial BDADDR!
478          * This could be because the factory BDADDR was stored separately in
479          * the Controller's non-volatile memory rather than in device's file
480          * system.
481          **/
482         BTIF_TRACE_WARNING("***********************************************");
483         BTIF_TRACE_WARNING("BTIF init BDA was %s", old_address);
484         BTIF_TRACE_WARNING("Controller BDA is %s", bdstr);
485         BTIF_TRACE_WARNING("***********************************************");
486
487         btif_local_bd_addr = *controller->get_address();
488
489         //save the bd address to config file
490         btif_config_set_str("Adapter", "Address", bdstr);
491         btif_config_save();
492
493         //fire HAL callback for property change
494         prop.type = BT_PROPERTY_BDADDR;
495         prop.val = (void*)&btif_local_bd_addr;
496         prop.len = sizeof(bt_bdaddr_t);
497         HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
498     }
499
500     bte_main_postload_cfg();
501 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
502     bte_main_enable_lpm(TRUE);
503 #endif
504     /* add passing up bd address as well ? */
505
506     /* callback to HAL */
507     if (status == BTA_SUCCESS)
508     {
509         /* initialize a2dp service */
510         btif_av_init();
511
512         /* init rfcomm & l2cap api */
513         btif_sock_init();
514
515         /* init pan */
516         btif_pan_init();
517
518         /* load did configuration */
519         bte_load_did_conf(BTE_DID_CONF_FILE);
520
521 #ifdef BTIF_DM_OOB_TEST
522         btif_dm_load_local_oob();
523 #endif
524
525         future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
526     }
527     else
528     {
529         /* cleanup rfcomm & l2cap api */
530         btif_sock_cleanup();
531
532         btif_pan_cleanup();
533
534         future_ready(stack_manager_get_hack_future(), FUTURE_FAIL);
535     }
536 }
537
538 /*******************************************************************************
539 **
540 ** Function         btif_disable_bluetooth
541 **
542 ** Description      Inititates shutdown of Bluetooth system.
543 **                  Any active links will be dropped and device entering
544 **                  non connectable/discoverable mode
545 **
546 ** Returns          void
547 **
548 *******************************************************************************/
549 bt_status_t btif_disable_bluetooth(void)
550 {
551     BTIF_TRACE_DEBUG("BTIF DISABLE BLUETOOTH");
552
553     btif_dm_on_disable();
554     /* cleanup rfcomm & l2cap api */
555     btif_sock_cleanup();
556     btif_pan_cleanup();
557     BTA_DisableBluetooth();
558
559     return BT_STATUS_SUCCESS;
560 }
561
562 /*******************************************************************************
563 **
564 ** Function         btif_disable_bluetooth_evt
565 **
566 ** Description      Event notifying BT disable is now complete.
567 **                  Terminates main stack tasks and notifies HAL
568 **                  user with updated BT state.
569 **
570 ** Returns          void
571 **
572 *******************************************************************************/
573
574 void btif_disable_bluetooth_evt(void)
575 {
576     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
577
578 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
579     bte_main_enable_lpm(FALSE);
580 #endif
581
582 #if (BLE_INCLUDED == TRUE)
583      BTA_VendorCleanup();
584 #endif
585
586      bte_main_disable();
587
588     /* callback to HAL */
589     future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
590 }
591
592 /*******************************************************************************
593 **
594 ** Function         btif_shutdown_bluetooth
595 **
596 ** Description      Finalizes BT scheduler shutdown and terminates BTIF
597 **                  task.
598 **
599 ** Returns          void
600 **
601 *******************************************************************************/
602
603 bt_status_t btif_shutdown_bluetooth(void)
604 {
605     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
606
607     btif_transfer_context(btif_jni_disassociate, 0, NULL, 0, NULL);
608
609     btif_queue_release();
610
611     thread_free(bt_jni_workqueue_thread);
612     bt_jni_workqueue_thread = NULL;
613
614     bte_main_shutdown();
615
616     btif_dut_mode = 0;
617
618     BTIF_TRACE_DEBUG("%s done", __FUNCTION__);
619
620     return BT_STATUS_SUCCESS;
621 }
622
623 /*******************************************************************************
624 **
625 ** Function         btif_dut_mode_cback
626 **
627 ** Description     Callback invoked on completion of vendor specific test mode command
628 **
629 ** Returns          None
630 **
631 *******************************************************************************/
632 static void btif_dut_mode_cback( tBTM_VSC_CMPL *p )
633 {
634     UNUSED(p);
635     /* For now nothing to be done. */
636 }
637
638 /*******************************************************************************
639 **
640 ** Function         btif_dut_mode_configure
641 **
642 ** Description      Configure Test Mode - 'enable' to 1 puts the device in test mode and 0 exits
643 **                       test mode
644 **
645 ** Returns          BT_STATUS_SUCCESS on success
646 **
647 *******************************************************************************/
648 bt_status_t btif_dut_mode_configure(uint8_t enable)
649 {
650     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
651
652     if (!stack_manager_get_interface()->get_stack_is_running()) {
653         BTIF_TRACE_ERROR("btif_dut_mode_configure : Bluetooth not enabled");
654         return BT_STATUS_NOT_READY;
655     }
656
657     btif_dut_mode = enable;
658     if (enable == 1) {
659         BTA_EnableTestMode();
660     } else {
661         BTA_DisableTestMode();
662     }
663     return BT_STATUS_SUCCESS;
664 }
665
666 /*******************************************************************************
667 **
668 ** Function         btif_dut_mode_send
669 **
670 ** Description     Sends a HCI Vendor specific command to the controller
671 **
672 ** Returns          BT_STATUS_SUCCESS on success
673 **
674 *******************************************************************************/
675 bt_status_t btif_dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
676 {
677     /* TODO: Check that opcode is a vendor command group */
678     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
679     if (!btif_is_dut_mode()) {
680          BTIF_TRACE_ERROR("Bluedroid HAL needs to be init with test_mode set to 1.");
681          return BT_STATUS_FAIL;
682     }
683     BTM_VendorSpecificCommand(opcode, len, buf, btif_dut_mode_cback);
684     return BT_STATUS_SUCCESS;
685 }
686
687 /*****************************************************************************
688 **
689 **   btif api adapter property functions
690 **
691 *****************************************************************************/
692
693 static bt_status_t btif_in_get_adapter_properties(void)
694 {
695     bt_property_t properties[6];
696     uint32_t num_props;
697
698     bt_bdaddr_t addr;
699     bt_bdname_t name;
700     bt_scan_mode_t mode;
701     uint32_t disc_timeout;
702     bt_bdaddr_t bonded_devices[BTM_SEC_MAX_DEVICE_RECORDS];
703     bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
704     num_props = 0;
705
706     /* BD_ADDR */
707     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDADDR,
708                                sizeof(addr), &addr);
709     btif_storage_get_adapter_property(&properties[num_props]);
710     num_props++;
711
712     /* BD_NAME */
713     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDNAME,
714                                sizeof(name), &name);
715     btif_storage_get_adapter_property(&properties[num_props]);
716     num_props++;
717
718     /* SCAN_MODE */
719     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_ADAPTER_SCAN_MODE,
720                                sizeof(mode), &mode);
721     btif_storage_get_adapter_property(&properties[num_props]);
722     num_props++;
723
724     /* DISC_TIMEOUT */
725     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
726                                sizeof(disc_timeout), &disc_timeout);
727     btif_storage_get_adapter_property(&properties[num_props]);
728     num_props++;
729
730     /* BONDED_DEVICES */
731     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_ADAPTER_BONDED_DEVICES,
732                                sizeof(bonded_devices), bonded_devices);
733     btif_storage_get_adapter_property(&properties[num_props]);
734     num_props++;
735
736     /* LOCAL UUIDs */
737     BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_UUIDS,
738                                sizeof(local_uuids), local_uuids);
739     btif_storage_get_adapter_property(&properties[num_props]);
740     num_props++;
741
742     HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
743                      BT_STATUS_SUCCESS, num_props, properties);
744
745     return BT_STATUS_SUCCESS;
746 }
747
748 static bt_status_t btif_in_get_remote_device_properties(bt_bdaddr_t *bd_addr)
749 {
750     bt_property_t remote_properties[8];
751     uint32_t num_props = 0;
752
753     bt_bdname_t name, alias;
754     uint32_t cod, devtype;
755     bt_uuid_t remote_uuids[BT_MAX_NUM_UUIDS];
756
757     memset(remote_properties, 0, sizeof(remote_properties));
758     BTIF_STORAGE_FILL_PROPERTY(&remote_properties[num_props], BT_PROPERTY_BDNAME,
759                                sizeof(name), &name);
760     btif_storage_get_remote_device_property(bd_addr,
761                                             &remote_properties[num_props]);
762     num_props++;
763
764     BTIF_STORAGE_FILL_PROPERTY(&remote_properties[num_props], BT_PROPERTY_REMOTE_FRIENDLY_NAME,
765                                sizeof(alias), &alias);
766     btif_storage_get_remote_device_property(bd_addr,
767                                             &remote_properties[num_props]);
768     num_props++;
769
770     BTIF_STORAGE_FILL_PROPERTY(&remote_properties[num_props], BT_PROPERTY_CLASS_OF_DEVICE,
771                                sizeof(cod), &cod);
772     btif_storage_get_remote_device_property(bd_addr,
773                                             &remote_properties[num_props]);
774     num_props++;
775
776     BTIF_STORAGE_FILL_PROPERTY(&remote_properties[num_props], BT_PROPERTY_TYPE_OF_DEVICE,
777                                sizeof(devtype), &devtype);
778     btif_storage_get_remote_device_property(bd_addr,
779                                             &remote_properties[num_props]);
780     num_props++;
781
782     BTIF_STORAGE_FILL_PROPERTY(&remote_properties[num_props], BT_PROPERTY_UUIDS,
783                                sizeof(remote_uuids), remote_uuids);
784     btif_storage_get_remote_device_property(bd_addr,
785                                             &remote_properties[num_props]);
786     num_props++;
787
788     HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
789                      BT_STATUS_SUCCESS, bd_addr, num_props, remote_properties);
790
791     return BT_STATUS_SUCCESS;
792 }
793
794
795 /*******************************************************************************
796 **
797 ** Function         execute_storage_request
798 **
799 ** Description      Executes adapter storage request in BTIF context
800 **
801 ** Returns          bt_status_t
802 **
803 *******************************************************************************/
804
805 static void execute_storage_request(UINT16 event, char *p_param)
806 {
807     bt_status_t status = BT_STATUS_SUCCESS;
808
809     BTIF_TRACE_EVENT("execute storage request event : %d", event);
810
811     switch(event)
812     {
813         case BTIF_CORE_STORAGE_ADAPTER_WRITE:
814         {
815             btif_storage_req_t *p_req = (btif_storage_req_t*)p_param;
816             bt_property_t *p_prop = &(p_req->write_req.prop);
817             BTIF_TRACE_EVENT("type: %d, len %d, 0x%x", p_prop->type,
818                                p_prop->len, p_prop->val);
819
820             status = btif_storage_set_adapter_property(p_prop);
821             HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, p_prop);
822         } break;
823
824         case BTIF_CORE_STORAGE_ADAPTER_READ:
825         {
826             btif_storage_req_t *p_req = (btif_storage_req_t*)p_param;
827             char buf[512];
828             bt_property_t prop;
829             prop.type = p_req->read_req.type;
830             prop.val = (void*)buf;
831             prop.len = sizeof(buf);
832             if (prop.type == BT_PROPERTY_LOCAL_LE_FEATURES)
833             {
834                 #if (BLE_INCLUDED == TRUE)
835                 tBTM_BLE_VSC_CB cmn_vsc_cb;
836                 bt_local_le_features_t local_le_features;
837
838                 /* LE features are not stored in storage. Should be retrived from stack */
839                 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
840                 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
841
842                 prop.len = sizeof (bt_local_le_features_t);
843                 if (cmn_vsc_cb.filter_support == 1)
844                     local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
845                 else
846                     local_le_features.max_adv_filter_supported = 0;
847                 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
848                 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
849                 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
850                 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
851                 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
852                 local_le_features.version_supported = cmn_vsc_cb.version_supported;
853                 local_le_features.total_trackable_advertisers =
854                     cmn_vsc_cb.total_trackable_advertisers;
855                 memcpy(prop.val, &local_le_features, prop.len);
856                 #endif
857             }
858             else
859             {
860                 status = btif_storage_get_adapter_property(&prop);
861             }
862             HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 1, &prop);
863         } break;
864
865         case BTIF_CORE_STORAGE_ADAPTER_READ_ALL:
866         {
867             status = btif_in_get_adapter_properties();
868         } break;
869
870         case BTIF_CORE_STORAGE_NOTIFY_STATUS:
871         {
872             HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, 0, NULL);
873         } break;
874
875         default:
876             BTIF_TRACE_ERROR("%s invalid event id (%d)", __FUNCTION__, event);
877             break;
878     }
879 }
880
881 static void execute_storage_remote_request(UINT16 event, char *p_param)
882 {
883     bt_status_t status = BT_STATUS_FAIL;
884     bt_property_t prop;
885
886     BTIF_TRACE_EVENT("execute storage remote request event : %d", event);
887
888     switch (event)
889     {
890         case BTIF_CORE_STORAGE_REMOTE_READ:
891         {
892             char buf[1024];
893             btif_storage_req_t *p_req = (btif_storage_req_t*)p_param;
894             prop.type = p_req->read_req.type;
895             prop.val = (void*) buf;
896             prop.len = sizeof(buf);
897
898             status = btif_storage_get_remote_device_property(&(p_req->read_req.bd_addr),
899                                                              &prop);
900             HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
901                             status, &(p_req->read_req.bd_addr), 1, &prop);
902         }break;
903         case BTIF_CORE_STORAGE_REMOTE_WRITE:
904         {
905            btif_storage_req_t *p_req = (btif_storage_req_t*)p_param;
906            status = btif_storage_set_remote_device_property(&(p_req->write_req.bd_addr),
907                                                             &(p_req->write_req.prop));
908         }break;
909         case BTIF_CORE_STORAGE_REMOTE_READ_ALL:
910         {
911            btif_storage_req_t *p_req = (btif_storage_req_t*)p_param;
912            btif_in_get_remote_device_properties(&p_req->read_req.bd_addr);
913         }break;
914     }
915 }
916
917 void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props,
918                                     bt_property_t *p_props)
919 {
920     HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
921                      status, num_props, p_props);
922
923 }
924 void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
925                                    uint32_t num_props, bt_property_t *p_props)
926 {
927     HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
928                      status, remote_addr, num_props, p_props);
929 }
930
931 /*******************************************************************************
932 **
933 ** Function         btif_in_storage_request_copy_cb
934 **
935 ** Description     Switch context callback function to perform the deep copy for
936 **                 both the adapter and remote_device property API
937 **
938 ** Returns          None
939 **
940 *******************************************************************************/
941 static void btif_in_storage_request_copy_cb(UINT16 event,
942                                                  char *p_new_buf, char *p_old_buf)
943 {
944      btif_storage_req_t *new_req = (btif_storage_req_t*)p_new_buf;
945      btif_storage_req_t *old_req = (btif_storage_req_t*)p_old_buf;
946
947      BTIF_TRACE_EVENT("%s", __FUNCTION__);
948      switch (event)
949      {
950          case BTIF_CORE_STORAGE_REMOTE_WRITE:
951          case BTIF_CORE_STORAGE_ADAPTER_WRITE:
952          {
953              bdcpy(new_req->write_req.bd_addr.address, old_req->write_req.bd_addr.address);
954              /* Copy the member variables one at a time */
955              new_req->write_req.prop.type = old_req->write_req.prop.type;
956              new_req->write_req.prop.len = old_req->write_req.prop.len;
957
958              new_req->write_req.prop.val = (UINT8 *)(p_new_buf + sizeof(btif_storage_req_t));
959              memcpy(new_req->write_req.prop.val, old_req->write_req.prop.val,
960                     old_req->write_req.prop.len);
961          }break;
962      }
963 }
964
965 /*******************************************************************************
966 **
967 ** Function         btif_get_adapter_properties
968 **
969 ** Description      Fetch all available properties (local & remote)
970 **
971 ** Returns          bt_status_t
972 **
973 *******************************************************************************/
974
975 bt_status_t btif_get_adapter_properties(void)
976 {
977     BTIF_TRACE_EVENT("%s", __FUNCTION__);
978
979     if (!btif_is_enabled())
980         return BT_STATUS_NOT_READY;
981
982     return btif_transfer_context(execute_storage_request,
983                                  BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
984                                  NULL, 0, NULL);
985 }
986
987 /*******************************************************************************
988 **
989 ** Function         btif_get_adapter_property
990 **
991 ** Description      Fetches property value from local cache
992 **
993 ** Returns          bt_status_t
994 **
995 *******************************************************************************/
996
997 bt_status_t btif_get_adapter_property(bt_property_type_t type)
998 {
999     btif_storage_req_t req;
1000
1001     BTIF_TRACE_EVENT("%s %d", __FUNCTION__, type);
1002
1003     /* Allow get_adapter_property only for BDADDR and BDNAME if BT is disabled */
1004     if (!btif_is_enabled() && (type != BT_PROPERTY_BDADDR) && (type != BT_PROPERTY_BDNAME))
1005         return BT_STATUS_NOT_READY;
1006
1007     memset(&(req.read_req.bd_addr), 0, sizeof(bt_bdaddr_t));
1008     req.read_req.type = type;
1009
1010     return btif_transfer_context(execute_storage_request,
1011                                  BTIF_CORE_STORAGE_ADAPTER_READ,
1012                                 (char*)&req, sizeof(btif_storage_req_t), NULL);
1013 }
1014
1015 /*******************************************************************************
1016 **
1017 ** Function         btif_set_adapter_property
1018 **
1019 ** Description      Updates core stack with property value and stores it in
1020 **                  local cache
1021 **
1022 ** Returns          bt_status_t
1023 **
1024 *******************************************************************************/
1025
1026 bt_status_t btif_set_adapter_property(const bt_property_t *property)
1027 {
1028     btif_storage_req_t req;
1029     bt_status_t status = BT_STATUS_SUCCESS;
1030     int storage_req_id = BTIF_CORE_STORAGE_NOTIFY_STATUS; /* default */
1031     char bd_name[BTM_MAX_LOC_BD_NAME_LEN +1];
1032     UINT16  name_len = 0;
1033
1034     BTIF_TRACE_EVENT("btif_set_adapter_property type: %d, len %d, 0x%x",
1035                       property->type, property->len, property->val);
1036
1037     if (!btif_is_enabled())
1038         return BT_STATUS_NOT_READY;
1039
1040     switch(property->type)
1041     {
1042         case BT_PROPERTY_BDNAME:
1043             {
1044                 name_len = property->len > BTM_MAX_LOC_BD_NAME_LEN ? BTM_MAX_LOC_BD_NAME_LEN:
1045                                                                      property->len;
1046                 memcpy(bd_name,property->val, name_len);
1047                 bd_name[name_len] = '\0';
1048
1049                 BTIF_TRACE_EVENT("set property name : %s", (char *)bd_name);
1050
1051                 BTA_DmSetDeviceName((char *)bd_name);
1052
1053                 storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE;
1054             }
1055             break;
1056
1057         case BT_PROPERTY_ADAPTER_SCAN_MODE:
1058             {
1059                 bt_scan_mode_t mode = *(bt_scan_mode_t*)property->val;
1060                 tBTA_DM_DISC disc_mode;
1061                 tBTA_DM_CONN conn_mode;
1062
1063                 switch(mode)
1064                 {
1065                     case BT_SCAN_MODE_NONE:
1066                         disc_mode = BTA_DM_NON_DISC;
1067                         conn_mode = BTA_DM_NON_CONN;
1068                         break;
1069
1070                     case BT_SCAN_MODE_CONNECTABLE:
1071                         disc_mode = BTA_DM_NON_DISC;
1072                         conn_mode = BTA_DM_CONN;
1073                         break;
1074
1075                     case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
1076                         disc_mode = BTA_DM_GENERAL_DISC;
1077                         conn_mode = BTA_DM_CONN;
1078                         break;
1079
1080                     default:
1081                         BTIF_TRACE_ERROR("invalid scan mode (0x%x)", mode);
1082                         return BT_STATUS_PARM_INVALID;
1083                 }
1084
1085                 BTIF_TRACE_EVENT("set property scan mode : %x", mode);
1086
1087                 BTA_DmSetVisibility(disc_mode, conn_mode, BTA_DM_IGNORE, BTA_DM_IGNORE);
1088
1089                 storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE;
1090             }
1091             break;
1092         case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
1093             {
1094                 /* Nothing to do beside store the value in NV.  Java
1095                    will change the SCAN_MODE property after setting timeout,
1096                    if required */
1097                 storage_req_id = BTIF_CORE_STORAGE_ADAPTER_WRITE;
1098             }
1099             break;
1100         case BT_PROPERTY_BDADDR:
1101         case BT_PROPERTY_UUIDS:
1102         case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
1103         case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
1104             /* no write support through HAL, these properties are only populated from BTA events */
1105             status = BT_STATUS_FAIL;
1106             break;
1107         default:
1108             BTIF_TRACE_ERROR("btif_get_adapter_property : invalid type %d",
1109             property->type);
1110             status = BT_STATUS_FAIL;
1111             break;
1112     }
1113
1114     if (storage_req_id != BTIF_CORE_STORAGE_NO_ACTION)
1115     {
1116         /* pass on to storage for updating local database */
1117
1118         memset(&(req.write_req.bd_addr), 0, sizeof(bt_bdaddr_t));
1119         memcpy(&(req.write_req.prop), property, sizeof(bt_property_t));
1120
1121         return btif_transfer_context(execute_storage_request,
1122                                      storage_req_id,
1123                                      (char*)&req,
1124                                      sizeof(btif_storage_req_t)+property->len,
1125                                      btif_in_storage_request_copy_cb);
1126     }
1127
1128     return status;
1129
1130 }
1131
1132 /*******************************************************************************
1133 **
1134 ** Function         btif_get_remote_device_property
1135 **
1136 ** Description      Fetches the remote device property from the NVRAM
1137 **
1138 ** Returns          bt_status_t
1139 **
1140 *******************************************************************************/
1141 bt_status_t btif_get_remote_device_property(bt_bdaddr_t *remote_addr,
1142                                                  bt_property_type_t type)
1143 {
1144     btif_storage_req_t req;
1145
1146     if (!btif_is_enabled())
1147         return BT_STATUS_NOT_READY;
1148
1149     memcpy(&(req.read_req.bd_addr), remote_addr, sizeof(bt_bdaddr_t));
1150     req.read_req.type = type;
1151     return btif_transfer_context(execute_storage_remote_request,
1152                                  BTIF_CORE_STORAGE_REMOTE_READ,
1153                                  (char*)&req, sizeof(btif_storage_req_t),
1154                                  NULL);
1155 }
1156
1157 /*******************************************************************************
1158 **
1159 ** Function         btif_get_remote_device_properties
1160 **
1161 ** Description      Fetches all the remote device properties from NVRAM
1162 **
1163 ** Returns          bt_status_t
1164 **
1165 *******************************************************************************/
1166 bt_status_t btif_get_remote_device_properties(bt_bdaddr_t *remote_addr)
1167 {
1168     btif_storage_req_t req;
1169
1170     if (!btif_is_enabled())
1171         return BT_STATUS_NOT_READY;
1172
1173     memcpy(&(req.read_req.bd_addr), remote_addr, sizeof(bt_bdaddr_t));
1174     return btif_transfer_context(execute_storage_remote_request,
1175                                  BTIF_CORE_STORAGE_REMOTE_READ_ALL,
1176                                  (char*)&req, sizeof(btif_storage_req_t),
1177                                  NULL);
1178 }
1179
1180 /*******************************************************************************
1181 **
1182 ** Function         btif_set_remote_device_property
1183 **
1184 ** Description      Writes the remote device property to NVRAM.
1185 **                  Currently, BT_PROPERTY_REMOTE_FRIENDLY_NAME is the only
1186 **                  remote device property that can be set
1187 **
1188 ** Returns          bt_status_t
1189 **
1190 *******************************************************************************/
1191 bt_status_t btif_set_remote_device_property(bt_bdaddr_t *remote_addr,
1192                                                  const bt_property_t *property)
1193 {
1194     btif_storage_req_t req;
1195
1196     if (!btif_is_enabled())
1197         return BT_STATUS_NOT_READY;
1198
1199     memcpy(&(req.write_req.bd_addr), remote_addr, sizeof(bt_bdaddr_t));
1200     memcpy(&(req.write_req.prop), property, sizeof(bt_property_t));
1201
1202     return btif_transfer_context(execute_storage_remote_request,
1203                                  BTIF_CORE_STORAGE_REMOTE_WRITE,
1204                                  (char*)&req,
1205                                  sizeof(btif_storage_req_t)+property->len,
1206                                  btif_in_storage_request_copy_cb);
1207 }
1208
1209
1210 /*******************************************************************************
1211 **
1212 ** Function         btif_get_remote_service_record
1213 **
1214 ** Description      Looks up the service matching uuid on the remote device
1215 **                  and fetches the SCN and service_name if the UUID is found
1216 **
1217 ** Returns          bt_status_t
1218 **
1219 *******************************************************************************/
1220 bt_status_t btif_get_remote_service_record(bt_bdaddr_t *remote_addr,
1221                                                bt_uuid_t *uuid)
1222 {
1223     if (!btif_is_enabled())
1224         return BT_STATUS_NOT_READY;
1225
1226     return btif_dm_get_remote_service_record(remote_addr, uuid);
1227 }
1228
1229
1230 /*******************************************************************************
1231 **
1232 ** Function         btif_get_enabled_services_mask
1233 **
1234 ** Description      Fetches currently enabled services
1235 **
1236 ** Returns          tBTA_SERVICE_MASK
1237 **
1238 *******************************************************************************/
1239
1240 tBTA_SERVICE_MASK btif_get_enabled_services_mask(void)
1241 {
1242     return btif_enabled_services;
1243 }
1244
1245 /*******************************************************************************
1246 **
1247 ** Function         btif_enable_service
1248 **
1249 ** Description      Enables the service 'service_ID' to the service_mask.
1250 **                  Upon BT enable, BTIF core shall invoke the BTA APIs to
1251 **                  enable the profiles
1252 **
1253 ** Returns          bt_status_t
1254 **
1255 *******************************************************************************/
1256 bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id)
1257 {
1258     tBTA_SERVICE_ID *p_id = &service_id;
1259
1260     /* If BT is enabled, we need to switch to BTIF context and trigger the
1261      * enable for that profile
1262      *
1263      * Otherwise, we just set the flag. On BT_Enable, the DM will trigger
1264      * enable for the profiles that have been enabled */
1265
1266     btif_enabled_services |= (1 << service_id);
1267
1268     BTIF_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btif_enabled_services);
1269
1270     if (btif_is_enabled())
1271     {
1272         btif_transfer_context(btif_dm_execute_service_request,
1273                               BTIF_DM_ENABLE_SERVICE,
1274                               (char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
1275     }
1276
1277     return BT_STATUS_SUCCESS;
1278 }
1279 /*******************************************************************************
1280 **
1281 ** Function         btif_disable_service
1282 **
1283 ** Description      Disables the service 'service_ID' to the service_mask.
1284 **                  Upon BT disable, BTIF core shall invoke the BTA APIs to
1285 **                  disable the profiles
1286 **
1287 ** Returns          bt_status_t
1288 **
1289 *******************************************************************************/
1290 bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id)
1291 {
1292     tBTA_SERVICE_ID *p_id = &service_id;
1293
1294     /* If BT is enabled, we need to switch to BTIF context and trigger the
1295      * disable for that profile so that the appropriate uuid_property_changed will
1296      * be triggerred. Otherwise, we just need to clear the service_id in the mask
1297      */
1298
1299     btif_enabled_services &=  (tBTA_SERVICE_MASK)(~(1<<service_id));
1300
1301     BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
1302
1303     if (btif_is_enabled())
1304     {
1305         btif_transfer_context(btif_dm_execute_service_request,
1306                               BTIF_DM_DISABLE_SERVICE,
1307                               (char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
1308     }
1309
1310     return BT_STATUS_SUCCESS;
1311 }
1312
1313 static void btif_jni_associate(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param) {
1314   BTIF_TRACE_DEBUG("%s Associating thread to JVM", __func__);
1315   HAL_CBACK(bt_hal_cbacks, thread_evt_cb, ASSOCIATE_JVM);
1316 }
1317
1318 static void btif_jni_disassociate(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param) {
1319   BTIF_TRACE_DEBUG("%s Disassociating thread from JVM", __func__);
1320   HAL_CBACK(bt_hal_cbacks, thread_evt_cb, DISASSOCIATE_JVM);
1321   bt_hal_cbacks = NULL;
1322   future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
1323 }
1324