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;
/*******************************************************************************
**
/* release all queued indications */
while (!fixed_queue_is_empty(p_tcb->pending_ind_q))
- osi_freebuf(fixed_queue_try_dequeue(p_tcb->pending_ind_q));
+ osi_free(fixed_queue_try_dequeue(p_tcb->pending_ind_q));
fixed_queue_free(p_tcb->pending_ind_q, NULL);
p_tcb->pending_ind_q = NULL;
}
/* release all queued indications */
while (!fixed_queue_is_empty(p_tcb->pending_enc_clcb))
- osi_freebuf(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb));
+ osi_free(fixed_queue_try_dequeue(p_tcb->pending_enc_clcb));
fixed_queue_free(p_tcb->pending_enc_clcb, NULL);
p_tcb->pending_enc_clcb = NULL;
}
memcpy(req.srv_chg.bda, bd_addr, BD_ADDR_LEN);
(*gatt_cb.cb_info.p_srv_chg_callback)(GATTS_SRV_CHG_CMD_REMOVE_CLIENT,&req, NULL);
}
- osi_freebuf(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q,
+ osi_free(fixed_queue_try_remove_from_queue(gatt_cb.srv_chg_clt_q,
p_buf));
}
}
*******************************************************************************/
tGATT_VALUE *gatt_add_pending_ind(tGATT_TCB *p_tcb, tGATT_VALUE *p_ind)
{
+ tGATT_VALUE *p_buf = (tGATT_VALUE *)osi_malloc(sizeof(tGATT_VALUE));
+
GATT_TRACE_DEBUG("%s", __func__);
+ GATT_TRACE_DEBUG("enqueue a pending indication");
+
+ memcpy(p_buf, p_ind, sizeof(tGATT_VALUE));
+ fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf);
- tGATT_VALUE *p_buf = (tGATT_VALUE *)osi_getbuf((UINT16)sizeof(tGATT_VALUE));
- if (p_buf != NULL)
- {
- GATT_TRACE_DEBUG("enqueue a pending indication");
- memcpy(p_buf, p_ind, sizeof(tGATT_VALUE));
- fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf);
- }
return p_buf;
}
-
/*******************************************************************************
**
** Function gatt_add_pending_new_srv_start
*******************************************************************************/
tGATTS_PENDING_NEW_SRV_START *gatt_add_pending_new_srv_start(tGATTS_HNDL_RANGE *p_new_srv_start)
{
+ tGATTS_PENDING_NEW_SRV_START *p_buf =
+ (tGATTS_PENDING_NEW_SRV_START *)osi_malloc(sizeof(tGATTS_PENDING_NEW_SRV_START));
+
GATT_TRACE_DEBUG("%s", __func__);
+ GATT_TRACE_DEBUG("enqueue a new pending new srv start");
+
+ p_buf->p_new_srv_start = p_new_srv_start;
+ fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf);
- tGATTS_PENDING_NEW_SRV_START *p_buf =
- (tGATTS_PENDING_NEW_SRV_START *)osi_getbuf((UINT16)sizeof(tGATTS_PENDING_NEW_SRV_START));
- if (p_buf != NULL)
- {
- GATT_TRACE_DEBUG("enqueue a new pending new srv start");
- p_buf->p_new_srv_start = p_new_srv_start;
- fixed_queue_enqueue(gatt_cb.pending_new_srv_start_q, p_buf);
- }
return p_buf;
}
*******************************************************************************/
tGATTS_SRV_CHG *gatt_add_srv_chg_clt(tGATTS_SRV_CHG *p_srv_chg)
{
- GATT_TRACE_DEBUG ("%s", __func__);
+ tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)osi_malloc(sizeof(tGATTS_SRV_CHG));
- tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)osi_getbuf((UINT16)sizeof(tGATTS_SRV_CHG));
- if (p_buf != NULL)
- {
- GATT_TRACE_DEBUG ("enqueue a srv chg client");
- memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG));
- fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf);
- }
+ GATT_TRACE_DEBUG("%s", __func__);
+ GATT_TRACE_DEBUG("enqueue a srv chg client");
+
+ memcpy(p_buf, p_srv_chg, sizeof(tGATTS_SRV_CHG));
+ fixed_queue_enqueue(gatt_cb.srv_chg_clt_q, p_buf);
return p_buf;
}
-
/*******************************************************************************
**
** Function gatt_alloc_hdl_buffer
if (p)
{
while (!fixed_queue_is_empty(p->svc_db.svc_buffer))
- osi_freebuf(fixed_queue_try_dequeue(p->svc_db.svc_buffer));
+ osi_free(fixed_queue_try_dequeue(p->svc_db.svc_buffer));
fixed_queue_free(p->svc_db.svc_buffer, NULL);
memset(p, 0, sizeof(tGATT_HDL_LIST_ELEM));
}
if (memcmp(p_app_id, &p_elem->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0)
{
while (!fixed_queue_is_empty(p_elem->svc_db.svc_buffer))
- osi_freebuf(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer));
+ osi_free(fixed_queue_try_dequeue(p_elem->svc_db.svc_buffer));
fixed_queue_free(p_elem->svc_db.svc_buffer, NULL);
p_elem->svc_db.svc_buffer = NULL;
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->sr_cmd.multi_rsp_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->in_use = TRUE;
p_tcb->tcb_idx = i;
p_tcb->transport = transport;
**
** 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
*******************************************************************************/
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
** 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 &&
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
{
}
}
- 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
** 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);
}
/*******************************************************************************
**
{
if (p_clcb && p_clcb->in_use)
{
+ alarm_free(p_clcb->gatt_rsp_timer_ent);
memset(p_clcb, 0, sizeof(tGATT_CLCB));
}
}
}
}
- if (p_clcb->p_attr_buf)
- {
- osi_freebuf(p_clcb->p_attr_buf);
- }
+ osi_free_and_reset((void **)&p_clcb->p_attr_buf);
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);
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);
}
}
- 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);
+ p_tcb->sr_cmd.multi_rsp_q = NULL;
for (i = 0; i < GATT_MAX_APPS; i ++)
{
bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
}
else
- BCM_STRNCPY_S(str_buf, sizeof(str_buf), "Unknown UUID 0", 15);
+ strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf));
GATT_TRACE_DEBUG ("UUID=[%s]", str_buf);
-
}
*******************************************************************************/
tGATT_PENDING_ENC_CLCB* gatt_add_pending_enc_channel_clcb(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb)
{
- GATT_TRACE_DEBUG ("gatt_add_pending_new_srv_start");
-
tGATT_PENDING_ENC_CLCB *p_buf =
- (tGATT_PENDING_ENC_CLCB *)osi_getbuf((UINT16)sizeof(tGATT_PENDING_ENC_CLCB));
- if (p_buf != NULL)
- {
- GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb");
- p_buf->p_clcb = p_clcb;
- fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf);
- }
+ (tGATT_PENDING_ENC_CLCB *)osi_malloc(sizeof(tGATT_PENDING_ENC_CLCB));
+
+ GATT_TRACE_DEBUG ("%s", __func__);
+ GATT_TRACE_DEBUG("enqueue a new pending encryption channel clcb");
+
+ p_buf->p_clcb = p_clcb;
+ fixed_queue_enqueue(p_tcb->pending_enc_clcb, p_buf);
+
return p_buf;
}
/*******************************************************************************