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

Commit 1102fdba authored by Hui Peng's avatar Hui Peng Committed by Automerger Merge Worker
Browse files

Reorganize the code for checking auth requirement am: 6bacbe90

parents 0ef14bdb 6bacbe90
Loading
Loading
Loading
Loading
+56 −39
Original line number Diff line number Diff line
@@ -4439,22 +4439,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");

      /*
@@ -4479,8 +4497,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 */