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

Commit 829d8981 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Encrypt LE link immediately on reconnection

LE link must be encrypted immediately on connection if device are
already bonded.

Ignore-AOSP-First: security
Test: mmm packages/modules/Bluetooth
Flag: com.android.bluetooth.flags.le_enc_on_reconnection
Bug: 362977693
Bug: 363033295
Change-Id: I607af8214f4fd9c3905f2e053ba136cd6189361f
parent 9520cdc1
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1535,13 +1535,22 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t /* enc_mo
 *
 ******************************************************************************/
void btm_ble_connection_established(const RawAddress& bda) {
  if (!com::android::bluetooth::flags::name_discovery_for_le_pairing()) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
  if (p_dev_rec == nullptr) {
    log::warn("No security record for {}", bda);
    return;
  }

  // Encrypt the link if device is bonded
  if (com::android::bluetooth::flags::le_enc_on_reconnection() &&
      p_dev_rec->sec_rec.is_le_link_key_known()) {
    btm_ble_set_encryption(bda, BTM_BLE_SEC_ENCRYPT,
                           p_dev_rec->role_central ? HCI_ROLE_CENTRAL : HCI_ROLE_PERIPHERAL);
  }

  // Read device name if it is not known already, we may need it for pairing
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
  if (p_dev_rec != nullptr && !p_dev_rec->sec_rec.is_name_known()) {
  if (com::android::bluetooth::flags::name_discovery_for_le_pairing() &&
      !p_dev_rec->sec_rec.is_name_known()) {
    btm_ble_read_remote_name(bda, nullptr);
  }
}