From: Jakub Pawlowski Date: Thu, 25 Oct 2018 22:23:21 +0000 (+0200) Subject: Minor style fixes in gatt_api.cc X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0f79e3506994bf00c5fcfbf8d1669b189982b2f3;p=android-x86%2Fsystem-bt.git Minor style fixes in gatt_api.cc Test: compilation Change-Id: I3050d84443149a5ed77ab1e07f079553546b628c --- diff --git a/stack/gatt/gatt_api.cc b/stack/gatt/gatt_api.cc index e1ac2f7c1..a830137a6 100644 --- a/stack/gatt/gatt_api.cc +++ b/stack/gatt/gatt_api.cc @@ -407,11 +407,7 @@ void GATTS_StopService(uint16_t service_handle) { ******************************************************************************/ 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); @@ -425,6 +421,7 @@ tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle, 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; @@ -433,24 +430,20 @@ tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle, 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; } @@ -909,10 +902,9 @@ tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t handle) { ******************************************************************************/ 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); @@ -1021,20 +1013,19 @@ void GATT_Deregister(tGATT_IF gatt_if) { 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; } } } @@ -1107,30 +1098,25 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct, 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); } /******************************************************************************* @@ -1212,20 +1198,15 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& 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; } /******************************************************************************* @@ -1248,17 +1229,15 @@ bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if, 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; } /******************************************************************************* diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h index 060b3176a..e2cba48ce 100644 --- a/stack/gatt/gatt_int.h +++ b/stack/gatt/gatt_int.h @@ -461,7 +461,7 @@ extern bool gatt_find_the_connected_bda(uint8_t start_idx, RawAddress& bda, tBT_TRANSPORT* p_transport); extern void gatt_set_srv_chg(void); extern void gatt_delete_dev_from_srv_chg_clt_list(const RawAddress& bd_addr); -extern tGATT_VALUE* gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind); +extern void gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind); extern void gatt_free_srvc_db_buffer_app_id(const bluetooth::Uuid& app_id); extern bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb); diff --git a/stack/gatt/gatt_utils.cc b/stack/gatt/gatt_utils.cc index 25095a94e..f62cc5671 100644 --- a/stack/gatt/gatt_utils.cc +++ b/stack/gatt/gatt_utils.cc @@ -155,25 +155,13 @@ void gatt_set_srv_chg(void) { } } -/******************************************************************************* - * - * Function gatt_add_pending_ind - * - * Description Add a pending indication - * - * Returns Pointer to the current pending indication buffer, NULL no buffer - * available - * - ******************************************************************************/ -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)); - +/** Add a pending indication */ +void gatt_add_pending_ind(tGATT_TCB* p_tcb, tGATT_VALUE* p_ind) { VLOG(1) << __func__ << "enqueue a pending indication"; + tGATT_VALUE* p_buf = (tGATT_VALUE*)osi_malloc(sizeof(tGATT_VALUE)); memcpy(p_buf, p_ind, sizeof(tGATT_VALUE)); fixed_queue_enqueue(p_tcb->pending_ind_q, p_buf); - - return p_buf; } /*******************************************************************************