blob: 19ca291b6f99bae56531e5517740d5b4161174a7 [file] [log] [blame]
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +05301#include <functional>
2#include <systemintfcmds.h>
Vishwanatha Subbanna6e8979d2017-07-13 16:48:20 +05303#include <host-ipmid/ipmid-host-cmd.hpp>
4#include <host-ipmid/ipmid-host-cmd-utils.hpp>
Andrew Geissler1b9d4e52017-03-21 15:04:05 -05005#include <utils.hpp>
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +05306#include <phosphor-logging/log.hpp>
Andrew Geissler83159702017-04-03 13:31:13 -05007#include <config.h>
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +05308#include <host-interface.hpp>
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05009namespace phosphor
10{
11namespace host
12{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053013namespace command
Andrew Geissler83159702017-04-03 13:31:13 -050014{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053015
16// When you see Base:: you know we're referencing our base class
17namespace Base = sdbusplus::xyz::openbmc_project::Control::server;
18
19// IPMI OEM command.
20// https://github.com/openbmc/openbmc/issues/2082 for handling
21// Non-OEM commands that need to send SMS_ATN
22using OEMCmd = uint8_t;
23
24// Map of IPMI OEM command to its equivalent interface command.
25// This is needed when invoking the callback handler to indicate
26// the status of the executed command.
27static const std::map<OEMCmd, Host::Command> intfCommand = {
Andrew Geissler83159702017-04-03 13:31:13 -050028 {
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053029 CMD_HEARTBEAT,
30 Base::Host::Command::Heartbeat
31 },
Andrew Geissler83159702017-04-03 13:31:13 -050032 {
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053033 CMD_POWER,
34 Base::Host::Command::SoftOff
Andrew Geissler83159702017-04-03 13:31:13 -050035 }
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053036};
Andrew Geissler83159702017-04-03 13:31:13 -050037
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053038// Map of Interface command to its corresponding IPMI OEM command.
39// This is needed when pushing IPMI commands to command manager's
40// queue. The same pair will be returned when IPMI asks us
41// why a SMS_ATN was sent
42static const std::map<Host::Command, IpmiCmdData> ipmiCommand = {
43 {
44 Base::Host::Command::Heartbeat,
45 std::make_pair(CMD_HEARTBEAT, 0x00)
46 },
47 {
48 Base::Host::Command::SoftOff,
49 std::make_pair(CMD_POWER, SOFT_OFF)
50 }
51};
Andrew Geissler83159702017-04-03 13:31:13 -050052
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053053// Called at user request
54void Host::execute(Base::Host::Command command)
Andrew Geissler83159702017-04-03 13:31:13 -050055{
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053056 using namespace phosphor::logging;
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050057
Aditya Saripalli5fb14602017-11-09 14:46:27 +053058 log<level::DEBUG>("Pushing cmd on to queue",
Andrew Geissler0c07c322017-03-22 14:02:30 -050059 entry("CONTROL_HOST_CMD=%s",
60 convertForMessage(command)));
61
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053062 auto cmd = std::make_tuple(ipmiCommand.at(command),
63 std::bind(&Host::commandStatusHandler,
64 this, std::placeholders::_1,
65 std::placeholders::_2));
Andrew Geissler0c07c322017-03-22 14:02:30 -050066
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053067 return ipmid_send_cmd_to_host(std::move(cmd));
Andrew Geissler62817fa92017-03-20 14:20:49 -050068}
69
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053070// Called into by Command Manager
71void Host::commandStatusHandler(IpmiCmdData cmd, bool status)
72{
73 // Need to convert <cmd> to the equivalent one mentioned in spec
74 auto value = status ? Result::Success : Result::Failure;
75
76 // Fire a signal
77 this->commandComplete(intfCommand.at(std::get<0>(cmd)), value);
78}
79
80} // namespace command
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050081} // namespace host
82} // namepsace phosphor