Refactor the Bluetooth timers
* Updated the alarm API:
- Existing API alarm_new() is modified to take an alarm name
as an argument.
- New API alarm_new_periodic() is used to create a periodic
alarm.
- Added new API alarm_is_scheduled() to test whether an alarm is
scheduled.
- Existing API alarm_set_periodic() is removed: a periodic
alarm is created by alarm_new_periodic().
- Added new API alarm_set_on_queue() to set an alarm whose
callback is executed on a specific queue.
- Added new API alarm_register_processing_queue() and
alarm_unregister_processing_queue() to register/unregister
a queue and the corresponding thread for alarm processing.
- Added corresponding unit tests.
* Updated the alarm internals:
- Added alarm_info_t for collecting alarm-related information
and statistics.
- Collect and store alarm-related statistics into alarm_info_t
per alarm.
- Include the alarm-related statistics and info into the native
dumpsys output for Bluetooth.
- Once an alarm expires, the alarm execution is scheduled for
processing on another internal alarm-specific thread, not
on the thread that is maintaining the alarms.
- Implemented callback execution ordering guarantee among
timers on the same thread with exactly same timeout values.
* Refactor some of the usage of alarm_set() and simplify the
code by using alarm_set_on_queue() instead.
* Removed the non_repeating timers wrapper, and use directly
the alarm mechanism / API.
* Refactored all timer_entry_t timers and replaced them with alarm_t
timers:
- Replaced the btu_start_timer() / btu_stop_timer() /
btu_start_quick_timer() / btu_stop_quick_timer() /
btu_oneshot_alarm() mechanism with alarm_set_on_queue() and
alarm_cancel()
- Removed the whole mechanism around the BTU_TTYPE_* timers.
* Fixed a bug when processing the GATT indication confirmation timer
expiration (timer tGATT_TCB.conf_timer: b/26610829).
* Renamed and/or split misc. timeout functions, fields, and timers
* Renamed time-related constants and changed the values from seconds
to milliseconds
* Replaced timer tAVDT_CCB.timer_entry with three mutually exclusive timers:
idle_ccb_timer, ret_ccb_timer, rsp_ccb_timer
The reason we are using three timers, is because in the original code
function avdt_ccb_chk_timer() used the timer type in its logic: it
would stop the timer only if the type is "idle".
* Removed btm_ble_timeout() and replaced it with multiple timeout
callback functions (per timer)
* Fix the actual value of the global constant BT_1SEC_TIMEOUT and
rename it to BT_1SEC_TIMEOUT_MS
* Removed btu_cb and associated timers and events, because they are
never used.
* Removed unused timers, functions, struct and declarations that are
not used / needed.
Bug: 26611369
Bug: 26610829
Change-Id: I812c8c31710a5daefc58b01fcf35c353768f390f
diff --git a/bta/ag/bta_ag_act.c b/bta/ag/bta_ag_act.c
index 8a28cfb..6bbab4b 100644
--- a/bta/ag/bta_ag_act.c
+++ b/bta/ag/bta_ag_act.c
@@ -430,9 +430,9 @@
bta_ag_at_reinit(&p_scb->at_cb);
/* stop timers */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
#if (BTM_WBS_INCLUDED == TRUE)
- bta_sys_stop_timer(&p_scb->cn_timer);
+ alarm_cancel(p_scb->codec_negotiation_timer);
#endif
close.hdr.handle = bta_ag_scb_to_idx(p_scb);
@@ -522,13 +522,11 @@
bta_ag_cback_open(p_scb, NULL, BTA_AG_SUCCESS);
- if (p_scb->conn_service == BTA_AG_HFP)
- {
+ if (p_scb->conn_service == BTA_AG_HFP) {
/* if hfp start timer for service level conn */
- bta_sys_start_timer(&p_scb->act_timer, BTA_AG_SVC_TOUT_EVT, p_bta_ag_cfg->conn_tout);
- }
- else
- {
+ bta_sys_start_timer(p_scb->ring_timer, p_bta_ag_cfg->conn_tout,
+ BTA_AG_SVC_TIMEOUT_EVT, bta_ag_scb_to_idx(p_scb));
+ } else {
/* else service level conn is open */
bta_ag_svc_conn_open(p_scb, p_data);
}
@@ -567,11 +565,9 @@
/* Collision Handling */
for (i = 0, ag_scb = &bta_ag_cb.scb[0]; i < BTA_AG_NUM_SCB; i++, ag_scb++)
{
- if ((ag_scb->in_use) && (ag_scb->colli_tmr_on))
+ if (ag_scb->in_use && alarm_is_scheduled(ag_scb->collision_timer))
{
- /* stop collision timer */
- ag_scb->colli_tmr_on = FALSE;
- bta_sys_stop_timer (&ag_scb->colli_timer);
+ alarm_cancel(ag_scb->collision_timer);
if (bdcmp (dev_addr, ag_scb->peer_addr) == 0)
{
@@ -814,8 +810,7 @@
/* Clear AT+BIA mask from previous SLC if any. */
p_scb->bia_masked_out = 0;
- /* stop timer */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
/* call callback */
evt.hdr.handle = bta_ag_scb_to_idx(p_scb);
diff --git a/bta/ag/bta_ag_cmd.c b/bta/ag/bta_ag_cmd.c
index 89074ca..3439535 100644
--- a/bta/ag/bta_ag_cmd.c
+++ b/bta/ag/bta_ag_cmd.c
@@ -41,8 +41,8 @@
** Constants
*****************************************************************************/
-/* ring timeout */
-#define BTA_AG_RING_TOUT 5000
+/* Ring timeout */
+#define BTA_AG_RING_TIMEOUT_MS (5 * 1000) /* 5 seconds */
#define BTA_AG_CMD_MAX_VAL 32767 /* Maximum value is signed 16-bit value */
@@ -1249,9 +1249,7 @@
case BTA_AG_HF_CMD_BCS:
bta_ag_send_ok(p_scb);
-
- /* stop cn timer */
- bta_sys_stop_timer(&p_scb->cn_timer);
+ alarm_cancel(p_scb->codec_negotiation_timer);
switch(int_arg)
{
@@ -1383,7 +1381,7 @@
/* if incoming call connected stop ring timer */
if (p_result->result == BTA_AG_IN_CALL_CONN_RES)
{
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
}
if (!(p_scb->features & BTA_AG_FEAT_NOSCO))
@@ -1402,8 +1400,7 @@
break;
case BTA_AG_END_CALL_RES:
- /* stop ring timer */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
/* close sco */
if ((bta_ag_sco_is_open(p_scb) || bta_ag_sco_is_opening(p_scb)) && !(p_scb->features & BTA_AG_FEAT_NOSCO))
@@ -1513,8 +1510,7 @@
break;
case BTA_AG_IN_CALL_CONN_RES:
- /* stop ring timer */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
/* if sco not opened and we need to open it, send indicators first
** then open sco.
@@ -1536,8 +1532,7 @@
break;
case BTA_AG_IN_CALL_HELD_RES:
- /* stop ring timer */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
bta_ag_send_call_inds(p_scb, p_result->result);
@@ -1598,8 +1593,7 @@
break;
case BTA_AG_END_CALL_RES:
- /* stop ring timer */
- bta_sys_stop_timer(&p_scb->act_timer);
+ alarm_cancel(p_scb->ring_timer);
/* if sco open, close sco then send indicator values */
if ((bta_ag_sco_is_open(p_scb) || bta_ag_sco_is_opening(p_scb)) && !(p_scb->features & BTA_AG_FEAT_NOSCO))
@@ -1828,8 +1822,6 @@
}
#endif
- /* restart ring timer */
- bta_sys_start_timer(&p_scb->act_timer, BTA_AG_RING_TOUT_EVT, BTA_AG_RING_TOUT);
+ bta_sys_start_timer(p_scb->ring_timer, BTA_AG_RING_TIMEOUT_MS,
+ BTA_AG_RING_TIMEOUT_EVT, bta_ag_scb_to_idx(p_scb));
}
-
-
diff --git a/bta/ag/bta_ag_int.h b/bta/ag/bta_ag_int.h
index 55ae45e..a95f0a8 100644
--- a/bta/ag/bta_ag_int.h
+++ b/bta/ag/bta_ag_int.h
@@ -54,9 +54,9 @@
#define BTA_AG_NUM_SCB 2
#endif
-/* Timer to wait for retry in case of collision */
-#ifndef BTA_AG_COLLISION_TIMER
-#define BTA_AG_COLLISION_TIMER 2000
+/* Time to wait for retry in case of collision */
+#ifndef BTA_AG_COLLISION_TIMEOUT_MS
+#define BTA_AG_COLLISION_TIMEOUT_MS (2 * 1000) /* 2 seconds */
#endif
/* RFCOMM MTU SIZE */
@@ -105,8 +105,8 @@
BTA_AG_DISC_OK_EVT,
BTA_AG_DISC_FAIL_EVT,
BTA_AG_CI_RX_WRITE_EVT,
- BTA_AG_RING_TOUT_EVT,
- BTA_AG_SVC_TOUT_EVT,
+ BTA_AG_RING_TIMEOUT_EVT,
+ BTA_AG_SVC_TIMEOUT_EVT,
BTA_AG_CI_SCO_DATA_EVT,
BTA_AG_CI_SLC_READY_EVT,
BTA_AG_MAX_EVT,
@@ -251,7 +251,6 @@
char clip[BTA_AG_AT_MAX_LEN+1]; /* number string used for CLIP */
UINT16 serv_handle[BTA_AG_NUM_IDX]; /* RFCOMM server handles */
tBTA_AG_AT_CB at_cb; /* AT command interpreter */
- timer_entry_t act_timer; /* ring timer */
BD_ADDR peer_addr; /* peer bd address */
tSDP_DISCOVERY_DB *p_disc_db; /* pointer to discovery database */
tBTA_SERVICE_MASK reg_services; /* services specified in register API */
@@ -263,15 +262,6 @@
tBTA_AG_PEER_FEAT peer_features; /* peer device features */
UINT16 peer_version; /* profile version of peer device */
UINT16 hsp_version; /* HSP profile version */
-#if (BTM_WBS_INCLUDED == TRUE )
- tBTA_AG_PEER_CODEC peer_codecs; /* codecs for eSCO supported by the peer */
- tBTA_AG_PEER_CODEC sco_codec; /* codec to be used for eSCO connection */
- tBTA_AG_PEER_CODEC inuse_codec; /* codec being used for the current SCO connection */
- BOOLEAN codec_updated; /* set to TRUE whenever the app updates codec type */
- BOOLEAN codec_fallback; /* If sco nego fails for mSBC, fallback to CVSD */
- tBTA_AG_SCO_MSBC_SETTINGS codec_msbc_settings; /* settings to be used for the impending eSCO */
- timer_entry_t cn_timer; /* codec negotiation timer */
-#endif
UINT16 sco_idx; /* SCO handle */
BOOLEAN in_use; /* scb in use */
BOOLEAN dealloc; /* TRUE if service shutting down */
@@ -281,8 +271,6 @@
BOOLEAN cmee_enabled; /* set to TRUE if HF enables CME ERROR reporting */
BOOLEAN inband_enabled; /* set to TRUE if inband ring enabled */
BOOLEAN svc_conn; /* set to TRUE when service level connection up */
- timer_entry_t colli_timer; /* Collision timer */
- BOOLEAN colli_tmr_on; /* TRUE if collision timer is active */
UINT8 state; /* state machine state */
UINT8 conn_service; /* connected service */
UINT8 peer_scn; /* peer scn */
@@ -298,6 +286,18 @@
UINT8 callheld_ind; /* CIEV call held indicator value */
BOOLEAN retry_with_sco_only; /* indicator to try with SCO only when eSCO fails */
UINT32 bia_masked_out; /* indicators HF does not want us to send */
+ alarm_t *collision_timer;
+ alarm_t *ring_timer;
+#if (BTM_WBS_INCLUDED == TRUE)
+ alarm_t *codec_negotiation_timer;
+ tBTA_AG_PEER_CODEC peer_codecs; /* codecs for eSCO supported by the peer */
+ tBTA_AG_PEER_CODEC sco_codec; /* codec to be used for eSCO connection */
+ tBTA_AG_PEER_CODEC inuse_codec; /* codec being used for the current SCO connection */
+ BOOLEAN codec_updated; /* set to TRUE whenever the app updates codec type */
+ BOOLEAN codec_fallback; /* If sco nego fails for mSBC, fallback to CVSD */
+ tBTA_AG_SCO_MSBC_SETTINGS codec_msbc_settings; /* settings to be used for the impending eSCO */
+#endif
+
} tBTA_AG_SCB;
/* type for sco data */
diff --git a/bta/ag/bta_ag_main.c b/bta/ag/bta_ag_main.c
index cd85261..606b531 100644
--- a/bta/ag/bta_ag_main.c
+++ b/bta/ag/bta_ag_main.c
@@ -36,6 +36,8 @@
#define BTA_AG_DEBUG FALSE
#endif
+extern fixed_queue_t *btu_bta_alarm_queue;
+
#if BTA_AG_DEBUG == TRUE
static char *bta_ag_evt_str(UINT16 event, tBTA_AG_RES result);
static char *bta_ag_state_str(UINT8 state);
@@ -274,29 +276,6 @@
/*******************************************************************************
**
-** Function bta_ag_timer_cback
-**
-** Description AG timer callback.
-**
-**
-** Returns void
-**
-*******************************************************************************/
-static void bta_ag_timer_cback(void *p)
-{
- BT_HDR *p_buf;
- timer_entry_t *p_te = (timer_entry_t *) p;
-
- if ((p_buf = (BT_HDR *) osi_getbuf(sizeof(BT_HDR))) != NULL)
- {
- p_buf->event = p_te->event;
- p_buf->layer_specific = bta_ag_scb_to_idx((tBTA_AG_SCB *) p_te->param);
- bta_sys_sendmsg(p_buf);
- }
-}
-
-/*******************************************************************************
-**
** Function bta_ag_scb_alloc
**
** Description Allocate an AG service control block.
@@ -321,9 +300,11 @@
p_scb->codec_updated = FALSE;
#endif
/* set up timers */
- p_scb->act_timer.param = p_scb;
- p_scb->act_timer.p_cback = bta_ag_timer_cback;
+ p_scb->ring_timer = alarm_new("bta_ag.scb_ring_timer");
+ p_scb->collision_timer = alarm_new("bta_ag.scb_collision_timer");
#if (BTM_WBS_INCLUDED == TRUE)
+ p_scb->codec_negotiation_timer =
+ alarm_new("bta_ag.scb_codec_negotiation_timer");
/* set eSCO mSBC setting to T2 as the preferred */
p_scb->codec_msbc_settings = BTA_AG_SCO_MSBC_SETTINGS_T2;
#endif
@@ -358,12 +339,12 @@
APPL_TRACE_DEBUG("bta_ag_scb_dealloc %d", bta_ag_scb_to_idx(p_scb));
- /* stop timers */
- bta_sys_stop_timer(&p_scb->act_timer);
+ /* stop and free timers */
+ alarm_free(p_scb->ring_timer);
#if (BTM_WBS_INCLUDED == TRUE)
- bta_sys_stop_timer(&p_scb->cn_timer);
+ alarm_free(p_scb->codec_negotiation_timer);
#endif
- bta_sys_stop_timer(&p_scb->colli_timer);
+ alarm_free(p_scb->collision_timer);
/* initialize control block */
memset(p_scb, 0, sizeof(tBTA_AG_SCB));
@@ -568,7 +549,7 @@
/*******************************************************************************
**
-** Function bta_ag_colli_timer_cback
+** Function bta_ag_collision_timer_cback
**
** Description AG connection collision timer callback
**
@@ -576,25 +557,15 @@
** Returns void
**
*******************************************************************************/
-static void bta_ag_colli_timer_cback (timer_entry_t *p_te)
+static void bta_ag_collision_timer_cback(void *data)
{
- tBTA_AG_SCB *p_scb;
+ tBTA_AG_SCB *p_scb = (tBTA_AG_SCB *)data;
- APPL_TRACE_DEBUG ("bta_ag_colli_timer_cback");
+ APPL_TRACE_DEBUG("%s", __func__);
- if (p_te)
- {
- p_scb = (tBTA_AG_SCB *)p_te->param;
-
- if (p_scb)
- {
- p_scb->colli_tmr_on = FALSE;
-
- /* If the peer haven't opened AG connection */
- /* we will restart opening process. */
- bta_ag_resume_open (p_scb);
- }
- }
+ /* If the peer haven't opened AG connection */
+ /* we will restart opening process. */
+ bta_ag_resume_open(p_scb);
}
/*******************************************************************************
@@ -649,13 +620,10 @@
bta_ag_start_servers(p_scb, p_scb->reg_services);
/* Start timer to han */
- p_scb->colli_timer.p_cback =
- (timer_callback_t *)&bta_ag_colli_timer_cback;
- p_scb->colli_timer.param = p_scb;
- bta_sys_start_timer(&p_scb->colli_timer, 0, BTA_AG_COLLISION_TIMER);
- p_scb->colli_tmr_on = TRUE;
+ alarm_set_on_queue(p_scb->collision_timer, BTA_AG_COLLISION_TIMEOUT_MS,
+ bta_ag_collision_timer_cback, p_scb,
+ btu_bta_alarm_queue);
}
-
}
/*******************************************************************************
@@ -700,6 +668,13 @@
static void bta_ag_api_enable(tBTA_AG_DATA *p_data)
{
/* initialize control block */
+ for (size_t i = 0; i < BTA_AG_NUM_SCB; i++) {
+ alarm_free(bta_ag_cb.scb[i].ring_timer);
+#if (BTM_WBS_INCLUDED == TRUE)
+ alarm_free(bta_ag_cb.scb[i].codec_negotiation_timer);
+#endif
+ alarm_free(bta_ag_cb.scb[i].collision_timer);
+ }
memset(&bta_ag_cb, 0, sizeof(tBTA_AG_CB));
/* store callback function */
@@ -1007,9 +982,9 @@
return "Discovery Failed";
case BTA_AG_CI_RX_WRITE_EVT:
return "CI RX Write";
- case BTA_AG_RING_TOUT_EVT:
+ case BTA_AG_RING_TIMEOUT_EVT:
return "Ring Timeout";
- case BTA_AG_SVC_TOUT_EVT:
+ case BTA_AG_SVC_TIMEOUT_EVT:
return "Service Timeout";
case BTA_AG_API_ENABLE_EVT:
return "Enable AG";
diff --git a/bta/ag/bta_ag_sco.c b/bta/ag/bta_ag_sco.c
index 3a3abee..89c103d 100644
--- a/bta/ag/bta_ag_sco.c
+++ b/bta/ag/bta_ag_sco.c
@@ -38,10 +38,13 @@
#define BTA_AG_SCO_DEBUG FALSE
#endif
-#ifndef BTA_AG_CODEC_NEGO_TIMEOUT
-#define BTA_AG_CODEC_NEGO_TIMEOUT 3000
+/* Codec negotiation timeout */
+#ifndef BTA_AG_CODEC_NEGOTIATION_TIMEOUT_MS
+#define BTA_AG_CODEC_NEGOTIATION_TIMEOUT_MS (3 * 1000) /* 3 seconds */
#endif
+extern fixed_queue_t *btu_bta_alarm_queue;
+
#if BTA_AG_SCO_DEBUG == TRUE
static char *bta_ag_sco_evt_str(UINT8 event);
static char *bta_ag_sco_state_str(UINT8 state);
@@ -640,7 +643,7 @@
/*******************************************************************************
**
-** Function bta_ag_cn_timer_cback
+** Function bta_ag_codec_negotiation_timer_cback
**
** Description
**
@@ -648,23 +651,15 @@
** Returns void
**
*******************************************************************************/
-static void bta_ag_cn_timer_cback (timer_entry_t *p_te)
+static void bta_ag_codec_negotiation_timer_cback(void *data)
{
- tBTA_AG_SCB *p_scb;
+ tBTA_AG_SCB *p_scb = (tBTA_AG_SCB *)data;
- if (p_te)
- {
- p_scb = (tBTA_AG_SCB *)p_te->param;
+ /* Announce that codec negotiation failed. */
+ bta_ag_sco_codec_nego(p_scb, FALSE);
- if (p_scb)
- {
- /* Announce that codec negotiation failed. */
- bta_ag_sco_codec_nego(p_scb, FALSE);
-
- /* call app callback */
- bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_CLOSE_EVT);
- }
- }
+ /* call app callback */
+ bta_ag_cback_sco(p_scb, BTA_AG_AUDIO_CLOSE_EVT);
}
/*******************************************************************************
@@ -692,9 +687,11 @@
bta_ag_send_bcs(p_scb, NULL);
/* Start timer to handle timeout */
- p_scb->cn_timer.p_cback = (timer_callback_t *)&bta_ag_cn_timer_cback;
- p_scb->cn_timer.param = p_scb;
- bta_sys_start_timer(&p_scb->cn_timer, 0, BTA_AG_CODEC_NEGO_TIMEOUT);
+ alarm_set_on_queue(p_scb->codec_negotiation_timer,
+ BTA_AG_CODEC_NEGOTIATION_TIMEOUT_MS,
+ bta_ag_codec_negotiation_timer_cback,
+ p_scb,
+ btu_bta_alarm_queue);
}
else
{
diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c
index 137767e..69aca94 100644
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -349,14 +349,16 @@
APPL_TRACE_DEBUG("bta_av_st_rc_timer rc_handle:%d, use_rc: %d",
p_scb->rc_handle, p_scb->use_rc);
/* for outgoing RC connection as INT/CT */
- if( (p_scb->rc_handle == BTA_AV_RC_HANDLE_NONE) &&
- /*(bta_av_cb.features & BTA_AV_FEAT_RCCT) &&*/
- (p_scb->use_rc == TRUE || (p_scb->role & BTA_AV_ROLE_AD_ACP)) )
+ if ((p_scb->rc_handle == BTA_AV_RC_HANDLE_NONE) &&
+ /* (bta_av_cb.features & BTA_AV_FEAT_RCCT) && */
+ (p_scb->use_rc == TRUE || (p_scb->role & BTA_AV_ROLE_AD_ACP)))
{
- if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0)
- bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
- else
+ if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0) {
+ bta_sys_start_timer(p_scb->avrc_ct_timer, BTA_AV_RC_DISC_TIME_VAL,
+ BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
+ } else {
p_scb->wait |= BTA_AV_WAIT_CHECK_RC;
+ }
}
}
@@ -994,7 +996,8 @@
if (p_scb->wait & BTA_AV_WAIT_CHECK_RC)
{
p_scb->wait &= ~BTA_AV_WAIT_CHECK_RC;
- bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
+ bta_sys_start_timer(p_scb->avrc_ct_timer, BTA_AV_RC_DISC_TIME_VAL,
+ BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
}
if (bta_av_cb.features & BTA_AV_FEAT_MASTER)
@@ -1083,7 +1086,7 @@
p_scb->cur_psc_mask = 0;
p_scb->wait = 0;
p_scb->num_disc_snks = 0;
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
vendor_get_interface()->send_command(BT_VND_OP_A2DP_OFFLOAD_STOP, (void*)&p_scb->l2c_cid);
if (p_scb->offload_start_pending) {
@@ -1155,7 +1158,7 @@
/* Clear collision mask */
p_scb->coll_mask = 0;
- bta_sys_stop_timer(&bta_av_cb.acp_sig_tmr);
+ alarm_cancel(bta_av_cb.accept_signalling_timer);
/* if no codec parameters in configuration, fail */
if ((p_evt_cfg->num_codec == 0) ||
@@ -1230,19 +1233,17 @@
tBTA_AV_RCB *p_rcb;
UNUSED(p_data);
- APPL_TRACE_DEBUG("bta_av_disconnect_req conn_lcb: 0x%x", bta_av_cb.conn_lcb);
+ APPL_TRACE_DEBUG("%s conn_lcb: 0x%x", __func__, bta_av_cb.conn_lcb);
- bta_sys_stop_timer(&bta_av_cb.sig_tmr);
- bta_sys_stop_timer(&p_scb->timer);
- if(bta_av_cb.conn_lcb)
- {
+ alarm_cancel(bta_av_cb.link_signalling_timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
+
+ if (bta_av_cb.conn_lcb) {
p_rcb = bta_av_get_rcb_by_shdl((UINT8)(p_scb->hdi + 1));
if (p_rcb)
bta_av_del_rc(p_rcb);
AVDT_DisconnectReq(p_scb->peer_addr, bta_av_dt_cback[p_scb->hdi]);
- }
- else
- {
+ } else {
bta_av_ssm_execute(p_scb, BTA_AV_AVDT_DISCONNECT_EVT, NULL);
}
}
@@ -1323,7 +1324,7 @@
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, p_data->ci_setconfig.err_code,
p_data->ci_setconfig.category);
- bta_sys_stop_timer(&bta_av_cb.sig_tmr);
+ alarm_cancel(bta_av_cb.link_signalling_timer);
if(p_data->ci_setconfig.err_code == AVDT_SUCCESS)
{
@@ -1547,7 +1548,7 @@
{
bta_av_str_stopped(p_scb, NULL);
}
- bta_sys_stop_timer(&bta_av_cb.sig_tmr);
+ alarm_cancel(bta_av_cb.link_signalling_timer);
/* close stream */
p_scb->started = FALSE;
@@ -1560,10 +1561,8 @@
* for whatever reason the the close request can not be sent in time.
* when this timer expires, AVDT_DisconnectReq will be called to disconnect the link
*/
- bta_sys_start_timer(&p_scb->timer,
- (UINT16)BTA_AV_API_CLOSE_EVT,
- BTA_AV_CLOSE_REQ_TIME_VAL);
-
+ bta_sys_start_timer(p_scb->avrc_ct_timer, BTA_AV_CLOSE_REQ_TIME_VAL,
+ BTA_AV_API_CLOSE_EVT, p_scb->hndl);
}
/*******************************************************************************
@@ -2190,8 +2189,7 @@
return;
}
- /*if(bta_av_cb.features & BTA_AV_FEAT_RCCT)*/
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
memcpy(p_cfg, &p_scb->cfg, sizeof(tAVDT_CFG));
p_cfg->num_protect = p_rcfg->num_protect;
@@ -3051,7 +3049,7 @@
if (!bta_av_link_role_ok(p_scb, A2D_SET_ONE_BIT))
{
APPL_TRACE_ERROR ("failed to start streaming for role management reasons!!");
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
start.chnl = p_scb->chnl;
start.status = BTA_AV_FAIL_ROLE;
start.initiator = TRUE;
@@ -3078,10 +3076,13 @@
if(p_scb->rc_handle == BTA_AV_RC_HANDLE_NONE)
{
/* AVRC channel is not connected. delay a little bit */
- if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0)
- bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RC_DISC_TIME_VAL);
- else
+ if ((p_scb->wait & BTA_AV_WAIT_ROLE_SW_BITS) == 0) {
+ bta_sys_start_timer(p_scb->avrc_ct_timer,
+ BTA_AV_RC_DISC_TIME_VAL,
+ BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
+ } else {
p_scb->wait |= BTA_AV_WAIT_CHECK_RC;
+ }
}
}
else
diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c
index fad6e23..1310a26 100644
--- a/bta/av/bta_av_act.c
+++ b/bta/av/bta_av_act.c
@@ -52,18 +52,20 @@
/*****************************************************************************
** Constants
*****************************************************************************/
-/* the timer in milliseconds to wait for open req after setconfig for incoming connections */
-#ifndef BTA_AV_SIG_TIME_VAL
-#define BTA_AV_SIG_TIME_VAL 8000
+/* the timeout to wait for open req after setconfig for incoming connections */
+#ifndef BTA_AV_SIGNALLING_TIMEOUT_MS
+#define BTA_AV_SIGNALLING_TIMEOUT_MS (8 * 1000) /* 8 seconds */
#endif
-/* In millisec to wait for signalling from SNK when it is initiated from SNK. */
-/* If not, we will start signalling from SRC. */
-#ifndef BTA_AV_ACP_SIG_TIME_VAL
-#define BTA_AV_ACP_SIG_TIME_VAL 2000
+/* Time to wait for signalling from SNK when it is initiated from SNK. */
+/* If not, we will start signalling from SRC. */
+#ifndef BTA_AV_ACCEPT_SIGNALLING_TIMEOUT_MS
+#define BTA_AV_ACCEPT_SIGNALLING_TIMEOUT_MS (2 * 1000) /* 2 seconds */
#endif
-static void bta_av_acp_sig_timer_cback(timer_entry_t *p_te);
+extern fixed_queue_t *btu_bta_alarm_queue;
+
+static void bta_av_accept_signalling_timer_cback(void *data);
/*******************************************************************************
**
@@ -123,7 +125,7 @@
p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE;
/* just in case the RC timer is active
if (bta_av_cb.features & BTA_AV_FEAT_RCCT && p_scb->chnl == BTA_AV_CHNL_AUDIO) */
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
}
}
@@ -512,7 +514,7 @@
APPL_TRACE_DEBUG("bta_av_rc_opened shdl:%d, srch %d", i + 1, p_scb->rc_handle);
shdl = i+1;
LOG_INFO(LOG_TAG, "%s allow incoming AVRCP connections:%d", __func__, p_scb->use_rc);
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
disc = p_scb->hndl;
break;
}
@@ -1077,7 +1079,7 @@
/* just in case the RC timer is active
if (bta_av_cb.features & BTA_AV_FEAT_RCCT &&
p_scb->chnl == BTA_AV_CHNL_AUDIO) */
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
}
}
@@ -1326,7 +1328,7 @@
/* just in case the RC timer is active
if (p_cb->features & BTA_AV_FEAT_RCCT) */
{
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
}
/* one audio channel goes down. check if we need to restore high priority */
chk_restore = TRUE;
@@ -1433,7 +1435,7 @@
void bta_av_api_disconnect(tBTA_AV_DATA *p_data)
{
AVDT_DisconnectReq(p_data->api_discnt.bd_addr, bta_av_conn_cback);
- bta_sys_stop_timer(&bta_av_cb.sig_tmr);
+ alarm_cancel(bta_av_cb.link_signalling_timer);
}
/*******************************************************************************
@@ -1449,7 +1451,7 @@
{
UINT16 event = p_data->str_msg.hdr.layer_specific;
tBTA_AV_CB *p_cb = &bta_av_cb;
- int xx;
+ UINT32 xx;
UINT8 mask;
tBTA_AV_LCB *p_lcb = NULL;
@@ -1489,22 +1491,18 @@
/* The Pending Event should be sent as soon as the L2CAP signalling channel
* is set up, which is NOW. Earlier this was done only after
- * BTA_AV_SIG_TIME_VAL milliseconds.
+ * BTA_AV_SIGNALLING_TIMEOUT_MS.
* The following function shall send the event and start the recurring timer
*/
- bta_av_sig_timer(NULL);
+ bta_av_signalling_timer(NULL);
/* Possible collision : need to avoid outgoing processing while the timer is running */
p_cb->p_scb[xx]->coll_mask = BTA_AV_COLL_INC_TMR;
-
- // TODO(armansito): Why is this variable called "xx" and
- // why is it a signed integer? The callback reinterprets
- // it as a UINT8 and then reassigns it as param that
- // way, so should this be unsigned?
- p_cb->acp_sig_tmr.param = INT_TO_PTR(xx);
- p_cb->acp_sig_tmr.p_cback =
- (timer_callback_t *)&bta_av_acp_sig_timer_cback;
- bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
+ alarm_set_on_queue(p_cb->accept_signalling_timer,
+ BTA_AV_ACCEPT_SIGNALLING_TIMEOUT_MS,
+ bta_av_accept_signalling_timer_cback,
+ UINT_TO_PTR(xx),
+ btu_bta_alarm_queue);
}
break;
}
@@ -1524,7 +1522,7 @@
#if ( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
else if (event == BTA_AR_AVDT_CONN_EVT)
{
- bta_sys_stop_timer(&bta_av_cb.sig_tmr);
+ alarm_cancel(bta_av_cb.link_signalling_timer);
}
#endif
else
@@ -1551,16 +1549,17 @@
/*******************************************************************************
**
-** Function bta_av_sig_timer
+** Function bta_av_signalling_timer
**
** Description process the signal channel timer. This timer is started
** when the AVDTP signal channel is connected. If no profile
-** is connected, the timer goes off every BTA_AV_SIG_TIME_VAL
+** is connected, the timer goes off every
+** BTA_AV_SIGNALLING_TIMEOUT_MS.
**
** Returns void
**
*******************************************************************************/
-void bta_av_sig_timer(tBTA_AV_DATA *p_data)
+void bta_av_signalling_timer(tBTA_AV_DATA *p_data)
{
tBTA_AV_CB *p_cb = &bta_av_cb;
int xx;
@@ -1569,7 +1568,7 @@
tBTA_AV_PEND pend;
UNUSED(p_data);
- APPL_TRACE_DEBUG("bta_av_sig_timer");
+ APPL_TRACE_DEBUG("%s", __func__);
for(xx=0; xx<BTA_AV_NUM_LINKS; xx++)
{
mask = 1 << xx;
@@ -1577,9 +1576,10 @@
{
/* this entry is used. check if it is connected */
p_lcb = &p_cb->lcb[xx];
- if (!p_lcb->conn_msk)
- {
- bta_sys_start_timer(&p_cb->sig_tmr, BTA_AV_SIG_TIMER_EVT, BTA_AV_SIG_TIME_VAL);
+ if (!p_lcb->conn_msk) {
+ bta_sys_start_timer(p_cb->link_signalling_timer,
+ BTA_AV_SIGNALLING_TIMEOUT_MS,
+ BTA_AV_SIGNALLING_TIMER_EVT, 0);
bdcpy(pend.bd_addr, p_lcb->addr);
(*p_cb->p_cback)(BTA_AV_PENDING_EVT, (tBTA_AV *) &pend);
}
@@ -1589,7 +1589,7 @@
/*******************************************************************************
**
-** Function bta_av_acp_sig_timer_cback
+** Function bta_av_accept_signalling_timer_cback
**
** Description Process the timeout when SRC is accepting connection
** and SNK did not start signalling.
@@ -1597,9 +1597,9 @@
** Returns void
**
*******************************************************************************/
-static void bta_av_acp_sig_timer_cback(timer_entry_t *p_te)
+static void bta_av_accept_signalling_timer_cback(void *data)
{
- UINT8 inx = PTR_TO_UINT(p_te->param);
+ UINT32 inx = PTR_TO_UINT(data);
tBTA_AV_CB *p_cb = &bta_av_cb;
tBTA_AV_SCB *p_scb = NULL;
tBTA_AV_API_OPEN *p_buf;
@@ -1609,7 +1609,7 @@
}
if (p_scb)
{
- APPL_TRACE_DEBUG("bta_av_acp_sig_timer_cback, coll_mask = 0x%02X", p_scb->coll_mask);
+ APPL_TRACE_DEBUG("%s coll_mask = 0x%02X", __func__, p_scb->coll_mask);
if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR)
{
@@ -1622,10 +1622,11 @@
/* We are still doing SDP. Run the timer again. */
p_scb->coll_mask |= BTA_AV_COLL_INC_TMR;
- p_cb->acp_sig_tmr.param = UINT_TO_PTR(inx);
- p_cb->acp_sig_tmr.p_cback =
- (timer_callback_t *)&bta_av_acp_sig_timer_cback;
- bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
+ alarm_set_on_queue(p_cb->accept_signalling_timer,
+ BTA_AV_ACCEPT_SIGNALLING_TIMEOUT_MS,
+ bta_av_accept_signalling_timer_cback,
+ UINT_TO_PTR(inx),
+ btu_bta_alarm_queue);
}
else
{
@@ -2176,7 +2177,7 @@
}
/* make sure that the timer is not active */
- bta_sys_stop_timer(&p_scb->timer);
+ alarm_cancel(p_scb->avrc_ct_timer);
utl_freebuf((void **)&p_cb->p_scb[p_scb->hdi]);
}
diff --git a/bta/av/bta_av_int.h b/bta/av/bta_av_int.h
index d2c3cc1..9d3a7d0 100644
--- a/bta/av/bta_av_int.h
+++ b/bta/av/bta_av_int.h
@@ -94,7 +94,7 @@
BTA_AV_API_DISCONNECT_EVT,
BTA_AV_CI_SRC_DATA_READY_EVT,
BTA_AV_SIG_CHG_EVT,
- BTA_AV_SIG_TIMER_EVT,
+ BTA_AV_SIGNALLING_TIMER_EVT,
BTA_AV_SDP_AVRC_DISC_EVT,
BTA_AV_AVRC_CLOSE_EVT,
BTA_AV_CONN_CHG_EVT,
@@ -486,7 +486,7 @@
tBTA_AV_Q_INFO q_info;
tAVDT_SEP_INFO sep_info[BTA_AV_NUM_SEPS]; /* stream discovery results */
tAVDT_CFG cfg; /* local SEP configuration */
- timer_entry_t timer; /* delay timer for AVRC CT */
+ alarm_t *avrc_ct_timer; /* delay timer for AVRC CT */
BD_ADDR peer_addr; /* peer BD address */
UINT16 l2c_cid; /* L2CAP channel ID */
UINT16 stream_mtu; /* MTU of stream */
@@ -574,8 +574,8 @@
tBTA_AV_CBACK *p_cback; /* application callback function */
tBTA_AV_RCB rcb[BTA_AV_NUM_RCB]; /* RCB control block */
tBTA_AV_LCB lcb[BTA_AV_NUM_LINKS+1]; /* link control block */
- timer_entry_t sig_tmr; /* link timer */
- timer_entry_t acp_sig_tmr; /* timer to monitor signalling when accepting */
+ alarm_t *link_signalling_timer;
+ alarm_t *accept_signalling_timer; /* timer to monitor signalling when accepting */
UINT32 sdp_a2d_handle; /* SDP record handle for audio src */
#if (BTA_AV_SINK_INCLUDED == TRUE)
UINT32 sdp_a2d_snk_handle; /* SDP record handle for audio snk */
@@ -666,7 +666,7 @@
/* nsm action functions */
extern void bta_av_api_disconnect(tBTA_AV_DATA *p_data);
extern void bta_av_sig_chg(tBTA_AV_DATA *p_data);
-extern void bta_av_sig_timer(tBTA_AV_DATA *p_data);
+extern void bta_av_signalling_timer(tBTA_AV_DATA *p_data);
extern void bta_av_rc_disc_done(tBTA_AV_DATA *p_data);
extern void bta_av_rc_closed(tBTA_AV_DATA *p_data);
extern void bta_av_rc_disc(UINT8 disc);
diff --git a/bta/av/bta_av_main.c b/bta/av/bta_av_main.c
index 8f6a5df..91b2e9f 100644
--- a/bta/av/bta_av_main.c
+++ b/bta/av/bta_av_main.c
@@ -179,7 +179,7 @@
bta_av_api_disconnect, /* BTA_AV_API_DISCONNECT_EVT */
bta_av_ci_data, /* BTA_AV_CI_SRC_DATA_READY_EVT */
bta_av_sig_chg, /* BTA_AV_SIG_CHG_EVT */
- bta_av_sig_timer, /* BTA_AV_SIG_TIMER_EVT */
+ bta_av_signalling_timer, /* BTA_AV_SIGNALLING_TIMER_EVT */
bta_av_rc_disc_done, /* BTA_AV_SDP_AVRC_DISC_EVT */
bta_av_rc_closed, /* BTA_AV_AVRC_CLOSE_EVT */
bta_av_conn_chg, /* BTA_AV_CONN_CHG_EVT */
@@ -209,42 +209,6 @@
/*******************************************************************************
**
-** Function bta_av_timer_cback
-**
-** Description forward the event to stream state machine
-**
-** Returns void
-**
-*******************************************************************************/
-static void bta_av_timer_cback(void *p_te)
-{
- BT_HDR *p_buf;
- timer_entry_t *p = (timer_entry_t *)p_te;
- int xx;
- tBTA_AV_SCB *p_scb = NULL;
-
- /* find the SCB that has the timer */
- for(xx=0; xx<BTA_AV_NUM_STRS; xx++)
- {
- if(bta_av_cb.p_scb[xx] && &(bta_av_cb.p_scb[xx]->timer)== p)
- {
- p_scb = bta_av_cb.p_scb[xx];
- break;
- }
- }
-
- if (p_scb && (p_buf = (BT_HDR *) osi_getbuf(sizeof(BT_HDR))) != NULL)
- {
- /* send the event through the audio state machine.
- * only when the audio SM is open, the main SM opens the RC connection as INT */
- p_buf->event = p->event;
- p_buf->layer_specific = p_scb->hndl;
- bta_sys_sendmsg(p_buf);
- }
-}
-
-/*******************************************************************************
-**
** Function bta_av_api_enable
**
** Description Handle an API enable event.
@@ -258,6 +222,9 @@
int i;
tBTA_AV_ENABLE enable;
+ alarm_free(bta_av_cb.link_signalling_timer);
+ alarm_free(bta_av_cb.accept_signalling_timer);
+
/* initialize control block */
memset(&bta_av_cb, 0, sizeof(tBTA_AV_CB));
@@ -266,6 +233,14 @@
bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE;
+ /*
+ * TODO: The "disable" event handling is missing - there we need
+ * to alarm_free() the alarms below.
+ */
+ bta_av_cb.link_signalling_timer = alarm_new("bta_av.link_signalling_timer");
+ bta_av_cb.accept_signalling_timer =
+ alarm_new("bta_av.accept_signalling_timer");
+
/* store parameters */
bta_av_cb.p_cback = p_data->api_enable.p_cback;
bta_av_cb.features = p_data->api_enable.features;
@@ -389,6 +364,7 @@
p_ret->hndl = (tBTA_AV_HNDL)((xx + 1) | chnl);
p_ret->hdi = xx;
p_ret->a2d_list = list_new(NULL);
+ p_ret->avrc_ct_timer = alarm_new("bta_av.avrc_ct_timer");
bta_av_cb.p_scb[xx] = p_ret;
}
break;
@@ -566,7 +542,6 @@
p_scb->app_id = registr.app_id;
/* initialize the stream control block */
- p_scb->timer.p_cback = (timer_callback_t *)&bta_av_timer_cback;
registr.status = BTA_AV_SUCCESS;
if((bta_av_cb.reg_audio + bta_av_cb.reg_video) == 0)
@@ -1098,7 +1073,9 @@
{
/* can not switch role on SCBI
* start the timer on SCB - because this function is ONLY called when SCB gets API_OPEN */
- bta_sys_start_timer(&p_scb->timer, BTA_AV_AVRC_TIMER_EVT, BTA_AV_RS_TIME_VAL);
+ bta_sys_start_timer(p_scb->avrc_ct_timer,
+ BTA_AV_RS_TIME_VAL,
+ BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
}
needed = TRUE;
/* mark the original channel as waiting for RS result */
@@ -1419,7 +1396,7 @@
case BTA_AV_API_DISCONNECT_EVT: return "API_DISCNT";
case BTA_AV_CI_SRC_DATA_READY_EVT: return "CI_DATA_READY";
case BTA_AV_SIG_CHG_EVT: return "SIG_CHG";
- case BTA_AV_SIG_TIMER_EVT: return "SIG_TMR";
+ case BTA_AV_SIGNALLING_TIMER_EVT: return "SIGNALLING_TIMER";
case BTA_AV_SDP_AVRC_DISC_EVT: return "SDP_AVRC_DISC";
case BTA_AV_AVRC_CLOSE_EVT: return "AVRC_CLOSE";
case BTA_AV_CONN_CHG_EVT: return "CONN_CHG";
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index f182551..43cdb1b 100644
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -87,8 +87,8 @@
tBTA_SERVICE_MASK *p_services_to_search,
tBTA_SERVICE_MASK *p_services_found);
-static void bta_dm_search_timer_cback(timer_entry_t *p_te);
-static void bta_dm_disable_conn_down_timer_cback(timer_entry_t *p_te);
+static void bta_dm_search_timer_cback(void *data);
+static void bta_dm_disable_conn_down_timer_cback(void *data);
static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
static void bta_dm_adjust_roles(BOOLEAN delay_role_switch);
static char *bta_dm_get_remname(void);
@@ -122,12 +122,32 @@
#endif
#endif
+/* Disable timer interval (in milliseconds) */
+#ifndef BTA_DM_DISABLE_TIMER_MS
+#define BTA_DM_DISABLE_TIMER_MS 5000
+#endif
+
+/* Disable timer retrial interval (in milliseconds) */
+#ifndef BTA_DM_DISABLE_TIMER_RETRIAL_MS
+#define BTA_DM_DISABLE_TIMER_RETRIAL_MS 1500
+#endif
+
+/* Disable connection down timer (in milliseconds) */
+#ifndef BTA_DM_DISABLE_CONN_DOWN_TIMER_MS
+#define BTA_DM_DISABLE_CONN_DOWN_TIMER_MS 1000
+#endif
+
+/* Switch delay timer (in milliseconds) */
+#ifndef BTA_DM_SWITCH_DELAY_TIMER_MS
+#define BTA_DM_SWITCH_DELAY_TIMER_MS 500
+#endif
+
static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);
static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
static void bta_dm_observe_cmpl_cb(void * p_result);
-static void bta_dm_delay_role_switch_cback(timer_entry_t *p_te);
+static void bta_dm_delay_role_switch_cback(void *data);
extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8* p_uuid128);
-static void bta_dm_disable_timer_cback(timer_entry_t *p_te);
+static void bta_dm_disable_timer_cback(void *data);
const UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID] =
@@ -236,6 +256,7 @@
UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
extern DEV_CLASS local_device_default_class;
+extern fixed_queue_t *btu_bta_alarm_queue;
/*******************************************************************************
**
@@ -285,6 +306,39 @@
/*******************************************************************************
**
+** Function bta_dm_init_cb
+**
+** Description Initializes or re-initializes the bta_dm_cb control block
+**
+**
+** Returns void
+**
+*******************************************************************************/
+void bta_dm_init_cb(void)
+{
+ /*
+ * TODO: Should alarm_free() the bta_dm_cb timers during graceful
+ * shutdown.
+ */
+ alarm_free(bta_dm_cb.disable_timer);
+ alarm_free(bta_dm_cb.switch_delay_timer);
+ for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
+ for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
+ alarm_free(bta_dm_cb.pm_timer[i].timer[j]);
+ }
+ }
+ memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
+ bta_dm_cb.disable_timer = alarm_new("bta_dm.disable_timer");
+ bta_dm_cb.switch_delay_timer = alarm_new("bta_dm.switch_delay_timer");
+ for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
+ for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
+ bta_dm_cb.pm_timer[i].timer[j] = alarm_new("bta_dm.pm_timer");
+ }
+ }
+}
+
+/*******************************************************************************
+**
** Function bta_dm_sys_hw_cback
**
** Description callback register to SYS to get HW status updates
@@ -318,7 +372,7 @@
bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL);
/* reinitialize the control block */
- memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
+ bta_dm_init_cb();
/* unregister from SYS */
bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH );
@@ -335,14 +389,25 @@
/* save security callback */
temp_cback = bta_dm_cb.p_sec_cback;
/* make sure the control block is properly initialized */
- memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
+ bta_dm_init_cb();
/* and retrieve the callback */
bta_dm_cb.p_sec_cback=temp_cback;
bta_dm_cb.is_bta_dm_active = TRUE;
/* hw is ready, go on with BTA DM initialization */
- memset(&bta_dm_search_cb, 0x00, sizeof(bta_dm_search_cb));
- memset(&bta_dm_conn_srvcs, 0x00, sizeof(bta_dm_conn_srvcs));
+ alarm_free(bta_dm_search_cb.search_timer);
+ alarm_free(bta_dm_search_cb.gatt_close_timer);
+ memset(&bta_dm_search_cb, 0, sizeof(bta_dm_search_cb));
+ /*
+ * TODO: Should alarm_free() the bta_dm_search_cb timers during
+ * graceful shutdown.
+ */
+ bta_dm_search_cb.search_timer =
+ alarm_new("bta_dm_search.search_timer");
+ bta_dm_search_cb.gatt_close_timer =
+ alarm_new("bta_dm_search.gatt_close_timer");
+
+ memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs));
memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB));
memcpy(dev_class, p_bta_dm_cfg->dev_class, sizeof(dev_class));
@@ -441,22 +506,19 @@
*/
APPL_TRACE_WARNING("%s BTA_DISABLE_DELAY set to %d ms",
__FUNCTION__, BTA_DISABLE_DELAY);
- bta_sys_stop_timer(&bta_dm_cb.disable_timer);
- bta_dm_cb.disable_timer.p_cback =
- (timer_callback_t *)&bta_dm_disable_conn_down_timer_cback;
- bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, BTA_DISABLE_DELAY);
+ alarm_set_on_queue(bta_dm_cb.disable_timer, BTA_DISABLE_DELAY,
+ bta_dm_disable_conn_down_timer_cback, NULL,
+ btu_bta_alarm_queue);
#else
bta_dm_disable_conn_down_timer_cback(NULL);
#endif
}
else
{
- bta_dm_cb.disable_timer.p_cback =
- (timer_callback_t *)&bta_dm_disable_timer_cback;
- bta_dm_cb.disable_timer.param = INT_TO_PTR(0);
- bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000);
+ alarm_set_on_queue(bta_dm_cb.disable_timer, BTA_DM_DISABLE_TIMER_MS,
+ bta_dm_disable_timer_cback, UINT_TO_PTR(0),
+ btu_bta_alarm_queue);
}
-
}
/*******************************************************************************
@@ -471,16 +533,16 @@
** Returns void
**
*******************************************************************************/
-static void bta_dm_disable_timer_cback(timer_entry_t *p_te)
+static void bta_dm_disable_timer_cback(void *data)
{
UINT8 i;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
BOOLEAN trigger_disc = FALSE;
+ uint32_t param = PTR_TO_UINT(data);
+ APPL_TRACE_EVENT("%s trial %u", __func__, param);
- APPL_TRACE_EVENT(" bta_dm_disable_timer_cback trial %d ", p_te->param);
-
- if(BTM_GetNumAclLinks() && PTR_TO_INT(p_te->param) == 0)
+ if ((BTM_GetNumAclLinks() && param) == 0)
{
for(i=0; i<bta_dm_cb.device_list.count; i++)
{
@@ -495,10 +557,10 @@
to be sent out to avoid jave layer disable timeout */
if (trigger_disc)
{
- bta_dm_cb.disable_timer.p_cback =
- (timer_callback_t *)&bta_dm_disable_timer_cback;
- bta_dm_cb.disable_timer.param = INT_TO_PTR(1);
- bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 1500);
+ alarm_set_on_queue(bta_dm_cb.disable_timer,
+ BTA_DM_DISABLE_TIMER_RETRIAL_MS,
+ bta_dm_disable_timer_cback, UINT_TO_PTR(1),
+ btu_bta_alarm_queue);
}
}
else
@@ -1919,11 +1981,11 @@
{
/* wait until link is disconnected or timeout */
bta_dm_search_cb.sdp_results = TRUE;
- bta_dm_search_cb.search_timer.p_cback =
- (timer_callback_t *)&bta_dm_search_timer_cback;
- bta_sys_start_timer(&bta_dm_search_cb.search_timer, 0, 1000*(L2CAP_LINK_INACTIVITY_TOUT+1) );
+ alarm_set_on_queue(bta_dm_search_cb.search_timer,
+ 1000 * (L2CAP_LINK_INACTIVITY_TOUT + 1),
+ bta_dm_search_timer_cback, NULL,
+ btu_bta_alarm_queue);
}
-
}
/*******************************************************************************
@@ -1936,7 +1998,7 @@
** Returns void
**
*******************************************************************************/
-static void bta_dm_search_timer_cback(timer_entry_t *p_te)
+static void bta_dm_search_timer_cback(UNUSED_ATTR void *data)
{
APPL_TRACE_EVENT("%s", __func__);
bta_dm_search_cb.wait_disc = FALSE;
@@ -3430,7 +3492,7 @@
if(bta_dm_search_cb.sdp_results)
{
APPL_TRACE_EVENT(" timer stopped ");
- bta_sys_stop_timer(&bta_dm_search_cb.search_timer);
+ alarm_cancel(bta_dm_search_cb.search_timer);
bta_dm_discover_next_device();
}
@@ -3440,14 +3502,14 @@
{
if(!BTM_GetNumAclLinks())
{
- bta_sys_stop_timer(&bta_dm_cb.disable_timer);
- bta_dm_cb.disable_timer.p_cback =
- (timer_callback_t *)&bta_dm_disable_conn_down_timer_cback;
/*
* Start a timer to make sure that the profiles
* get the disconnect event.
*/
- bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 1000);
+ alarm_set_on_queue(bta_dm_cb.disable_timer,
+ BTA_DM_DISABLE_CONN_DOWN_TIMER_MS,
+ bta_dm_disable_conn_down_timer_cback, NULL,
+ btu_bta_alarm_queue);
}
}
if (conn.link_down.is_removed)
@@ -3484,7 +3546,7 @@
** Returns void
**
*******************************************************************************/
-static void bta_dm_disable_conn_down_timer_cback(timer_entry_t *p_te)
+static void bta_dm_disable_conn_down_timer_cback(UNUSED_ATTR void *data)
{
tBTA_SYS_HW_MSG *sys_enable_event;
@@ -3587,10 +3649,10 @@
** Returns void
**
*******************************************************************************/
-static void bta_dm_delay_role_switch_cback(timer_entry_t *p_te)
+static void bta_dm_delay_role_switch_cback(UNUSED_ATTR void *data)
{
- APPL_TRACE_EVENT("bta_dm_delay_role_switch_cback: initiating Delayed RS");
- bta_dm_adjust_roles (FALSE);
+ APPL_TRACE_EVENT("%s: initiating Delayed RS", __func__);
+ bta_dm_adjust_roles(FALSE);
}
/*******************************************************************************
@@ -3706,12 +3768,12 @@
}
else
{
- bta_dm_cb.switch_delay_timer.p_cback =
- (timer_callback_t *)&bta_dm_delay_role_switch_cback;
- bta_sys_start_timer(&bta_dm_cb.switch_delay_timer, 0, 500);
+ alarm_set_on_queue(bta_dm_cb.switch_delay_timer,
+ BTA_DM_SWITCH_DELAY_TIMER_MS,
+ bta_dm_delay_role_switch_cback,
+ NULL, btu_bta_alarm_queue);
}
}
-
}
}
@@ -3809,14 +3871,10 @@
UINT8 local_name_len;
/* wait until complete to disable */
- if (bta_dm_cb.disable_timer.in_use)
+ if (alarm_is_scheduled(bta_dm_cb.disable_timer))
return;
#if ( BTA_EIR_CANNED_UUID_LIST != TRUE )
- /* wait until App is ready */
- if (bta_dm_cb.app_ready_timer.in_use)
- return;
-
/* if local name is not provided, get it from controller */
if( local_name == NULL )
{
@@ -5575,9 +5633,11 @@
if (conn_id != BTA_GATT_INVALID_CONN_ID)
{
/* start a GATT channel close delay timer */
- bta_sys_start_timer(&bta_dm_search_cb.gatt_close_timer, BTA_DM_DISC_CLOSE_TOUT_EVT,
- BTA_DM_GATT_CLOSE_DELAY_TOUT);
- bdcpy(bta_dm_search_cb.pending_close_bda, bta_dm_search_cb.peer_bdaddr);
+ bta_sys_start_timer(bta_dm_search_cb.gatt_close_timer,
+ BTA_DM_GATT_CLOSE_DELAY_TOUT,
+ BTA_DM_DISC_CLOSE_TOUT_EVT, 0);
+ bdcpy(bta_dm_search_cb.pending_close_bda,
+ bta_dm_search_cb.peer_bdaddr);
}
bta_dm_search_cb.gatt_disc_active = FALSE;
}
@@ -5621,7 +5681,7 @@
bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
{
memset(bta_dm_search_cb.pending_close_bda, 0, BD_ADDR_LEN);
- bta_sys_stop_timer(&bta_dm_search_cb.gatt_close_timer);
+ alarm_cancel(bta_dm_search_cb.gatt_close_timer);
btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
}
else
diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c
index deecab3..b2f4c7f 100644
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -68,7 +68,7 @@
if (bta_dm_cb.disabling)
return BTA_FAILURE;
- memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
+ bta_dm_init_cb();
bta_sys_register (BTA_ID_DM, &bta_dm_reg );
bta_sys_register (BTA_ID_DM_SEARCH, &bta_dm_search_reg );
diff --git a/bta/dm/bta_dm_int.h b/bta/dm/bta_dm_int.h
index dcc8870..057a13a 100644
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -833,7 +833,7 @@
* Keep three different timers for PARK, SNIFF and SUSPEND if TBFC is
* supported.
*/
- timer_entry_t timer[BTA_DM_PM_MODE_TIMER_MAX];
+ alarm_t * timer[BTA_DM_PM_MODE_TIMER_MAX];
UINT8 srvc_id[BTA_DM_PM_MODE_TIMER_MAX];
UINT8 pm_action[BTA_DM_PM_MODE_TIMER_MAX];
@@ -863,7 +863,7 @@
#endif
UINT16 state;
BOOLEAN disabling;
- timer_entry_t disable_timer;
+ alarm_t *disable_timer;
UINT32 wbt_sdp_handle; /* WIDCOMM Extensions SDP record handle */
UINT8 wbt_scn; /* WIDCOMM Extensions SCN */
UINT8 num_master_only;
@@ -889,7 +889,6 @@
BOOLEAN just_works; /* TRUE, if "Just Works" association model */
#if ( BTA_EIR_CANNED_UUID_LIST != TRUE )
/* store UUID list for EIR */
- timer_entry_t app_ready_timer;
UINT32 eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
#if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
tBT_UUID custom_uuid[BTA_EIR_SERVER_NUM_CUSTOM_UUID];
@@ -899,7 +898,7 @@
tBTA_DM_ENCRYPT_CBACK *p_encrypt_cback;
- timer_entry_t switch_delay_timer;
+ alarm_t *switch_delay_timer;
} tBTA_DM_CB;
@@ -921,7 +920,7 @@
BD_ADDR peer_bdaddr;
BOOLEAN name_discover_done;
BD_NAME peer_name;
- timer_entry_t search_timer;
+ alarm_t * search_timer;
UINT8 service_index;
tBTA_DM_MSG * p_search_queue; /* search or discover commands during search cancel stored here */
BOOLEAN wait_disc;
@@ -943,7 +942,7 @@
UINT8 * p_ble_rawdata;
UINT32 ble_raw_size;
UINT32 ble_raw_used;
- timer_entry_t gatt_close_timer; /* GATT channel close delay timer */
+ alarm_t * gatt_close_timer; /* GATT channel close delay timer */
BD_ADDR pending_close_bda; /* pending GATT channel remote device address */
#endif
#endif
@@ -1082,6 +1081,7 @@
extern void bta_dm_enable (tBTA_DM_MSG *p_data);
extern void bta_dm_disable (tBTA_DM_MSG *p_data);
+extern void bta_dm_init_cb(void);
extern void bta_dm_set_dev_name (tBTA_DM_MSG *p_data);
extern void bta_dm_set_visibility (tBTA_DM_MSG *p_data);
diff --git a/bta/dm/bta_dm_pm.c b/bta/dm/bta_dm_pm.c
index 4e65d40..b464ee7 100644
--- a/bta/dm/bta_dm_pm.c
+++ b/bta/dm/bta_dm_pm.c
@@ -33,10 +33,12 @@
#include "btm_api.h"
+extern fixed_queue_t *btu_bta_alarm_queue;
+
static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_mode,
tBTA_DM_PM_REQ pm_req);
-static void bta_dm_pm_timer_cback(void *p_te);
+static void bta_dm_pm_timer_cback(void *data);
static void bta_dm_pm_btm_cback(BD_ADDR bd_addr, tBTM_PM_STATUS status, UINT16 value, UINT8 hci_status);
static BOOLEAN bta_dm_pm_park(BD_ADDR peer_addr);
static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index);
@@ -278,10 +280,10 @@
**
*******************************************************************************/
static void bta_dm_pm_start_timer(tBTA_PM_TIMER *p_timer, UINT8 timer_idx,
- INT32 timeout, UINT8 srvc_id, UINT8 pm_action)
+ period_ms_t timeout_ms, UINT8 srvc_id,
+ UINT8 pm_action)
{
p_timer->in_use = TRUE;
- p_timer->timer[timer_idx].p_cback = bta_dm_pm_timer_cback;
if (p_timer->srvc_id[timer_idx] == BTA_ID_MAX)
p_timer->active++;
@@ -291,7 +293,9 @@
p_timer->srvc_id[timer_idx] = srvc_id;
- bta_sys_start_timer(&p_timer->timer[timer_idx], 0, timeout);
+ alarm_set_on_queue(p_timer->timer[timer_idx], timeout_ms,
+ bta_dm_pm_timer_cback, p_timer->timer[timer_idx],
+ btu_bta_alarm_queue);
}
/*******************************************************************************
@@ -315,7 +319,7 @@
assert(p_timer->in_use && (p_timer->active > 0));
- bta_sys_stop_timer(&p_timer->timer[timer_idx]);
+ alarm_cancel(p_timer->timer[timer_idx]);
p_timer->srvc_id[timer_idx] = BTA_ID_MAX;
/* NOTE: pm_action[timer_idx] intentionally not reset */
@@ -324,11 +328,6 @@
p_timer->in_use = FALSE;
}
-UINT32 bta_dm_pm_get_remaining_ticks (timer_entry_t *p_target_te)
-{
- return bta_sys_get_remaining_ticks(p_target_te);
-}
-
/*******************************************************************************
**
** Function bta_dm_pm_cback
@@ -525,7 +524,7 @@
{
tBTA_DM_PM_ACTION pm_action = BTA_DM_PM_NO_ACTION;
- UINT16 timeout = 0;
+ period_ms_t timeout_ms = 0;
UINT8 i,j;
tBTA_DM_PM_ACTION failed_pm = 0;
tBTA_DM_PEER_DEVICE *p_peer_device = NULL;
@@ -537,7 +536,7 @@
tBTA_DM_SRVCS *p_srvcs = NULL;
BOOLEAN timer_started = FALSE;
UINT8 timer_idx, available_timer = BTA_DM_PM_MODE_TIMER_MAX;
- UINT32 remaining_ticks = 0;
+ period_ms_t remaining_ms = 0;
if(!bta_dm_cb.device_list.count)
return;
@@ -588,7 +587,7 @@
if (pm_req != BTA_DM_PM_NEW_REQ || p_srvcs->new_request)
{
p_srvcs->new_request = FALSE;
- timeout = p_act0->timeout;
+ timeout_ms = p_act0->timeout;
}
}
}
@@ -600,7 +599,7 @@
if(p_act1->power_mode > pm_action)
{
pm_action = p_act1->power_mode;
- timeout = p_act1->timeout;
+ timeout_ms = p_act1->timeout;
}
}
}
@@ -618,22 +617,22 @@
/* no timeout needed if no action is required */
if(pm_action == BTA_DM_PM_NO_ACTION)
{
- timeout = 0;
+ timeout_ms = 0;
}
}
}
/* if need to start a timer */
- if((pm_req != BTA_DM_PM_EXECUTE) && timeout)
+ if ((pm_req != BTA_DM_PM_EXECUTE) && (timeout_ms > 0))
{
- for(i=0; i<BTA_DM_NUM_PM_TIMER; i++)
+ for (i=0; i<BTA_DM_NUM_PM_TIMER; i++)
{
- if(bta_dm_cb.pm_timer[i].in_use && bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr) == 0)
+ if (bta_dm_cb.pm_timer[i].in_use && bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr) == 0)
{
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX)
{
- remaining_ticks = bta_dm_pm_get_remaining_ticks(&bta_dm_cb.pm_timer[i].timer[timer_idx]);
- if (remaining_ticks < timeout)
+ remaining_ms = alarm_get_remaining_ms(bta_dm_cb.pm_timer[i].timer[timer_idx]);
+ if (remaining_ms < timeout_ms)
{
/* Cancel and restart the timer */
/*
@@ -645,7 +644,9 @@
*/
bta_dm_pm_stop_timer_by_index(&bta_dm_cb.pm_timer[i],
timer_idx);
- bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[i], timer_idx, timeout, p_srvcs->id, pm_action);
+ bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[i],
+ timer_idx, timeout_ms,
+ p_srvcs->id, pm_action);
}
timer_started = TRUE;
}
@@ -653,7 +654,8 @@
}
else if (!bta_dm_cb.pm_timer[i].in_use)
{
- APPL_TRACE_DEBUG("%s dm_pm_timer:%d, %d", __func__, i, timeout);
+ APPL_TRACE_DEBUG("%s dm_pm_timer:%d, %d ms", __func__, i,
+ timeout_ms);
if (available_timer == BTA_DM_PM_MODE_TIMER_MAX)
available_timer = i;
}
@@ -666,7 +668,9 @@
bdcpy(bta_dm_cb.pm_timer[available_timer].peer_bdaddr, peer_addr);
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX)
{
- bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[available_timer], timer_idx, timeout, p_srvcs->id, pm_action);
+ bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[available_timer],
+ timer_idx, timeout_ms,
+ p_srvcs->id, pm_action);
timer_started = TRUE;
}
}
@@ -929,9 +933,10 @@
** Returns void
**
*******************************************************************************/
-static void bta_dm_pm_timer_cback(void *p_te)
+static void bta_dm_pm_timer_cback(void *data)
{
UINT8 i, j;
+ alarm_t *alarm = (alarm_t *)data;
for (i=0; i<BTA_DM_NUM_PM_TIMER; i++)
{
@@ -940,7 +945,7 @@
{
for (j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
{
- if(&bta_dm_cb.pm_timer[i].timer[j] == (timer_entry_t *)p_te)
+ if (bta_dm_cb.pm_timer[i].timer[j] == alarm)
{
bta_dm_cb.pm_timer[i].active --;
bta_dm_cb.pm_timer[i].srvc_id[j] = BTA_ID_MAX;
diff --git a/bta/hf_client/bta_hf_client_act.c b/bta/hf_client/bta_hf_client_act.c
index 718f906..d41f298 100644
--- a/bta/hf_client/bta_hf_client_act.c
+++ b/bta/hf_client/bta_hf_client_act.c
@@ -280,11 +280,8 @@
}
/* Collision Handling */
- if (bta_hf_client_cb.scb.colli_tmr_on)
- {
- /* stop collision timer */
- bta_hf_client_cb.scb.colli_tmr_on = FALSE;
- bta_sys_stop_timer (&bta_hf_client_cb.scb.colli_timer);
+ if (alarm_is_scheduled(bta_hf_client_cb.scb.collision_timer)) {
+ alarm_cancel(bta_hf_client_cb.scb.collision_timer);
if (bdcmp (dev_addr, bta_hf_client_cb.scb.peer_addr) == 0)
{
diff --git a/bta/hf_client/bta_hf_client_at.c b/bta/hf_client/bta_hf_client_at.c
index f487a7f..7b21ea2 100644
--- a/bta/hf_client/bta_hf_client_at.c
+++ b/bta/hf_client/bta_hf_client_at.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdio.h>
+#include "osi/include/osi.h"
#include "bta_hf_client_api.h"
#include "bta_hf_client_int.h"
#include "port_api.h"
@@ -30,10 +31,10 @@
/* minimum length of AT event */
#define BTA_HF_CLIENT_AT_EVENT_MIN_LEN 3
-/* timeout for AT response */
+/* timeout (in milliseconds) for AT response */
#define BTA_HF_CLIENT_AT_TIMEOUT 29989
-/* timeout for AT hold timer */
+/* timeout (in milliseconds) for AT hold timer */
#define BTA_HF_CLIENT_AT_HOLD_TIMEOUT 41
/******************************************************************************
@@ -44,6 +45,8 @@
/* BRSF: store received values here */
extern tBTA_HF_CLIENT_CB bta_hf_client_cb;
+extern fixed_queue_t *btu_bta_alarm_queue;
+
/******************************************************************************
** SUPPORTED EVENT MESSAGES
*******************************************************************************/
@@ -139,45 +142,31 @@
}
}
-static void bta_hf_client_at_resp_timer_cback(timer_entry_t *p_te)
+static void bta_hf_client_at_resp_timer_cback(UNUSED_ATTR void *data)
{
- if (p_te)
- {
- bta_hf_client_cb.scb.at_cb.resp_timer_on = FALSE;
-
- APPL_TRACE_ERROR("HFPClient: AT response timeout, disconnecting");
-
- bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
- }
-}
-
-static void bta_hf_client_stop_at_resp_timer(void)
-{
- if (bta_hf_client_cb.scb.at_cb.resp_timer_on)
- {
- bta_hf_client_cb.scb.at_cb.resp_timer_on = FALSE;
- bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.resp_timer);
- }
+ APPL_TRACE_ERROR("HFPClient: AT response timeout, disconnecting");
+ bta_hf_client_sm_execute(BTA_HF_CLIENT_API_CLOSE_EVT, NULL);
}
static void bta_hf_client_start_at_resp_timer(void)
{
- if (bta_hf_client_cb.scb.at_cb.resp_timer_on)
- {
- bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.resp_timer);
- }
+ alarm_set_on_queue(bta_hf_client_cb.scb.at_cb.resp_timer,
+ BTA_HF_CLIENT_AT_TIMEOUT,
+ bta_hf_client_at_resp_timer_cback,
+ NULL,
+ btu_bta_alarm_queue);
+}
- bta_hf_client_cb.scb.at_cb.resp_timer.p_cback =
- (timer_callback_t *)&bta_hf_client_at_resp_timer_cback;
- bta_sys_start_timer(&bta_hf_client_cb.scb.at_cb.resp_timer, 0, BTA_HF_CLIENT_AT_TIMEOUT);
- bta_hf_client_cb.scb.at_cb.resp_timer_on = TRUE;
+static void bta_hf_client_stop_at_resp_timer(void)
+{
+ alarm_cancel(bta_hf_client_cb.scb.at_cb.resp_timer);
}
static void bta_hf_client_send_at(tBTA_HF_CLIENT_AT_CMD cmd, char *buf, UINT16 buf_len)
{
if ((bta_hf_client_cb.scb.at_cb.current_cmd == BTA_HF_CLIENT_AT_NONE ||
bta_hf_client_cb.scb.svc_conn == FALSE) &&
- bta_hf_client_cb.scb.at_cb.hold_timer_on == FALSE)
+ !alarm_is_scheduled(bta_hf_client_cb.scb.at_cb.hold_timer))
{
UINT16 len;
@@ -221,42 +210,26 @@
}
}
-static void bta_hf_client_at_hold_timer_cback(timer_entry_t *p_te)
+static void bta_hf_client_at_hold_timer_cback(UNUSED_ATTR void *data)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
-
- if (p_te)
- {
- bta_hf_client_cb.scb.at_cb.hold_timer_on = FALSE;
- bta_hf_client_send_queued_at();
- }
+ bta_hf_client_send_queued_at();
}
static void bta_hf_client_stop_at_hold_timer(void)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
-
- if (bta_hf_client_cb.scb.at_cb.hold_timer_on)
- {
- bta_hf_client_cb.scb.at_cb.hold_timer_on = FALSE;
- bta_sys_stop_timer (&bta_hf_client_cb.scb.at_cb.hold_timer);
- }
+ alarm_cancel(bta_hf_client_cb.scb.at_cb.hold_timer);
}
static void bta_hf_client_start_at_hold_timer(void)
{
- timer_entry_t *p_te = &bta_hf_client_cb.scb.at_cb.hold_timer;
-
APPL_TRACE_DEBUG("%s", __FUNCTION__);
-
- if (bta_hf_client_cb.scb.at_cb.hold_timer_on)
- {
- bta_sys_stop_timer(p_te);
- }
-
- p_te->p_cback = (timer_callback_t *)&bta_hf_client_at_hold_timer_cback;
- bta_sys_start_timer(p_te, 0, BTA_HF_CLIENT_AT_HOLD_TIMEOUT);
- bta_hf_client_cb.scb.at_cb.hold_timer_on = TRUE;
+ alarm_set_on_queue(bta_hf_client_cb.scb.at_cb.hold_timer,
+ BTA_HF_CLIENT_AT_HOLD_TIMEOUT,
+ bta_hf_client_at_hold_timer_cback,
+ NULL,
+ btu_bta_alarm_queue);
}
/******************************************************************************
@@ -1812,7 +1785,13 @@
void bta_hf_client_at_init(void)
{
+ alarm_free(bta_hf_client_cb.scb.at_cb.resp_timer);
+ alarm_free(bta_hf_client_cb.scb.at_cb.hold_timer);
memset(&bta_hf_client_cb.scb.at_cb, 0, sizeof(tBTA_HF_CLIENT_AT_CB));
+ bta_hf_client_cb.scb.at_cb.resp_timer =
+ alarm_new("bta_hf_client.scb_at_resp_timer");
+ bta_hf_client_cb.scb.at_cb.hold_timer =
+ alarm_new("bta_hf_client.scb_at_hold_timer");
bta_hf_client_at_reset();
}
diff --git a/bta/hf_client/bta_hf_client_at.h b/bta/hf_client/bta_hf_client_at.h
index f6f2c85..78b5d63 100644
--- a/bta/hf_client/bta_hf_client_at.h
+++ b/bta/hf_client/bta_hf_client_at.h
@@ -96,12 +96,8 @@
unsigned int offset;
tBTA_HF_CLIENT_AT_CMD current_cmd;
tBTA_HF_CLIENT_AT_QCMD *queued_cmd;
-
- timer_entry_t resp_timer; /* AT response timer */
- BOOLEAN resp_timer_on; /* TRUE if AT response timer is active */
-
- timer_entry_t hold_timer; /* AT hold timer */
- BOOLEAN hold_timer_on; /* TRUE if AT hold timer is active */
+ alarm_t *resp_timer; /* AT response timer */
+ alarm_t *hold_timer; /* AT hold timer */
/* CIND: lookup table to store the sequence of incoming indicators and their values
so when their values come later, we know which value in sequence match certain indicator */
diff --git a/bta/hf_client/bta_hf_client_int.h b/bta/hf_client/bta_hf_client_int.h
index 083a90f..a2dbde2 100644
--- a/bta/hf_client/bta_hf_client_int.h
+++ b/bta/hf_client/bta_hf_client_int.h
@@ -36,9 +36,9 @@
#define BTA_HF_CLIENT_ACP 0 /* accepted connection */
#define BTA_HF_CLIENT_INT 1 /* initiating connection */
-/* Timer to wait for retry in case of collision */
-#ifndef BTA_HF_CLIENT_COLLISION_TIMER
-#define BTA_HF_CLIENT_COLLISION_TIMER 2411
+/* Time (in milliseconds) to wait for retry in case of collision */
+#ifndef BTA_HF_CLIENT_COLLISION_TIMER_MS
+#define BTA_HF_CLIENT_COLLISION_TIMER_MS 2411
#endif
enum
@@ -160,8 +160,7 @@
tBTA_HF_CLIENT_AT_CB at_cb; /* AT Parser control block */
UINT8 state; /* state machine state */
tBTM_SCO_CODEC_TYPE negotiated_codec; /* negotiated codec */
- timer_entry_t colli_timer; /* Collision timer */
- BOOLEAN colli_tmr_on; /* TRUE if collision timer is active */
+ alarm_t *collision_timer; /* Collision timer */
} tBTA_HF_CLIENT_SCB;
/* sco states */
diff --git a/bta/hf_client/bta_hf_client_main.c b/bta/hf_client/bta_hf_client_main.c
index f7afbf4..b5314b3 100644
--- a/bta/hf_client/bta_hf_client_main.c
+++ b/bta/hf_client/bta_hf_client_main.c
@@ -27,6 +27,7 @@
#include <cutils/properties.h>
#endif // !defined(OS_GENERIC)
+#include "osi/include/osi.h"
#include "bt_utils.h"
#include "bta_api.h"
#include "bta_sys.h"
@@ -40,6 +41,8 @@
#define BTA_HF_CLIENT_DEBUG FALSE
#endif
+extern fixed_queue_t *btu_bta_alarm_queue;
+
#if BTA_HF_CLIENT_DEBUG == TRUE
static char *bta_hf_client_evt_str(UINT16 event);
static char *bta_hf_client_state_str(UINT8 state);
@@ -246,7 +249,12 @@
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
+ alarm_free(bta_hf_client_cb.scb.collision_timer);
+ alarm_free(bta_hf_client_cb.scb.at_cb.resp_timer);
+ alarm_free(bta_hf_client_cb.scb.at_cb.hold_timer);
memset(&bta_hf_client_cb.scb, 0, sizeof(tBTA_HF_CLIENT_SCB));
+ bta_hf_client_cb.scb.collision_timer =
+ alarm_new("bta_hf_client.scb_collision_timer");
bta_hf_client_cb.scb.sco_idx = BTM_INVALID_SCO_INDEX;
bta_hf_client_cb.scb.negotiated_codec = BTM_SCO_CODEC_CVSD;
}
@@ -294,7 +302,7 @@
/*******************************************************************************
**
-** Function bta_hf_client_colli_timer_cback
+** Function bta_hf_client_collision_timer_cback
**
** Description HF Client connection collision timer callback
**
@@ -302,17 +310,12 @@
** Returns void
**
*******************************************************************************/
-static void bta_hf_client_colli_timer_cback (timer_entry_t *p_te)
+static void bta_hf_client_collision_timer_cback(UNUSED_ATTR void *data)
{
APPL_TRACE_DEBUG("%s", __FUNCTION__);
- if (p_te)
- {
- bta_hf_client_cb.scb.colli_tmr_on = FALSE;
-
- /* If the peer haven't opened connection, restart opening process */
- bta_hf_client_resume_open ();
- }
+ /* If the peer haven't opened connection, restart opening process */
+ bta_hf_client_resume_open();
}
/*******************************************************************************
@@ -361,10 +364,11 @@
bta_hf_client_start_server();
/* Start timer to handle connection opening restart */
- bta_hf_client_cb.scb.colli_timer.p_cback =
- (timer_callback_t *)&bta_hf_client_colli_timer_cback;
- bta_sys_start_timer(&bta_hf_client_cb.scb.colli_timer, 0, BTA_HF_CLIENT_COLLISION_TIMER);
- bta_hf_client_cb.scb.colli_tmr_on = TRUE;
+ alarm_set_on_queue(bta_hf_client_cb.scb.collision_timer,
+ BTA_HF_CLIENT_COLLISION_TIMER_MS,
+ bta_hf_client_collision_timer_cback,
+ NULL,
+ btu_bta_alarm_queue);
}
}
diff --git a/bta/include/bta_av_api.h b/bta/include/bta_av_api.h
index 04ba603..701d90c 100644
--- a/bta/include/bta_av_api.h
+++ b/bta/include/bta_av_api.h
@@ -245,8 +245,9 @@
#define BTA_AV_RECONFIG_EVT 14 /* reconfigure response */
#define BTA_AV_SUSPEND_EVT 15 /* suspend response */
#define BTA_AV_PENDING_EVT 16 /* incoming connection pending:
- * signal channel is open and stream is not open
- * after BTA_AV_SIG_TIME_VAL ms */
+ * signal channel is open and stream is
+ * not open after
+ * BTA_AV_SIGNALLING_TIMEOUT_MS */
#define BTA_AV_META_MSG_EVT 17 /* metadata messages */
#define BTA_AV_REJECT_EVT 18 /* incoming connection rejected */
#define BTA_AV_RC_FEAT_EVT 19 /* remote control channel peer supported features update */
diff --git a/bta/sys/bta_sys.h b/bta/sys/bta_sys.h
index 5ecb4bb..cf503aa 100644
--- a/bta/sys/bta_sys.h
+++ b/bta/sys/bta_sys.h
@@ -25,7 +25,7 @@
#define BTA_SYS_H
#include "bt_target.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
#include "bt_common.h"
/*****************************************************************************
@@ -228,10 +228,9 @@
extern BOOLEAN bta_sys_is_register(UINT8 id);
extern UINT16 bta_sys_get_sys_features(void);
extern void bta_sys_sendmsg(void *p_msg);
-extern void bta_sys_start_timer(timer_entry_t *p_te, UINT16 type, INT32 timeout_ms);
-extern void bta_sys_stop_timer(timer_entry_t *p_te);
+extern void bta_sys_start_timer(alarm_t *alarm, period_ms_t interval,
+ uint16_t event, uint16_t layer_specific);
extern void bta_sys_disable(tBTA_SYS_HW_MODULE module);
-extern UINT32 bta_sys_get_remaining_ticks(timer_entry_t *p_target_te);
extern void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback);
extern void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module );
diff --git a/bta/sys/bta_sys_main.c b/bta/sys/bta_sys_main.c
index 9a149f3..fc838bf 100644
--- a/bta/sys/bta_sys_main.c
+++ b/bta/sys/bta_sys_main.c
@@ -52,9 +52,6 @@
#endif
fixed_queue_t *btu_bta_alarm_queue;
-static hash_map_t *bta_alarm_hash_map;
-static const size_t BTA_ALARM_HASH_MAP_SIZE = 17;
-static pthread_mutex_t bta_alarm_lock;
extern thread_t *bt_workqueue_thread;
/* trace level */
@@ -64,7 +61,6 @@
// Communication queue between btu_task and bta.
extern fixed_queue_t *btu_bta_msg_queue;
-void btu_bta_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context);
static const tBTA_SYS_REG bta_sys_hw_reg =
{
@@ -178,16 +174,9 @@
{
memset(&bta_sys_cb, 0, sizeof(tBTA_SYS_CB));
- pthread_mutex_init(&bta_alarm_lock, NULL);
-
- bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE,
- hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL);
btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX);
- fixed_queue_register_dequeue(btu_bta_alarm_queue,
- thread_get_reactor(bt_workqueue_thread),
- btu_bta_alarm_ready,
- NULL);
+ alarm_register_processing_queue(btu_bta_alarm_queue, bt_workqueue_thread);
appl_trace_level = APPL_INITIAL_TRACE_LEVEL;
@@ -206,8 +195,6 @@
void bta_sys_free(void) {
fixed_queue_free(btu_bta_alarm_queue, NULL);
btu_bta_alarm_queue = NULL;
- hash_map_free(bta_alarm_hash_map);
- pthread_mutex_destroy(&bta_alarm_lock);
}
/*******************************************************************************
@@ -618,66 +605,15 @@
** Returns void
**
*******************************************************************************/
-void bta_alarm_cb(void *data) {
- assert(data != NULL);
- timer_entry_t *p_te = (timer_entry_t *)data;
-
- fixed_queue_enqueue(btu_bta_alarm_queue, p_te);
-}
-
-void bta_sys_start_timer(timer_entry_t *p_te, UINT16 type, INT32 timeout_ms) {
- assert(p_te != NULL);
-
- // Get the alarm for this p_te.
- pthread_mutex_lock(&bta_alarm_lock);
- if (!hash_map_has_key(bta_alarm_hash_map, p_te)) {
- hash_map_set(bta_alarm_hash_map, p_te, alarm_new());
- }
- pthread_mutex_unlock(&bta_alarm_lock);
-
- alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s unable to create alarm.", __func__);
- return;
- }
-
- p_te->event = type;
- p_te->ticks = timeout_ms;
- alarm_set(alarm, (period_ms_t)timeout_ms, bta_alarm_cb, p_te);
-}
-
-UINT32 bta_sys_get_remaining_ticks(timer_entry_t *p_target_te)
+void bta_sys_start_timer(alarm_t *alarm, period_ms_t interval, uint16_t event,
+ uint16_t layer_specific)
{
- pthread_mutex_lock(&bta_alarm_lock);
- alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_target_te);
- pthread_mutex_unlock(&bta_alarm_lock);
- if (alarm == NULL) {
- LOG_ERROR("%s unable to get alarm", __func__);
- return 0;
- }
+ BT_HDR *p_buf = (BT_HDR *)osi_getbuf(sizeof(BT_HDR));
- return alarm_get_remaining_ms(alarm);
-}
-
-
-/*******************************************************************************
-**
-** Function bta_sys_stop_timer
-**
-** Description Stop a BTA timer.
-**
-** Returns void
-**
-*******************************************************************************/
-void bta_sys_stop_timer(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_DEBUG(LOG_TAG, "%s expected alarm was not in bta alarm hash map.", __func__);
- return;
- }
- alarm_cancel(alarm);
+ p_buf->event = event;
+ p_buf->layer_specific = layer_specific;
+ alarm_set_on_queue(alarm, interval, bta_sys_sendmsg, p_buf,
+ btu_bta_alarm_queue);
}
/*******************************************************************************
diff --git a/btif/include/btif_gatt_multi_adv_util.h b/btif/include/btif_gatt_multi_adv_util.h
index a7580f0..456ccf5 100644
--- a/btif/include/btif_gatt_multi_adv_util.h
+++ b/btif/include/btif_gatt_multi_adv_util.h
@@ -56,7 +56,7 @@
tBTA_BLE_AD_MASK mask;
tBTA_BLE_ADV_DATA data;
tBTA_BLE_ADV_PARAMS param;
- timer_entry_t timer_entry;
+ alarm_t *multi_adv_timer;
int timeout_s;
} btgatt_multi_adv_inst_cb;
@@ -90,5 +90,5 @@
int service_data_len, char* service_data, int service_uuid_len,
char* service_uuid, btif_adv_data_t *p_multi_adv_inst);
extern void btif_gattc_adv_data_cleanup(const btif_adv_data_t* adv);
-void btif_multi_adv_timer_ctrl(int client_if, timer_callback_t cb);
+void btif_multi_adv_timer_ctrl(int client_if, alarm_callback_t cb);
diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h
index 97b5cd7..cf9731f 100644
--- a/btif/include/btif_hh.h
+++ b/btif/include/btif_hh.h
@@ -67,8 +67,7 @@
BOOLEAN ready_for_data;
pthread_t hh_poll_thread_id;
UINT8 hh_keep_polling;
- BOOLEAN vup_timer_active;
- timer_entry_t vup_timer;
+ alarm_t *vup_timer;
BOOLEAN local_vup; // Indicated locally initiated VUP
} btif_hh_device_t;
diff --git a/btif/include/btif_hl.h b/btif/include/btif_hl.h
index 1926541..f94c833 100644
--- a/btif/include/btif_hl.h
+++ b/btif/include/btif_hl.h
@@ -23,7 +23,7 @@
#include "bta_hl_api.h"
#include "bt_common.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
/*******************************************************************************
** Constants & Macros
@@ -215,8 +215,7 @@
UINT8 sdp_idx;
tBTA_HL_SDP sdp;
btif_hl_cch_op_t cch_oper;
- BOOLEAN cch_timer_active;
- timer_entry_t cch_timer;
+ alarm_t *cch_timer;
} btif_hl_mcl_cb_t;
typedef struct
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c
index f2dde9d..160a8d3 100644
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -51,11 +51,13 @@
#include "btsnoop.h"
#include "btsnoop_mem.h"
#include "osi/include/allocation_tracker.h"
+#include "osi/include/alarm.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/wakelock.h"
#include "stack_manager.h"
#include "btif_config.h"
+#include "btif/include/btif_debug_btsnoop.h"
/************************************************************************************
** Constants & Macros
@@ -322,6 +324,12 @@
static void dump(int fd)
{
btif_debug_dump(fd);
+ alarm_debug_dump(fd);
+#if defined(BTSNOOP_MEM) && (BTSNOOP_MEM == TRUE)
+ btif_debug_btsnoop_dump(fd);
+#endif
+
+ close(fd);
}
static const void* get_profile_interface (const char *profile_id)
diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c
index ff3c8c2..7268dc8 100644
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -40,7 +40,7 @@
#define BTIF_AV_SERVICE_NAME "Advanced Audio"
#define BTIF_AVK_SERVICE_NAME "Advanced Audio Sink"
-#define BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS 2
+#define BTIF_TIMEOUT_AV_OPEN_ON_RC_MS (2 * 1000)
typedef enum {
BTIF_AV_STATE_IDLE = 0x0,
@@ -93,7 +93,7 @@
static btav_callbacks_t *bt_av_src_callbacks = NULL;
static btav_callbacks_t *bt_av_sink_callbacks = NULL;
static btif_av_cb_t btif_av_cb = {0};
-static timer_entry_t te_av_open_on_rc;
+static alarm_t *av_open_on_rc_timer = NULL;
/* both interface and media task needs to be ready to alloc incoming request */
#define CHECK_BTAV_INIT() if (((bt_av_src_callbacks == NULL) &&(bt_av_sink_callbacks == NULL)) \
@@ -145,6 +145,8 @@
extern UINT8 btif_rc_get_connected_peer_handle(void);
extern void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp);
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*****************************************************************************
** Local helper functions
******************************************************************************/
@@ -208,7 +210,7 @@
*****************************************************************************/
/*******************************************************************************
**
-** Function btif_initiate_av_open_tmr_hdlr
+** Function btif_initiate_av_open_timer_timeout
**
** Description Timer to trigger AV open if the remote headset establishes
** RC connection w/o AV connection. The timer is needed to IOP
@@ -217,11 +219,11 @@
** Returns void
**
*******************************************************************************/
-static void btif_initiate_av_open_tmr_hdlr(timer_entry_t *p_te)
+static void btif_initiate_av_open_timer_timeout(UNUSED_ATTR void *data)
{
BD_ADDR peer_addr;
btif_av_connect_req_t connect_req;
- UNUSED(p_te);
+
/* is there at least one RC connection - There should be */
if (btif_rc_get_connected_peer(peer_addr)) {
BTIF_TRACE_DEBUG("%s Issuing connect to the remote RC peer", __FUNCTION__);
@@ -335,10 +337,10 @@
*/
BTIF_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV");
- memset(&te_av_open_on_rc, 0, sizeof(te_av_open_on_rc));
- te_av_open_on_rc.param = btif_initiate_av_open_tmr_hdlr;
- btu_start_timer(&te_av_open_on_rc, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_AV_OPEN_ON_RC_SECS);
+ alarm_set_on_queue(av_open_on_rc_timer,
+ BTIF_TIMEOUT_AV_OPEN_ON_RC_MS,
+ btif_initiate_av_open_timer_timeout, NULL,
+ btu_general_alarm_queue);
btif_rc_handler(event, p_data);
break;
@@ -417,10 +419,8 @@
break;
case BTA_AV_RC_CLOSE_EVT:
- if (te_av_open_on_rc.in_use) {
- BTIF_TRACE_DEBUG("BTA_AV_RC_CLOSE_EVT: Stopping AV timer.");
- btu_stop_timer(&te_av_open_on_rc);
- }
+ BTIF_TRACE_DEBUG("BTA_AV_RC_CLOSE_EVT: Stopping AV timer.");
+ alarm_cancel(av_open_on_rc_timer);
btif_rc_handler(event, p_data);
break;
@@ -1154,6 +1154,8 @@
{
if (btif_av_cb.sm_handle == NULL)
{
+ alarm_free(av_open_on_rc_timer);
+ av_open_on_rc_timer = alarm_new("btif_av.av_open_on_rc_timer");
if (!btif_a2dp_start_media_task())
return BT_STATUS_FAIL;
diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c
index d8cfc62..5f389b4 100644
--- a/btif/src/btif_config.c
+++ b/btif/src/btif_config.c
@@ -94,7 +94,7 @@
static pthread_mutex_t lock; // protects operations on |config|.
static config_t *config;
-static alarm_t *alarm_timer;
+static alarm_t *config_timer;
// Module lifecycle functions
@@ -122,19 +122,19 @@
// TODO(sharvil): use a non-wake alarm for this once we have
// API support for it. There's no need to wake the system to
// write back to disk.
- alarm_timer = alarm_new();
- if (!alarm_timer) {
+ config_timer = alarm_new("btif.config");
+ if (!config_timer) {
LOG_ERROR(LOG_TAG, "%s unable to create alarm.", __func__);
goto error;
}
return future_new_immediate(FUTURE_SUCCESS);
-error:;
- alarm_free(alarm_timer);
+error:
+ alarm_free(config_timer);
config_free(config);
pthread_mutex_destroy(&lock);
- alarm_timer = NULL;
+ config_timer = NULL;
config = NULL;
return future_new_immediate(FUTURE_FAIL);
}
@@ -147,10 +147,10 @@
static future_t *clean_up(void) {
btif_config_flush();
- alarm_free(alarm_timer);
+ alarm_free(config_timer);
config_free(config);
pthread_mutex_destroy(&lock);
- alarm_timer = NULL;
+ config_timer = NULL;
config = NULL;
return future_new_immediate(FUTURE_SUCCESS);
}
@@ -355,17 +355,17 @@
}
void btif_config_save(void) {
- assert(alarm_timer != NULL);
+ assert(config_timer != NULL);
assert(config != NULL);
- alarm_set(alarm_timer, CONFIG_SETTLE_PERIOD_MS, timer_config_save_cb, NULL);
+ alarm_set(config_timer, CONFIG_SETTLE_PERIOD_MS, timer_config_save_cb, NULL);
}
void btif_config_flush(void) {
assert(config != NULL);
- assert(alarm_timer != NULL);
+ assert(config_timer != NULL);
- alarm_cancel(alarm_timer);
+ alarm_cancel(config_timer);
btif_config_write(0, NULL);
pthread_mutex_lock(&lock);
@@ -375,9 +375,9 @@
int btif_config_clear(void){
assert(config != NULL);
- assert(alarm_timer != NULL);
+ assert(config_timer != NULL);
- alarm_cancel(alarm_timer);
+ alarm_cancel(config_timer);
pthread_mutex_lock(&lock);
config_free(config);
@@ -402,7 +402,7 @@
static void btif_config_write(UNUSED_ATTR UINT16 event, UNUSED_ATTR char *p_param) {
assert(config != NULL);
- assert(alarm_timer != NULL);
+ assert(config_timer != NULL);
btif_config_devcache_cleanup();
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index 9ae88a6..cf472f8 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -242,9 +242,9 @@
********************************************************************************/
static bt_status_t btif_gattc_multi_adv_disable(int client_if);
-static void btif_multi_adv_stop_cb(void *p_te)
+static void btif_multi_adv_stop_cb(void *data)
{
- int client_if = PTR_TO_INT(((timer_entry_t*)p_te)->data);
+ int client_if = PTR_TO_INT(data);
btif_gattc_multi_adv_disable(client_if); // Does context switch
}
@@ -680,7 +680,8 @@
, p_btif_cb->status
);
btif_multi_adv_timer_ctrl(p_btif_cb->client_if,
- (p_btif_cb->status==0 ? btif_multi_adv_stop_cb : NULL));
+ (p_btif_cb->status == BTA_GATT_OK) ?
+ btif_multi_adv_stop_cb : NULL);
break;
}
@@ -692,7 +693,8 @@
, p_btif_cb->status
);
btif_multi_adv_timer_ctrl(p_btif_cb->client_if,
- (p_btif_cb->status==0 ? btif_multi_adv_stop_cb : NULL));
+ (p_btif_cb->status == BTA_GATT_OK) ?
+ btif_multi_adv_stop_cb : NULL);
break;
}
diff --git a/btif/src/btif_gatt_multi_adv_util.c b/btif/src/btif_gatt_multi_adv_util.c
index f695256..830a605 100644
--- a/btif/src/btif_gatt_multi_adv_util.c
+++ b/btif/src/btif_gatt_multi_adv_util.c
@@ -44,6 +44,8 @@
#include "btif_gatt_multi_adv_util.h"
#include "btif_gatt_util.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
** Static variables
********************************************************************************/
@@ -502,9 +504,8 @@
// Discoverability timer cleanup
if (stop_timer)
{
- if (p_multi_inst_cb->timer_entry.in_use)
- btu_stop_timer_oneshot(&p_multi_inst_cb->timer_entry);
- p_multi_inst_cb->timer_entry.in_use = 0;
+ alarm_free(p_multi_inst_cb->multi_adv_timer);
+ p_multi_inst_cb->multi_adv_timer = NULL;
}
memset(&p_multi_inst_cb->data, 0, sizeof(p_multi_inst_cb->data));
@@ -517,7 +518,7 @@
*buf = NULL;
}
-void btif_multi_adv_timer_ctrl(int client_if, timer_callback_t cb)
+void btif_multi_adv_timer_ctrl(int client_if, alarm_callback_t cb)
{
int inst_id = btif_multi_adv_instid_for_clientif(client_if);
if (inst_id == INVALID_ADV_INST)
@@ -531,21 +532,20 @@
if (p_multi_adv_data_cb == NULL)
return;
+ btgatt_multi_adv_inst_cb *inst_cb = &p_multi_adv_data_cb->inst_cb[cbindex];
if (cb == NULL)
{
- if (p_multi_adv_data_cb->inst_cb[cbindex].timer_entry.in_use)
- btu_stop_timer_oneshot(&p_multi_adv_data_cb->inst_cb[cbindex].timer_entry);
+ alarm_free(inst_cb->multi_adv_timer);
+ inst_cb->multi_adv_timer = NULL;
} else {
- if (p_multi_adv_data_cb->inst_cb[cbindex].timeout_s != 0)
+ if (inst_cb->timeout_s != 0)
{
- if (p_multi_adv_data_cb->inst_cb[cbindex].timer_entry.in_use)
- btu_stop_timer_oneshot(&p_multi_adv_data_cb->inst_cb[cbindex].timer_entry);
-
- memset(&p_multi_adv_data_cb->inst_cb[cbindex].timer_entry, 0, sizeof(timer_entry_t));
- p_multi_adv_data_cb->inst_cb[cbindex].timer_entry.param = cb;
- p_multi_adv_data_cb->inst_cb[cbindex].timer_entry.data = INT_TO_PTR(client_if);
- btu_start_timer_oneshot(&p_multi_adv_data_cb->inst_cb[cbindex].timer_entry,
- BTU_TTYPE_USER_FUNC, p_multi_adv_data_cb->inst_cb[cbindex].timeout_s);
+ alarm_free(inst_cb->multi_adv_timer);
+ inst_cb->multi_adv_timer = alarm_new("btif_gatt.multi_adv_timer");
+ alarm_set_on_queue(inst_cb->multi_adv_timer,
+ inst_cb->timeout_s * 1000,
+ cb, INT_TO_PTR(client_if),
+ btu_general_alarm_queue);
}
}
}
diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c
index 7eb9770..bd88f24 100644
--- a/btif/src/btif_hh.c
+++ b/btif/src/btif_hh.c
@@ -29,6 +29,7 @@
#include "btif_hh.h"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -64,6 +65,7 @@
#define LOGITECH_KB_MX5500_VENDOR_ID 0x046D
#define LOGITECH_KB_MX5500_PRODUCT_ID 0xB30B
+extern fixed_queue_t *btu_general_alarm_queue;
extern const int BT_UID;
extern const int BT_GID;
static int btif_hh_keylockstates=0; //The current key state of each key
@@ -71,7 +73,7 @@
#define BTIF_HH_ID_1 0
#define BTIF_HH_DEV_DISCONNECTED 3
-#define BTIF_TIMEOUT_VUP_SECS 3
+#define BTIF_TIMEOUT_VUP_MS (3 * 1000)
#ifndef BTUI_HH_SECURITY
#define BTUI_HH_SECURITY (BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)
@@ -158,7 +160,7 @@
static void toggle_os_keylockstates(int fd, int changedkeystates);
static void sync_lockstate_on_connect(btif_hh_device_t *p_dev);
//static void hh_update_keyboard_lockstates(btif_hh_device_t *p_dev);
-void btif_hh_tmr_hdlr(timer_entry_t *p_te);
+void btif_hh_timer_timeout(void *data);
/************************************************************************************
** Functions
@@ -397,15 +399,12 @@
*******************************************************************************/
void btif_hh_stop_vup_timer(bt_bdaddr_t *bd_addr)
{
- btif_hh_device_t *p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
- if(p_dev != NULL)
- {
- if (p_dev->vup_timer_active)
- {
- BTIF_TRACE_DEBUG("stop VUP timer ");
- btu_stop_timer(&p_dev->vup_timer);
- }
- p_dev->vup_timer_active = FALSE;
+ btif_hh_device_t *p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
+
+ if (p_dev != NULL) {
+ BTIF_TRACE_DEBUG("stop VUP timer");
+ alarm_free(p_dev->vup_timer);
+ p_dev->vup_timer = NULL;
}
}
/*******************************************************************************
@@ -418,25 +417,16 @@
*******************************************************************************/
void btif_hh_start_vup_timer(bt_bdaddr_t *bd_addr)
{
+ BTIF_TRACE_DEBUG("%s", __func__);
+
btif_hh_device_t *p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
+ assert(p_dev != NULL);
- if (p_dev->vup_timer_active == FALSE)
- {
- BTIF_TRACE_DEBUG("Start VUP timer ");
- memset(&p_dev->vup_timer, 0, sizeof(timer_entry_t));
- p_dev->vup_timer.param = btif_hh_tmr_hdlr;
- btu_start_timer(&p_dev->vup_timer, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_VUP_SECS);
- }
- else
- {
- BTIF_TRACE_DEBUG("Restart VUP timer ");
- btu_stop_timer(&p_dev->vup_timer);
- btu_start_timer(&p_dev->vup_timer, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_VUP_SECS);
- }
- p_dev->vup_timer_active = TRUE;
-
+ alarm_free(p_dev->vup_timer);
+ p_dev->vup_timer = alarm_new("btif_hh.vup_timer");
+ alarm_set_on_queue(p_dev->vup_timer, BTIF_TIMEOUT_VUP_MS,
+ btif_hh_timer_timeout, p_dev,
+ btu_general_alarm_queue);
}
/*******************************************************************************
@@ -744,9 +734,12 @@
btif_hh_cb.status = BTIF_HH_DISABLED;
if (p_data->status == BTA_HH_OK) {
int i;
- //Clear the control block
+ // Clear the control block
+ for (i = 0; i < BTIF_HH_MAX_HID; i++) {
+ alarm_free(btif_hh_cb.devices[i].vup_timer);
+ }
memset(&btif_hh_cb, 0, sizeof(btif_hh_cb));
- for (i = 0; i < BTIF_HH_MAX_HID; i++){
+ for (i = 0; i < BTIF_HH_MAX_HID; i++) {
btif_hh_cb.devices[i].dev_status = BTHH_CONN_STATE_UNKNOWN;
}
}
@@ -792,8 +785,7 @@
btif_dm_hh_open_failed(bdaddr);
p_dev = btif_hh_find_dev_by_bda(bdaddr);
if (p_dev != NULL) {
- if(p_dev->vup_timer_active)
- btif_hh_stop_vup_timer(&(p_dev->bd_addr));
+ btif_hh_stop_vup_timer(&(p_dev->bd_addr));
if (p_dev->fd >= 0) {
bta_hh_co_destroy(p_dev->fd);
p_dev->fd = -1;
@@ -811,8 +803,7 @@
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev != NULL) {
BTIF_TRACE_DEBUG("%s: uhid fd = %d", __FUNCTION__, p_dev->fd);
- if(p_dev->vup_timer_active)
- btif_hh_stop_vup_timer(&(p_dev->bd_addr));
+ btif_hh_stop_vup_timer(&(p_dev->bd_addr));
if (p_dev->fd >= 0) {
bta_hh_co_destroy(p_dev->fd);
p_dev->fd = -1;
@@ -1032,10 +1023,7 @@
p_dev->bd_addr.address[2],p_dev->bd_addr.address[3],
p_dev->bd_addr.address[4], p_dev->bd_addr.address[5]);
/* Stop the VUP timer */
- if(p_dev->vup_timer_active)
- {
- btif_hh_stop_vup_timer(&(p_dev->bd_addr));
- }
+ btif_hh_stop_vup_timer(&(p_dev->bd_addr));
p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
BTIF_TRACE_DEBUG("%s---Sending connection state change", __FUNCTION__);
HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
@@ -1158,43 +1146,30 @@
/*******************************************************************************
**
-** Function btif_hh_tmr_hdlr
+** Function btif_hh_timer_timeout
**
** Description Process timer timeout
**
** Returns void
*******************************************************************************/
-void btif_hh_tmr_hdlr(timer_entry_t *p_te)
+void btif_hh_timer_timeout(void *data)
{
- btif_hh_device_t *p_dev;
- UINT8 i;
- tBTA_HH_EVT event;
+ btif_hh_device_t *p_dev = (btif_hh_device_t *)data;
+ tBTA_HH_EVT event = BTA_HH_VC_UNPLUG_EVT;
tBTA_HH p_data;
- int param_len = 0;
+ int param_len = sizeof(tBTA_HH_CBDATA);
+
+ BTIF_TRACE_DEBUG("%s", __func__);
+ if (p_dev->dev_status != BTHH_CONN_STATE_CONNECTED)
+ return;
+
memset(&p_data, 0, sizeof(tBTA_HH));
+ p_data.dev_status.status = BTHH_ERR;
+ p_data.dev_status.handle = p_dev->dev_handle;
- BTIF_TRACE_DEBUG("%s timer_in_use=%d", __FUNCTION__, p_te->in_use);
-
- for (i = 0; i < BTIF_HH_MAX_HID; i++) {
- if (btif_hh_cb.devices[i].dev_status == BTHH_CONN_STATE_CONNECTED)
- {
-
- p_dev = &btif_hh_cb.devices[i];
-
- if (p_dev->vup_timer_active)
- {
- p_dev->vup_timer_active = FALSE;
- event = BTA_HH_VC_UNPLUG_EVT;
- p_data.dev_status.status = BTHH_ERR;
- p_data.dev_status.handle = p_dev->dev_handle;
- param_len = sizeof(tBTA_HH_CBDATA);
-
- /* switch context to btif task context */
- btif_transfer_context(btif_hh_upstreams_evt, (uint16_t)event, (void*)&p_data,
- param_len, NULL);
- }
- }
- }
+ /* switch context to btif task context */
+ btif_transfer_context(btif_hh_upstreams_evt, (uint16_t)event,
+ (char *)&p_data, param_len, NULL);
}
/*******************************************************************************
diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c
index 14f0343..f1cf4b3 100644
--- a/btif/src/btif_hl.c
+++ b/btif/src/btif_hl.c
@@ -70,6 +70,8 @@
extern BOOLEAN btif_hl_create_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx);
extern void btif_hl_release_socket(UINT8 app_idx, UINT8 mcl_idx, UINT8 mdl_idx);
+extern fixed_queue_t *btu_general_alarm_queue;
+
btif_hl_cb_t btif_hl_cb;
btif_hl_cb_t *p_btif_hl_cb = &btif_hl_cb;
@@ -168,7 +170,8 @@
prctl(BTIF_IF_GET_NAME, name, 0, 0, 0);
BTIF_TRACE_DEBUG("Process name (%s)", name);
}
-#define BTIF_TIMEOUT_CCH_NO_DCH_SECS 30
+#define BTIF_TIMEOUT_CCH_NO_DCH_MS (30 * 1000)
+
/*******************************************************************************
**
** Function btif_hl_if_channel_setup_pending
@@ -262,43 +265,26 @@
}
/*******************************************************************************
**
-** Function btif_hl_tmr_hdlr
+** Function btif_hl_timer_timeout
**
** Description Process timer timeout
**
** Returns void
*******************************************************************************/
-void btif_hl_tmr_hdlr(timer_entry_t *p_te)
+void btif_hl_timer_timeout(void *data)
{
- btif_hl_mcl_cb_t *p_mcb;
- UINT8 i,j;
- BTIF_TRACE_DEBUG("%s timer_in_use=%d", __FUNCTION__, p_te->in_use);
+ btif_hl_mcl_cb_t *p_mcb = (btif_hl_mcl_cb_t *)data;
- for (i=0; i < BTA_HL_NUM_APPS ; i ++)
- {
- for (j=0; j< BTA_HL_NUM_MCLS; j++)
- {
- p_mcb =BTIF_HL_GET_MCL_CB_PTR(i,j);
-
- if (p_mcb->cch_timer_active)
- {
- BTIF_TRACE_DEBUG("%app_idx=%d, mcl_idx=%d mcl-connected=%d",
- i, j, p_mcb->is_connected);
- p_mcb->cch_timer_active = FALSE;
- if (p_mcb->is_connected)
- {
- BTIF_TRACE_DEBUG("Idle timeout Close CCH app_idx=%d mcl_idx=%d mcl_handle=%d",
- i ,j, p_mcb->mcl_handle);
- BTA_HlCchClose(p_mcb->mcl_handle);
- }
- else
- {
- BTIF_TRACE_DEBUG("CCH idle timeout But CCH not connected app_idx=%d mcl_idx=%d ",i,j);
- }
- }
- }
+ BTIF_TRACE_DEBUG("%s", __func__);
+ if (p_mcb->is_connected) {
+ BTIF_TRACE_DEBUG("Idle timeout Close CCH mcl_handle=%d",
+ p_mcb->mcl_handle);
+ BTA_HlCchClose(p_mcb->mcl_handle);
+ } else {
+ BTIF_TRACE_DEBUG("CCH idle timeout But CCH not connected");
}
}
+
/*******************************************************************************
**
** Function btif_hl_stop_cch_timer
@@ -310,16 +296,11 @@
void btif_hl_stop_cch_timer(UINT8 app_idx, UINT8 mcl_idx)
{
btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
- BTIF_TRACE_DEBUG("%s app_idx=%d, mcl_idx=%d timer_in_use=%d",
- __FUNCTION__,app_idx, mcl_idx, p_mcb->cch_timer.in_use);
- p_mcb->cch_timer_active = FALSE;
- if (p_mcb->cch_timer.in_use)
- {
- BTIF_TRACE_DEBUG("stop CCH timer ");
- btu_stop_timer(&p_mcb->cch_timer);
- }
+ BTIF_TRACE_DEBUG("%s app_idx=%d, mcl_idx=%d", __func__, app_idx, mcl_idx);
+ alarm_cancel(p_mcb->cch_timer);
}
+
/*******************************************************************************
**
** Function btif_hl_start_cch_timer
@@ -331,28 +312,15 @@
void btif_hl_start_cch_timer(UINT8 app_idx, UINT8 mcl_idx)
{
btif_hl_mcl_cb_t *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
- BTIF_TRACE_DEBUG("%s app_idx=%d, mcl_idx=%d timer_active=%d timer_in_use=%d",
- __FUNCTION__,app_idx, mcl_idx,
- p_mcb->cch_timer_active, p_mcb->cch_timer.in_use);
+ BTIF_TRACE_DEBUG("%s app_idx=%d, mcl_idx=%d", __func__, app_idx, mcl_idx);
- p_mcb->cch_timer_active = TRUE;
- if (!p_mcb->cch_timer.in_use)
- {
- BTIF_TRACE_DEBUG("Start CCH timer ");
- memset(&p_mcb->cch_timer, 0, sizeof(timer_entry_t));
- p_mcb->cch_timer.param = btif_hl_tmr_hdlr;
- btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_CCH_NO_DCH_SECS);
- }
- else
- {
- BTIF_TRACE_DEBUG("Restart CCH timer ");
- btu_stop_timer(&p_mcb->cch_timer);
- btu_start_timer(&p_mcb->cch_timer, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_CCH_NO_DCH_SECS);
- }
-
+ alarm_free(p_mcb->cch_timer);
+ p_mcb->cch_timer = alarm_new("btif_hl.mcl_cch_timer");
+ alarm_set_on_queue(p_mcb->cch_timer, BTIF_TIMEOUT_CCH_NO_DCH_MS,
+ btif_hl_timer_timeout, p_mcb,
+ btu_general_alarm_queue);
}
+
/*******************************************************************************
**
** Function btif_hl_find_mdl_idx
@@ -511,6 +479,7 @@
btif_hl_mcl_cb_t *p_mcb;
BTIF_TRACE_DEBUG("%s app_idx=%d, mcl_idx=%d", __FUNCTION__,app_idx, mcl_idx);
p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
+ alarm_free(p_mcb->cch_timer);
memset(p_mcb, 0, sizeof(btif_hl_mcl_cb_t));
}
@@ -897,7 +866,8 @@
if (btif_hl_find_avail_mcl_idx(app_idx, &mcl_idx))
{
p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
- memset(p_mcb,0, sizeof(btif_hl_mcl_cb_t));
+ alarm_free(p_mcb->cch_timer);
+ memset(p_mcb, 0, sizeof(btif_hl_mcl_cb_t));
p_mcb->in_use = TRUE;
bdcpy(p_mcb->bd_addr, bd_addr);
@@ -1343,7 +1313,9 @@
if ((app_idx < BTA_HL_NUM_APPS) && btif_hl_cb.acb[app_idx].in_use )
{
btif_hl_cb.acb[app_idx].in_use = FALSE;
- memset (&btif_hl_cb.acb[app_idx], 0, sizeof(btif_hl_app_cb_t));
+ for (size_t i = 0; i < BTA_HL_NUM_MCLS; i++)
+ alarm_free(btif_hl_cb.acb[app_idx].mcb[i].cch_timer);
+ memset(&btif_hl_cb.acb[app_idx], 0, sizeof(btif_hl_app_cb_t));
}
}
/*******************************************************************************
@@ -2080,7 +2052,9 @@
if (p_data->dereg_cfm.status == BTA_HL_STATUS_OK)
{
btif_hl_clean_mdls_using_app_idx(app_idx);
- memset(p_acb, 0,sizeof(btif_hl_app_cb_t));
+ for (size_t i = 0; i < BTA_HL_NUM_MCLS; i++)
+ alarm_free(p_acb->mcb[i].cch_timer);
+ memset(p_acb, 0, sizeof(btif_hl_app_cb_t));
}
else
state = BTHL_APP_REG_STATE_DEREG_FAILED;
@@ -2422,6 +2396,7 @@
if (btif_hl_find_avail_mcl_idx(i, &mcl_idx))
{
p_mcb = BTIF_HL_GET_MCL_CB_PTR(i, mcl_idx);
+ alarm_free(p_mcb->cch_timer);
memset(p_mcb, 0, sizeof(btif_hl_mcl_cb_t));
p_mcb->in_use = TRUE;
p_mcb->is_connected = TRUE;
@@ -3836,6 +3811,11 @@
if (p_data->disable_cfm.status == BTA_HL_STATUS_OK)
{
+ for (size_t i = 0; i < BTA_HL_NUM_APPS; i++) {
+ for (size_t j = 0; j < BTA_HL_NUM_MCLS; j++) {
+ alarm_free(p_btif_hl_cb->acb[i].mcb[j].cch_timer);
+ }
+ }
memset(p_btif_hl_cb, 0, sizeof(btif_hl_cb_t));
btif_hl_set_state(BTIF_HL_STATE_DISABLED);
}
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c
index 2eefcb1..a79c3c1 100644
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -223,8 +223,6 @@
#if (BTA_AV_INCLUDED == TRUE)
fixed_queue_t *TxAaQ;
fixed_queue_t *RxSbcQ;
- BOOLEAN is_tx_timer;
- BOOLEAN is_rx_timer;
UINT16 TxAaMtuSize;
UINT32 timestamp;
UINT8 TxTranscoding;
@@ -392,8 +390,7 @@
/* send stop request only if we are actively streaming and haven't received
a stop request. Potentially audioflinger detached abnormally */
- if (btif_media_cb.is_tx_timer)
- {
+ if (alarm_is_scheduled(btif_media_cb.media_alarm)) {
/* post stop event and wait for audio path to stop */
btif_dispatch_sm_event(BTIF_AV_STOP_STREAM_REQ_EVT, NULL, 0);
}
@@ -502,7 +499,8 @@
break;
case A2DP_CTRL_CMD_STOP:
- if (btif_media_cb.peer_sep == AVDT_TSEP_SNK && btif_media_cb.is_tx_timer == FALSE)
+ if (btif_media_cb.peer_sep == AVDT_TSEP_SNK &&
+ (!alarm_is_scheduled(btif_media_cb.media_alarm)))
{
/* we are already stopped, just ack back */
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
@@ -767,7 +765,6 @@
// Stop timer
alarm_free(btif_media_cb.media_alarm);
btif_media_cb.media_alarm = NULL;
- btif_media_cb.is_tx_timer = FALSE;
// Exit thread
fixed_queue_free(btif_media_cmd_msg_queue, NULL);
@@ -1248,7 +1245,7 @@
log_tstamps_us("media task tx timer");
#if (BTA_AV_INCLUDED == TRUE)
- if(btif_media_cb.is_tx_timer == TRUE)
+ if (alarm_is_scheduled(btif_media_cb.media_alarm))
{
btif_media_send_aa_frame();
}
@@ -1761,135 +1758,124 @@
SINT16 s16FrameLen;
UINT8 protect = 0;
- APPL_TRACE_DEBUG("btif_media_task_enc_update : minmtu %d, maxbp %d minbp %d",
- pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool, pUpdateAudio->MinBitPool);
+ APPL_TRACE_DEBUG("%s : minmtu %d, maxbp %d minbp %d", __func__,
+ pUpdateAudio->MinMtuSize, pUpdateAudio->MaxBitPool,
+ pUpdateAudio->MinBitPool);
- /* Only update the bitrate and MTU size while timer is running to make sure it has been initialized */
- //if (btif_media_cb.is_tx_timer)
- {
- btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE -
- BTIF_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE -
+ BTIF_MEDIA_AA_SBC_OFFSET - sizeof(BT_HDR))
< pUpdateAudio->MinMtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_SBC_OFFSET
- sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
- /* Set the initial target bit rate */
- pstrEncParams->u16BitRate = btif_media_task_get_sbc_rate();
+ /* Set the initial target bit rate */
+ pstrEncParams->u16BitRate = btif_media_task_get_sbc_rate();
- if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
- s16SamplingFreq = 16000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
- s16SamplingFreq = 32000;
- else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
- s16SamplingFreq = 44100;
- else
- s16SamplingFreq = 48000;
+ if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
+ s16SamplingFreq = 16000;
+ else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
+ s16SamplingFreq = 32000;
+ else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
+ s16SamplingFreq = 44100;
+ else
+ s16SamplingFreq = 48000;
- do
- {
- if (pstrEncParams->s16NumOfBlocks == 0 || pstrEncParams->s16NumOfSubBands == 0
- || pstrEncParams->s16NumOfChannels == 0)
- {
- APPL_TRACE_ERROR("btif_media_task_enc_update() - Avoiding division by zero...");
- APPL_TRACE_ERROR("btif_media_task_enc_update() - block=%d, subBands=%d, channels=%d",
- pstrEncParams->s16NumOfBlocks, pstrEncParams->s16NumOfSubBands,
- pstrEncParams->s16NumOfChannels);
- break;
- }
+ do {
+ if (pstrEncParams->s16NumOfBlocks == 0 ||
+ pstrEncParams->s16NumOfSubBands == 0 ||
+ pstrEncParams->s16NumOfChannels == 0) {
+ APPL_TRACE_ERROR("%s - Avoiding division by zero...", __func__);
+ APPL_TRACE_ERROR("%s - block=%d, subBands=%d, channels=%d",
+ __func__,
+ pstrEncParams->s16NumOfBlocks,
+ pstrEncParams->s16NumOfSubBands,
+ pstrEncParams->s16NumOfChannels);
+ break;
+ }
- if ((pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) ||
- (pstrEncParams->s16ChannelMode == SBC_STEREO) )
- {
- s16BitPool = (SINT16)( (pstrEncParams->u16BitRate *
+ if ((pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) ||
+ (pstrEncParams->s16ChannelMode == SBC_STEREO)) {
+ s16BitPool = (SINT16)((pstrEncParams->u16BitRate *
pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
- -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
+ - ((32 + (4 * pstrEncParams->s16NumOfSubBands *
pstrEncParams->s16NumOfChannels)
- + ( (pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands ) )
- / pstrEncParams->s16NumOfBlocks) );
+ + ((pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands))
+ / pstrEncParams->s16NumOfBlocks));
- s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
- pstrEncParams->s16NumOfChannels)/8
- + ( ((pstrEncParams->s16ChannelMode - 2) *
+ s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands *
+ pstrEncParams->s16NumOfChannels) / 8
+ + (((pstrEncParams->s16ChannelMode - 2) *
pstrEncParams->s16NumOfSubBands)
- + (pstrEncParams->s16NumOfBlocks * s16BitPool) ) / 8;
+ + (pstrEncParams->s16NumOfBlocks * s16BitPool)) / 8;
- s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
+ s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
/ (pstrEncParams->s16NumOfSubBands *
pstrEncParams->s16NumOfBlocks * 1000);
- if (s16BitRate > pstrEncParams->u16BitRate)
- s16BitPool--;
+ if (s16BitRate > pstrEncParams->u16BitRate)
+ s16BitPool--;
- if(pstrEncParams->s16NumOfSubBands == 8)
- s16BitPool = (s16BitPool > 255) ? 255 : s16BitPool;
- else
- s16BitPool = (s16BitPool > 128) ? 128 : s16BitPool;
- }
+ if (pstrEncParams->s16NumOfSubBands == 8)
+ s16BitPool = (s16BitPool > 255) ? 255 : s16BitPool;
else
- {
- s16BitPool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
+ s16BitPool = (s16BitPool > 128) ? 128 : s16BitPool;
+ } else {
+ s16BitPool = (SINT16)(((pstrEncParams->s16NumOfSubBands *
pstrEncParams->u16BitRate * 1000)
/ (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
- -( ( (32 / pstrEncParams->s16NumOfChannels) +
- (4 * pstrEncParams->s16NumOfSubBands) )
- / pstrEncParams->s16NumOfBlocks ) );
+ - (((32 / pstrEncParams->s16NumOfChannels) +
+ (4 * pstrEncParams->s16NumOfSubBands))
+ / pstrEncParams->s16NumOfBlocks));
- pstrEncParams->s16BitPool = (s16BitPool >
- (16 * pstrEncParams->s16NumOfSubBands))
- ? (16*pstrEncParams->s16NumOfSubBands) : s16BitPool;
- }
+ pstrEncParams->s16BitPool =
+ (s16BitPool > (16 * pstrEncParams->s16NumOfSubBands)) ?
+ (16 * pstrEncParams->s16NumOfSubBands) : s16BitPool;
+ }
- if (s16BitPool < 0)
- {
- s16BitPool = 0;
- }
+ if (s16BitPool < 0)
+ s16BitPool = 0;
- APPL_TRACE_EVENT("bitpool candidate : %d (%d kbps)",
+ APPL_TRACE_EVENT("%s bitpool candidate : %d (%d kbps)", __func__,
s16BitPool, pstrEncParams->u16BitRate);
- if (s16BitPool > pUpdateAudio->MaxBitPool)
- {
- APPL_TRACE_DEBUG("btif_media_task_enc_update computed bitpool too large (%d)",
- s16BitPool);
- /* Decrease bitrate */
- btif_media_cb.encoder.u16BitRate -= BTIF_MEDIA_BITRATE_STEP;
- /* Record that we have decreased the bitrate */
- protect |= 1;
- }
- else if (s16BitPool < pUpdateAudio->MinBitPool)
- {
- APPL_TRACE_WARNING("btif_media_task_enc_update computed bitpool too small (%d)", s16BitPool);
+ if (s16BitPool > pUpdateAudio->MaxBitPool) {
+ APPL_TRACE_DEBUG("%s computed bitpool too large (%d)", __func__,
+ s16BitPool);
+ /* Decrease bitrate */
+ btif_media_cb.encoder.u16BitRate -= BTIF_MEDIA_BITRATE_STEP;
+ /* Record that we have decreased the bitrate */
+ protect |= 1;
+ } else if (s16BitPool < pUpdateAudio->MinBitPool) {
+ APPL_TRACE_WARNING("%s computed bitpool too small (%d)", __func__,
+ s16BitPool);
- /* Increase bitrate */
- UINT16 previous_u16BitRate = btif_media_cb.encoder.u16BitRate;
- btif_media_cb.encoder.u16BitRate += BTIF_MEDIA_BITRATE_STEP;
- /* Record that we have increased the bitrate */
- protect |= 2;
- /* Check over-flow */
- if (btif_media_cb.encoder.u16BitRate < previous_u16BitRate)
- protect |= 3;
- }
- else
- {
- break;
- }
- /* In case we have already increased and decreased the bitrate, just stop */
- if (protect == 3)
- {
- APPL_TRACE_ERROR("btif_media_task_enc_update could not find bitpool in range");
- break;
- }
- } while (1);
+ /* Increase bitrate */
+ UINT16 previous_u16BitRate = btif_media_cb.encoder.u16BitRate;
+ btif_media_cb.encoder.u16BitRate += BTIF_MEDIA_BITRATE_STEP;
+ /* Record that we have increased the bitrate */
+ protect |= 2;
+ /* Check over-flow */
+ if (btif_media_cb.encoder.u16BitRate < previous_u16BitRate)
+ protect |= 3;
+ } else {
+ break;
+ }
+ /* In case we have already increased and decreased the bitrate, just stop */
+ if (protect == 3) {
+ APPL_TRACE_ERROR("%s could not find bitpool in range", __func__);
+ break;
+ }
+ } while (1);
- /* Finally update the bitpool in the encoder structure */
- pstrEncParams->s16BitPool = s16BitPool;
+ /* Finally update the bitpool in the encoder structure */
+ pstrEncParams->s16BitPool = s16BitPool;
- APPL_TRACE_DEBUG("btif_media_task_enc_update final bit rate %d, final bit pool %d",
- btif_media_cb.encoder.u16BitRate, btif_media_cb.encoder.s16BitPool);
+ APPL_TRACE_DEBUG("%s final bit rate %d, final bit pool %d", __func__,
+ btif_media_cb.encoder.u16BitRate,
+ btif_media_cb.encoder.s16BitPool);
- /* make sure we reinitialize encoder with new settings */
- SBC_Encoder_Init(&(btif_media_cb.encoder));
- }
+ /* make sure we reinitialize encoder with new settings */
+ SBC_Encoder_Init(&(btif_media_cb.encoder));
}
/*******************************************************************************
@@ -2079,13 +2065,14 @@
#ifdef USE_AUDIO_TRACK
BtifAvrcpAudioTrackStart(btif_media_cb.audio_track);
#endif
- btif_media_cb.decode_alarm = alarm_new();
+ btif_media_cb.decode_alarm = alarm_new_periodic("btif.media_decode");
if (!btif_media_cb.decode_alarm) {
LOG_ERROR(LOG_TAG, "%s unable to allocate decode alarm.", __func__);
return;
}
- alarm_set_periodic(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL);
+ alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK,
+ btif_decode_alarm_cb, NULL);
}
#if (BTA_AV_SINK_INCLUDED == TRUE)
@@ -2294,18 +2281,10 @@
*******************************************************************************/
static void btif_media_task_aa_start_tx(void)
{
- APPL_TRACE_DEBUG("btif_media_task_aa_start_tx is timer %d, feeding mode %d",
- btif_media_cb.is_tx_timer, btif_media_cb.feeding_mode);
+ APPL_TRACE_DEBUG("%s media_alarm %srunning, feeding mode %d", __func__,
+ alarm_is_scheduled(btif_media_cb.media_alarm)? "" : "not ",
+ btif_media_cb.feeding_mode);
- if (btif_media_cb.is_tx_timer) {
- LOG_ERROR(LOG_TAG, "%s media alarm already running", __func__);
- return;
- }
-
- /* Use a timer to poll the UIPC, get rid of the UIPC call back */
- // UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_CBACK, NULL);
-
- btif_media_cb.is_tx_timer = TRUE;
last_frame_us = 0;
/* Reset the media feeding state */
@@ -2313,16 +2292,15 @@
APPL_TRACE_EVENT("starting timer %dms", BTIF_MEDIA_TIME_TICK);
- assert(btif_media_cb.media_alarm == NULL);
-
- btif_media_cb.media_alarm = alarm_new();
+ alarm_free(btif_media_cb.media_alarm);
+ btif_media_cb.media_alarm = alarm_new_periodic("btif.media_task");
if (!btif_media_cb.media_alarm) {
LOG_ERROR(LOG_TAG, "%s unable to allocate media alarm.", __func__);
return;
}
- alarm_set_periodic(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK,
- btif_media_task_alarm_cb, NULL);
+ alarm_set(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK,
+ btif_media_task_alarm_cb, NULL);
}
/*******************************************************************************
@@ -2336,14 +2314,14 @@
*******************************************************************************/
static void btif_media_task_aa_stop_tx(void)
{
- APPL_TRACE_DEBUG("%s is_tx_timer: %d", __func__, btif_media_cb.is_tx_timer);
+ APPL_TRACE_DEBUG("%s media_alarm is %srunning", __func__,
+ alarm_is_scheduled(btif_media_cb.media_alarm)? "" : "not ");
- const bool send_ack = (btif_media_cb.is_tx_timer != FALSE);
+ const bool send_ack = alarm_is_scheduled(btif_media_cb.media_alarm);
/* Stop the timer first */
alarm_free(btif_media_cb.media_alarm);
btif_media_cb.media_alarm = NULL;
- btif_media_cb.is_tx_timer = FALSE;
UIPC_Close(UIPC_CH_ID_AV_AUDIO);
@@ -2720,7 +2698,7 @@
nb_frame = 0;
/* break read loop if timer was stopped (media task stopped) */
- if ( btif_media_cb.is_tx_timer == FALSE )
+ if (! alarm_is_scheduled(btif_media_cb.media_alarm))
{
osi_freebuf(p_buf);
return;
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index d0f38c7..4852413 100644
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -114,9 +114,9 @@
} btif_rc_cmd_ctxt_t;
/* 2 second timeout to get interim response */
-#define BTIF_TIMEOUT_RC_INTERIM_RSP 2
-#define BTIF_TIMEOUT_RC_STATUS_CMD 2
-#define BTIF_TIMEOUT_RC_CONTROL_CMD 2
+#define BTIF_TIMEOUT_RC_INTERIM_RSP_MS (2 * 1000)
+#define BTIF_TIMEOUT_RC_STATUS_CMD_MS (2 * 1000)
+#define BTIF_TIMEOUT_RC_CONTROL_CMD_MS (2 * 1000)
typedef enum
@@ -132,10 +132,6 @@
btif_rc_nfn_reg_status_t status;
} btif_rc_supported_event_t;
-#define RC_TIMER_STATUS_CMD 0
-#define RC_TIMER_CONTROL_CMD 1
-#define RC_TIMER_PLAY_STATUS 2
-
#define BTIF_RC_STS_TIMEOUT 0xFE
typedef struct {
UINT8 label;
@@ -148,12 +144,10 @@
} btif_rc_control_cmd_timer_t;
typedef struct {
- UINT8 timer_id;
union {
btif_rc_status_cmd_timer_t rc_status_cmd;
btif_rc_control_cmd_timer_t rc_control_cmd;
};
- timer_entry_t tle;
} btif_rc_timer_context_t;
typedef struct {
@@ -181,7 +175,7 @@
uint8_t rc_vol_label;
list_t *rc_supported_event_list;
btif_rc_player_app_settings_t rc_app_settings;
- timer_entry_t tle_rc_play_status;
+ alarm_t *rc_play_status_timer;
BOOLEAN rc_features_processed;
UINT64 rc_playing_uid;
BOOLEAN rc_procedure_complete;
@@ -191,7 +185,8 @@
BOOLEAN in_use;
UINT8 lbl;
UINT8 handle;
- timer_entry_t tle_txn;
+ btif_rc_timer_context_t txn_timer_context;
+ alarm_t *txn_timer;
} rc_transaction_t;
typedef struct
@@ -213,7 +208,7 @@
static int uinput_create(char *name);
static int init_uinput (void);
static void close_uinput (void);
-static void sleep_ms(uint32_t timeout_ms);
+static void sleep_ms(period_ms_t timeout_ms);
static const struct {
const char *name;
@@ -252,9 +247,8 @@
static void btif_rc_ctrl_upstreams_rsp_evt(
UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8* p_buf, UINT16 buf_len, UINT8 rsp_type);
static void rc_ctrl_procedure_complete();
-static void rc_stop_play_status_timer ();
+static void rc_stop_play_status_timer();
static void register_for_event_notification (btif_rc_supported_event_t *p_event);
-static void rc_timeout_handler (UINT16 event, char* p_data);
static void handle_get_capability_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_CAPS_RSP *p_rsp);
static void handle_app_attr_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_ATTR_RSP *p_rsp);
static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp);
@@ -276,6 +270,7 @@
#endif
static void btif_rc_upstreams_evt(UINT16 event, tAVRC_COMMAND* p_param, UINT8 ctype, UINT8 label);
static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp, UINT8 ctype, UINT8 label);
+static void rc_start_play_status_timer(void);
/*****************************************************************************
** Static variables
@@ -294,6 +289,8 @@
extern BOOLEAN btif_hf_call_terminated_recently();
extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*****************************************************************************
** Functions
******************************************************************************/
@@ -633,11 +630,7 @@
sizeof(btif_rc_player_app_settings_t));
btif_rc_cb.rc_features_processed = FALSE;
btif_rc_cb.rc_procedure_complete = FALSE;
- /* Check and stop play status timer */
- if (btif_rc_cb.tle_rc_play_status.in_use == TRUE)
- {
- rc_stop_play_status_timer();
- }
+ rc_stop_play_status_timer();
/* Check and clear the notification event list */
if (btif_rc_cb.rc_supported_event_list != NULL)
{
@@ -1512,7 +1505,7 @@
static void rc_supported_event_free(void* p_data)
{
- osi_freebuf (p_data);
+ osi_freebuf(p_data);
}
#endif
@@ -1810,7 +1803,7 @@
}
else
{
- if (NULL!=p_msg)
+ if (p_msg != NULL)
osi_freebuf(p_msg);
BTIF_TRACE_ERROR("%s: failed to obtain transaction details. status: 0x%02x",
__FUNCTION__, tran_status);
@@ -1865,7 +1858,7 @@
}
else
{
- if (NULL!=p_msg)
+ if (p_msg != NULL)
osi_freebuf(p_msg);
BTIF_TRACE_ERROR("%s transaction not obtained with label: %d",__FUNCTION__,lbl);
}
@@ -2041,22 +2034,165 @@
/***************************************************************************
**
-** Function rc_timeout_callback
+** Function btif_rc_status_cmd_timeout_handler
**
-** Description RC timeout callback.
+** Description RC status command timeout handler (Runs in BTIF context).
+** Returns None
+**
+***************************************************************************/
+static void btif_rc_status_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
+ char *data)
+{
+ btif_rc_timer_context_t *p_context;
+ tAVRC_RESPONSE avrc_response = {0};
+ tBTA_AV_META_MSG meta_msg;
+
+ p_context = (btif_rc_timer_context_t *)data;
+ memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
+ meta_msg.rc_handle = btif_rc_cb.rc_handle;
+
+ switch (p_context->rc_status_cmd.pdu_id) {
+ case AVRC_PDU_REGISTER_NOTIFICATION:
+ rc_notification_interim_timout(p_context->rc_status_cmd.label);
+ break;
+
+ case AVRC_PDU_GET_CAPABILITIES:
+ avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
+ handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
+ break;
+
+ case AVRC_PDU_LIST_PLAYER_APP_ATTR:
+ avrc_response.list_app_attr.status = BTIF_RC_STS_TIMEOUT;
+ handle_app_attr_response(&meta_msg, &avrc_response.list_app_attr);
+ break;
+
+ case AVRC_PDU_LIST_PLAYER_APP_VALUES:
+ avrc_response.list_app_values.status = BTIF_RC_STS_TIMEOUT;
+ handle_app_val_response(&meta_msg, &avrc_response.list_app_values);
+ break;
+
+ case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
+ avrc_response.get_cur_app_val.status = BTIF_RC_STS_TIMEOUT;
+ handle_app_cur_val_response(&meta_msg, &avrc_response.get_cur_app_val);
+ break;
+
+ case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
+ avrc_response.get_app_attr_txt.status = BTIF_RC_STS_TIMEOUT;
+ handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_attr_txt);
+ break;
+
+ case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
+ avrc_response.get_app_val_txt.status = BTIF_RC_STS_TIMEOUT;
+ handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_val_txt);
+ break;
+
+ case AVRC_PDU_GET_ELEMENT_ATTR:
+ avrc_response.get_elem_attrs.status = BTIF_RC_STS_TIMEOUT;
+ handle_get_elem_attr_response(&meta_msg, &avrc_response.get_elem_attrs);
+ break;
+
+ case AVRC_PDU_GET_PLAY_STATUS:
+ avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
+ handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
+ break;
+ }
+ release_transaction(p_context->rc_status_cmd.label);
+}
+
+/***************************************************************************
+**
+** Function btif_rc_status_cmd_timer_timeout
+**
+** Description RC status command timeout callback.
** This is called from BTU context and switches to BTIF
** context to handle the timeout events
** Returns None
**
***************************************************************************/
-static void rc_timeout_callback (timer_entry_t *tle)
+static void btif_rc_status_cmd_timer_timeout(void *data)
{
- char *p_data = (char*)tle->data;
+ btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
- tle->data = NULL;
- btif_transfer_context(rc_timeout_handler, 0,
- p_data, sizeof(btif_rc_timer_context_t), NULL);
- osi_freebuf (p_data);
+ btif_transfer_context(btif_rc_status_cmd_timeout_handler, 0,
+ (char *)p_data, sizeof(btif_rc_timer_context_t),
+ NULL);
+}
+
+/***************************************************************************
+**
+** Function btif_rc_control_cmd_timeout_handler
+**
+** Description RC control command timeout handler (Runs in BTIF context).
+** Returns None
+**
+***************************************************************************/
+static void btif_rc_control_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
+ char *data)
+{
+ btif_rc_timer_context_t *p_context = (btif_rc_timer_context_t *)data;
+ tAVRC_RESPONSE avrc_response = {0};
+ tBTA_AV_META_MSG meta_msg;
+
+ memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
+ meta_msg.rc_handle = btif_rc_cb.rc_handle;
+
+ switch (p_context->rc_control_cmd.pdu_id) {
+ case AVRC_PDU_SET_PLAYER_APP_VALUE:
+ avrc_response.set_app_val.status = BTIF_RC_STS_TIMEOUT;
+ handle_set_app_attr_val_response(&meta_msg,
+ &avrc_response.set_app_val);
+ break;
+ }
+ release_transaction(p_context->rc_control_cmd.label);
+}
+
+/***************************************************************************
+**
+** Function btif_rc_control_cmd_timer_timeout
+**
+** Description RC control command timeout callback.
+** This is called from BTU context and switches to BTIF
+** context to handle the timeout events
+** Returns None
+**
+***************************************************************************/
+static void btif_rc_control_cmd_timer_timeout(void *data)
+{
+ btif_rc_timer_context_t *p_data = (btif_rc_timer_context_t *)data;
+
+ btif_transfer_context(btif_rc_control_cmd_timeout_handler, 0,
+ (char *)p_data, sizeof(btif_rc_timer_context_t),
+ NULL);
+}
+
+/***************************************************************************
+**
+** Function btif_rc_play_status_timeout_handler
+**
+** Description RC play status timeout handler (Runs in BTIF context).
+** Returns None
+**
+***************************************************************************/
+static void btif_rc_play_status_timeout_handler(UNUSED_ATTR uint16_t event,
+ UNUSED_ATTR char *p_data)
+{
+ get_play_status_cmd();
+ rc_start_play_status_timer();
+}
+
+/***************************************************************************
+**
+** Function btif_rc_play_status_timer_timeout
+**
+** Description RC play status timeout callback.
+** This is called from BTU context and switches to BTIF
+** context to handle the timeout events
+** Returns None
+**
+***************************************************************************/
+static void btif_rc_play_status_timer_timeout(UNUSED_ATTR void *data)
+{
+ btif_transfer_context(btif_rc_play_status_timeout_handler, 0, 0, 0, NULL);
}
/***************************************************************************
@@ -2067,22 +2203,18 @@
** Returns None
**
***************************************************************************/
-void rc_start_play_status_timer ()
+static void rc_start_play_status_timer(void)
{
- btif_rc_timer_context_t *p_rc_timer_context;
/* Start the Play status timer only if it is not started */
- if (btif_rc_cb.tle_rc_play_status.data == NULL)
- {
- p_rc_timer_context = (btif_rc_timer_context_t*) osi_getbuf(sizeof(btif_rc_timer_context_t));
- if (p_rc_timer_context != NULL)
- {
- p_rc_timer_context->timer_id = RC_TIMER_PLAY_STATUS;
- memset(&btif_rc_cb.tle_rc_play_status, 0, sizeof(timer_entry_t));
- btif_rc_cb.tle_rc_play_status.param = rc_timeout_callback;
- btif_rc_cb.tle_rc_play_status.data = p_rc_timer_context;
- btu_start_timer(&btif_rc_cb.tle_rc_play_status, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_RC_INTERIM_RSP);
+ if (!alarm_is_scheduled(btif_rc_cb.rc_play_status_timer)) {
+ if (btif_rc_cb.rc_play_status_timer == NULL) {
+ btif_rc_cb.rc_play_status_timer =
+ alarm_new("btif_rc.rc_play_status_timer");
}
+ alarm_set_on_queue(btif_rc_cb.rc_play_status_timer,
+ BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
+ btif_rc_play_status_timer_timeout, NULL,
+ btu_general_alarm_queue);
}
}
@@ -2094,109 +2226,10 @@
** Returns None
**
***************************************************************************/
-void rc_stop_play_status_timer ()
+void rc_stop_play_status_timer()
{
- if (btif_rc_cb.tle_rc_play_status.data != NULL)
- {
- btu_stop_timer (&btif_rc_cb.tle_rc_play_status);
- osi_freebuf(btif_rc_cb.tle_rc_play_status.data);
- btif_rc_cb.tle_rc_play_status.data = NULL;
- }
-}
-
-/***************************************************************************
-**
-** Function rc_timeout_handler
-**
-** Description RC timeout handler (Runs in BTIF context).
-** main handler for all the timers created from RC module
-** Returns None
-**
-***************************************************************************/
-static void rc_timeout_handler (UINT16 event, char* p_data)
-{
- btif_rc_timer_context_t *p_rc_timer_context;
- tAVRC_RESPONSE avrc_response = {0};
- tBTA_AV_META_MSG meta_msg;
-
- p_rc_timer_context = (btif_rc_timer_context_t *)p_data;
- memset(&meta_msg, 0, sizeof(tBTA_AV_META_MSG));
- meta_msg.rc_handle = btif_rc_cb.rc_handle;
-
- switch (p_rc_timer_context->timer_id)
- {
- case RC_TIMER_STATUS_CMD:
- switch (p_rc_timer_context->rc_status_cmd.pdu_id)
- {
- case AVRC_PDU_REGISTER_NOTIFICATION:
- rc_notification_interim_timout(
- p_rc_timer_context->rc_status_cmd.label);
- break;
-
- case AVRC_PDU_GET_CAPABILITIES:
- avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
- handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
- break;
-
- case AVRC_PDU_LIST_PLAYER_APP_ATTR:
- avrc_response.list_app_attr.status = BTIF_RC_STS_TIMEOUT;
- handle_app_attr_response(&meta_msg, &avrc_response.list_app_attr);
- break;
-
- case AVRC_PDU_LIST_PLAYER_APP_VALUES:
- avrc_response.list_app_values.status = BTIF_RC_STS_TIMEOUT;
- handle_app_val_response(&meta_msg, &avrc_response.list_app_values);
- break;
-
- case AVRC_PDU_GET_CUR_PLAYER_APP_VALUE:
- avrc_response.get_cur_app_val.status = BTIF_RC_STS_TIMEOUT;
- handle_app_cur_val_response(&meta_msg, &avrc_response.get_cur_app_val);
- break;
-
- case AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT:
- avrc_response.get_app_attr_txt.status = BTIF_RC_STS_TIMEOUT;
- handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_attr_txt);
- break;
-
- case AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT:
- avrc_response.get_app_val_txt.status = BTIF_RC_STS_TIMEOUT;
- handle_app_attr_txt_response(&meta_msg, &avrc_response.get_app_val_txt);
- break;
-
- case AVRC_PDU_GET_ELEMENT_ATTR:
- avrc_response.get_elem_attrs.status = BTIF_RC_STS_TIMEOUT;
- handle_get_elem_attr_response(&meta_msg, &avrc_response.get_elem_attrs);
- break;
-
- case AVRC_PDU_GET_PLAY_STATUS:
- avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
- handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
- break;
- }
- release_transaction (p_rc_timer_context->rc_status_cmd.label);
- break;
-
- case RC_TIMER_CONTROL_CMD:
- switch (p_rc_timer_context->rc_control_cmd.pdu_id)
- {
- case AVRC_PDU_SET_PLAYER_APP_VALUE:
- avrc_response.set_app_val.status = BTIF_RC_STS_TIMEOUT;
- handle_set_app_attr_val_response(&meta_msg, &avrc_response.set_app_val);
- break;
- }
- release_transaction (p_rc_timer_context->rc_control_cmd.label);
- break;
-
- case RC_TIMER_PLAY_STATUS:
- get_play_status_cmd();
- rc_start_play_status_timer();
- break;
-
- default:
- BTIF_TRACE_ERROR("%s Error unknown timer id %d",
- __FUNCTION__, p_rc_timer_context->timer_id);
- break;
- }
+ if (btif_rc_cb.rc_play_status_timer != NULL)
+ alarm_cancel(btif_rc_cb.rc_play_status_timer);
}
/***************************************************************************
@@ -2209,7 +2242,7 @@
** Returns None
**
***************************************************************************/
-static void register_for_event_notification (btif_rc_supported_event_t *p_event)
+static void register_for_event_notification(btif_rc_supported_event_t *p_event)
{
bt_status_t status;
rc_transaction_t *p_transaction;
@@ -2217,7 +2250,7 @@
status = get_transaction(&p_transaction);
if (status == BT_STATUS_SUCCESS)
{
- btif_rc_timer_context_t *p_rc_timer_context;
+ btif_rc_timer_context_t *p_context = &p_transaction->txn_timer_context;
status = register_notification_cmd (p_transaction->lbl, p_event->event_id, 0);
if (status != BT_STATUS_SUCCESS)
@@ -2229,18 +2262,16 @@
}
p_event->label = p_transaction->lbl;
p_event->status = eREGISTERED;
- p_rc_timer_context = (btif_rc_timer_context_t*) osi_getbuf(sizeof(btif_rc_timer_context_t));
- if (p_rc_timer_context != NULL)
- {
- p_rc_timer_context->timer_id = RC_TIMER_STATUS_CMD;
- p_rc_timer_context->rc_status_cmd.label = p_transaction->lbl;
- p_rc_timer_context->rc_status_cmd.pdu_id = AVRC_PDU_REGISTER_NOTIFICATION;
- memset(&p_transaction->tle_txn, 0, sizeof(timer_entry_t));
- p_transaction->tle_txn.param = rc_timeout_callback;
- p_transaction->tle_txn.data = p_rc_timer_context;
- btu_start_timer(&p_transaction->tle_txn, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_RC_INTERIM_RSP);
- }
+ p_context->rc_status_cmd.label = p_transaction->lbl;
+ p_context->rc_status_cmd.pdu_id = AVRC_PDU_REGISTER_NOTIFICATION;
+
+ alarm_free(p_transaction->txn_timer);
+ p_transaction->txn_timer =
+ alarm_new("btif_rc.status_command_txn_timer");
+ alarm_set_on_queue(p_transaction->txn_timer,
+ BTIF_TIMEOUT_RC_INTERIM_RSP_MS,
+ btif_rc_status_cmd_timer_timeout, p_context,
+ btu_general_alarm_queue);
}
else
{
@@ -2249,54 +2280,31 @@
}
}
-static void start_status_command_timer (UINT8 pdu_id, rc_transaction_t *p_txn)
+static void start_status_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
{
- bt_status_t status;
- btif_rc_timer_context_t *p_rc_timer_context;
+ btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
+ p_context->rc_status_cmd.label = p_txn->lbl;
+ p_context->rc_status_cmd.pdu_id = pdu_id;
- p_rc_timer_context = (btif_rc_timer_context_t*) osi_getbuf(sizeof(btif_rc_timer_context_t));
- if (p_rc_timer_context != NULL)
- {
- p_rc_timer_context->timer_id = RC_TIMER_STATUS_CMD;
- p_rc_timer_context->rc_status_cmd.label = p_txn->lbl;
- p_rc_timer_context->rc_status_cmd.pdu_id = pdu_id;
-
- memset(&p_txn->tle_txn, 0, sizeof(timer_entry_t));
- p_txn->tle_txn.param = rc_timeout_callback;
- p_txn->tle_txn.data = p_rc_timer_context;
- btu_start_timer(&p_txn->tle_txn, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_RC_STATUS_CMD);
- }
- else
- {
- BTIF_TRACE_ERROR("%s Getbuf failed while starting command timer",
- __FUNCTION__);
- }
+ alarm_free(p_txn->txn_timer);
+ p_txn->txn_timer = alarm_new("btif_rc.status_command_txn_timer");
+ alarm_set_on_queue(p_txn->txn_timer, BTIF_TIMEOUT_RC_STATUS_CMD_MS,
+ btif_rc_status_cmd_timer_timeout, p_context,
+ btu_general_alarm_queue);
}
-static void start_control_command_timer (UINT8 pdu_id, rc_transaction_t *p_txn)
+static void start_control_command_timer(UINT8 pdu_id, rc_transaction_t *p_txn)
{
- bt_status_t status;
- btif_rc_timer_context_t *p_rc_timer_context;
+ btif_rc_timer_context_t *p_context = &p_txn->txn_timer_context;
+ p_context->rc_control_cmd.label = p_txn->lbl;
+ p_context->rc_control_cmd.pdu_id = pdu_id;
- p_rc_timer_context = (btif_rc_timer_context_t*) osi_getbuf(sizeof(btif_rc_timer_context_t));
- if (p_rc_timer_context != NULL)
- {
- p_rc_timer_context->timer_id = RC_TIMER_CONTROL_CMD;
- p_rc_timer_context->rc_control_cmd.label = p_txn->lbl;
- p_rc_timer_context->rc_control_cmd.pdu_id = pdu_id;
-
- memset(&p_txn->tle_txn, 0, sizeof(timer_entry_t));
- p_txn->tle_txn.param = rc_timeout_callback;
- p_txn->tle_txn.data = p_rc_timer_context;
- btu_start_timer(&p_txn->tle_txn, BTU_TTYPE_USER_FUNC,
- BTIF_TIMEOUT_RC_CONTROL_CMD);
- }
- else
- {
- BTIF_TRACE_ERROR("%s Getbuf failed while starting command timer",
- __FUNCTION__);
- }
+ alarm_free(p_txn->txn_timer);
+ p_txn->txn_timer = alarm_new("btif_rc.control_command_txn_timer");
+ alarm_set_on_queue(p_txn->txn_timer,
+ BTIF_TIMEOUT_RC_CONTROL_CMD_MS,
+ btif_rc_control_cmd_timer_timeout, p_context,
+ btu_general_alarm_queue);
}
/***************************************************************************
@@ -2334,7 +2342,7 @@
(p_rsp->param.event_id[xx] == AVRC_EVT_TRACK_CHANGE)||
(p_rsp->param.event_id[xx] == AVRC_EVT_APP_SETTING_CHANGE))
{
- p_event = (btif_rc_supported_event_t*) osi_getbuf(sizeof(btif_rc_supported_event_t));
+ p_event = (btif_rc_supported_event_t *)osi_getbuf(sizeof(btif_rc_supported_event_t));
p_event->event_id = p_rsp->param.event_id[xx];
p_event->status = eNOT_REGISTERED;
list_append(btif_rc_cb.rc_supported_event_list, p_event);
@@ -2655,7 +2663,6 @@
static void handle_app_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_LIST_APP_VALUES_RSP *p_rsp)
{
UINT8 xx, attr_index;
- int i,j;
UINT8 attrs[AVRC_MAX_APP_ATTR_SIZE];
btif_rc_player_app_settings_t *p_app_settings;
bt_bdaddr_t rc_addr;
@@ -2783,7 +2790,7 @@
***************************************************************************/
static void handle_app_attr_txt_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_APP_ATTR_TXT_RSP *p_rsp)
{
- UINT8 xx, attr_index;
+ UINT8 xx;
UINT8 vals[AVRC_MAX_APP_ATTR_SIZE];
btif_rc_player_app_settings_t *p_app_settings;
bt_bdaddr_t rc_addr;
@@ -2805,7 +2812,7 @@
p_app_settings->num_ext_attrs = 0;
for (xx = 0; xx < p_app_settings->ext_attr_index; xx++)
{
- osi_freebuf (p_app_settings->ext_attrs[xx].p_str);
+ osi_freebuf(p_app_settings->ext_attrs[xx].p_str);
}
p_app_settings->ext_attr_index = 0;
@@ -2884,10 +2891,10 @@
for (x = 0; x < p_ext_attr->num_val; x++)
{
- osi_freebuf (p_ext_attr->ext_attr_val[x].p_str);
+ osi_freebuf(p_ext_attr->ext_attr_val[x].p_str);
}
p_ext_attr->num_val = 0;
- osi_freebuf (p_app_settings->ext_attrs[xx].p_str);
+ osi_freebuf(p_app_settings->ext_attrs[xx].p_str);
}
p_app_settings->ext_attr_index = 0;
@@ -2956,10 +2963,10 @@
for (x = 0; x < p_ext_attr->num_val; x++)
{
- osi_freebuf (p_ext_attr->ext_attr_val[x].p_str);
+ osi_freebuf(p_ext_attr->ext_attr_val[x].p_str);
}
p_ext_attr->num_val = 0;
- osi_freebuf (p_app_settings->ext_attrs[xx].p_str);
+ osi_freebuf(p_app_settings->ext_attrs[xx].p_str);
}
p_app_settings->num_attrs = 0;
}
@@ -3010,25 +3017,22 @@
if (p_rsp->status == AVRC_STS_NO_ERROR)
{
- p_attr = (btrc_element_attr_val_t*)osi_getbuf (p_rsp->num_attr * sizeof(btrc_element_attr_val_t));
- if (p_attr != NULL)
+ p_attr = (btrc_element_attr_val_t *)osi_getbuf(p_rsp->num_attr * sizeof(btrc_element_attr_val_t));
+ memset(p_attr, 0, osi_get_buf_size(p_attr));
+ for (xx = 0; xx < p_rsp->num_attr; xx++)
{
- memset(p_attr, 0, osi_get_buf_size (p_attr));
- for (xx = 0; xx < p_rsp->num_attr; xx++)
+ p_attr[xx].attr_id = p_rsp->p_attrs[xx].attr_id;
+ /* Todo. Legth limit check to include null */
+ if (p_rsp->p_attrs[xx].name.str_len && p_rsp->p_attrs[xx].name.p_str)
{
- p_attr[xx].attr_id = p_rsp->p_attrs[xx].attr_id;
- /* Todo. Legth limit check to include null */
- if (p_rsp->p_attrs[xx].name.str_len && p_rsp->p_attrs[xx].name.p_str)
- {
- memcpy(p_attr[xx].text, p_rsp->p_attrs[xx].name.p_str,
- p_rsp->p_attrs[xx].name.str_len);
- osi_freebuf (p_rsp->p_attrs[xx].name.p_str);
- }
+ memcpy(p_attr[xx].text, p_rsp->p_attrs[xx].name.p_str,
+ p_rsp->p_attrs[xx].name.str_len);
+ osi_freebuf(p_rsp->p_attrs[xx].name.p_str);
}
- HAL_CBACK(bt_rc_ctrl_callbacks, track_changed_cb,
- &rc_addr, p_rsp->num_attr, p_attr);
- osi_freebuf (p_attr);
}
+ HAL_CBACK(bt_rc_ctrl_callbacks, track_changed_cb,
+ &rc_addr, p_rsp->num_attr, p_attr);
+ osi_freebuf(p_attr);
}
else if (p_rsp->status == BTIF_RC_STS_TIMEOUT)
{
@@ -3099,12 +3103,8 @@
return;
}
- btu_stop_timer (&p_txn->tle_txn);
- if (p_txn->tle_txn.data != NULL)
- {
- osi_freebuf (p_txn->tle_txn.data);
- p_txn->tle_txn.data = NULL;
- }
+ if (p_txn->txn_timer != NULL)
+ alarm_cancel(p_txn->txn_timer);
}
/***************************************************************************
@@ -3263,6 +3263,7 @@
{
bt_rc_callbacks = NULL;
}
+ alarm_free(btif_rc_cb.rc_play_status_timer);
memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
lbl_destroy();
BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
@@ -3285,6 +3286,7 @@
{
bt_rc_ctrl_callbacks = NULL;
}
+ alarm_free(btif_rc_cb.rc_play_status_timer);
memset(&btif_rc_cb, 0, sizeof(btif_rc_cb_t));
lbl_destroy();
BTIF_TRACE_EVENT("## %s ## completed", __FUNCTION__);
@@ -3523,12 +3525,7 @@
avrc_cmd.set_app_val.num_val = num_attrib;
avrc_cmd.set_app_val.pdu = AVRC_PDU_SET_PLAYER_APP_VALUE;
avrc_cmd.set_app_val.p_vals =
- (tAVRC_APP_SETTING*)osi_getbuf(sizeof(tAVRC_APP_SETTING)*num_attrib);
- if (avrc_cmd.set_app_val.p_vals == NULL)
- {
- BTIF_TRACE_ERROR("%s: alloc failed", __FUNCTION__);
- return BT_STATUS_FAIL;
- }
+ (tAVRC_APP_SETTING *)osi_getbuf(sizeof(tAVRC_APP_SETTING) * num_attrib);
for (count = 0; count < num_attrib; count++)
{
avrc_cmd.set_app_val.p_vals[count].attr_id = attrib_ids[count];
@@ -3610,7 +3607,7 @@
{
BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x", __FUNCTION__, status);
}
- if (NULL != p_msg)
+ if (p_msg != NULL)
osi_freebuf(p_msg);
#else
BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
@@ -3671,7 +3668,7 @@
BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
__FUNCTION__, status);
}
- if (NULL != p_msg)
+ if (p_msg != NULL)
osi_freebuf(p_msg);
#else
BTIF_TRACE_DEBUG("%s: feature not enabled", __FUNCTION__);
@@ -3939,7 +3936,7 @@
}
else
{
- if (NULL!=p_msg)
+ if (p_msg != NULL)
osi_freebuf(p_msg);
BTIF_TRACE_ERROR("%s: failed to build command. status: 0x%02x",
__FUNCTION__, status);
@@ -3971,21 +3968,19 @@
if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
{
bt_status_t tran_status = get_transaction(&p_transaction);
- if ((BT_STATUS_SUCCESS == tran_status) && (NULL != p_transaction))
- {
- UINT8* p_buf = (UINT8*)osi_getbuf(AVRC_PASS_THRU_GROUP_LEN);
- if (p_buf != NULL)
- {
- UINT8* start = p_buf;
- UINT24_TO_BE_STREAM(start, AVRC_CO_METADATA);
- *(start)++ = 0;
- UINT8_TO_BE_STREAM(start, key_code);
- BTA_AvRemoteVendorUniqueCmd(btif_rc_cb.rc_handle, p_transaction->lbl,
- (tBTA_AV_STATE)key_state, p_buf, AVRC_PASS_THRU_GROUP_LEN);
- status = BT_STATUS_SUCCESS;
- BTIF_TRACE_DEBUG("%s: succesfully sent group_navigation command to BTA",
- __FUNCTION__);
- }
+ if ((BT_STATUS_SUCCESS == tran_status) && (NULL != p_transaction)) {
+ UINT8* p_buf = (UINT8 *)osi_getbuf(AVRC_PASS_THRU_GROUP_LEN);
+ UINT8* start = p_buf;
+ UINT24_TO_BE_STREAM(start, AVRC_CO_METADATA);
+ *(start)++ = 0;
+ UINT8_TO_BE_STREAM(start, key_code);
+ BTA_AvRemoteVendorUniqueCmd(btif_rc_cb.rc_handle,
+ p_transaction->lbl,
+ (tBTA_AV_STATE)key_state, p_buf,
+ AVRC_PASS_THRU_GROUP_LEN);
+ status = BT_STATUS_SUCCESS;
+ BTIF_TRACE_DEBUG("%s: succesfully sent group_navigation command to BTA",
+ __FUNCTION__);
}
else
{
@@ -4115,15 +4110,13 @@
static void initialize_transaction(int lbl)
{
pthread_mutex_lock(&device.lbllock);
- if (lbl < MAX_TRANSACTIONS_PER_SESSION)
- {
- if (device.transaction[lbl].tle_txn.in_use == TRUE)
- {
- clear_cmd_timeout (lbl);
+ if (lbl < MAX_TRANSACTIONS_PER_SESSION) {
+ if (alarm_is_scheduled(device.transaction[lbl].txn_timer)) {
+ clear_cmd_timeout(lbl);
}
- device.transaction[lbl].lbl = lbl;
- device.transaction[lbl].in_use=FALSE;
- device.transaction[lbl].handle=0;
+ device.transaction[lbl].lbl = lbl;
+ device.transaction[lbl].in_use=FALSE;
+ device.transaction[lbl].handle=0;
}
pthread_mutex_unlock(&device.lbllock);
}
@@ -4268,7 +4261,7 @@
**
** Returns void
*******************************************************************************/
-static void sleep_ms(uint32_t timeout_ms) {
+static void sleep_ms(period_ms_t timeout_ms) {
struct timespec delay;
delay.tv_sec = timeout_ms / 1000;
delay.tv_nsec = 1000 * 1000 * (timeout_ms % 1000);
diff --git a/hci/src/hci_layer.c b/hci/src/hci_layer.c
index 14289de..a962bb2 100644
--- a/hci/src/hci_layer.c
+++ b/hci/src/hci_layer.c
@@ -43,9 +43,9 @@
#include "hcidefs.h"
#include "hcimsgs.h"
#include "low_power_manager.h"
+#include "osi/include/alarm.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
-#include "osi/include/non_repeating_timer.h"
#include "osi/include/reactor.h"
#include "packet_fragmenter.h"
#include "vendor.h"
@@ -106,7 +106,7 @@
#define STRING_VALUE_OF(x) #x
static const uint32_t EPILOG_TIMEOUT_MS = 3000;
-static const uint32_t COMMAND_PENDING_TIMEOUT = 8000;
+static const uint32_t COMMAND_PENDING_TIMEOUT_MS = 8000;
// Our interface
static bool interface_created;
@@ -127,8 +127,8 @@
static thread_t *thread; // We own this
static volatile bool firmware_is_configured = false;
-static non_repeating_timer_t *epilog_timer;
-static non_repeating_timer_t *startup_timer;
+static alarm_t *epilog_timer;
+static alarm_t *startup_timer;
// Outbound-related
static int command_credits = 1;
@@ -136,7 +136,7 @@
static fixed_queue_t *packet_queue;
// Inbound-related
-static non_repeating_timer_t *command_response_timer;
+static alarm_t *command_response_timer;
static list_t *commands_pending_response;
static pthread_mutex_t commands_pending_response_lock;
static packet_receive_data_t incoming_packets[INBOUND_PACKET_TYPE_COUNT];
@@ -166,6 +166,7 @@
static serial_data_type_t event_to_data_type(uint16_t event);
static waiting_command_t *get_waiting_command(command_opcode_t opcode);
+static void update_command_response_timer(void);
// Module lifecycle functions
@@ -194,22 +195,22 @@
startup_timeout_ms = DEFAULT_STARTUP_TIMEOUT_MS;
#endif // !defined(OS_GENERIC)
- startup_timer = non_repeating_timer_new(startup_timeout_ms, startup_timer_expired, NULL);
+ startup_timer = alarm_new("hci.startup_timer");
if (!startup_timer) {
LOG_ERROR(LOG_TAG, "%s unable to create startup timer.", __func__);
goto error;
}
// Make sure we run in a bounded amount of time
- non_repeating_timer_restart(startup_timer);
+ alarm_set(startup_timer, startup_timeout_ms, startup_timer_expired, NULL);
- epilog_timer = non_repeating_timer_new(EPILOG_TIMEOUT_MS, epilog_timer_expired, NULL);
+ epilog_timer = alarm_new("hci.epilog_timer");
if (!epilog_timer) {
LOG_ERROR(LOG_TAG, "%s unable to create epilog timer.", __func__);
goto error;
}
- command_response_timer = non_repeating_timer_new(COMMAND_PENDING_TIMEOUT, command_timed_out, NULL);
+ command_response_timer = alarm_new("hci.command_response_timer");
if (!command_response_timer) {
LOG_ERROR(LOG_TAG, "%s unable to create command response timer.", __func__);
goto error;
@@ -279,7 +280,8 @@
LOG_DEBUG(LOG_TAG, "%s starting async portion", __func__);
thread_post(thread, event_finish_startup, NULL);
return local_startup_future;
-error:;
+
+error:
shut_down(); // returns NULL so no need to wait for it
return future_new_immediate(FUTURE_FAIL);
}
@@ -291,7 +293,7 @@
if (thread) {
if (firmware_is_configured) {
- non_repeating_timer_restart(epilog_timer);
+ alarm_set(epilog_timer, EPILOG_TIMEOUT_MS, epilog_timer_expired, NULL);
thread_post(thread, event_epilog, NULL);
} else {
thread_stop(thread);
@@ -310,12 +312,13 @@
packet_fragmenter->cleanup();
- non_repeating_timer_free(epilog_timer);
- non_repeating_timer_free(command_response_timer);
- non_repeating_timer_free(startup_timer);
-
+ // Free the timers
+ alarm_free(epilog_timer);
epilog_timer = NULL;
+ alarm_free(command_response_timer);
command_response_timer = NULL;
+ alarm_free(startup_timer);
+ startup_timer = NULL;
low_power_manager->cleanup();
hal->close();
@@ -420,7 +423,7 @@
static void firmware_config_callback(UNUSED_ATTR bool success) {
LOG_INFO(LOG_TAG, "%s", __func__);
firmware_is_configured = true;
- non_repeating_timer_cancel(startup_timer);
+ alarm_cancel(startup_timer);
future_ready(startup_future, FUTURE_SUCCESS);
startup_future = NULL;
@@ -456,6 +459,7 @@
static void epilog_finished_callback(UNUSED_ATTR bool success) {
LOG_INFO(LOG_TAG, "%s", __func__);
+ alarm_cancel(epilog_timer);
thread_stop(thread);
}
@@ -481,7 +485,7 @@
packet_fragmenter->fragment_and_dispatch(wait_entry->command);
low_power_manager->transmit_done();
- non_repeating_timer_restart_if(command_response_timer, !list_is_empty(commands_pending_response));
+ update_command_response_timer();
}
}
@@ -685,8 +689,9 @@
}
return false;
-intercepted:;
- non_repeating_timer_restart_if(command_response_timer, !list_is_empty(commands_pending_response));
+
+intercepted:
+ update_command_response_timer();
if (wait_entry) {
// If it has a callback, it's responsible for freeing the packet
@@ -756,6 +761,15 @@
return NULL;
}
+static void update_command_response_timer(void) {
+ if (list_is_empty(commands_pending_response)) {
+ alarm_cancel(command_response_timer);
+ } else {
+ alarm_set(command_response_timer, COMMAND_PENDING_TIMEOUT_MS,
+ command_timed_out, NULL);
+ }
+}
+
static void init_layer_interface() {
if (!interface_created) {
interface.send_low_power_command = low_power_manager->post_command;
diff --git a/hci/src/low_power_manager.c b/hci/src/low_power_manager.c
index d28e0d9..f231502 100644
--- a/hci/src/low_power_manager.c
+++ b/hci/src/low_power_manager.c
@@ -81,7 +81,7 @@
vendor->set_callback(VENDOR_SET_LPM_MODE, vendor_enable_disable_callback);
- idle_alarm = alarm_new();
+ idle_alarm = alarm_new("hci.idle");
if (!idle_alarm) {
LOG_ERROR(LOG_TAG, "%s could not create idle alarm.", __func__);
}
diff --git a/include/bt_target.h b/include/bt_target.h
index e41f036..fae7d47 100644
--- a/include/bt_target.h
+++ b/include/bt_target.h
@@ -345,24 +345,6 @@
/******************************************************************************
**
-** HCI Services (H4)
-**
-******************************************************************************/
-
-/* Use 2 second for low-resolution systems, override to 1 for high-resolution systems */
-#ifndef BT_1SEC_TIMEOUT
-#define BT_1SEC_TIMEOUT (2)
-#endif
-
-/* Quick Timer */
-/* if L2CAP_FCR_INCLUDED is TRUE then it should have 100 millisecond resolution */
-/* if none of them is included then QUICK_TIMER_TICKS_PER_SEC is set to 0 to exclude quick timer */
-#ifndef QUICK_TIMER_TICKS_PER_SEC
-#define QUICK_TIMER_TICKS_PER_SEC 10 /* 100ms timer */
-#endif
-
-/******************************************************************************
-**
** BTM
**
******************************************************************************/
diff --git a/include/bt_trace.h b/include/bt_trace.h
index 8947b11..cfb7b5a 100644
--- a/include/bt_trace.h
+++ b/include/bt_trace.h
@@ -227,10 +227,10 @@
/* Define tracing for the HCI unit
*/
-#define HCI_TRACE_ERROR(...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__);}
-#define HCI_TRACE_WARNING(...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__);}
-#define HCI_TRACE_EVENT(...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__);}
-#define HCI_TRACE_DEBUG(...) {if (btu_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__);}
+#define HCI_TRACE_ERROR(...) {if (btu_trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_ERROR, ##__VA_ARGS__);}
+#define HCI_TRACE_WARNING(...) {if (btu_trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_WARNING, ##__VA_ARGS__);}
+#define HCI_TRACE_EVENT(...) {if (btu_trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, ##__VA_ARGS__);}
+#define HCI_TRACE_DEBUG(...) {if (btu_trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE(TRACE_LAYER_HCI, TRACE_TYPE_DEBUG, ##__VA_ARGS__);}
/* Define tracing for BTM
diff --git a/main/bte_logmsg.c b/main/bte_logmsg.c
index b514a3f..efeed4a 100644
--- a/main/bte_logmsg.c
+++ b/main/bte_logmsg.c
@@ -213,9 +213,9 @@
static uint8_t BTU_SetTraceLevel(uint8_t new_level) {
if (new_level != 0xFF)
- btu_cb.trace_level = new_level;
+ btu_trace_level = new_level;
- return btu_cb.trace_level;
+ return btu_trace_level;
}
static void load_levels_from_config(const config_t *config) {
diff --git a/osi/Android.mk b/osi/Android.mk
index a332980..789a17f 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -40,7 +40,6 @@
./src/hash_map_utils.c \
./src/list.c \
./src/mutex.c \
- ./src/non_repeating_timer.c \
./src/reactor.c \
./src/ringbuffer.c \
./src/semaphore.c \
diff --git a/osi/BUILD.gn b/osi/BUILD.gn
index 05d386a..28307f3 100644
--- a/osi/BUILD.gn
+++ b/osi/BUILD.gn
@@ -32,7 +32,6 @@
"src/hash_map_utils.c",
"src/list.c",
"src/mutex.c",
- "src/non_repeating_timer.c",
"src/reactor.c",
"src/ringbuffer.c",
"src/semaphore.c",
diff --git a/osi/include/alarm.h b/osi/include/alarm.h
index 13c7d87..9a4210c 100644
--- a/osi/include/alarm.h
+++ b/osi/include/alarm.h
@@ -18,40 +18,93 @@
#pragma once
+#include <stdbool.h>
#include <stdint.h>
typedef struct alarm_t alarm_t;
+typedef struct fixed_queue_t fixed_queue_t;
+typedef struct thread_t thread_t;
typedef uint64_t period_ms_t;
-// Prototype for the callback function.
+// Prototype for the alarm callback function.
typedef void (*alarm_callback_t)(void *data);
-// Creates a new alarm object. The returned object must be freed by calling
-// |alarm_free|. Returns NULL on failure.
-alarm_t *alarm_new(void);
+// Creates a new one-time off alarm object with user-assigned
+// |name|. |name| may not be NULL, and a copy of the string will
+// be stored internally. The value of |name| has no semantic
+// meaning. It is recommended that the name is unique (for
+// better debuggability), but that is not enforced. The returned
+// object must be freed by calling |alarm_free|. Returns NULL on
+// failure.
+alarm_t *alarm_new(const char *name);
-// Frees an alarm object created by |alarm_new|. |alarm| may be NULL. If the
-// alarm is pending, it will be cancelled. It is not safe to call |alarm_free|
-// from inside the callback of |alarm|.
+// Creates a new periodic alarm object with user-assigned |name|.
+// |name| may not be NULL, and a copy of the string will be
+// stored internally. The value of |name| has no semantic
+// meaning. It is recommended that the name is unique (for better
+// debuggability), but that is not enforced. The returned object
+// must be freed by calling |alarm_free|. Returns NULL on
+// failure.
+alarm_t *alarm_new_periodic(const char *name);
+
+// Frees an |alarm| object created by |alarm_new| or
+// |alarm_new_periodic|. |alarm| may be NULL. If the alarm is
+// pending, it will be cancelled first. It is not safe to call
+// |alarm_free| from inside the callback of |alarm|.
void alarm_free(alarm_t *alarm);
-// Sets an alarm to fire |cb| after the given |deadline|. Note that |deadline| is the
-// number of milliseconds relative to the current time. |data| is a context variable
-// for the callback and may be NULL. |cb| will be called back in the context of an
-// unspecified thread (i.e. it will not be called back in the same thread as the caller).
-// |alarm| and |cb| may not be NULL.
-void alarm_set(alarm_t *alarm, period_ms_t deadline, alarm_callback_t cb, void *data);
+// Sets an |alarm| to execute a callback in the future. The |cb|
+// callback is called after the given |interval_ms|, where
+// |interval_ms| is the number of milliseconds relative to the
+// current time. If |alarm| was created with
+// |alarm_new_periodic|, the alarm is scheduled to fire
+// periodically every |interval_ms|, otherwise it is a one time
+// only alarm. A periodic alarm repeats every |interval_ms| until
+// it is cancelled or freed. When the alarm fires, the |cb|
+// callback is called with the context argument |data|:
+//
+// void cb(void *data) {...}
+//
+// The |data| argument may be NULL, but the |cb| callback may not
+// be NULL. All |cb| callbacks scheduled through this call are
+// called within a single (internally created) thread. That
+// thread is not same as the caller’s thread. If two (or more)
+// alarms are set back-to-back with the same |interval_ms|, the
+// callbacks will be called in the order the alarms are set.
+void alarm_set(alarm_t *alarm, period_ms_t interval_ms,
+ alarm_callback_t cb, void *data);
-// Like alarm_set, except the alarm repeats every |period| ms until it is cancelled or
-// freed or |alarm_set| is called to set it non-periodically.
-void alarm_set_periodic(alarm_t *alarm, period_ms_t period, alarm_callback_t cb, void *data);
+// Sets an |alarm| to execute a callback in the future on a
+// specific |queue|. This function is same as |alarm_set| except
+// that the |cb| callback is scheduled for execution in the
+// context of the thread responsible for processing |queue|.
+// Also, the callback execution ordering guarantee exists only
+// among alarms that are scheduled on the same queue. |queue|
+// may not be NULL.
+void alarm_set_on_queue(alarm_t *alarm, period_ms_t interval_ms,
+ alarm_callback_t cb, void *data,
+ fixed_queue_t *queue);
-// This function cancels the |alarm| if it was previously set. When this call
-// returns, the caller has a guarantee that the callback is not in progress and
-// will not be called if it hasn't already been called. This function is idempotent.
+// This function cancels the |alarm| if it was previously set.
+// When this call returns, the caller has a guarantee that the
+// callback is not in progress and will not be called if it
+// hasn't already been called. This function is idempotent.
// |alarm| may not be NULL.
void alarm_cancel(alarm_t *alarm);
+// Tests whether the |alarm| is scheduled.
+// Return true if the |alarm| is scheduled or NULL, otherwise false.
+bool alarm_is_scheduled(const alarm_t *alarm);
+
+// Registers |queue| for processing alarm callbacks on |thread|.
+// |queue| may not be NULL. |thread| may not be NULL.
+void alarm_register_processing_queue(fixed_queue_t *queue, thread_t *thread);
+
+// Unregisters |queue| for processing alarm callbacks on whichever thread
+// it is registered with. |queue| may not be NULL.
+// This function is idempotent.
+void alarm_unregister_processing_queue(fixed_queue_t *queue);
+
// Figure out how much time until next expiration.
// Returns 0 if not armed. |alarm| may not be NULL.
// TODO: Remove this function once PM timers can be re-factored
@@ -61,3 +114,7 @@
// This function should be called by the OSI module cleanup during
// graceful shutdown.
void alarm_cleanup(void);
+
+// Dump alarm-related statistics and debug info to the |fd| file descriptor.
+// The information is in user-readable text format. The |fd| must be valid.
+void alarm_debug_dump(int fd);
diff --git a/osi/include/non_repeating_timer.h b/osi/include/non_repeating_timer.h
deleted file mode 100644
index 542683c..0000000
--- a/osi/include/non_repeating_timer.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2014 Google, Inc.
- *
- * 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.
- *
- ******************************************************************************/
-
-#pragma once
-
-#include <stdbool.h>
-
-#include "osi/include/alarm.h"
-
-typedef struct non_repeating_timer_t non_repeating_timer_t;
-
-// Creates a new non repeating timer of |duration| with callback |cb|. |cb| will be
-// called back in the context of an upspecified thread, and may not be NULL. |data|
-// is a context variable for the callback and may be NULL. The returned object must
-// be freed by calling |non_repeating_timer_free|. Returns NULL on failure.
-non_repeating_timer_t *non_repeating_timer_new(period_ms_t duration, alarm_callback_t cb, void *data);
-
-// Frees a non repeating timer created by |non_repeating_timer_new|. |timer| may be
-// NULL. If the timer is currently running, it will be cancelled. It is not safe to
-// call |non_repeating_timer_free| from inside the callback of a non repeating timer.
-void non_repeating_timer_free(non_repeating_timer_t *timer);
-
-// Restarts the non repeating timer. If it is currently running, the timer is reset.
-// |timer| may not be NULL.
-void non_repeating_timer_restart(non_repeating_timer_t *timer);
-
-// Restarts the non repeating timer if |condition| is true, otherwise ensures it is
-// not running. |timer| may not be NULL.
-void non_repeating_timer_restart_if(non_repeating_timer_t *timer, bool condition);
-
-// Cancels the non repeating timer if it is currently running. All the semantics of
-// |alarm_cancel| apply here. |timer| may not be NULL.
-void non_repeating_timer_cancel(non_repeating_timer_t *timer);
-
-//
-// TODO: timer_entry_t below should be removed, and its usage everywhere
-// should be replaced by |non_repeating_timer_t| .
-//
-
-// Timer entry callback type
-typedef void (timer_callback_t)(void *p_te);
-typedef void* timer_param_t;
-
-//
-// Define a timer entry
-//
-typedef struct _timer_entry
-{
- timer_callback_t *p_cback;
- int32_t ticks;
- int32_t ticks_initial;
- timer_param_t param;
- timer_param_t data;
- uint16_t event;
- uint8_t in_use;
-} timer_entry_t;
diff --git a/osi/include/osi.h b/osi/include/osi.h
index 73a8db1..78aa68c 100644
--- a/osi/include/osi.h
+++ b/osi/include/osi.h
@@ -25,8 +25,6 @@
#define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x)
#endif // COMPILE_ASSERT
-typedef uint32_t timeout_t;
-
// Macros for safe integer to pointer conversion. In the C language, data is
// commonly cast to opaque pointer containers and back for generic parameter
// passing in callbacks. These macros should be used sparingly in new code
diff --git a/osi/include/thread.h b/osi/include/thread.h
index 9c4068e..b77f726 100644
--- a/osi/include/thread.h
+++ b/osi/include/thread.h
@@ -51,6 +51,7 @@
// does not block unless there are an excessive number of functions posted to
// |thread| that have not been dispatched yet. Neither |thread| nor |func| may
// be NULL. |context| may be NULL.
+// Return true on success, otherwise false.
bool thread_post(thread_t *thread, thread_fn func, void *context);
// Requests |thread| to stop. Only |thread_free| and |thread_name| may be called
@@ -67,6 +68,7 @@
// |thread| may not be NULL.
bool thread_is_self(const thread_t *thread);
+// Returns the reactor for the given |thread|. |thread| may not be NULL.
reactor_t *thread_get_reactor(const thread_t *thread);
// Returns the name of the given |thread|. |thread| may not be NULL.
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index b675e5f..a2328da 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -33,6 +33,7 @@
#include <hardware/bluetooth.h>
#include "osi/include/allocator.h"
+#include "osi/include/fixed_queue.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -47,19 +48,42 @@
// TODO(eisenbach): Determine correct thread priority (from parent?/per alarm?)
static const int CALLBACK_THREAD_PRIORITY_HIGH = -19;
+typedef struct {
+ size_t count;
+ period_ms_t total_ms;
+ period_ms_t max_ms;
+} stat_t;
+
+// Alarm-related information and statistics
+typedef struct {
+ const char *name;
+ size_t scheduled_count;
+ size_t canceled_count;
+ size_t rescheduled_count;
+ size_t total_updates;
+ period_ms_t last_update_ms;
+ stat_t callback_execution;
+ stat_t overdue_scheduling;
+ stat_t premature_scheduling;
+} alarm_stats_t;
+
struct alarm_t {
// The lock is held while the callback for this alarm is being executed.
- // It allows us to release the coarse-grained monitor lock while a potentially
- // long-running callback is executing. |alarm_cancel| uses this lock to provide
- // a guarantee to its caller that the callback will not be in progress when it
- // returns.
+ // It allows us to release the coarse-grained monitor lock while a
+ // potentially long-running callback is executing. |alarm_cancel| uses this
+ // lock to provide a guarantee to its caller that the callback will not be
+ // in progress when it returns.
pthread_mutex_t callback_lock;
period_ms_t creation_time;
period_ms_t period;
period_ms_t deadline;
+ period_ms_t prev_deadline; // Previous deadline - used for accounting of
+ // periodic timers
bool is_periodic;
+ fixed_queue_t *queue; // The processing queue to add this alarm to
alarm_callback_t callback;
void *data;
+ alarm_stats_t stats;
};
@@ -72,29 +96,58 @@
static const clockid_t CLOCK_ID_ALARM = CLOCK_BOOTTIME_ALARM;
// This mutex ensures that the |alarm_set|, |alarm_cancel|, and alarm callback
-// functions execute serially and not concurrently. As a result, this mutex also
-// protects the |alarms| list.
+// functions execute serially and not concurrently. As a result, this mutex
+// also protects the |alarms| list.
static pthread_mutex_t monitor;
static list_t *alarms;
static timer_t timer;
static timer_t wakeup_timer;
static bool timer_set;
-// All alarm callbacks are dispatched from |callback_thread|
-static thread_t *callback_thread;
-static bool callback_thread_active;
+// All alarm callbacks are dispatched from |dispatcher_thread|
+static thread_t *dispatcher_thread;
+static bool dispatcher_thread_active;
static semaphore_t *alarm_expired;
+// Default alarm callback thread and queue
+static thread_t *default_callback_thread;
+static fixed_queue_t *default_callback_queue;
+
+static alarm_t *alarm_new_internal(const char *name, bool is_periodic);
static bool lazy_initialize(void);
static period_ms_t now(void);
-static void alarm_set_internal(alarm_t *alarm, period_ms_t deadline, alarm_callback_t cb, void *data, bool is_periodic);
-static void schedule_next_instance(alarm_t *alarm, bool force_reschedule);
+static void alarm_set_internal(alarm_t *alarm, period_ms_t period,
+ alarm_callback_t cb, void *data,
+ fixed_queue_t *queue);
+static void remove_pending_alarm(alarm_t *alarm);
+static void schedule_next_instance(alarm_t *alarm);
static void reschedule_root_alarm(void);
+static void alarm_queue_ready(fixed_queue_t *queue, void *context);
static void timer_callback(void *data);
static void callback_dispatch(void *context);
static bool timer_create_internal(const clockid_t clock_id, timer_t *timer);
+static void update_scheduling_stats(alarm_stats_t *stats,
+ period_ms_t now_ms,
+ period_ms_t deadline_ms,
+ period_ms_t execution_delta_ms);
-alarm_t *alarm_new(void) {
+static void update_stat(stat_t *stat, period_ms_t delta)
+{
+ if (stat->max_ms < delta)
+ stat->max_ms = delta;
+ stat->total_ms += delta;
+ stat->count++;
+}
+
+alarm_t *alarm_new(const char *name) {
+ return alarm_new_internal(name, false);
+}
+
+alarm_t *alarm_new_periodic(const char *name) {
+ return alarm_new_internal(name, true);
+}
+
+static alarm_t *alarm_new_internal(const char *name, bool is_periodic) {
// Make sure we have a list we can insert alarms into.
if (!alarms && !lazy_initialize()) {
assert(false); // if initialization failed, we should not continue
@@ -114,20 +167,28 @@
// within the callback function of the alarm.
int error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (error) {
- LOG_ERROR(LOG_TAG, "%s unable to create a recursive mutex: %s", __func__, strerror(error));
+ LOG_ERROR(LOG_TAG, "%s unable to create a recursive mutex: %s",
+ __func__, strerror(error));
goto error;
}
error = pthread_mutex_init(&ret->callback_lock, &attr);
if (error) {
- LOG_ERROR(LOG_TAG, "%s unable to initialize mutex: %s", __func__, strerror(error));
+ LOG_ERROR(LOG_TAG, "%s unable to initialize mutex: %s",
+ __func__, strerror(error));
goto error;
}
+ ret->is_periodic = is_periodic;
+
+ alarm_stats_t *stats = &ret->stats;
+ stats->name = osi_strdup(name);
+ // NOTE: The stats were reset by osi_calloc() above
+
pthread_mutexattr_destroy(&attr);
return ret;
-error:;
+error:
pthread_mutexattr_destroy(&attr);
osi_free(ret);
return NULL;
@@ -139,31 +200,39 @@
alarm_cancel(alarm);
pthread_mutex_destroy(&alarm->callback_lock);
+ osi_free((void *)alarm->stats.name);
osi_free(alarm);
}
period_ms_t alarm_get_remaining_ms(const alarm_t *alarm) {
assert(alarm != NULL);
period_ms_t remaining_ms = 0;
+ period_ms_t just_now = now();
pthread_mutex_lock(&monitor);
- if (alarm->deadline)
- remaining_ms = alarm->deadline - now();
+ if (alarm->deadline > just_now)
+ remaining_ms = alarm->deadline - just_now;
pthread_mutex_unlock(&monitor);
return remaining_ms;
}
-void alarm_set(alarm_t *alarm, period_ms_t deadline, alarm_callback_t cb, void *data) {
- alarm_set_internal(alarm, deadline, cb, data, false);
+void alarm_set(alarm_t *alarm, period_ms_t interval_ms,
+ alarm_callback_t cb, void *data) {
+ alarm_set_on_queue(alarm, interval_ms, cb, data, default_callback_queue);
}
-void alarm_set_periodic(alarm_t *alarm, period_ms_t period, alarm_callback_t cb, void *data) {
- alarm_set_internal(alarm, period, cb, data, true);
+void alarm_set_on_queue(alarm_t *alarm, period_ms_t interval_ms,
+ alarm_callback_t cb, void *data,
+ fixed_queue_t *queue) {
+ assert(queue != NULL);
+ alarm_set_internal(alarm, interval_ms, cb, data, queue);
}
// Runs in exclusion with alarm_cancel and timer_callback.
-static void alarm_set_internal(alarm_t *alarm, period_ms_t period, alarm_callback_t cb, void *data, bool is_periodic) {
+static void alarm_set_internal(alarm_t *alarm, period_ms_t period,
+ alarm_callback_t cb, void *data,
+ fixed_queue_t *queue) {
assert(alarms != NULL);
assert(alarm != NULL);
assert(cb != NULL);
@@ -171,12 +240,13 @@
pthread_mutex_lock(&monitor);
alarm->creation_time = now();
- alarm->is_periodic = is_periodic;
alarm->period = period;
+ alarm->queue = queue;
alarm->callback = cb;
alarm->data = data;
- schedule_next_instance(alarm, false);
+ schedule_next_instance(alarm);
+ alarm->stats.scheduled_count++;
pthread_mutex_unlock(&monitor);
}
@@ -189,10 +259,13 @@
bool needs_reschedule = (!list_is_empty(alarms) && list_front(alarms) == alarm);
- list_remove(alarms, alarm);
+ remove_pending_alarm(alarm);
+
alarm->deadline = 0;
+ alarm->prev_deadline = 0;
alarm->callback = NULL;
alarm->data = NULL;
+ alarm->stats.canceled_count++;
if (needs_reschedule)
reschedule_root_alarm();
@@ -204,15 +277,26 @@
pthread_mutex_unlock(&alarm->callback_lock);
}
+bool alarm_is_scheduled(const alarm_t *alarm) {
+ if ((alarms == NULL) || (alarm == NULL))
+ return false;
+ return (alarm->callback != NULL);
+}
+
void alarm_cleanup(void) {
// If lazy_initialize never ran there is nothing else to do
if (!alarms)
return;
- callback_thread_active = false;
+ dispatcher_thread_active = false;
semaphore_post(alarm_expired);
- thread_free(callback_thread);
- callback_thread = NULL;
+ thread_free(dispatcher_thread);
+ dispatcher_thread = NULL;
+
+ fixed_queue_free(default_callback_queue, NULL);
+ default_callback_queue = NULL;
+ thread_free(default_callback_thread);
+ default_callback_thread = NULL;
semaphore_free(alarm_expired);
alarm_expired = NULL;
@@ -253,22 +337,44 @@
goto error;
}
- callback_thread_active = true;
- callback_thread = thread_new("alarm_callbacks");
- if (!callback_thread) {
+ default_callback_thread = thread_new_sized("alarm_default_callbacks",
+ SIZE_MAX);
+ if (default_callback_thread == NULL) {
+ LOG_ERROR(LOG_TAG, "%s unable to create default alarm callbacks thread.",
+ __func__);
+ goto error;
+ }
+ thread_set_priority(default_callback_thread, CALLBACK_THREAD_PRIORITY_HIGH);
+ default_callback_queue = fixed_queue_new(SIZE_MAX);
+ if (default_callback_queue == NULL) {
+ LOG_ERROR(LOG_TAG, "%s unable to create default alarm callbacks queue.",
+ __func__);
+ goto error;
+ }
+ alarm_register_processing_queue(default_callback_queue,
+ default_callback_thread);
+
+ dispatcher_thread_active = true;
+ dispatcher_thread = thread_new("alarm_dispatcher");
+ if (!dispatcher_thread) {
LOG_ERROR(LOG_TAG, "%s unable to create alarm callback thread.", __func__);
goto error;
}
- thread_set_priority(callback_thread, CALLBACK_THREAD_PRIORITY_HIGH);
- thread_post(callback_thread, callback_dispatch, NULL);
+ thread_set_priority(dispatcher_thread, CALLBACK_THREAD_PRIORITY_HIGH);
+ thread_post(dispatcher_thread, callback_dispatch, NULL);
return true;
error:
- thread_free(callback_thread);
- callback_thread = NULL;
+ fixed_queue_free(default_callback_queue, NULL);
+ default_callback_queue = NULL;
+ thread_free(default_callback_thread);
+ default_callback_thread = NULL;
- callback_thread_active = false;
+ thread_free(dispatcher_thread);
+ dispatcher_thread = NULL;
+
+ dispatcher_thread_active = false;
semaphore_free(alarm_expired);
alarm_expired = NULL;
@@ -292,41 +398,58 @@
struct timespec ts;
if (clock_gettime(CLOCK_ID, &ts) == -1) {
- LOG_ERROR(LOG_TAG, "%s unable to get current time: %s", __func__, strerror(errno));
+ LOG_ERROR(LOG_TAG, "%s unable to get current time: %s",
+ __func__, strerror(errno));
return 0;
}
return (ts.tv_sec * 1000LL) + (ts.tv_nsec / 1000000LL);
}
+// Remove alarm from internal alarm list and the processing queue
+// The caller must hold the |monitor| lock.
+static void remove_pending_alarm(alarm_t *alarm) {
+ list_remove(alarms, alarm);
+ while (fixed_queue_try_remove_from_queue(alarm->queue, alarm) != NULL) {
+ // Remove all repeated alarm instances from the queue.
+ // NOTE: We are defensive here - we shouldn't have repeated alarm instances
+ }
+}
+
// Must be called with monitor held
-static void schedule_next_instance(alarm_t *alarm, bool force_reschedule) {
+static void schedule_next_instance(alarm_t *alarm) {
// If the alarm is currently set and it's at the start of the list,
// we'll need to re-schedule since we've adjusted the earliest deadline.
bool needs_reschedule = (!list_is_empty(alarms) && list_front(alarms) == alarm);
if (alarm->callback)
- list_remove(alarms, alarm);
+ remove_pending_alarm(alarm);
// Calculate the next deadline for this alarm
period_ms_t just_now = now();
- period_ms_t ms_into_period = alarm->is_periodic ? ((just_now - alarm->creation_time) % alarm->period) : 0;
+ period_ms_t ms_into_period = 0;
+ if (alarm->is_periodic)
+ ms_into_period = ((just_now - alarm->creation_time) % alarm->period);
alarm->deadline = just_now + (alarm->period - ms_into_period);
// Add it into the timer list sorted by deadline (earliest deadline first).
- if (list_is_empty(alarms) || ((alarm_t *)list_front(alarms))->deadline >= alarm->deadline)
+ if (list_is_empty(alarms) ||
+ ((alarm_t *)list_front(alarms))->deadline > alarm->deadline) {
list_prepend(alarms, alarm);
- else
+ } else {
for (list_node_t *node = list_begin(alarms); node != list_end(alarms); node = list_next(node)) {
list_node_t *next = list_next(node);
- if (next == list_end(alarms) || ((alarm_t *)list_node(next))->deadline >= alarm->deadline) {
+ if (next == list_end(alarms) || ((alarm_t *)list_node(next))->deadline > alarm->deadline) {
list_insert_after(alarms, node, alarm);
break;
}
}
+ }
// If the new alarm has the earliest deadline, we need to re-evaluate our schedule.
- if (force_reschedule || needs_reschedule || (!list_is_empty(alarms) && list_front(alarms) == alarm))
+ if (needs_reschedule ||
+ (!list_is_empty(alarms) && list_front(alarms) == alarm)) {
reschedule_root_alarm();
+ }
}
// NOTE: must be called with monitor lock.
@@ -355,17 +478,18 @@
timer_time.it_value.tv_sec = (next->deadline / 1000);
timer_time.it_value.tv_nsec = (next->deadline % 1000) * 1000000LL;
- // It is entirely unsafe to call timer_settime(2) with a zeroed timerspec for
- // timers with *_ALARM clock IDs. Although the man page states that the timer
- // would be canceled, the current behavior (as of Linux kernel 3.17) is that
- // the callback is issued immediately. The only way to cancel an *_ALARM timer
- // is to delete the timer. But unfortunately, deleting and re-creating a timer
- // is rather expensive; every timer_create(2) spawns a new thread. So we simply
- // set the timer to fire at the largest possible time.
+ // It is entirely unsafe to call timer_settime(2) with a zeroed timerspec
+ // for timers with *_ALARM clock IDs. Although the man page states that the
+ // timer would be canceled, the current behavior (as of Linux kernel 3.17)
+ // is that the callback is issued immediately. The only way to cancel an
+ // *_ALARM timer is to delete the timer. But unfortunately, deleting and
+ // re-creating a timer is rather expensive; every timer_create(2) spawns a
+ // new thread. So we simply set the timer to fire at the largest possible
+ // time.
//
- // If we've reached this code path, we're going to grab a wake lock and wait for
- // the next timer to fire. In that case, there's no reason to have a pending wakeup
- // timer so we simply cancel it.
+ // If we've reached this code path, we're going to grab a wake lock and
+ // wait for the next timer to fire. In that case, there's no reason to
+ // have a pending wakeup timer so we simply cancel it.
struct itimerspec end_of_time;
memset(&end_of_time, 0, sizeof(end_of_time));
end_of_time.it_value.tv_sec = (time_t)(1LL << (sizeof(time_t) * 8 - 2));
@@ -394,36 +518,96 @@
if (timer_settime(timer, TIMER_ABSTIME, &timer_time, NULL) == -1)
LOG_ERROR(LOG_TAG, "%s unable to set timer: %s", __func__, strerror(errno));
- // If next expiration was in the past (e.g. short timer that got context switched)
- // then the timer might have diarmed itself. Detect this case and work around it
- // by manually signalling the |alarm_expired| semaphore.
+ // If next expiration was in the past (e.g. short timer that got context
+ // switched) then the timer might have diarmed itself. Detect this case and
+ // work around it by manually signalling the |alarm_expired| semaphore.
//
- // It is possible that the timer was actually super short (a few milliseconds)
- // and the timer expired normally before we called |timer_gettime|. Worst case,
- // |alarm_expired| is signaled twice for that alarm. Nothing bad should happen in
- // that case though since the callback dispatch function checks to make sure the
- // timer at the head of the list actually expired.
+ // It is possible that the timer was actually super short (a few
+ // milliseconds) and the timer expired normally before we called
+ // |timer_gettime|. Worst case, |alarm_expired| is signaled twice for that
+ // alarm. Nothing bad should happen in that case though since the callback
+ // dispatch function checks to make sure the timer at the head of the list
+ // actually expired.
if (timer_set) {
struct itimerspec time_to_expire;
timer_gettime(timer, &time_to_expire);
- if (time_to_expire.it_value.tv_sec == 0 && time_to_expire.it_value.tv_nsec == 0) {
- LOG_ERROR(LOG_TAG, "%s alarm expiration too close for posix timers, switching to guns", __func__);
+ if (time_to_expire.it_value.tv_sec == 0 &&
+ time_to_expire.it_value.tv_nsec == 0) {
+ LOG_DEBUG(LOG_TAG, "%s alarm expiration too close for posix timers, switching to guns", __func__);
semaphore_post(alarm_expired);
}
}
}
+void alarm_register_processing_queue(fixed_queue_t *queue, thread_t *thread) {
+ assert(queue != NULL);
+ assert(thread != NULL);
+
+ fixed_queue_register_dequeue(queue, thread_get_reactor(thread),
+ alarm_queue_ready, NULL);
+}
+
+void alarm_unregister_processing_queue(fixed_queue_t *queue) {
+ fixed_queue_unregister_dequeue(queue);
+}
+
+static void alarm_queue_ready(fixed_queue_t *queue,
+ UNUSED_ATTR void *context) {
+ assert(queue != NULL);
+
+ pthread_mutex_lock(&monitor);
+ alarm_t *alarm = (alarm_t *)fixed_queue_try_dequeue(queue);
+ if (alarm == NULL) {
+ pthread_mutex_unlock(&monitor);
+ return; // The alarm was probably canceled
+ }
+
+ //
+ // If the alarm is not periodic, we've fully serviced it now, and can reset
+ // some of its internal state. This is useful to distinguish between expired
+ // alarms and active ones.
+ //
+ alarm_callback_t callback = alarm->callback;
+ void *data = alarm->data;
+ period_ms_t deadline = alarm->deadline;
+ if (alarm->is_periodic) {
+ // The periodic alarm has been rescheduled and alarm->deadline has been
+ // updated, hence we need to use the previous deadline.
+ deadline = alarm->prev_deadline;
+ } else {
+ alarm->deadline = 0;
+ alarm->callback = NULL;
+ alarm->data = NULL;
+ }
+
+ pthread_mutex_lock(&alarm->callback_lock);
+ pthread_mutex_unlock(&monitor);
+
+ period_ms_t t0 = now();
+ callback(data);
+ period_ms_t t1 = now();
+
+ // Update the statistics
+ assert(t1 >= t0);
+ period_ms_t delta = t1 - t0;
+ update_scheduling_stats(&alarm->stats, t0, deadline, delta);
+
+ pthread_mutex_unlock(&alarm->callback_lock);
+}
+
// Callback function for wake alarms and our posix timer
static void timer_callback(UNUSED_ATTR void *ptr) {
semaphore_post(alarm_expired);
}
-// Function running on |callback_thread| that dispatches alarm callbacks upon
-// alarm expiration, which is signaled using |alarm_expired|.
+// Function running on |dispatcher_thread| that performs the following:
+// (1) Receives a signal using |alarm_exired| that the alarm has expired
+// (2) Dispatches the alarm callback for processing by the corresponding
+// thread for that alarm.
static void callback_dispatch(UNUSED_ATTR void *context) {
while (true) {
semaphore_wait(alarm_expired);
- if (!callback_thread_active)
+ if (!dispatcher_thread_active)
break;
pthread_mutex_lock(&monitor);
@@ -433,7 +617,8 @@
// We're done here if there are no alarms or the alarm at the front is in
// the future. Release the monitor lock and exit right away since there's
// nothing left to do.
- if (list_is_empty(alarms) || (alarm = list_front(alarms))->deadline > now()) {
+ if (list_is_empty(alarms) ||
+ (alarm = list_front(alarms))->deadline > now()) {
reschedule_root_alarm();
pthread_mutex_unlock(&monitor);
continue;
@@ -441,26 +626,17 @@
list_remove(alarms, alarm);
- alarm_callback_t callback = alarm->callback;
- void *data = alarm->data;
-
if (alarm->is_periodic) {
- schedule_next_instance(alarm, true);
- } else {
- reschedule_root_alarm();
-
- alarm->deadline = 0;
- alarm->callback = NULL;
- alarm->data = NULL;
+ alarm->prev_deadline = alarm->deadline;
+ schedule_next_instance(alarm);
+ alarm->stats.rescheduled_count++;
}
+ reschedule_root_alarm();
- // Downgrade lock.
- pthread_mutex_lock(&alarm->callback_lock);
+ // Enqueue the alarm for processing
+ fixed_queue_enqueue(alarm->queue, alarm);
+
pthread_mutex_unlock(&monitor);
-
- callback(data);
-
- pthread_mutex_unlock(&alarm->callback_lock);
}
LOG_DEBUG(LOG_TAG, "%s Callback thread exited", __func__);
@@ -481,3 +657,87 @@
return true;
}
+
+static void update_scheduling_stats(alarm_stats_t *stats,
+ period_ms_t now_ms,
+ period_ms_t deadline_ms,
+ period_ms_t execution_delta_ms)
+{
+ stats->total_updates++;
+ stats->last_update_ms = now_ms;
+
+ update_stat(&stats->callback_execution, execution_delta_ms);
+
+ if (deadline_ms < now_ms) {
+ // Overdue scheduling
+ period_ms_t delta_ms = now_ms - deadline_ms;
+ update_stat(&stats->overdue_scheduling, delta_ms);
+ } else if (deadline_ms > now_ms) {
+ // Premature scheduling
+ period_ms_t delta_ms = deadline_ms - now_ms;
+ update_stat(&stats->premature_scheduling, delta_ms);
+ }
+}
+
+static void dump_stat(int fd, stat_t *stat, const char *description)
+{
+ period_ms_t ave_time_ms;
+
+ ave_time_ms = 0;
+ if (stat->count != 0) {
+ ave_time_ms = stat->total_ms / stat->count;
+ }
+ dprintf(fd, "%s in ms (total/max/ave) : %llu / %llu / %llu\n",
+ description,
+ (unsigned long long)stat->total_ms,
+ (unsigned long long)stat->max_ms,
+ (unsigned long long)ave_time_ms);
+}
+
+void alarm_debug_dump(int fd)
+{
+ dprintf(fd, "\nBluetooth Alarms Statistics:\n");
+
+ pthread_mutex_lock(&monitor);
+
+ if (alarms == NULL) {
+ pthread_mutex_unlock(&monitor);
+ dprintf(fd, " None\n");
+ return;
+ }
+
+ period_ms_t just_now = now();
+
+ dprintf(fd, " Total Alarms: %zu\n\n", list_length(alarms));
+
+ // Dump info for each alarm
+ for (list_node_t *node = list_begin(alarms); node != list_end(alarms);
+ node = list_next(node)) {
+ alarm_t *alarm = (alarm_t *)list_node(node);
+ alarm_stats_t *stats = &alarm->stats;
+
+ dprintf(fd, " Alarm : %s (%s)\n", stats->name,
+ (alarm->is_periodic) ? "PERIODIC" : "SINGLE");
+
+ dprintf(fd, " Action counts (sched/resched/exec/cancel) : %zu / %zu / %zu / %zu\n",
+ stats->scheduled_count, stats->rescheduled_count,
+ stats->callback_execution.count, stats->canceled_count);
+
+ dprintf(fd, " Deviation counts (overdue/premature) : %zu / %zu\n",
+ stats->overdue_scheduling.count,
+ stats->premature_scheduling.count);
+
+ dprintf(fd, " Time in ms (since creation/interval/remaining) : %llu / %llu / %lld\n",
+ (unsigned long long)(just_now - alarm->creation_time),
+ (unsigned long long) alarm->period,
+ (long long)(alarm->deadline - just_now));
+
+ dump_stat(fd, &stats->callback_execution, " Callback execution time");
+ dump_stat(fd, &stats->overdue_scheduling, " Overdue scheduling time");
+ dump_stat(fd, &stats->premature_scheduling,
+ " Premature scheduling time");
+
+ dprintf(fd, "\n");
+ }
+ pthread_mutex_unlock(&monitor);
+}
diff --git a/osi/src/non_repeating_timer.c b/osi/src/non_repeating_timer.c
deleted file mode 100644
index e5e95d4..0000000
--- a/osi/src/non_repeating_timer.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2014 Google, Inc.
- *
- * 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 <assert.h>
-
-#include "osi/include/allocator.h"
-#include "osi/include/osi.h"
-#include "osi/include/non_repeating_timer.h"
-
-struct non_repeating_timer_t {
- alarm_t *alarm;
- period_ms_t duration;
- alarm_callback_t callback;
- void *data;
-};
-
-non_repeating_timer_t *non_repeating_timer_new(period_ms_t duration, alarm_callback_t cb, void *data) {
- assert(cb != NULL);
-
- non_repeating_timer_t *ret = osi_calloc(sizeof(non_repeating_timer_t));
-
- ret->alarm = alarm_new();
- if (!ret->alarm)
- goto error;
-
- ret->duration = duration;
- ret->callback = cb;
- ret->data = data;
-
- return ret;
-error:;
- non_repeating_timer_free(ret);
- return NULL;
-}
-
-void non_repeating_timer_free(non_repeating_timer_t *timer) {
- if (!timer)
- return;
-
- alarm_free(timer->alarm);
- osi_free(timer);
-}
-
-void non_repeating_timer_restart(non_repeating_timer_t *timer) {
- non_repeating_timer_restart_if(timer, true);
-}
-
-void non_repeating_timer_restart_if(non_repeating_timer_t *timer, bool condition) {
- assert(timer != NULL);
- if (condition)
- alarm_set(timer->alarm, timer->duration, timer->callback, timer->data);
- else
- non_repeating_timer_cancel(timer);
-}
-
-void non_repeating_timer_cancel(non_repeating_timer_t *timer) {
- assert(timer != NULL);
- alarm_cancel(timer->alarm);
-}
diff --git a/osi/test/alarm_test.cpp b/osi/test/alarm_test.cpp
index 88beaf5..c4a2dca 100644
--- a/osi/test/alarm_test.cpp
+++ b/osi/test/alarm_test.cpp
@@ -22,12 +22,15 @@
extern "C" {
#include "osi/include/alarm.h"
+#include "osi/include/fixed_queue.h"
#include "osi/include/osi.h"
#include "osi/include/semaphore.h"
+#include "osi/include/thread.h"
}
static semaphore_t *semaphore;
static int cb_counter;
+static int cb_misordered_counter;
static const uint64_t EPSILON_MS = 5;
@@ -40,6 +43,7 @@
virtual void SetUp() {
AlarmTestHarness::SetUp();
cb_counter = 0;
+ cb_misordered_counter = 0;
semaphore = semaphore_new(0);
}
@@ -55,8 +59,16 @@
semaphore_post(semaphore);
}
+static void ordered_cb(void *data) {
+ int i = PTR_TO_INT(data);
+ if (i != cb_counter)
+ cb_misordered_counter++;
+ ++cb_counter;
+ semaphore_post(semaphore);
+}
+
TEST_F(AlarmTest, test_new_free_simple) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_new_free_simple");
ASSERT_TRUE(alarm != NULL);
alarm_free(alarm);
}
@@ -66,25 +78,25 @@
}
TEST_F(AlarmTest, test_simple_cancel) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_simple_cancel");
alarm_cancel(alarm);
alarm_free(alarm);
}
TEST_F(AlarmTest, test_cancel) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_cancel");
alarm_set(alarm, 10, cb, NULL);
alarm_cancel(alarm);
msleep(10 + EPSILON_MS);
EXPECT_EQ(cb_counter, 0);
- EXPECT_FALSE(WakeLockHeld());;
+ EXPECT_FALSE(WakeLockHeld());
alarm_free(alarm);
}
TEST_F(AlarmTest, test_cancel_idempotent) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_cancel_idempotent");
alarm_set(alarm, 10, cb, NULL);
alarm_cancel(alarm);
alarm_cancel(alarm);
@@ -93,7 +105,8 @@
}
TEST_F(AlarmTest, test_set_short) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_set_short");
+
alarm_set(alarm, 10, cb, NULL);
EXPECT_EQ(cb_counter, 0);
@@ -107,8 +120,28 @@
alarm_free(alarm);
}
+TEST_F(AlarmTest, test_set_short_periodic) {
+ alarm_t *alarm = alarm_new_periodic("alarm_test.test_set_short_periodic");
+
+ alarm_set(alarm, 10, cb, NULL);
+
+ EXPECT_EQ(cb_counter, 0);
+ EXPECT_TRUE(WakeLockHeld());
+
+ for (int i = 1; i <= 10; i++) {
+ semaphore_wait(semaphore);
+
+ EXPECT_GE(cb_counter, i);
+ EXPECT_TRUE(WakeLockHeld());
+ }
+ alarm_cancel(alarm);
+ EXPECT_FALSE(WakeLockHeld());
+
+ alarm_free(alarm);
+}
+
TEST_F(AlarmTest, test_set_long) {
- alarm_t *alarm = alarm_new();
+ alarm_t *alarm = alarm_new("alarm_test.test_set_long");
alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL);
EXPECT_EQ(cb_counter, 0);
@@ -124,8 +157,8 @@
TEST_F(AlarmTest, test_set_short_short) {
alarm_t *alarm[2] = {
- alarm_new(),
- alarm_new()
+ alarm_new("alarm_test.test_set_short_short_0"),
+ alarm_new("alarm_test.test_set_short_short_1")
};
alarm_set(alarm[0], 10, cb, NULL);
@@ -150,8 +183,8 @@
TEST_F(AlarmTest, test_set_short_long) {
alarm_t *alarm[2] = {
- alarm_new(),
- alarm_new()
+ alarm_new("alarm_test.test_set_short_long_0"),
+ alarm_new("alarm_test.test_set_short_long_1")
};
alarm_set(alarm[0], 10, cb, NULL);
@@ -176,8 +209,8 @@
TEST_F(AlarmTest, test_set_long_long) {
alarm_t *alarm[2] = {
- alarm_new(),
- alarm_new()
+ alarm_new("alarm_test.test_set_long_long_0"),
+ alarm_new("alarm_test.test_set_long_long_1")
};
alarm_set(alarm[0], TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL);
@@ -200,11 +233,98 @@
alarm_free(alarm[1]);
}
+TEST_F(AlarmTest, test_is_scheduled) {
+ alarm_t *alarm = alarm_new("alarm_test.test_is_scheduled");
+
+ EXPECT_FALSE(alarm_is_scheduled((alarm_t *)NULL));
+ EXPECT_FALSE(alarm_is_scheduled(alarm));
+ alarm_set(alarm, TIMER_INTERVAL_FOR_WAKELOCK_IN_MS + EPSILON_MS, cb, NULL);
+ EXPECT_TRUE(alarm_is_scheduled(alarm));
+
+ EXPECT_EQ(cb_counter, 0);
+ EXPECT_FALSE(WakeLockHeld());
+
+ semaphore_wait(semaphore);
+
+ EXPECT_FALSE(alarm_is_scheduled(alarm));
+ EXPECT_EQ(cb_counter, 1);
+ EXPECT_FALSE(WakeLockHeld());
+
+ alarm_free(alarm);
+}
+
+// Test whether the callbacks are invoked in the expected order
+TEST_F(AlarmTest, test_callback_ordering) {
+ alarm_t *alarms[100];
+
+ for (int i = 0; i < 100; i++) {
+ const std::string alarm_name = "alarm_test.test_callback_ordering[" +
+ std::to_string(i) + "]";
+ alarms[i] = alarm_new(alarm_name.c_str());
+ }
+
+ for (int i = 0; i < 100; i++) {
+ alarm_set(alarms[i], 100, ordered_cb, INT_TO_PTR(i));
+ }
+
+ for (int i = 1; i <= 100; i++) {
+ semaphore_wait(semaphore);
+ EXPECT_GE(cb_counter, i);
+ }
+ EXPECT_EQ(cb_counter, 100);
+ EXPECT_EQ(cb_misordered_counter, 0);
+
+ for (int i = 0; i < 100; i++)
+ alarm_free(alarms[i]);
+
+ EXPECT_FALSE(WakeLockHeld());
+}
+
+// Test whether the callbacks are involed in the expected order on a
+// separate queue.
+TEST_F(AlarmTest, test_callback_ordering_on_queue) {
+ alarm_t *alarms[100];
+ fixed_queue_t *queue = fixed_queue_new(SIZE_MAX);
+ thread_t *thread = thread_new("timers.test_callback_ordering_on_queue.thread");
+
+ alarm_register_processing_queue(queue, thread);
+
+ for (int i = 0; i < 100; i++) {
+ const std::string alarm_name =
+ "alarm_test.test_callback_ordering_on_queue[" +
+ std::to_string(i) + "]";
+ alarms[i] = alarm_new(alarm_name.c_str());
+ }
+
+ for (int i = 0; i < 100; i++) {
+ alarm_set_on_queue(alarms[i], 100, ordered_cb, INT_TO_PTR(i), queue);
+ }
+
+ for (int i = 1; i <= 100; i++) {
+ semaphore_wait(semaphore);
+ EXPECT_GE(cb_counter, i);
+ }
+ EXPECT_EQ(cb_counter, 100);
+ EXPECT_EQ(cb_misordered_counter, 0);
+
+ for (int i = 0; i < 100; i++)
+ alarm_free(alarms[i]);
+
+ EXPECT_FALSE(WakeLockHeld());
+
+ alarm_unregister_processing_queue(queue);
+ fixed_queue_free(queue, NULL);
+ thread_free(thread);
+}
+
// Try to catch any race conditions between the timer callback and |alarm_free|.
TEST_F(AlarmTest, test_callback_free_race) {
for (int i = 0; i < 1000; ++i) {
- alarm_t *alarm = alarm_new();
+ const std::string alarm_name = "alarm_test.test_callback_free_race[" +
+ std::to_string(i) + "]";
+ alarm_t *alarm = alarm_new(alarm_name.c_str());
alarm_set(alarm, 0, cb, NULL);
alarm_free(alarm);
}
+ alarm_cleanup();
}
diff --git a/stack/avdt/avdt_api.c b/stack/avdt/avdt_api.c
index ea754c7..30b41da 100644
--- a/stack/avdt/avdt_api.c
+++ b/stack/avdt/avdt_api.c
@@ -39,57 +39,39 @@
tAVDT_CB avdt_cb;
#endif
-
-/*******************************************************************************
-**
-** Function avdt_process_timeout
-**
-** Description This function is called by BTU when an AVDTP timer
-** expires. The function sends a timer event to the
-** appropriate CCB or SCB state machine.
-**
-** This function is for use internal to the stack only.
-**
-**
-** Returns void
-**
-*******************************************************************************/
-void avdt_process_timeout(timer_entry_t *p_te)
+void avdt_ccb_idle_ccb_timer_timeout(void *data)
{
- UINT8 event = 0;
- UINT8 err_code = AVDT_ERR_TIMEOUT;
+ tAVDT_CCB *p_ccb = (tAVDT_CCB *)data;
+ uint8_t avdt_event = AVDT_CCB_IDLE_TOUT_EVT;
+ uint8_t err_code = AVDT_ERR_TIMEOUT;
- switch (p_te->event)
- {
- case BTU_TTYPE_AVDT_CCB_RET:
- event = AVDT_CCB_RET_TOUT_EVT + AVDT_CCB_MKR;
- break;
+ avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code);
+}
- case BTU_TTYPE_AVDT_CCB_RSP:
- event = AVDT_CCB_RSP_TOUT_EVT + AVDT_CCB_MKR;
- break;
+void avdt_ccb_ret_ccb_timer_timeout(void *data)
+{
+ tAVDT_CCB *p_ccb = (tAVDT_CCB *)data;
+ uint8_t avdt_event = AVDT_CCB_RET_TOUT_EVT;
+ uint8_t err_code = AVDT_ERR_TIMEOUT;
- case BTU_TTYPE_AVDT_CCB_IDLE:
- event = AVDT_CCB_IDLE_TOUT_EVT + AVDT_CCB_MKR;
- break;
+ avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code);
+}
- case BTU_TTYPE_AVDT_SCB_TC:
- event = AVDT_SCB_TC_TOUT_EVT;
- break;
+void avdt_ccb_rsp_ccb_timer_timeout(void *data)
+{
+ tAVDT_CCB *p_ccb = (tAVDT_CCB *)data;
+ uint8_t avdt_event = AVDT_CCB_RSP_TOUT_EVT;
+ uint8_t err_code = AVDT_ERR_TIMEOUT;
- default:
- break;
- }
+ avdt_ccb_event(p_ccb, avdt_event, (tAVDT_CCB_EVT *)&err_code);
+}
- if (event & AVDT_CCB_MKR)
- {
- avdt_ccb_event((tAVDT_CCB *) p_te->param, (UINT8) (event & ~AVDT_CCB_MKR),
- (tAVDT_CCB_EVT *) &err_code);
- }
- else
- {
- avdt_scb_event((tAVDT_SCB *) p_te->param, event, NULL);
- }
+void avdt_scb_transport_channel_timer_timeout(void *data)
+{
+ tAVDT_SCB *p_scb = (tAVDT_SCB *)data;
+ uint8_t avdt_event = AVDT_SCB_TC_TOUT_EVT;
+
+ avdt_scb_event(p_scb, avdt_event, NULL);
}
/*******************************************************************************
diff --git a/stack/avdt/avdt_ccb.c b/stack/avdt/avdt_ccb.c
index 00a3cbe..194af6b 100644
--- a/stack/avdt/avdt_ccb.c
+++ b/stack/avdt/avdt_ccb.c
@@ -386,7 +386,9 @@
memcpy(p_ccb->peer_addr, bd_addr, BD_ADDR_LEN);
p_ccb->cmd_q = fixed_queue_new(SIZE_MAX);
p_ccb->rsp_q = fixed_queue_new(SIZE_MAX);
- p_ccb->timer_entry.param = p_ccb;
+ p_ccb->idle_ccb_timer = alarm_new("avdt_ccb.idle_ccb_timer");
+ p_ccb->ret_ccb_timer = alarm_new("avdt_ccb.ret_ccb_timer");
+ p_ccb->rsp_ccb_timer = alarm_new("avdt_ccb.rsp_ccb_timer");
AVDT_TRACE_DEBUG("avdt_ccb_alloc %d", i);
break;
}
@@ -416,7 +418,9 @@
UNUSED(p_data);
AVDT_TRACE_DEBUG("avdt_ccb_dealloc %d", avdt_ccb_to_idx(p_ccb));
- btu_stop_timer(&p_ccb->timer_entry);
+ alarm_free(p_ccb->idle_ccb_timer);
+ alarm_free(p_ccb->ret_ccb_timer);
+ alarm_free(p_ccb->rsp_ccb_timer);
fixed_queue_free(p_ccb->cmd_q, NULL);
fixed_queue_free(p_ccb->rsp_q, NULL);
memset(p_ccb, 0, sizeof(tAVDT_CCB));
diff --git a/stack/avdt/avdt_ccb_act.c b/stack/avdt/avdt_ccb_act.c
index 24b7cf4..8844b39 100644
--- a/stack/avdt/avdt_ccb_act.c
+++ b/stack/avdt/avdt_ccb_act.c
@@ -34,6 +34,8 @@
#include "btu.h"
#include "btm_api.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function avdt_ccb_clear_ccb
@@ -143,7 +145,12 @@
/* if no active scbs start idle timer */
if (i == AVDT_NUM_SEPS)
{
- btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_IDLE, avdt_cb.rcb.idle_tout);
+ alarm_cancel(p_ccb->ret_ccb_timer);
+ alarm_cancel(p_ccb->rsp_ccb_timer);
+ period_ms_t interval_ms = avdt_cb.rcb.idle_tout * 1000;
+ alarm_set_on_queue(p_ccb->idle_ccb_timer, interval_ms,
+ avdt_ccb_idle_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
@@ -830,8 +837,13 @@
}
}
- /* restart timer */
- btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RET, avdt_cb.rcb.ret_tout);
+ /* restart ret timer */
+ alarm_cancel(p_ccb->idle_ccb_timer);
+ alarm_cancel(p_ccb->rsp_ccb_timer);
+ period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000;
+ alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms,
+ avdt_ccb_ret_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
@@ -998,10 +1010,7 @@
{
UNUSED(p_data);
- if (p_ccb->timer_entry.event == BTU_TTYPE_AVDT_CCB_IDLE)
- {
- btu_stop_timer(&p_ccb->timer_entry);
- }
+ alarm_cancel(p_ccb->idle_ccb_timer);
}
/*******************************************************************************
diff --git a/stack/avdt/avdt_int.h b/stack/avdt/avdt_int.h
index f87fcfa..5746025 100644
--- a/stack/avdt/avdt_int.h
+++ b/stack/avdt/avdt_int.h
@@ -24,8 +24,8 @@
#ifndef AVDT_INT_H
#define AVDT_INT_H
+#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
-#include "osi/include/non_repeating_timer.h"
#include "bt_common.h"
#include "avdt_api.h"
#include "avdtc_api.h"
@@ -103,11 +103,11 @@
*/
#define AVDT_MSG_OFFSET (L2CAP_MIN_OFFSET + AVDT_NUM_SEPS + AVDT_LEN_TYPE_START)
-/* scb transport channel connect timeout value */
-#define AVDT_SCB_TC_CONN_TOUT 10
+/* scb transport channel connect timeout value (in milliseconds) */
+#define AVDT_SCB_TC_CONN_TIMEOUT_MS (10 * 1000)
-/* scb transport channel disconnect timeout value */
-#define AVDT_SCB_TC_DISC_TOUT 10
+/* scb transport channel disconnect timeout value (in milliseconds) */
+#define AVDT_SCB_TC_DISC_TIMEOUT_MS (10 * 1000)
/* maximum number of command retransmissions */
#ifndef AVDT_RET_MAX
@@ -424,7 +424,13 @@
/* channel control block type */
typedef struct {
BD_ADDR peer_addr; /* BD address of peer */
- timer_entry_t timer_entry; /* CCB timer entry */
+ /*
+ * NOTE: idle_ccb_timer, ret_ccb_timer and rsp_ccb_timer are mutually
+ * exclusive - no more than one timer should be running at the same time.
+ */
+ alarm_t *idle_ccb_timer; /* Idle CCB timer entry */
+ alarm_t *ret_ccb_timer; /* Ret CCB timer entry */
+ alarm_t *rsp_ccb_timer; /* Rsp CCB timer entry */
fixed_queue_t *cmd_q; /* Queue for outgoing command messages */
fixed_queue_t *rsp_q; /* Queue for outgoing response and reject messages */
tAVDT_CTRL_CBACK *proc_cback; /* Procedure callback function */
@@ -483,7 +489,7 @@
tAVDT_CS cs; /* stream creation struct */
tAVDT_CFG curr_cfg; /* current configuration */
tAVDT_CFG req_cfg; /* requested configuration */
- timer_entry_t timer_entry; /* timer entry */
+ alarm_t *transport_channel_timer; /* transport channel connect timer */
BT_HDR *p_pkt; /* packet waiting to be sent */
tAVDT_CCB *p_ccb; /* ccb associated with this scb */
UINT16 media_seq; /* media packet sequence number */
@@ -668,7 +674,8 @@
extern void avdt_scb_free_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
extern void avdt_scb_chk_snd_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
extern void avdt_scb_clr_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
-extern void avdt_scb_tc_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
+extern void avdt_scb_transport_channel_timer(tAVDT_SCB *p_scb,
+ tAVDT_SCB_EVT *p_data);
extern void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data);
extern void avdt_scb_queue_frags(tAVDT_SCB *p_scb, UINT8 **pp_data,
UINT32 *p_data_len, fixed_queue_t *pq);
@@ -697,7 +704,10 @@
extern void avdt_ad_open_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, UINT8 role);
extern void avdt_ad_close_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb);
-extern void avdt_process_timeout(timer_entry_t *p_te);
+extern void avdt_ccb_idle_ccb_timer_timeout(void *data);
+extern void avdt_ccb_ret_ccb_timer_timeout(void *data);
+extern void avdt_ccb_rsp_ccb_timer_timeout(void *data);
+extern void avdt_scb_transport_channel_timer_timeout(void *data);
/*****************************************************************************
** macros
diff --git a/stack/avdt/avdt_msg.c b/stack/avdt/avdt_msg.c
index 7fdaac8..511c5a1 100644
--- a/stack/avdt/avdt_msg.c
+++ b/stack/avdt/avdt_msg.c
@@ -36,6 +36,8 @@
#include "bt_common.h"
#include "btu.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*****************************************************************************
** constants
*****************************************************************************/
@@ -1307,11 +1309,21 @@
if ((sig == AVDT_SIG_DISCOVER) || (sig == AVDT_SIG_GETCAP) ||
(sig == AVDT_SIG_SECURITY) || (avdt_cb.rcb.ret_tout == 0))
{
- btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RSP, avdt_cb.rcb.sig_tout);
+ alarm_cancel(p_ccb->idle_ccb_timer);
+ alarm_cancel(p_ccb->ret_ccb_timer);
+ period_ms_t interval_ms = avdt_cb.rcb.sig_tout * 1000;
+ alarm_set_on_queue(p_ccb->rsp_ccb_timer, interval_ms,
+ avdt_ccb_rsp_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else if (sig != AVDT_SIG_DELAY_RPT)
{
- btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_AVDT_CCB_RET, avdt_cb.rcb.ret_tout);
+ alarm_cancel(p_ccb->idle_ccb_timer);
+ alarm_cancel(p_ccb->rsp_ccb_timer);
+ period_ms_t interval_ms = avdt_cb.rcb.ret_tout * 1000;
+ alarm_set_on_queue(p_ccb->ret_ccb_timer, interval_ms,
+ avdt_ccb_ret_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
}
@@ -1842,7 +1854,9 @@
(AVDT_LAYERSPEC_LABEL(p_ccb->p_curr_cmd->layer_specific) == label))
{
/* stop timer */
- btu_stop_timer(&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->idle_ccb_timer);
+ alarm_cancel(p_ccb->ret_ccb_timer);
+ alarm_cancel(p_ccb->rsp_ccb_timer);
/* clear retransmission count */
p_ccb->ret_count = 0;
diff --git a/stack/avdt/avdt_scb.c b/stack/avdt/avdt_scb.c
index f7d3c9c..6e26fa3 100644
--- a/stack/avdt/avdt_scb.c
+++ b/stack/avdt/avdt_scb.c
@@ -165,7 +165,7 @@
avdt_scb_free_pkt,
avdt_scb_clr_pkt,
avdt_scb_chk_snd_pkt,
- avdt_scb_tc_timer,
+ avdt_scb_transport_channel_timer,
avdt_scb_clr_vars,
avdt_scb_dealloc
};
@@ -594,6 +594,8 @@
{
if (!p_scb->allocated)
{
+ alarm_free(p_scb->transport_channel_timer);
+ p_scb->transport_channel_timer = NULL;
fixed_queue_free(p_scb->frag_q, NULL);
memset(p_scb,0,sizeof(tAVDT_SCB));
p_scb->allocated = TRUE;
@@ -615,7 +617,8 @@
#endif
}
#endif
- p_scb->timer_entry.param = p_scb;
+ p_scb->transport_channel_timer =
+ alarm_new("avdt_scb.transport_channel_timer");
AVDT_TRACE_DEBUG("avdt_scb_alloc hdl=%d, psc_mask:0x%x", i+1, p_cs->cfg.psc_mask);
break;
}
@@ -649,7 +652,8 @@
UNUSED(p_data);
AVDT_TRACE_DEBUG("avdt_scb_dealloc hdl=%d", avdt_scb_to_hdl(p_scb));
- btu_stop_timer(&p_scb->timer_entry);
+ alarm_free(p_scb->transport_channel_timer);
+ p_scb->transport_channel_timer = NULL;
#if AVDT_MULTIPLEXING == TRUE
/* free fragments we're holding, if any; it shouldn't happen */
diff --git a/stack/avdt/avdt_scb_act.c b/stack/avdt/avdt_scb_act.c
index 8e74520..f4d0f04 100644
--- a/stack/avdt/avdt_scb_act.c
+++ b/stack/avdt/avdt_scb_act.c
@@ -33,6 +33,9 @@
#include "bt_common.h"
#include "btu.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/* This table is used to lookup the callback event that matches a particular
** state machine API request event. Note that state machine API request
** events are at the beginning of the event list starting at zero, thus
@@ -227,7 +230,10 @@
avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_INT);
/* start tc connect timer */
- btu_start_timer(&p_scb->timer_entry, BTU_TTYPE_AVDT_SCB_TC, AVDT_SCB_TC_CONN_TOUT);
+ alarm_set_on_queue(p_scb->transport_channel_timer,
+ AVDT_SCB_TC_CONN_TIMEOUT_MS,
+ avdt_scb_transport_channel_timer_timeout, p_scb,
+ btu_general_alarm_queue);
}
/*******************************************************************************
@@ -1020,8 +1026,7 @@
p_scb->p_pkt = NULL;
}
- /* stop transport channel timer */
- btu_stop_timer(&p_scb->timer_entry);
+ alarm_cancel(p_scb->transport_channel_timer);
if ((p_scb->role == AVDT_CLOSE_INT) || (p_scb->role == AVDT_OPEN_INT))
{
@@ -1153,8 +1158,7 @@
UINT8 role;
#endif
- /* stop transport channel connect timer */
- btu_stop_timer(&p_scb->timer_entry);
+ alarm_cancel(p_scb->transport_channel_timer);
event = (p_scb->role == AVDT_OPEN_INT) ? AVDT_OPEN_CFM_EVT : AVDT_OPEN_IND_EVT;
p_data->open.hdr.err_code = 0;
@@ -1550,8 +1554,10 @@
/* send response */
avdt_msg_send_rsp(p_scb->p_ccb, AVDT_SIG_OPEN, &p_data->msg);
- /* start tc connect timer */
- btu_start_timer(&p_scb->timer_entry, BTU_TTYPE_AVDT_SCB_TC, AVDT_SCB_TC_CONN_TOUT);
+ alarm_set_on_queue(p_scb->transport_channel_timer,
+ AVDT_SCB_TC_CONN_TIMEOUT_MS,
+ avdt_scb_transport_channel_timer_timeout, p_scb,
+ btu_general_alarm_queue);
}
/*******************************************************************************
@@ -2045,7 +2051,7 @@
/*******************************************************************************
**
-** Function avdt_scb_tc_timer
+** Function avdt_scb_transport_channel_timer
**
** Description This function is called to start a timer when the peer
** initiates closing of the stream. The timer verifies that
@@ -2054,11 +2060,14 @@
** Returns Nothing.
**
*******************************************************************************/
-void avdt_scb_tc_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
+void avdt_scb_transport_channel_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
{
UNUSED(p_data);
- btu_start_timer(&p_scb->timer_entry, BTU_TTYPE_AVDT_SCB_TC, AVDT_SCB_TC_DISC_TOUT);
+ alarm_set_on_queue(p_scb->transport_channel_timer,
+ AVDT_SCB_TC_DISC_TIMEOUT_MS,
+ avdt_scb_transport_channel_timer_timeout, p_scb,
+ btu_general_alarm_queue);
}
/*******************************************************************************
diff --git a/stack/bnep/bnep_api.c b/stack/bnep/bnep_api.c
index d0009c6..5c4e0e5 100644
--- a/stack/bnep/bnep_api.c
+++ b/stack/bnep/bnep_api.c
@@ -26,6 +26,9 @@
#include "bnep_api.h"
#include "bnep_int.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function BNEP_Init
@@ -45,9 +48,6 @@
#else
bnep_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
#endif
-
- /* Start a timer to read our BD address */
- btu_start_timer(&bnep_cb.bnep_te, BTU_TTYPE_BNEP, 2);
}
@@ -208,7 +208,9 @@
}
/* Start timer waiting for connect */
- btu_start_timer(&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
*p_handle = p_bcb->handle;
diff --git a/stack/bnep/bnep_int.h b/stack/bnep/bnep_int.h
index 25ca170..126be04 100644
--- a/stack/bnep/bnep_int.h
+++ b/stack/bnep/bnep_int.h
@@ -80,9 +80,9 @@
/* Timeout definitions.
*/
-#define BNEP_CONN_TIMEOUT 20 /* Connection related timeout */
-#define BNEP_HOST_TIMEOUT 200 /* host responce timeout */
-#define BNEP_FILTER_SET_TIMEOUT 10
+#define BNEP_CONN_TIMEOUT_MS (20 * 1000) /* Connection related timeout */
+#define BNEP_HOST_TIMEOUT_MS (200 * 1000) /* host responce timeout */
+#define BNEP_FILTER_SET_TIMEOUT_MS (10 * 1000)
/* Define the Out-Flow default values. */
#define BNEP_OFLOW_QOS_FLAG 0
@@ -133,7 +133,7 @@
UINT16 l2cap_cid;
BD_ADDR rem_bda;
UINT16 rem_mtu_size;
- timer_entry_t conn_te;
+ alarm_t *conn_timer;
fixed_queue_t *xmit_q;
UINT16 sent_num_filters;
@@ -180,7 +180,6 @@
tL2CAP_APPL_INFO reg_info;
- timer_entry_t bnep_te;
BOOLEAN profile_registered; /* TRUE when we got our BD addr */
UINT8 trace_level;
@@ -204,7 +203,7 @@
extern tBNEP_RESULT bnep_register_with_l2cap (void);
extern void bnep_disconnect (tBNEP_CONN *p_bcb, UINT16 reason);
extern tBNEP_CONN *bnep_conn_originate (UINT8 *p_bd_addr);
-extern void bnep_process_timeout(timer_entry_t *p_te);
+extern void bnep_conn_timer_timeout(void *data);
extern void bnep_connected (tBNEP_CONN *p_bcb);
diff --git a/stack/bnep/bnep_main.c b/stack/bnep/bnep_main.c
index 15eff46..16e6d92 100644
--- a/stack/bnep/bnep_main.c
+++ b/stack/bnep/bnep_main.c
@@ -46,6 +46,8 @@
#include "device/include/controller.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* G L O B A L B N E P D A T A */
/********************************************************************************/
@@ -145,7 +147,9 @@
L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
/* Start timer waiting for config setup */
- btu_start_timer(&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
BNEP_TRACE_EVENT("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid);
@@ -165,10 +169,10 @@
*******************************************************************************/
static void bnep_connect_cfm (UINT16 l2cap_cid, UINT16 result)
{
- tBNEP_CONN *bcb;
+ tBNEP_CONN *p_bcb;
/* Find CCB based on CID */
- if ((bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
+ if ((p_bcb = bnepu_find_bcb_by_cid (l2cap_cid)) == NULL)
{
BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid);
return;
@@ -176,30 +180,32 @@
/* If the connection response contains success status, then */
/* Transition to the next state and startup the timer. */
- if ((result == L2CAP_CONN_OK) && (bcb->con_state == BNEP_STATE_CONN_START))
+ if ((result == L2CAP_CONN_OK) && (p_bcb->con_state == BNEP_STATE_CONN_START))
{
- bcb->con_state = BNEP_STATE_CFG_SETUP;
+ p_bcb->con_state = BNEP_STATE_CFG_SETUP;
/* Send a Configuration Request. */
L2CA_ConfigReq (l2cap_cid, &bnep_cb.l2cap_my_cfg);
/* Start timer waiting for config results */
- btu_start_timer (&bcb->conn_te, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
- BNEP_TRACE_EVENT ("BNEP - got conn cnf, sent cfg req, CID: 0x%x", bcb->l2cap_cid);
+ BNEP_TRACE_EVENT ("BNEP - got conn cnf, sent cfg req, CID: 0x%x", p_bcb->l2cap_cid);
}
else
{
- BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, bcb->l2cap_cid);
+ BNEP_TRACE_WARNING ("BNEP - Rcvd conn cnf with error: 0x%x CID 0x%x", result, p_bcb->l2cap_cid);
/* Tell the upper layer, if he has a callback */
if (bnep_cb.p_conn_state_cb &&
- bcb->con_flags & BNEP_FLAGS_IS_ORIG)
+ p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
{
- (*bnep_cb.p_conn_state_cb) (bcb->handle, bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
+ (*bnep_cb.p_conn_state_cb) (p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, FALSE);
}
- bnepu_release_bcb (bcb);
+ bnepu_release_bcb (p_bcb);
}
}
@@ -264,7 +270,9 @@
p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
/* Start timer waiting for setup or response */
- btu_start_timer (&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_HOST_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
{
@@ -310,7 +318,9 @@
p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
/* Start timer waiting for setup or response */
- btu_start_timer (&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_HOST_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_HOST_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
if (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)
{
@@ -661,7 +671,7 @@
/*******************************************************************************
**
-** Function bnep_process_timeout
+** Function bnep_conn_timer_timeout
**
** Description This function processes a timeout. If it is a startup
** timeout, we check for reading our BD address. If it
@@ -670,16 +680,9 @@
** Returns void
**
*******************************************************************************/
-void bnep_process_timeout(timer_entry_t *p_te)
+void bnep_conn_timer_timeout(void *data)
{
- tBNEP_CONN *p_bcb;
-
- if (!p_te->param)
- {
- return;
- }
-
- p_bcb = (tBNEP_CONN *)p_te->param;
+ tBNEP_CONN *p_bcb = (tBNEP_CONN *)data;
BNEP_TRACE_EVENT ("BNEP - CCB timeout in state: %d CID: 0x%x flags %x, re_transmit %d",
p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags, p_bcb->re_transmits);
@@ -700,7 +703,9 @@
if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
{
bnep_send_conn_req (p_bcb);
- btu_start_timer (&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
else
{
@@ -731,7 +736,9 @@
if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
{
bnepu_send_peer_our_filters (p_bcb);
- btu_start_timer (&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
else
{
@@ -750,7 +757,9 @@
if (p_bcb->re_transmits++ != BNEP_MAX_RETRANSMITS)
{
bnepu_send_peer_our_multi_filters (p_bcb);
- btu_start_timer (&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
else
{
@@ -791,7 +800,7 @@
p_bcb->con_flags &= (~BNEP_FLAGS_SETUP_RCVD);
/* Ensure timer is stopped */
- btu_stop_timer(&p_bcb->conn_te);
+ alarm_cancel(p_bcb->conn_timer);
p_bcb->re_transmits = 0;
/* Tell the upper layer, if he has a callback */
diff --git a/stack/bnep/bnep_utils.c b/stack/bnep/bnep_utils.c
index 41c582f..0aa7671 100644
--- a/stack/bnep/bnep_utils.c
+++ b/stack/bnep/bnep_utils.c
@@ -33,6 +33,8 @@
#include "device/include/controller.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* L O C A L F U N C T I O N P R O T O T Y P E S */
/********************************************************************************/
@@ -118,9 +120,9 @@
{
if (p_bcb->con_state == BNEP_STATE_IDLE)
{
+ alarm_free(p_bcb->conn_timer);
memset ((UINT8 *)p_bcb, 0, sizeof (tBNEP_CONN));
-
- p_bcb->conn_te.param = p_bcb;
+ p_bcb->conn_timer = alarm_new("bnep.conn_timer");
memcpy ((UINT8 *)(p_bcb->rem_bda), (UINT8 *)p_rem_bda, BD_ADDR_LEN);
p_bcb->handle = xx + 1;
@@ -147,7 +149,8 @@
void bnepu_release_bcb (tBNEP_CONN *p_bcb)
{
/* Ensure timer is stopped */
- btu_stop_timer(&p_bcb->conn_te);
+ alarm_free(p_bcb->conn_timer);
+ p_bcb->conn_timer = NULL;
/* Drop any response pointer we may be holding */
p_bcb->con_state = BNEP_STATE_IDLE;
@@ -310,7 +313,9 @@
p_bcb->con_flags |= BNEP_FLAGS_FILTER_RESP_PEND;
/* Start timer waiting for setup response */
- btu_start_timer(&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
@@ -362,7 +367,9 @@
p_bcb->con_flags |= BNEP_FLAGS_MULTI_RESP_PEND;
/* Start timer waiting for setup response */
- btu_start_timer(&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_FILTER_SET_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
}
@@ -744,7 +751,7 @@
memcpy ((UINT8 *)&(p_bcb->dst_uuid), (UINT8 *)&(p_bcb->prv_dst_uuid), sizeof (tBT_UUID));
/* Ensure timer is stopped */
- btu_stop_timer(&p_bcb->conn_te);
+ alarm_cancel(p_bcb->conn_timer);
p_bcb->re_transmits = 0;
/* Tell the user if he has a callback */
@@ -1001,7 +1008,7 @@
}
/* Ensure timer is stopped */
- btu_stop_timer(&p_bcb->conn_te);
+ alarm_cancel(p_bcb->conn_timer);
p_bcb->con_flags &= ~BNEP_FLAGS_FILTER_RESP_PEND;
p_bcb->re_transmits = 0;
@@ -1047,7 +1054,7 @@
}
/* Ensure timer is stopped */
- btu_stop_timer(&p_bcb->conn_te);
+ alarm_cancel(p_bcb->conn_timer);
p_bcb->con_flags &= ~BNEP_FLAGS_MULTI_RESP_PEND;
p_bcb->re_transmits = 0;
@@ -1245,7 +1252,9 @@
p_bcb->con_state = BNEP_STATE_CONN_SETUP;
bnep_send_conn_req (p_bcb);
- btu_start_timer(&p_bcb->conn_te, BTU_TTYPE_BNEP, BNEP_CONN_TIMEOUT);
+ alarm_set_on_queue(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
+ bnep_conn_timer_timeout, p_bcb,
+ btu_general_alarm_queue);
return;
}
diff --git a/stack/btm/btm_acl.c b/stack/btm/btm_acl.c
index 342185b..ef96e1d 100644
--- a/stack/btm/btm_acl.c
+++ b/stack/btm/btm_acl.c
@@ -48,11 +48,15 @@
#include "hcidefs.h"
#include "bt_utils.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
static void btm_read_remote_features (UINT16 handle);
static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number);
static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages);
-#define BTM_DEV_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */
+/* 3 seconds timeout waiting for responses */
+#define BTM_DEV_REPLY_TIMEOUT_MS (3 * 1000)
/*******************************************************************************
**
@@ -1873,20 +1877,23 @@
bd[3], bd[4], bd[5]);
/* If someone already waiting on the version, do not allow another */
- if (btm_cb.devcb.p_qossu_cmpl_cb)
+ if (btm_cb.devcb.p_qos_setup_cmpl_cb)
return(BTM_BUSY);
if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL)
{
- btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
- btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
+ btm_cb.devcb.p_qos_setup_cmpl_cb = p_cb;
+ alarm_set_on_queue(btm_cb.devcb.qos_setup_timer,
+ BTM_DEV_REPLY_TIMEOUT_MS,
+ btm_qos_setup_timeout, NULL,
+ btu_general_alarm_queue);
if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
p_flow->token_rate, p_flow->peak_bandwidth,
p_flow->latency,p_flow->delay_variation))
{
- btm_cb.devcb.p_qossu_cmpl_cb = NULL;
- btu_stop_timer(&btm_cb.devcb.qossu_timer);
+ btm_cb.devcb.p_qos_setup_cmpl_cb = NULL;
+ alarm_cancel(btm_cb.devcb.qos_setup_timer);
return(BTM_NO_RESOURCES);
}
else
@@ -1899,6 +1906,23 @@
/*******************************************************************************
**
+** Function btm_qos_setup_timeout
+**
+** Description Callback when QoS setup times out.
+**
+** Returns void
+**
+*******************************************************************************/
+void btm_qos_setup_timeout(UNUSED_ATTR void *data)
+{
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb;
+ btm_cb.devcb.p_qos_setup_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
+}
+
+/*******************************************************************************
+**
** Function btm_qos_setup_complete
**
** Description This function is called when the command complete message
@@ -1907,15 +1931,16 @@
** Returns void
**
*******************************************************************************/
-void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
+void btm_qos_setup_complete(UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
{
- tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb;
tBTM_QOS_SETUP_CMPL qossu;
- BTM_TRACE_DEBUG ("btm_qos_setup_complete");
- btu_stop_timer (&btm_cb.devcb.qossu_timer);
- btm_cb.devcb.p_qossu_cmpl_cb = NULL;
+ BTM_TRACE_DEBUG("%s", __func__);
+ alarm_cancel(btm_cb.devcb.qos_setup_timer);
+ btm_cb.devcb.p_qos_setup_cmpl_cb = NULL;
+ /* If there was a registered callback, call it */
if (p_cb)
{
memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
@@ -1936,7 +1961,6 @@
}
}
-
/*******************************************************************************
**
** Function BTM_ReadRSSI
@@ -1973,15 +1997,15 @@
p = btm_bda_to_acl(remote_bda, transport);
if (p != (tACL_CONN *)NULL)
{
- btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
- BTM_DEV_REPLY_TIMEOUT);
-
btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
+ alarm_set_on_queue(btm_cb.devcb.read_rssi_timer,
+ BTM_DEV_REPLY_TIMEOUT_MS, btm_read_rssi_timeout,
+ NULL, btu_general_alarm_queue);
if (!btsnd_hcic_read_rssi (p->hci_handle))
{
btm_cb.devcb.p_rssi_cmpl_cb = NULL;
- btu_stop_timer (&btm_cb.devcb.rssi_timer);
+ alarm_cancel(btm_cb.devcb.read_rssi_timer);
return(BTM_NO_RESOURCES);
}
else
@@ -2012,20 +2036,22 @@
remote_bda[3], remote_bda[4], remote_bda[5]);
/* If someone already waiting on the version, do not allow another */
- if (btm_cb.devcb.p_lnk_qual_cmpl_cb)
+ if (btm_cb.devcb.p_link_qual_cmpl_cb)
return(BTM_BUSY);
p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
if (p != (tACL_CONN *)NULL)
{
- btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
- BTM_DEV_REPLY_TIMEOUT);
- btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
+ btm_cb.devcb.p_link_qual_cmpl_cb = p_cb;
+ alarm_set_on_queue(btm_cb.devcb.read_link_quality_timer,
+ BTM_DEV_REPLY_TIMEOUT_MS,
+ btm_read_link_quality_timeout, NULL,
+ btu_general_alarm_queue);
if (!btsnd_hcic_get_link_quality (p->hci_handle))
{
- btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
- btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
+ btm_cb.devcb.p_link_qual_cmpl_cb = NULL;
+ alarm_cancel(btm_cb.devcb.read_link_quality_timer);
return(BTM_NO_RESOURCES);
}
else
@@ -2066,10 +2092,11 @@
p = btm_bda_to_acl(remote_bda, transport);
if (p != (tACL_CONN *)NULL)
{
- btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
- BTM_DEV_REPLY_TIMEOUT);
-
btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
+ alarm_set_on_queue(btm_cb.devcb.read_tx_power_timer,
+ BTM_DEV_REPLY_TIMEOUT_MS,
+ btm_read_tx_power_timeout, NULL,
+ btu_general_alarm_queue);
#if BLE_INCLUDED == TRUE
if (p->transport == BT_TRANSPORT_LE)
@@ -2085,7 +2112,7 @@
if (!ret)
{
btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
- btu_stop_timer (&btm_cb.devcb.tx_power_timer);
+ alarm_cancel(btm_cb.devcb.read_tx_power_timer);
return(BTM_NO_RESOURCES);
}
else
@@ -2095,6 +2122,24 @@
/* If here, no BD Addr found */
return (BTM_UNKNOWN_ADDR);
}
+
+/*******************************************************************************
+**
+** Function btm_read_tx_power_timeout
+**
+** Description Callback when reading the tx power times out.
+**
+** Returns void
+**
+*******************************************************************************/
+void btm_read_tx_power_timeout(UNUSED_ATTR void *data)
+{
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
+ btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
+}
+
/*******************************************************************************
**
** Function btm_read_tx_power_complete
@@ -2105,19 +2150,19 @@
** Returns void
**
*******************************************************************************/
-void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
+void btm_read_tx_power_complete(UINT8 *p, BOOLEAN is_ble)
{
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
tBTM_TX_POWER_RESULTS results;
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
- BTM_TRACE_DEBUG ("btm_read_tx_power_complete");
- btu_stop_timer (&btm_cb.devcb.tx_power_timer);
- /* If there was a callback registered for read rssi, call it */
+ BTM_TRACE_DEBUG("%s", __func__);
+ alarm_cancel(btm_cb.devcb.read_tx_power_timer);
btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
+ /* If there was a registered callback, call it */
if (p_cb)
{
STREAM_TO_UINT8 (results.hci_status, p);
@@ -2160,6 +2205,23 @@
/*******************************************************************************
**
+** Function btm_read_rssi_timeout
+**
+** Description Callback when reading the RSSI times out.
+**
+** Returns void
+**
+*******************************************************************************/
+void btm_read_rssi_timeout(UNUSED_ATTR void *data)
+{
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
+ btm_cb.devcb.p_rssi_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
+}
+
+/*******************************************************************************
+**
** Function btm_read_rssi_complete
**
** Description This function is called when the command complete message
@@ -2175,12 +2237,12 @@
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
- BTM_TRACE_DEBUG ("btm_read_rssi_complete");
- btu_stop_timer (&btm_cb.devcb.rssi_timer);
- /* If there was a callback registered for read rssi, call it */
+ BTM_TRACE_DEBUG("%s", __func__);
+ alarm_cancel(btm_cb.devcb.read_rssi_timer);
btm_cb.devcb.p_rssi_cmpl_cb = NULL;
+ /* If there was a registered callback, call it */
if (p_cb)
{
STREAM_TO_UINT8 (results.hci_status, p);
@@ -2214,6 +2276,23 @@
/*******************************************************************************
**
+** Function btm_read_link_quality_timeout
+**
+** Description Callback when reading the link quality times out.
+**
+** Returns void
+**
+*******************************************************************************/
+void btm_read_link_quality_timeout(UNUSED_ATTR void *data)
+{
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb;
+ btm_cb.devcb.p_link_qual_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
+}
+
+/*******************************************************************************
+**
** Function btm_read_link_quality_complete
**
** Description This function is called when the command complete message
@@ -2222,19 +2301,19 @@
** Returns void
**
*******************************************************************************/
-void btm_read_link_quality_complete (UINT8 *p)
+void btm_read_link_quality_complete(UINT8 *p)
{
- tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb;
tBTM_LINK_QUALITY_RESULTS results;
UINT16 handle;
tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
UINT16 index;
- BTM_TRACE_DEBUG ("btm_read_link_quality_complete");
- btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
- /* If there was a callback registered for read rssi, call it */
- btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
+ BTM_TRACE_DEBUG("%s", __func__);
+ alarm_cancel(btm_cb.devcb.read_link_quality_timer);
+ btm_cb.devcb.p_link_qual_cmpl_cb = NULL;
+ /* If there was a registered callback, call it */
if (p_cb)
{
STREAM_TO_UINT8 (results.hci_status, p);
diff --git a/stack/btm/btm_ble_addr.c b/stack/btm/btm_ble_addr.c
index 96fb050..8866f76 100644
--- a/stack/btm/btm_ble_addr.c
+++ b/stack/btm/btm_ble_addr.c
@@ -36,6 +36,8 @@
#include "smp_api.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function btm_gen_resolve_paddr_cmpl
@@ -63,14 +65,13 @@
p_cb->own_addr_type = BLE_ADDR_RANDOM;
/* start a periodical timer to refresh random addr */
- btu_stop_timer_oneshot(&p_cb->raddr_timer_ent);
+ period_ms_t interval_ms = BTM_BLE_PRIVATE_ADDR_INT_MS;
#if (BTM_BLE_CONFORMANCE_TESTING == TRUE)
- btu_start_timer_oneshot(&p_cb->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
- btm_cb.ble_ctr_cb.rpa_tout);
-#else
- btu_start_timer_oneshot(&p_cb->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
- BTM_BLE_PRIVATE_ADDR_INT);
+ interval_ms = btm_cb.ble_ctr_cb.rpa_tout * 1000;
#endif
+ alarm_set_on_queue(p_cb->refresh_raddr_timer, interval_ms,
+ btm_ble_refresh_raddr_timer_timeout, NULL,
+ btu_general_alarm_queue);
}
else
{
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 4fe2afa..1403d46 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -51,10 +51,13 @@
#define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff
#define BTM_BLE_POLICY_UNKNOWN 0xff
-#define BTM_EXT_BLE_RMT_NAME_TIMEOUT 30
+#define BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS (30 * 1000)
#define MIN_ADV_LENGTH 2
#define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
#if BLE_VND_INCLUDED == TRUE
@@ -73,6 +76,12 @@
tBLE_ADDR_TYPE *p_peer_addr_type,
tBLE_ADDR_TYPE *p_own_addr_type);
static void btm_ble_stop_observe(void);
+static void btm_ble_fast_adv_timer_timeout(void *data);
+static void btm_ble_start_slow_adv(void);
+static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(void *data);
+static void btm_ble_inquiry_timer_timeout(void *data);
+static void btm_ble_observer_timer_timeout(void *data);
+
#define BTM_BLE_INQ_RESULT 0x01
#define BTM_BLE_OBS_RESULT 0x02
@@ -402,9 +411,13 @@
if (status == BTM_CMD_STARTED)
{
btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE;
- if (duration != 0)
+ if (duration != 0) {
/* start observer timer */
- btu_start_timer (&btm_cb.ble_ctr_cb.obs_timer_ent, BTU_TTYPE_BLE_OBSERVE, duration);
+ period_ms_t duration_ms = duration * 1000;
+ alarm_set_on_queue(btm_cb.ble_ctr_cb.observer_timer,
+ duration_ms, btm_ble_observer_timer_timeout,
+ NULL, btu_general_alarm_queue);
+ }
}
}
else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
@@ -1755,7 +1768,7 @@
btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max);
- btu_stop_timer(&p_cb->fast_adv_timer);
+ alarm_cancel(p_cb->fast_adv_timer);
/* update adv params if start advertising */
BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type);
@@ -1801,8 +1814,10 @@
{
p_cb->fast_adv_on = TRUE;
/* start initial GAP mode adv timer */
- btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV,
- BTM_BLE_GAP_FAST_ADV_TOUT);
+ alarm_set_on_queue(p_cb->fast_adv_timer,
+ BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS,
+ btm_ble_fast_adv_timer_timeout, NULL,
+ btu_general_alarm_queue);
}
else
{
@@ -1814,10 +1829,12 @@
/* set up stop advertising timer */
if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE)
{
- BTM_TRACE_EVENT ("start timer for limited disc mode duration=%d (180 secs)", BTM_BLE_GAP_LIM_TOUT);
+ BTM_TRACE_EVENT("start timer for limited disc mode duration=%d ms",
+ BTM_BLE_GAP_LIM_TIMEOUT_MS);
/* start Tgap(lim_timeout) */
- btu_start_timer (&p_cb->inq_timer_ent, BTU_TTYPE_BLE_GAP_LIM_DISC,
- BTM_BLE_GAP_LIM_TOUT);
+ alarm_set_on_queue(p_cb->inquiry_timer, BTM_BLE_GAP_LIM_TIMEOUT_MS,
+ btm_ble_inquiry_timer_gap_limited_discovery_timeout,
+ NULL, btu_general_alarm_queue);
}
return status;
}
@@ -1861,7 +1878,7 @@
btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max);
- btu_stop_timer(&p_cb->fast_adv_timer);
+ alarm_cancel(p_cb->fast_adv_timer);
/* update adv params if needed */
if (new_mode == BTM_BLE_ADV_ENABLE)
{
@@ -1903,8 +1920,10 @@
{
p_cb->fast_adv_on = TRUE;
/* start initial GAP mode adv timer */
- btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV,
- BTM_BLE_GAP_FAST_ADV_TOUT);
+ alarm_set_on_queue(p_cb->fast_adv_timer,
+ BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS,
+ btm_ble_fast_adv_timer_timeout, NULL,
+ btu_general_alarm_queue);
}
else
{
@@ -1983,10 +2002,12 @@
BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", p_inq->inq_active);
- if (duration != 0)
- {
+ if (duration != 0) {
/* start inquiry timer */
- btu_start_timer (&p_ble_cb->inq_var.inq_timer_ent, BTU_TTYPE_BLE_INQUIRY, duration);
+ period_ms_t duration_ms = duration * 1000;
+ alarm_set_on_queue(p_ble_cb->inq_var.inquiry_timer,
+ duration_ms, btm_ble_inquiry_timer_timeout,
+ NULL, btu_general_alarm_queue);
}
}
@@ -2063,9 +2084,10 @@
memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN);
- btu_start_timer (&p_inq->rmt_name_timer_ent,
- BTU_TTYPE_BTM_RMT_NAME,
- BTM_EXT_BLE_RMT_NAME_TIMEOUT);
+ alarm_set_on_queue(p_inq->remote_name_timer,
+ BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS,
+ btm_inq_remote_name_timer_timeout, NULL,
+ btu_general_alarm_queue);
return BTM_CMD_STARTED;
}
@@ -2090,7 +2112,7 @@
p_inq->remname_active = FALSE;
memset(p_inq->remname_bda, 0, BD_ADDR_LEN);
- btu_stop_timer(&p_inq->rmt_name_timer_ent);
+ alarm_cancel(p_inq->remote_name_timer);
return status;
}
@@ -2911,7 +2933,7 @@
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb;
- btu_stop_timer (&p_ble_cb->inq_var.inq_timer_ent);
+ alarm_cancel(p_ble_cb->inq_var.inquiry_timer);
p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK;
@@ -2947,7 +2969,7 @@
tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb;
tBTM_CMPL_CB *p_obs_cb = p_ble_cb->p_obs_cmpl_cb;
- btu_stop_timer (&p_ble_cb->obs_timer_ent);
+ alarm_cancel(p_ble_cb->observer_timer);
p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE;
@@ -3078,6 +3100,12 @@
return rt;
}
+static void btm_ble_fast_adv_timer_timeout(UNUSED_ATTR void *data)
+{
+ /* fast adv is completed, fall back to slow adv interval */
+ btm_ble_start_slow_adv();
+}
+
/*******************************************************************************
**
** Function btm_ble_start_slow_adv
@@ -3087,7 +3115,7 @@
** Returns void
**
*******************************************************************************/
-static void btm_ble_start_slow_adv (void)
+static void btm_ble_start_slow_adv(void)
{
tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
@@ -3112,59 +3140,38 @@
btm_ble_start_adv();
}
}
-/*******************************************************************************
-**
-** Function btm_ble_timeout
-**
-** Description Called when BTM BLE inquiry timer expires
-**
-** Returns void
-**
-*******************************************************************************/
-void btm_ble_timeout(timer_entry_t *p_te)
+
+static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(UNUSED_ATTR void *data)
{
- BTM_TRACE_EVENT ("btm_ble_timeout");
+ /* lim_timeout expired, limited discovery should exit now */
+ btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE;
+ btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode,
+ btm_cb.btm_inq_vars.discoverable_mode);
+}
- switch (p_te->event)
- {
- case BTU_TTYPE_BLE_OBSERVE:
- btm_ble_stop_observe();
- break;
+static void btm_ble_inquiry_timer_timeout(UNUSED_ATTR void *data)
+{
+ btm_ble_stop_inquiry();
+}
- case BTU_TTYPE_BLE_INQUIRY:
- btm_ble_stop_inquiry();
- break;
+static void btm_ble_observer_timer_timeout(UNUSED_ATTR void *data)
+{
+ btm_ble_stop_observe();
+}
- case BTU_TTYPE_BLE_GAP_LIM_DISC:
- /* lim_timeout expiried, limited discovery should exit now */
- btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE;
- btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, btm_cb.btm_inq_vars.discoverable_mode);
- break;
+void btm_ble_adv_raddr_timer_timeout(void *data)
+{
+ if ((btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) &&
+ (BTM_BleMaxMultiAdvInstanceCount() > 0)) {
+ btm_ble_multi_adv_configure_rpa((tBTM_BLE_MULTI_ADV_INST *)data);
+ }
+}
- case BTU_TTYPE_BLE_RANDOM_ADDR:
- if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM)
- {
- if (NULL == (void *)(p_te->param))
- {
- /* refresh the random addr */
- btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low);
- }
- else
- {
- if (BTM_BleMaxMultiAdvInstanceCount() > 0)
- btm_ble_multi_adv_configure_rpa((tBTM_BLE_MULTI_ADV_INST*)p_te->param);
- }
- }
- break;
-
- case BTU_TTYPE_BLE_GAP_FAST_ADV:
- /* fast adv is completed, fall back to slow adv interval */
- btm_ble_start_slow_adv();
- break;
-
- default:
- break;
-
+void btm_ble_refresh_raddr_timer_timeout(UNUSED_ATTR void *data)
+{
+ if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) {
+ /* refresh the random addr */
+ btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low);
}
}
@@ -3360,15 +3367,19 @@
** Returns void
**
*******************************************************************************/
-void btm_ble_init (void)
+void btm_ble_init(void)
{
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
BTM_TRACE_DEBUG("%s", __func__);
+ alarm_free(p_cb->observer_timer);
+ alarm_free(p_cb->inq_var.fast_adv_timer);
memset(p_cb, 0, sizeof(tBTM_BLE_CB));
memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB));
btm_cb.cmn_ble_vsc_cb.values_read = FALSE;
+
+ p_cb->observer_timer = alarm_new("btm_ble.observer_timer");
p_cb->cur_states = 0;
p_cb->conn_pending_q = fixed_queue_new(SIZE_MAX);
@@ -3379,12 +3390,17 @@
p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP;
p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE;
p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE;
+ p_cb->inq_var.fast_adv_timer = alarm_new("btm_ble_inq.fast_adv_timer");
+ p_cb->inq_var.inquiry_timer = alarm_new("btm_ble_inq.inquiry_timer");
/* for background connection, reset connection params to be undefined */
p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF;
p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT;
+ p_cb->addr_mgnt_cb.refresh_raddr_timer =
+ alarm_new("btm_ble_addr.refresh_raddr_timer");
+
#if BLE_VND_INCLUDED == FALSE
btm_ble_adv_filter_init();
#endif
diff --git a/stack/btm/btm_ble_int.h b/stack/btm/btm_ble_int.h
index 5d143a4..07ec077 100644
--- a/stack/btm/btm_ble_int.h
+++ b/stack/btm/btm_ble_int.h
@@ -61,7 +61,7 @@
#define BTM_BLE_GAP_DISC_SCAN_INT 18 /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms */
#define BTM_BLE_GAP_DISC_SCAN_WIN 18 /* scan_window = 11.25 ms= 0x0010 * 0.625 ms */
#define BTM_BLE_GAP_ADV_INT 512 /* Tgap(gen_disc) = 1.28 s= 512 * 0.625 ms */
-#define BTM_BLE_GAP_LIM_TOUT 180 /* Tgap(lim_timeout) = 180s max */
+#define BTM_BLE_GAP_LIM_TIMEOUT_MS (180 * 1000) /* Tgap(lim_timeout) = 180s max */
#define BTM_BLE_LOW_LATENCY_SCAN_INT 8000 /* Interval(scan_int) = 5s= 8000 * 0.625 ms */
#define BTM_BLE_LOW_LATENCY_SCAN_WIN 8000 /* scan_window = 5s= 8000 * 0.625 ms */
@@ -72,7 +72,7 @@
#define BTM_BLE_GAP_ADV_DIR_MAX_INT 800 /* Tgap(dir_conn_adv_int_max) = 500 ms = 800 * 0.625 ms */
#define BTM_BLE_GAP_ADV_DIR_MIN_INT 400 /* Tgap(dir_conn_adv_int_min) = 250 ms = 400 * 0.625 ms */
-#define BTM_BLE_GAP_FAST_ADV_TOUT 30
+#define BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS (30 * 1000)
#define BTM_BLE_SEC_REQ_ACT_NONE 0
#define BTM_BLE_SEC_REQ_ACT_ENCRYPT 1 /* encrypt the link using current key or key refresh */
@@ -124,7 +124,8 @@
#define BTM_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF))
-#define BTM_BLE_PRIVATE_ADDR_INT 900 /* 15 minutes minimum for random address refreshing */
+/* 15 minutes minimum for random address refreshing */
+#define BTM_BLE_PRIVATE_ADDR_INT_MS (15 * 60 * 1000)
typedef struct
{
@@ -145,7 +146,7 @@
tBLE_BD_ADDR direct_bda;
tBTM_BLE_EVT directed_conn;
BOOLEAN fast_adv_on;
- timer_entry_t fast_adv_timer;
+ alarm_t *fast_adv_timer;
UINT8 adv_len;
UINT8 adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX];
@@ -156,7 +157,7 @@
tBTM_BLE_LOCAL_ADV_DATA adv_data;
tBTM_BLE_ADV_CHNL_MAP adv_chnl_map;
- timer_entry_t inq_timer_ent;
+ alarm_t *inquiry_timer;
BOOLEAN scan_rsp;
UINT8 state; /* Current state that the inquiry process is in */
INT8 tx_power;
@@ -179,7 +180,7 @@
tBTM_BLE_RESOLVE_CBACK *p_resolve_cback;
tBTM_BLE_ADDR_CBACK *p_generate_cback;
void *p;
- timer_entry_t raddr_timer_ent;
+ alarm_t *refresh_raddr_timer;
} tBTM_LE_RANDOM_CB;
#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10
@@ -304,7 +305,7 @@
/* observer callback and timer */
tBTM_INQ_RESULTS_CB *p_obs_results_cb;
tBTM_CMPL_CB *p_obs_cmpl_cb;
- timer_entry_t obs_timer_ent;
+ alarm_t *observer_timer;
/* background connection procedure cb value */
tBTM_BLE_CONN_TYPE bg_conn_type;
@@ -345,7 +346,8 @@
extern "C" {
#endif
-extern void btm_ble_timeout(timer_entry_t *p_te);
+extern void btm_ble_adv_raddr_timer_timeout(void *data);
+extern void btm_ble_refresh_raddr_timer_timeout(void *data);
extern void btm_ble_process_adv_pkt (UINT8 *p);
extern void btm_ble_proc_scan_rsp_rpt (UINT8 *p);
extern tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb);
diff --git a/stack/btm/btm_ble_multi_adv.c b/stack/btm/btm_ble_multi_adv.c
index 2ea2698..3599e8d 100644
--- a/stack/btm/btm_ble_multi_adv.c
+++ b/stack/btm/btm_ble_multi_adv.c
@@ -51,6 +51,7 @@
/************************************************************************************
** Externs
************************************************************************************/
+extern fixed_queue_t *btu_general_alarm_queue;
extern void btm_ble_update_dmt_flag_bits(UINT8 *flag_value,
const UINT16 connect_mode, const UINT16 disc_mode);
@@ -311,12 +312,11 @@
p_inst->adv_evt = p_params->adv_type;
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
- if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE)
- {
- /* start timer */
- p_inst->raddr_timer_ent.param = (timer_param_t)p_inst;
- btu_start_timer_oneshot(&p_inst->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
- BTM_BLE_PRIVATE_ADDR_INT);
+ if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) {
+ alarm_set_on_queue(p_inst->adv_raddr_timer,
+ BTM_BLE_PRIVATE_ADDR_INT_MS,
+ btm_ble_adv_raddr_timer_timeout, p_inst,
+ btu_general_alarm_queue);
}
#endif
btm_ble_multi_adv_enq_op_q(BTM_BLE_MULTI_ADV_SET_PARAM, p_inst->inst_id, cb_evt);
@@ -357,12 +357,13 @@
btm_ble_multi_adv_vsc_cmpl_cback)) == BTM_CMD_STARTED)
{
/* start a periodical timer to refresh random addr */
- btu_stop_timer_oneshot(&p_inst->raddr_timer_ent);
- p_inst->raddr_timer_ent.param = (timer_param_t)p_inst;
- btu_start_timer_oneshot(&p_inst->raddr_timer_ent, BTU_TTYPE_BLE_RANDOM_ADDR,
- BTM_BLE_PRIVATE_ADDR_INT);
-
- btm_ble_multi_adv_enq_op_q(BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR, p_inst->inst_id, 0);
+ /* TODO: is the above comment correct - is the timer periodical? */
+ alarm_set_on_queue(p_inst->adv_raddr_timer,
+ BTM_BLE_PRIVATE_ADDR_INT_MS,
+ btm_ble_adv_raddr_timer_timeout, p_inst,
+ btu_general_alarm_queue);
+ btm_ble_multi_adv_enq_op_q(BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR,
+ p_inst->inst_id, 0);
}
return rt;
}
@@ -520,9 +521,9 @@
{
p_inst->in_use = FALSE;
if (enable)
- btm_ble_multi_adv_configure_rpa (p_inst);
+ btm_ble_multi_adv_configure_rpa(p_inst);
else
- btu_stop_timer_oneshot(&p_inst->raddr_timer_ent);
+ alarm_cancel(p_inst->adv_raddr_timer);
}
}
@@ -734,9 +735,9 @@
if ((rt = btm_ble_enable_multi_adv(FALSE, inst_id, BTM_BLE_MULTI_ADV_DISABLE_EVT))
== BTM_CMD_STARTED)
{
- btm_ble_multi_adv_configure_rpa(&btm_multi_adv_cb.p_adv_inst[inst_id-1]);
- btu_stop_timer_oneshot(&btm_multi_adv_cb.p_adv_inst[inst_id-1].raddr_timer_ent);
- btm_multi_adv_cb.p_adv_inst[inst_id-1].in_use = FALSE;
+ btm_ble_multi_adv_configure_rpa(&btm_multi_adv_cb.p_adv_inst[inst_id - 1]);
+ alarm_cancel(btm_multi_adv_cb.p_adv_inst[inst_id - 1].adv_raddr_timer);
+ btm_multi_adv_cb.p_adv_inst[inst_id - 1].in_use = FALSE;
}
}
return rt;
@@ -838,6 +839,8 @@
for (i = 0; i < btm_cb.cmn_ble_vsc_cb.adv_inst_max; i++) {
btm_multi_adv_cb.p_adv_inst[i].index = i;
btm_multi_adv_cb.p_adv_inst[i].inst_id = i + 1;
+ btm_multi_adv_cb.p_adv_inst[i].adv_raddr_timer =
+ alarm_new("btm_ble.adv_raddr_timer");
}
BTM_RegisterForVSEvents(btm_ble_multi_adv_vse_cback, TRUE);
@@ -855,8 +858,12 @@
*******************************************************************************/
void btm_ble_multi_adv_cleanup(void)
{
- if (btm_multi_adv_cb.p_adv_inst)
+ if (btm_multi_adv_cb.p_adv_inst) {
+ for (size_t i = 0; i < btm_cb.cmn_ble_vsc_cb.adv_inst_max; i++) {
+ alarm_free(btm_multi_adv_cb.p_adv_inst[i].adv_raddr_timer);
+ }
osi_freebuf(btm_multi_adv_cb.p_adv_inst);
+ }
if (btm_multi_adv_cb.op_q.p_sub_code)
osi_freebuf(btm_multi_adv_cb.op_q.p_sub_code);
diff --git a/stack/btm/btm_devctl.c b/stack/btm/btm_devctl.c
index 0df2c12..a636e27 100644
--- a/stack/btm/btm_devctl.c
+++ b/stack/btm/btm_devctl.c
@@ -44,6 +44,7 @@
#include "gatt_int.h"
#endif /* BLE_INCLUDED */
+extern fixed_queue_t *btu_general_alarm_queue;
extern thread_t *bt_workqueue_thread;
/********************************************************************************/
@@ -54,8 +55,8 @@
#define BTM_DEV_RESET_TIMEOUT 4
#endif
-#define BTM_DEV_REPLY_TIMEOUT 2 /* 1 second expiration time is not good. Timer may start between 0 and 1 second. */
- /* if it starts at the very end of the 0 second, timer will expire really easily. */
+// TODO: Reevaluate this value in the context of timers with ms granularity
+#define BTM_DEV_NAME_REPLY_TIMEOUT_MS (2 * 1000) /* 2 seconds for name reply */
#define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */
@@ -85,8 +86,15 @@
memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME));
#endif
- btm_cb.devcb.reset_timer.param = (timer_param_t)TT_DEV_RESET;
- btm_cb.devcb.rln_timer.param = (timer_param_t)TT_DEV_RLN;
+ btm_cb.devcb.read_local_name_timer =
+ alarm_new("btm.read_local_name_timer");
+ btm_cb.devcb.read_rssi_timer = alarm_new("btm.read_rssi_timer");
+ btm_cb.devcb.read_link_quality_timer =
+ alarm_new("btm.read_link_quality_timer");
+ btm_cb.devcb.read_inq_tx_power_timer =
+ alarm_new("btm.read_inq_tx_power_timer");
+ btm_cb.devcb.qos_setup_timer = alarm_new("btm.qos_setup_timer");
+ btm_cb.devcb.read_tx_power_timer = alarm_new("btm.read_tx_power_timer");
btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 +
BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 +
@@ -179,7 +187,7 @@
controller->get_ble_resolving_list_max_size() > 0) {
btm_ble_resolving_list_init(controller->get_ble_resolving_list_max_size());
/* set the default random private address timeout */
- btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT);
+ btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT_MS / 1000);
}
#endif
@@ -229,26 +237,19 @@
/*******************************************************************************
**
-** Function btm_dev_timeout
+** Function btm_read_local_name_timeout
**
-** Description This function is called when a timer entry expires.
+** Description Callback when reading the local name times out.
**
** Returns void
**
*******************************************************************************/
-void btm_dev_timeout (timer_entry_t *p_te)
+void btm_read_local_name_timeout(UNUSED_ATTR void *data)
{
- timer_param_t timer_type = (timer_param_t)p_te->param;
-
- if (timer_type == (timer_param_t)TT_DEV_RLN)
- {
- tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
-
- btm_cb.devcb.p_rln_cmpl_cb = NULL;
-
- if (p_cb)
- (*p_cb)((void *) NULL);
- }
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
+ btm_cb.devcb.p_rln_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
}
/*******************************************************************************
@@ -510,7 +511,10 @@
btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback;
btsnd_hcic_read_name();
- btu_start_timer (&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
+ alarm_set_on_queue(btm_cb.devcb.read_local_name_timer,
+ BTM_DEV_NAME_REPLY_TIMEOUT_MS,
+ btm_read_local_name_timeout, NULL,
+ btu_general_alarm_queue);
return BTM_CMD_STARTED;
}
@@ -531,7 +535,7 @@
UINT8 status;
UNUSED(evt_len);
- btu_stop_timer (&btm_cb.devcb.rln_timer);
+ alarm_cancel(btm_cb.devcb.read_local_name_timer);
/* If there was a callback address for read local name, call it */
btm_cb.devcb.p_rln_cmpl_cb = NULL;
diff --git a/stack/btm/btm_inq.c b/stack/btm/btm_inq.c
index d2f8389..274f1ed 100644
--- a/stack/btm/btm_inq.c
+++ b/stack/btm/btm_inq.c
@@ -41,12 +41,16 @@
#include "btm_int.h"
#include "hcidefs.h"
-#define BTM_INQ_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */
+/* 3 second timeout waiting for responses */
+#define BTM_INQ_REPLY_TIMEOUT_MS (3 * 1000)
/* TRUE to enable DEBUG traces for btm_inq */
#ifndef BTM_INQ_DEBUG
#define BTM_INQ_DEBUG FALSE
#endif
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* L O C A L D A T A D E F I N I T I O N S */
/********************************************************************************/
@@ -1069,7 +1073,7 @@
#endif
return (btm_initiate_rem_name (remote_bda, p_cur, BTM_RMT_NAME_EXT,
- BTM_EXT_RMT_NAME_TIMEOUT, p_cb));
+ BTM_EXT_RMT_NAME_TIMEOUT_MS, p_cb));
}
/*******************************************************************************
@@ -1244,18 +1248,19 @@
*******************************************************************************/
tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb)
{
- if (btm_cb.devcb.p_txpwer_cmpl_cb)
+ if (btm_cb.devcb.p_inq_tx_power_cmpl_cb)
return (BTM_BUSY);
- btu_start_timer (&btm_cb.devcb.txpwer_timer, BTU_TTYPE_BTM_ACL, BTM_INQ_REPLY_TIMEOUT );
-
-
- btm_cb.devcb.p_txpwer_cmpl_cb = p_cb;
+ btm_cb.devcb.p_inq_tx_power_cmpl_cb = p_cb;
+ alarm_set_on_queue(btm_cb.devcb.read_inq_tx_power_timer,
+ BTM_INQ_REPLY_TIMEOUT_MS,
+ btm_read_inq_tx_power_timeout, NULL,
+ btu_general_alarm_queue);
if (!btsnd_hcic_read_inq_tx_power ())
{
- btm_cb.devcb.p_txpwer_cmpl_cb = NULL;
- btu_stop_timer (&btm_cb.devcb.txpwer_timer);
+ btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL;
+ alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer);
return (BTM_NO_RESOURCES);
}
else
@@ -1287,8 +1292,6 @@
UINT8 temp_inq_active;
tBTM_STATUS status;
- btu_stop_timer (&p_inq->inq_timer_ent);
-
/* If an inquiry or periodic inquiry is active, reset the mode to inactive */
if (p_inq->inq_active != BTM_INQUIRY_INACTIVE)
{
@@ -1311,7 +1314,7 @@
/* Cancel a remote name request if active, and notify the caller (if waiting) */
if (p_inq->remname_active )
{
- btu_stop_timer (&p_inq->rmt_name_timer_ent);
+ alarm_cancel(p_inq->remote_name_timer);
p_inq->remname_active = FALSE;
memset(p_inq->remname_bda, 0, BD_ADDR_LEN);
@@ -1370,6 +1373,9 @@
#if 0 /* cleared in btm_init; put back in if called from anywhere else! */
memset (&btm_cb.btm_inq_vars, 0, sizeof (tBTM_INQUIRY_VAR_ST));
#endif
+ alarm_free(btm_cb.btm_inq_vars.remote_name_timer);
+ btm_cb.btm_inq_vars.remote_name_timer =
+ alarm_new("btm_inq.remote_name_timer");
btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
}
@@ -2245,7 +2251,8 @@
**
*******************************************************************************/
tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur,
- UINT8 origin, UINT32 timeout, tBTM_CMPL_CB *p_cb)
+ UINT8 origin, period_ms_t timeout_ms,
+ tBTM_CMPL_CB *p_cb)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BOOLEAN cmd_ok;
@@ -2277,9 +2284,10 @@
/* If there is no remote name request running,call the callback function and start timer */
p_inq->p_remname_cmpl_cb = p_cb;
memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN);
- btu_start_timer (&p_inq->rmt_name_timer_ent,
- BTU_TTYPE_BTM_RMT_NAME,
- timeout);
+
+ alarm_set_on_queue(p_inq->remote_name_timer, timeout_ms,
+ btm_inq_remote_name_timer_timeout, NULL,
+ btu_general_alarm_queue);
/* If the database entry exists for the device, use its clock offset */
if (p_cur)
@@ -2356,7 +2364,7 @@
btm_ble_cancel_remote_name(p_inq->remname_bda);
}
#endif
- btu_stop_timer (&p_inq->rmt_name_timer_ent);
+ alarm_cancel(p_inq->remote_name_timer);
p_inq->remname_active = FALSE;
/* Clean up and return the status if the command was not successful */
/* Note: If part of the inquiry, the name is not stored, and the */
@@ -2398,6 +2406,11 @@
}
}
+void btm_inq_remote_name_timer_timeout(UNUSED_ATTR void *data)
+{
+ btm_inq_rmt_name_failed();
+}
+
/*******************************************************************************
**
** Function btm_inq_rmt_name_failed
@@ -2420,24 +2433,43 @@
btm_sec_rmt_name_request_complete (NULL, NULL, HCI_ERR_UNSPECIFIED);
}
+
/*******************************************************************************
**
-** Function btm_read_linq_tx_power_complete
+** Function btm_read_inq_tx_power_timeout
+**
+** Description Callback when reading the inquiry tx power times out.
+**
+** Returns void
+**
+*******************************************************************************/
+void btm_read_inq_tx_power_timeout(UNUSED_ATTR void *data)
+{
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb;
+ btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL;
+ if (p_cb)
+ (*p_cb)((void *) NULL);
+}
+
+/*******************************************************************************
+**
+** Function btm_read_inq_tx_power_complete
**
** Description read inquiry tx power level complete callback function.
**
** Returns void
**
*******************************************************************************/
-void btm_read_linq_tx_power_complete(UINT8 *p)
+void btm_read_inq_tx_power_complete(UINT8 *p)
{
- tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_txpwer_cmpl_cb;
+ tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb;
tBTM_INQ_TXPWR_RESULTS results;
- btu_stop_timer (&btm_cb.devcb.txpwer_timer);
- /* If there was a callback registered for read inq tx power, call it */
- btm_cb.devcb.p_txpwer_cmpl_cb = NULL;
+ BTM_TRACE_DEBUG("%s", __func__);
+ alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer);
+ btm_cb.devcb.p_inq_tx_power_cmpl_cb = NULL;
+ /* If there was a registered callback, call it */
if (p_cb)
{
STREAM_TO_UINT8 (results.hci_status, p);
diff --git a/stack/btm/btm_int.h b/stack/btm/btm_int.h
index 796f416..899a866 100644
--- a/stack/btm/btm_int.h
+++ b/stack/btm/btm_int.h
@@ -30,8 +30,8 @@
#include "hcidefs.h"
#include "rfcdefs.h"
+#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
-#include "osi/include/non_repeating_timer.h"
#include "btm_api.h"
@@ -122,13 +122,6 @@
} tACL_CONN;
-/*****************************************************
-** TIMER Definitions
-******************************************************/
-#define TT_DEV_RESET 1
-#define TT_DEV_RLN 2
-#define TT_DEV_RLNKP 4 /* Read Link Policy Settings */
-
/* Define the Device Management control structure
*/
typedef struct
@@ -138,30 +131,29 @@
tBTM_CMPL_CB *p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */
- timer_entry_t reset_timer;
-
- timer_entry_t rln_timer;
+ alarm_t *read_local_name_timer; /* Read local name timer */
tBTM_CMPL_CB *p_rln_cmpl_cb; /* Callback function to be called when */
/* read local name function complete */
- timer_entry_t rssi_timer;
+ alarm_t *read_rssi_timer; /* Read RSSI timer */
tBTM_CMPL_CB *p_rssi_cmpl_cb; /* Callback function to be called when */
- /* read rssi function completes */
- timer_entry_t lnk_quality_timer;
- tBTM_CMPL_CB *p_lnk_qual_cmpl_cb;/* Callback function to be called when */
+ /* read RSSI function completes */
+ alarm_t *read_link_quality_timer;
+ tBTM_CMPL_CB *p_link_qual_cmpl_cb; /* Callback function to be called when */
/* read link quality function completes */
- timer_entry_t txpwer_timer;
- tBTM_CMPL_CB *p_txpwer_cmpl_cb; /* Callback function to be called when */
+
+ alarm_t *read_inq_tx_power_timer;
+ tBTM_CMPL_CB *p_inq_tx_power_cmpl_cb; /* Callback function to be called when */
/* read inq tx power function completes */
- timer_entry_t qossu_timer;
- tBTM_CMPL_CB *p_qossu_cmpl_cb; /* Callback function to be called when */
+ alarm_t *qos_setup_timer; /* QoS setup timer */
+ tBTM_CMPL_CB *p_qos_setup_cmpl_cb; /* Callback function to be called when */
/* qos setup function completes */
tBTM_ROLE_SWITCH_CMPL switch_role_ref_data;
tBTM_CMPL_CB *p_switch_role_cb; /* Callback function to be called when */
/* requested switch role is completed */
- timer_entry_t tx_power_timer;
+ alarm_t *read_tx_power_timer; /* Read tx power timer */
tBTM_CMPL_CB *p_tx_power_cmpl_cb;/* Callback function to be called */
DEV_CLASS dev_class; /* Local device class */
@@ -249,10 +241,10 @@
{
tBTM_CMPL_CB *p_remname_cmpl_cb;
-#define BTM_EXT_RMT_NAME_TIMEOUT 40
+#define BTM_EXT_RMT_NAME_TIMEOUT_MS (40 * 1000) /* 40 seconds */
- timer_entry_t rmt_name_timer_ent;
+ alarm_t *remote_name_timer;
UINT16 discoverable_mode;
UINT16 connectable_mode;
@@ -279,7 +271,6 @@
UINT32 inq_counter; /* Counter incremented each time an inquiry completes */
/* Used for determining whether or not duplicate devices */
/* have responded to the same inquiry */
- timer_entry_t inq_timer_ent;
tINQ_BDADDR *p_bd_db; /* Pointer to memory that holds bdaddrs */
UINT16 num_bd_entries; /* Number of entries in database */
UINT16 max_bd_entries; /* Maximum number of entries that can be stored */
@@ -845,7 +836,7 @@
tBTM_RMT_NAME_CALLBACK *p_rmt_name_callback[BTM_SEC_MAX_RMT_NAME_CALLBACKS];
tBTM_SEC_DEV_REC *p_collided_dev_rec;
- timer_entry_t sec_collision_te;
+ alarm_t *sec_collision_timer;
UINT32 collision_start_time;
UINT32 max_collision_delay;
UINT32 dev_rec_count; /* Counter used for device record timestamp */
@@ -866,7 +857,7 @@
tBTM_PAIRING_STATE pairing_state; /* The current pairing state */
UINT8 pairing_flags; /* The current pairing flags */
BD_ADDR pairing_bda; /* The device currently pairing */
- timer_entry_t pairing_te; /* Timer for pairing process */
+ alarm_t *pairing_timer; /* Timer for pairing process */
UINT16 disc_handle; /* for legacy devices */
UINT8 disc_reason; /* for legacy devices */
tBTM_SEC_SERV_REC sec_serv_rec[BTM_SEC_MAX_SERVICE_RECORDS];
@@ -913,14 +904,15 @@
/* Internal functions provided by btm_inq.c
*******************************************
*/
-extern tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda,
- tBTM_INQ_INFO *p_cur,
- UINT8 origin, UINT32 timeout,
- tBTM_CMPL_CB *p_cb);
+extern tBTM_STATUS btm_initiate_rem_name(BD_ADDR remote_bda,
+ tBTM_INQ_INFO *p_cur,
+ UINT8 origin, period_ms_t timeout_ms,
+ tBTM_CMPL_CB *p_cb);
extern void btm_process_remote_name (BD_ADDR bda, BD_NAME name, UINT16 evt_len,
UINT8 hci_status);
extern void btm_inq_rmt_name_failed(void);
+extern void btm_inq_remote_name_timer_timeout(void *data);
/* Inquiry related functions */
extern void btm_clr_inq_db (BD_ADDR p_bda);
@@ -952,9 +944,16 @@
extern UINT8 btm_handle_to_acl_index (UINT16 hci_handle);
extern void btm_read_link_policy_complete (UINT8 *p);
-extern void btm_read_rssi_complete (UINT8 *p);
-extern void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble);
-extern void btm_read_link_quality_complete (UINT8 *p);
+
+extern void btm_read_rssi_timeout(void *data);
+extern void btm_read_rssi_complete(UINT8 *p);
+
+extern void btm_read_tx_power_timeout(void *data);
+extern void btm_read_tx_power_complete(UINT8 *p, BOOLEAN is_ble);
+
+extern void btm_read_link_quality_timeout(void *data);
+extern void btm_read_link_quality_complete(UINT8 *p);
+
extern tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types);
extern void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset);
extern void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role);
@@ -986,7 +985,10 @@
#else
#define btm_sco_chk_pend_unpark(hci_status, hci_handle)
#endif /* BTM_SCO_INCLUDED */
-extern void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow);
+
+extern void btm_qos_setup_timeout(void *data);
+extern void btm_qos_setup_complete(UINT8 status, UINT16 handle,
+ FLOW_SPEC *p_flow);
/* Internal functions provided by btm_sco.c
@@ -1013,9 +1015,9 @@
/* Internal functions provided by btm_devctl.c
**********************************************
*/
-extern void btm_dev_init (void);
-extern void btm_dev_timeout(timer_entry_t *p_te);
-extern void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len);
+extern void btm_dev_init(void);
+extern void btm_read_local_name_timeout(void *data);
+extern void btm_read_local_name_complete(UINT8 *p, UINT16 evt_len);
#if (BLE_INCLUDED == TRUE)
extern void btm_ble_add_2_white_list_complete(UINT8 status);
@@ -1062,7 +1064,9 @@
tBTM_SEC_CALLBACK *p_callback, void *p_ref_data);
extern void btm_sec_conn_req (UINT8 *bda, UINT8 *dc);
extern void btm_create_conn_cancel_complete (UINT8 *p);
-extern void btm_read_linq_tx_power_complete (UINT8 *p);
+
+extern void btm_read_inq_tx_power_timeout(void *data);
+extern void btm_read_inq_tx_power_complete(UINT8 *p);
extern void btm_sec_init (UINT8 sec_mode);
extern void btm_sec_dev_reset (void);
diff --git a/stack/btm/btm_main.c b/stack/btm/btm_main.c
index 3f60727..0d83a23 100644
--- a/stack/btm/btm_main.c
+++ b/stack/btm/btm_main.c
@@ -51,6 +51,8 @@
/* All fields are cleared; nonzero fields are reinitialized in appropriate function */
memset(&btm_cb, 0, sizeof(tBTM_CB));
btm_cb.page_queue = fixed_queue_new(SIZE_MAX);
+ btm_cb.sec_collision_timer = alarm_new("btm.sec_collision_timer");
+ btm_cb.pairing_timer = alarm_new("btm.pairing_timer");
#if defined(BTM_INITIAL_TRACE_LEVEL)
btm_cb.trace_level = BTM_INITIAL_TRACE_LEVEL;
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index 22ecae3..cbf9e86 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -49,6 +49,8 @@
#define BTM_SEC_MAX_COLLISION_DELAY (5000)
+extern fixed_queue_t *btu_general_alarm_queue;
+
#ifdef APPL_AUTH_WRITE_EXCEPTION
BOOLEAN (APPL_AUTH_WRITE_EXCEPTION)(BD_ADDR bd_addr);
#endif
@@ -66,9 +68,9 @@
static BOOLEAN btm_sec_start_get_name (tBTM_SEC_DEV_REC *p_dev_rec);
static BOOLEAN btm_sec_start_authentication (tBTM_SEC_DEV_REC *p_dev_rec);
static BOOLEAN btm_sec_start_encryption (tBTM_SEC_DEV_REC *p_dev_rec);
-static void btm_sec_collision_timeout(timer_entry_t *p_te);
+static void btm_sec_collision_timeout(void *data);
static void btm_restore_mode(void);
-static void btm_sec_pairing_timeout(timer_entry_t *p_te);
+static void btm_sec_pairing_timeout(void *data);
static tBTM_STATUS btm_sec_dd_create_conn (tBTM_SEC_DEV_REC *p_dev_rec);
static void btm_sec_change_pairing_state (tBTM_PAIRING_STATE new_state);
@@ -3836,12 +3838,14 @@
btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_DISCONNECT);
/* Change the timer to 1 second */
- btu_start_timer (&btm_cb.pairing_te, BTU_TTYPE_USER_FUNC, BT_1SEC_TIMEOUT);
+ alarm_set_on_queue(btm_cb.pairing_timer, BT_1SEC_TIMEOUT_MS,
+ btm_sec_pairing_timeout, NULL,
+ btu_general_alarm_queue);
}
else if (memcmp (btm_cb.pairing_bda, evt_data.bd_addr, BD_ADDR_LEN) == 0)
{
/* stop the timer */
- btu_stop_timer(&btm_cb.pairing_te);
+ alarm_cancel(btm_cb.pairing_timer);
if (p_dev_rec->sec_state != BTM_SEC_STATE_AUTHENTICATING)
{
@@ -3981,8 +3985,9 @@
p_dev_rec->sec_state = 0;
btm_cb.p_collided_dev_rec = p_dev_rec;
- btm_cb.sec_collision_te.param = UINT_TO_PTR(btm_sec_collision_timeout);
- btu_start_timer (&btm_cb.sec_collision_te, BTU_TTYPE_USER_FUNC, BT_1SEC_TIMEOUT);
+ alarm_set_on_queue(btm_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS,
+ btm_sec_collision_timeout, NULL,
+ btu_general_alarm_queue);
}
}
}
@@ -4370,18 +4375,17 @@
** Returns Pointer to the TLE struct
**
*******************************************************************************/
-static void btm_sec_connect_after_reject_timeout(timer_entry_t *p_te)
+static void btm_sec_connect_after_reject_timeout(UNUSED_ATTR void *data)
{
tBTM_SEC_DEV_REC *p_dev_rec = btm_cb.p_collided_dev_rec;
- UNUSED(p_te);
- BTM_TRACE_EVENT ("btm_sec_connect_after_reject_timeout()");
- btm_cb.sec_collision_te.param = 0;
+ BTM_TRACE_EVENT("%s", __func__);
btm_cb.p_collided_dev_rec = 0;
if (btm_sec_dd_create_conn(p_dev_rec) != BTM_CMD_STARTED)
{
- BTM_TRACE_WARNING ("Security Manager: btm_sec_connect_after_reject_timeout: failed to start connection");
+ BTM_TRACE_WARNING("Security Manager: %s: failed to start connection",
+ __func__);
btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE);
@@ -4477,8 +4481,9 @@
/* Start timer with 0 to initiate connection with new LCB */
/* because L2CAP will delete current LCB with this event */
btm_cb.p_collided_dev_rec = p_dev_rec;
- btm_cb.sec_collision_te.param = UINT_TO_PTR(btm_sec_connect_after_reject_timeout);
- btu_start_timer (&btm_cb.sec_collision_te, BTU_TTYPE_USER_FUNC, 0);
+ alarm_set_on_queue(btm_cb.sec_collision_timer, 0,
+ btm_sec_connect_after_reject_timeout,
+ NULL, btu_general_alarm_queue);
}
else
{
@@ -4535,8 +4540,9 @@
/* Start timer with 0 to initiate connection with new LCB */
/* because L2CAP will delete current LCB with this event */
btm_cb.p_collided_dev_rec = p_dev_rec;
- btm_cb.sec_collision_te.param = UINT_TO_PTR(btm_sec_connect_after_reject_timeout);
- btu_start_timer(&btm_cb.sec_collision_te, BTU_TTYPE_USER_FUNC, 0);
+ alarm_set_on_queue(btm_cb.sec_collision_timer, 0,
+ btm_sec_connect_after_reject_timeout,
+ NULL, btu_general_alarm_queue);
}
return;
@@ -5040,7 +5046,7 @@
** Returns Pointer to the TLE struct
**
*******************************************************************************/
-static void btm_sec_pairing_timeout (timer_entry_t *p_te)
+static void btm_sec_pairing_timeout(UNUSED_ATTR void *data)
{
tBTM_CB *p_cb = &btm_cb;
tBTM_SEC_DEV_REC *p_dev_rec;
@@ -5050,15 +5056,13 @@
tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_YES;
#endif
UINT8 name[2];
- UNUSED(p_te);
- p_cb->pairing_te.param = 0;
/* Coverity: FALSE-POSITIVE error from Coverity tool. Please do NOT remove following comment. */
/* coverity[UNUSED_VALUE] pointer p_dev_rec is actually used several times... This is a Coverity false-positive, i.e. a fake issue.
*/
p_dev_rec = btm_find_dev (p_cb->pairing_bda);
- BTM_TRACE_EVENT ("btm_sec_pairing_timeout() State: %s Flags: %u",
+ BTM_TRACE_EVENT ("%s State: %s Flags: %u", __func__,
btm_pair_state_descr(p_cb->pairing_state), p_cb->pairing_flags);
switch (p_cb->pairing_state)
@@ -5119,9 +5123,10 @@
* now it's time to tear down the ACL link*/
if (p_dev_rec == NULL)
{
- BTM_TRACE_ERROR ("btm_sec_pairing_timeout() BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x",
- (p_cb->pairing_bda[0]<<24) + (p_cb->pairing_bda[1]<<16) + (p_cb->pairing_bda[2]<<8) + p_cb->pairing_bda[3],
- (p_cb->pairing_bda[4] << 8) + p_cb->pairing_bda[5]);
+ BTM_TRACE_ERROR("%s BTM_PAIR_STATE_WAIT_DISCONNECT unknown BDA: %08x%04x",
+ __func__,
+ (p_cb->pairing_bda[0]<<24) + (p_cb->pairing_bda[1]<<16) + (p_cb->pairing_bda[2]<<8) + p_cb->pairing_bda[3],
+ (p_cb->pairing_bda[4] << 8) + p_cb->pairing_bda[5]);
break;
}
btm_sec_send_hci_disconnect (p_dev_rec, HCI_ERR_AUTH_FAILURE, p_dev_rec->hci_handle);
@@ -5149,7 +5154,8 @@
break;
default:
- BTM_TRACE_WARNING ("btm_sec_pairing_timeout() not processed state: %s", btm_pair_state_descr(btm_cb.pairing_state));
+ BTM_TRACE_WARNING("%s not processed state: %s", __func__,
+ btm_pair_state_descr(btm_cb.pairing_state));
btm_sec_change_pairing_state (BTM_PAIR_STATE_IDLE);
break;
}
@@ -5792,12 +5798,9 @@
** Returns Pointer to the TLE struct
**
*******************************************************************************/
-static void btm_sec_collision_timeout (timer_entry_t *p_te)
+static void btm_sec_collision_timeout(UNUSED_ATTR void *data)
{
- UNUSED(p_te);
-
BTM_TRACE_EVENT ("%s()", __func__);
- btm_cb.sec_collision_te.param = 0;
tBTM_STATUS status = btm_sec_execute_procedure (btm_cb.p_collided_dev_rec);
@@ -5915,7 +5918,7 @@
if (new_state == BTM_PAIR_STATE_IDLE)
{
- btu_stop_timer(&btm_cb.pairing_te);
+ alarm_cancel(btm_cb.pairing_timer);
btm_cb.pairing_flags = 0;
btm_cb.pin_code_len = 0;
@@ -5931,13 +5934,14 @@
}
else
{
- /* If transitionng out of idle, mark the lcb as bonding */
+ /* If transitioning out of idle, mark the lcb as bonding */
if (old_state == BTM_PAIR_STATE_IDLE)
l2cu_update_lcb_4_bonding (btm_cb.pairing_bda, TRUE);
- btm_cb.pairing_te.param = (timer_param_t)btm_sec_pairing_timeout;
-
- btu_start_timer(&btm_cb.pairing_te, BTU_TTYPE_USER_FUNC, BTM_SEC_TIMEOUT_VALUE);
+ alarm_set_on_queue(btm_cb.pairing_timer,
+ BTM_SEC_TIMEOUT_VALUE * 1000,
+ btm_sec_pairing_timeout, NULL,
+ btu_general_alarm_queue);
}
}
diff --git a/stack/btu/btu_hcif.c b/stack/btu/btu_hcif.c
index 1bdb7c7..e28d9cd 100644
--- a/stack/btu/btu_hcif.c
+++ b/stack/btu/btu_hcif.c
@@ -385,35 +385,6 @@
/*******************************************************************************
**
-** Function btu_hcif_send_host_rdy_for_data
-**
-** Description This function is called to check if it can send commands
-** to the Host Controller. It may be passed the address of
-** a packet to send.
-**
-** Returns void
-**
-*******************************************************************************/
-void btu_hcif_send_host_rdy_for_data(void)
-{
- UINT16 num_pkts[MAX_L2CAP_LINKS + 4]; /* 3 SCO connections */
- UINT16 handles[MAX_L2CAP_LINKS + 4];
- UINT8 num_ents;
-
- /* Get the L2CAP numbers */
- num_ents = l2c_link_pkts_rcvd (num_pkts, handles);
-
- /* Get the SCO numbers */
- /* No SCO for now ?? */
-
- if (num_ents)
- {
- btsnd_hcic_host_num_xmitted_pkts (num_ents, handles, num_pkts);
- }
-}
-
-/*******************************************************************************
-**
** Function btu_hcif_inquiry_comp_evt
**
** Description Process event HCI_INQUIRY_COMP_EVT
@@ -850,7 +821,7 @@
break;
case HCI_READ_INQ_TX_POWER_LEVEL:
- btm_read_linq_tx_power_complete (p);
+ btm_read_inq_tx_power_complete(p);
break;
#if (BLE_INCLUDED == TRUE)
diff --git a/stack/btu/btu_init.c b/stack/btu/btu_init.c
index ee60325..688ed88 100644
--- a/stack/btu/btu_init.c
+++ b/stack/btu/btu_init.c
@@ -58,21 +58,6 @@
// General timer queue.
fixed_queue_t *btu_general_alarm_queue;
-hash_map_t *btu_general_alarm_hash_map;
-pthread_mutex_t btu_general_alarm_lock;
-static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 17;
-
-// Oneshot timer queue.
-fixed_queue_t *btu_oneshot_alarm_queue;
-hash_map_t *btu_oneshot_alarm_hash_map;
-pthread_mutex_t btu_oneshot_alarm_lock;
-static const size_t BTU_ONESHOT_ALARM_HASH_MAP_SIZE = 17;
-
-// l2cap timer queue.
-fixed_queue_t *btu_l2cap_alarm_queue;
-hash_map_t *btu_l2cap_alarm_hash_map;
-pthread_mutex_t btu_l2cap_alarm_lock;
-static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 17;
thread_t *bt_workqueue_thread;
static const char *BT_WORKQUEUE_NAME = "bt_workqueue";
@@ -149,49 +134,16 @@
******************************************************************************/
void BTU_StartUp(void)
{
- memset (&btu_cb, 0, sizeof (tBTU_CB));
- btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL;
+ btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
btu_bta_msg_queue = fixed_queue_new(SIZE_MAX);
if (btu_bta_msg_queue == NULL)
goto error_exit;
- btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE,
- hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL);
- if (btu_general_alarm_hash_map == NULL)
- goto error_exit;
-
- if (pthread_mutex_init(&btu_general_alarm_lock, NULL))
- goto error_exit;
-
btu_general_alarm_queue = fixed_queue_new(SIZE_MAX);
if (btu_general_alarm_queue == NULL)
goto error_exit;
- btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE,
- hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL);
- if (btu_oneshot_alarm_hash_map == NULL)
- goto error_exit;
-
- if (pthread_mutex_init(&btu_oneshot_alarm_lock, NULL))
- goto error_exit;
-
- btu_oneshot_alarm_queue = fixed_queue_new(SIZE_MAX);
- if (btu_oneshot_alarm_queue == NULL)
- goto error_exit;
-
- btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE,
- hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL);
- if (btu_l2cap_alarm_hash_map == NULL)
- goto error_exit;
-
- if (pthread_mutex_init(&btu_l2cap_alarm_lock, NULL))
- goto error_exit;
-
- btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX);
- if (btu_l2cap_alarm_queue == NULL)
- goto error_exit;
-
bt_workqueue_thread = thread_new(BT_WORKQUEUE_NAME);
if (bt_workqueue_thread == NULL)
goto error_exit;
@@ -213,60 +165,10 @@
fixed_queue_free(btu_bta_msg_queue, NULL);
btu_bta_msg_queue = NULL;
- hash_map_free(btu_general_alarm_hash_map);
- btu_general_alarm_hash_map = NULL;
- pthread_mutex_destroy(&btu_general_alarm_lock);
fixed_queue_free(btu_general_alarm_queue, NULL);
btu_general_alarm_queue = NULL;
- hash_map_free(btu_oneshot_alarm_hash_map);
- btu_oneshot_alarm_hash_map = NULL;
- pthread_mutex_destroy(&btu_oneshot_alarm_lock);
- fixed_queue_free(btu_oneshot_alarm_queue, NULL);
- btu_oneshot_alarm_queue = NULL;
-
- hash_map_free(btu_l2cap_alarm_hash_map);
- btu_l2cap_alarm_hash_map = NULL;
- pthread_mutex_destroy(&btu_l2cap_alarm_lock);
- fixed_queue_free(btu_l2cap_alarm_queue, NULL);
- btu_l2cap_alarm_queue = NULL;
-
thread_free(bt_workqueue_thread);
bt_workqueue_thread = NULL;
}
-
-/*****************************************************************************
-**
-** Function BTU_BleAclPktSize
-**
-** Description export the BLE ACL packet size.
-**
-** Returns UINT16
-**
-******************************************************************************/
-UINT16 BTU_BleAclPktSize(void)
-{
-#if BLE_INCLUDED == TRUE
- return controller_get_interface()->get_acl_packet_size_ble();
-#else
- return 0;
-#endif
-}
-
-/*******************************************************************************
-**
-** Function btu_uipc_rx_cback
-**
-** Description
-**
-**
-** Returns void
-**
-*******************************************************************************/
-void btu_uipc_rx_cback(BT_HDR *p_msg) {
- assert(p_msg != NULL);
- BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, "btu_uipc_rx_cback event 0x%x,"
- " len %d, offset %d", p_msg->event, p_msg->len, p_msg->offset);
- fixed_queue_enqueue(btu_hci_msg_queue, p_msg);
-}
diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c
index b38f3c1..b94a7ad 100644
--- a/stack/btu/btu_task.c
+++ b/stack/btu/btu_task.c
@@ -86,9 +86,7 @@
/* Define BTU storage area
*/
-#if BTU_DYNAMIC_MEMORY == FALSE
-tBTU_CB btu_cb;
-#endif
+uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
// Communication queue between btu_task and bta.
extern fixed_queue_t *btu_bta_msg_queue;
@@ -98,30 +96,12 @@
// General timer queue.
extern fixed_queue_t *btu_general_alarm_queue;
-extern hash_map_t *btu_general_alarm_hash_map;
-extern pthread_mutex_t btu_general_alarm_lock;
-
-// Oneshot timer queue.
-extern fixed_queue_t *btu_oneshot_alarm_queue;
-extern hash_map_t *btu_oneshot_alarm_hash_map;
-extern pthread_mutex_t btu_oneshot_alarm_lock;
-
-// l2cap timer queue.
-extern fixed_queue_t *btu_l2cap_alarm_queue;
-extern hash_map_t *btu_l2cap_alarm_hash_map;
-extern pthread_mutex_t btu_l2cap_alarm_lock;
extern fixed_queue_t *event_queue;
extern fixed_queue_t *btif_msg_queue;
extern thread_t *bt_workqueue_thread;
-/* Define a function prototype to allow a generic timeout handler */
-typedef void (tUSER_TIMEOUT_FUNC) (timer_entry_t *p_te);
-
-static void btu_l2cap_alarm_process(timer_entry_t *p_te);
-static void btu_general_alarm_process(timer_entry_t *p_te);
-static void btu_bta_alarm_process(timer_entry_t *p_te);
static void btu_hci_msg_process(BT_HDR *p_msg);
void btu_hci_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
@@ -129,52 +109,11 @@
btu_hci_msg_process(p_msg);
}
-void btu_general_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
- timer_entry_t *p_te = (timer_entry_t *)fixed_queue_dequeue(queue);
- btu_general_alarm_process(p_te);
-}
-
-void btu_oneshot_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
- timer_entry_t *p_te = (timer_entry_t *)fixed_queue_dequeue(queue);
- btu_general_alarm_process(p_te);
-
- switch (p_te->event) {
-#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
- case BTU_TTYPE_BLE_RANDOM_ADDR:
- btm_ble_timeout(p_te);
- break;
-#endif
-
- case BTU_TTYPE_USER_FUNC:
- {
- tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_te->param;
- (*p_uf)(p_te);
- }
- break;
-
- default:
- // FAIL
- BTM_TRACE_WARNING("Received unexpected oneshot timer event:0x%x\n",
- p_te->event);
- break;
- }
-}
-
-void btu_l2cap_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
- timer_entry_t *p_te = (timer_entry_t *)fixed_queue_dequeue(queue);
- btu_l2cap_alarm_process(p_te);
-}
-
void btu_bta_msg_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
BT_HDR *p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
bta_sys_event(p_msg);
}
-void btu_bta_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
- timer_entry_t *p_te = (timer_entry_t *)fixed_queue_dequeue(queue);
- btu_bta_alarm_process(p_te);
-}
-
static void btu_hci_msg_process(BT_HDR *p_msg) {
/* Determine the input message type. */
switch (p_msg->event & BT_EVT_MASK)
@@ -213,46 +152,10 @@
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;
-
- 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;
- }
- }
- }
-
- if (handled == FALSE)
- osi_freebuf (p_msg);
-
+ default:
+ osi_freebuf(p_msg);
break;
}
-
-}
-
-static void btu_bta_alarm_process(timer_entry_t *p_te) {
- /* call timer callback */
- if (p_te->p_cback) {
- (*p_te->p_cback)(p_te);
- } else if (p_te->event) {
- BT_HDR *p_msg;
- if ((p_msg = (BT_HDR *) osi_getbuf(sizeof(BT_HDR))) != NULL) {
- p_msg->event = p_te->event;
- p_msg->layer_specific = 0;
- bta_sys_sendmsg(p_msg);
- }
- }
}
void btu_task_start_up(UNUSED_ATTR void *context) {
@@ -294,28 +197,13 @@
btu_hci_msg_ready,
NULL);
- fixed_queue_register_dequeue(btu_general_alarm_queue,
- thread_get_reactor(bt_workqueue_thread),
- btu_general_alarm_ready,
- NULL);
-
- fixed_queue_register_dequeue(btu_oneshot_alarm_queue,
- thread_get_reactor(bt_workqueue_thread),
- btu_oneshot_alarm_ready,
- NULL);
-
- fixed_queue_register_dequeue(btu_l2cap_alarm_queue,
- thread_get_reactor(bt_workqueue_thread),
- btu_l2cap_alarm_ready,
- NULL);
+ alarm_register_processing_queue(btu_general_alarm_queue, bt_workqueue_thread);
}
void btu_task_shut_down(UNUSED_ATTR void *context) {
fixed_queue_unregister_dequeue(btu_bta_msg_queue);
fixed_queue_unregister_dequeue(btu_hci_msg_queue);
- fixed_queue_unregister_dequeue(btu_general_alarm_queue);
- fixed_queue_unregister_dequeue(btu_oneshot_alarm_queue);
- fixed_queue_unregister_dequeue(btu_l2cap_alarm_queue);
+ alarm_unregister_processing_queue(btu_general_alarm_queue);
#if ( BT_USE_TRACES==TRUE )
module_clean_up(get_module(BTE_LOGMSG_MODULE));
@@ -325,310 +213,6 @@
btu_free_core();
}
-/*******************************************************************************
-**
-** 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
-**
-*******************************************************************************/
-static void btu_general_alarm_process(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- switch (p_te->event) {
- case BTU_TTYPE_BTM_DEV_CTL:
- btm_dev_timeout(p_te);
- 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:
- l2c_process_timeout (p_te);
- break;
-
- case BTU_TTYPE_SDP:
- sdp_conn_timeout ((tCONN_CB *)p_te->param);
- break;
-
- case BTU_TTYPE_BTM_RMT_NAME:
- btm_inq_rmt_name_failed();
- break;
-
- case BTU_TTYPE_RFCOMM_MFC:
- case BTU_TTYPE_RFCOMM_PORT:
- rfcomm_process_timeout (p_te);
- break;
-
-#if ((defined(BNEP_INCLUDED) && BNEP_INCLUDED == TRUE))
- case BTU_TTYPE_BNEP:
- bnep_process_timeout(p_te);
- break;
-#endif
-
-#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
- 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_te);
- break;
-#endif
-
-#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
- case BTU_TTYPE_HID_HOST_REPAGE_TO :
- hidh_proc_repage_timeout(p_te);
- break;
-#endif
-
-#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
- 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:
- case BTU_TTYPE_BLE_OBSERVE:
- btm_ble_timeout(p_te);
- break;
-
- case BTU_TTYPE_ATT_WAIT_FOR_RSP:
- gatt_rsp_timeout(p_te);
- break;
-
- case BTU_TTYPE_ATT_WAIT_FOR_IND_ACK:
- gatt_ind_ack_timeout(p_te);
- break;
-#if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
- case BTU_TTYPE_SMP_PAIRING_CMD:
- smp_rsp_timeout(p_te);
- break;
-#endif
-
-#endif
-
-#if (MCA_INCLUDED == TRUE)
- case BTU_TTYPE_MCA_CCB_RSP:
- mca_process_timeout(p_te);
- break;
-#endif
- case BTU_TTYPE_USER_FUNC:
- {
- tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_te->param;
- (*p_uf)(p_te);
- }
- break;
-
- 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_te == p_te)
- {
- btu_cb.timer_reg[i].timer_cb(p_te);
- handled = TRUE;
- }
- }
- break;
- }
-}
-
-void btu_general_alarm_cb(void *data) {
- assert(data != NULL);
- timer_entry_t *p_te = (timer_entry_t *)data;
-
- fixed_queue_enqueue(btu_general_alarm_queue, p_te);
-}
-
-void btu_start_timer(timer_entry_t *p_te, UINT16 type, UINT32 timeout_sec) {
- assert(p_te != NULL);
-
- // Get the alarm for the timer entry.
- pthread_mutex_lock(&btu_general_alarm_lock);
- if (!hash_map_has_key(btu_general_alarm_hash_map, p_te)) {
- hash_map_set(btu_general_alarm_hash_map, p_te, alarm_new());
- }
- pthread_mutex_unlock(&btu_general_alarm_lock);
-
- alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__);
- return;
- }
- alarm_cancel(alarm);
-
- p_te->event = type;
- // NOTE: This value is in seconds but stored in a ticks field.
- p_te->ticks = timeout_sec;
- p_te->in_use = TRUE;
- alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_general_alarm_cb, (void *)p_te);
-}
-
-/*******************************************************************************
-**
-** Function btu_stop_timer
-**
-** Description Stop a timer.
-**
-** Returns void
-**
-*******************************************************************************/
-void btu_stop_timer(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- if (p_te->in_use == FALSE)
- return;
- p_te->in_use = FALSE;
-
- // Get the alarm for the timer entry.
- alarm_t *alarm = hash_map_get(btu_general_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__);
- return;
- }
- alarm_cancel(alarm);
-}
-
-#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
-**
-*******************************************************************************/
-static void btu_l2cap_alarm_process(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- switch (p_te->event) {
- case BTU_TTYPE_L2CAP_CHNL: /* monitor or retransmission timer */
- case BTU_TTYPE_L2CAP_FCR_ACK: /* ack timer */
- l2c_process_timeout(p_te);
- break;
-
- default:
- break;
- }
-}
-
-static void btu_l2cap_alarm_cb(void *data) {
- assert(data != NULL);
- timer_entry_t *p_te = (timer_entry_t *)data;
-
- fixed_queue_enqueue(btu_l2cap_alarm_queue, p_te);
-}
-
-void btu_start_quick_timer(timer_entry_t *p_te, UINT16 type, UINT32 timeout_ticks) {
- assert(p_te != NULL);
-
- // Get the alarm for the timer entry.
- pthread_mutex_lock(&btu_l2cap_alarm_lock);
- if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_te)) {
- hash_map_set(btu_l2cap_alarm_hash_map, p_te, alarm_new());
- }
- pthread_mutex_unlock(&btu_l2cap_alarm_lock);
-
- alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__);
- return;
- }
- alarm_cancel(alarm);
-
- p_te->event = type;
- p_te->ticks = timeout_ticks;
- p_te->in_use = TRUE;
- // The quick timer ticks are 100ms long.
- alarm_set(alarm, (period_ms_t)(timeout_ticks * 100), btu_l2cap_alarm_cb, (void *)p_te);
-}
-
-/*******************************************************************************
-**
-** Function btu_stop_quick_timer
-**
-** Description Stop a timer.
-**
-** Returns void
-**
-*******************************************************************************/
-void btu_stop_quick_timer(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- if (p_te->in_use == FALSE)
- return;
- p_te->in_use = FALSE;
-
- // Get the alarm for the timer entry.
- alarm_t *alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__);
- return;
- }
- alarm_cancel(alarm);
-}
-#endif /* defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) */
-
-void btu_oneshot_alarm_cb(void *data) {
- assert(data != NULL);
- timer_entry_t *p_te = (timer_entry_t *)data;
-
- btu_stop_timer_oneshot(p_te);
-
- fixed_queue_enqueue(btu_oneshot_alarm_queue, p_te);
-}
-
-/*
- * Starts a oneshot timer with a timeout in seconds.
- */
-void btu_start_timer_oneshot(timer_entry_t *p_te, UINT16 type, UINT32 timeout_sec) {
- assert(p_te != NULL);
-
- // Get the alarm for the timer entry.
- pthread_mutex_lock(&btu_oneshot_alarm_lock);
- if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_te)) {
- hash_map_set(btu_oneshot_alarm_hash_map, p_te, alarm_new());
- }
- pthread_mutex_unlock(&btu_oneshot_alarm_lock);
-
- alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_ERROR(LOG_TAG, "%s Unable to create alarm", __func__);
- return;
- }
- alarm_cancel(alarm);
-
- p_te->event = type;
- p_te->in_use = TRUE;
- // NOTE: This value is in seconds but stored in a ticks field.
- p_te->ticks = timeout_sec;
- alarm_set(alarm, (period_ms_t)(timeout_sec * 1000), btu_oneshot_alarm_cb, (void *)p_te);
-}
-
-void btu_stop_timer_oneshot(timer_entry_t *p_te) {
- assert(p_te != NULL);
-
- if (p_te->in_use == FALSE)
- return;
- p_te->in_use = FALSE;
-
- // Get the alarm for the timer entry.
- alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_te);
- if (alarm == NULL) {
- LOG_WARN(LOG_TAG, "%s Unable to find expected alarm in hashmap", __func__);
- return;
- }
- alarm_cancel(alarm);
-}
-
#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
/*******************************************************************************
**
diff --git a/stack/gatt/gatt_api.c b/stack/gatt/gatt_api.c
index b096ff4..7be5786 100644
--- a/stack/gatt/gatt_api.c
+++ b/stack/gatt/gatt_api.c
@@ -34,7 +34,6 @@
#include "l2c_api.h"
#include "btm_int.h"
-
/*******************************************************************************
**
** Function GATT_SetTraceLevel
@@ -1116,7 +1115,7 @@
{
if (p_tcb->ind_count > 0 )
{
- btu_stop_timer (&p_tcb->ind_ack_timer_ent);
+ alarm_cancel(p_tcb->ind_ack_timer);
GATT_TRACE_DEBUG ("notif_count=%d ", p_tcb->ind_count);
/* send confirmation now */
@@ -1299,7 +1298,7 @@
(p_clcb->p_reg->gatt_if == gatt_if) &&
(p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx))
{
- btu_stop_timer(&p_clcb->rsp_timer_ent);
+ alarm_cancel(p_clcb->gatt_rsp_timer_ent);
gatt_clcb_dealloc (p_clcb);
break;
}
diff --git a/stack/gatt/gatt_cl.c b/stack/gatt/gatt_cl.c
index 74a9d7f..48a550b 100644
--- a/stack/gatt/gatt_cl.c
+++ b/stack/gatt/gatt_cl.c
@@ -1181,7 +1181,7 @@
}
else
{
- btu_stop_timer (&p_clcb->rsp_timer_ent);
+ alarm_cancel(p_clcb->gatt_rsp_timer_ent);
p_clcb->retry_count = 0;
}
}
diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h
index 61c987d..56760e9 100644
--- a/stack/gatt/gatt_int.h
+++ b/stack/gatt/gatt_int.h
@@ -75,8 +75,8 @@
#define GATT_HDR_SIZE 3 /* 1B opcode + 2B handle */
/* wait for ATT cmd response timeout value */
-#define GATT_WAIT_FOR_RSP_TOUT 30
-#define GATT_WAIT_FOR_DISC_RSP_TOUT 5
+#define GATT_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000)
+#define GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS (5 * 1000)
#define GATT_REQ_RETRY_LIMIT 2
/* characteristic descriptor type */
@@ -360,7 +360,7 @@
tGATT_CH_STATE ch_state;
UINT8 ch_flags;
- tGATT_IF app_hold_link[GATT_MAX_APPS];
+ tGATT_IF app_hold_link[GATT_MAX_APPS];
/* server needs */
/* server response data */
@@ -368,15 +368,15 @@
UINT16 indicate_handle;
fixed_queue_t *pending_ind_q;
- timer_entry_t conf_timer_ent; /* peer confirm to indication timer */
+ alarm_t *conf_timer; /* peer confirm to indication timer */
- UINT8 prep_cnt[GATT_MAX_APPS];
- UINT8 ind_count;
+ UINT8 prep_cnt[GATT_MAX_APPS];
+ UINT8 ind_count;
- tGATT_CMD_Q cl_cmd_q[GATT_CL_MAX_LCB];
- timer_entry_t ind_ack_timer_ent; /* local app confirm to indication timer */
- UINT8 pending_cl_req;
- UINT8 next_slot_inq; /* index of next available slot in queue */
+ tGATT_CMD_Q cl_cmd_q[GATT_CL_MAX_LCB];
+ alarm_t *ind_ack_timer; /* local app confirm to indication timer */
+ UINT8 pending_cl_req;
+ UINT8 next_slot_inq; /* index of next available slot in queue */
BOOLEAN in_use;
UINT8 tcb_idx;
@@ -410,7 +410,7 @@
BOOLEAN first_read_blob_after_read;
tGATT_READ_INC_UUID128 read_uuid128;
BOOLEAN in_use;
- timer_entry_t rsp_timer_ent; /* peer response timer */
+ alarm_t *gatt_rsp_timer_ent; /* peer response timer */
UINT8 retry_count;
} tGATT_CLCB;
@@ -420,25 +420,6 @@
tGATT_CLCB *p_clcb;
}tGATT_PENDING_ENC_CLCB;
-
-#define GATT_SIGN_WRITE 1
-#define GATT_VERIFY_SIGN_DATA 2
-
-typedef struct
-{
- BT_HDR hdr;
- tGATT_CLCB *p_clcb;
-}tGATT_SIGN_WRITE_OP;
-
-typedef struct
-{
- BT_HDR hdr;
- tGATT_TCB *p_tcb;
- BT_HDR *p_data;
-
-}tGATT_VERIFY_SIGN_OP;
-
-
typedef struct
{
UINT16 clcb_idx;
@@ -585,8 +566,9 @@
extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport, UINT8 *p_sec_flag, UINT8 *p_key_size);
extern void gatt_start_rsp_timer(UINT16 clcb_idx);
extern void gatt_start_conf_timer(tGATT_TCB *p_tcb);
-extern void gatt_rsp_timeout(timer_entry_t *p_te);
-extern void gatt_ind_ack_timeout(timer_entry_t *p_te);
+extern void gatt_rsp_timeout(void *data);
+extern void gatt_indication_confirmation_timeout(void *data);
+extern void gatt_ind_ack_timeout(void *data);
extern void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb);
extern tGATT_STATUS gatt_send_error_rsp(tGATT_TCB *p_tcb, UINT8 err_code, UINT8 op_code, UINT16 handle, BOOLEAN deq);
extern void gatt_dbg_display_uuid(tBT_UUID bt_uuid);
diff --git a/stack/gatt/gatt_main.c b/stack/gatt/gatt_main.c
index 48b2c95..b8de4cb 100644
--- a/stack/gatt/gatt_main.c
+++ b/stack/gatt/gatt_main.c
@@ -163,8 +163,16 @@
{
fixed_queue_free(gatt_cb.tcb[i].pending_enc_clcb, NULL);
gatt_cb.tcb[i].pending_enc_clcb = NULL;
+
fixed_queue_free(gatt_cb.tcb[i].pending_ind_q, NULL);
gatt_cb.tcb[i].pending_ind_q = NULL;
+
+ alarm_free(gatt_cb.tcb[i].conf_timer);
+ gatt_cb.tcb[i].conf_timer = NULL;
+
+ alarm_free(gatt_cb.tcb[i].ind_ack_timer);
+ gatt_cb.tcb[i].ind_ack_timer = NULL;
+
fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL);
gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL;
}
diff --git a/stack/gatt/gatt_sr.c b/stack/gatt/gatt_sr.c
index 9be12aa..268f0ca 100644
--- a/stack/gatt/gatt_sr.c
+++ b/stack/gatt/gatt_sr.c
@@ -1429,7 +1429,7 @@
BOOLEAN continue_processing;
UINT16 conn_id;
- btu_stop_timer (&p_tcb->conf_timer_ent);
+ alarm_cancel(p_tcb->conf_timer);
if (GATT_HANDLE_IS_VALID(handle))
{
p_tcb->indicate_handle = 0;
diff --git a/stack/gatt/gatt_utils.c b/stack/gatt/gatt_utils.c
index f993fa1..d4885a8 100644
--- a/stack/gatt/gatt_utils.c
+++ b/stack/gatt/gatt_utils.c
@@ -79,6 +79,7 @@
static const UINT8 base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+extern fixed_queue_t *btu_general_alarm_queue;
/*******************************************************************************
**
@@ -975,6 +976,8 @@
memset(p_tcb, 0, sizeof(tGATT_TCB));
p_tcb->pending_enc_clcb = fixed_queue_new(SIZE_MAX);
p_tcb->pending_ind_q = fixed_queue_new(SIZE_MAX);
+ p_tcb->conf_timer = alarm_new("gatt.conf_timer");
+ p_tcb->ind_ack_timer = alarm_new("gatt.ind_ack_timer");
p_tcb->sr_cmd.multi_rsp_q = fixed_queue_new(SIZE_MAX);
p_tcb->in_use = TRUE;
p_tcb->tcb_idx = i;
@@ -1198,37 +1201,44 @@
**
** Description Start a wait_for_response timer.
**
-** Returns TRUE if command sent, otherwise FALSE.
+** Returns void
**
*******************************************************************************/
void gatt_start_rsp_timer(UINT16 clcb_idx)
{
tGATT_CLCB *p_clcb = &gatt_cb.clcb[clcb_idx];
- UINT32 timeout = GATT_WAIT_FOR_RSP_TOUT;
- p_clcb->rsp_timer_ent.param = (timer_param_t)p_clcb;
+ period_ms_t timeout_ms = GATT_WAIT_FOR_RSP_TIMEOUT_MS;
+
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
- p_clcb->op_subtype == GATT_DISC_SRVC_ALL)
- {
- timeout = GATT_WAIT_FOR_DISC_RSP_TOUT;
+ p_clcb->op_subtype == GATT_DISC_SRVC_ALL) {
+ timeout_ms = GATT_WAIT_FOR_DISC_RSP_TIMEOUT_MS;
}
- btu_start_timer (&p_clcb->rsp_timer_ent, BTU_TTYPE_ATT_WAIT_FOR_RSP,
- timeout);
+
+ // TODO: The tGATT_CLCB memory and state management needs cleanup,
+ // and then the timers can be allocated elsewhere.
+ if (p_clcb->gatt_rsp_timer_ent == NULL) {
+ p_clcb->gatt_rsp_timer_ent = alarm_new("gatt.gatt_rsp_timer_ent");
+ }
+ alarm_set_on_queue(p_clcb->gatt_rsp_timer_ent, timeout_ms,
+ gatt_rsp_timeout, p_clcb, btu_general_alarm_queue);
}
+
/*******************************************************************************
**
** Function gatt_start_conf_timer
**
** Description Start a wait_for_confirmation timer.
**
-** Returns TRUE if command sent, otherwise FALSE.
+** Returns void
**
*******************************************************************************/
-void gatt_start_conf_timer(tGATT_TCB *p_tcb)
+void gatt_start_conf_timer(tGATT_TCB *p_tcb)
{
- p_tcb->conf_timer_ent.param = (timer_param_t)p_tcb;
- btu_start_timer (&p_tcb->conf_timer_ent, BTU_TTYPE_ATT_WAIT_FOR_RSP,
- GATT_WAIT_FOR_RSP_TOUT);
+ alarm_set_on_queue(p_tcb->conf_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS,
+ gatt_indication_confirmation_timeout, p_tcb,
+ btu_general_alarm_queue);
}
+
/*******************************************************************************
**
** Function gatt_start_ind_ack_timer
@@ -1240,12 +1250,11 @@
*******************************************************************************/
void gatt_start_ind_ack_timer(tGATT_TCB *p_tcb)
{
- p_tcb->ind_ack_timer_ent.param = (timer_param_t)p_tcb;
/* start notification cache timer */
- btu_start_timer (&p_tcb->ind_ack_timer_ent, BTU_TTYPE_ATT_WAIT_FOR_IND_ACK,
- GATT_WAIT_FOR_RSP_TOUT);
-
+ alarm_set_on_queue(p_tcb->ind_ack_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS,
+ gatt_ind_ack_timeout, p_tcb, btu_general_alarm_queue);
}
+
/*******************************************************************************
**
** Function gatt_rsp_timeout
@@ -1255,12 +1264,13 @@
** Returns void
**
*******************************************************************************/
-void gatt_rsp_timeout(timer_entry_t *p_te)
+void gatt_rsp_timeout(void *data)
{
- tGATT_CLCB *p_clcb = (tGATT_CLCB *)p_te->param;
+ tGATT_CLCB *p_clcb = (tGATT_CLCB *)data;
+
if (p_clcb == NULL || p_clcb->p_tcb == NULL)
{
- GATT_TRACE_WARNING("gatt_rsp_timeout clcb is already deleted");
+ GATT_TRACE_WARNING("%s clcb is already deleted", __func__);
return;
}
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
@@ -1268,10 +1278,11 @@
p_clcb->retry_count < GATT_REQ_RETRY_LIMIT)
{
UINT8 rsp_code;
- GATT_TRACE_WARNING("gatt_rsp_timeout retry discovery primary service");
+ GATT_TRACE_WARNING("%s retry discovery primary service", __func__);
if (p_clcb != gatt_cmd_dequeue(p_clcb->p_tcb, &rsp_code))
{
- GATT_TRACE_ERROR("gatt_rsp_timeout command queue out of sync, disconnect");
+ GATT_TRACE_ERROR("%s command queue out of sync, disconnect",
+ __func__);
}
else
{
@@ -1281,12 +1292,29 @@
}
}
- GATT_TRACE_WARNING("gatt_rsp_timeout disconnecting...");
+ GATT_TRACE_WARNING("%s disconnecting...", __func__);
gatt_disconnect (p_clcb->p_tcb);
}
/*******************************************************************************
**
+** Function gatt_indication_confirmation_timeout
+**
+** Description Called when the indication confirmation timer expires
+**
+** Returns void
+**
+*******************************************************************************/
+void gatt_indication_confirmation_timeout(void *data)
+{
+ tGATT_TCB *p_tcb = (tGATT_TCB *)data;
+
+ GATT_TRACE_WARNING("%s disconnecting...", __func__);
+ gatt_disconnect(p_tcb);
+}
+
+/*******************************************************************************
+**
** Function gatt_ind_ack_timeout
**
** Description Called when GATT wait for ATT handle confirmation timeout
@@ -1294,16 +1322,16 @@
** Returns void
**
*******************************************************************************/
-void gatt_ind_ack_timeout(timer_entry_t *p_te)
+void gatt_ind_ack_timeout(void *data)
{
- tGATT_TCB * p_tcb = (tGATT_TCB *)p_te->param;
+ tGATT_TCB *p_tcb = (tGATT_TCB *)data;
- GATT_TRACE_WARNING("gatt_ind_ack_timeout send ack now");
+ GATT_TRACE_WARNING("%s send ack now", __func__);
if (p_tcb != NULL)
p_tcb->ind_count = 0;
- attp_send_cl_msg(((tGATT_TCB *)p_te->param), 0, GATT_HANDLE_VALUE_CONF, NULL);
+ attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
}
/*******************************************************************************
**
@@ -1687,6 +1715,7 @@
{
if (p_clcb && p_clcb->in_use)
{
+ alarm_free(p_clcb->gatt_rsp_timer_ent);
memset(p_clcb, 0, sizeof(tGATT_CLCB));
}
}
@@ -2205,7 +2234,7 @@
operation = p_clcb->operation;
conn_id = p_clcb->conn_id;
- btu_stop_timer(&p_clcb->rsp_timer_ent);
+ alarm_cancel(p_clcb->gatt_rsp_timer_ent);
gatt_clcb_dealloc(p_clcb);
@@ -2248,7 +2277,7 @@
p_clcb = &gatt_cb.clcb[i];
if (p_clcb->in_use && p_clcb->p_tcb == p_tcb)
{
- btu_stop_timer(&p_clcb->rsp_timer_ent);
+ alarm_cancel(p_clcb->gatt_rsp_timer_ent);
GATT_TRACE_DEBUG ("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id, p_clcb->clcb_idx);
if (p_clcb->operation != GATTC_OPTYPE_NONE)
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
@@ -2258,8 +2287,10 @@
}
}
- btu_stop_timer (&p_tcb->ind_ack_timer_ent);
- btu_stop_timer (&p_tcb->conf_timer_ent);
+ alarm_free(p_tcb->ind_ack_timer);
+ p_tcb->ind_ack_timer = NULL;
+ alarm_free(p_tcb->conf_timer);
+ p_tcb->conf_timer = NULL;
gatt_free_pending_ind(p_tcb);
gatt_free_pending_enc_queue(p_tcb);
fixed_queue_free(p_tcb->sr_cmd.multi_rsp_q, NULL);
diff --git a/stack/hid/hid_conn.h b/stack/hid/hid_conn.h
index ced63df..211efbd 100644
--- a/stack/hid/hid_conn.h
+++ b/stack/hid/hid_conn.h
@@ -25,7 +25,7 @@
#ifndef HID_CONN_H
#define HID_CONN_H
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
/* Define the HID Connection Block
*/
@@ -57,8 +57,7 @@
UINT16 intr_cid;
UINT16 rem_mtu_size;
UINT16 disc_reason; /* Reason for disconnecting (for HID_HDEV_EVT_CLOSE) */
- timer_entry_t timer_entry;
-
+ alarm_t *process_repage_timer;
} tHID_CONN;
#define HID_SEC_CHN 1
diff --git a/stack/hid/hidh_api.c b/stack/hid/hidh_api.c
index af07cb2..7b0163b 100644
--- a/stack/hid/hidh_api.c
+++ b/stack/hid/hidh_api.c
@@ -241,6 +241,11 @@
{
memset(&hh_cb, 0, sizeof(tHID_HOST_CTB));
+ for (size_t i = 0; i < HID_HOST_MAX_DEVICES; i++) {
+ hh_cb.devices[i].conn.process_repage_timer =
+ alarm_new("hid_devices_conn.process_repage_timer");
+ }
+
#if defined(HID_INITIAL_TRACE_LEVEL)
hh_cb.trace_level = HID_INITIAL_TRACE_LEVEL;
#else
@@ -490,7 +495,7 @@
return HID_ERR_INVALID_PARAM;
hh_cb.devices[dev_handle].conn_tries = HID_HOST_MAX_CONN_RETRY+1;
- btu_stop_timer( &(hh_cb.devices[dev_handle].conn.timer_entry) ) ;
+ alarm_cancel(hh_cb.devices[dev_handle].conn.process_repage_timer);
if( hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED )
return HID_ERR_NO_CONNECTION;
diff --git a/stack/hid/hidh_conn.c b/stack/hid/hidh_conn.c
index d1cb700..9683b15 100644
--- a/stack/hid/hidh_conn.c
+++ b/stack/hid/hidh_conn.c
@@ -45,6 +45,9 @@
#include "osi/include/osi.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
static UINT8 find_conn_by_cid (UINT16 cid);
static void hidh_conn_retry (UINT8 dhandle);
@@ -292,19 +295,24 @@
psm, l2cap_cid);
}
+void hidh_process_repage_timer_timeout(void *data)
+{
+ uint8_t dhandle = PTR_TO_UINT(data);
+ hidh_try_repage(dhandle);
+}
+
/*******************************************************************************
**
-** Function hidh_proc_repage_timeout
+** Function hidh_try_repage
**
-** Description This function handles timeout (to page device).
+** Description This function processes timeout (to page device).
**
** Returns void
**
*******************************************************************************/
-void hidh_proc_repage_timeout(timer_entry_t *p_te)
+void hidh_try_repage(UINT8 dhandle)
{
tHID_HOST_DEV_CTB *device;
- UINT8 dhandle = PTR_TO_UINT(p_te->param);
hidh_conn_initiate(dhandle);
@@ -662,8 +670,10 @@
(hh_cb.devices[dhandle].attr_mask & HID_NORMALLY_CONNECTABLE))
{
hh_cb.devices[dhandle].conn_tries = 0;
- hh_cb.devices[dhandle].conn.timer_entry.param = UINT_TO_PTR(dhandle);
- btu_start_timer (&(hh_cb.devices[dhandle].conn.timer_entry), BTU_TTYPE_HID_HOST_REPAGE_TO, HID_HOST_REPAGE_WIN);
+ period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000;
+ alarm_set_on_queue(hh_cb.devices[dhandle].conn.process_repage_timer,
+ interval_ms, hidh_process_repage_timer_timeout,
+ UINT_TO_PTR(dhandle), btu_general_alarm_queue);
hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, disc_res, NULL);
}
else
@@ -1097,10 +1107,12 @@
tHID_HOST_DEV_CTB *p_dev = &hh_cb.devices[dhandle];
p_dev->conn.conn_state = HID_CONN_STATE_UNUSED;
- p_dev->conn.timer_entry.param = UINT_TO_PTR(dhandle);
#if (HID_HOST_REPAGE_WIN > 0)
- btu_start_timer (&(p_dev->conn.timer_entry), BTU_TTYPE_HID_HOST_REPAGE_TO, HID_HOST_REPAGE_WIN);
+ period_ms_t interval_ms = HID_HOST_REPAGE_WIN * 1000;
+ alarm_set_on_queue(p_dev->conn.process_repage_timer,
+ interval_ms, hidh_process_repage_timer_timeout,
+ UINT_TO_PTR(dhandle), btu_general_alarm_queue);
#else
- hidh_proc_repage_timeout( &(p_dev->conn.timer_entry) );
+ hidh_process_repage_process(dhandle);
#endif
}
diff --git a/stack/hid/hidh_int.h b/stack/hid/hidh_int.h
index 5ab59c7..c89c330 100644
--- a/stack/hid/hidh_int.h
+++ b/stack/hid/hidh_int.h
@@ -69,7 +69,8 @@
extern void hidh_conn_dereg( void );
extern tHID_STATUS hidh_conn_disconnect (UINT8 dhandle);
extern tHID_STATUS hidh_conn_initiate (UINT8 dhandle);
-extern void hidh_proc_repage_timeout(timer_entry_t *p_te);
+extern void hidh_process_repage_timer_timeout(void *data);
+extern void hidh_try_repage(UINT8 dhandle);
#ifdef __cplusplus
extern "C"
diff --git a/stack/include/bt_types.h b/stack/include/bt_types.h
index 688ffb4..cad52be 100644
--- a/stack/include/bt_types.h
+++ b/stack/include/bt_types.h
@@ -224,7 +224,6 @@
#define BT_PSM_UDI_CP 0x001D /* Unrestricted Digital Information Profile C-Plane */
#define BT_PSM_ATT 0x001F /* Attribute Protocol */
-
/* These macros extract the HCI opcodes from a buffer
*/
#define HCI_GET_CMD_HDR_OPCODE(p) (UINT16)((*((UINT8 *)((p) + 1) + p->offset) + \
@@ -411,20 +410,7 @@
#define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */
-/* Bluetooth CLK27 */
-#define BT_CLK27 (2 << 26)
-
-/* Bluetooth CLK12 is 1.28 sec */
-#define BT_CLK12_TO_MS(x) ((x) * 1280)
-#define BT_MS_TO_CLK12(x) ((x) / 1280)
-#define BT_CLK12_TO_SLOTS(x) ((x) << 11)
-
-/* Bluetooth CLK is 0.625 msec */
-#define BT_CLK_TO_MS(x) (((x) * 5 + 3) / 8)
-#define BT_MS_TO_CLK(x) (((x) * 8 + 2) / 5)
-
-#define BT_CLK_TO_MICROSECS(x) (((x) * 5000 + 3) / 8)
-#define BT_MICROSECS_TO_CLK(x) (((x) * 8 + 2499) / 5000)
+#define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */
/* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */
#define MAX_UUID_SIZE 16
diff --git a/stack/include/btm_ble_api.h b/stack/include/btm_ble_api.h
index 739a027..e63cb07 100644
--- a/stack/include/btm_ble_api.h
+++ b/stack/include/btm_ble_api.h
@@ -27,7 +27,7 @@
#include "btm_api.h"
#include "bt_common.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
#include <hardware/bt_common_types.h>
#define CHNL_MAP_LEN 5
@@ -502,7 +502,7 @@
BOOLEAN in_use;
UINT8 adv_evt;
BD_ADDR rpa;
- timer_entry_t raddr_timer_ent;
+ alarm_t *adv_raddr_timer;
tBTM_BLE_MULTI_ADV_CBACK *p_cback;
void *p_ref;
UINT8 index;
diff --git a/stack/include/btu.h b/stack/include/btu.h
index a994549..d0415f9 100644
--- a/stack/include/btu.h
+++ b/stack/include/btu.h
@@ -29,7 +29,7 @@
#include "bt_target.h"
#include "bt_common.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
// HACK(zachoverflow): temporary dark magic
#define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing
@@ -50,204 +50,19 @@
void *context;
} command_status_hack_t;
-/* callbacks
-*/
-typedef void (*tBTU_TIMER_CALLBACK)(timer_entry_t *p_te);
-typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
-
-
-/* Define the timer types maintained by BTU
-*/
-#define BTU_TTYPE_BTM_DEV_CTL 1
-#define BTU_TTYPE_L2CAP_LINK 2
-#define BTU_TTYPE_L2CAP_CHNL 3
-#define BTU_TTYPE_L2CAP_HOLD 4
-#define BTU_TTYPE_SDP 5
-#define BTU_TTYPE_BTM_SCO 6
-#define BTU_TTYPE_BTM_ACL 9
-#define BTU_TTYPE_BTM_RMT_NAME 10
-#define BTU_TTYPE_RFCOMM_MFC 11
-#define BTU_TTYPE_RFCOMM_PORT 12
-#define BTU_TTYPE_TCS_L2CAP 13
-#define BTU_TTYPE_TCS_CALL 14
-#define BTU_TTYPE_TCS_WUG 15
-#define BTU_TTYPE_AUTO_SYNC 16
-#define BTU_TTYPE_CTP_RECON 17
-#define BTU_TTYPE_CTP_T100 18
-#define BTU_TTYPE_CTP_GUARD 19
-#define BTU_TTYPE_CTP_DETACH 20
-
-#define BTU_TTYPE_SPP_CONN_RETRY 21
-#define BTU_TTYPE_USER_FUNC 22
-
-#define BTU_TTYPE_FTP_DISC 25
-#define BTU_TTYPE_OPP_DISC 26
-
-#define BTU_TTYPE_CTP_TL_DISCVY 28
-#define BTU_TTYPE_IPFRAG_TIMER 29
-#define BTU_TTYPE_HSP2_AT_CMD_TO 30
-#define BTU_TTYPE_HSP2_REPEAT_RING 31
-
-#define BTU_TTYPE_CTP_GW_INIT 32
-#define BTU_TTYPE_CTP_GW_CONN 33
-#define BTU_TTYPE_CTP_GW_IDLE 35
-
-#define BTU_TTYPE_ICP_L2CAP 36
-#define BTU_TTYPE_ICP_T100 37
-
-#define BTU_TTYPE_HSP2_WAIT_OK 38
-
-/* HCRP Timers */
-#define BTU_TTYPE_HCRP_NOTIF_REG 39
-#define BTU_TTYPE_HCRP_PROTO_RSP 40
-#define BTU_TTYPE_HCRP_CR_GRANT 41
-#define BTU_TTYPE_HCRP_CR_CHECK 42
-#define BTU_TTYPE_HCRP_W4_CLOSE 43
-
-/* HCRPM Timers */
-#define BTU_TTYPE_HCRPM_NOTIF_REG 44
-#define BTU_TTYPE_HCRPM_NOTIF_KEEP 45
-#define BTU_TTYPE_HCRPM_API_RSP 46
-#define BTU_TTYPE_HCRPM_W4_OPEN 47
-#define BTU_TTYPE_HCRPM_W4_CLOSE 48
-
-/* BNEP Timers */
-#define BTU_TTYPE_BNEP 50
-
-#define BTU_TTYPE_HSP2_SDP_FAIL_TO 55
-#define BTU_TTYPE_HSP2_SDP_RTRY_TO 56
-
-/* BTU internal */
-/* unused 60 */
-
-#define BTU_TTYPE_AVDT_CCB_RET 61
-#define BTU_TTYPE_AVDT_CCB_RSP 62
-#define BTU_TTYPE_AVDT_CCB_IDLE 63
-#define BTU_TTYPE_AVDT_SCB_TC 64
-
-#define BTU_TTYPE_HID_DEV_REPAGE_TO 65
-#define BTU_TTYPE_HID_HOST_REPAGE_TO 66
-
-#define BTU_TTYPE_HSP2_DELAY_CKPD_RCV 67
-
-#define BTU_TTYPE_SAP_TO 68
-
-/* BPP Timer */
-#define BTU_TTYPE_BPP_REF_CHNL 72
-
-/* LP HC idle Timer */
-#define BTU_TTYPE_LP_HC_IDLE_TO 74
-
-/* Patch RAM Timer */
-#define BTU_TTYPE_PATCHRAM_TO 75
-
-/* eL2CAP Info Request and other proto cmds timer */
-#define BTU_TTYPE_L2CAP_FCR_ACK 78
-#define BTU_TTYPE_L2CAP_INFO 79
-
-#define BTU_TTYPE_MCA_CCB_RSP 98
-
-/* BTU internal timer for BLE activity */
-#define BTU_TTYPE_BLE_INQUIRY 99
-#define BTU_TTYPE_BLE_GAP_LIM_DISC 100
-#define BTU_TTYPE_ATT_WAIT_FOR_RSP 101
-#define BTU_TTYPE_SMP_PAIRING_CMD 102
-#define BTU_TTYPE_BLE_RANDOM_ADDR 103
-#define BTU_TTYPE_ATT_WAIT_FOR_APP_RSP 104
-#define BTU_TTYPE_ATT_WAIT_FOR_IND_ACK 105
-
-#define BTU_TTYPE_BLE_GAP_FAST_ADV 106
-#define BTU_TTYPE_BLE_OBSERVE 107
-
-
-#define BTU_TTYPE_UCD_TO 108
-
-/* This is the inquiry response information held by BTU, and available
-** to applications.
-*/
-typedef struct
-{
- BD_ADDR remote_bd_addr;
- UINT8 page_scan_rep_mode;
- UINT8 page_scan_per_mode;
- UINT8 page_scan_mode;
- DEV_CLASS dev_class;
- UINT16 clock_offset;
-} tBTU_INQ_INFO;
-
-
-
-#define BTU_MAX_REG_TIMER (2) /* max # timer callbacks which may register */
-#define BTU_MAX_REG_EVENT (6) /* max # event callbacks which may register */
-#define BTU_DEFAULT_DATA_SIZE (0x2a0)
-
-#if (BLE_INCLUDED == TRUE)
-#define BTU_DEFAULT_BLE_DATA_SIZE (27)
-#endif
-
-/* structure to hold registered timers */
-typedef struct
-{
- timer_entry_t *p_te; /* timer entry */
- tBTU_TIMER_CALLBACK timer_cb; /* callback triggered when timer expires */
-} tBTU_TIMER_REG;
-
-/* structure to hold registered event callbacks */
-typedef struct
-{
- UINT16 event_range; /* start of event range */
- tBTU_EVENT_CALLBACK event_cb; /* callback triggered when event is in range */
-} tBTU_EVENT_REG;
-
-#define NFC_MAX_LOCAL_CTRLS 0
-
-/* the index to BTU command queue array */
-#define NFC_CONTROLLER_ID (1)
-#define BTU_MAX_LOCAL_CTRLS (1 + NFC_MAX_LOCAL_CTRLS) /* only BR/EDR */
-
-/* Define structure holding BTU variables
-*/
-typedef struct
-{
- tBTU_TIMER_REG timer_reg[BTU_MAX_REG_TIMER];
- tBTU_EVENT_REG event_reg[BTU_MAX_REG_EVENT];
-
- BOOLEAN reset_complete; /* TRUE after first ack from device received */
- UINT8 trace_level; /* Trace level for HCI layer */
-} tBTU_CB;
#ifdef __cplusplus
extern "C" {
#endif
/* Global BTU data */
-#if BTU_DYNAMIC_MEMORY == FALSE
-extern tBTU_CB btu_cb;
-#else
-extern tBTU_CB *btu_cb_ptr;
-#define btu_cb (*btu_cb_ptr)
-#endif
+extern uint8_t btu_trace_level;
extern const BD_ADDR BT_BD_ANY;
/* Functions provided by btu_task.c
************************************
*/
-extern void btu_start_timer (timer_entry_t *p_te, UINT16 type, UINT32 timeout);
-extern void btu_stop_timer (timer_entry_t *p_te);
-extern void btu_start_timer_oneshot(timer_entry_t *p_te, UINT16 type, UINT32 timeout);
-extern void btu_stop_timer_oneshot(timer_entry_t *p_te);
-
-extern void btu_uipc_rx_cback(BT_HDR *p_msg);
-
-/*
-** Quick Timer
-*/
-#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
-extern void btu_start_quick_timer (timer_entry_t *p_te, UINT16 type, UINT32 timeout);
-extern void btu_stop_quick_timer (timer_entry_t *p_te);
-extern void btu_process_quick_timer_evt (void);
-#endif
#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
extern void btu_check_bt_sleep (void);
@@ -258,8 +73,6 @@
*/
extern void btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf);
extern void btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg);
-extern void btu_hcif_send_host_rdy_for_data(void);
-extern void btu_hcif_cmd_timeout (UINT8 controller_id);
/* Functions provided by btu_core.c
************************************
@@ -270,8 +83,6 @@
void BTU_StartUp(void);
void BTU_ShutDown(void);
-extern UINT16 BTU_BleAclPktSize(void);
-
#ifdef __cplusplus
}
#endif
diff --git a/stack/include/dyn_mem.h b/stack/include/dyn_mem.h
index 2693ae6..de599ed 100644
--- a/stack/include/dyn_mem.h
+++ b/stack/include/dyn_mem.h
@@ -22,10 +22,6 @@
** Define memory usage for each CORE component (if not defined in bdroid_buildcfg.h)
** The default for each component is to use static memory allocations.
*/
-#ifndef BTU_DYNAMIC_MEMORY
-#define BTU_DYNAMIC_MEMORY FALSE
-#endif
-
#ifndef BTM_DYNAMIC_MEMORY
#define BTM_DYNAMIC_MEMORY FALSE
#endif
diff --git a/stack/include/port_ext.h b/stack/include/port_ext.h
index 11e1e11..b940e4e 100644
--- a/stack/include/port_ext.h
+++ b/stack/include/port_ext.h
@@ -27,6 +27,6 @@
#include "bt_common.h"
-/* Port emulation entity Entry Points */
-extern void rfcomm_process_timeout (timer_entry_t *p_te);
+extern void rfcomm_port_timer_timeout(void *data);
+extern void rfcomm_mcb_timer_timeout(void *data);
#endif
diff --git a/stack/l2cap/l2c_api.c b/stack/l2cap/l2c_api.c
index c82c80a..d84b9f8 100644
--- a/stack/l2cap/l2c_api.c
+++ b/stack/l2cap/l2c_api.c
@@ -41,6 +41,9 @@
#include "osi/include/allocator.h"
#include "osi/include/log.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function L2CA_Register
@@ -687,7 +690,10 @@
{
l2cu_adj_id(p_lcb, L2CAP_ADJ_BRCM_ID); /* Make sure not using Broadcom ID */
l2cu_send_peer_echo_req (p_lcb, NULL, 0);
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_ECHO_RSP_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_ECHO_RSP_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
}
return (TRUE);
diff --git a/stack/l2cap/l2c_ble.c b/stack/l2cap/l2c_ble.c
index 93f10fd..bf7b522 100644
--- a/stack/l2cap/l2c_ble.c
+++ b/stack/l2cap/l2c_ble.c
@@ -33,6 +33,9 @@
#include "device/include/controller.h"
#if (BLE_INCLUDED == TRUE)
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
static void l2cble_start_conn_update (tL2C_LCB *p_lcb);
/*******************************************************************************
@@ -299,7 +302,7 @@
L2CAP_TRACE_ERROR ("L2CAP got BLE scanner conn_comp in bad state: %d", p_lcb->link_state);
return;
}
- btu_stop_timer(&p_lcb->timer_entry);
+ alarm_cancel(p_lcb->l2c_lcb_timer);
/* Save the handle */
p_lcb->handle = handle;
@@ -759,7 +762,10 @@
p_lcb->link_state = LST_CONNECTING;
l2cb.is_ble_connecting = TRUE;
memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN);
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
btm_ble_set_conn_st (BLE_DIR_CONN);
return (TRUE);
@@ -939,8 +945,12 @@
/* so we may need a timer to kick off this link's transmissions. */
if ( (p_lcb->link_state == LST_CONNECTED)
&& (!list_is_empty(p_lcb->link_xmit_data_q))
- && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) )
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
+ && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) {
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
+ }
}
}
}
diff --git a/stack/l2cap/l2c_csm.c b/stack/l2cap/l2c_csm.c
index 03ebfc2..32ca988 100644
--- a/stack/l2cap/l2c_csm.c
+++ b/stack/l2cap/l2c_csm.c
@@ -36,6 +36,9 @@
#include "btu.h"
#include "hcimsgs.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* L O C A L F U N C T I O N P R O T O T Y P E S */
/********************************************************************************/
@@ -221,7 +224,10 @@
else
{
l2cu_send_peer_connect_req (p_ccb);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
break;
@@ -234,7 +240,7 @@
case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connect request */
/* stop link timer to avoid race condition between A2MP, Security, and L2CAP */
- btu_stop_timer (&p_ccb->p_lcb->timer_entry);
+ alarm_cancel(p_ccb->p_lcb->l2c_lcb_timer);
/* Cancel sniff mode if needed */
{
@@ -341,7 +347,10 @@
}
else
{
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
l2cu_send_peer_connect_req (p_ccb); /* Start Connection */
}
}
@@ -422,7 +431,10 @@
if (!p_ccb->p_lcb->w4_info_rsp)
{
/* Don't need to get info from peer or already retrieved so continue */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
L2CAP_TRACE_API ("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", p_ccb->local_cid);
(*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb) (p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid,
@@ -448,7 +460,10 @@
if (((tL2C_CONN_INFO *)p_data)->status == BTM_DELAY_CHECK)
{
/* start a timer - encryption change not received before L2CAP connect req */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_DELAY_CHECK_SM4);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
{
@@ -480,7 +495,9 @@
if (!btsnd_hcic_disconnect (p_ccb->p_lcb->handle, HCI_ERR_AUTH_FAILURE))
{
L2CAP_TRACE_API ("L2CAP - Calling btsnd_hcic_disconnect for handle %i failed", p_ccb->p_lcb->handle);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, 1);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, BT_1SEC_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
break;
@@ -534,7 +551,9 @@
case L2CEVT_L2CAP_CONNECT_RSP: /* Got peer connect confirm */
p_ccb->remote_cid = p_ci->remote_cid;
p_ccb->chnl_state = CST_CONFIG;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
L2CAP_TRACE_API ("L2CAP - Calling Connect_Cfm_Cb(), CID: 0x%04x, Success", p_ccb->local_cid);
(*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, L2CAP_CONN_OK);
@@ -542,7 +561,10 @@
case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Got peer connect pending */
p_ccb->remote_cid = p_ci->remote_cid;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT_EXT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
if (p_ccb->p_rcb->api.pL2CA_ConnectPnd_Cb)
{
L2CAP_TRACE_API ("L2CAP - Calling Connect_Pnd_Cb(), CID: 0x%04x", p_ccb->local_cid);
@@ -568,7 +590,10 @@
{
l2cu_send_peer_disc_req (p_ccb);
p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
l2cu_release_ccb (p_ccb);
@@ -589,7 +614,10 @@
else
{
/* We have feature info, so now send peer connect request */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
l2cu_send_peer_connect_req (p_ccb); /* Start Connection */
}
break;
@@ -635,13 +663,19 @@
{
l2cu_send_peer_connect_rsp (p_ccb, L2CAP_CONN_OK, 0);
p_ccb->chnl_state = CST_CONFIG;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
{
/* If pending, stay in same state and start extended timer */
l2cu_send_peer_connect_rsp (p_ccb, p_ci->l2cap_result, p_ci->l2cap_status);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT_EXT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
break;
@@ -666,12 +700,18 @@
case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */
l2cu_send_peer_disc_req (p_ccb);
p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CAP_INFO_RSP:
/* We have feature info, so now give the upper layer connect IND */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
L2CAP_TRACE_API ("L2CAP - Calling Connect_Ind_Cb(), CID: 0x%04x", p_ccb->local_cid);
(*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb) (p_ccb->p_lcb->remote_bd_addr,
@@ -762,7 +802,7 @@
p_ccb->config_done |= RECONFIG_FLAG;
p_ccb->chnl_state = CST_OPEN;
l2c_link_adjust_chnl_allocation ();
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
/* If using eRTM and waiting for an ACK, restart the ACK timer */
if (p_ccb->fcrb.wait_ack)
@@ -795,7 +835,7 @@
case L2CEVT_L2CAP_CONFIG_RSP_NEG: /* Peer config error rsp */
/* Disable the Timer */
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
/* If failure was channel mode try to renegotiate */
if (l2c_fcr_renegotiate_chan(p_ccb, p_cfg) == FALSE)
@@ -806,7 +846,10 @@
break;
case L2CEVT_L2CAP_DISCONNECT_REQ: /* Peer disconnected request */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP;
L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", p_ccb->local_cid);
(*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, TRUE);
@@ -815,7 +858,10 @@
case L2CEVT_L2CA_CONFIG_REQ: /* Upper layer config req */
l2cu_process_our_cfg_req (p_ccb, p_cfg);
l2cu_send_peer_config_req (p_ccb, p_cfg);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CA_CONFIG_RSP: /* Upper layer config rsp */
@@ -851,7 +897,7 @@
p_ccb->config_done |= RECONFIG_FLAG;
p_ccb->chnl_state = CST_OPEN;
l2c_link_adjust_chnl_allocation ();
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
}
l2cu_send_peer_config_rsp (p_ccb, p_cfg);
@@ -874,13 +920,19 @@
case L2CEVT_L2CA_CONFIG_RSP_NEG: /* Upper layer config reject */
l2cu_send_peer_config_rsp (p_ccb, p_cfg);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */
l2cu_send_peer_disc_req (p_ccb);
p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */
@@ -982,7 +1034,10 @@
p_ccb->chnl_state = CST_CONFIG;
p_ccb->config_done &= ~CFG_DONE_MASK;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
if ((cfg_result = l2cu_process_peer_cfg_req (p_ccb, p_cfg)) == L2CAP_PEER_CFG_OK)
{
@@ -992,7 +1047,7 @@
/* Error in config parameters: reset state and config flag */
else if (cfg_result == L2CAP_PEER_CFG_UNACCEPTABLE)
{
- btu_stop_timer(&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
p_ccb->chnl_state = tempstate;
p_ccb->config_done = tempcfgdone;
l2cu_send_peer_config_rsp (p_ccb, p_cfg);
@@ -1019,7 +1074,10 @@
// btla-specific --
p_ccb->chnl_state = CST_W4_L2CA_DISCONNECT_RSP;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
L2CAP_TRACE_API ("L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x%04x Conf Needed", p_ccb->local_cid);
(*p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb)(p_ccb->local_cid, TRUE);
break;
@@ -1040,7 +1098,10 @@
l2cu_send_peer_disc_req (p_ccb);
p_ccb->chnl_state = CST_W4_L2CAP_DISCONNECT_RSP;
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_DISCONNECT_TOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_DISCONNECT_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
@@ -1053,7 +1114,10 @@
p_ccb->config_done &= ~CFG_DONE_MASK;
l2cu_process_our_cfg_req (p_ccb, (tL2CAP_CFG_INFO *)p_data);
l2cu_send_peer_config_req (p_ccb, (tL2CAP_CFG_INFO *)p_data);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_TIMEOUT:
diff --git a/stack/l2cap/l2c_fcr.c b/stack/l2cap/l2c_fcr.c
index d6cfcec..943571c 100644
--- a/stack/l2cap/l2c_fcr.c
+++ b/stack/l2cap/l2c_fcr.c
@@ -38,6 +38,9 @@
#include "btm_int.h"
#include "btu.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/* Flag passed to retransmit_i_frames() when all packets should be retransmitted */
#define L2C_FCR_RETX_ALL_PKTS 0xFF
@@ -185,8 +188,11 @@
}
/* Only start a timer that was not started */
- if (p_ccb->fcrb.mon_retrans_timer.in_use == 0)
- btu_start_quick_timer (&p_ccb->fcrb.mon_retrans_timer, BTU_TTYPE_L2CAP_CHNL, tout*QUICK_TIMER_TICKS_PER_SEC/1000);
+ if (!alarm_is_scheduled(p_ccb->fcrb.mon_retrans_timer)) {
+ alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer, tout,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
+ }
}
/*******************************************************************************
@@ -201,10 +207,7 @@
void l2c_fcr_stop_timer (tL2C_CCB *p_ccb)
{
assert(p_ccb != NULL);
- if (p_ccb->fcrb.mon_retrans_timer.in_use)
- {
- btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
- }
+ alarm_cancel(p_ccb->fcrb.mon_retrans_timer);
}
/*******************************************************************************
@@ -221,7 +224,10 @@
assert(p_ccb != NULL);
tL2C_FCRB *p_fcrb = &p_ccb->fcrb;
- l2c_fcr_stop_timer (p_ccb);
+ alarm_free(p_fcrb->mon_retrans_timer);
+ p_fcrb->mon_retrans_timer = NULL;
+ alarm_free(p_fcrb->ack_timer);
+ p_fcrb->ack_timer = NULL;
if (p_fcrb->p_rx_sdu)
osi_freebuf (p_fcrb->p_rx_sdu);
@@ -240,9 +246,6 @@
fixed_queue_free(p_fcrb->retrans_q, NULL);
p_fcrb->retrans_q = NULL;
- btu_stop_quick_timer (&p_fcrb->ack_timer);
- btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
-
#if (L2CAP_ERTM_STATS == TRUE)
if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) )
{
@@ -437,8 +440,7 @@
p_fcrb->last_ack_sent = p_ccb->fcrb.next_seq_expected;
- if (p_ccb->fcrb.ack_timer.in_use)
- btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
+ alarm_cancel(p_ccb->fcrb.ack_timer);
}
/* Set the control word */
@@ -587,8 +589,7 @@
p_ccb->fcrb.last_ack_sent = p_ccb->fcrb.next_seq_expected;
- if (p_ccb->fcrb.ack_timer.in_use)
- btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
+ alarm_cancel(p_ccb->fcrb.ack_timer);
}
else
{
@@ -725,7 +726,10 @@
/* This is a small optimization... the monitor timer is 12 secs, but we saw */
/* that if the other side sends us a poll when we are waiting for a final, */
/* then it speeds up recovery significantly if we poll him back soon after his poll. */
- btu_start_quick_timer (&p_ccb->fcrb.mon_retrans_timer, BTU_TTYPE_L2CAP_CHNL, QUICK_TIMER_TICKS_PER_SEC);
+ alarm_set_on_queue(p_ccb->fcrb.mon_retrans_timer,
+ BT_1SEC_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
osi_freebuf (p_buf);
return;
@@ -1206,7 +1210,7 @@
p_fcrb->srej_sent = TRUE;
l2c_fcr_send_S_frame (p_ccb, L2CAP_FCR_SUP_SREJ, 0);
}
- btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
+ alarm_cancel(p_ccb->fcrb.ack_timer);
}
}
return;
@@ -1240,10 +1244,11 @@
if (delay_ack)
{
/* If it is the first I frame we did not ack, start ack timer */
- if (!p_ccb->fcrb.ack_timer.in_use)
- {
- btu_start_quick_timer (&p_ccb->fcrb.ack_timer, BTU_TTYPE_L2CAP_FCR_ACK,
- (L2CAP_FCR_ACK_TOUT*QUICK_TIMER_TICKS_PER_SEC)/1000);
+ if (!alarm_is_scheduled(p_ccb->fcrb.ack_timer)) {
+ alarm_set_on_queue(p_ccb->fcrb.ack_timer,
+ L2CAP_FCR_ACK_TIMEOUT_MS,
+ l2c_fcrb_ack_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
else if ((fixed_queue_is_empty(p_ccb->xmit_hold_q) ||
@@ -2107,7 +2112,10 @@
l2cu_process_our_cfg_req (p_ccb, &p_ccb->our_cfg);
l2cu_send_peer_config_req (p_ccb, &p_ccb->our_cfg);
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_CHNL_CFG_TIMEOUT);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_CHNL_CFG_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
return (TRUE);
}
}
diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h
index ade5a24..c02f48e 100644
--- a/stack/l2cap/l2c_int.h
+++ b/stack/l2cap/l2c_int.h
@@ -26,9 +26,9 @@
#include <stdbool.h>
+#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/list.h"
-#include "osi/include/non_repeating_timer.h"
#include "btm_api.h"
#include "bt_common.h"
#include "l2c_api.h"
@@ -36,33 +36,23 @@
#define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */
-/* Timeouts. Since L2CAP works off a 1-second list, all are in seconds.
-*/
-#define L2CAP_LINK_ROLE_SWITCH_TOUT 10 /* 10 seconds */
-#define L2CAP_LINK_CONNECT_TOUT 60 /* 30 seconds */
-#define L2CAP_LINK_CONNECT_TOUT_EXT 120 /* 120 seconds */
-#define L2CAP_ECHO_RSP_TOUT 30 /* 30 seconds */
-#define L2CAP_LINK_FLOW_CONTROL_TOUT 2 /* 2 seconds */
-#define L2CAP_LINK_DISCONNECT_TOUT 30 /* 30 seconds */
-
-#ifndef L2CAP_CHNL_CONNECT_TOUT /* BTIF needs to override for internal project needs */
-#define L2CAP_CHNL_CONNECT_TOUT 60 /* 60 seconds */
-#endif
-
-#define L2CAP_CHNL_CONNECT_TOUT_EXT 120 /* 120 seconds */
-#define L2CAP_CHNL_CFG_TIMEOUT 30 /* 30 seconds */
-#define L2CAP_CHNL_DISCONNECT_TOUT 10 /* 10 seconds */
-#define L2CAP_DELAY_CHECK_SM4 2 /* 2 seconds */
-#define L2CAP_WAIT_INFO_RSP_TOUT 3 /* 3 seconds */
-#define L2CAP_WAIT_UNPARK_TOUT 2 /* 2 seconds */
-#define L2CAP_LINK_INFO_RESP_TOUT 2 /* 2 seconds */
-#define L2CAP_BLE_LINK_CONNECT_TOUT 30 /* 30 seconds */
-#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */
-
-/* quick timer uses millisecond unit */
-#define L2CAP_DEFAULT_RETRANS_TOUT 2000 /* 2000 milliseconds */
-#define L2CAP_DEFAULT_MONITOR_TOUT 12000 /* 12000 milliseconds */
-#define L2CAP_FCR_ACK_TOUT 200 /* 200 milliseconds */
+/*
+ * Timeout values (in milliseconds).
+ */
+#define L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS (10 * 1000) /* 10 seconds */
+#define L2CAP_LINK_CONNECT_TIMEOUT_MS (60 * 1000) /* 30 seconds */
+#define L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */
+#define L2CAP_ECHO_RSP_TIMEOUT_MS (30 * 1000) /* 30 seconds */
+#define L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS (2 * 1000) /* 2 seconds */
+#define L2CAP_LINK_DISCONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */
+#define L2CAP_CHNL_CONNECT_TIMEOUT_MS (60 * 1000) /* 60 seconds */
+#define L2CAP_CHNL_CONNECT_EXT_TIMEOUT_MS (120 * 1000) /* 120 seconds */
+#define L2CAP_CHNL_CFG_TIMEOUT_MS (30 * 1000) /* 30 seconds */
+#define L2CAP_CHNL_DISCONNECT_TIMEOUT_MS (10 * 1000) /* 10 seconds */
+#define L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS (2 * 1000) /* 2 seconds */
+#define L2CAP_WAIT_INFO_RSP_TIMEOUT_MS (3 * 1000) /* 3 seconds */
+#define L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS (30 * 1000) /* 30 seconds */
+#define L2CAP_FCR_ACK_TIMEOUT_MS 200 /* 200 milliseconds */
/* Define the possible L2CAP channel states. The names of
** the states may seem a bit strange, but they are taken from
@@ -184,8 +174,8 @@
fixed_queue_t *srej_rcv_hold_q; /* Buffers rcvd but held pending SREJ rsp */
fixed_queue_t *retrans_q; /* Buffers being retransmitted */
- timer_entry_t ack_timer; /* Timer delaying RR */
- timer_entry_t mon_retrans_timer; /* Timer Monitor or Retransmission */
+ alarm_t *ack_timer; /* Timer delaying RR */
+ alarm_t *mon_retrans_timer; /* Timer Monitor or Retransmission */
#if (L2CAP_ERTM_STATS == TRUE)
UINT32 connect_tick_count; /* Time channel was established */
@@ -268,7 +258,7 @@
UINT16 local_cid; /* Local CID */
UINT16 remote_cid; /* Remote CID */
- timer_entry_t timer_entry; /* CCB Timer Entry */
+ alarm_t *l2c_ccb_timer; /* CCB Timer Entry */
tL2C_RCB *p_rcb; /* Registration CB for this Channel */
bool should_free_rcb; /* True if RCB was allocated on the heap */
@@ -361,13 +351,13 @@
BOOLEAN in_use; /* TRUE when in use, FALSE when not */
tL2C_LINK_STATE link_state;
- timer_entry_t timer_entry; /* Timer entry for timeout evt */
+ alarm_t *l2c_lcb_timer; /* Timer entry for timeout evt */
UINT16 handle; /* The handle used with LM */
tL2C_CCB_Q ccb_queue; /* Queue of CCBs on this LCB */
tL2C_CCB *p_pending_ccb; /* ccb of waiting channel during link disconnect */
- timer_entry_t info_timer_entry; /* Timer entry for info resp timeout evt */
+ alarm_t *info_resp_timer; /* Timer entry for info resp timeout evt */
BD_ADDR remote_bd_addr; /* The BD address of the remote */
UINT8 link_role; /* Master or slave */
@@ -459,7 +449,7 @@
UINT16 idle_timeout; /* Idle timeout */
list_t *rcv_pending_q; /* Recv pending queue */
- timer_entry_t rcv_hold_te; /* Timer entry for rcv hold */
+ alarm_t *receive_hold_timer; /* Timer entry for rcv hold */
tL2C_LCB *p_cur_hcit_lcb; /* Current HCI Transport buffer */
UINT16 num_links_active; /* Number of links active */
@@ -553,7 +543,10 @@
void l2c_init(void);
void l2c_free(void);
-extern void l2c_process_timeout(timer_entry_t *p_te);
+extern void l2c_receive_hold_timer_timeout(void *data);
+extern void l2c_ccb_timer_timeout(void *data);
+extern void l2c_lcb_timer_timeout(void *data);
+extern void l2c_fcrb_ack_timer_timeout(void *data);
extern UINT8 l2c_data_write (UINT16 cid, BT_HDR *p_data, UINT16 flag);
extern void l2c_rcv_acl_data (BT_HDR *p_msg);
extern void l2c_process_held_packets (BOOLEAN timed_out);
@@ -675,7 +668,7 @@
extern BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason);
extern BOOLEAN l2c_link_hci_qos_violation (UINT16 handle);
extern void l2c_link_timeout (tL2C_LCB *p_lcb);
-extern void l2c_info_timeout (tL2C_LCB *p_lcb);
+extern void l2c_info_resp_timer_timeout(void *data);
extern void l2c_link_check_send_pkts (tL2C_LCB *p_lcb, tL2C_CCB *p_ccb, BT_HDR *p_buf);
extern void l2c_link_adjust_allocation (void);
extern void l2c_link_process_num_completed_pkts (UINT8 *p);
diff --git a/stack/l2cap/l2c_link.c b/stack/l2cap/l2c_link.c
index 4e935ed..66c7d70 100644
--- a/stack/l2cap/l2c_link.c
+++ b/stack/l2cap/l2c_link.c
@@ -41,6 +41,9 @@
#include "btm_api.h"
#include "btm_int.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
static BOOLEAN l2c_link_send_to_lower (tL2C_LCB *p_lcb, BT_HDR *p_buf);
/*******************************************************************************
@@ -106,7 +109,9 @@
p_lcb->link_state = LST_CONNECTING;
/* Start a timer waiting for connect complete */
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_CONNECT_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer, L2CAP_LINK_CONNECT_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
return (TRUE);
}
@@ -218,7 +223,7 @@
/* Update the timeouts in the hold queue */
l2c_process_held_packets(FALSE);
- btu_stop_timer (&p_lcb->timer_entry);
+ alarm_cancel(p_lcb->l2c_lcb_timer);
/* For all channels, send the event through their FSMs */
for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb)
@@ -229,11 +234,17 @@
if (p_lcb->p_echo_rsp_cb)
{
l2cu_send_peer_echo_req (p_lcb, NULL, 0);
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_ECHO_RSP_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_ECHO_RSP_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
}
else if (!p_lcb->ccb_queue.p_first_ccb)
{
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_STARTUP_TOUT);
+ period_ms_t timeout_ms = L2CAP_LINK_STARTUP_TOUT * 1000;
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
}
}
/* Max number of acl connections. */
@@ -328,13 +339,15 @@
switch(status)
{
case BTM_SUCCESS:
- L2CAP_TRACE_DEBUG ("ccb timer ticks: %u", p_ccb->timer_entry.ticks);
event = L2CEVT_SEC_COMP;
break;
case BTM_DELAY_CHECK:
/* start a timer - encryption change not received before L2CAP connect req */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, L2CAP_DELAY_CHECK_SM4);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer,
+ L2CAP_DELAY_CHECK_SM4_TIMEOUT_MS,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
return;
default:
@@ -533,7 +546,6 @@
void l2c_link_timeout (tL2C_LCB *p_lcb)
{
tL2C_CCB *p_ccb;
- UINT16 timeout;
tBTM_STATUS rc;
L2CAP_TRACE_EVENT ("L2CAP - l2c_link_timeout() link state %d first CCB %p is_bonding:%d",
@@ -598,46 +610,50 @@
/* If no channels in use, drop the link. */
if (!p_lcb->ccb_queue.p_first_ccb)
{
+ period_ms_t timeout_ms;
+ bool start_timeout = true;
+
rc = btm_sec_disconnect (p_lcb->handle, HCI_ERR_PEER_USER);
if (rc == BTM_CMD_STORED)
{
/* Security Manager will take care of disconnecting, state will be updated at that time */
- timeout = 0xFFFF;
+ start_timeout = false;
}
else if (rc == BTM_CMD_STARTED)
{
p_lcb->link_state = LST_DISCONNECTING;
- timeout = L2CAP_LINK_DISCONNECT_TOUT;
+ timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS;
}
else if (rc == BTM_SUCCESS)
{
l2cu_process_fixed_disc_cback(p_lcb);
/* BTM SEC will make sure that link is release (probably after pairing is done) */
p_lcb->link_state = LST_DISCONNECTING;
- timeout = 0xFFFF;
+ start_timeout = false;
}
else if (rc == BTM_BUSY)
{
/* BTM is still executing security process. Let lcb stay as connected */
- timeout = 0xFFFF;
+ start_timeout = false;
}
else if ((p_lcb->is_bonding)
&& (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER)))
{
l2cu_process_fixed_disc_cback(p_lcb);
p_lcb->link_state = LST_DISCONNECTING;
- timeout = L2CAP_LINK_DISCONNECT_TOUT;
+ timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS;
}
else
{
/* probably no buffer to send disconnect */
- timeout = BT_1SEC_TIMEOUT;
+ timeout_ms = BT_1SEC_TIMEOUT_MS;
}
- if (timeout != 0xFFFF)
- {
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, timeout);
+ if (start_timeout) {
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
}
}
else
@@ -650,15 +666,16 @@
/*******************************************************************************
**
-** Function l2c_info_timeout
+** Function l2c_info_resp_timer_timeout
**
** Description This function is called when an info request times out
**
** Returns void
**
*******************************************************************************/
-void l2c_info_timeout (tL2C_LCB *p_lcb)
+void l2c_info_resp_timer_timeout(void *data)
{
+ tL2C_LCB *p_lcb = (tL2C_LCB *)data;
tL2C_CCB *p_ccb;
tL2C_CONN_INFO ci;
@@ -670,7 +687,10 @@
{
if ( (p_ccb->chnl_state == CST_ORIG_W4_SEC_COMP) || (p_ccb->chnl_state == CST_TERM_W4_SEC_COMP) )
{
- btu_start_timer (&p_lcb->info_timer_entry, BTU_TTYPE_L2CAP_INFO, L2CAP_WAIT_INFO_RSP_TOUT);
+ alarm_set_on_queue(p_lcb->info_resp_timer,
+ L2CAP_WAIT_INFO_RSP_TIMEOUT_MS,
+ l2c_info_resp_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
return;
}
}
@@ -814,11 +834,14 @@
/* so we may need a timer to kick off this link's transmissions. */
if ( (p_lcb->link_state == LST_CONNECTED)
&& (!list_is_empty(p_lcb->link_xmit_data_q))
- && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) )
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
+ && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) {
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
+ }
}
}
-
}
/*******************************************************************************
@@ -959,7 +982,10 @@
if ( (p_lcb) && (!p_lcb->ccb_queue.p_first_ccb) )
{
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_CONNECT_TOUT_EXT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_CONNECT_EXT_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
}
}
@@ -1184,10 +1210,13 @@
/* There is a special case where we have readjusted the link quotas and */
/* this link may have sent anything but some other link sent packets so */
/* so we may need a timer to kick off this link's transmissions. */
- if ( (!list_is_empty(p_lcb->link_xmit_data_q)) && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) )
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_FLOW_CONTROL_TOUT);
+ if ( (!list_is_empty(p_lcb->link_xmit_data_q)) && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) {
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
+ }
}
-
}
/*******************************************************************************
diff --git a/stack/l2cap/l2c_main.c b/stack/l2cap/l2c_main.c
index f8b7991..6961308 100644
--- a/stack/l2cap/l2c_main.c
+++ b/stack/l2cap/l2c_main.c
@@ -40,6 +40,9 @@
#include "l2cdefs.h"
#include "osi/include/log.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* L O C A L F U N C T I O N P R O T O T Y P E S */
/********************************************************************************/
@@ -159,8 +162,12 @@
p_msg->layer_specific = 2;
list_append(l2cb.rcv_pending_q, p_msg);
- if (list_length(l2cb.rcv_pending_q) == 1)
- btu_start_timer (&l2cb.rcv_hold_te, BTU_TTYPE_L2CAP_HOLD, BT_1SEC_TIMEOUT);
+ if (list_length(l2cb.rcv_pending_q) == 1) {
+ alarm_set_on_queue(l2cb.receive_hold_timer,
+ BT_1SEC_TIMEOUT_MS,
+ l2c_receive_hold_timer_timeout, NULL,
+ btu_general_alarm_queue);
+ }
return;
} else {
@@ -417,7 +424,7 @@
/* SonyEricsson Info request Bug workaround (Continue connection) */
else if (rej_reason == L2CAP_CMD_REJ_NOT_UNDERSTOOD && p_lcb->w4_info_rsp)
{
- btu_stop_timer (&p_lcb->info_timer_entry);
+ alarm_cancel(p_lcb->info_resp_timer);
p_lcb->w4_info_rsp = FALSE;
ci.status = HCI_SUCCESS;
@@ -734,7 +741,7 @@
/* Stop the link connect timer if sent before L2CAP connection is up */
if (p_lcb->w4_info_rsp)
{
- btu_stop_timer (&p_lcb->info_timer_entry);
+ alarm_cancel(p_lcb->info_resp_timer);
p_lcb->w4_info_rsp = FALSE;
}
@@ -814,7 +821,7 @@
return;
if (!timed_out) {
- btu_stop_timer(&l2cb.rcv_hold_te);
+ alarm_cancel(l2cb.receive_hold_timer);
L2CAP_TRACE_WARNING("L2CAP HOLD CONTINUE");
} else {
L2CAP_TRACE_WARNING("L2CAP HOLD TIMEOUT");
@@ -832,8 +839,11 @@
}
/* If anyone still in the queue, restart the timeout */
- if (!list_is_empty(l2cb.rcv_pending_q))
- btu_start_timer (&l2cb.rcv_hold_te, BTU_TTYPE_L2CAP_HOLD, BT_1SEC_TIMEOUT);
+ if (!list_is_empty(l2cb.rcv_pending_q)) {
+ alarm_set_on_queue(l2cb.receive_hold_timer, BT_1SEC_TIMEOUT_MS,
+ l2c_receive_hold_timer_timeout, NULL,
+ btu_general_alarm_queue);
+ }
}
/*******************************************************************************
@@ -901,47 +911,38 @@
l2cb.rcv_pending_q = list_new(NULL);
if (l2cb.rcv_pending_q == NULL)
LOG_ERROR(LOG_TAG, "%s unable to allocate memory for link layer control block", __func__);
+ l2cb.receive_hold_timer = alarm_new("l2c.receive_hold_timer");
}
void l2c_free(void) {
list_free(l2cb.rcv_pending_q);
}
-/*******************************************************************************
-**
-** Function l2c_process_timeout
-**
-** Description This function is called when an L2CAP-related timeout occurs
-**
-** Returns void
-**
-*******************************************************************************/
-void l2c_process_timeout (timer_entry_t *p_te)
+void l2c_receive_hold_timer_timeout(UNUSED_ATTR void *data)
{
- /* What type of timeout ? */
- switch (p_te->event)
- {
- case BTU_TTYPE_L2CAP_LINK:
- l2c_link_timeout ((tL2C_LCB *)p_te->param);
- break;
+ /* Update the timeouts in the hold queue */
+ l2c_process_held_packets(TRUE);
+}
- case BTU_TTYPE_L2CAP_CHNL:
- l2c_csm_execute (((tL2C_CCB *)p_te->param), L2CEVT_TIMEOUT, NULL);
- break;
+void l2c_ccb_timer_timeout(void *data)
+{
+ tL2C_CCB *p_ccb = (tL2C_CCB *)data;
- case BTU_TTYPE_L2CAP_FCR_ACK:
- l2c_csm_execute (((tL2C_CCB *)p_te->param), L2CEVT_ACK_TIMEOUT, NULL);
- break;
+ l2c_csm_execute(p_ccb, L2CEVT_TIMEOUT, NULL);
+}
- case BTU_TTYPE_L2CAP_HOLD:
- /* Update the timeouts in the hold queue */
- l2c_process_held_packets(TRUE);
- break;
+void l2c_fcrb_ack_timer_timeout(void *data)
+{
+ tL2C_CCB *p_ccb = (tL2C_CCB *)data;
- case BTU_TTYPE_L2CAP_INFO:
- l2c_info_timeout((tL2C_LCB *)p_te->param);
- break;
- }
+ l2c_csm_execute(p_ccb, L2CEVT_ACK_TIMEOUT, NULL);
+}
+
+void l2c_lcb_timer_timeout(void *data)
+{
+ tL2C_LCB *p_lcb = (tL2C_LCB *)data;
+
+ l2c_link_timeout(p_lcb);
}
/*******************************************************************************
diff --git a/stack/l2cap/l2c_ucd.c b/stack/l2cap/l2c_ucd.c
index a047504..204bed8 100644
--- a/stack/l2cap/l2c_ucd.c
+++ b/stack/l2cap/l2c_ucd.c
@@ -37,6 +37,9 @@
#include "btm_int.h"
#if (L2CAP_UCD_INCLUDED == TRUE)
+
+extern fixed_queue_t *btu_bta_alarm_queue;
+
static BOOLEAN l2c_ucd_connect ( BD_ADDR rem_bda );
/*******************************************************************************
@@ -1014,12 +1017,17 @@
{
/* start a timer to send next UCD packet in OPEN state */
/* it will prevent stack overflow */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, 0);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
{
/* start a timer for idle timeout of UCD */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, p_ccb->fixed_chnl_idle_tout);
+ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000;
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
break;
@@ -1028,7 +1036,10 @@
l2c_ucd_discard_pending_out_sec_q(p_ccb);
/* start a timer for idle timeout of UCD */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, p_ccb->fixed_chnl_idle_tout);
+ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000;
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
@@ -1062,12 +1073,17 @@
{
/* start a timer to check next UCD packet in OPEN state */
/* it will prevent stack overflow */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, 0);
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, 0,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
{
/* start a timer for idle timeout of UCD */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, p_ccb->fixed_chnl_idle_tout);
+ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000;
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
break;
@@ -1081,7 +1097,10 @@
l2c_ucd_discard_pending_in_sec_q (p_ccb);
/* start a timer for idle timeout of UCD */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_L2CAP_CHNL, p_ccb->fixed_chnl_idle_tout);
+ period_ms_t timeout_ms = p_ccb->fixed_chnl_idle_tout * 1000;
+ alarm_set_on_queue(p_ccb->l2c_ccb_timer, timeout_ms,
+ l2c_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
break;
case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
@@ -1116,7 +1135,7 @@
{
case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */
/* stop idle timer of UCD */
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
fixed_queue_enqueue(p_ccb->p_lcb->ucd_in_sec_pending_q, p_data);
l2c_ucd_check_pending_in_sec_q (p_ccb);
@@ -1124,7 +1143,7 @@
case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
/* stop idle timer of UCD */
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->l2c_ccb_timer);
l2c_ucd_enqueue_pending_out_sec_q(p_ccb, p_data);
diff --git a/stack/l2cap/l2c_utils.c b/stack/l2cap/l2c_utils.c
index c680fa4..ef96cbc 100644
--- a/stack/l2cap/l2c_utils.c
+++ b/stack/l2cap/l2c_utils.c
@@ -41,6 +41,8 @@
#include "bt_utils.h"
#include "osi/include/allocator.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function l2cu_allocate_lcb
@@ -59,6 +61,8 @@
{
if (!p_lcb->in_use)
{
+ alarm_free(p_lcb->l2c_lcb_timer);
+ alarm_free(p_lcb->info_resp_timer);
memset (p_lcb, 0, sizeof (tL2C_LCB));
memcpy (p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN);
@@ -67,8 +71,8 @@
p_lcb->link_state = LST_DISCONNECTED;
p_lcb->handle = HCI_INVALID_HANDLE;
p_lcb->link_flush_tout = 0xFFFF;
- p_lcb->timer_entry.param = (timer_param_t)p_lcb;
- p_lcb->info_timer_entry.param = (timer_param_t)p_lcb;
+ p_lcb->l2c_lcb_timer = alarm_new("l2c_lcb.l2c_lcb_timer");
+ p_lcb->info_resp_timer = alarm_new("l2c_lcb.info_resp_timer");
p_lcb->idle_timeout = l2cb.idle_timeout;
p_lcb->id = 1; /* spec does not allow '0' */
p_lcb->is_bonding = is_bonding;
@@ -127,8 +131,8 @@
**
** Function l2cu_release_lcb
**
-** Description Release an LCB. All timers will be stopped, channels
-** dropped, buffers returned etc.
+** Description Release an LCB. All timers will be stopped and freed,
+** channels dropped, buffers returned etc.
**
** Returns void
**
@@ -140,9 +144,11 @@
p_lcb->in_use = FALSE;
p_lcb->is_bonding = FALSE;
- /* Stop timers */
- btu_stop_timer (&p_lcb->timer_entry);
- btu_stop_timer (&p_lcb->info_timer_entry);
+ /* Stop and free timers */
+ alarm_free(p_lcb->l2c_lcb_timer);
+ p_lcb->l2c_lcb_timer = NULL;
+ alarm_free(p_lcb->info_resp_timer);
+ p_lcb->info_resp_timer = NULL;
/* Release any unfinished L2CAP packet on this link */
if (p_lcb->p_hcit_rcv_acl)
@@ -1110,7 +1116,9 @@
UINT16_TO_STREAM (p, info_type);
p_lcb->w4_info_rsp = TRUE;
- btu_start_timer (&p_lcb->info_timer_entry, BTU_TTYPE_L2CAP_INFO, L2CAP_WAIT_INFO_RSP_TOUT);
+ alarm_set_on_queue(p_lcb->info_resp_timer, L2CAP_WAIT_INFO_RSP_TIMEOUT_MS,
+ l2c_info_resp_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
l2c_link_check_send_pkts (p_lcb, NULL, p_buf);
}
@@ -1554,24 +1562,18 @@
memset (&p_ccb->ertm_info, 0, sizeof(tL2CAP_ERTM_INFO));
p_ccb->peer_cfg_already_rejected = FALSE;
p_ccb->fcr_cfg_tries = L2CAP_MAX_FCR_CFG_TRIES;
- p_ccb->fcrb.ack_timer.param = (timer_param_t)p_ccb;
- /* if timer is running, stop it */
- if (p_ccb->fcrb.ack_timer.in_use)
- btu_stop_quick_timer (&p_ccb->fcrb.ack_timer);
-
- p_ccb->fcrb.mon_retrans_timer.param = (timer_param_t)p_ccb;
+ alarm_free(p_ccb->fcrb.ack_timer);
+ p_ccb->fcrb.ack_timer = alarm_new("l2c_fcrb.ack_timer");
// btla-specific ++
/* CSP408639 Fix: When L2CAP send amp move channel request or receive
* L2CEVT_AMP_MOVE_REQ do following sequence. Send channel move
* request -> Stop retrans/monitor timer -> Change channel state to CST_AMP_MOVING. */
- if (p_ccb->fcrb.mon_retrans_timer.in_use)
- btu_stop_quick_timer (&p_ccb->fcrb.mon_retrans_timer);
+ alarm_free(p_ccb->fcrb.mon_retrans_timer);
+ p_ccb->fcrb.mon_retrans_timer = alarm_new("l2c_fcrb.mon_retrans_timer");
// btla-specific --
- l2c_fcr_stop_timer (p_ccb);
-
p_ccb->ertm_info.preferred_mode = L2CAP_FCR_BASIC_MODE; /* Default mode for channel is basic mode */
p_ccb->ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_BASIC; /* Default mode for channel is basic mode */
p_ccb->ertm_info.fcr_rx_buf_size = L2CAP_FCR_RX_BUF_SIZE;
@@ -1606,8 +1608,8 @@
p_ccb->is_flushable = FALSE;
#endif
- p_ccb->timer_entry.param = (timer_param_t)p_ccb;
- p_ccb->timer_entry.in_use = 0;
+ alarm_free(p_ccb->l2c_ccb_timer);
+ p_ccb->l2c_ccb_timer = alarm_new("l2c.l2c_ccb_timer");
l2c_link_adjust_chnl_allocation ();
@@ -1629,7 +1631,6 @@
*******************************************************************************/
BOOLEAN l2cu_start_post_bond_timer (UINT16 handle)
{
- UINT16 timeout;
tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle);
if (!p_lcb)
@@ -1642,26 +1643,22 @@
return (FALSE);
/* If no channels on the connection, start idle timeout */
- if ( (p_lcb->link_state == LST_CONNECTED) || (p_lcb->link_state == LST_CONNECTING) || (p_lcb->link_state == LST_DISCONNECTING) )
- {
- if (p_lcb->idle_timeout == 0)
- {
- if (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER))
- {
+ if ((p_lcb->link_state == LST_CONNECTED) ||
+ (p_lcb->link_state == LST_CONNECTING) ||
+ (p_lcb->link_state == LST_DISCONNECTING)) {
+ period_ms_t timeout_ms = L2CAP_BONDING_TIMEOUT * 1000;
+
+ if (p_lcb->idle_timeout == 0) {
+ if (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER)) {
p_lcb->link_state = LST_DISCONNECTING;
- timeout = L2CAP_LINK_DISCONNECT_TOUT;
+ timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS;
+ } else {
+ timeout_ms = BT_1SEC_TIMEOUT_MS;
}
- else
- timeout = BT_1SEC_TIMEOUT;
}
- else
- {
- timeout = L2CAP_BONDING_TIMEOUT;
- }
-
- if (timeout != 0xFFFF)
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, timeout);
-
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
return (TRUE);
}
@@ -1704,8 +1701,9 @@
btm_sec_clr_temp_auth_service (p_lcb->remote_bd_addr);
- /* Stop the timer */
- btu_stop_timer (&p_ccb->timer_entry);
+ /* Free the timer */
+ alarm_free(p_ccb->l2c_ccb_timer);
+ p_ccb->l2c_ccb_timer = NULL;
while (!fixed_queue_is_empty(p_ccb->xmit_hold_q))
osi_freebuf(fixed_queue_try_dequeue(p_ccb->xmit_hold_q));
@@ -2291,7 +2289,10 @@
if (BTM_SwitchRole (p_lcb_cur->remote_bd_addr, HCI_ROLE_MASTER, NULL) == BTM_CMD_STARTED)
{
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_LINK_ROLE_SWITCH_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
return (TRUE);
}
}
@@ -2400,8 +2401,10 @@
btm_acl_update_busy_level (BTM_BLI_PAGE_EVT);
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK,
- L2CAP_LINK_CONNECT_TOUT);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer,
+ L2CAP_LINK_CONNECT_TIMEOUT_MS,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
return (TRUE);
}
@@ -2699,7 +2702,7 @@
if ((p_ccb = l2cu_allocate_ccb (NULL, 0)) == NULL)
return (FALSE);
- btu_stop_timer(&p_lcb->timer_entry);
+ alarm_cancel(p_lcb->l2c_lcb_timer);
/* Set CID for the connection */
p_ccb->local_cid = fixed_cid;
@@ -2712,9 +2715,6 @@
p_ccb->is_flushable = FALSE;
- p_ccb->timer_entry.param = (timer_param_t)p_ccb;
-
-
if (p_fcr)
{
/* Set the FCR parameters. For now, we will use default pools */
@@ -2756,15 +2756,18 @@
void l2cu_no_dynamic_ccbs (tL2C_LCB *p_lcb)
{
tBTM_STATUS rc;
- UINT16 timeout = p_lcb->idle_timeout;
+ period_ms_t timeout_ms = p_lcb->idle_timeout * 1000;
+ bool start_timeout = true;
#if (L2CAP_NUM_FIXED_CHNLS > 0)
int xx;
for (xx = 0; xx < L2CAP_NUM_FIXED_CHNLS; xx++)
{
- if ( (p_lcb->p_fixed_ccbs[xx] != NULL) && (p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout > timeout) )
- timeout = p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout;
+ if ((p_lcb->p_fixed_ccbs[xx] != NULL) &&
+ (p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000 > timeout_ms)) {
+ timeout_ms = p_lcb->p_fixed_ccbs[xx]->fixed_chnl_idle_tout * 1000;
+ }
}
#endif
@@ -2772,7 +2775,7 @@
if (p_lcb->is_bonding)
return;
- if (timeout == 0)
+ if (timeout_ms == 0)
{
L2CAP_TRACE_DEBUG ("l2cu_no_dynamic_ccbs() IDLE timer 0, disconnecting link");
@@ -2781,37 +2784,37 @@
{
l2cu_process_fixed_disc_cback(p_lcb);
p_lcb->link_state = LST_DISCONNECTING;
- timeout = L2CAP_LINK_DISCONNECT_TOUT;
+ timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS;
}
else if (rc == BTM_SUCCESS)
{
l2cu_process_fixed_disc_cback(p_lcb);
/* BTM SEC will make sure that link is release (probably after pairing is done) */
p_lcb->link_state = LST_DISCONNECTING;
- timeout = 0xFFFF;
+ start_timeout = false;
}
else if ( (p_lcb->is_bonding)
&& (btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER)) )
{
l2cu_process_fixed_disc_cback(p_lcb);
p_lcb->link_state = LST_DISCONNECTING;
- timeout = L2CAP_LINK_DISCONNECT_TOUT;
+ timeout_ms = L2CAP_LINK_DISCONNECT_TIMEOUT_MS;
}
else
{
/* probably no buffer to send disconnect */
- timeout = BT_1SEC_TIMEOUT;
+ timeout_ms = BT_1SEC_TIMEOUT_MS;
}
}
- if (timeout != 0xFFFF)
- {
- L2CAP_TRACE_DEBUG ("l2cu_no_dynamic_ccbs() starting IDLE timeout: %d", timeout);
- btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, timeout);
- }
- else
- {
- btu_stop_timer(&p_lcb->timer_entry);
+ if (start_timeout) {
+ L2CAP_TRACE_DEBUG("%s starting IDLE timeout: %d ms", __func__,
+ timeout_ms);
+ alarm_set_on_queue(p_lcb->l2c_lcb_timer, timeout_ms,
+ l2c_lcb_timer_timeout, p_lcb,
+ btu_general_alarm_queue);
+ } else {
+ alarm_cancel(p_lcb->l2c_lcb_timer);
}
}
diff --git a/stack/mcap/mca_api.c b/stack/mcap/mca_api.c
index 48ae0e7..8ee8089 100644
--- a/stack/mcap/mca_api.c
+++ b/stack/mcap/mca_api.c
@@ -47,13 +47,11 @@
** Returns void
**
*******************************************************************************/
-void mca_process_timeout(timer_entry_t *p_te)
+void mca_ccb_timer_timeout(void *data)
{
- if (p_te->event == BTU_TTYPE_MCA_CCB_RSP)
- {
- p_te->event = 0;
- mca_ccb_event((tMCA_CCB *) p_te->param, MCA_CCB_RSP_TOUT_EVT, NULL);
- }
+ tMCA_CCB *p_ccb = (tMCA_CCB *)data;
+
+ mca_ccb_event(p_ccb, MCA_CCB_RSP_TOUT_EVT, NULL);
}
/*******************************************************************************
diff --git a/stack/mcap/mca_cact.c b/stack/mcap/mca_cact.c
index 329ab70..9884f9a 100644
--- a/stack/mcap/mca_cact.c
+++ b/stack/mcap/mca_cact.c
@@ -33,6 +33,9 @@
#include "btu.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*****************************************************************************
** constants
*****************************************************************************/
@@ -136,8 +139,10 @@
p_msg->hdr.layer_specific = TRUE; /* mark this message as sent */
p_pkt->len = p - p_start;
L2CA_DataWrite (p_ccb->lcid, p_pkt);
- p_ccb->timer_entry.param = (timer_param_t)p_ccb;
- btu_start_timer(&p_ccb->timer_entry, BTU_TTYPE_MCA_CCB_RSP, p_ccb->p_rcb->reg.rsp_tout);
+ period_ms_t interval_ms = p_ccb->p_rcb->reg.rsp_tout * 1000;
+ alarm_set_on_queue(p_ccb->mca_ccb_timer, interval_ms,
+ mca_ccb_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
}
/* else the L2CAP channel is congested. keep the message to be sent later */
diff --git a/stack/mcap/mca_csm.c b/stack/mcap/mca_csm.c
index 0077f35..281b76b 100644
--- a/stack/mcap/mca_csm.c
+++ b/stack/mcap/mca_csm.c
@@ -166,11 +166,7 @@
*******************************************************************************/
void mca_stop_timer(tMCA_CCB *p_ccb)
{
- if (p_ccb->timer_entry.event == BTU_TTYPE_MCA_CCB_RSP)
- {
- btu_stop_timer(&p_ccb->timer_entry);
- p_ccb->timer_entry.event = 0;
- }
+ alarm_cancel(p_ccb->mca_ccb_timer);
}
/*******************************************************************************
@@ -270,6 +266,7 @@
if (p_ccb_tmp->state == MCA_CCB_NULL_ST)
{
p_ccb_tmp->p_rcb = p_rcb;
+ p_ccb_tmp->mca_ccb_timer = alarm_new("mca.mca_ccb_timer");
p_ccb_tmp->state = MCA_CCB_OPENING_ST;
p_ccb_tmp->cong = TRUE;
memcpy(p_ccb_tmp->peer_addr, bd_addr, BD_ADDR_LEN);
@@ -317,7 +314,8 @@
mca_ccb_report_event(p_ccb, MCA_DISCONNECT_IND_EVT, &evt_data);
}
mca_free_tc_tbl_by_lcid (p_ccb->lcid);
- memset (p_ccb, 0, sizeof (tMCA_CCB));
+ alarm_free(p_ccb->mca_ccb_timer);
+ memset(p_ccb, 0, sizeof(tMCA_CCB));
}
/*******************************************************************************
diff --git a/stack/mcap/mca_int.h b/stack/mcap/mca_int.h
index ae230f1..00a92f5 100644
--- a/stack/mcap/mca_int.h
+++ b/stack/mcap/mca_int.h
@@ -24,7 +24,7 @@
#ifndef MCA_INT_H
#define MCA_INT_H
#include "bt_common.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
#include "mca_api.h"
/*****************************************************************************
@@ -205,7 +205,7 @@
*/
typedef struct {
tMCA_RCB *p_rcb; /* the associated registration control block */
- timer_entry_t timer_entry; /* CCB timer entry */
+ alarm_t *mca_ccb_timer; /* MCA CCB timer entry */
tMCA_CCB_MSG *p_tx_req; /* Current request being sent/awaiting response */
tMCA_CCB_MSG *p_rx_msg; /* Current message received/being processed */
BD_ADDR peer_addr; /* BD address of peer */
@@ -319,7 +319,7 @@
extern tMCA_RCB *mca_rcb_by_handle(tMCA_HANDLE handle);
extern BOOLEAN mca_is_valid_dep_id(tMCA_RCB *p_rcb, tMCA_DEP dep);
extern void mca_free_buf(void **p_buf);
-extern void mca_process_timeout(timer_entry_t *p_te);
+extern void mca_ccb_timer_timeout(void *data);
extern void mca_stop_timer(tMCA_CCB *p_ccb);
/* l2c functions */
diff --git a/stack/rfcomm/port_int.h b/stack/rfcomm/port_int.h
index f6d4b5c..72bdeb1 100644
--- a/stack/rfcomm/port_int.h
+++ b/stack/rfcomm/port_int.h
@@ -26,8 +26,8 @@
#define PORT_INT_H
#include "bt_target.h"
+#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
-#include "osi/include/non_repeating_timer.h"
#include "bt_common.h"
#include "rfcdefs.h"
#include "port_api.h"
@@ -92,7 +92,7 @@
*/
typedef struct
{
- timer_entry_t timer_entry; /* Timer entry */
+ alarm_t *mcb_timer; /* MCB timer */
fixed_queue_t *cmd_q; /* Queue for command messages on this mux */
UINT8 port_inx[RFCOMM_MAX_DLCI + 1]; /* Array for quick access to */
/* tPORT based on dlci */
@@ -116,8 +116,7 @@
/*
** RFCOMM Port Connection Control Block
*/
-struct t_rfc_port
-{
+typedef struct {
#define RFC_PORT_STATE_IDLE 0
#define RFC_PORT_STATE_WAIT_START 1
#define RFC_PORT_STATE_OPENING 2
@@ -136,15 +135,14 @@
tRFC_MCB *p_mcb;
- timer_entry_t timer_entry; /* Timer entry */
-};
-typedef struct t_rfc_port tRFC_PORT;
+ alarm_t *port_timer;
+} tRFC_PORT;
/*
** Define control block containing information about PORT connection
*/
-struct t_port_info
+typedef struct
{
UINT8 inx; /* Index of this control block in the port_info array */
BOOLEAN in_use; /* True when structure is allocated */
@@ -206,8 +204,7 @@
BOOLEAN keep_port_handle; /* TRUE if port is not deallocated when closing */
/* it is set to TRUE for server when allocating port */
UINT16 keep_mtu; /* Max MTU that port can receive by server */
-};
-typedef struct t_port_info tPORT;
+} tPORT;
/* Define the PORT/RFCOMM control structure
diff --git a/stack/rfcomm/port_utils.c b/stack/rfcomm/port_utils.c
index b1eaee8..9b7df13 100644
--- a/stack/rfcomm/port_utils.c
+++ b/stack/rfcomm/port_utils.c
@@ -77,7 +77,8 @@
{
fixed_queue_free(p_port->tx.queue, NULL);
fixed_queue_free(p_port->rx.queue, NULL);
- memset (p_port, 0, sizeof (tPORT));
+ alarm_free(p_port->rfc.port_timer);
+ memset(p_port, 0, sizeof (tPORT));
p_port->in_use = TRUE;
p_port->inx = yy + 1;
@@ -113,6 +114,7 @@
{
fixed_queue_free(p_port->tx.queue, NULL);
fixed_queue_free(p_port->rx.queue, NULL);
+ alarm_free(p_port->rfc.port_timer);
p_port->ev_mask = 0;
p_port->p_callback = NULL;
@@ -136,6 +138,7 @@
memset (&p_port->tx, 0, sizeof (p_port->tx));
p_port->rx.queue = fixed_queue_new(SIZE_MAX);
p_port->tx.queue = fixed_queue_new(SIZE_MAX);
+ p_port->rfc.port_timer = alarm_new("rfcomm_port.port_timer");
}
/*******************************************************************************
@@ -234,6 +237,8 @@
mutex_global_unlock();
+ alarm_cancel(p_port->rfc.port_timer);
+
p_port->state = PORT_STATE_CLOSED;
if (p_port->rfc.state == RFC_STATE_CLOSED)
@@ -276,9 +281,11 @@
RFCOMM_TRACE_DEBUG ("port_release_port:Clean-up handle:%d", p_port->inx);
fixed_queue_free(p_port->tx.queue, NULL);
fixed_queue_free(p_port->rx.queue, NULL);
+ alarm_free(p_port->rfc.port_timer);
memset (p_port, 0, sizeof (tPORT));
p_port->rx.queue = fixed_queue_new(SIZE_MAX);
p_port->tx.queue = fixed_queue_new(SIZE_MAX);
+ p_port->rfc.port_timer = alarm_new("rfcomm_port.port_timer");
}
}
}
diff --git a/stack/rfcomm/rfc_utils.c b/stack/rfcomm/rfc_utils.c
index 53fdc0d..8d8c345 100644
--- a/stack/rfcomm/rfc_utils.c
+++ b/stack/rfcomm/rfc_utils.c
@@ -37,6 +37,8 @@
#include <string.h>
+extern fixed_queue_t *btu_general_alarm_queue;
+
/*******************************************************************************
**
** Function rfc_calc_fcs
@@ -170,12 +172,14 @@
if (rfc_cb.port.rfc_mcb[j].state == RFC_MX_STATE_IDLE)
{
/* New multiplexer control block */
+ alarm_free(p_mcb->mcb_timer);
fixed_queue_free(p_mcb->cmd_q, NULL);
memset (p_mcb, 0, sizeof (tRFC_MCB));
memcpy (p_mcb->bd_addr, bd_addr, BD_ADDR_LEN);
RFCOMM_TRACE_DEBUG("rfc_alloc_multiplexer_channel:is_initiator:%d, create new p_mcb:%p, index:%d",
is_initiator, &rfc_cb.port.rfc_mcb[j], j);
+ p_mcb->mcb_timer = alarm_new("rfcomm_mcb.mcb_timer");
p_mcb->cmd_q = fixed_queue_new(SIZE_MAX);
p_mcb->is_initiator = is_initiator;
@@ -203,6 +207,7 @@
void *p_buf;
rfc_timer_stop (p_mcb);
+ alarm_free(p_mcb->mcb_timer);
while ((p_buf = fixed_queue_try_dequeue(p_mcb->cmd_q)) != NULL)
osi_freebuf(p_buf);
@@ -220,15 +225,14 @@
** Description Start RFC Timer
**
*******************************************************************************/
-void rfc_timer_start (tRFC_MCB *p_mcb, UINT16 timeout)
+void rfc_timer_start(tRFC_MCB *p_mcb, UINT16 timeout)
{
- timer_entry_t *p_te = &p_mcb->timer_entry;
+ RFCOMM_TRACE_EVENT ("%s - timeout:%d seconds", __func__, timeout);
- RFCOMM_TRACE_EVENT ("rfc_timer_start - timeout:%d", timeout);
-
- p_te->param = p_mcb;
-
- btu_start_timer (p_te, BTU_TTYPE_RFCOMM_MFC, timeout);
+ period_ms_t interval_ms = timeout * 1000;
+ alarm_set_on_queue(p_mcb->mcb_timer, interval_ms,
+ rfcomm_mcb_timer_timeout, p_mcb,
+ btu_general_alarm_queue);
}
@@ -239,11 +243,11 @@
** Description Stop RFC Timer
**
*******************************************************************************/
-void rfc_timer_stop (tRFC_MCB *p_mcb)
+void rfc_timer_stop(tRFC_MCB *p_mcb)
{
- RFCOMM_TRACE_EVENT ("rfc_timer_stop");
+ RFCOMM_TRACE_EVENT("%s", __func__);
- btu_stop_timer (&p_mcb->timer_entry);
+ alarm_cancel(p_mcb->mcb_timer);
}
@@ -254,18 +258,16 @@
** Description Start RFC Timer
**
*******************************************************************************/
-void rfc_port_timer_start (tPORT *p_port, UINT16 timeout)
+void rfc_port_timer_start(tPORT *p_port, UINT16 timeout)
{
- timer_entry_t *p_te = &p_port->rfc.timer_entry;
+ RFCOMM_TRACE_EVENT("%s - timeout:%d seconds", __func__, timeout);
- RFCOMM_TRACE_EVENT ("rfc_port_timer_start - timeout:%d", timeout);
-
- p_te->param = p_port;
-
- btu_start_timer (p_te, BTU_TTYPE_RFCOMM_PORT, timeout);
+ period_ms_t interval_ms = timeout * 1000;
+ alarm_set_on_queue(p_port->rfc.port_timer, interval_ms,
+ rfcomm_port_timer_timeout, p_port,
+ btu_general_alarm_queue);
}
-
/*******************************************************************************
**
** Function rfc_port_timer_stop
@@ -273,11 +275,11 @@
** Description Stop RFC Timer
**
*******************************************************************************/
-void rfc_port_timer_stop (tPORT *p_port)
+void rfc_port_timer_stop(tPORT *p_port)
{
- RFCOMM_TRACE_EVENT ("rfc_port_timer_stop");
+ RFCOMM_TRACE_EVENT ("%s", __func__);
- btu_stop_timer (&p_port->rfc.timer_entry);
+ alarm_cancel(p_port->rfc.port_timer);
}
@@ -314,33 +316,19 @@
rfc_timer_start (p_mcb, RFC_MCB_RELEASE_INACT_TIMER);
}
-
-/*******************************************************************************
-**
-** Function rfcomm_process_timeout
-**
-** Description The function called every second to check RFCOMM timers
-**
-** Returns void
-**
-*******************************************************************************/
-void rfcomm_process_timeout (timer_entry_t *p_te)
+void rfcomm_port_timer_timeout(void *data)
{
- switch (p_te->event)
- {
- case BTU_TTYPE_RFCOMM_MFC:
- rfc_mx_sm_execute ((tRFC_MCB *)p_te->param, RFC_EVENT_TIMEOUT, NULL);
- break;
+ tPORT *p_port = (tPORT *)data;
- case BTU_TTYPE_RFCOMM_PORT:
- rfc_port_sm_execute ((tPORT *)p_te->param, RFC_EVENT_TIMEOUT, NULL);
- break;
-
- default:
- break;
- }
+ rfc_port_sm_execute(p_port, RFC_EVENT_TIMEOUT, NULL);
}
+void rfcomm_mcb_timer_timeout(void *data)
+{
+ tRFC_MCB *p_mcb = (tRFC_MCB *)data;
+
+ rfc_mx_sm_execute(p_mcb, RFC_EVENT_TIMEOUT, NULL);
+}
/*******************************************************************************
**
diff --git a/stack/sdp/sdp_discovery.c b/stack/sdp/sdp_discovery.c
index 4616ca3..067d066 100644
--- a/stack/sdp/sdp_discovery.c
+++ b/stack/sdp/sdp_discovery.c
@@ -56,6 +56,7 @@
/* Safety check in case we go crazy */
#define MAX_NEST_LEVELS 5
+extern fixed_queue_t *btu_general_alarm_queue;
/*******************************************************************************
**
@@ -178,8 +179,8 @@
L2CA_DataWrite (p_ccb->connection_id, p_cmd);
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
-
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue);
}
/*******************************************************************************
@@ -232,7 +233,7 @@
#endif
/* stop inactivity timer when we receive a response */
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_cancel(p_ccb->sdp_conn_timer);
/* Got a reply!! Check what we got back */
p = (UINT8 *)(p_msg + 1) + p_msg->offset;
@@ -537,7 +538,9 @@
L2CA_DataWrite (p_ccb->connection_id, p_msg);
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
}
else
{
@@ -688,7 +691,9 @@
L2CA_DataWrite (p_ccb->connection_id, p_msg);
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
return;
}
diff --git a/stack/sdp/sdp_main.c b/stack/sdp/sdp_main.c
index 19f48b5..822b528 100644
--- a/stack/sdp/sdp_main.c
+++ b/stack/sdp/sdp_main.c
@@ -43,6 +43,8 @@
#include "sdpint.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
/********************************************************************************/
/* G L O B A L S D P D A T A */
/********************************************************************************/
@@ -379,16 +381,17 @@
{
p_ccb->con_state = SDP_STATE_CONNECTED;
- if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)
+ if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) {
sdp_disc_connected (p_ccb);
- else
+ } else {
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
+ }
}
-
}
-
/*******************************************************************************
**
** Function sdp_config_cfm
@@ -421,11 +424,14 @@
{
p_ccb->con_state = SDP_STATE_CONNECTED;
- if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)
+ if (p_ccb->con_flags & SDP_FLAGS_IS_ORIG) {
sdp_disc_connected (p_ccb);
- else
+ } else {
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb,
+ btu_general_alarm_queue);
+ }
}
}
else
@@ -692,7 +698,7 @@
/*******************************************************************************
**
-** Function sdp_conn_timeout
+** Function sdp_conn_timer_timeout
**
** Description This function processes a timeout. Currently, we simply send
** a disconnect request to L2CAP.
@@ -700,8 +706,10 @@
** Returns void
**
*******************************************************************************/
-void sdp_conn_timeout (tCONN_CB*p_ccb)
+void sdp_conn_timer_timeout(void *data)
{
+ tCONN_CB *p_ccb = (tCONN_CB *)data;
+
SDP_TRACE_EVENT ("SDP - CCB timeout in state: %d CID: 0x%x",
p_ccb->con_state, p_ccb->connection_id);
diff --git a/stack/sdp/sdp_server.c b/stack/sdp/sdp_server.c
index c28c342..c0dc6cf 100644
--- a/stack/sdp/sdp_server.c
+++ b/stack/sdp/sdp_server.c
@@ -42,6 +42,8 @@
#if SDP_SERVER_ENABLED == TRUE
+extern fixed_queue_t *btu_general_alarm_queue;
+
/* Maximum number of bytes to reserve out of SDP MTU for response data */
#define SDP_MAX_SERVICE_RSPHDR_LEN 12
#define SDP_MAX_SERVATTR_RSPHDR_LEN 10
@@ -121,7 +123,8 @@
/* Start inactivity timer */
- btu_start_timer (&p_ccb->timer_entry, BTU_TTYPE_SDP, SDP_INACT_TIMEOUT);
+ alarm_set_on_queue(p_ccb->sdp_conn_timer, SDP_INACT_TIMEOUT_MS,
+ sdp_conn_timer_timeout, p_ccb, btu_general_alarm_queue);
/* The first byte in the message is the pdu type */
pdu_id = *p_req++;
diff --git a/stack/sdp/sdp_utils.c b/stack/sdp/sdp_utils.c
index fa196ee..61f3594 100644
--- a/stack/sdp/sdp_utils.c
+++ b/stack/sdp/sdp_utils.c
@@ -120,10 +120,8 @@
{
if (p_ccb->con_state == SDP_STATE_IDLE)
{
- memset (p_ccb, 0, sizeof (tCONN_CB));
-
- p_ccb->timer_entry.param = p_ccb;
-
+ memset(p_ccb, 0, sizeof(tCONN_CB));
+ p_ccb->sdp_conn_timer = alarm_new("sdp.sdp_conn_timer");
return (p_ccb);
}
}
@@ -145,7 +143,8 @@
void sdpu_release_ccb (tCONN_CB *p_ccb)
{
/* Ensure timer is stopped */
- btu_stop_timer (&p_ccb->timer_entry);
+ alarm_free(p_ccb->sdp_conn_timer);
+ p_ccb->sdp_conn_timer = NULL;
/* Drop any response pointer we may be holding */
p_ccb->con_state = SDP_STATE_IDLE;
diff --git a/stack/sdp/sdpint.h b/stack/sdp/sdpint.h
index 3a2cfdd..bfd17ad 100644
--- a/stack/sdp/sdpint.h
+++ b/stack/sdp/sdpint.h
@@ -26,7 +26,7 @@
#define SDP_INT_H
#include "bt_target.h"
-#include "osi/include/non_repeating_timer.h"
+#include "osi/include/alarm.h"
#include "sdp_api.h"
#include "l2c_api.h"
@@ -36,7 +36,7 @@
#define SDP_MAX_CONTINUATION_LEN 16 /* As per the spec */
/* Timeout definitions. */
-#define SDP_INACT_TIMEOUT 30 /* Inactivity timeout */
+#define SDP_INACT_TIMEOUT_MS (30 * 1000) /* Inactivity timeout (in ms) */
/* Define the Out-Flow default values. */
@@ -179,7 +179,7 @@
UINT8 con_flags;
BD_ADDR device_address;
- timer_entry_t timer_entry;
+ alarm_t *sdp_conn_timer;
UINT16 rem_mtu_size;
UINT16 connection_id;
UINT16 list_len; /* length of the response in the GKI buffer */
@@ -265,7 +265,7 @@
extern void sdp_conn_rcv_l2e_connected (BT_HDR *p_msg);
extern void sdp_conn_rcv_l2e_conn_failed (BT_HDR *p_msg);
extern void sdp_conn_rcv_l2e_data (BT_HDR *p_msg);
-extern void sdp_conn_timeout (tCONN_CB *p_ccb);
+extern void sdp_conn_timer_timeout(void *data);
extern tCONN_CB *sdp_conn_originate (UINT8 *p_bd_addr);
diff --git a/stack/smp/smp_api.c b/stack/smp/smp_api.c
index 4d7b16d..03f7518 100644
--- a/stack/smp/smp_api.c
+++ b/stack/smp/smp_api.c
@@ -49,6 +49,7 @@
void SMP_Init(void)
{
memset(&smp_cb, 0, sizeof(tSMP_CB));
+ smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent");
#if defined(SMP_INITIAL_TRACE_LEVEL)
smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL;
diff --git a/stack/smp/smp_int.h b/stack/smp/smp_int.h
index 2d2f7ea..e0cfe63 100644
--- a/stack/smp/smp_int.h
+++ b/stack/smp/smp_int.h
@@ -50,7 +50,7 @@
#define SMP_MAX_CONN 2
#endif
-#define SMP_WAIT_FOR_RSP_TOUT 30
+#define SMP_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000)
#define SMP_OPCODE_INIT 0x04
@@ -268,7 +268,7 @@
typedef struct
{
tSMP_CALLBACK *p_callback;
- timer_entry_t rsp_timer_ent;
+ alarm_t *smp_rsp_timer_ent;
UINT8 trace_level;
BD_ADDR pairing_bda;
tSMP_STATE state;
@@ -479,7 +479,7 @@
extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb);
extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey);
extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 * p_data);
-extern void smp_rsp_timeout(timer_entry_t *p_te);
+extern void smp_rsp_timeout(void *data);
extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b);
extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
UINT8 *plain_text, UINT8 pt_len,
diff --git a/stack/smp/smp_l2c.c b/stack/smp/smp_l2c.c
index 06eaeea..164612f 100644
--- a/stack/smp/smp_l2c.c
+++ b/stack/smp/smp_l2c.c
@@ -33,6 +33,8 @@
#include "smp_int.h"
+extern fixed_queue_t *btu_general_alarm_queue;
+
static void smp_tx_complete_callback(UINT16 cid, UINT16 num_pkt);
static void smp_connect_callback(UINT16 channel, BD_ADDR bd_addr, BOOLEAN connected, UINT16 reason,
@@ -177,9 +179,9 @@
if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0)
{
- btu_stop_timer (&p_cb->rsp_timer_ent);
- btu_start_timer (&p_cb->rsp_timer_ent, BTU_TTYPE_SMP_PAIRING_CMD,
- SMP_WAIT_FOR_RSP_TOUT);
+ alarm_set_on_queue(p_cb->smp_rsp_timer_ent,
+ SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL,
+ btu_general_alarm_queue);
if (cmd == SMP_OPCODE_CONFIRM)
{
@@ -328,9 +330,9 @@
if (memcmp(&bd_addr[0], p_cb->pairing_bda, BD_ADDR_LEN) == 0)
{
- btu_stop_timer (&p_cb->rsp_timer_ent);
- btu_start_timer (&p_cb->rsp_timer_ent, BTU_TTYPE_SMP_PAIRING_CMD,
- SMP_WAIT_FOR_RSP_TOUT);
+ alarm_set_on_queue(p_cb->smp_rsp_timer_ent,
+ SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL,
+ btu_general_alarm_queue);
p_cb->rcvd_cmd_code = cmd;
p_cb->rcvd_cmd_len = (UINT8) p_buf->len;
diff --git a/stack/smp/smp_utils.c b/stack/smp/smp_utils.c
index ae62e8b..d9b456f 100644
--- a/stack/smp/smp_utils.c
+++ b/stack/smp/smp_utils.c
@@ -37,6 +37,9 @@
#include "device/include/controller.h"
#include "btm_int.h"
+
+extern fixed_queue_t *btu_general_alarm_queue;
+
#define SMP_PAIRING_REQ_SIZE 7
#define SMP_CONFIRM_CMD_SIZE (BT_OCTET16_LEN + 1)
#define SMP_RAND_CMD_SIZE (BT_OCTET16_LEN + 1)
@@ -324,10 +327,9 @@
smp_send_msg_to_L2CAP(p_cb->pairing_bda, p_buf))
{
sent = TRUE;
-
- btu_stop_timer (&p_cb->rsp_timer_ent);
- btu_start_timer (&p_cb->rsp_timer_ent, BTU_TTYPE_SMP_PAIRING_CMD,
- SMP_WAIT_FOR_RSP_TOUT);
+ alarm_set_on_queue(p_cb->smp_rsp_timer_ent,
+ SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout,
+ NULL, btu_general_alarm_queue);
}
}
@@ -354,11 +356,10 @@
** Returns void
**
*******************************************************************************/
-void smp_rsp_timeout(timer_entry_t *p_te)
+void smp_rsp_timeout(UNUSED_ATTR void *data)
{
tSMP_CB *p_cb = &smp_cb;
UINT8 failure = SMP_RSP_TIMEOUT;
- UNUSED(p_te);
SMP_TRACE_EVENT("%s state:%d br_state:%d", __FUNCTION__, p_cb->state, p_cb->br_state);
@@ -872,6 +873,7 @@
SMP_TRACE_EVENT("smp_cb_cleanup");
+ alarm_free(p_cb->smp_rsp_timer_ent);
memset(p_cb, 0, sizeof(tSMP_CB));
p_cb->p_callback = p_callback;
p_cb->trace_level = trace_level;
@@ -909,8 +911,9 @@
*******************************************************************************/
void smp_reset_control_value(tSMP_CB *p_cb)
{
- SMP_TRACE_EVENT("smp_reset_control_value");
- btu_stop_timer (&p_cb->rsp_timer_ent);
+ SMP_TRACE_EVENT("%s", __func__);
+
+ alarm_cancel(p_cb->smp_rsp_timer_ent);
p_cb->flags = 0;
/* set the link idle timer to drop the link when pairing is done
usually service discovery will follow authentication complete, to avoid
@@ -1118,7 +1121,7 @@
** Description Always returns TRUE.
**
*******************************************************************************/
-BOOLEAN smp_parameter_unconditionally_valid(tSMP_CB *p_cb)
+BOOLEAN smp_parameter_unconditionally_valid(UNUSED_ATTR tSMP_CB *p_cb)
{
return TRUE;
}
@@ -1130,7 +1133,7 @@
** Description Always returns FALSE.
**
*******************************************************************************/
-BOOLEAN smp_parameter_unconditionally_invalid(tSMP_CB *p_cb)
+BOOLEAN smp_parameter_unconditionally_invalid(UNUSED_ATTR tSMP_CB *p_cb)
{
return FALSE;
}