1 /******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 *
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:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 ******************************************************************************/
18 #include <string.h>
19
20
21 #include "osi/alarm.h"
22 #include "osi/thread.h"
23 #include "common/bt_target.h"
24 #include "common/bt_trace.h"
25 #include "stack/bt_types.h"
26 #include "osi/allocator.h"
27 #include "osi/mutex.h"
28 #include "stack/btm_api.h"
29 #include "btm_int.h"
30 #include "stack/btu.h"
31 #include "osi/hash_map.h"
32 #include "stack/hcimsgs.h"
33 #include "l2c_int.h"
34 #include "osi/osi.h"
35
36 #if (defined(SDP_INCLUDED) && SDP_INCLUDED == 1)
37 #include "sdpint.h"
38 #endif
39
40 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == 1)
41 #include "stack/port_api.h"
42 #include "stack/port_ext.h"
43 #endif
44
45 #if (defined(GAP_INCLUDED) && GAP_INCLUDED == 1)
46 #include "gap_int.h"
47 #endif
48
49 #if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == 1)
50 #include "bnep_int.h"
51 #endif
52
53 #if (defined(PAN_INCLUDED) && PAN_INCLUDED == 1)
54 #include "pan_int.h"
55 #endif
56
57 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == 1 )
58 #include "hidh_int.h"
59 #endif
60
61 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == 1)
62 #include "avdt_int.h"
63 #else
64 extern void avdt_rcv_sync_info (BT_HDR *p_buf);
65 #endif
66
67 #if (defined(MCA_INCLUDED) && MCA_INCLUDED == 1)
68 #include "mca_api.h"
69 #include "mca_defs.h"
70 #include "mca_int.h"
71 #endif
72
73 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
74 #include "bta/bta_sys.h"
75 #endif
76
77 #if (BLE_INCLUDED == 1)
78 #include "gatt_int.h"
79 #if (SMP_INCLUDED == 1)
80 #include "smp_int.h"
81 #endif
82 #include "btm_ble_int.h"
83 #endif
84
85 typedef struct {
86 uint32_t sig;
87 void *param;
88 } btu_thread_evt_t;
89
90 //#if (defined(BT_APP_DEMO) && BT_APP_DEMO == 1)
91 //#include "bt_app_common.h"
92 //#endif
93
94 extern bt_status_t BTE_InitStack(void);
95 extern void BTE_DeinitStack(void);
96
97 /* Define BTU storage area
98 */
99 #if BTU_DYNAMIC_MEMORY == 0
100 tBTU_CB btu_cb;
101 #else
102 tBTU_CB *btu_cb_ptr;
103 #endif
104
105 extern hash_map_t *btu_general_alarm_hash_map;
106 extern osi_mutex_t btu_general_alarm_lock;
107
108 // Oneshot timer queue.
109 extern hash_map_t *btu_oneshot_alarm_hash_map;
110 extern osi_mutex_t btu_oneshot_alarm_lock;
111
112 // l2cap timer queue.
113 extern hash_map_t *btu_l2cap_alarm_hash_map;
114 extern osi_mutex_t btu_l2cap_alarm_lock;
115
116 extern void *btu_thread;
117
118 extern bluedroid_init_done_cb_t bluedroid_init_done_cb;
119
120 /* Define a function prototype to allow a generic timeout handler */
121 typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle);
122
123 static void btu_l2cap_alarm_process(void *param);
124 static void btu_general_alarm_process(void *param);
125 static void btu_hci_msg_process(void *param);
126
127 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
128 static void btu_bta_alarm_process(void *param);
129 #endif
130
btu_hci_msg_process(void * param)131 static void btu_hci_msg_process(void *param)
132 {
133 /* Determine the input message type. */
134 BT_HDR *p_msg = (BT_HDR *)param;
135
136 switch (p_msg->event & BT_EVT_MASK) {
137 case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this
138 {
139 post_to_task_hack_t *ph = (post_to_task_hack_t *) &p_msg->data[0];
140 ph->callback(p_msg);
141 break;
142 }
143 case BT_EVT_TO_BTU_HCI_ACL:
144 /* All Acl Data goes to L2CAP */
145 l2c_rcv_acl_data (p_msg);
146 break;
147
148 case BT_EVT_TO_BTU_L2C_SEG_XMIT:
149 /* L2CAP segment transmit complete */
150 l2c_link_segments_xmitted (p_msg);
151 break;
152
153 case BT_EVT_TO_BTU_HCI_SCO:
154 #if BTM_SCO_INCLUDED == 1
155 btm_route_sco_data (p_msg);
156 break;
157 #endif
158
159 case BT_EVT_TO_BTU_HCI_EVT:
160 btu_hcif_process_event ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
161 osi_free(p_msg);
162
163 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == 1)
164 /* If host receives events which it doesn't response to, */
165 /* host should start idle timer to enter sleep mode. */
166 btu_check_bt_sleep ();
167 #endif
168 break;
169
170 case BT_EVT_TO_BTU_HCI_CMD:
171 btu_hcif_send_cmd ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
172 break;
173
174 default:;
175 int i = 0;
176 uint16_t mask = (UINT16) (p_msg->event & BT_EVT_MASK);
177 BOOLEAN handled = 0;
178
179 for (; !handled && i < BTU_MAX_REG_EVENT; i++) {
180 if (btu_cb.event_reg[i].event_cb == NULL) {
181 continue;
182 }
183
184 if (mask == btu_cb.event_reg[i].event_range) {
185 if (btu_cb.event_reg[i].event_cb) {
186 btu_cb.event_reg[i].event_cb(p_msg);
187 handled = 1;
188 }
189 }
190 }
191
192 if (handled == 0) {
193 osi_free (p_msg);
194 }
195
196 break;
197 }
198
199 }
200
201 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
btu_bta_alarm_process(void * param)202 static void btu_bta_alarm_process(void *param)
203 {
204 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
205 // call timer callback
206 if (p_tle->p_cback) {
207 (*p_tle->p_cback)(p_tle);
208 } else if (p_tle->event) {
209 BT_HDR *p_msg;
210 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
211 p_msg->event = p_tle->event;
212 p_msg->layer_specific = 0;
213 //osi_free(p_msg);
214 bta_sys_sendmsg(p_msg);
215 }
216 }
217 }
218 #endif
219
btu_task_post(uint32_t sig,void * param,uint32_t timeout)220 bool btu_task_post(uint32_t sig, void *param, uint32_t timeout)
221 {
222 bool status = false;
223
224 switch (sig) {
225 case SIG_BTU_START_UP:
226 status = osi_thread_post(btu_thread, btu_task_start_up, param, 0, timeout);
227 break;
228 case SIG_BTU_HCI_MSG:
229 status = osi_thread_post(btu_thread, btu_hci_msg_process, param, 0, timeout);
230 break;
231 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
232 case SIG_BTU_BTA_MSG:
233 status = osi_thread_post(btu_thread, bta_sys_event, param, 0, timeout);
234 break;
235 case SIG_BTU_BTA_ALARM:
236 status = osi_thread_post(btu_thread, btu_bta_alarm_process, param, 0, timeout);
237 break;
238 #endif
239 case SIG_BTU_GENERAL_ALARM:
240 case SIG_BTU_ONESHOT_ALARM:
241 status = osi_thread_post(btu_thread, btu_general_alarm_process, param, 0, timeout);
242 break;
243 case SIG_BTU_L2CAP_ALARM:
244 status = osi_thread_post(btu_thread, btu_l2cap_alarm_process, param, 0, timeout);
245 break;
246 default:
247 break;
248 }
249
250 return status;
251 }
252
btu_task_start_up(void * param)253 void btu_task_start_up(void *param)
254 {
255 UNUSED(param);
256 /* Initialize the mandatory core stack control blocks
257 (BTU, BTM, L2CAP, and SDP)
258 */
259 btu_init_core();
260
261 /* Initialize any optional stack components */
262 BTE_InitStack();
263
264 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
265 bta_sys_init();
266 #endif
267
268 // Inform the bt jni thread initialization is ok.
269 // btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL);
270 #if(defined(BT_APP_DEMO) && BT_APP_DEMO == 1)
271 if (bluedroid_init_done_cb) {
272 bluedroid_init_done_cb();
273 }
274 #endif
275 }
276
btu_task_shut_down(void)277 void btu_task_shut_down(void)
278 {
279 #if (defined(BTA_INCLUDED) && BTA_INCLUDED == 1)
280 bta_sys_free();
281 #endif
282 BTE_DeinitStack();
283
284 btu_free_core();
285 }
286
287 /*******************************************************************************
288 **
289 ** Function btu_start_timer
290 **
291 ** Description Start a timer for the specified amount of time.
292 ** NOTE: The timeout resolution is in SECONDS! (Even
293 ** though the timer structure field is ticks)
294 **
295 ** Returns void
296 **
297 *******************************************************************************/
btu_general_alarm_process(void * param)298 static void btu_general_alarm_process(void *param)
299 {
300 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
301 assert(p_tle != NULL);
302
303 switch (p_tle->event) {
304 case BTU_TTYPE_BTM_DEV_CTL:
305 btm_dev_timeout(p_tle);
306 break;
307
308 case BTU_TTYPE_L2CAP_LINK:
309 case BTU_TTYPE_L2CAP_CHNL:
310 case BTU_TTYPE_L2CAP_HOLD:
311 case BTU_TTYPE_L2CAP_INFO:
312 case BTU_TTYPE_L2CAP_FCR_ACK:
313 case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS:
314 l2c_process_timeout (p_tle);
315 break;
316 #if (defined(SDP_INCLUDED) && SDP_INCLUDED == 1)
317 case BTU_TTYPE_SDP:
318 sdp_conn_timeout ((tCONN_CB *)p_tle->param);
319 break;
320 #endif
321 case BTU_TTYPE_BTM_RMT_NAME:
322 btm_inq_rmt_name_failed();
323 break;
324 #if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == 1)
325 case BTU_TTYPE_RFCOMM_MFC:
326 case BTU_TTYPE_RFCOMM_PORT:
327 rfcomm_process_timeout (p_tle);
328 break;
329 #endif
330 #if ((defined(BNEP_INCLUDED) && BNEP_INCLUDED == 1))
331 case BTU_TTYPE_BNEP:
332 bnep_process_timeout(p_tle);
333 break;
334 #endif
335
336
337 #if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == 1)
338 case BTU_TTYPE_AVDT_CCB_RET:
339 case BTU_TTYPE_AVDT_CCB_RSP:
340 case BTU_TTYPE_AVDT_CCB_IDLE:
341 case BTU_TTYPE_AVDT_SCB_TC:
342 avdt_process_timeout(p_tle);
343 break;
344 #endif
345
346 #if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == 1)
347 case BTU_TTYPE_HID_HOST_REPAGE_TO :
348 hidh_proc_repage_timeout(p_tle);
349 break;
350 #endif
351
352 #if (defined(BLE_INCLUDED) && BLE_INCLUDED == 1)
353 case BTU_TTYPE_BLE_INQUIRY:
354 case BTU_TTYPE_BLE_GAP_LIM_DISC:
355 case BTU_TTYPE_BLE_RANDOM_ADDR:
356 case BTU_TTYPE_BLE_GAP_FAST_ADV:
357 case BTU_TTYPE_BLE_SCAN:
358 case BTU_TTYPE_BLE_OBSERVE:
359 btm_ble_timeout(p_tle);
360 break;
361
362 case BTU_TTYPE_ATT_WAIT_FOR_RSP:
363 gatt_rsp_timeout(p_tle);
364 break;
365
366 case BTU_TTYPE_ATT_WAIT_FOR_IND_ACK:
367 gatt_ind_ack_timeout(p_tle);
368 break;
369
370 #if (defined(SMP_INCLUDED) && SMP_INCLUDED == 1)
371 case BTU_TTYPE_SMP_PAIRING_CMD:
372 smp_rsp_timeout(p_tle);
373 break;
374 #endif
375
376 #endif
377
378 #if (MCA_INCLUDED == 1)
379 case BTU_TTYPE_MCA_CCB_RSP:
380 mca_process_timeout(p_tle);
381 break;
382 #endif
383 case BTU_TTYPE_USER_FUNC: {
384 tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
385 (*p_uf)(p_tle);
386 }
387 break;
388
389 case BTU_TTYPE_BTM_QOS:
390 btm_qos_setup_timeout(p_tle);
391 break;
392 default:
393 for (int i = 0; i < BTU_MAX_REG_TIMER; i++) {
394 if (btu_cb.timer_reg[i].timer_cb == NULL) {
395 continue;
396 }
397 if (btu_cb.timer_reg[i].p_tle == p_tle) {
398 btu_cb.timer_reg[i].timer_cb(p_tle);
399 break;
400 }
401 }
402 break;
403 }
404 }
405
btu_general_alarm_cb(void * data)406 void btu_general_alarm_cb(void *data)
407 {
408 assert(data != NULL);
409 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
410
411 btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
412 }
413
btu_start_timer(TIMER_LIST_ENT * p_tle,UINT16 type,UINT32 timeout_sec)414 void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
415 {
416 osi_alarm_t *alarm = NULL;
417
418 assert(p_tle != NULL);
419
420 // Get the alarm for the timer list entry.
421 osi_mutex_lock(&btu_general_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
422 if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
423 alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0);
424 hash_map_set(btu_general_alarm_hash_map, p_tle, alarm);
425 }
426 osi_mutex_unlock(&btu_general_alarm_lock);
427
428 alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
429 if (alarm == NULL) {
430 HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
431 return;
432 }
433 osi_alarm_cancel(alarm);
434
435 p_tle->event = type;
436 // NOTE: This value is in seconds but stored in a ticks field.
437 p_tle->ticks = timeout_sec;
438 p_tle->in_use = 1;
439 osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
440 }
441
442
443 /*******************************************************************************
444 **
445 ** Function btu_stop_timer
446 **
447 ** Description Stop a timer.
448 **
449 ** Returns void
450 **
451 *******************************************************************************/
btu_stop_timer(TIMER_LIST_ENT * p_tle)452 void btu_stop_timer(TIMER_LIST_ENT *p_tle)
453 {
454 assert(p_tle != NULL);
455
456 if (p_tle->in_use == 0) {
457 return;
458 }
459 p_tle->in_use = 0;
460
461 // Get the alarm for the timer list entry.
462 osi_alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
463 if (alarm == NULL) {
464 HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
465 return;
466 }
467 osi_alarm_cancel(alarm);
468 }
469
470 /*******************************************************************************
471 **
472 ** Function btu_free_timer
473 **
474 ** Description Stop and free a timer.
475 **
476 ** Returns void
477 **
478 *******************************************************************************/
btu_free_timer(TIMER_LIST_ENT * p_tle)479 void btu_free_timer(TIMER_LIST_ENT *p_tle)
480 {
481 assert(p_tle != NULL);
482
483 p_tle->in_use = 0;
484
485 // Get the alarm for the timer list entry.
486 osi_alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
487 if (alarm == NULL) {
488 HCI_TRACE_DEBUG("%s Unable to find expected alarm in hashmap", __func__);
489 return;
490 }
491 osi_alarm_cancel(alarm);
492 hash_map_erase(btu_general_alarm_hash_map, p_tle);
493 }
494
495 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
496 /*******************************************************************************
497 **
498 ** Function btu_start_quick_timer
499 **
500 ** Description Start a timer for the specified amount of time in ticks.
501 **
502 ** Returns void
503 **
504 *******************************************************************************/
btu_l2cap_alarm_process(void * param)505 static void btu_l2cap_alarm_process(void *param)
506 {
507 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
508 assert(p_tle != NULL);
509
510 switch (p_tle->event) {
511 case BTU_TTYPE_L2CAP_CHNL: /* monitor or retransmission timer */
512 case BTU_TTYPE_L2CAP_FCR_ACK: /* ack timer */
513 l2c_process_timeout (p_tle);
514 break;
515
516 default:
517 break;
518 }
519 }
520
btu_l2cap_alarm_cb(void * data)521 static void btu_l2cap_alarm_cb(void *data)
522 {
523 assert(data != NULL);
524 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
525
526 btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
527 }
528
btu_start_quick_timer(TIMER_LIST_ENT * p_tle,UINT16 type,UINT32 timeout_ticks)529 void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks)
530 {
531 osi_alarm_t *alarm = NULL;
532
533 assert(p_tle != NULL);
534
535 // Get the alarm for the timer list entry.
536 osi_mutex_lock(&btu_l2cap_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
537 if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
538 alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0);
539 hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm);
540 }
541 osi_mutex_unlock(&btu_l2cap_alarm_lock);
542
543 alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
544 if (alarm == NULL) {
545 HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
546 return;
547 }
548 osi_alarm_cancel(alarm);
549
550 p_tle->event = type;
551 p_tle->ticks = timeout_ticks;
552 p_tle->in_use = 1;
553 // The quick timer ticks are 100ms long.
554 osi_alarm_set(alarm, (period_ms_t)(timeout_ticks * 100));
555 }
556
557 /*******************************************************************************
558 **
559 ** Function btu_stop_quick_timer
560 **
561 ** Description Stop a timer.
562 **
563 ** Returns void
564 **
565 *******************************************************************************/
btu_stop_quick_timer(TIMER_LIST_ENT * p_tle)566 void btu_stop_quick_timer(TIMER_LIST_ENT *p_tle)
567 {
568 assert(p_tle != NULL);
569
570 if (p_tle->in_use == 0) {
571 return;
572 }
573 p_tle->in_use = 0;
574
575 // Get the alarm for the timer list entry.
576 osi_alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
577 if (alarm == NULL) {
578 HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
579 return;
580 }
581 osi_alarm_cancel(alarm);
582 }
583
btu_free_quick_timer(TIMER_LIST_ENT * p_tle)584 void btu_free_quick_timer(TIMER_LIST_ENT *p_tle)
585 {
586 assert(p_tle != NULL);
587
588 p_tle->in_use = 0;
589
590 // Get the alarm for the timer list entry.
591 osi_alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
592 if (alarm == NULL) {
593 HCI_TRACE_DEBUG("%s Unable to find expected alarm in hashmap", __func__);
594 return;
595 }
596 osi_alarm_cancel(alarm);
597 hash_map_erase(btu_l2cap_alarm_hash_map, p_tle);
598 }
599
600 #endif /* defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) */
601
btu_oneshot_alarm_cb(void * data)602 void btu_oneshot_alarm_cb(void *data)
603 {
604 assert(data != NULL);
605 TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
606
607 btu_stop_timer_oneshot(p_tle);
608
609 btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
610 }
611
612 /*
613 * Starts a oneshot timer with a timeout in seconds.
614 */
btu_start_timer_oneshot(TIMER_LIST_ENT * p_tle,UINT16 type,UINT32 timeout_sec)615 void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
616 {
617 osi_alarm_t *alarm = NULL;
618
619 assert(p_tle != NULL);
620
621 // Get the alarm for the timer list entry.
622 osi_mutex_lock(&btu_oneshot_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
623 if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
624 alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0);
625 hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm);
626 }
627 osi_mutex_unlock(&btu_oneshot_alarm_lock);
628
629 alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
630 if (alarm == NULL) {
631 HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
632 return;
633 }
634 osi_alarm_cancel(alarm);
635
636 p_tle->event = type;
637 p_tle->in_use = 1;
638 // NOTE: This value is in seconds but stored in a ticks field.
639 p_tle->ticks = timeout_sec;
640 osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
641 }
642
btu_stop_timer_oneshot(TIMER_LIST_ENT * p_tle)643 void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle)
644 {
645 assert(p_tle != NULL);
646
647 if (p_tle->in_use == 0) {
648 return;
649 }
650 p_tle->in_use = 0;
651
652 // Get the alarm for the timer list entry.
653 osi_alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
654 if (alarm == NULL) {
655 HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
656 return;
657 }
658 osi_alarm_cancel(alarm);
659 }
660
661 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == 1)
662 /*******************************************************************************
663 **
664 ** Function btu_check_bt_sleep
665 **
666 ** Description This function is called to check if controller can go to sleep.
667 **
668 ** Returns void
669 **
670 *******************************************************************************/
btu_check_bt_sleep(void)671 void btu_check_bt_sleep (void)
672 {
673 // TODO(zachoverflow) take pending commands into account?
674 if (l2cb.controller_xmit_window == l2cb.num_lm_acl_bufs) {
675 bte_main_lpm_allow_bt_device_sleep();
676 }
677 }
678 #endif
679