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

Commit 6bacbe90 authored by Hui Peng's avatar Hui Peng
Browse files

Reorganize the code for checking auth requirement

Original bug
Bug: 294854926

regressions:
Bug: 299570702

Test: Test: m com.android.btservices
Test: QA validation
Merged-In: I976a5a6d7bb819fd6accdc71eb1501b9606f3ae4
Change-Id: I976a5a6d7bb819fd6accdc71eb1501b9606f3ae4
parent 9e4cef21
Loading
Loading
Loading
Loading
+56 −39
Original line number Original line Diff line number Diff line
@@ -4411,22 +4411,40 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {


  /* If connection is not authenticated and authentication is required */
  /* If connection is not authenticated and authentication is required */
  /* start authentication and return PENDING to the caller */
  /* start authentication and return PENDING to the caller */
  if ((((!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) &&
  if (p_dev_rec->hci_handle != HCI_INVALID_HANDLE) {
        ((p_dev_rec->IsLocallyInitiated() &&
    bool start_auth = false;
          (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) ||

         (!p_dev_rec->IsLocallyInitiated() &&
    // Check link status of BR/EDR
          (p_dev_rec->security_required & BTM_SEC_IN_AUTHENTICATE)))) ||
    if (!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) {
       (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) &&
      if (p_dev_rec->IsLocallyInitiated()) {
        (!p_dev_rec->IsLocallyInitiated() &&
        if (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE) {
         (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) &&
          LOG_DEBUG("Outgoing authentication Required");
      (p_dev_rec->hci_handle != HCI_INVALID_HANDLE)) {
          start_auth = true;
        }
      } else {
        if (p_dev_rec->security_required & BTM_SEC_IN_AUTHENTICATE) {
          LOG_DEBUG("Incoming authentication Required");
          start_auth = true;
        }
      }
    }

    if (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED)) {
      /*
      /*
       * We rely on BTM_SEC_16_DIGIT_PIN_AUTHED being set if MITM is in use,
       * We rely on BTM_SEC_16_DIGIT_PIN_AUTHED being set if MITM is in use,
       * as 16 DIGIT is only needed if MITM is not used. Unfortunately, the
       * as 16 DIGIT is only needed if MITM is not used. Unfortunately, the
       * BTM_SEC_AUTHENTICATED is used for both MITM and non-MITM
       * BTM_SEC_AUTHENTICATED is used for both MITM and non-MITM
       * authenticated connections, hence we cannot distinguish here.
       * authenticated connections, hence we cannot distinguish here.
       */
       */
      if (!p_dev_rec->IsLocallyInitiated()) {
        if (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN) {
          LOG_DEBUG("BTM_SEC_IN_MIN_16_DIGIT_PIN Required");
          start_auth = true;
        }
      }
    }


    if (start_auth) {
      LOG_DEBUG("Security Manager: Start authentication");
      LOG_DEBUG("Security Manager: Start authentication");


      /*
      /*
@@ -4451,8 +4469,7 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {


      btm_sec_wait_and_start_authentication(p_dev_rec);
      btm_sec_wait_and_start_authentication(p_dev_rec);
      return (BTM_CMD_STARTED);
      return (BTM_CMD_STARTED);
  } else {
    }
    LOG_DEBUG("Authentication not required");
  }
  }


  /* If connection is not encrypted and encryption is required */
  /* If connection is not encrypted and encryption is required */