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

Commit 4b86ebbf authored by Hui Peng's avatar Hui Peng Committed by Gerrit Code Review
Browse files

Merge "Backport "Reorganize the code for ..." to AOSP" into main

parents 2770e354 01f9d8e5
Loading
Loading
Loading
Loading
+56 −39
Original line number Diff line number Diff line
@@ -4482,22 +4482,40 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {

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

    // Check link status of BR/EDR
    if (!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) {
      if (p_dev_rec->IsLocallyInitiated()) {
        if (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE) {
          LOG_DEBUG("Outgoing authentication Required");
          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,
       * as 16 DIGIT is only needed if MITM is not used. Unfortunately, the
       * BTM_SEC_AUTHENTICATED is used for both MITM and non-MITM
       * 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");

      /*
@@ -4522,8 +4540,7 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {

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

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