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

Commit 948f1966 authored by Palash Ahuja's avatar Palash Ahuja Committed by Gerrit Code Review
Browse files

Merge "BluetoothMetrics: Log Authentication Complete Event" into main

parents fada88b8 a7bc54fb
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -56,6 +56,37 @@ State MapErrorCodeToState(ErrorCode reason) {
  }
}

State MapHCIStatusToState(tHCI_STATUS status) {
  // TODO - map the error codes to the state enum variants.
  switch (status) {
    case tHCI_STATUS::HCI_SUCCESS:
      return State::SUCCESS;
    // Timeout related errors
    case tHCI_STATUS::HCI_ERR_PAGE_TIMEOUT:
      return State::PAGE_TIMEOUT;
    case tHCI_STATUS::HCI_ERR_CONNECTION_TOUT:
      return State::CONNECTION_TIMEOUT;
    case tHCI_STATUS::HCI_ERR_HOST_TIMEOUT:
      return State::CONNECTION_ACCEPT_TIMEOUT;
    case tHCI_STATUS::HCI_ERR_LMP_RESPONSE_TIMEOUT:
      return State::TRANSACTION_RESPONSE_TIMEOUT;
    case tHCI_STATUS::HCI_ERR_AUTH_FAILURE:
      return State::AUTH_FAILURE;
    case tHCI_STATUS::HCI_ERR_CONNECTION_EXISTS:
      return State::ALREADY_CONNECTED;
    case tHCI_STATUS::HCI_ERR_REPEATED_ATTEMPTS:
      return State::REPEATED_ATTEMPTS;
    case tHCI_STATUS::HCI_ERR_KEY_MISSING:
      return State::KEY_MISSING;
    case tHCI_STATUS::HCI_ERR_PAIRING_NOT_ALLOWED:
      return State::PAIRING_NOT_ALLOWED;
    case tHCI_STATUS::HCI_ERR_HOST_REJECT_RESOURCES:
      return State::RESOURCES_EXCEEDED;
    default:
      return State::STATE_UNKNOWN;
  }
}

void LogAclCompletionEvent(const hci::Address& address, ErrorCode reason,
                           bool is_locally_initiated) {
  bluetooth::os::LogMetricBluetoothEvent(address,
@@ -87,5 +118,14 @@ void LogUserConfirmationRequestResponse(const hci::Address& address, bool positi
                                         positive ? State::SUCCESS : State::FAIL);
}

void LogAuthenticationComplete(const RawAddress& raw_address, tHCI_STATUS hci_status) {
  hci::Address address = bluetooth::ToGdAddress(raw_address);
  bluetooth::os::LogMetricBluetoothEvent(address,
                                         hci_status == tHCI_STATUS::HCI_SUCCESS
                                                 ? EventType::AUTHENTICATION_COMPLETE
                                                 : EventType::AUTHENTICATION_COMPLETE_FAIL,
                                         MapHCIStatusToState(hci_status));
}

}  // namespace metrics
}  // namespace bluetooth
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include "hci/address.h"
#include "hci/hci_packets.h"
#include "stack/include/btm_status.h"
#include "stack/include/hci_error_code.h"
#include "types/raw_address.h"

namespace bluetooth {
@@ -32,5 +33,7 @@ void LogAclAfterRemoteNameRequest(const RawAddress& raw_address, tBTM_STATUS sta

void LogUserConfirmationRequestResponse(const hci::Address& address, bool positive);

void LogAuthenticationComplete(const RawAddress& raw_address, tHCI_STATUS hci_status);

}  // namespace metrics
}  // namespace bluetooth
+1 −0
Original line number Diff line number Diff line
@@ -2998,6 +2998,7 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) {
  bool was_authenticating = false;

  if (p_dev_rec) {
    bluetooth::metrics::LogAuthenticationComplete(p_dev_rec->bd_addr, status);
    log::verbose(
            "Security Manager: in state: {}, handle: {}, status: {}, "
            "dev->sec_rec.classic_link:{}, bda: {}, RName: {}",