blob: 1f9bfcb2bfb34e5d9e3671432185d71dd1dd5cc4 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "config.h"
2
3#include "host-interface.hpp"
4
5#include "systemintfcmds.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07006
7#include <functional>
William A. Kennington III194375f2018-12-14 02:14:33 -08008#include <ipmid-host/cmd-utils.hpp>
9#include <ipmid-host/cmd.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070010#include <ipmid/utils.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070011#include <phosphor-logging/log.hpp>
Patrick Venture46470a32018-09-07 19:26:25 -070012
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050013namespace phosphor
14{
15namespace host
16{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053017namespace command
Andrew Geissler83159702017-04-03 13:31:13 -050018{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053019
20// When you see Base:: you know we're referencing our base class
21namespace Base = sdbusplus::xyz::openbmc_project::Control::server;
22
23// IPMI OEM command.
24// https://github.com/openbmc/openbmc/issues/2082 for handling
25// Non-OEM commands that need to send SMS_ATN
26using OEMCmd = uint8_t;
27
28// Map of IPMI OEM command to its equivalent interface command.
29// This is needed when invoking the callback handler to indicate
30// the status of the executed command.
31static const std::map<OEMCmd, Host::Command> intfCommand = {
Patrick Venture0b02be92018-08-31 11:55:55 -070032 {CMD_HEARTBEAT, Base::Host::Command::Heartbeat},
33 {CMD_POWER, Base::Host::Command::SoftOff}};
Andrew Geissler83159702017-04-03 13:31:13 -050034
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053035// Map of Interface command to its corresponding IPMI OEM command.
36// This is needed when pushing IPMI commands to command manager's
37// queue. The same pair will be returned when IPMI asks us
38// why a SMS_ATN was sent
39static const std::map<Host::Command, IpmiCmdData> ipmiCommand = {
Patrick Venture0b02be92018-08-31 11:55:55 -070040 {Base::Host::Command::Heartbeat, std::make_pair(CMD_HEARTBEAT, 0x00)},
41 {Base::Host::Command::SoftOff, std::make_pair(CMD_POWER, SOFT_OFF)}};
Andrew Geissler83159702017-04-03 13:31:13 -050042
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053043// Called at user request
44void Host::execute(Base::Host::Command command)
Andrew Geissler83159702017-04-03 13:31:13 -050045{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053046 using namespace phosphor::logging;
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050047
Patrick Venture0b02be92018-08-31 11:55:55 -070048 log<level::DEBUG>(
49 "Pushing cmd on to queue",
50 entry("CONTROL_HOST_CMD=%s", convertForMessage(command).c_str()));
Andrew Geissler0c07c322017-03-22 14:02:30 -050051
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053052 auto cmd = std::make_tuple(ipmiCommand.at(command),
Patrick Venture0b02be92018-08-31 11:55:55 -070053 std::bind(&Host::commandStatusHandler, this,
54 std::placeholders::_1,
55 std::placeholders::_2));
Andrew Geissler0c07c322017-03-22 14:02:30 -050056
Chen,Yugang0e862fa2019-09-06 11:03:05 +080057 ipmid_send_cmd_to_host(std::move(cmd));
Andrew Geissler62817fa92017-03-20 14:20:49 -050058}
59
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053060// Called into by Command Manager
61void Host::commandStatusHandler(IpmiCmdData cmd, bool status)
62{
63 // Need to convert <cmd> to the equivalent one mentioned in spec
64 auto value = status ? Result::Success : Result::Failure;
65
66 // Fire a signal
67 this->commandComplete(intfCommand.at(std::get<0>(cmd)), value);
68}
69
70} // namespace command
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050071} // namespace host
Patrick Venture0b02be92018-08-31 11:55:55 -070072} // namespace phosphor