Loading system/include/hardware/bt_common_types.h +10 −0 Original line number Diff line number Diff line Loading @@ -128,4 +128,14 @@ struct MsftAdvMonitor { std::vector<MsftAdvMonitorPattern> patterns; }; #if __has_include(<bluetooth/log.h>) #include <bluetooth/log.h> namespace fmt { template <> struct formatter<bt_gatt_db_attribute_type_t> : enum_formatter<bt_gatt_db_attribute_type_t> {}; } // namespace fmt #endif // __has_include(<bluetooth/log.h>) #endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */ system/stack/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -971,6 +971,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_gd", "libbluetooth_log", Loading Loading @@ -1024,6 +1025,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading Loading @@ -1326,6 +1328,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading Loading @@ -1858,6 +1861,7 @@ cc_test { ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading system/stack/gatt/att_protocol.cc +41 −38 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ ******************************************************************************/ #include <base/logging.h> #include <bluetooth/log.h> #include "gatt_int.h" #include "internal_include/bt_target.h" Loading @@ -39,6 +40,8 @@ using base::StringPrintf; using bluetooth::Uuid; using namespace bluetooth; /********************************************************************** * ATT protocl message building utility * **********************************************************************/ Loading Loading @@ -312,8 +315,7 @@ static BT_HDR* attp_build_value_cmd(uint16_t payload_size, uint8_t op_code, /* update handle value pair length */ if (op_code == GATT_RSP_READ_BY_TYPE) *p_pair_len = (len + 2); LOG(WARNING) << StringPrintf( "attribute value too long, to be truncated to %d", len); log::warn("attribute value too long, to be truncated to {}", len); } ARRAY_TO_STREAM(p, p_data, len); Loading @@ -335,18 +337,18 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, uint16_t lcid, uint16_t l2cap_ret; if (lcid == L2CAP_ATT_CID) { LOG_DEBUG("Sending ATT message on att fixed channel"); log::debug("Sending ATT message on att fixed channel"); l2cap_ret = L2CA_SendFixedChnlData(lcid, tcb.peer_bda, p_toL2CAP); } else { LOG_DEBUG("Sending ATT message on lcid:%hu", lcid); log::debug("Sending ATT message on lcid:{}", lcid); l2cap_ret = (uint16_t)L2CA_DataWrite(lcid, p_toL2CAP); } if (l2cap_ret == L2CAP_DW_FAILED) { LOG(ERROR) << __func__ << ": failed to write data to L2CAP"; log::error("failed to write data to L2CAP"); return GATT_INTERNAL_ERROR; } else if (l2cap_ret == L2CAP_DW_CONGESTED) { VLOG(1) << StringPrintf("ATT congested, message accepted"); log::verbose("ATT congested, message accepted"); return GATT_CONGESTED; } return GATT_SUCCESS; Loading @@ -358,7 +360,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, uint16_t offset = 0; if (payload_size == 0) { LOG_ERROR("Cannot send response (op: 0x%02x) due to payload size = 0, %s", log::error( "Cannot send response (op: 0x{:02x}) due to payload size = 0, {}", op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda)); return nullptr; } Loading @@ -366,8 +369,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, switch (op_code) { case GATT_RSP_READ_BLOB: case GATT_RSP_PREPARE_WRITE: VLOG(1) << StringPrintf( "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = %d offset = %d", log::verbose( "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = {} offset = {}", p_msg->attr_value.len, p_msg->attr_value.offset); offset = p_msg->attr_value.offset; FALLTHROUGH_INTENDED; /* FALLTHROUGH */ Loading @@ -393,7 +396,7 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, return attp_build_mtu_cmd(op_code, p_msg->mtu); default: LOG(FATAL) << "attp_build_sr_msg: unknown op code = " << +op_code; log::fatal("attp_build_sr_msg: unknown op code = {}", +op_code); return nullptr; } } Loading @@ -414,11 +417,11 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, ******************************************************************************/ tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, uint16_t cid, BT_HDR* p_msg) { if (p_msg == NULL) { LOG_WARN("Unable to send empty message"); log::warn("Unable to send empty message"); return GATT_NO_RESOURCES; } LOG_DEBUG("Sending server response or indication message to client"); log::debug("Sending server response or indication message to client"); p_msg->offset = L2CAP_MIN_OFFSET; return attp_send_msg_to_l2cap(tcb, cid, p_msg); } Loading @@ -442,24 +445,24 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) && cmd_code != GATT_HANDLE_VALUE_CONF) { if (gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd)) { LOG_DEBUG("Enqueued ATT command %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::debug("Enqueued ATT command {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); return GATT_CMD_STARTED; } LOG_ERROR("%s, cid 0x%02x already disconnected", log::error("{}, cid 0x{:02x} already disconnected", ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid); return GATT_INTERNAL_ERROR; } LOG_DEBUG( "Sending ATT command to l2cap cid:0x%04x eatt_channels:%u transport:%s", p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport).c_str()); log::debug( "Sending ATT command to l2cap cid:0x{:04x} eatt_channels:{} transport:{}", p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport)); tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd); if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) { LOG_WARN( "Unable to send ATT command to l2cap layer %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::warn( "Unable to send ATT command to l2cap layer {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); return GATT_INTERNAL_ERROR; } Loading @@ -467,11 +470,12 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, return att_ret; } LOG_DEBUG("Starting ATT response timer %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::debug("Starting ATT response timer {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); gatt_start_rsp_timer(p_clcb); if (!gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL)) { LOG_ERROR("Could not queue sent request. %s, cid 0x%02x already disconnected", log::error( "Could not queue sent request. {}, cid 0x{:02x} already disconnected", ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid); return GATT_INTERNAL_ERROR; } Loading Loading @@ -530,13 +534,13 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, uint16_t offset = 0, handle; if (!p_clcb) { LOG_ERROR("Missing p_clcb"); log::error("Missing p_clcb"); return GATT_ILLEGAL_PARAMETER; } uint16_t payload_size = gatt_tcb_get_payload_size(tcb, p_clcb->cid); if (payload_size == 0) { LOG_ERROR("Cannot send request (op: 0x%02x) due to payload size = 0, %s", log::error("Cannot send request (op: 0x{:02x}) due to payload size = 0, {}", op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda)); return GATT_NO_RESOURCES; } Loading @@ -544,8 +548,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, switch (op_code) { case GATT_REQ_MTU: if (p_msg->mtu > GATT_MAX_MTU_SIZE) { LOG_WARN( "GATT message MTU is larger than max GATT MTU size op_code:%hhu", log::warn( "GATT message MTU is larger than max GATT MTU size op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -558,7 +562,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, if (!GATT_HANDLE_IS_VALID(p_msg->browse.s_handle) || !GATT_HANDLE_IS_VALID(p_msg->browse.e_handle) || p_msg->browse.s_handle > p_msg->browse.e_handle) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -574,7 +578,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, (op_code == GATT_REQ_READ) ? p_msg->handle : p_msg->read_blob.handle; /* handle checking */ if (!GATT_HANDLE_IS_VALID(handle)) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -588,7 +592,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, case GATT_CMD_WRITE: case GATT_SIGN_CMD_WRITE: if (!GATT_HANDLE_IS_VALID(p_msg->attr_value.handle)) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading Loading @@ -618,9 +622,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, } if (p_cmd == NULL) { LOG_WARN( "Unable to build proper GATT message to send to peer device " "op_code:%hhu", log::warn( "Unable to build proper GATT message to send to peer device op_code:{}", op_code); return GATT_NO_RESOURCES; } Loading system/stack/gatt/connection_manager.cc +67 −63 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <base/functional/callback.h> #include <base/location.h> #include <base/logging.h> #include <bluetooth/log.h> #include <map> #include <memory> Loading @@ -41,6 +42,8 @@ #define DIRECT_CONNECT_TIMEOUT (30 * 1000) /* 30 seconds */ using namespace bluetooth; constexpr char kBtmLogTag[] = "TA"; struct closure_data { Loading @@ -50,7 +53,7 @@ struct closure_data { static void alarm_closure_cb(void* p) { closure_data* data = (closure_data*)p; VLOG(1) << "executing timer scheduled at %s" << data->posted_from.ToString(); log::verbose("executing timer scheduled at {}", data->posted_from.ToString()); std::move(data->user_task).Run(); delete data; } Loading @@ -61,7 +64,7 @@ void alarm_set_closure(const base::Location& posted_from, alarm_t* alarm, closure_data* data = new closure_data; data->posted_from = posted_from; data->user_task = std::move(user_task); VLOG(1) << "scheduling timer %s" << data->posted_from.ToString(); log::verbose("scheduling timer {}", data->posted_from.ToString()); alarm_set_on_mloop(alarm, interval_ms, alarm_closure_cb, data); } Loading Loading @@ -112,7 +115,7 @@ bool is_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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); return (it != bgconn_dev.end()) ? it->second.doing_bg_conn : std::set<tAPP_ID>(); Loading @@ -135,14 +138,14 @@ bool IsTargetedAnnouncement(const uint8_t* p_eir, uint16_t eir_len) { } STREAM_TO_UINT16(uuid, p_tmp); LOG_DEBUG("Found UUID 0x%04x", uuid); log::debug("Found UUID 0x{:04x}", uuid); if (uuid != 0x184E && uuid != 0x1853) { continue; } STREAM_TO_UINT8(announcement_type, p_tmp); LOG_DEBUG("Found announcement_type 0x%02x", announcement_type); log::debug("Found announcement_type 0x{:02x}", announcement_type); if (announcement_type == 0x01) { return true; } Loading @@ -164,21 +167,22 @@ static void target_announcement_observe_results_cb(tBTM_INQ_RESULTS* p_inq, } if (!IsTargetedAnnouncement(p_eir, eir_len)) { LOG_DEBUG("Not a targeted announcement for device %s", log::debug("Not a targeted announcement for device {}", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } LOG_INFO("Found targeted announcement for device %s", log::info("Found targeted announcement for device {}", ADDRESS_TO_LOGGABLE_CSTR(addr)); if (it->second.is_in_accept_list) { LOG_INFO("Device %s is already connecting", ADDRESS_TO_LOGGABLE_CSTR(addr)); log::info("Device {} is already connecting", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } if (BTM_GetHCIConnHandle(addr, BT_TRANSPORT_LE) != 0xFFFF) { LOG_DEBUG("Device %s already connected", ADDRESS_TO_LOGGABLE_CSTR(addr)); log::debug("Device {} already connected", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } Loading @@ -193,7 +197,7 @@ static void target_announcement_observe_results_cb(tBTM_INQ_RESULTS* p_inq, } void target_announcements_filtering_set(bool enable) { LOG_DEBUG("enable %d", enable); log::debug("enable {}", enable); BTM_LogHistory(kBtmLogTag, RawAddress::kEmpty, (enable ? "Start filtering" : "Stop filtering")); Loading @@ -211,7 +215,7 @@ void target_announcements_filtering_set(bool enable) { */ bool background_connect_targeted_announcement_add(tAPP_ID app_id, const RawAddress& address) { LOG_INFO("app_id=%d, address=%s", static_cast<int>(app_id), log::info("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); bool disable_accept_list = false; Loading @@ -220,9 +224,9 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, if (it != bgconn_dev.end()) { // check if filtering already enabled if (it->second.doing_targeted_announcements_conn.count(app_id)) { LOG_INFO( "app_id=%d, already doing targeted announcement filtering to " "address=%s", log::info( "app_id={}, already doing targeted announcement filtering to " "address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return true; } Loading @@ -232,14 +236,14 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, // Check if connecting if (!it->second.doing_direct_conn.empty()) { LOG_INFO("app_id=%d, address=%s, already in direct connection", log::info("app_id={}, address={}, already in direct connection", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); } else if (!targeted_filtering_enabled && !it->second.doing_bg_conn.empty()) { // device is already in the acceptlist so we would have to remove it LOG_INFO( "already doing background connection to address=%s. Need to disable " log::info( "already doing background connection to address={}. Need to disable " "it.", ADDRESS_TO_LOGGABLE_CSTR(address)); disable_accept_list = true; Loading @@ -266,7 +270,7 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, /** 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); bool in_acceptlist = false; Loading @@ -274,14 +278,14 @@ 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_DEBUG("app_id=%d, already doing background connection to address=%s", log::debug("app_id={}, already doing background connection to address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return true; } // Already in acceptlist ? if (it->second.is_in_accept_list) { LOG_DEBUG("app_id=%d, address=%s, already in accept list", log::debug("app_id={}, address={}, already in accept list", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); in_acceptlist = true; } else { Loading @@ -293,10 +297,10 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) { if (!in_acceptlist) { // the device is not in the acceptlist if (is_targeted_announcement_enabled) { LOG_DEBUG("Targeted announcement enabled, do not add to AcceptList"); log::debug("Targeted announcement enabled, do not add to AcceptList"); } else { if (!BTM_AcceptlistAdd(address)) { LOG_WARN("Failed to add device %s to accept list for app %d", log::warn("Failed to add device {} to accept list for app {}", ADDRESS_TO_LOGGABLE_CSTR(address), static_cast<int>(app_id)); return false; } Loading @@ -313,10 +317,10 @@ 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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("address %s is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); log::warn("address {} is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -329,11 +333,11 @@ bool remove_unconditional(const RawAddress& address) { * 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) { LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("address %s is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); log::warn("address {} is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -345,7 +349,7 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { bool removed_from_ta = (it->second.doing_targeted_announcements_conn.erase(app_id) > 0); if (!removed_from_bg_conn && !removed_from_ta) { LOG_WARN("Failed to remove background connection app %d for address %s", log::warn("Failed to remove background connection app {} for address {}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -356,17 +360,17 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { } if (is_anyone_connecting(it)) { LOG_DEBUG("some device is still connecting, app_id=%d, address=%s", log::debug("some device is still connecting, app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); /* Check which method should be used now.*/ if (!accept_list_enabled) { /* Accept list was not used */ if (!it->second.doing_targeted_announcements_conn.empty()) { /* Keep using filtering */ LOG_DEBUG(" Keep using target announcement filtering"); log::debug("Keep using target announcement filtering"); } else if (!it->second.doing_bg_conn.empty()) { if (!BTM_AcceptlistAdd(address)) { LOG_WARN("Could not re add device to accept list"); log::warn("Could not re add device to accept list"); } else { bgconn_dev[address].is_in_accept_list = true; } Loading Loading @@ -397,7 +401,7 @@ bool is_background_connection(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)); log::debug("app_id={}", static_cast<int>(app_id)); auto it = bgconn_dev.begin(); auto end = bgconn_dev.end(); /* update the BG conn device list */ Loading @@ -418,7 +422,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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); 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; Loading @@ -428,14 +432,14 @@ static void remove_all_clients_with_pending_connections( } void on_connection_complete(const RawAddress& address) { LOG_INFO("Le connection completed to device:%s", log::info("Le connection completed to device:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); remove_all_clients_with_pending_connections(address); } void on_connection_timed_out_from_shim(const RawAddress& address) { LOG_INFO("Connection failed %s", ADDRESS_TO_LOGGABLE_CSTR(address)); log::info("Connection failed {}", ADDRESS_TO_LOGGABLE_CSTR(address)); on_connection_timed_out(0x00, address); } Loading @@ -450,7 +454,7 @@ 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); on_connection_timed_out(app_id, address); Loading @@ -462,21 +466,21 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) { /** Add a device to the direct 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); bool in_acceptlist = false; auto it = bgconn_dev.find(address); if (it != bgconn_dev.end()) { // app already trying to connect to this particular device if (it->second.doing_direct_conn.count(app_id)) { LOG(INFO) << "direct connect attempt from app_id=" << loghex(app_id) << " already in progress"; log::info("direct connect attempt from app_id={} already in progress", loghex(app_id)); return false; } // are we already in the acceptlist ? if (it->second.is_in_accept_list) { LOG_WARN("Background connection attempt already in progress app_id=%x", log::warn("Background connection attempt already in progress app_id={:x}", app_id); in_acceptlist = true; } Loading @@ -485,7 +489,7 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) { if (!in_acceptlist) { if (!BTM_AcceptlistAdd(address, true)) { // if we can't add to acceptlist, turn parameters back to slow. LOG_WARN("Unable to add le device to acceptlist"); log::warn("Unable to add le device to acceptlist"); return false; } bgconn_dev[address].is_in_accept_list = true; Loading @@ -510,18 +514,18 @@ static void schedule_direct_connect_add(uint8_t app_id, bool direct_connect_remove(uint8_t app_id, const RawAddress& address, bool connection_timeout) { LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("Unable to find background connection to remove peer:%s", log::warn("Unable to find background connection to remove peer:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } auto app_it = it->second.doing_direct_conn.find(app_id); if (app_it == it->second.doing_direct_conn.end()) { LOG_WARN("Unable to find direct connection to remove peer:%s", log::warn("Unable to find direct connection to remove peer:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -540,8 +544,8 @@ bool direct_connect_remove(uint8_t app_id, const RawAddress& address, * the allow list. */ if (!BTM_AcceptlistAdd(address)) { LOG_WARN( "Failed to re-add device %s to accept list after connection " log::warn( "Failed to re-add device {} to accept list after connection " "timeout", ADDRESS_TO_LOGGABLE_CSTR(address)); } Loading Loading
system/include/hardware/bt_common_types.h +10 −0 Original line number Diff line number Diff line Loading @@ -128,4 +128,14 @@ struct MsftAdvMonitor { std::vector<MsftAdvMonitorPattern> patterns; }; #if __has_include(<bluetooth/log.h>) #include <bluetooth/log.h> namespace fmt { template <> struct formatter<bt_gatt_db_attribute_type_t> : enum_formatter<bt_gatt_db_attribute_type_t> {}; } // namespace fmt #endif // __has_include(<bluetooth/log.h>) #endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */
system/stack/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -971,6 +971,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_gd", "libbluetooth_log", Loading Loading @@ -1024,6 +1025,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading Loading @@ -1326,6 +1328,7 @@ cc_test { "libcutils", ], static_libs: [ "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading Loading @@ -1858,6 +1861,7 @@ cc_test { ], static_libs: [ "bluetooth_flags_c_lib", "libbase", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", Loading
system/stack/gatt/att_protocol.cc +41 −38 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ ******************************************************************************/ #include <base/logging.h> #include <bluetooth/log.h> #include "gatt_int.h" #include "internal_include/bt_target.h" Loading @@ -39,6 +40,8 @@ using base::StringPrintf; using bluetooth::Uuid; using namespace bluetooth; /********************************************************************** * ATT protocl message building utility * **********************************************************************/ Loading Loading @@ -312,8 +315,7 @@ static BT_HDR* attp_build_value_cmd(uint16_t payload_size, uint8_t op_code, /* update handle value pair length */ if (op_code == GATT_RSP_READ_BY_TYPE) *p_pair_len = (len + 2); LOG(WARNING) << StringPrintf( "attribute value too long, to be truncated to %d", len); log::warn("attribute value too long, to be truncated to {}", len); } ARRAY_TO_STREAM(p, p_data, len); Loading @@ -335,18 +337,18 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, uint16_t lcid, uint16_t l2cap_ret; if (lcid == L2CAP_ATT_CID) { LOG_DEBUG("Sending ATT message on att fixed channel"); log::debug("Sending ATT message on att fixed channel"); l2cap_ret = L2CA_SendFixedChnlData(lcid, tcb.peer_bda, p_toL2CAP); } else { LOG_DEBUG("Sending ATT message on lcid:%hu", lcid); log::debug("Sending ATT message on lcid:{}", lcid); l2cap_ret = (uint16_t)L2CA_DataWrite(lcid, p_toL2CAP); } if (l2cap_ret == L2CAP_DW_FAILED) { LOG(ERROR) << __func__ << ": failed to write data to L2CAP"; log::error("failed to write data to L2CAP"); return GATT_INTERNAL_ERROR; } else if (l2cap_ret == L2CAP_DW_CONGESTED) { VLOG(1) << StringPrintf("ATT congested, message accepted"); log::verbose("ATT congested, message accepted"); return GATT_CONGESTED; } return GATT_SUCCESS; Loading @@ -358,7 +360,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, uint16_t offset = 0; if (payload_size == 0) { LOG_ERROR("Cannot send response (op: 0x%02x) due to payload size = 0, %s", log::error( "Cannot send response (op: 0x{:02x}) due to payload size = 0, {}", op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda)); return nullptr; } Loading @@ -366,8 +369,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, switch (op_code) { case GATT_RSP_READ_BLOB: case GATT_RSP_PREPARE_WRITE: VLOG(1) << StringPrintf( "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = %d offset = %d", log::verbose( "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = {} offset = {}", p_msg->attr_value.len, p_msg->attr_value.offset); offset = p_msg->attr_value.offset; FALLTHROUGH_INTENDED; /* FALLTHROUGH */ Loading @@ -393,7 +396,7 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, return attp_build_mtu_cmd(op_code, p_msg->mtu); default: LOG(FATAL) << "attp_build_sr_msg: unknown op code = " << +op_code; log::fatal("attp_build_sr_msg: unknown op code = {}", +op_code); return nullptr; } } Loading @@ -414,11 +417,11 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg, ******************************************************************************/ tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, uint16_t cid, BT_HDR* p_msg) { if (p_msg == NULL) { LOG_WARN("Unable to send empty message"); log::warn("Unable to send empty message"); return GATT_NO_RESOURCES; } LOG_DEBUG("Sending server response or indication message to client"); log::debug("Sending server response or indication message to client"); p_msg->offset = L2CAP_MIN_OFFSET; return attp_send_msg_to_l2cap(tcb, cid, p_msg); } Loading @@ -442,24 +445,24 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) && cmd_code != GATT_HANDLE_VALUE_CONF) { if (gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd)) { LOG_DEBUG("Enqueued ATT command %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::debug("Enqueued ATT command {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); return GATT_CMD_STARTED; } LOG_ERROR("%s, cid 0x%02x already disconnected", log::error("{}, cid 0x{:02x} already disconnected", ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid); return GATT_INTERNAL_ERROR; } LOG_DEBUG( "Sending ATT command to l2cap cid:0x%04x eatt_channels:%u transport:%s", p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport).c_str()); log::debug( "Sending ATT command to l2cap cid:0x{:04x} eatt_channels:{} transport:{}", p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport)); tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd); if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) { LOG_WARN( "Unable to send ATT command to l2cap layer %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::warn( "Unable to send ATT command to l2cap layer {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); return GATT_INTERNAL_ERROR; } Loading @@ -467,11 +470,12 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, return att_ret; } LOG_DEBUG("Starting ATT response timer %p conn_id=0x%04x, cid=%d", p_clcb, p_clcb->conn_id, p_clcb->cid); log::debug("Starting ATT response timer {} conn_id=0x{:04x}, cid={}", fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid); gatt_start_rsp_timer(p_clcb); if (!gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL)) { LOG_ERROR("Could not queue sent request. %s, cid 0x%02x already disconnected", log::error( "Could not queue sent request. {}, cid 0x{:02x} already disconnected", ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid); return GATT_INTERNAL_ERROR; } Loading Loading @@ -530,13 +534,13 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, uint16_t offset = 0, handle; if (!p_clcb) { LOG_ERROR("Missing p_clcb"); log::error("Missing p_clcb"); return GATT_ILLEGAL_PARAMETER; } uint16_t payload_size = gatt_tcb_get_payload_size(tcb, p_clcb->cid); if (payload_size == 0) { LOG_ERROR("Cannot send request (op: 0x%02x) due to payload size = 0, %s", log::error("Cannot send request (op: 0x{:02x}) due to payload size = 0, {}", op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda)); return GATT_NO_RESOURCES; } Loading @@ -544,8 +548,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, switch (op_code) { case GATT_REQ_MTU: if (p_msg->mtu > GATT_MAX_MTU_SIZE) { LOG_WARN( "GATT message MTU is larger than max GATT MTU size op_code:%hhu", log::warn( "GATT message MTU is larger than max GATT MTU size op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -558,7 +562,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, if (!GATT_HANDLE_IS_VALID(p_msg->browse.s_handle) || !GATT_HANDLE_IS_VALID(p_msg->browse.e_handle) || p_msg->browse.s_handle > p_msg->browse.e_handle) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -574,7 +578,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, (op_code == GATT_REQ_READ) ? p_msg->handle : p_msg->read_blob.handle; /* handle checking */ if (!GATT_HANDLE_IS_VALID(handle)) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading @@ -588,7 +592,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, case GATT_CMD_WRITE: case GATT_SIGN_CMD_WRITE: if (!GATT_HANDLE_IS_VALID(p_msg->attr_value.handle)) { LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code); log::warn("GATT message has invalid handle op_code:{}", op_code); return GATT_ILLEGAL_PARAMETER; } Loading Loading @@ -618,9 +622,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, } if (p_cmd == NULL) { LOG_WARN( "Unable to build proper GATT message to send to peer device " "op_code:%hhu", log::warn( "Unable to build proper GATT message to send to peer device op_code:{}", op_code); return GATT_NO_RESOURCES; } Loading
system/stack/gatt/connection_manager.cc +67 −63 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <base/functional/callback.h> #include <base/location.h> #include <base/logging.h> #include <bluetooth/log.h> #include <map> #include <memory> Loading @@ -41,6 +42,8 @@ #define DIRECT_CONNECT_TIMEOUT (30 * 1000) /* 30 seconds */ using namespace bluetooth; constexpr char kBtmLogTag[] = "TA"; struct closure_data { Loading @@ -50,7 +53,7 @@ struct closure_data { static void alarm_closure_cb(void* p) { closure_data* data = (closure_data*)p; VLOG(1) << "executing timer scheduled at %s" << data->posted_from.ToString(); log::verbose("executing timer scheduled at {}", data->posted_from.ToString()); std::move(data->user_task).Run(); delete data; } Loading @@ -61,7 +64,7 @@ void alarm_set_closure(const base::Location& posted_from, alarm_t* alarm, closure_data* data = new closure_data; data->posted_from = posted_from; data->user_task = std::move(user_task); VLOG(1) << "scheduling timer %s" << data->posted_from.ToString(); log::verbose("scheduling timer {}", data->posted_from.ToString()); alarm_set_on_mloop(alarm, interval_ms, alarm_closure_cb, data); } Loading Loading @@ -112,7 +115,7 @@ bool is_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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); return (it != bgconn_dev.end()) ? it->second.doing_bg_conn : std::set<tAPP_ID>(); Loading @@ -135,14 +138,14 @@ bool IsTargetedAnnouncement(const uint8_t* p_eir, uint16_t eir_len) { } STREAM_TO_UINT16(uuid, p_tmp); LOG_DEBUG("Found UUID 0x%04x", uuid); log::debug("Found UUID 0x{:04x}", uuid); if (uuid != 0x184E && uuid != 0x1853) { continue; } STREAM_TO_UINT8(announcement_type, p_tmp); LOG_DEBUG("Found announcement_type 0x%02x", announcement_type); log::debug("Found announcement_type 0x{:02x}", announcement_type); if (announcement_type == 0x01) { return true; } Loading @@ -164,21 +167,22 @@ static void target_announcement_observe_results_cb(tBTM_INQ_RESULTS* p_inq, } if (!IsTargetedAnnouncement(p_eir, eir_len)) { LOG_DEBUG("Not a targeted announcement for device %s", log::debug("Not a targeted announcement for device {}", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } LOG_INFO("Found targeted announcement for device %s", log::info("Found targeted announcement for device {}", ADDRESS_TO_LOGGABLE_CSTR(addr)); if (it->second.is_in_accept_list) { LOG_INFO("Device %s is already connecting", ADDRESS_TO_LOGGABLE_CSTR(addr)); log::info("Device {} is already connecting", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } if (BTM_GetHCIConnHandle(addr, BT_TRANSPORT_LE) != 0xFFFF) { LOG_DEBUG("Device %s already connected", ADDRESS_TO_LOGGABLE_CSTR(addr)); log::debug("Device {} already connected", ADDRESS_TO_LOGGABLE_CSTR(addr)); return; } Loading @@ -193,7 +197,7 @@ static void target_announcement_observe_results_cb(tBTM_INQ_RESULTS* p_inq, } void target_announcements_filtering_set(bool enable) { LOG_DEBUG("enable %d", enable); log::debug("enable {}", enable); BTM_LogHistory(kBtmLogTag, RawAddress::kEmpty, (enable ? "Start filtering" : "Stop filtering")); Loading @@ -211,7 +215,7 @@ void target_announcements_filtering_set(bool enable) { */ bool background_connect_targeted_announcement_add(tAPP_ID app_id, const RawAddress& address) { LOG_INFO("app_id=%d, address=%s", static_cast<int>(app_id), log::info("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); bool disable_accept_list = false; Loading @@ -220,9 +224,9 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, if (it != bgconn_dev.end()) { // check if filtering already enabled if (it->second.doing_targeted_announcements_conn.count(app_id)) { LOG_INFO( "app_id=%d, already doing targeted announcement filtering to " "address=%s", log::info( "app_id={}, already doing targeted announcement filtering to " "address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return true; } Loading @@ -232,14 +236,14 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, // Check if connecting if (!it->second.doing_direct_conn.empty()) { LOG_INFO("app_id=%d, address=%s, already in direct connection", log::info("app_id={}, address={}, already in direct connection", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); } else if (!targeted_filtering_enabled && !it->second.doing_bg_conn.empty()) { // device is already in the acceptlist so we would have to remove it LOG_INFO( "already doing background connection to address=%s. Need to disable " log::info( "already doing background connection to address={}. Need to disable " "it.", ADDRESS_TO_LOGGABLE_CSTR(address)); disable_accept_list = true; Loading @@ -266,7 +270,7 @@ bool background_connect_targeted_announcement_add(tAPP_ID app_id, /** 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); bool in_acceptlist = false; Loading @@ -274,14 +278,14 @@ 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_DEBUG("app_id=%d, already doing background connection to address=%s", log::debug("app_id={}, already doing background connection to address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return true; } // Already in acceptlist ? if (it->second.is_in_accept_list) { LOG_DEBUG("app_id=%d, address=%s, already in accept list", log::debug("app_id={}, address={}, already in accept list", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); in_acceptlist = true; } else { Loading @@ -293,10 +297,10 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) { if (!in_acceptlist) { // the device is not in the acceptlist if (is_targeted_announcement_enabled) { LOG_DEBUG("Targeted announcement enabled, do not add to AcceptList"); log::debug("Targeted announcement enabled, do not add to AcceptList"); } else { if (!BTM_AcceptlistAdd(address)) { LOG_WARN("Failed to add device %s to accept list for app %d", log::warn("Failed to add device {} to accept list for app {}", ADDRESS_TO_LOGGABLE_CSTR(address), static_cast<int>(app_id)); return false; } Loading @@ -313,10 +317,10 @@ 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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("address %s is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); log::warn("address {} is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -329,11 +333,11 @@ bool remove_unconditional(const RawAddress& address) { * 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) { LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("address %s is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); log::warn("address {} is not found", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -345,7 +349,7 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { bool removed_from_ta = (it->second.doing_targeted_announcements_conn.erase(app_id) > 0); if (!removed_from_bg_conn && !removed_from_ta) { LOG_WARN("Failed to remove background connection app %d for address %s", log::warn("Failed to remove background connection app {} for address {}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -356,17 +360,17 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { } if (is_anyone_connecting(it)) { LOG_DEBUG("some device is still connecting, app_id=%d, address=%s", log::debug("some device is still connecting, app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); /* Check which method should be used now.*/ if (!accept_list_enabled) { /* Accept list was not used */ if (!it->second.doing_targeted_announcements_conn.empty()) { /* Keep using filtering */ LOG_DEBUG(" Keep using target announcement filtering"); log::debug("Keep using target announcement filtering"); } else if (!it->second.doing_bg_conn.empty()) { if (!BTM_AcceptlistAdd(address)) { LOG_WARN("Could not re add device to accept list"); log::warn("Could not re add device to accept list"); } else { bgconn_dev[address].is_in_accept_list = true; } Loading Loading @@ -397,7 +401,7 @@ bool is_background_connection(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)); log::debug("app_id={}", static_cast<int>(app_id)); auto it = bgconn_dev.begin(); auto end = bgconn_dev.end(); /* update the BG conn device list */ Loading @@ -418,7 +422,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_TO_LOGGABLE_CSTR(address)); log::debug("address={}", ADDRESS_TO_LOGGABLE_CSTR(address)); 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; Loading @@ -428,14 +432,14 @@ static void remove_all_clients_with_pending_connections( } void on_connection_complete(const RawAddress& address) { LOG_INFO("Le connection completed to device:%s", log::info("Le connection completed to device:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); remove_all_clients_with_pending_connections(address); } void on_connection_timed_out_from_shim(const RawAddress& address) { LOG_INFO("Connection failed %s", ADDRESS_TO_LOGGABLE_CSTR(address)); log::info("Connection failed {}", ADDRESS_TO_LOGGABLE_CSTR(address)); on_connection_timed_out(0x00, address); } Loading @@ -450,7 +454,7 @@ 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); on_connection_timed_out(app_id, address); Loading @@ -462,21 +466,21 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) { /** Add a device to the direct 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), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); bool in_acceptlist = false; auto it = bgconn_dev.find(address); if (it != bgconn_dev.end()) { // app already trying to connect to this particular device if (it->second.doing_direct_conn.count(app_id)) { LOG(INFO) << "direct connect attempt from app_id=" << loghex(app_id) << " already in progress"; log::info("direct connect attempt from app_id={} already in progress", loghex(app_id)); return false; } // are we already in the acceptlist ? if (it->second.is_in_accept_list) { LOG_WARN("Background connection attempt already in progress app_id=%x", log::warn("Background connection attempt already in progress app_id={:x}", app_id); in_acceptlist = true; } Loading @@ -485,7 +489,7 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) { if (!in_acceptlist) { if (!BTM_AcceptlistAdd(address, true)) { // if we can't add to acceptlist, turn parameters back to slow. LOG_WARN("Unable to add le device to acceptlist"); log::warn("Unable to add le device to acceptlist"); return false; } bgconn_dev[address].is_in_accept_list = true; Loading @@ -510,18 +514,18 @@ static void schedule_direct_connect_add(uint8_t app_id, bool direct_connect_remove(uint8_t app_id, const RawAddress& address, bool connection_timeout) { LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), log::debug("app_id={}, address={}", static_cast<int>(app_id), ADDRESS_TO_LOGGABLE_CSTR(address)); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("Unable to find background connection to remove peer:%s", log::warn("Unable to find background connection to remove peer:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } auto app_it = it->second.doing_direct_conn.find(app_id); if (app_it == it->second.doing_direct_conn.end()) { LOG_WARN("Unable to find direct connection to remove peer:%s", log::warn("Unable to find direct connection to remove peer:{}", ADDRESS_TO_LOGGABLE_CSTR(address)); return false; } Loading @@ -540,8 +544,8 @@ bool direct_connect_remove(uint8_t app_id, const RawAddress& address, * the allow list. */ if (!BTM_AcceptlistAdd(address)) { LOG_WARN( "Failed to re-add device %s to accept list after connection " log::warn( "Failed to re-add device {} to accept list after connection " "timeout", ADDRESS_TO_LOGGABLE_CSTR(address)); } Loading