From 58431835ec7c24fd2d6113eba65bcc9d29d29c1f Mon Sep 17 00:00:00 2001 From: Chienyuan Date: Fri, 19 Feb 2021 17:19:07 +0800 Subject: [PATCH] gd: Get local address from acl module for legacy SMP Tag: #gd-refactor Bug: 179452679 Test: gd/cert/run --host Test: manual, pair LE device Change-Id: I35e4ef614272865bd52ec66959384279705cc042 --- main/shim/acl.cc | 17 +++++++++++++++++ main/shim/acl.h | 2 ++ main/shim/acl_api.cc | 9 +++++++++ main/shim/acl_api.h | 3 +++ stack/acl/btm_acl.cc | 4 ++++ stack/test/common/mock_main_shim_acl_api.cc | 5 +++++ 6 files changed, 40 insertions(+) diff --git a/main/shim/acl.cc b/main/shim/acl.cc index b96b415ff..21b603649 100644 --- a/main/shim/acl.cc +++ b/main/shim/acl.cc @@ -570,6 +570,10 @@ class LeShimAclConnection // TODO Issue LeReadRemoteFeatures Command } + bluetooth::hci::AddressWithType GetLocalAddressWithType() { + return connection_->GetLocalAddress(); + } + void OnConnectionUpdate(hci::ErrorCode hci_status, uint16_t connection_interval, uint16_t connection_latency, @@ -1041,6 +1045,19 @@ void shim::legacy::Acl::OnClassicLinkDisconnected(HciHandle handle, is_locally_initiated, reason))); } +bluetooth::hci::AddressWithType shim::legacy::Acl::GetConnectionLocalAddress( + const RawAddress& remote_bda) { + bluetooth::hci::AddressWithType address_with_type; + auto remote_address = ToGdAddress(remote_bda); + for (auto& [handle, connection] : pimpl_->handle_to_le_connection_map_) { + if (connection->GetRemoteAddressWithType().GetAddress() == remote_address) { + return connection->GetLocalAddressWithType(); + } + } + LOG_WARN("address not found!"); + return address_with_type; +} + void shim::legacy::Acl::OnLeLinkDisconnected(HciHandle handle, hci::ErrorCode reason) { hci::AddressWithType remote_address_with_type = diff --git a/main/shim/acl.h b/main/shim/acl.h index f063391cf..ea822fa84 100644 --- a/main/shim/acl.h +++ b/main/shim/acl.h @@ -55,6 +55,8 @@ class Acl : public hci::acl_manager::ConnectionCallbacks, std::unique_ptr) override; void OnLeConnectFail(hci::AddressWithType, hci::ErrorCode reason) override; void OnLeLinkDisconnected(uint16_t handle, hci::ErrorCode reason); + bluetooth::hci::AddressWithType GetConnectionLocalAddress( + const RawAddress& remote_bda); // LinkConnectionInterface void CreateClassicConnection(const hci::Address& address) override; diff --git a/main/shim/acl_api.cc b/main/shim/acl_api.cc index 538bc9dd8..12b2a18c5 100644 --- a/main/shim/acl_api.cc +++ b/main/shim/acl_api.cc @@ -94,3 +94,12 @@ void bluetooth::shim::ACL_Shutdown() { void bluetooth::shim::ACL_IgnoreAllLeConnections() { return Stack::GetInstance()->GetAcl()->ClearAcceptList(); } + +void bluetooth::shim::ACL_ReadConnectionAddress(const RawAddress& pseudo_addr, + RawAddress& conn_addr, + uint8_t* p_addr_type) { + auto local_address = + Stack::GetInstance()->GetAcl()->GetConnectionLocalAddress(pseudo_addr); + conn_addr = ToRawAddress(local_address.GetAddress()); + *p_addr_type = static_cast(local_address.GetAddressType()); +} \ No newline at end of file diff --git a/main/shim/acl_api.h b/main/shim/acl_api.h index 9e5c0bd16..3e9f24b85 100644 --- a/main/shim/acl_api.h +++ b/main/shim/acl_api.h @@ -35,5 +35,8 @@ void ACL_ConfigureLePrivacy(bool is_le_privacy_enabled); void ACL_Shutdown(); void ACL_IgnoreAllLeConnections(); +void ACL_ReadConnectionAddress(const RawAddress& pseudo_addr, + RawAddress& conn_addr, uint8_t* p_addr_type); + } // namespace shim } // namespace bluetooth diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 2a2c5e361..4a54ce0b0 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -2319,6 +2319,10 @@ void BTM_ReadConnectionAddr(const RawAddress& remote_bda, bluetooth::shim::L2CA_ReadConnectionAddr(remote_bda, local_conn_addr, p_addr_type); return; + } else if (bluetooth::shim::is_gd_scanning_enabled()) { + bluetooth::shim::ACL_ReadConnectionAddress(remote_bda, local_conn_addr, + p_addr_type); + return; } tACL_CONN* p_acl = internal_.btm_bda_to_acl(remote_bda, BT_TRANSPORT_LE); diff --git a/stack/test/common/mock_main_shim_acl_api.cc b/stack/test/common/mock_main_shim_acl_api.cc index d2cccd716..b5bf4a269 100644 --- a/stack/test/common/mock_main_shim_acl_api.cc +++ b/stack/test/common/mock_main_shim_acl_api.cc @@ -64,3 +64,8 @@ void bluetooth::shim::ACL_Disconnect(uint16_t handle, bool is_classic, void bluetooth::shim::ACL_IgnoreAllLeConnections() { mock_function_count_map[__func__]++; } +void bluetooth::shim::ACL_ReadConnectionAddress(const RawAddress& pseudo_addr, + RawAddress& conn_addr, + uint8_t* p_addr_type) { + mock_function_count_map[__func__]++; +} \ No newline at end of file -- 2.11.0