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

Commit d52034c9 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge "Invalidate the bonded status when the device is deleted" into main

parents 82346399 92abe9f7
Loading
Loading
Loading
Loading
+36 −31
Original line number Diff line number Diff line
@@ -159,15 +159,24 @@ void BTM_AcceptlistRemove(const RawAddress& address);
 * Returns true if removed OK, false if not found or ACL link is active.
 */
bool BTM_SecDeleteDevice(const RawAddress& bd_addr) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
    LOG_WARN("Unable to delete link key for unknown device %s",
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return true;
  }

  /* Invalidate bonded status */
  p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN;
  p_dev_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_KNOWN;

  if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
      BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) {
    LOG_WARN("%s FAILED: Cannot Delete when connection to %s is active",
             __func__, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    LOG_WARN("FAILED: Cannot Delete when connection to %s is active",
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return false;
  }

  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec != NULL) {
  RawAddress bda = p_dev_rec->bd_addr;

  LOG_INFO("Remove device %s from filter accept list before delete record",
@@ -189,15 +198,11 @@ bool BTM_SecDeleteDevice(const RawAddress& bd_addr) {
  wipe_secrets_and_remove(p_dev_rec);
  /* Tell controller to get rid of the link key, if it has one stored */
  BTM_DeleteStoredLinkKey(&bda, NULL);
    LOG_INFO("%s %s complete", __func__, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  LOG_INFO("%s complete", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  BTM_LogHistory(kBtmLogTag, bd_addr, "Device removed",
                 base::StringPrintf("device_type:%s bond_type:%s",
                                    DeviceTypeText(device_type).c_str(),
                                    bond_type_text(bond_type).c_str()));
  } else {
    LOG_WARN("%s Unable to delete link key for unknown device %s", __func__,
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  }

  return true;
}