OSDN Git Service

Add stack/gatt/gatt_main::gatt_find_in_device_record
authorChris Manton <cmanton@google.com>
Thu, 29 Oct 2020 23:10:23 +0000 (16:10 -0700)
committerChris Manton <cmanton@google.com>
Wed, 4 Nov 2020 18:30:05 +0000 (10:30 -0800)
Bug: 171568335
Tag: #refactor
Test: acts/bin/act.py -tp ~/Goog/tools/test/connectivity -tc BleCocTest
Test: atest --host bluetooth_test_gd

Change-Id: I5e1713f1a7cb00559448148d2275e8eeefb414dd

stack/acl/btm_acl.cc
stack/gatt/gatt_main.cc

index 74778cf..ba36929 100644 (file)
@@ -62,6 +62,9 @@
 #include "stack/include/sco_hci_link_interface.h"
 #include "types/raw_address.h"
 
+void gatt_find_in_device_record(const RawAddress& bd_addr,
+                                tBLE_BD_ADDR* address_with_type);
+
 struct StackAclBtmAcl {
   tACL_CONN* acl_allocate_connection();
   tACL_CONN* acl_get_connection_from_handle(uint16_t handle);
@@ -2883,6 +2886,9 @@ bool acl_create_le_connection_with_id(uint8_t id, const RawAddress& bd_addr) {
         .bda = bd_addr,
         .type = BLE_ADDR_RANDOM,
     };
+    gatt_find_in_device_record(bd_addr, &address_with_type);
+    LOG_DEBUG("Creating le connection to:%s",
+              address_with_type.ToString().c_str());
     bluetooth::shim::ACL_CreateLeConnection(address_with_type);
     return true;
   }
index 6dfbd76..2e66a43 100644 (file)
@@ -175,6 +175,26 @@ void gatt_free(void) {
   EattExtension::GetInstance()->Stop();
 }
 
+void gatt_find_in_device_record(const RawAddress& bd_addr,
+                                tBLE_BD_ADDR* address_with_type) {
+  const tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
+  if (p_dev_rec == nullptr) {
+    return;
+  }
+
+  if (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
+    if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
+      *address_with_type = {.type = p_dev_rec->ble.ble_addr_type,
+                            .bda = bd_addr};
+      return;
+    }
+    *address_with_type = p_dev_rec->ble.identity_address_with_type;
+    return;
+  }
+  *address_with_type = {.type = BLE_ADDR_PUBLIC, .bda = bd_addr};
+  return;
+}
+
 /*******************************************************************************
  *
  * Function         gatt_connect