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

Commit 783ef4e0 authored by Rahul Arya's avatar Rahul Arya Committed by Cherrypicker Worker
Browse files

Don't ignore encryption change events while in IDLE state

If we hit an LMP timeout, we may have pending security operations while
in the IDLE state. If we then get an encryption change event while in
IDLE, we should handle it, as otherwise these security operations will
be unhandled.

Test: manual
Bug: 267672620
(cherry picked from https://android-review.googlesource.com/q/commit:ddb86a183f311f8f6f82178d011a18fe2d2cc1b1)
Merged-In: I61c6eb5bd72ba6c3dac1186de1b893e5b461e368
Change-Id: I61c6eb5bd72ba6c3dac1186de1b893e5b461e368
Bug: 263323082
parent 56d0a41f
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -162,6 +162,18 @@ static bool concurrentPeerAuthIsEnabled() {
  return sCONCURRENT_PEER_AUTH_IS_ENABLED;
}

/**
 * Whether we should handle encryption change events from a peer device, while
 * we are in the IDLE state. This matters if we are waiting to retry encryption
 * following an LMP timeout, and then we get an encryption change event from the
 * peer.
 */
static bool handleUnexpectedEncryptionChange() {
  static const bool sHandleUnexpectedEncryptionChange = osi_property_get_bool(
      "bluetooth.btm.sec.handle_unexpected_encryption_change.enabled", false);
  return sHandleUnexpectedEncryptionChange;
}

void NotifyBondingCanceled(tBTM_STATUS btm_status) {
  if (btm_cb.api.p_bond_cancel_cmpl_callback) {
    btm_cb.api.p_bond_cancel_cmpl_callback(BTM_SUCCESS);
@@ -3415,12 +3427,16 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status,
                      __func__, p_dev_rec, p_dev_rec->p_callback);
      p_dev_rec->p_callback = NULL;
      l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr);
      return;
    } else if (!concurrentPeerAuthIsEnabled() &&
               p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) {
      p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
      return;
    }
    if (!handleUnexpectedEncryptionChange()) {
      return;
    }
  }

  p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
  /* If encryption setup failed, notify the waiting layer */