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

Commit 39f9817d authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "Allow encryption request to proceed in unrelated states" into main am: a9888dd8

parents 4cab46c7 a9888dd8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -396,6 +396,7 @@ init_flags!(
        sdp_return_classic_services_when_le_discovery_fails = true,
        use_rsi_from_cached_inqiry_results = false,
        att_mtu_default: i32 = 517,
        encryption_in_busy_state = true,
    }
    // dynamic flags can be updated at runtime and should be accessed directly
    // to check.
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ mod ffi {
        fn sdp_return_classic_services_when_le_discovery_fails_is_enabled() -> bool;
        fn use_rsi_from_cached_inqiry_results_is_enabled() -> bool;
        fn get_att_mtu_default() -> i32;
        fn encryption_in_busy_state_is_enabled() -> bool;
    }
}

+46 −7
Original line number Diff line number Diff line
@@ -1148,7 +1148,45 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
      break;
  }

  /* enqueue security request if security is active */
  /* Enqueue security request if security is active */
  if (bluetooth::common::init_flags::encryption_in_busy_state_is_enabled()) {
    bool enqueue = false;
    switch (p_dev_rec->sec_state) {
      case BTM_SEC_STATE_AUTHENTICATING:
      case BTM_SEC_STATE_DISCONNECTING_BOTH:
        /* Applicable for both transports */
        enqueue = true;
        break;

      case BTM_SEC_STATE_ENCRYPTING:
      case BTM_SEC_STATE_DISCONNECTING:
        if (transport == BT_TRANSPORT_BR_EDR) {
          enqueue = true;
        }
        break;

      case BTM_SEC_STATE_LE_ENCRYPTING:
      case BTM_SEC_STATE_DISCONNECTING_BLE:
        if (transport == BT_TRANSPORT_LE) {
          enqueue = true;
        }
        break;

      default:
        if (p_dev_rec->p_callback != nullptr) {
          enqueue = true;
        }
        break;
    }

    if (enqueue) {
      LOG_WARN("Security Manager: Enqueue request in state:%s",
               security_state_text(p_dev_rec->sec_state).c_str());
      btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data,
                                    sec_act);
      return BTM_CMD_STARTED;
    }
  } else {
    if (p_dev_rec->p_callback || (p_dev_rec->sec_state != BTM_SEC_STATE_IDLE)) {
      LOG_WARN("Security Manager: BTM_SetEncryption busy, enqueue request");
      btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data,
@@ -1156,6 +1194,7 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
      LOG_INFO("Queued start encryption");
      return BTM_CMD_STARTED;
    }
  }

  p_dev_rec->p_callback = p_callback;
  p_dev_rec->p_ref_data = p_ref_data;