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

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

Merge "Avoid cancelling pairing when disconnected on other transport" into main

parents 2a910c69 f4217e22
Loading
Loading
Loading
Loading
+38 −2
Original line number Diff line number Diff line
@@ -3762,14 +3762,25 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason,
  const tBT_TRANSPORT transport =
      (handle == p_dev_rec->hci_handle) ? BT_TRANSPORT_BR_EDR : BT_TRANSPORT_LE;

  bool pairing_transport_matches = true;
  if (com::android::bluetooth::flags::
          cancel_pairing_only_on_disconnected_transport()) {
    tBT_TRANSPORT pairing_transport =
        (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) == 0
            ? BT_TRANSPORT_BR_EDR
            : BT_TRANSPORT_LE;
    pairing_transport_matches = (transport == pairing_transport);
  }

  /* clear unused flags */
  p_dev_rec->sm4 &= BTM_SM4_TRUE;

  /* If we are in the process of bonding we need to tell client that auth failed
   */
  const uint8_t old_pairing_flags = btm_sec_cb.pairing_flags;
  if ((btm_sec_cb.pairing_state != BTM_PAIR_STATE_IDLE) &&
      (btm_sec_cb.pairing_bda == p_dev_rec->bd_addr)) {
  if (btm_sec_cb.pairing_state != BTM_PAIR_STATE_IDLE &&
      btm_sec_cb.pairing_bda == p_dev_rec->bd_addr &&
      pairing_transport_matches) {
    log::debug("Disconnected while pairing process active handle:0x{:04x}",
               handle);
    btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_IDLE);
@@ -3855,6 +3866,31 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason,
                                       : BTM_SEC_STATE_DISCONNECTING_BLE;
    return;
  }

  if (com::android::bluetooth::flags::
          cancel_pairing_only_on_disconnected_transport()) {
    if (btm_sec_cb.pairing_state != BTM_PAIR_STATE_IDLE &&
        btm_sec_cb.pairing_bda == p_dev_rec->bd_addr &&
        !pairing_transport_matches) {
      log::debug("Disconnection on the other transport while pairing");
      return;
    }

    if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_LE_ENCRYPTING &&
        transport != BT_TRANSPORT_LE) {
      log::debug("Disconnection on the other transport while encrypting LE");
      return;
    }

    if ((p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING ||
         p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_ENCRYPTING) &&
        transport != BT_TRANSPORT_BR_EDR) {
      log::debug(
          "Disconnection on the other transport while encrypting BR/EDR");
      return;
    }
  }

  p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE;
  p_dev_rec->sec_rec.security_required = BTM_SEC_NONE;