1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains the main Bluetooth Upper Layer processing loop.
22 * The Broadcom implementations of L2CAP RFCOMM, SDP and the BTIf run as one
23 * GKI task. This btu_task switches between them.
25 * Note that there will always be an L2CAP, but there may or may not be an
26 * RFCOMM or SDP. Whether these layers are present or not is determined by
29 ******************************************************************************/
33 #define LOG_TAG "btu_task"
34 #include <cutils/log.h>
40 #include "bt_target.h"
44 #include "btif_common.h"
48 #include "fixed_queue.h"
55 #include <sys/prctl.h>
59 #if ( defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE )
64 #if (defined(EVAL) && EVAL == TRUE)
68 #if GAP_INCLUDED == TRUE
72 #if (defined(OBX_INCLUDED) && OBX_INCLUDED == TRUE)
75 #if (defined(BIP_INCLUDED) && BIP_INCLUDED == TRUE)
79 #if (BPP_SND_INCLUDED == TRUE || BPP_INCLUDED == TRUE)
85 /* BTE application task */
86 #if APPL_INCLUDED == TRUE
90 #if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
94 #if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
98 #if (defined(SAP_SERVER_INCLUDED) && SAP_SERVER_INCLUDED == TRUE)
102 #if (defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE )
103 #include "hidd_int.h"
106 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE )
107 #include "hidh_int.h"
110 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
111 #include "avdt_int.h"
113 extern void avdt_rcv_sync_info (BT_HDR *p_buf); /* this is for hci_test */
116 #if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
118 #include "mca_defs.h"
124 #if (BLE_INCLUDED == TRUE)
125 #include "gatt_int.h"
126 #if (SMP_INCLUDED == TRUE)
129 #include "btm_ble_int.h"
137 BT_API extern void BTE_InitStack(void);
143 /* Define BTU storage area
145 #if BTU_DYNAMIC_MEMORY == FALSE
149 // Communication queue between btu_task and bta.
150 extern fixed_queue_t *btu_bta_msg_queue;
152 // Communication queue between btu_task and hci.
153 extern fixed_queue_t *btu_hci_msg_queue;
155 // Timer queue between btu_task and bta.
156 extern fixed_queue_t *btu_bta_alarm_queue;
158 // General timer queue.
159 extern fixed_queue_t *btu_general_alarm_queue;
160 extern hash_map_t *btu_general_alarm_hash_map;
161 extern pthread_mutex_t btu_general_alarm_lock;
163 // Oneshot timer queue.
164 extern fixed_queue_t *btu_oneshot_alarm_queue;
165 extern hash_map_t *btu_oneshot_alarm_hash_map;
166 extern pthread_mutex_t btu_oneshot_alarm_lock;
168 // l2cap timer queue.
169 extern fixed_queue_t *btu_l2cap_alarm_queue;
170 extern hash_map_t *btu_l2cap_alarm_hash_map;
171 extern pthread_mutex_t btu_l2cap_alarm_lock;
173 /* Define a function prototype to allow a generic timeout handler */
174 typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle);
176 static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle);
177 static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle);
179 static void btu_hci_msg_process(BT_HDR *p_msg) {
180 /* Determine the input message type. */
181 switch (p_msg->event & BT_EVT_MASK)
183 case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this
184 ((post_to_task_hack_t *)(&p_msg->data[0]))->callback(p_msg);
186 case BT_EVT_TO_BTU_HCI_ACL:
187 /* All Acl Data goes to L2CAP */
188 l2c_rcv_acl_data (p_msg);
191 case BT_EVT_TO_BTU_L2C_SEG_XMIT:
192 /* L2CAP segment transmit complete */
193 l2c_link_segments_xmitted (p_msg);
196 case BT_EVT_TO_BTU_HCI_SCO:
197 #if BTM_SCO_INCLUDED == TRUE
198 btm_route_sco_data (p_msg);
202 case BT_EVT_TO_BTU_HCI_EVT:
203 btu_hcif_process_event ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
206 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
207 /* If host receives events which it doesn't response to, */
208 /* host should start idle timer to enter sleep mode. */
209 btu_check_bt_sleep ();
213 case BT_EVT_TO_BTU_HCI_CMD:
214 btu_hcif_send_cmd ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
217 #if (defined(OBX_INCLUDED) && OBX_INCLUDED == TRUE)
218 #if (defined(OBX_SERVER_INCLUDED) && OBX_SERVER_INCLUDED == TRUE)
219 case BT_EVT_TO_OBX_SR_MSG:
220 obx_sr_proc_evt((tOBX_PORT_EVT *)(p_msg + 1));
224 case BT_EVT_TO_OBX_SR_L2C_MSG:
225 obx_sr_proc_l2c_evt((tOBX_L2C_EVT_MSG *)(p_msg + 1));
230 #if (defined(OBX_CLIENT_INCLUDED) && OBX_CLIENT_INCLUDED == TRUE)
231 case BT_EVT_TO_OBX_CL_MSG:
232 obx_cl_proc_evt((tOBX_PORT_EVT *)(p_msg + 1));
236 case BT_EVT_TO_OBX_CL_L2C_MSG:
237 obx_cl_proc_l2c_evt((tOBX_L2C_EVT_MSG *)(p_msg + 1));
242 #if (defined(BIP_INCLUDED) && BIP_INCLUDED == TRUE)
243 case BT_EVT_TO_BIP_CMDS :
244 bip_proc_btu_event(p_msg);
248 #if (BPP_SND_INCLUDED == TRUE || BPP_INCLUDED == TRUE)
249 case BT_EVT_TO_BPP_PR_CMDS:
250 bpp_pr_proc_event(p_msg);
253 case BT_EVT_TO_BPP_SND_CMDS:
254 bpp_snd_proc_event(p_msg);
262 #if (defined(SAP_SERVER_INCLUDED) && SAP_SERVER_INCLUDED == TRUE)
263 case BT_EVT_TO_BTU_SAP :
264 sap_proc_btu_event(p_msg);
268 #if (defined(GAP_CONN_INCLUDED) && GAP_CONN_INCLUDED == TRUE && GAP_CONN_POST_EVT_INCLUDED == TRUE)
269 case BT_EVT_TO_GAP_MSG :
270 gap_proc_btu_event(p_msg);
274 // NOTE: The timer calls below may not be sent by HCI.
275 case BT_EVT_TO_START_TIMER :
276 /* Start free running 1 second timer for list management */
277 GKI_start_timer (TIMER_0, GKI_SECS_TO_TICKS (1), TRUE);
281 case BT_EVT_TO_STOP_TIMER:
282 if (GKI_timer_queue_is_empty(&btu_cb.timer_queue)) {
283 GKI_stop_timer(TIMER_0);
288 case BT_EVT_TO_START_TIMER_ONESHOT:
289 if (!GKI_timer_queue_is_empty(&btu_cb.timer_queue_oneshot)) {
290 TIMER_LIST_ENT *tle = GKI_timer_getfirst(&btu_cb.timer_queue_oneshot);
291 // Start non-repeating timer.
292 GKI_start_timer(TIMER_3, tle->ticks, FALSE);
294 BTM_TRACE_WARNING("Oneshot timer queue empty when received start request");
299 case BT_EVT_TO_STOP_TIMER_ONESHOT:
300 if (GKI_timer_queue_is_empty(&btu_cb.timer_queue_oneshot)) {
301 GKI_stop_timer(TIMER_3);
303 BTM_TRACE_WARNING("Oneshot timer queue not empty when received stop request");
308 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
309 case BT_EVT_TO_START_QUICK_TIMER :
310 GKI_start_timer (TIMER_2, QUICK_TIMER_TICKS, TRUE);
317 uint16_t mask = (UINT16) (p_msg->event & BT_EVT_MASK);
318 BOOLEAN handled = FALSE;
320 for (; !handled && i < BTU_MAX_REG_EVENT; i++)
322 if (btu_cb.event_reg[i].event_cb == NULL)
325 if (mask == btu_cb.event_reg[i].event_range)
327 if (btu_cb.event_reg[i].event_cb)
329 btu_cb.event_reg[i].event_cb(p_msg);
335 if (handled == FALSE)
343 static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) {
344 /* call timer callback */
345 if (p_tle->p_cback) {
346 (*p_tle->p_cback)(p_tle);
347 } else if (p_tle->event) {
349 if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
350 p_msg->event = p_tle->event;
351 p_msg->layer_specific = 0;
352 bta_sys_sendmsg(p_msg);
357 /*******************************************************************************
361 ** Description This is the main task of the Bluetooth Upper Layers unit.
362 ** It sits in a loop waiting for messages, and dispatches them
363 ** to the appropiate handlers.
365 ** Returns should never return
367 *******************************************************************************/
368 BTU_API void btu_task (void)
372 TIMER_LIST_ENT *p_tle;
377 /* wait an event that HCISU is ready */
378 BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API,
379 "btu_task pending for preload complete event");
383 event = GKI_wait (0xFFFF, 0);
384 if (event & EVENT_MASK(GKI_SHUTDOWN_EVT))
386 /* indicates BT ENABLE abort */
387 BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_WARNING,
388 "btu_task start abort!");
391 else if (event & BT_EVT_PRELOAD_CMPL)
397 BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_WARNING,
398 "btu_task ignore evt %04x while pending for preload complete",
403 BT_TRACE(TRACE_LAYER_BTU, TRACE_TYPE_API,
404 "btu_task received preload complete event");
406 /* Initialize the mandatory core stack control blocks
407 (BTU, BTM, L2CAP, and SDP)
411 /* Initialize any optional stack components */
416 /* Initialise platform trace levels at this point as BTE_InitStack() and bta_sys_init()
417 * reset the control blocks and preset the trace level with XXX_INITIAL_TRACE_LEVEL
419 #if ( BT_USE_TRACES==TRUE )
420 BTE_InitTraceLevels();
423 // Inform the bt jni thread initialization is ok.
424 btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL);
426 raise_priority_a2dp(TASK_HIGH_BTU);
428 /* Wait for, and process, events */
430 event = GKI_wait (0xFFFF, 0);
432 // HCI message queue.
433 while (!fixed_queue_is_empty(btu_hci_msg_queue)) {
434 p_msg = (BT_HDR *)fixed_queue_dequeue(btu_hci_msg_queue);
435 btu_hci_msg_process(p_msg);
438 // General alarm queue.
439 while (!fixed_queue_is_empty(btu_general_alarm_queue)) {
440 p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_general_alarm_queue);
441 btu_general_alarm_process(p_tle);
444 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
445 // L2CAP alarm queue.
446 while (!fixed_queue_is_empty(btu_l2cap_alarm_queue)) {
447 p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_l2cap_alarm_queue);
448 btu_l2cap_alarm_process(p_tle);
450 #endif // QUICK_TIMER
452 // BTA message queue.
453 while (!fixed_queue_is_empty(btu_bta_msg_queue)) {
454 p_msg = (BT_HDR *)fixed_queue_dequeue(btu_bta_msg_queue);
455 bta_sys_event(p_msg);
459 while (!fixed_queue_is_empty(btu_bta_alarm_queue)) {
460 p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_bta_alarm_queue);
461 btu_bta_alarm_process(p_tle);
464 while (!fixed_queue_is_empty(btu_oneshot_alarm_queue)) {
465 p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(btu_oneshot_alarm_queue);
466 switch (p_tle->event) {
467 #if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
468 case BTU_TTYPE_BLE_RANDOM_ADDR:
469 btm_ble_timeout(p_tle);
473 case BTU_TTYPE_USER_FUNC:
475 tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
482 BTM_TRACE_WARNING("Received unexpected oneshot timer event:0x%x\n",
488 if (event & EVENT_MASK(APPL_EVT_7))
499 /*******************************************************************************
501 ** Function btu_start_timer
503 ** Description Start a timer for the specified amount of time.
504 ** NOTE: The timeout resolution is in SECONDS! (Even
505 ** though the timer structure field is ticks)
509 *******************************************************************************/
510 static void btu_general_alarm_process(TIMER_LIST_ENT *p_tle) {
511 assert(p_tle != NULL);
513 switch (p_tle->event) {
514 case BTU_TTYPE_BTM_DEV_CTL:
515 btm_dev_timeout(p_tle);
518 case BTU_TTYPE_BTM_ACL:
519 btm_acl_timeout(p_tle);
522 case BTU_TTYPE_L2CAP_LINK:
523 case BTU_TTYPE_L2CAP_CHNL:
524 case BTU_TTYPE_L2CAP_HOLD:
525 case BTU_TTYPE_L2CAP_INFO:
526 case BTU_TTYPE_L2CAP_FCR_ACK:
527 l2c_process_timeout (p_tle);
531 sdp_conn_timeout ((tCONN_CB *)p_tle->param);
534 case BTU_TTYPE_BTM_RMT_NAME:
535 btm_inq_rmt_name_failed();
538 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
539 case BTU_TTYPE_RFCOMM_MFC:
540 case BTU_TTYPE_RFCOMM_PORT:
541 rfcomm_process_timeout (p_tle);
544 #endif /* If defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE */
546 #if ((defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE))
548 bnep_process_timeout(p_tle);
553 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
554 case BTU_TTYPE_AVDT_CCB_RET:
555 case BTU_TTYPE_AVDT_CCB_RSP:
556 case BTU_TTYPE_AVDT_CCB_IDLE:
557 case BTU_TTYPE_AVDT_SCB_TC:
558 avdt_process_timeout(p_tle);
562 #if (defined(OBX_INCLUDED) && OBX_INCLUDED == TRUE)
563 #if (defined(OBX_CLIENT_INCLUDED) && OBX_CLIENT_INCLUDED == TRUE)
564 case BTU_TTYPE_OBX_CLIENT_TO:
565 obx_cl_timeout(p_tle);
568 #if (defined(OBX_SERVER_INCLUDED) && OBX_SERVER_INCLUDED == TRUE)
569 case BTU_TTYPE_OBX_SERVER_TO:
570 obx_sr_timeout(p_tle);
573 case BTU_TTYPE_OBX_SVR_SESS_TO:
574 obx_sr_sess_timeout(p_tle);
579 #if (defined(SAP_SERVER_INCLUDED) && SAP_SERVER_INCLUDED == TRUE)
580 case BTU_TTYPE_SAP_TO:
581 sap_process_timeout(p_tle);
585 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
586 case BTU_TTYPE_HID_HOST_REPAGE_TO :
587 hidh_proc_repage_timeout(p_tle);
591 #if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
592 case BTU_TTYPE_BLE_INQUIRY:
593 case BTU_TTYPE_BLE_GAP_LIM_DISC:
594 case BTU_TTYPE_BLE_RANDOM_ADDR:
595 case BTU_TTYPE_BLE_GAP_FAST_ADV:
596 case BTU_TTYPE_BLE_OBSERVE:
597 btm_ble_timeout(p_tle);
600 case BTU_TTYPE_ATT_WAIT_FOR_RSP:
601 gatt_rsp_timeout(p_tle);
604 case BTU_TTYPE_ATT_WAIT_FOR_IND_ACK:
605 gatt_ind_ack_timeout(p_tle);
607 #if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
608 case BTU_TTYPE_SMP_PAIRING_CMD:
609 smp_rsp_timeout(p_tle);
615 #if (MCA_INCLUDED == TRUE)
616 case BTU_TTYPE_MCA_CCB_RSP:
617 mca_process_timeout(p_tle);
620 case BTU_TTYPE_USER_FUNC:
622 tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
629 BOOLEAN handled = FALSE;
631 for (; !handled && i < BTU_MAX_REG_TIMER; i++)
633 if (btu_cb.timer_reg[i].timer_cb == NULL)
635 if (btu_cb.timer_reg[i].p_tle == p_tle)
637 btu_cb.timer_reg[i].timer_cb(p_tle);
645 void btu_general_alarm_cb(void *data) {
646 assert(data != NULL);
647 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
649 fixed_queue_enqueue(btu_general_alarm_queue, p_tle);
650 GKI_send_event(BTU_TASK, TIMER_0_EVT_MASK);
653 void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
654 assert(p_tle != NULL);
656 // Get the alarm for the timer list entry.
657 pthread_mutex_lock(&btu_general_alarm_lock);
658 if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
659 hash_map_set(btu_general_alarm_hash_map, p_tle, alarm_new());
661 pthread_mutex_unlock(&btu_general_alarm_lock);
663 alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
665 ALOGE("%s Unable to create alarm\n", __func__);
671 // NOTE: This value is in seconds but stored in a ticks field.
672 p_tle->ticks = timeout_sec;
673 if (p_tle->in_use == TRUE)
674 ALOGW("%s Starting alarm already in use\n", __func__);
675 p_tle->in_use = TRUE;
676 alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_general_alarm_cb, (void *)p_tle);
679 /*******************************************************************************
681 ** Function btu_remaining_time
683 ** Description Return amount of time to expire
685 ** Returns time in second
687 *******************************************************************************/
688 UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle)
690 return(GKI_get_remaining_ticks (&btu_cb.timer_queue, p_tle));
693 /*******************************************************************************
695 ** Function btu_stop_timer
697 ** Description Stop a timer.
701 *******************************************************************************/
702 void btu_stop_timer(TIMER_LIST_ENT *p_tle) {
703 assert(p_tle != NULL);
705 if (p_tle->in_use == FALSE)
707 p_tle->in_use = FALSE;
709 // Get the alarm for the timer list entry.
710 alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
712 ALOGW("%s Unable to find expected alarm in hashmap\n", __func__);
718 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
719 /*******************************************************************************
721 ** Function btu_start_quick_timer
723 ** Description Start a timer for the specified amount of time in ticks.
727 *******************************************************************************/
728 static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle) {
729 assert(p_tle != NULL);
731 switch (p_tle->event) {
732 case BTU_TTYPE_L2CAP_CHNL: /* monitor or retransmission timer */
733 case BTU_TTYPE_L2CAP_FCR_ACK: /* ack timer */
734 l2c_process_timeout (p_tle);
742 static void btu_l2cap_alarm_cb(void *data) {
743 assert(data != NULL);
744 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
746 fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle);
747 GKI_send_event(BTU_TASK, TIMER_2_EVT_MASK);
750 void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) {
751 assert(p_tle != NULL);
753 // Get the alarm for the timer list entry.
754 pthread_mutex_lock(&btu_l2cap_alarm_lock);
755 if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
756 hash_map_set(btu_l2cap_alarm_hash_map, p_tle, alarm_new());
758 pthread_mutex_unlock(&btu_l2cap_alarm_lock);
760 alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
762 ALOGE("%s Unable to create alarm\n", __func__);
768 p_tle->ticks = timeout_ticks;
769 if (p_tle->in_use == TRUE)
770 ALOGW("%s Starting alarm already in use\n", __func__);
771 p_tle->in_use = TRUE;
772 // The quick timer ticks are 100ms long.
773 alarm_set(alarm, (period_ms_t)(timeout_ticks * 100), btu_l2cap_alarm_cb, (void *)p_tle);
776 /*******************************************************************************
778 ** Function btu_stop_quick_timer
780 ** Description Stop a timer.
784 *******************************************************************************/
785 void btu_stop_quick_timer(TIMER_LIST_ENT *p_tle) {
786 assert(p_tle != NULL);
788 if (p_tle->in_use == FALSE)
790 p_tle->in_use = FALSE;
792 // Get the alarm for the timer list entry.
793 alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
795 ALOGW("%s Unable to find expected alarm in hashmap\n", __func__);
800 #endif /* defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) */
802 void btu_oneshot_alarm_cb(void *data) {
803 assert(data != NULL);
804 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
806 btu_stop_timer_oneshot(p_tle);
808 fixed_queue_enqueue(btu_oneshot_alarm_queue, p_tle);
809 GKI_send_event(BTU_TASK, TIMER_3_EVT_MASK);
813 * Starts a oneshot timer with a timeout in seconds.
815 void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
816 assert(p_tle != NULL);
818 // Get the alarm for the timer list entry.
819 pthread_mutex_lock(&btu_oneshot_alarm_lock);
820 if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
821 hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm_new());
823 pthread_mutex_unlock(&btu_oneshot_alarm_lock);
825 alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
827 ALOGE("%s Unable to create alarm\n", __func__);
833 if (p_tle->in_use == TRUE)
834 ALOGW("%s Starting alarm already in use\n", __func__);
835 p_tle->in_use = TRUE;
836 // NOTE: This value is in seconds but stored in a ticks field.
837 p_tle->ticks = timeout_sec;
838 alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_oneshot_alarm_cb, (void *)p_tle);
841 void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle) {
842 assert(p_tle != NULL);
844 if (p_tle->in_use == FALSE)
846 p_tle->in_use = FALSE;
848 // Get the alarm for the timer list entry.
849 alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
851 ALOGW("%s Unable to find expected alarm in hashmap\n", __func__);
857 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
858 /*******************************************************************************
860 ** Function btu_check_bt_sleep
862 ** Description This function is called to check if controller can go to sleep.
866 *******************************************************************************/
867 void btu_check_bt_sleep (void)
869 if ((GKI_queue_is_empty(&btu_cb.hci_cmd_cb[LOCAL_BR_EDR_CONTROLLER_ID].cmd_cmpl_q)
870 && GKI_queue_is_empty(&btu_cb.hci_cmd_cb[LOCAL_BR_EDR_CONTROLLER_ID].cmd_xmit_q)))
872 if (l2cb.controller_xmit_window == l2cb.num_lm_acl_bufs)
874 /* enable dev to sleep in the cmd cplt and cmd status only and num cplt packet */
875 HCI_LP_ALLOW_BT_DEVICE_SLEEP();