blob: 1f27163ab5a325f4850400c3df92ffa2327f7182 [file] [log] [blame]
Andrew Geissler83159702017-04-03 13:31:13 -05001#include <config.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07002#include <systemintfcmds.h>
3
4#include <functional>
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +05305#include <host-interface.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include <host-ipmid/ipmid-host-cmd-utils.hpp>
7#include <host-ipmid/ipmid-host-cmd.hpp>
8#include <phosphor-logging/log.hpp>
9#include <utils.hpp>
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050010namespace phosphor
11{
12namespace host
13{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053014namespace command
Andrew Geissler83159702017-04-03 13:31:13 -050015{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053016
17// When you see Base:: you know we're referencing our base class
18namespace Base = sdbusplus::xyz::openbmc_project::Control::server;
19
20// IPMI OEM command.
21// https://github.com/openbmc/openbmc/issues/2082 for handling
22// Non-OEM commands that need to send SMS_ATN
23using OEMCmd = uint8_t;
24
25// Map of IPMI OEM command to its equivalent interface command.
26// This is needed when invoking the callback handler to indicate
27// the status of the executed command.
28static const std::map<OEMCmd, Host::Command> intfCommand = {
Patrick Venture0b02be92018-08-31 11:55:55 -070029 {CMD_HEARTBEAT, Base::Host::Command::Heartbeat},
30 {CMD_POWER, Base::Host::Command::SoftOff}};
Andrew Geissler83159702017-04-03 13:31:13 -050031
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053032// Map of Interface command to its corresponding IPMI OEM command.
33// This is needed when pushing IPMI commands to command manager's
34// queue. The same pair will be returned when IPMI asks us
35// why a SMS_ATN was sent
36static const std::map<Host::Command, IpmiCmdData> ipmiCommand = {
Patrick Venture0b02be92018-08-31 11:55:55 -070037 {Base::Host::Command::Heartbeat, std::make_pair(CMD_HEARTBEAT, 0x00)},
38 {Base::Host::Command::SoftOff, std::make_pair(CMD_POWER, SOFT_OFF)}};
Andrew Geissler83159702017-04-03 13:31:13 -050039
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053040// Called at user request
41void Host::execute(Base::Host::Command command)
Andrew Geissler83159702017-04-03 13:31:13 -050042{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053043 using namespace phosphor::logging;
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050044
Patrick Venture0b02be92018-08-31 11:55:55 -070045 log<level::DEBUG>(
46 "Pushing cmd on to queue",
47 entry("CONTROL_HOST_CMD=%s", convertForMessage(command).c_str()));
Andrew Geissler0c07c322017-03-22 14:02:30 -050048
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053049 auto cmd = std::make_tuple(ipmiCommand.at(command),
Patrick Venture0b02be92018-08-31 11:55:55 -070050 std::bind(&Host::commandStatusHandler, this,
51 std::placeholders::_1,
52 std::placeholders::_2));
Andrew Geissler0c07c322017-03-22 14:02:30 -050053
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053054 return ipmid_send_cmd_to_host(std::move(cmd));
Andrew Geissler62817fa92017-03-20 14:20:49 -050055}
56
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053057// Called into by Command Manager
58void Host::commandStatusHandler(IpmiCmdData cmd, bool status)
59{
60 // Need to convert <cmd> to the equivalent one mentioned in spec
61 auto value = status ? Result::Success : Result::Failure;
62
63 // Fire a signal
64 this->commandComplete(intfCommand.at(std::get<0>(cmd)), value);
65}
66
67} // namespace command
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050068} // namespace host
Patrick Venture0b02be92018-08-31 11:55:55 -070069} // namespace phosphor