blob: e00e07ff1a0eac9a0d96f0707bbdd7907a66e661 [file] [log] [blame]
Vishwanatha Subbanna07655062017-07-14 20:31:57 +05301#include <chrono>
2#include <functional>
3#include <oemhandler.hpp>
4#include <host-ipmid/ipmid-host-cmd.hpp>
5#include <host-ipmid/ipmid-host-cmd-utils.hpp>
6#include <phosphor-logging/log.hpp>
7#include <config.h>
8#include <host-interface.hpp>
9namespace open_power
10{
11namespace host
12{
13namespace command
14{
15
16// IPMI command
17// https://github.com/openbmc/openbmc/issues/2082 for handling
18// Non-OEM commands that need to send SMS_ATN
19using OEMCmd = uint8_t;
20
21// Map of IPMI OEM command to its equivalent interface command.
22// This is needed when invoking the callback handler to indicate
23// the status of the executed command.
24static const std::map<OEMCmd, Host::Command> intfCommand = {
25 {
26 IPMI_CMD_OCC_RESET,
27 Base::Host::Command::OCCReset
28 }
29};
30
31// Called at user request
32void Host::execute(Base::Host::Command command,
33 sdbusplus::message::variant<uint8_t> data)
34{
35 using namespace phosphor::logging;
36
37 log<level::INFO>("Pushing cmd on to queue",
38 entry("CONTROL_HOST_CMD=%s",
Joseph Reynolds9debcd62018-05-30 12:31:45 -050039 convertForMessage(command).c_str()));
Vishwanatha Subbanna07655062017-07-14 20:31:57 +053040
41 // If the command is OCCReset, then all we need is just sensor ID
42 // This is the only command that is being used now.
43 if (command == Base::Host::Command::OCCReset)
44 {
45 auto sensorID = sdbusplus::message::variant_ns::get<uint8_t>(data);
46
47 auto cmd = std::make_tuple(std::make_pair(IPMI_CMD_OCC_RESET, sensorID),
48 std::bind(&Host::commandStatusHandler,
49 this, std::placeholders::_1,
50 std::placeholders::_2));
51
52 return ipmid_send_cmd_to_host(std::move(cmd));
53 }
54 return;
55}
56
57// 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
68} // namespace host
69} // namepsace open_power