summaryrefslogtreecommitdiff
path: root/system/stack/gatt
diff options
context:
space:
mode:
Diffstat (limited to 'system/stack/gatt')
-rw-r--r--system/stack/gatt/connection_manager.cc64
-rw-r--r--system/stack/gatt/gatt_api.cc54
-rw-r--r--system/stack/gatt/gatt_main.cc45
-rw-r--r--system/stack/gatt/gatt_utils.cc2
4 files changed, 114 insertions, 51 deletions
diff --git a/system/stack/gatt/connection_manager.cc b/system/stack/gatt/connection_manager.cc
index b2499b4949..c6052c236c 100644
--- a/system/stack/gatt/connection_manager.cc
+++ b/system/stack/gatt/connection_manager.cc
@@ -86,6 +86,7 @@ bool anyone_connecting(
/** background connection device from the list. Returns pointer to the device
* record, or nullptr if not found */
std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& address) {
+ LOG_DEBUG("address=%s", address.ToString().c_str());
auto it = bgconn_dev.find(address);
return (it != bgconn_dev.end()) ? it->second.doing_bg_conn
: std::set<tAPP_ID>();
@@ -94,6 +95,8 @@ std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& address) {
/** Add a device from the background connection list. Returns true if device
* added to the list, or already in list, false otherwise */
bool background_connect_add(uint8_t app_id, const RawAddress& address) {
+ LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
+ address.ToString().c_str());
if (bluetooth::shim::is_gd_l2cap_enabled()) {
return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address);
}
@@ -103,23 +106,30 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) {
if (it != bgconn_dev.end()) {
// device already in the acceptlist, just add interested app to the list
if (it->second.doing_bg_conn.count(app_id)) {
- LOG(INFO) << "App id=" << loghex(app_id)
- << "already doing background connection to " << address;
+ LOG_DEBUG("app_id=%d, already doing background connection to address=%s",
+ static_cast<int>(app_id), address.ToString().c_str());
return true;
}
// Already in acceptlist ?
if (anyone_connecting(it)) {
+ LOG_DEBUG("app_id=%d, address=%s, already in accept list",
+ static_cast<int>(app_id), address.ToString().c_str());
in_acceptlist = true;
}
}
if (!in_acceptlist) {
// the device is not in the acceptlist
- if (!BTM_AcceptlistAdd(address)) return false;
+ if (!BTM_AcceptlistAdd(address)) {
+ LOG_WARN("Failed to add device %s to accept list for app %d",
+ address.ToString().c_str(), static_cast<int>(app_id));
+ return false;
+ }
}
- // create endtry for address, and insert app_id.
+ // create entry for address, and insert app_id.
+ // new tAPPS_CONNECTING will be default constructed if not exist
bgconn_dev[address].doing_bg_conn.insert(app_id);
return true;
}
@@ -127,8 +137,12 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) {
/** Removes all registrations for connection for given device.
* Returns true if anything was removed, false otherwise */
bool remove_unconditional(const RawAddress& address) {
+ LOG_DEBUG("address=%s", address.ToString().c_str());
auto it = bgconn_dev.find(address);
- if (it == bgconn_dev.end()) return false;
+ if (it == bgconn_dev.end()) {
+ LOG_WARN("address %s is not found", address.ToString().c_str());
+ return false;
+ }
BTM_AcceptlistRemove(address);
bgconn_dev.erase(it);
@@ -140,25 +154,41 @@ bool remove_unconditional(const RawAddress& address) {
* shim purposes.
* Returns true if anything was removed, false otherwise */
bool remove_unconditional_from_shim(const RawAddress& address) {
+ LOG_DEBUG("address=%s", address.ToString().c_str());
auto it = bgconn_dev.find(address);
- if (it == bgconn_dev.end()) return false;
+ if (it == bgconn_dev.end()) {
+ LOG_WARN("address %s is not found", address.ToString().c_str());
+ return false;
+ }
bgconn_dev.erase(it);
return true;
}
/** Remove device from the background connection device list or listening to
- * advertising list. Returns true if device was on the list and was succesfully
- * removed */
+ * advertising list. Returns true if device was on the list and was
+ * successfully removed */
bool background_connect_remove(uint8_t app_id, const RawAddress& address) {
- VLOG(2) << __func__;
+ LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
+ address.ToString().c_str());
auto it = bgconn_dev.find(address);
- if (it == bgconn_dev.end()) return false;
+ if (it == bgconn_dev.end()) {
+ LOG_WARN("address %s is not found", address.ToString().c_str());
+ return false;
+ }
- if (!it->second.doing_bg_conn.erase(app_id)) return false;
+ if (!it->second.doing_bg_conn.erase(app_id)) {
+ LOG_WARN("Failed to remove background connection app %d for address %s",
+ static_cast<int>(app_id), address.ToString().c_str());
+ return false;
+ }
- if (anyone_connecting(it)) return true;
+ if (anyone_connecting(it)) {
+ LOG_DEBUG("some device is still connecting, app_id=%d, address=%s",
+ static_cast<int>(app_id), address.ToString().c_str());
+ return true;
+ }
- // no more apps interested - remove from acceptlist and delete record
+ // no more apps interested - remove from accept list and delete record
BTM_AcceptlistRemove(address);
bgconn_dev.erase(it);
return true;
@@ -166,6 +196,7 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) {
/** deregister all related background connetion device. */
void on_app_deregistered(uint8_t app_id) {
+ LOG_DEBUG("app_id=%d", static_cast<int>(app_id));
auto it = bgconn_dev.begin();
auto end = bgconn_dev.end();
/* update the BG conn device list */
@@ -186,6 +217,7 @@ void on_app_deregistered(uint8_t app_id) {
static void remove_all_clients_with_pending_connections(
const RawAddress& address) {
+ LOG_DEBUG("address=%s", address.ToString().c_str());
auto it = bgconn_dev.find(address);
while (it != bgconn_dev.end() && !it->second.doing_direct_conn.empty()) {
uint8_t app_id = it->second.doing_direct_conn.begin()->first;
@@ -212,6 +244,8 @@ void reset(bool after_reset) {
}
void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) {
+ LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
+ address.ToString().c_str());
on_connection_timed_out(app_id, address);
// TODO: this would free the timer, from within the timer callback, which is
@@ -222,6 +256,8 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) {
/** Add a device to the direcgt connection list. Returns true if device
* added to the list, false otherwise */
bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
+ LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
+ address.ToString().c_str());
if (bluetooth::shim::is_gd_l2cap_enabled()) {
return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address);
}
@@ -274,6 +310,8 @@ static bool any_direct_connect_left() {
}
bool direct_connect_remove(uint8_t app_id, const RawAddress& address) {
+ LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
+ address.ToString().c_str());
auto it = bgconn_dev.find(address);
if (it == bgconn_dev.end()) {
LOG_WARN("Unable to find background connection to remove");
diff --git a/system/stack/gatt/gatt_api.cc b/system/stack/gatt/gatt_api.cc
index ded621b2f6..b55e62563e 100644
--- a/system/stack/gatt/gatt_api.cc
+++ b/system/stack/gatt/gatt_api.cc
@@ -961,16 +961,17 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout,
bool status = false;
tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
- if (p_tcb != NULL) {
+ if (p_tcb != nullptr) {
status = L2CA_SetLeGattTimeout(bd_addr, idle_tout);
- if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP)
+ if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) {
L2CA_SetIdleTimeoutByBdAddr(
p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, BT_TRANSPORT_LE);
+ }
}
- VLOG(1) << __func__ << " idle_tout=" << idle_tout << ", status=" << +status
- << " (1-OK 0-not performed)";
+ LOG_INFO("idle_timeout=%d, status=%d, (1-OK 0-not performed)", idle_tout,
+ +status);
}
/*******************************************************************************
@@ -1162,22 +1163,18 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
/* Make sure app is registered */
tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
if (!p_reg) {
- LOG(ERROR) << __func__
- << ": Unable to find registered app gatt_if=" << +gatt_if;
+ LOG_ERROR("Unable to find registered app gatt_if=%d", +gatt_if);
return false;
}
if (!is_direct && transport != BT_TRANSPORT_LE) {
- LOG(ERROR) << __func__
- << ": Unsupported transport for background connection gatt_if="
- << +gatt_if;
+ LOG_WARN("Unsupported transport for background connection gatt_if=%d",
+ +gatt_if);
return false;
}
if (opportunistic) {
- LOG(INFO) << __func__
- << ": Registered for opportunistic connection gatt_if="
- << +gatt_if;
+ LOG_INFO("Registered for opportunistic connection gatt_if=%d", +gatt_if);
return true;
}
@@ -1193,20 +1190,27 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct,
// RPA can rotate, causing address to "expire" in the background
// connection list. RPA is allowed for direct connect, as such request
// times out after 30 seconds
- LOG(INFO) << __func__
- << ": Unable to add RPA to background connection gatt_if="
- << +gatt_if;
- ret = true;
+ LOG_WARN("Unable to add RPA %s to background connection gatt_if=%d",
+ bd_addr.ToString().c_str(), +gatt_if);
+ ret = false;
} else {
- LOG_DEBUG("Adding to acceptlist device:%s", PRIVATE_ADDRESS(bd_addr));
+ LOG_DEBUG("Adding to accept list device:%s", PRIVATE_ADDRESS(bd_addr));
ret = connection_manager::background_connect_add(gatt_if, bd_addr);
}
}
tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport);
// background connections don't necessarily create tcb
- if (p_tcb && ret)
+ if (p_tcb && ret) {
gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, !is_direct);
+ } else {
+ if (p_tcb == nullptr) {
+ LOG_DEBUG("p_tcb is null");
+ }
+ if (!ret) {
+ LOG_DEBUG("Previous step returned false");
+ }
+ }
return ret;
}
@@ -1239,10 +1243,11 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
return false;
}
- if (is_direct)
+ if (is_direct) {
return gatt_cancel_open(gatt_if, bd_addr);
- else
+ } else {
return gatt_auto_connect_dev_remove(p_reg->gatt_if, bd_addr);
+ }
}
VLOG(1) << " unconditional";
@@ -1283,11 +1288,14 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr,
*
******************************************************************************/
tGATT_STATUS GATT_Disconnect(uint16_t conn_id) {
- LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id);
+ LOG_INFO("conn_id=%d", +conn_id);
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) {
+ LOG_WARN("Cannot find TCB for connection %d", conn_id);
+ return GATT_ILLEGAL_PARAMETER;
+ }
tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id);
gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
@@ -1351,6 +1359,6 @@ bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr,
status = true;
}
- VLOG(1) << __func__ << " status= " << +status;
+ LOG_DEBUG("status=%d", status);
return status;
}
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index 6b61708209..f2d0637b7a 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -290,26 +290,27 @@ bool gatt_disconnect(tGATT_TCB* p_tcb) {
******************************************************************************/
bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
bool is_add) {
+ LOG_DEBUG("gatt_if=%d, is_add=%d, peer_bda=%s", +gatt_if, is_add,
+ p_tcb->peer_bda.ToString().c_str());
auto& holders = p_tcb->app_hold_link;
- VLOG(1) << __func__;
if (is_add) {
auto ret = holders.insert(gatt_if);
if (ret.second) {
- VLOG(1) << "added gatt_if=" << +gatt_if;
+ LOG_DEBUG("added gatt_if=%d", +gatt_if);
} else {
- VLOG(1) << "attempt to add already existing gatt_if=" << +gatt_if;
+ LOG_DEBUG("attempt to add already existing gatt_if=%d", +gatt_if);
}
return true;
}
//! is_add
if (!holders.erase(gatt_if)) {
- VLOG(1) << "attempt to remove nonexisting gatt_if=" << +gatt_if;
+ LOG_WARN("attempt to remove non-existing gatt_if=%d", +gatt_if);
return false;
}
- VLOG(1) << "removed gatt_if=" << +gatt_if;
+ LOG_INFO("removed gatt_if=%d", +gatt_if);
return true;
}
@@ -326,16 +327,23 @@ bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
******************************************************************************/
void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
bool is_add, bool check_acl_link) {
- VLOG(1) << StringPrintf("%s: is_add=%d chk_link=%d", __func__, is_add,
- check_acl_link);
+ LOG_DEBUG("gatt_if=%d, is_add=%d chk_link=%d", +gatt_if, is_add,
+ check_acl_link);
- if (!p_tcb) return;
+ if (!p_tcb) {
+ LOG_WARN("p_tcb is null");
+ return;
+ }
// If we make no modification, i.e. kill app that was never connected to a
// device, skip updating the device state.
- if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) return;
+ if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) {
+ LOG_INFO("App status is not updated for gatt_if=%d", +gatt_if);
+ return;
+ }
if (!check_acl_link) {
+ LOG_INFO("check_acl_link is false, no need to check");
return;
}
@@ -345,28 +353,37 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb,
if (is_add) {
if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) {
- VLOG(1) << "disable link idle timer";
+ LOG_INFO("disable link idle timer for %s",
+ p_tcb->peer_bda.ToString().c_str());
/* acl link is connected disable the idle timeout */
GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT,
p_tcb->transport);
+ } else {
+ LOG_INFO("invalid handle %d or dynamic CID %d", is_valid_handle,
+ p_tcb->att_lcid);
}
} else {
if (p_tcb->app_hold_link.empty()) {
// acl link is connected but no application needs to use the link
if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) {
-
/* Drop EATT before closing ATT */
EattExtension::GetInstance()->Disconnect(p_tcb->peer_bda);
/* for fixed channel, set the timeout value to
GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP seconds */
- VLOG(1) << " start link idle timer = "
- << GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP << " sec";
+ LOG_INFO(
+ "GATT fixed channel is no longer useful, start link idle timer for "
+ "%d seconds",
+ GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP);
GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP,
p_tcb->transport);
- } else
+ } else {
// disconnect the dynamic channel
+ LOG_INFO("disconnect GATT dynamic channel");
gatt_disconnect(p_tcb);
+ }
+ } else {
+ LOG_INFO("is_add=false, but some app is still using the ACL link");
}
}
}
diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc
index 338b277aca..11a0f85eb6 100644
--- a/system/stack/gatt/gatt_utils.cc
+++ b/system/stack/gatt/gatt_utils.cc
@@ -409,7 +409,7 @@ tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx) {
******************************************************************************/
tGATT_TCB* gatt_find_tcb_by_addr(const RawAddress& bda,
tBT_TRANSPORT transport) {
- tGATT_TCB* p_tcb = NULL;
+ tGATT_TCB* p_tcb = nullptr;
uint8_t i = 0;
i = gatt_find_i_tcb_by_addr(bda, transport);