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

Commit 264de23c authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

btm_sec: Don't clear security record on encryption failed

Clearing keys will block future tries to enable encryption even on
reconnection unless Bluetooth is turned OFF/ON.

If stack does not remove bonding, it should also not invalidate keys.

Bug: 342516733
Bug: 342521414
Flag: com.android.bluetooth.flags.sec_dont_clear_keys_on_encryption_err
Test: mmm packages/modules/Bluetooth
Test: atest net_test_stack_btm
Change-Id: Ief94ca7a5937160d4436bffb7e7183189eb91a13
parent 596b96ea
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -3271,9 +3271,15 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status,
  if (transport == BT_TRANSPORT_LE) {
    if (status == HCI_ERR_KEY_MISSING || status == HCI_ERR_AUTH_FAILURE ||
        status == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) {
      if (com::android::bluetooth::flags::
              sec_dont_clear_keys_on_encryption_err()) {
        log::error("{} encrypt failure status 0x{:x}", p_dev_rec->bd_addr,
                   status);
      } else {
        p_dev_rec->sec_rec.sec_flags &= ~(BTM_SEC_LE_LINK_KEY_KNOWN);
        p_dev_rec->sec_rec.ble_keys.key_type = BTM_LE_KEY_NONE;
      }
    }
    p_dev_rec->sec_rec.sec_status = status;
    btm_ble_link_encrypted(p_dev_rec->ble.pseudo_addr, encr_enable);