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

Commit 44c46b10 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Prioritize strict address match over RPA resolution

btm_find_dev() finds the device record for the given address. It goes
through the list of all device records and returns record where
1. identity address matches the given address,
2. pseudo address matches the given address, or
3. IRK can resolve the given address.
This means that if an IRK from one of device in the list prior to target
device record is able to resolve the address, that device record will be
returned.
The updated logic now first compares the identity and pseudo address
from the device records. If the exact device record is not found, then
it tries to find the device record which can resolve the address.

Test: mmm packages/modules/Bluetooth
Flag: EXEMPT bugfix
Bug: 372533704
Change-Id: I8a87d7a47e024014b0a909e0c468b197c774be32
parent caf04801
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) {
  return NULL;
}

static bool is_address_equal(void* data, void* context) {
static bool is_not_same_identity_or_pseudo_address(void* data, void* context) {
  tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data);
  const RawAddress* bd_addr = ((RawAddress*)context);

@@ -355,12 +355,18 @@ static bool is_address_equal(void* data, void* context) {
    return false;
  }

  return true;
}

static bool is_rpa_unresolvable(void* data, void* context) {
  tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data);
  const RawAddress* bd_addr = ((RawAddress*)context);

  if (btm_ble_addr_resolvable(*bd_addr, p_dev_rec)) {
    return false;
  }
  return true;
}

/*******************************************************************************
 *
 * Function         btm_find_dev
@@ -376,12 +382,19 @@ tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr) {
    return nullptr;
  }

  list_node_t* n = list_foreach(btm_sec_cb.sec_dev_rec, is_address_equal, (void*)&bd_addr);
  if (n) {
  // Find by matching identity address or pseudo address.
  list_node_t* n = list_foreach(btm_sec_cb.sec_dev_rec, is_not_same_identity_or_pseudo_address,
                                (void*)&bd_addr);
  // If not found by matching identity address or pseudo address, find by RPA
  if (n == nullptr) {
    n = list_foreach(btm_sec_cb.sec_dev_rec, is_rpa_unresolvable, (void*)&bd_addr);
  }

  if (n != nullptr) {
    return static_cast<tBTM_SEC_DEV_REC*>(list_node(n));
  }

  return NULL;
  return nullptr;
}

static bool has_lenc_and_address_is_equal(void* data, void* context) {
@@ -390,7 +403,7 @@ static bool has_lenc_and_address_is_equal(void* data, void* context) {
    return true;
  }

  return is_address_equal(data, context);
  return is_not_same_identity_or_pseudo_address(data, context);
}

/*******************************************************************************