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

Commit ed52d214 authored by Chris Manton's avatar Chris Manton
Browse files

Add helper to decode hci status

Bug: 166280067
Tag: #gd-refactor
Test: compile & verify basic functions working
Change-Id: Ifb04fa089770d876705601a36608226375c29132
parent 751b84a4
Loading
Loading
Loading
Loading
+84 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@


#include "gd/packet/raw_builder.h"
#include "gd/packet/raw_builder.h"
#include "stack/include/bt_types.h"
#include "stack/include/bt_types.h"
#include "stack/include/hci_error_code.h"


namespace bluetooth {
namespace bluetooth {


@@ -75,4 +76,87 @@ inline std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket(
  return payload;
  return payload;
}
}


inline uint8_t ToLegacyHciErrorCode(hci::ErrorCode reason) {
  switch (reason) {
    case hci::ErrorCode::SUCCESS:
      return HCI_SUCCESS;
    case hci::ErrorCode::UNKNOWN_HCI_COMMAND:
      return HCI_ERR_ILLEGAL_COMMAND;
    case hci::ErrorCode::UNKNOWN_CONNECTION:
      return HCI_ERR_NO_CONNECTION;
    case hci::ErrorCode::HARDWARE_FAILURE:
      return HCI_ERR_HW_FAILURE;
    case hci::ErrorCode::PAGE_TIMEOUT:
      return HCI_ERR_PAGE_TIMEOUT;
    case hci::ErrorCode::AUTHENTICATION_FAILURE:
      return HCI_ERR_AUTH_FAILURE;
    case hci::ErrorCode::PIN_OR_KEY_MISSING:
      return HCI_ERR_KEY_MISSING;
    case hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED:
      return HCI_ERR_MEMORY_FULL;
    case hci::ErrorCode::CONNECTION_TIMEOUT:
      return HCI_ERR_CONNECTION_TOUT;
    case hci::ErrorCode::CONNECTION_LIMIT_EXCEEDED:
      return HCI_ERR_MAX_NUM_OF_CONNECTIONS;
    case hci::ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED:
      return HCI_ERR_MAX_NUM_OF_SCOS;
    case hci::ErrorCode::CONNECTION_ALREADY_EXISTS:
      return HCI_ERR_CONNECTION_EXISTS;
    case hci::ErrorCode::COMMAND_DISALLOWED:
      return HCI_ERR_COMMAND_DISALLOWED;
    case hci::ErrorCode::CONNECTION_REJECTED_LIMITED_RESOURCES:
      return HCI_ERR_HOST_REJECT_RESOURCES;
    case hci::ErrorCode::CONNECTION_REJECTED_SECURITY_REASONS:
      return HCI_ERR_HOST_REJECT_SECURITY;
    case hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR:
      return HCI_ERR_HOST_REJECT_DEVICE;
    case hci::ErrorCode::CONNECTION_ACCEPT_TIMEOUT:
      return HCI_ERR_HOST_TIMEOUT;
    case hci::ErrorCode::UNSUPORTED_FEATURE_OR_PARAMETER_VALUE:
      return static_cast<uint8_t>(
          hci::ErrorCode::UNSUPORTED_FEATURE_OR_PARAMETER_VALUE);
    case hci::ErrorCode::INVALID_HCI_COMMAND_PARAMETERS:
      return HCI_ERR_ILLEGAL_PARAMETER_FMT;
    case hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION:
      return HCI_ERR_PEER_USER;
    case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES:
      return static_cast<uint8_t>(
          hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES);
    case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF:
      return static_cast<uint8_t>(
          hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF);
    case hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST:
      return HCI_ERR_CONN_CAUSE_LOCAL_HOST;
    case hci::ErrorCode::REPEATED_ATTEMPTS:
      return HCI_ERR_REPEATED_ATTEMPTS;
    case hci::ErrorCode::PAIRING_NOT_ALLOWED:
      return HCI_ERR_PAIRING_NOT_ALLOWED;
    case hci::ErrorCode::UNKNOWN_LMP_PDU:
      return static_cast<uint8_t>(hci::ErrorCode::UNKNOWN_LMP_PDU);
    case hci::ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE:
      return HCI_ERR_UNSUPPORTED_REM_FEATURE;
    case hci::ErrorCode::SCO_OFFSET_REJECTED:
      return static_cast<uint8_t>(hci::ErrorCode::SCO_OFFSET_REJECTED);
    case hci::ErrorCode::SCO_INTERVAL_REJECTED:
      return static_cast<uint8_t>(hci::ErrorCode::SCO_INTERVAL_REJECTED);
    case hci::ErrorCode::SCO_AIR_MODE_REJECTED:
      return static_cast<uint8_t>(hci::ErrorCode::SCO_AIR_MODE_REJECTED);
    case hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS:
      return static_cast<uint8_t>(hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS);
    case hci::ErrorCode::UNSPECIFIED_ERROR:
      return HCI_ERR_UNSPECIFIED;
    case hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER:
      return static_cast<uint8_t>(
          hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER);
    case hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED:
      return static_cast<uint8_t>(hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED);
    case hci::ErrorCode::LINK_LAYER_COLLISION:
      return HCI_ERR_LMP_ERR_TRANS_COLLISION;
    case hci::ErrorCode::ENCRYPTION_MODE_NOT_ACCEPTABLE:
      return HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE;
    case hci::ErrorCode::CONTROLLER_BUSY:
      return static_cast<uint8_t>(hci::ErrorCode::CONTROLLER_BUSY);
  }
}

}  // namespace bluetooth
}  // namespace bluetooth