#include "ipmi-standard-override.hpp"

void register_ipmi_override_functions() __attribute__((constructor));

auto ipmiAppGetSelfTestResultsOverride() -> ipmi::RspType<uint8_t, uint8_t> {
  // Byte 2:
  //  55h - No error.
  //  56h - Self Test function not implemented in this controller.
  //  57h - Corrupted or inaccesssible data or devices.
  //  58h - Fatal hardware error.
  //  FFh - reserved.
  //  all other: Device-specific 'internal failure'.
  //  Byte 3:
  //      For byte 2 = 55h, 56h, FFh:     00h
  //      For byte 2 = 58h, all other:    Device-specific
  //      For byte 2 = 57h:   self-test error bitfield.
  //      Note: returning 57h does not imply that all test were run.
  //      [7] 1b = Cannot access SEL device.
  //      [6] 1b = Cannot access SDR Repository.
  //      [5] 1b = Cannot access BMC FRU device.
  //      [4] 1b = IPMB signal lines do not respond.
  //      [3] 1b = SDR Repository empty.
  //      [2] 1b = Internal Use Area of BMC FRU corrupted.
  //      [1] 1b = controller update 'boot block' firmware corrupted.
  //      [0] 1b = controller operational firmware corrupted.
  constexpr uint8_t noError = 0x55;
  constexpr uint8_t bmcOK = 0x55;
  return ipmi::responseSuccess(noError, bmcOK);
}

void register_ipmi_override_functions() {

  // <Get Self Test Results>
  ipmi::registerHandler(ipmi::prioOverride, ipmi::netFnApp,
                        ipmi::app::cmdGetSelfTestResults, ipmi::Privilege::User,
                        ipmiAppGetSelfTestResultsOverride);
}