2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "osi/alarm.h"
|
|
|
|
#include "osi/thread.h"
|
|
|
|
#include "common/bt_target.h"
|
|
|
|
#include "common/bt_trace.h"
|
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "osi/allocator.h"
|
|
|
|
#include "osi/mutex.h"
|
|
|
|
#include "stack/btm_api.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "btm_int.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/btu.h"
|
|
|
|
#include "osi/hash_map.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "l2c_int.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "osi/osi.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(SDP_INCLUDED) && SDP_INCLUDED == TRUE)
|
|
|
|
#include "sdpint.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/port_api.h"
|
|
|
|
#include "stack/port_ext.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
|
|
|
|
#include "gap_int.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE)
|
|
|
|
#include "bnep_int.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(PAN_INCLUDED) && PAN_INCLUDED == TRUE)
|
|
|
|
#include "pan_int.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE )
|
|
|
|
#include "hidh_int.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
|
|
|
|
#include "avdt_int.h"
|
|
|
|
#else
|
|
|
|
extern void avdt_rcv_sync_info (BT_HDR *p_buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(MCA_INCLUDED) && MCA_INCLUDED == TRUE)
|
|
|
|
#include "mca_api.h"
|
|
|
|
#include "mca_defs.h"
|
|
|
|
#include "mca_int.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "bta/bta_sys.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
|
|
|
#include "gatt_int.h"
|
|
|
|
#if (SMP_INCLUDED == TRUE)
|
|
|
|
#include "smp_int.h"
|
|
|
|
#endif
|
|
|
|
#include "btm_ble_int.h"
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 05:24:25 -04:00
|
|
|
typedef struct {
|
|
|
|
uint32_t sig;
|
|
|
|
void *param;
|
|
|
|
} btu_thread_evt_t;
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
//#if (defined(BT_APP_DEMO) && BT_APP_DEMO == TRUE)
|
|
|
|
//#include "bt_app_common.h"
|
|
|
|
//#endif
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
extern bt_status_t BTE_InitStack(void);
|
2018-03-15 02:36:49 -04:00
|
|
|
extern void BTE_DeinitStack(void);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Define BTU storage area
|
|
|
|
*/
|
|
|
|
#if BTU_DYNAMIC_MEMORY == FALSE
|
|
|
|
tBTU_CB btu_cb;
|
2017-10-18 03:34:43 -04:00
|
|
|
#else
|
|
|
|
tBTU_CB *btu_cb_ptr;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern hash_map_t *btu_general_alarm_hash_map;
|
2017-08-17 09:13:45 -04:00
|
|
|
extern osi_mutex_t btu_general_alarm_lock;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
// Oneshot timer queue.
|
|
|
|
extern hash_map_t *btu_oneshot_alarm_hash_map;
|
2017-08-17 09:13:45 -04:00
|
|
|
extern osi_mutex_t btu_oneshot_alarm_lock;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
// l2cap timer queue.
|
|
|
|
extern hash_map_t *btu_l2cap_alarm_hash_map;
|
2017-08-17 09:13:45 -04:00
|
|
|
extern osi_mutex_t btu_l2cap_alarm_lock;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2018-09-14 05:24:25 -04:00
|
|
|
extern void *btu_thread;
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
extern bluedroid_init_done_cb_t bluedroid_init_done_cb;
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Define a function prototype to allow a generic timeout handler */
|
|
|
|
typedef void (tUSER_TIMEOUT_FUNC) (TIMER_LIST_ENT *p_tle);
|
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_l2cap_alarm_process(void *param);
|
|
|
|
static void btu_general_alarm_process(void *param);
|
|
|
|
static void btu_hci_msg_process(void *param);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_bta_alarm_process(void *param);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_hci_msg_process(void *param)
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Determine the input message type. */
|
2019-06-20 23:55:45 -04:00
|
|
|
BT_HDR *p_msg = (BT_HDR *)param;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (p_msg->event & BT_EVT_MASK) {
|
|
|
|
case BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK: // TODO(zachoverflow): remove this
|
2017-04-20 21:31:40 -04:00
|
|
|
{
|
|
|
|
post_to_task_hack_t *ph = (post_to_task_hack_t *) &p_msg->data[0];
|
|
|
|
ph->callback(p_msg);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
2017-04-20 21:31:40 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
case BT_EVT_TO_BTU_HCI_ACL:
|
|
|
|
/* All Acl Data goes to L2CAP */
|
|
|
|
l2c_rcv_acl_data (p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BT_EVT_TO_BTU_L2C_SEG_XMIT:
|
|
|
|
/* L2CAP segment transmit complete */
|
|
|
|
l2c_link_segments_xmitted (p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BT_EVT_TO_BTU_HCI_SCO:
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
btm_route_sco_data (p_msg);
|
2019-10-09 05:24:30 -04:00
|
|
|
osi_free(p_msg);
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
case BT_EVT_TO_BTU_HCI_EVT:
|
|
|
|
btu_hcif_process_event ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_free(p_msg);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
/* If host receives events which it doesn't response to, */
|
|
|
|
/* host should start idle timer to enter sleep mode. */
|
|
|
|
btu_check_bt_sleep ();
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
case BT_EVT_TO_BTU_HCI_CMD:
|
|
|
|
btu_hcif_send_cmd ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
int i = 0;
|
|
|
|
uint16_t mask = (UINT16) (p_msg->event & BT_EVT_MASK);
|
|
|
|
BOOLEAN handled = FALSE;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
for (; !handled && i < BTU_MAX_REG_EVENT; i++) {
|
|
|
|
if (btu_cb.event_reg[i].event_cb == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask == btu_cb.event_reg[i].event_range) {
|
|
|
|
if (btu_cb.event_reg[i].event_cb) {
|
|
|
|
btu_cb.event_reg[i].event_cb(p_msg);
|
|
|
|
handled = TRUE;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (handled == FALSE) {
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_free (p_msg);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_bta_alarm_process(void *param)
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2019-06-20 23:55:45 -04:00
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
|
2016-09-26 09:37:39 -04:00
|
|
|
// call timer callback
|
|
|
|
if (p_tle->p_cback) {
|
|
|
|
(*p_tle->p_cback)(p_tle);
|
|
|
|
} else if (p_tle->event) {
|
|
|
|
BT_HDR *p_msg;
|
2017-08-17 09:13:45 -04:00
|
|
|
if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_msg->event = p_tle->event;
|
|
|
|
p_msg->layer_specific = 0;
|
2017-08-17 09:13:45 -04:00
|
|
|
//osi_free(p_msg);
|
2016-09-26 09:37:39 -04:00
|
|
|
bta_sys_sendmsg(p_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
bool btu_task_post(uint32_t sig, void *param, uint32_t timeout)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
2019-06-20 23:55:45 -04:00
|
|
|
bool status = false;
|
2018-09-14 05:24:25 -04:00
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
switch (sig) {
|
2018-09-14 05:24:25 -04:00
|
|
|
case SIG_BTU_START_UP:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, btu_task_start_up, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
|
|
|
case SIG_BTU_HCI_MSG:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, btu_hci_msg_process, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2018-09-14 05:24:25 -04:00
|
|
|
case SIG_BTU_BTA_MSG:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, bta_sys_event, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
|
|
|
case SIG_BTU_BTA_ALARM:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, btu_bta_alarm_process, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2018-09-14 05:24:25 -04:00
|
|
|
case SIG_BTU_GENERAL_ALARM:
|
|
|
|
case SIG_BTU_ONESHOT_ALARM:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, btu_general_alarm_process, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
|
|
|
case SIG_BTU_L2CAP_ALARM:
|
2019-06-20 23:55:45 -04:00
|
|
|
status = osi_thread_post(btu_thread, btu_l2cap_alarm_process, param, 0, timeout);
|
2018-09-14 05:24:25 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
return status;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2019-06-20 23:55:45 -04:00
|
|
|
void btu_task_start_up(void *param)
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2019-06-20 23:55:45 -04:00
|
|
|
UNUSED(param);
|
2016-11-24 13:10:15 -05:00
|
|
|
/* Initialize the mandatory core stack control blocks
|
|
|
|
(BTU, BTM, L2CAP, and SDP)
|
|
|
|
*/
|
|
|
|
btu_init_core();
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
/* Initialize any optional stack components */
|
|
|
|
BTE_InitStack();
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
bta_sys_init();
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Inform the bt jni thread initialization is ok.
|
|
|
|
// btif_transfer_context(btif_init_ok, 0, NULL, 0, NULL);
|
2016-09-27 09:38:07 -04:00
|
|
|
#if(defined(BT_APP_DEMO) && BT_APP_DEMO == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
if (bluedroid_init_done_cb) {
|
|
|
|
bluedroid_init_done_cb();
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_task_shut_down(void)
|
|
|
|
{
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
bta_sys_free();
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2018-03-15 02:36:49 -04:00
|
|
|
BTE_DeinitStack();
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
btu_free_core();
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_start_timer
|
|
|
|
**
|
|
|
|
** Description Start a timer for the specified amount of time.
|
|
|
|
** NOTE: The timeout resolution is in SECONDS! (Even
|
|
|
|
** though the timer structure field is ticks)
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_general_alarm_process(void *param)
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2019-06-20 23:55:45 -04:00
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
|
2016-09-26 09:37:39 -04:00
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
switch (p_tle->event) {
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_BTM_DEV_CTL:
|
|
|
|
btm_dev_timeout(p_tle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTU_TTYPE_L2CAP_LINK:
|
|
|
|
case BTU_TTYPE_L2CAP_CHNL:
|
|
|
|
case BTU_TTYPE_L2CAP_HOLD:
|
|
|
|
case BTU_TTYPE_L2CAP_INFO:
|
|
|
|
case BTU_TTYPE_L2CAP_FCR_ACK:
|
2017-06-02 01:09:23 -04:00
|
|
|
case BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS:
|
2016-11-24 13:10:15 -05:00
|
|
|
l2c_process_timeout (p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(SDP_INCLUDED) && SDP_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_SDP:
|
|
|
|
sdp_conn_timeout ((tCONN_CB *)p_tle->param);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_BTM_RMT_NAME:
|
|
|
|
btm_inq_rmt_name_failed();
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(RFCOMM_INCLUDED) && RFCOMM_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_RFCOMM_MFC:
|
|
|
|
case BTU_TTYPE_RFCOMM_PORT:
|
|
|
|
rfcomm_process_timeout (p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
#if ((defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE))
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_BNEP:
|
|
|
|
bnep_process_timeout(p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_AVDT_CCB_RET:
|
|
|
|
case BTU_TTYPE_AVDT_CCB_RSP:
|
|
|
|
case BTU_TTYPE_AVDT_CCB_IDLE:
|
|
|
|
case BTU_TTYPE_AVDT_SCB_TC:
|
|
|
|
avdt_process_timeout(p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_HID_HOST_REPAGE_TO :
|
|
|
|
hidh_proc_repage_timeout(p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_BLE_INQUIRY:
|
|
|
|
case BTU_TTYPE_BLE_GAP_LIM_DISC:
|
|
|
|
case BTU_TTYPE_BLE_RANDOM_ADDR:
|
|
|
|
case BTU_TTYPE_BLE_GAP_FAST_ADV:
|
2017-09-22 05:06:08 -04:00
|
|
|
case BTU_TTYPE_BLE_SCAN:
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_BLE_OBSERVE:
|
|
|
|
btm_ble_timeout(p_tle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTU_TTYPE_ATT_WAIT_FOR_RSP:
|
|
|
|
gatt_rsp_timeout(p_tle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTU_TTYPE_ATT_WAIT_FOR_IND_ACK:
|
|
|
|
gatt_ind_ack_timeout(p_tle);
|
|
|
|
break;
|
2017-06-14 06:08:03 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_SMP_PAIRING_CMD:
|
|
|
|
smp_rsp_timeout(p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (MCA_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_MCA_CCB_RSP:
|
|
|
|
mca_process_timeout(p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTU_TTYPE_USER_FUNC: {
|
|
|
|
tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
|
|
|
|
(*p_uf)(p_tle);
|
|
|
|
}
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
default:;
|
|
|
|
int i = 0;
|
|
|
|
BOOLEAN handled = FALSE;
|
|
|
|
|
|
|
|
for (; !handled && i < BTU_MAX_REG_TIMER; i++) {
|
|
|
|
if (btu_cb.timer_reg[i].timer_cb == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (btu_cb.timer_reg[i].p_tle == p_tle) {
|
|
|
|
btu_cb.timer_reg[i].timer_cb(p_tle);
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_general_alarm_cb(void *data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-04-17 23:57:28 -04:00
|
|
|
btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
|
|
|
|
{
|
|
|
|
osi_alarm_t *alarm = NULL;
|
|
|
|
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_lock(&btu_general_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
|
|
|
|
alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0);
|
|
|
|
hash_map_set(btu_general_alarm_hash_map, p_tle, alarm);
|
|
|
|
}
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_unlock(&btu_general_alarm_lock);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
|
|
|
|
|
|
|
p_tle->event = type;
|
|
|
|
// NOTE: This value is in seconds but stored in a ticks field.
|
|
|
|
p_tle->ticks = timeout_sec;
|
|
|
|
p_tle->in_use = TRUE;
|
|
|
|
osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2017-06-14 06:08:03 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_stop_timer
|
|
|
|
**
|
|
|
|
** Description Stop a timer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_stop_timer(TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
if (p_tle->in_use == FALSE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_tle->in_use = FALSE;
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
|
|
|
osi_alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2018-01-05 03:48:29 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_free_timer
|
|
|
|
**
|
|
|
|
** Description Stop and free a timer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btu_free_timer(TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
p_tle->in_use = FALSE;
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
|
|
|
osi_alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_DEBUG("%s Unable to find expected alarm in hashmap", __func__);
|
2018-01-05 03:48:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
|
|
|
hash_map_erase(btu_general_alarm_hash_map, p_tle);
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_start_quick_timer
|
|
|
|
**
|
|
|
|
** Description Start a timer for the specified amount of time in ticks.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2019-06-20 23:55:45 -04:00
|
|
|
static void btu_l2cap_alarm_process(void *param)
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2019-06-20 23:55:45 -04:00
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)param;
|
2016-11-24 13:10:15 -05:00
|
|
|
assert(p_tle != NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (p_tle->event) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTU_TTYPE_L2CAP_CHNL: /* monitor or retransmission timer */
|
|
|
|
case BTU_TTYPE_L2CAP_FCR_ACK: /* ack timer */
|
2016-11-24 13:10:15 -05:00
|
|
|
l2c_process_timeout (p_tle);
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
default:
|
2016-11-24 13:10:15 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static void btu_l2cap_alarm_cb(void *data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-04-17 23:57:28 -04:00
|
|
|
btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks)
|
|
|
|
{
|
|
|
|
osi_alarm_t *alarm = NULL;
|
|
|
|
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_lock(&btu_l2cap_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
|
|
|
|
alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0);
|
|
|
|
hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm);
|
|
|
|
}
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_unlock(&btu_l2cap_alarm_lock);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
|
|
|
|
|
|
|
p_tle->event = type;
|
|
|
|
p_tle->ticks = timeout_ticks;
|
|
|
|
p_tle->in_use = TRUE;
|
|
|
|
// The quick timer ticks are 100ms long.
|
|
|
|
osi_alarm_set(alarm, (period_ms_t)(timeout_ticks * 100));
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_stop_quick_timer
|
|
|
|
**
|
|
|
|
** Description Stop a timer.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_stop_quick_timer(TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
if (p_tle->in_use == FALSE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_tle->in_use = FALSE;
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
|
|
|
osi_alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2018-01-27 06:03:06 -05:00
|
|
|
|
|
|
|
void btu_free_quick_timer(TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
p_tle->in_use = FALSE;
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
|
|
|
osi_alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_DEBUG("%s Unable to find expected alarm in hashmap", __func__);
|
2018-01-27 06:03:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
|
|
|
hash_map_erase(btu_l2cap_alarm_hash_map, p_tle);
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif /* defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) */
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_oneshot_alarm_cb(void *data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
btu_stop_timer_oneshot(p_tle);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-04-17 23:57:28 -04:00
|
|
|
btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, OSI_THREAD_MAX_TIMEOUT);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Starts a oneshot timer with a timeout in seconds.
|
|
|
|
*/
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
|
|
|
|
{
|
|
|
|
osi_alarm_t *alarm = NULL;
|
|
|
|
|
|
|
|
assert(p_tle != NULL);
|
|
|
|
|
|
|
|
// Get the alarm for the timer list entry.
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_lock(&btu_oneshot_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
|
|
|
|
alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0);
|
|
|
|
hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm);
|
|
|
|
}
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_mutex_unlock(&btu_oneshot_alarm_lock);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_ERROR("%s Unable to create alarm", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
|
|
|
|
|
|
|
p_tle->event = type;
|
|
|
|
p_tle->in_use = TRUE;
|
|
|
|
// NOTE: This value is in seconds but stored in a ticks field.
|
|
|
|
p_tle->ticks = timeout_sec;
|
|
|
|
osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
assert(p_tle != NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_tle->in_use == FALSE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_tle->in_use = FALSE;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Get the alarm for the timer list entry.
|
|
|
|
osi_alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
|
|
|
|
if (alarm == NULL) {
|
2018-04-24 22:11:06 -04:00
|
|
|
HCI_TRACE_WARNING("%s Unable to find expected alarm in hashmap", __func__);
|
2016-11-24 13:10:15 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
osi_alarm_cancel(alarm);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btu_check_bt_sleep
|
|
|
|
**
|
|
|
|
** Description This function is called to check if controller can go to sleep.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btu_check_bt_sleep (void)
|
|
|
|
{
|
|
|
|
// TODO(zachoverflow) take pending commands into account?
|
2016-11-24 13:10:15 -05:00
|
|
|
if (l2cb.controller_xmit_window == l2cb.num_lm_acl_bufs) {
|
2016-09-26 09:37:39 -04:00
|
|
|
bte_main_lpm_allow_bt_device_sleep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|