******************************************************************************/
tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle,
uint16_t val_len, uint8_t* p_val) {
- tGATT_STATUS cmd_status = GATT_NO_RESOURCES;
- tGATT_VALUE indication;
- BT_HDR* p_msg;
- tGATT_VALUE* p_buf;
tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id);
uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
if (!GATT_HANDLE_IS_VALID(attr_handle)) return GATT_ILLEGAL_PARAMETER;
+ tGATT_VALUE indication;
indication.conn_id = conn_id;
indication.handle = attr_handle;
indication.len = val_len;
if (GATT_HANDLE_IS_VALID(p_tcb->indicate_handle)) {
VLOG(1) << "Add a pending indication";
- p_buf = gatt_add_pending_ind(p_tcb, &indication);
- if (p_buf != NULL) {
- cmd_status = GATT_SUCCESS;
- } else {
- cmd_status = GATT_NO_RESOURCES;
- }
- } else {
- tGATT_SR_MSG gatt_sr_msg;
- gatt_sr_msg.attr_value = indication;
- p_msg = attp_build_sr_msg(*p_tcb, GATT_HANDLE_VALUE_IND, &gatt_sr_msg);
- if (p_msg != NULL) {
- cmd_status = attp_send_sr_msg(*p_tcb, p_msg);
-
- if (cmd_status == GATT_SUCCESS || cmd_status == GATT_CONGESTED) {
- p_tcb->indicate_handle = indication.handle;
- gatt_start_conf_timer(p_tcb);
- }
- }
+ gatt_add_pending_ind(p_tcb, &indication);
+ return GATT_SUCCESS;
+ }
+
+ tGATT_SR_MSG gatt_sr_msg;
+ gatt_sr_msg.attr_value = indication;
+ BT_HDR* p_msg =
+ attp_build_sr_msg(*p_tcb, GATT_HANDLE_VALUE_IND, &gatt_sr_msg);
+ if (!p_msg) return GATT_NO_RESOURCES;
+
+ tGATT_STATUS cmd_status = attp_send_sr_msg(*p_tcb, p_msg);
+ if (cmd_status == GATT_SUCCESS || cmd_status == GATT_CONGESTED) {
+ p_tcb->indicate_handle = indication.handle;
+ gatt_start_conf_timer(p_tcb);
}
return cmd_status;
}
******************************************************************************/
void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
tBT_TRANSPORT transport) {
- tGATT_TCB* p_tcb;
bool status = false;
- p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
+ tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
if (p_tcb != NULL) {
if (p_tcb->att_lcid == L2CAP_ATT_CID) {
status = L2CA_SetFixedChannelTout(bd_addr, L2CAP_ATT_CID, idle_tout);
tGATT_TCB* p_tcb;
int i, j;
for (i = 0, p_tcb = gatt_cb.tcb; i < GATT_MAX_PHY_CHANNEL; i++, p_tcb++) {
- if (p_tcb->in_use) {
- if (gatt_get_ch_state(p_tcb) != GATT_CH_CLOSE) {
- gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
- }
+ if (!p_tcb->in_use) continue;
- tGATT_CLCB* p_clcb;
- for (j = 0, p_clcb = &gatt_cb.clcb[j]; j < GATT_CL_MAX_LCB;
- j++, p_clcb++) {
- if (p_clcb->in_use && (p_clcb->p_reg->gatt_if == gatt_if) &&
- (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx)) {
- alarm_cancel(p_clcb->gatt_rsp_timer_ent);
- gatt_clcb_dealloc(p_clcb);
- break;
- }
+ if (gatt_get_ch_state(p_tcb) != GATT_CH_CLOSE) {
+ gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
+ }
+
+ tGATT_CLCB* p_clcb;
+ for (j = 0, p_clcb = &gatt_cb.clcb[j]; j < GATT_CL_MAX_LCB; j++, p_clcb++) {
+ if (p_clcb->in_use && (p_clcb->p_reg->gatt_if == gatt_if) &&
+ (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx)) {
+ alarm_cancel(p_clcb->gatt_rsp_timer_ent);
+ gatt_clcb_dealloc(p_clcb);
+ break;
}
}
}
bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
tBT_TRANSPORT transport, bool opportunistic,
uint8_t initiating_phys) {
- tGATT_REG* p_reg;
- bool status = false;
-
LOG(INFO) << __func__ << "gatt_if=" << +gatt_if << " " << bd_addr;
/* Make sure app is registered */
- p_reg = gatt_get_regcb(gatt_if);
- if (p_reg == NULL) {
+ tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
+ if (!p_reg) {
LOG(ERROR) << "gatt_if = " << +gatt_if << " is not registered";
return (false);
}
if (is_direct)
- status = gatt_act_connect(p_reg, bd_addr, transport, opportunistic,
- initiating_phys);
- else {
- if (transport == BT_TRANSPORT_LE)
- status = gatt_auto_connect_dev_add(p_reg, bd_addr);
- else {
- LOG(ERROR) << "Unsupported transport for background connection";
- }
- }
+ return gatt_act_connect(p_reg, bd_addr, transport, opportunistic,
+ initiating_phys);
- return status;
+ // is not direct
+ if (transport != BT_TRANSPORT_LE) {
+ LOG(ERROR) << "Unsupported transport for background connection";
+ return false;
+ }
+ return gatt_auto_connect_dev_add(p_reg, bd_addr);
}
/*******************************************************************************
*
******************************************************************************/
tGATT_STATUS GATT_Disconnect(uint16_t conn_id) {
- tGATT_STATUS ret = GATT_ILLEGAL_PARAMETER;
- tGATT_TCB* p_tcb = NULL;
- tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id);
- uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
-
LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id);
- p_tcb = gatt_get_tcb_by_idx(tcb_idx);
+ uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
+ tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx);
+ if (!p_tcb) return GATT_ILLEGAL_PARAMETER;
- if (p_tcb) {
- gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
- ret = GATT_SUCCESS;
- }
- return ret;
+ tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id);
+ gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
+ return GATT_SUCCESS;
}
/*******************************************************************************
tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx);
- bool status = false;
VLOG(1) << __func__ << " conn_id=" << loghex(conn_id);
- if (p_tcb && p_reg) {
- bd_addr = p_tcb->peer_bda;
- *p_gatt_if = gatt_if;
- *p_transport = p_tcb->transport;
- status = true;
- }
- return status;
+ if (!p_tcb || !p_reg) return false;
+
+ bd_addr = p_tcb->peer_bda;
+ *p_gatt_if = gatt_if;
+ *p_transport = p_tcb->transport;
+ return true;
}
/*******************************************************************************