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

Commit 2a0a6081 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Allow encryption request to proceed in unrelated states

Device security state is shared for both transports. Encryption request is saved if security
state is not idle.
This means that security state for a transport can block encryption request the encryption
request for another transport. Saved encryption requests are revived for just updating the
requester of encryption change status when encryption change is event is generated. Thus the
saved encryption requests are never acted upon.
For, example if LE encryption is requested while the BR/EDR link is disconnecting, the LE
encryption request is blocked and never acted upon.

Test: m com.android.btservices
Bug: 294886212
Change-Id: I7d29f6575d0b5ed3578051d800976c5f3149e552
parent 78686c7a
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;