From 59287a8869b5253a1b4203e0cc8a92f063dcc7e6 Mon Sep 17 00:00:00 2001 From: Yong Li Date: Tue, 25 Sep 2018 16:08:22 +0800 Subject: [PATCH] Fix "Unspecified error" on ipmi restart cause command Needs to convert the dbus value(enum) into ipmi value(uint8) Tested by: ipmitool chassis restart_cause Signed-off-by: Yong Li --- chassishandler.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/chassishandler.cpp b/chassishandler.cpp index 40eb4f5..c3d4931 100644 --- a/chassishandler.cpp +++ b/chassishandler.cpp @@ -106,7 +106,7 @@ static constexpr auto match = "chassis0"; const static constexpr char* stateHostInterface = "xyz.openbmc_project.State.Host"; const static constexpr char* hostRestartCauseInterface = - "xyz.openbmc_project.State.Host.HostRestartCause"; + "xyz.openbmc_project.State.Host"; const static constexpr char* hostRestartCause = "HostRestartCause"; const static constexpr char chassisCapIntf[] = "xyz.openbmc_project.Control.ChassisCapabilities"; @@ -1764,6 +1764,26 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return rc; } +namespace restart_cause +{ + +using namespace sdbusplus::xyz::openbmc_project::State::server; + +std::map dbusToIpmi = { + {Host::RestartCause::Unknown, 0x0}, + {Host::RestartCause::IpmiCommand, 0x1}, + {Host::RestartCause::ResetButton, 0x2}, + {Host::RestartCause::PowerButton, 0x3}, + {Host::RestartCause::WatchdogTimer, 0x4}, + {Host::RestartCause::OEM, 0x5}, + {Host::RestartCause::PowerPolicyAlwaysOn, 0x6}, + {Host::RestartCause::PowerPolicyPreviousState, 0x7}, + {Host::RestartCause::PEFReset, 0x8}, + {Host::RestartCause::PEFPowerCycle, 0x9}, + {Host::RestartCause::SoftReset, 0xa}, + {Host::RestartCause::RTCWakeup, 0xb}}; +} // namespace restart_cause + ipmi_ret_t ipmi_chassis_get_sys_restart_cause( ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request, ipmi_response_t response, ipmi_data_len_t data_len, ipmi_context_t context) @@ -1787,7 +1807,11 @@ ipmi_ret_t ipmi_chassis_get_sys_restart_cause( ipmi::Value variant = ipmi::getDbusProperty(bus, hostObject.second, hostObject.first, hostRestartCauseInterface, hostRestartCause); - resp->restartCause = variant.get(); + + std::string restartCause = + sdbusplus::message::variant_ns::get(variant); + resp->restartCause = restart_cause::dbusToIpmi.at( + restart_cause::Host::convertRestartCauseFromString(restartCause)); } catch (std::exception& e) -- 2.7.4