summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Manton <cmanton@google.com> 2024-05-13 16:15:21 -0700
committer Chris Manton <cmanton@google.com> 2024-05-24 22:29:04 +0000
commit012cdfd28e0796b7082e64b8c663ef500d450ced (patch)
tree8c91e58d7e563a68a89f5f355233c2f1ae771f30
parentff8e0e95362b1add50b059a1d2eb7013b2cff9c5 (diff)
stack::gatt Use nodiscard for API to ensure return values handled
Bug: 340342998 Test: m . Flag: EXEMPT, Logging Change Change-Id: Id87f47822fabc4fa0f21d34268d7dc10cf68de6c
-rw-r--r--system/bta/dm/bta_dm_act.cc10
-rw-r--r--system/bta/gatt/bta_gattc_act.cc60
-rw-r--r--system/bta/gatt/bta_gattc_cache.cc26
-rw-r--r--system/stack/fuzzers/gatt_fuzzer.cc22
-rw-r--r--system/stack/gap/gap_ble.cc17
-rw-r--r--system/stack/gatt/gatt_attr.cc107
-rw-r--r--system/stack/gatt/gatt_main.cc8
-rw-r--r--system/stack/gatt/gatt_sr.cc7
-rw-r--r--system/stack/include/gatt_api.h124
-rw-r--r--system/stack/srvc/srvc_eng.cc11
10 files changed, 273 insertions, 119 deletions
diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc
index 790180527c..981674876d 100644
--- a/system/bta/dm/bta_dm_act.cc
+++ b/system/bta/dm/bta_dm_act.cc
@@ -509,7 +509,10 @@ void bta_dm_remove_device(const RawAddress& bd_addr) {
peer_device.conn_state = BTA_DM_UNPAIRING;
/* Make sure device is not in acceptlist before we disconnect */
- GATT_CancelConnect(0, bd_addr, false);
+ if (!GATT_CancelConnect(0, bd_addr, false)) {
+ log::warn("Unable to cancel GATT connect peer:{} is_direct:{}",
+ bd_addr, false);
+ }
btm_remove_acl(bd_addr, peer_device.transport);
log::verbose("transport: {}", peer_device.transport);
@@ -562,7 +565,10 @@ void bta_dm_remove_device(const RawAddress& bd_addr) {
log::info("Remove ACL of address {}", other_address);
/* Make sure device is not in acceptlist before we disconnect */
- GATT_CancelConnect(0, bd_addr, false);
+ if (!GATT_CancelConnect(0, bd_addr, false)) {
+ log::warn("Unable to cancel GATT connect peer:{} is_direct:{}",
+ bd_addr, false);
+ }
btm_remove_acl(other_address, peer_device.transport);
break;
diff --git a/system/bta/gatt/bta_gattc_act.cc b/system/bta/gatt/bta_gattc_act.cc
index d0b7825dc6..1cdeacae34 100644
--- a/system/bta/gatt/bta_gattc_act.cc
+++ b/system/bta/gatt/bta_gattc_act.cc
@@ -236,8 +236,13 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) {
if (bta_gattc_cb.bg_track[i].cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) {
bta_gattc_mark_bg_conn(p_clreg->client_if,
bta_gattc_cb.bg_track[i].remote_bda, false);
- GATT_CancelConnect(p_clreg->client_if,
- bta_gattc_cb.bg_track[i].remote_bda, false);
+ if (!GATT_CancelConnect(p_clreg->client_if,
+ bta_gattc_cb.bg_track[i].remote_bda, false)) {
+ log::warn(
+ "Unable to cancel GATT connection client_if:{} peer:{} "
+ "is_direct:{}",
+ p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
+ }
}
}
@@ -521,8 +526,11 @@ void bta_gattc_conn(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
log::verbose("conn_id=0x{:x}", p_data->hdr.layer_specific);
p_clcb->bta_conn_id = p_data->int_conn.hdr.layer_specific;
- GATT_GetConnectionInfor(p_data->hdr.layer_specific, &gatt_if, p_clcb->bda,
- &p_clcb->transport);
+ if (!GATT_GetConnectionInfor(p_data->hdr.layer_specific, &gatt_if,
+ p_clcb->bda, &p_clcb->transport)) {
+ log::warn("Unable to get GATT connection information peer:{}",
+ p_clcb->bda);
+ }
}
p_clcb->p_srcb->connected = true;
@@ -1517,7 +1525,12 @@ static bool bta_gattc_process_srvc_chg_ind(uint16_t conn_id,
}
}
/* send confirmation here if this is an indication, it should always be */
- GATTC_SendHandleValueConfirm(conn_id, p_notify->cid);
+ if (GATTC_SendHandleValueConfirm(conn_id, p_notify->cid) != GATT_SUCCESS) {
+ log::warn(
+ "Unable to send GATT client handle value confirmation conn_id:{} "
+ "cid:{}",
+ conn_id, p_notify->cid);
+ }
/* if connection available, refresh cache by doing discovery now */
if (p_clcb) {
@@ -1570,24 +1583,42 @@ static void bta_gattc_process_indicate(uint16_t conn_id, tGATTC_OPTYPE op,
if (!GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport)) {
log::error("indication/notif for unknown app");
- if (op == GATTC_OPTYPE_INDICATION)
- GATTC_SendHandleValueConfirm(conn_id, p_data->cid);
+ if (op == GATTC_OPTYPE_INDICATION) {
+ if (GATTC_SendHandleValueConfirm(conn_id, p_data->cid) != GATT_SUCCESS) {
+ log::warn(
+ "Unable to send GATT client handle value confirmation conn_id:{} "
+ "cid:{}",
+ conn_id, p_data->cid);
+ }
+ }
return;
}
tBTA_GATTC_RCB* p_clrcb = bta_gattc_cl_get_regcb(gatt_if);
if (p_clrcb == NULL) {
log::error("indication/notif for unregistered app");
- if (op == GATTC_OPTYPE_INDICATION)
- GATTC_SendHandleValueConfirm(conn_id, p_data->cid);
+ if (op == GATTC_OPTYPE_INDICATION) {
+ if (GATTC_SendHandleValueConfirm(conn_id, p_data->cid) != GATT_SUCCESS) {
+ log::warn(
+ "Unable to send GATT client handle value confirmation conn_id:{} "
+ "cid:{}",
+ conn_id, p_data->cid);
+ }
+ }
return;
}
tBTA_GATTC_SERV* p_srcb = bta_gattc_find_srcb(remote_bda);
if (p_srcb == NULL) {
log::error("indication/notif for unknown device, ignore");
- if (op == GATTC_OPTYPE_INDICATION)
- GATTC_SendHandleValueConfirm(conn_id, p_data->cid);
+ if (op == GATTC_OPTYPE_INDICATION) {
+ if (GATTC_SendHandleValueConfirm(conn_id, p_data->cid) != GATT_SUCCESS) {
+ log::warn(
+ "Unable to send GATT client handle value confirmation conn_id:{} "
+ "cid:{}",
+ conn_id, p_data->cid);
+ }
+ }
return;
}
@@ -1624,7 +1655,12 @@ static void bta_gattc_process_indicate(uint16_t conn_id, tGATTC_OPTYPE op,
/* no one intersted and need ack? */
else if (op == GATTC_OPTYPE_INDICATION) {
log::verbose("no one interested, ack now");
- GATTC_SendHandleValueConfirm(conn_id, p_data->cid);
+ if (GATTC_SendHandleValueConfirm(conn_id, p_data->cid) != GATT_SUCCESS) {
+ log::warn(
+ "Unable to send GATT client handle value confirmation conn_id:{} "
+ "cid:{}",
+ conn_id, p_data->cid);
+ }
}
}
diff --git a/system/bta/gatt/bta_gattc_cache.cc b/system/bta/gatt/bta_gattc_cache.cc
index 2dac97b70e..6230e36db8 100644
--- a/system/bta/gatt/bta_gattc_cache.cc
+++ b/system/bta/gatt/bta_gattc_cache.cc
@@ -206,9 +206,8 @@ RobustCachingSupport GetRobustCachingSupport(const tBTA_GATTC_CLCB* p_clcb,
}
/** Start primary service discovery */
-tGATT_STATUS bta_gattc_discover_pri_service(uint16_t conn_id,
- tBTA_GATTC_SERV* p_server_cb,
- tGATT_DISC_TYPE disc_type) {
+[[nodiscard]] tGATT_STATUS bta_gattc_discover_pri_service(
+ uint16_t conn_id, tBTA_GATTC_SERV* p_server_cb, tGATT_DISC_TYPE disc_type) {
tBTA_GATTC_CLCB* p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
if (!p_clcb) return GATT_ERROR;
@@ -236,7 +235,10 @@ static void bta_gattc_explore_next_service(uint16_t conn_id,
log::verbose("Start service discovery");
/* start discovering included services */
- GATTC_Discover(conn_id, GATT_DISC_INC_SRVC, service.first, service.second);
+ if (GATTC_Discover(conn_id, GATT_DISC_INC_SRVC, service.first,
+ service.second) != GATT_SUCCESS) {
+ log::warn("Unable to discover GATT client conn_id:{}", conn_id);
+ }
return;
}
// No more services to discover
@@ -253,7 +255,10 @@ static void bta_gattc_explore_next_service(uint16_t conn_id,
if (p_srvc_cb->read_multiple_not_supported || descriptors.size() == 1) {
tGATT_READ_PARAM read_param{.by_handle = {.auth_req = GATT_AUTH_REQ_NONE,
.handle = descriptors.front()}};
- GATTC_Read(conn_id, GATT_READ_BY_HANDLE, &read_param);
+ if (GATTC_Read(conn_id, GATT_READ_BY_HANDLE, &read_param) !=
+ GATT_SUCCESS) {
+ log::warn("Unable to read GATT client conn_id:{}", conn_id);
+ }
// asynchronous continuation in bta_gattc_op_cmpl_during_discovery
return;
}
@@ -272,7 +277,9 @@ static void bta_gattc_explore_next_service(uint16_t conn_id,
read_param.read_multiple.auth_req = GATT_AUTH_REQ_NONE;
memcpy(&read_param.read_multiple.handles, descriptors.data(),
sizeof(uint16_t) * num_handles);
- GATTC_Read(conn_id, GATT_READ_MULTIPLE, &read_param);
+ if (GATTC_Read(conn_id, GATT_READ_MULTIPLE, &read_param) != GATT_SUCCESS) {
+ log::warn("Unable to read GATT client conn_id:{}", conn_id);
+ }
// asynchronous continuation in bta_gattc_op_cmpl_during_discovery
return;
@@ -331,7 +338,7 @@ void bta_gattc_start_disc_char_dscp(uint16_t conn_id,
}
if (GATTC_Discover(conn_id, GATT_DISC_CHAR_DSCPT, range.first,
- range.second) != 0) {
+ range.second) != GATT_SUCCESS) {
goto descriptor_discovery_done;
}
return;
@@ -557,7 +564,10 @@ void bta_gattc_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
case GATT_DISC_INC_SRVC: {
auto& service = p_srvc_cb->pending_discovery.CurrentlyExploredService();
/* start discovering characteristic */
- GATTC_Discover(conn_id, GATT_DISC_CHAR, service.first, service.second);
+ if (GATTC_Discover(conn_id, GATT_DISC_CHAR, service.first,
+ service.second) != GATT_SUCCESS) {
+ log::warn("Unable to discover GATT client conn_id:{}", conn_id);
+ }
break;
}
diff --git a/system/stack/fuzzers/gatt_fuzzer.cc b/system/stack/fuzzers/gatt_fuzzer.cc
index 01d82b8f52..f7aaf72422 100644
--- a/system/stack/fuzzers/gatt_fuzzer.cc
+++ b/system/stack/fuzzers/gatt_fuzzer.cc
@@ -187,7 +187,7 @@ static void ServerInit() {
.p_srv_chg_callback = [](tGATTS_SRV_CHG_CMD, tGATTS_SRV_CHG_REQ*,
tGATTS_SRV_CHG_RSP*) { return true; },
};
- GATTS_NVRegister(&appl_info);
+ (void)GATTS_NVRegister(&appl_info);
Uuid svc_uuid = Uuid::From16Bit(UUID_SERVCLASS_GAP_SERVER);
Uuid name_uuid = Uuid::From16Bit(GATT_UUID_GAP_DEVICE_NAME);
@@ -213,8 +213,8 @@ static void ServerInit() {
.permissions = GATT_PERM_READ}};
/* Add a GAP service */
- GATTS_AddService(s_AppIf, service,
- sizeof(service) / sizeof(btgatt_db_element_t));
+ (void)GATTS_AddService(s_AppIf, service,
+ sizeof(service) / sizeof(btgatt_db_element_t));
}
static void ServerCleanup() {
@@ -241,12 +241,12 @@ static void FuzzAsServer(FuzzedDataProvider& fdp) {
static void ClientInit() {
GattInit();
- GATT_Connect(s_AppIf, kDummyAddr, BTM_BLE_DIRECT_CONNECTION, BT_TRANSPORT_LE,
- false);
+ (void)GATT_Connect(s_AppIf, kDummyAddr, BTM_BLE_DIRECT_CONNECTION,
+ BT_TRANSPORT_LE, false);
}
static void ClientCleanup() {
- GATT_CancelConnect(s_AppIf, kDummyAddr, true);
+ (void)GATT_CancelConnect(s_AppIf, kDummyAddr, true);
GATT_Deregister(s_AppIf);
gatt_free();
}
@@ -261,7 +261,7 @@ static void FuzzAsClient(FuzzedDataProvider& fdp) {
switch (op) {
case GATTC_OPTYPE_CONFIG: {
auto mtu = fdp.ConsumeIntegral<uint16_t>();
- GATTC_ConfigureMTU(s_ConnId, mtu);
+ (void)GATTC_ConfigureMTU(s_ConnId, mtu);
break;
}
case GATTC_OPTYPE_DISCOVERY: {
@@ -269,7 +269,7 @@ static void FuzzAsClient(FuzzedDataProvider& fdp) {
0, GATT_DISC_MAX);
uint16_t start = fdp.ConsumeIntegral<uint16_t>();
uint16_t end = fdp.ConsumeIntegral<uint16_t>();
- GATTC_Discover(s_ConnId, type, start, end);
+ (void)GATTC_Discover(s_ConnId, type, start, end);
break;
}
case GATTC_OPTYPE_READ: {
@@ -277,7 +277,7 @@ static void FuzzAsClient(FuzzedDataProvider& fdp) {
0, GATT_READ_MAX);
tGATT_READ_PARAM param = {};
fdp.ConsumeData(&param, sizeof(param));
- GATTC_Read(s_ConnId, type, &param);
+ (void)GATTC_Read(s_ConnId, type, &param);
break;
}
case GATTC_OPTYPE_WRITE: {
@@ -287,12 +287,12 @@ static void FuzzAsClient(FuzzedDataProvider& fdp) {
value.len =
fdp.ConsumeIntegralInRange<uint16_t>(0, sizeof(value.value));
value.len = fdp.ConsumeData(&value.value, value.len);
- GATTC_Write(s_ConnId, type, &value);
+ (void)GATTC_Write(s_ConnId, type, &value);
break;
}
case GATTC_OPTYPE_EXE_WRITE: {
auto type = fdp.ConsumeBool();
- GATTC_ExecuteWrite(s_ConnId, type);
+ (void)GATTC_ExecuteWrite(s_ConnId, type);
break;
}
default:
diff --git a/system/stack/gap/gap_ble.cc b/system/stack/gap/gap_ble.cc
index a81489bf4f..f9d4e1cb7c 100644
--- a/system/stack/gap/gap_ble.cc
+++ b/system/stack/gap/gap_ble.cc
@@ -238,7 +238,11 @@ void server_attr_request_cback(uint16_t conn_id, uint32_t trans_id,
break;
}
- if (!ignore) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg);
+ if (!ignore) {
+ if (GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg) != GATT_SUCCESS) {
+ log::warn("Unable to send GATT ervier response conn_id:{}", conn_id);
+ }
+ }
}
/**
@@ -285,7 +289,9 @@ void cl_op_cmpl(tGAP_CLCB& clcb, bool status, uint16_t len, uint8_t* p_name) {
/* if no further activity is requested in callback, drop the link */
if (clcb.connected) {
if (!send_cl_read_request(clcb)) {
- GATT_Disconnect(clcb.conn_id);
+ if (GATT_Disconnect(clcb.conn_id) != GATT_SUCCESS) {
+ log::warn("Unable to disconnect GATT conn_id:{}", clcb.conn_id);
+ }
clcb_dealloc(clcb);
}
}
@@ -444,8 +450,11 @@ void gap_attr_db_init(void) {
};
/* Add a GAP service */
- GATTS_AddService(gatt_if, service,
- sizeof(service) / sizeof(btgatt_db_element_t));
+ if (GATTS_AddService(gatt_if, service,
+ sizeof(service) / sizeof(btgatt_db_element_t)) !=
+ GATT_SERVICE_STARTED) {
+ log::warn("Unable to add GATT services gatt_if:{}", gatt_if);
+ }
gatt_attr[0].uuid = GATT_UUID_GAP_DEVICE_NAME;
gatt_attr[0].handle = service[1].attribute_handle;
diff --git a/system/stack/gatt/gatt_attr.cc b/system/stack/gatt/gatt_attr.cc
index 327f440a9d..64bb0b070f 100644
--- a/system/stack/gatt/gatt_attr.cc
+++ b/system/stack/gatt/gatt_attr.cc
@@ -126,11 +126,22 @@ static tGATT_CBACK gatt_profile_cback = {
******************************************************************************/
uint16_t gatt_profile_find_conn_id_by_bd_addr(const RawAddress& remote_bda) {
uint16_t conn_id = GATT_INVALID_CONN_ID;
- GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
- BT_TRANSPORT_LE);
- if (conn_id == GATT_INVALID_CONN_ID)
- GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
- BT_TRANSPORT_BR_EDR);
+ if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
+ BT_TRANSPORT_LE)) {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ remote_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_LE));
+ }
+ if (conn_id == GATT_INVALID_CONN_ID) {
+ if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
+ BT_TRANSPORT_BR_EDR)) {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ remote_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_BR_EDR));
+ }
+ }
return conn_id;
}
@@ -336,7 +347,11 @@ static void gatt_request_cback(uint16_t conn_id, uint32_t trans_id,
break;
}
- if (rsp_needed) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg);
+ if (rsp_needed) {
+ if (GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg) != GATT_SUCCESS) {
+ log::warn("Unable to send GATT server response conn_id:{}", conn_id);
+ }
+ }
}
/*******************************************************************************
@@ -435,8 +450,11 @@ void gatt_profile_db_init(void) {
.permissions = GATT_PERM_READ,
}};
- GATTS_AddService(gatt_cb.gatt_if, service,
- sizeof(service) / sizeof(btgatt_db_element_t));
+ if (GATTS_AddService(gatt_cb.gatt_if, service,
+ sizeof(service) / sizeof(btgatt_db_element_t)) !=
+ GATT_SERVICE_STARTED) {
+ log::warn("Unable to add GATT server service gatt_if:{}", gatt_cb.gatt_if);
+ }
gatt_cb.handle_of_h_r = service[1].attribute_handle;
gatt_cb.handle_sr_supported_feat = service[2].attribute_handle;
@@ -693,18 +711,29 @@ static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB* p_clcb) {
switch (p_clcb->ccc_stage) {
case GATT_SVC_CHANGED_SERVICE: /* discover GATT service */
- GATTC_Discover(p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, 0x0001, 0xffff,
- Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER));
+ if (GATTC_Discover(p_clcb->conn_id, GATT_DISC_SRVC_BY_UUID, 0x0001,
+ 0xffff, Uuid::From16Bit(UUID_SERVCLASS_GATT_SERVER)) !=
+ GATT_SUCCESS) {
+ log::warn("Unable to discovery GATT client conn_id:{}",
+ p_clcb->conn_id);
+ }
break;
case GATT_SVC_CHANGED_CHARACTERISTIC: /* discover service change char */
- GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR, 0x0001, p_clcb->e_handle,
- Uuid::From16Bit(GATT_UUID_GATT_SRV_CHGD));
+ if (GATTC_Discover(
+ p_clcb->conn_id, GATT_DISC_CHAR, 0x0001, p_clcb->e_handle,
+ Uuid::From16Bit(GATT_UUID_GATT_SRV_CHGD)) != GATT_SUCCESS) {
+ log::warn("Unable to discovery GATT client conn_id:{}",
+ p_clcb->conn_id);
+ }
break;
case GATT_SVC_CHANGED_DESCRIPTOR: /* discover service change ccc */
- GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR_DSCPT, p_clcb->s_handle,
- p_clcb->e_handle);
+ if (GATTC_Discover(p_clcb->conn_id, GATT_DISC_CHAR_DSCPT,
+ p_clcb->s_handle, p_clcb->e_handle) != GATT_SUCCESS) {
+ log::warn("Unable to discovery GATT client conn_id:{}",
+ p_clcb->conn_id);
+ }
break;
case GATT_SVC_CHANGED_CONFIGURE_CCCD: /* write ccc */
@@ -714,7 +743,11 @@ static void gatt_cl_start_config_ccc(tGATT_PROFILE_CLCB* p_clcb) {
ccc_value.handle = p_clcb->s_handle;
ccc_value.len = 2;
ccc_value.value[0] = GATT_CLT_CONFIG_INDICATION;
- GATTC_Write(p_clcb->conn_id, GATT_WRITE, &ccc_value);
+ if (GATTC_Write(p_clcb->conn_id, GATT_WRITE, &ccc_value) !=
+ GATT_SUCCESS) {
+ log::warn("Unable to write GATT client data conn_id:{}",
+ p_clcb->conn_id);
+ }
gatt_op_cb_data cb_data;
cb_data.cb = base::BindOnce(
@@ -749,10 +782,22 @@ void GATT_ConfigServiceChangeCCC(const RawAddress& remote_bda, bool enable,
if (GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &p_clcb->conn_id,
transport)) {
p_clcb->connected = true;
+ } else {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ remote_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_LE));
}
+
/* hold the link here */
- GATT_Connect(gatt_cb.gatt_if, remote_bda, BTM_BLE_DIRECT_CONNECTION,
- transport, true);
+ if (!GATT_Connect(gatt_cb.gatt_if, remote_bda, BTM_BLE_DIRECT_CONNECTION,
+ transport, true)) {
+ log::warn(
+ "Unable to connect GATT client gatt_if:{} peer:{} transport:{} "
+ "connection_tyoe:{} opporunistic:{}",
+ gatt_cb.gatt_if, remote_bda, bt_transport_text(transport),
+ "BTM_BLE_DIRECT_CONNECTION", true);
+ }
p_clcb->ccc_stage = GATT_SVC_CHANGED_CONNECTING;
if (!p_clcb->connected) {
@@ -851,8 +896,14 @@ bool gatt_cl_read_sr_supp_feat_req(
log::verbose("BDA: {} read gatt supported features", peer_bda);
- GATT_GetConnIdIfConnected(gatt_cb.gatt_if, peer_bda, &conn_id,
- BT_TRANSPORT_LE);
+ if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, peer_bda, &conn_id,
+ BT_TRANSPORT_LE)) {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ peer_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_LE));
+ }
+
if (conn_id == GATT_INVALID_CONN_ID) return false;
p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
@@ -894,8 +945,13 @@ bool gatt_cl_read_sirk_req(
log::debug("BDA: {}, read SIRK", peer_bda);
- GATT_GetConnIdIfConnected(gatt_cb.gatt_if, peer_bda, &conn_id,
- BT_TRANSPORT_LE);
+ if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, peer_bda, &conn_id,
+ BT_TRANSPORT_LE)) {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ peer_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_LE));
+ }
if (conn_id == GATT_INVALID_CONN_ID) return false;
p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
@@ -931,8 +987,13 @@ bool gatt_profile_get_eatt_support(const RawAddress& remote_bda) {
log::verbose("BDA: {} read GATT support", remote_bda);
- GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
- BT_TRANSPORT_LE);
+ if (!GATT_GetConnIdIfConnected(gatt_cb.gatt_if, remote_bda, &conn_id,
+ BT_TRANSPORT_LE)) {
+ log::warn(
+ "Unable to get GATT connection id if connected peer:{} gatt_if:{} "
+ "transport:{}",
+ remote_bda, gatt_cb.gatt_if, bt_transport_text(BT_TRANSPORT_LE));
+ }
/* This read is important only when connected */
if (conn_id == GATT_INVALID_CONN_ID) return false;
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index 904dce3412..5bb62f637c 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -1090,8 +1090,12 @@ void gatt_send_srv_chg_ind(const RawAddress& peer_bda) {
uint8_t* p = handle_range;
UINT16_TO_STREAM(p, sGATT_DEFAULT_START_HANDLE);
UINT16_TO_STREAM(p, sGATT_LAST_HANDLE);
- GATTS_HandleValueIndication(conn_id, gatt_cb.handle_of_h_r,
- GATT_SIZE_OF_SRV_CHG_HNDL_RANGE, handle_range);
+ if (GATTS_HandleValueIndication(conn_id, gatt_cb.handle_of_h_r,
+ GATT_SIZE_OF_SRV_CHG_HNDL_RANGE,
+ handle_range) != GATT_SUCCESS) {
+ log::warn("Unable to handle GATT service value indication conn_id:{}",
+ conn_id);
+ }
}
/** Check sending service chnaged Indication is required or not if required then
diff --git a/system/stack/gatt/gatt_sr.cc b/system/stack/gatt/gatt_sr.cc
index c6b460d0a9..f573199ad4 100644
--- a/system/stack/gatt/gatt_sr.cc
+++ b/system/stack/gatt/gatt_sr.cc
@@ -1225,8 +1225,11 @@ static void gatts_chk_pending_ind(tGATT_TCB& tcb) {
tGATT_VALUE* p_buf =
(tGATT_VALUE*)fixed_queue_try_peek_first(tcb.pending_ind_q);
if (p_buf != NULL) {
- GATTS_HandleValueIndication(p_buf->conn_id, p_buf->handle, p_buf->len,
- p_buf->value);
+ if (GATTS_HandleValueIndication(p_buf->conn_id, p_buf->handle, p_buf->len,
+ p_buf->value) != GATT_SUCCESS) {
+ log::warn("Unable to send GATT server handle value conn_id:{}",
+ p_buf->conn_id);
+ }
osi_free(fixed_queue_try_remove_from_queue(tcb.pending_ind_q, p_buf));
}
}
diff --git a/system/stack/include/gatt_api.h b/system/stack/include/gatt_api.h
index f5778ed727..c2e6bf2f2c 100644
--- a/system/stack/include/gatt_api.h
+++ b/system/stack/include/gatt_api.h
@@ -833,7 +833,7 @@ typedef struct {
* Returns true if registered OK, else false
*
******************************************************************************/
-bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info);
+[[nodiscard]] bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info);
/*******************************************************************************
*
@@ -852,8 +852,9 @@ bool GATTS_NVRegister(tGATT_APPL_INFO* p_cb_info);
* on error error status is returned.
*
******************************************************************************/
-tGATT_STATUS GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t* service,
- int count);
+[[nodiscard]] tGATT_STATUS GATTS_AddService(tGATT_IF gatt_if,
+ btgatt_db_element_t* service,
+ int count);
/*******************************************************************************
*
@@ -869,8 +870,9 @@ tGATT_STATUS GATTS_AddService(tGATT_IF gatt_if, btgatt_db_element_t* service,
* Returns true if operation succeed, else false
*
******************************************************************************/
-bool GATTS_DeleteService(tGATT_IF gatt_if, bluetooth::Uuid* p_svc_uuid,
- uint16_t svc_inst);
+[[nodiscard]] bool GATTS_DeleteService(tGATT_IF gatt_if,
+ bluetooth::Uuid* p_svc_uuid,
+ uint16_t svc_inst);
/*******************************************************************************
*
@@ -901,8 +903,10 @@ void GATTS_StopService(uint16_t service_handle);
* code.
*
******************************************************************************/
-tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle,
- uint16_t val_len, uint8_t* p_val);
+[[nodiscard]] tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id,
+ uint16_t attr_handle,
+ uint16_t val_len,
+ uint8_t* p_val);
/*******************************************************************************
*
@@ -919,9 +923,10 @@ tGATT_STATUS GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_handle,
* Returns GATT_SUCCESS if successfully sent; otherwise error code.
*
******************************************************************************/
-tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id,
- uint16_t attr_handle,
- uint16_t val_len, uint8_t* p_val);
+[[nodiscard]] tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id,
+ uint16_t attr_handle,
+ uint16_t val_len,
+ uint8_t* p_val);
/*******************************************************************************
*
@@ -937,8 +942,9 @@ tGATT_STATUS GATTS_HandleValueNotification(uint16_t conn_id,
* Returns GATT_SUCCESS if successfully sent; otherwise error code.
*
******************************************************************************/
-tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
- tGATT_STATUS status, tGATTS_RSP* p_msg);
+[[nodiscard]] tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
+ tGATT_STATUS status,
+ tGATTS_RSP* p_msg);
/******************************************************************************/
/* GATT Profile Client Functions */
@@ -957,7 +963,7 @@ tGATT_STATUS GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
* Returns GATT_SUCCESS if command started successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
+[[nodiscard]] tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
/*******************************************************************************
* Function GATTC_UpdateUserAttMtuIfNeeded
@@ -1001,12 +1007,12 @@ void GATTC_UpdateUserAttMtuIfNeeded(const RawAddress& remote_bda,
* Exchange. Conn_id is stored for result.
*
******************************************************************************/
-tGATTC_TryMtuRequestResult GATTC_TryMtuRequest(const RawAddress& remote_bda,
- tBT_TRANSPORT transport,
- uint16_t conn_id,
- uint16_t* current_mtu);
+[[nodiscard]] tGATTC_TryMtuRequestResult GATTC_TryMtuRequest(
+ const RawAddress& remote_bda, tBT_TRANSPORT transport, uint16_t conn_id,
+ uint16_t* current_mtu);
-std::list<uint16_t> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest(
+[[nodiscard]] std::list<uint16_t>
+GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest(
const RawAddress& remote_bda);
/*******************************************************************************
*
@@ -1024,11 +1030,15 @@ std::list<uint16_t> GATTC_GetAndRemoveListOfConnIdsWaitingForMtuRequest(
* Returns GATT_SUCCESS if command received/sent successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
- uint16_t start_handle, uint16_t end_handle,
- const bluetooth::Uuid& uuid);
-tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
- uint16_t start_handle, uint16_t end_handle);
+[[nodiscard]] tGATT_STATUS GATTC_Discover(uint16_t conn_id,
+ tGATT_DISC_TYPE disc_type,
+ uint16_t start_handle,
+ uint16_t end_handle,
+ const bluetooth::Uuid& uuid);
+[[nodiscard]] tGATT_STATUS GATTC_Discover(uint16_t conn_id,
+ tGATT_DISC_TYPE disc_type,
+ uint16_t start_handle,
+ uint16_t end_handle);
/*******************************************************************************
*
@@ -1044,8 +1054,8 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
* Returns GATT_SUCCESS if command started successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type,
- tGATT_READ_PARAM* p_read);
+[[nodiscard]] tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type,
+ tGATT_READ_PARAM* p_read);
/*******************************************************************************
*
@@ -1061,8 +1071,8 @@ tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type,
* Returns GATT_SUCCESS if command started successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type,
- tGATT_VALUE* p_write);
+[[nodiscard]] tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type,
+ tGATT_VALUE* p_write);
/*******************************************************************************
*
@@ -1078,7 +1088,8 @@ tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type,
* Returns GATT_SUCCESS if command started successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
+[[nodiscard]] tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id,
+ bool is_execute);
/*******************************************************************************
*
@@ -1093,7 +1104,8 @@ tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
* Returns GATT_SUCCESS if command started successfully.
*
******************************************************************************/
-tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t handle);
+[[nodiscard]] tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id,
+ uint16_t handle);
/*******************************************************************************
*
@@ -1132,9 +1144,9 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
* with GATT
*
******************************************************************************/
-tGATT_IF GATT_Register(const bluetooth::Uuid& p_app_uuid128,
- const std::string& name, tGATT_CBACK* p_cb_info,
- bool eatt_support);
+[[nodiscard]] tGATT_IF GATT_Register(const bluetooth::Uuid& p_app_uuid128,
+ const std::string& name,
+ tGATT_CBACK* p_cb_info, bool eatt_support);
/*******************************************************************************
*
@@ -1184,19 +1196,22 @@ void GATT_StartIf(tGATT_IF gatt_if);
* Returns true if connection started; else false
*
******************************************************************************/
-bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
- tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
- bool opportunistic);
-bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
- tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
- bool opportunistic, uint8_t initiating_phys);
-bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
- tBLE_ADDR_TYPE addr_type, tBTM_BLE_CONN_TYPE connection_type,
- tBT_TRANSPORT transport, bool opportunistic);
-bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
- tBLE_ADDR_TYPE addr_type, tBTM_BLE_CONN_TYPE connection_type,
- tBT_TRANSPORT transport, bool opportunistic,
- uint8_t initiating_phys);
+[[nodiscard]] bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
+ tBTM_BLE_CONN_TYPE connection_type,
+ tBT_TRANSPORT transport, bool opportunistic);
+[[nodiscard]] bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
+ tBTM_BLE_CONN_TYPE connection_type,
+ tBT_TRANSPORT transport, bool opportunistic,
+ uint8_t initiating_phys);
+[[nodiscard]] bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
+ tBLE_ADDR_TYPE addr_type,
+ tBTM_BLE_CONN_TYPE connection_type,
+ tBT_TRANSPORT transport, bool opportunistic);
+[[nodiscard]] bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
+ tBLE_ADDR_TYPE addr_type,
+ tBTM_BLE_CONN_TYPE connection_type,
+ tBT_TRANSPORT transport, bool opportunistic,
+ uint8_t initiating_phys);
/*******************************************************************************
*
@@ -1215,8 +1230,9 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr,
* Returns true if connection started; else false
*
******************************************************************************/
-bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
- bool is_direct);
+[[nodiscard]] bool GATT_CancelConnect(tGATT_IF gatt_if,
+ const RawAddress& bd_addr,
+ bool is_direct);
/*******************************************************************************
*
@@ -1229,7 +1245,7 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
* Returns GATT_SUCCESS if disconnected.
*
******************************************************************************/
-tGATT_STATUS GATT_Disconnect(uint16_t conn_id);
+[[nodiscard]] tGATT_STATUS GATT_Disconnect(uint16_t conn_id);
/*******************************************************************************
*
@@ -1247,8 +1263,10 @@ tGATT_STATUS GATT_Disconnect(uint16_t conn_id);
* Returns true the logical link information is found for conn_id
*
******************************************************************************/
-bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if,
- RawAddress& bd_addr, tBT_TRANSPORT* p_transport);
+[[nodiscard]] bool GATT_GetConnectionInfor(uint16_t conn_id,
+ tGATT_IF* p_gatt_if,
+ RawAddress& bd_addr,
+ tBT_TRANSPORT* p_transport);
/*******************************************************************************
*
@@ -1266,8 +1284,10 @@ bool GATT_GetConnectionInfor(uint16_t conn_id, tGATT_IF* p_gatt_if,
* Returns true the logical link is connected
*
******************************************************************************/
-bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr,
- uint16_t* p_conn_id, tBT_TRANSPORT transport);
+[[nodiscard]] bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if,
+ const RawAddress& bd_addr,
+ uint16_t* p_conn_id,
+ tBT_TRANSPORT transport);
/*******************************************************************************
*
diff --git a/system/stack/srvc/srvc_eng.cc b/system/stack/srvc/srvc_eng.cc
index 44d0951d0a..6b64d1a741 100644
--- a/system/stack/srvc/srvc_eng.cc
+++ b/system/stack/srvc/srvc_eng.cc
@@ -19,7 +19,6 @@
#include <bluetooth/log.h>
#include "gatt_api.h"
-#include "os/logging/log_adapter.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"
#include "srvc_dis_int.h"
@@ -274,7 +273,11 @@ static void srvc_eng_s_request_cback(uint16_t conn_id, uint32_t trans_id,
srvc_eng_cb.clcb[clcb_idx].trans_id = 0;
- if (act == SRVC_ACT_RSP) GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg);
+ if (act == SRVC_ACT_RSP) {
+ if (GATTS_SendRsp(conn_id, trans_id, status, &rsp_msg) != GATT_SUCCESS) {
+ log::warn("Unable to send GATT server respond conn_id:{}", conn_id);
+ }
+ }
}
/*******************************************************************************
@@ -369,7 +372,9 @@ void srvc_eng_release_channel(uint16_t conn_id) {
p_clcb->cur_srvc_id = SRVC_ID_NONE;
/* check pending request */
- GATT_Disconnect(p_clcb->conn_id);
+ if (GATT_Disconnect(p_clcb->conn_id) != GATT_SUCCESS) {
+ log::warn("Unable to disconnect GATT conn_id:{}", p_clcb->conn_id);
+ }
}
/*******************************************************************************
*