Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b5b1f12 authored by Zhengping Jiang's avatar Zhengping Jiang
Browse files

floss: don't add device to acceptlist if already connected

If there is already a valid handle, there is no need to add the address
to the accept list. If the device is paired with a resolvable address
(RPA), the random address is used to search the handle.

Bug: 297629431
Bug: 338112215
Test: CTSV secure client test
Test: mma -j32
Flag: verify_handle_before_add_accept_list
Change-Id: Ice1aaeccac1ea8613b6471a1e5ccc30288d9de95
parent d641c570
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1517,6 +1517,14 @@ void shim::legacy::Acl::CancelClassicConnection(const hci::Address& address) {
                 "classic");
}

void shim::legacy::Acl::DeviceAlreadyConnected(
    const hci::AddressWithType& address_with_type, std::promise<bool> promise) {
  auto handle =
      GetAclManager()->HACK_GetLeHandle(address_with_type.GetAddress());
  // 0xffff(kIllegalConnectionHandle) is the invalid handle.
  promise.set_value(handle != 0xffff);
}

void shim::legacy::Acl::AcceptLeConnectionFrom(
    const hci::AddressWithType& address_with_type, bool is_direct,
    std::promise<bool> promise) {
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ class Acl : public hci::acl_manager::ConnectionCallbacks,
  // LinkConnectionInterface
  void CreateClassicConnection(const hci::Address& address) override;
  void CancelClassicConnection(const hci::Address& address) override;
  void DeviceAlreadyConnected(const hci::AddressWithType& address_with_type,
                              std::promise<bool> promise);
  void AcceptLeConnectionFrom(const hci::AddressWithType& address_with_type,
                              bool is_direct,
                              std::promise<bool> promise) override;
+10 −0
Original line number Diff line number Diff line
@@ -50,6 +50,16 @@ void bluetooth::shim::ACL_CancelClassicConnection(
  Stack::GetInstance()->GetAcl()->CancelClassicConnection(address);
}

bool bluetooth::shim::ACL_DeviceAlreadyConnected(
    const tBLE_BD_ADDR& legacy_address_with_type) {
  std::promise<bool> promise;
  auto future = promise.get_future();
  Stack::GetInstance()->GetAcl()->DeviceAlreadyConnected(
      ToAddressWithTypeFromLegacy(legacy_address_with_type),
      std::move(promise));
  return future.get();
}

bool bluetooth::shim::ACL_AcceptLeConnectionFrom(
    const tBLE_BD_ADDR& legacy_address_with_type, bool is_direct) {
  std::promise<bool> promise;
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ namespace shim {

void ACL_CreateClassicConnection(const RawAddress& raw_address);
void ACL_CancelClassicConnection(const RawAddress& raw_address);
bool ACL_DeviceAlreadyConnected(const tBLE_BD_ADDR& legacy_address_with_type);
bool ACL_AcceptLeConnectionFrom(const tBLE_BD_ADDR& legacy_address_with_type,
                                bool is_direct);
void ACL_IgnoreLeConnectionFrom(const tBLE_BD_ADDR& legacy_address_with_type);
+14 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "stack/btm/btm_ble_bgconn.h"

#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <cstdint>
#include <unordered_map>
@@ -38,6 +39,7 @@
#include "stack/btm/btm_ble_int.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/include/acl_api.h"
#include "types/raw_address.h"

using namespace bluetooth;
@@ -114,6 +116,18 @@ bool BTM_AcceptlistAdd(const RawAddress& address, bool is_direct) {
    return false;
  }

  if (com::android::bluetooth::flags::verify_handle_before_add_accept_list()) {
    // Only RPA is checked here. RPA is converted to the identity address in
    // BTM_Sec_GetAddressWithType if host has resolved it. Adding the identity
    // address to accept list is not necessary if a valid handle already exists
    // for the RPA.
    if (BTM_BLE_IS_RESOLVE_BDA(address) &&
        bluetooth::shim::ACL_DeviceAlreadyConnected(
            {.type = 0x01, .bda = address})) {
      log::info("Already connected, not adding to accept list.");
      return true;
    }
  }
  return bluetooth::shim::ACL_AcceptLeConnectionFrom(
      BTM_Sec_GetAddressWithType(address), is_direct);
}
Loading