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

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

Merge changes Ibcf00552,If46c5fe1 into main

* changes:
  Avoid unbonding on encryption request failure in peripheral role
  Flag for handling smp failure for bonded devices in peripheral role
parents 64df3259 7ed69cff
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -240,3 +240,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "bonded_device_smp_failure_handling"
    namespace: "bluetooth"
    description: "Don't remove bond on SMP failure for bonded devices in peripheral role"
    bug: "385181815"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+33 −0
Original line number Diff line number Diff line
@@ -1584,6 +1584,34 @@ void btm_ble_connection_established(const RawAddress& bda) {
  }
}

static bool btm_ble_complete_evt_ignore(const tBTM_SEC_DEV_REC* p_dev_rec,
                                        const tBTM_LE_EVT_DATA* p_data) {
  if (!com::android::bluetooth::flags::bonded_device_smp_failure_handling()) {
    return false;
  }
  // Encryption request in peripheral role results in SMP Security request. SMP may generate a
  // SMP_COMPLT_EVT failure event cases like below:
  // 1) Some central devices don't handle cross-over between encryption and SMP security request
  // 2) Link may get disconnected after the SMP security request was sent.
  if (p_data->complt.reason != SMP_SUCCESS && !p_dev_rec->role_central &&
      btm_sec_cb.pairing_bda != p_dev_rec->bd_addr &&
      btm_sec_cb.pairing_bda != p_dev_rec->ble.pseudo_addr &&
      p_dev_rec->sec_rec.is_le_link_key_known() &&
      p_dev_rec->sec_rec.ble_keys.key_type != BTM_LE_KEY_NONE) {
    if (p_dev_rec->sec_rec.is_le_device_encrypted()) {
      log::warn("Bonded device {} is already encrypted, ignoring SMP failure", p_dev_rec->bd_addr);
      return true;
    } else if (p_data->complt.reason == SMP_CONN_TOUT) {
      log::warn("Bonded device {} disconnected while waiting for encryption, ignoring SMP failure",
                p_dev_rec->bd_addr);
      l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle);
      return true;
    }
  }

  return false;
}

static void btm_ble_user_confirmation_req(const RawAddress& bd_addr, tBTM_SEC_DEV_REC* p_dev_rec,
                                          tBTM_LE_EVT event, tBTM_LE_EVT_DATA* p_data) {
  p_dev_rec->sec_rec.sec_flags |= BTM_SEC_LE_AUTHENTICATED;
@@ -1613,6 +1641,11 @@ static void btm_ble_consent_req(const RawAddress& bd_addr, tBTM_LE_EVT_DATA* p_d

static void btm_ble_complete_evt(const RawAddress& bd_addr, tBTM_SEC_DEV_REC* p_dev_rec,
                                 tBTM_LE_EVT_DATA* p_data) {

  if (btm_ble_complete_evt_ignore(p_dev_rec, p_data)) {
    return;
  }

  BTM_BLE_SEC_CALLBACK(BTM_LE_COMPLT_EVT, bd_addr, p_data);

  log::verbose("before update sec_level=0x{:x} sec_flags=0x{:x}", p_data->complt.sec_level,