OSDN Git Service

gd: Get local address from acl module for legacy SMP
authorChienyuan <chienyuanhuang@google.com>
Fri, 19 Feb 2021 09:19:07 +0000 (17:19 +0800)
committerChienyuan <chienyuanhuang@google.com>
Fri, 19 Feb 2021 09:40:09 +0000 (17:40 +0800)
Tag: #gd-refactor
Bug: 179452679
Test: gd/cert/run --host
Test: manual, pair LE device
Change-Id: I35e4ef614272865bd52ec66959384279705cc042

main/shim/acl.cc
main/shim/acl.h
main/shim/acl_api.cc
main/shim/acl_api.h
stack/acl/btm_acl.cc
stack/test/common/mock_main_shim_acl_api.cc

index b96b415..21b6036 100644 (file)
@@ -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 =
index f063391..ea822fa 100644 (file)
@@ -55,6 +55,8 @@ class Acl : public hci::acl_manager::ConnectionCallbacks,
       std::unique_ptr<hci::acl_manager::LeAclConnection>) 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;
index 538bc9d..12b2a18 100644 (file)
@@ -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<uint8_t>(local_address.GetAddressType());
+}
\ No newline at end of file
index 9e5c0bd..3e9f24b 100644 (file)
@@ -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
index 2a2c5e3..4a54ce0 100644 (file)
@@ -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);
index d2cccd7..b5bf4a2 100644 (file)
@@ -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