102261c0cSPatrick Venture #include <config.h>
202261c0cSPatrick Venture 
307655065SVishwanatha Subbanna #include <host-interface.hpp>
4822eaf6dSWilliam A. Kennington III #include <ipmid-host/cmd-utils.hpp>
5822eaf6dSWilliam A. Kennington III #include <ipmid-host/cmd.hpp>
602261c0cSPatrick Venture #include <oemhandler.hpp>
702261c0cSPatrick Venture #include <phosphor-logging/log.hpp>
8490126f9SPatrick Williams 
9490126f9SPatrick Williams #include <chrono>
10490126f9SPatrick Williams #include <functional>
1107655065SVishwanatha Subbanna namespace open_power
1207655065SVishwanatha Subbanna {
1307655065SVishwanatha Subbanna namespace host
1407655065SVishwanatha Subbanna {
1507655065SVishwanatha Subbanna namespace command
1607655065SVishwanatha Subbanna {
1707655065SVishwanatha Subbanna 
1807655065SVishwanatha Subbanna // IPMI command
1907655065SVishwanatha Subbanna // https://github.com/openbmc/openbmc/issues/2082 for handling
2007655065SVishwanatha Subbanna // Non-OEM commands that need to send SMS_ATN
2107655065SVishwanatha Subbanna using OEMCmd = uint8_t;
2207655065SVishwanatha Subbanna 
2307655065SVishwanatha Subbanna // Map of IPMI OEM command to its equivalent interface command.
2407655065SVishwanatha Subbanna // This is needed when invoking the callback handler to indicate
2507655065SVishwanatha Subbanna // the status of the executed command.
2607655065SVishwanatha Subbanna static const std::map<OEMCmd, Host::Command> intfCommand = {
2702261c0cSPatrick Venture     {IPMI_CMD_OCC_RESET, Base::Host::Command::OCCReset}};
2807655065SVishwanatha Subbanna 
2907655065SVishwanatha Subbanna // Called at user request
execute(Base::Host::Command command,std::variant<uint8_t> data)3061950109SPatrick Williams void Host::execute(Base::Host::Command command, std::variant<uint8_t> data)
3107655065SVishwanatha Subbanna {
3207655065SVishwanatha Subbanna     using namespace phosphor::logging;
3307655065SVishwanatha Subbanna 
3402261c0cSPatrick Venture     log<level::INFO>(
3502261c0cSPatrick Venture         "Pushing cmd on to queue",
3602261c0cSPatrick Venture         entry("CONTROL_HOST_CMD=%s", convertForMessage(command).c_str()));
3707655065SVishwanatha Subbanna 
3807655065SVishwanatha Subbanna     // If the command is OCCReset, then all we need is just sensor ID
3907655065SVishwanatha Subbanna     // This is the only command that is being used now.
4007655065SVishwanatha Subbanna     if (command == Base::Host::Command::OCCReset)
4107655065SVishwanatha Subbanna     {
4212f96693SPatrick Williams         auto sensorID = std::get<uint8_t>(data);
4307655065SVishwanatha Subbanna 
44*d9c74acdSPatrick Williams         auto cmd = std::make_tuple(
45*d9c74acdSPatrick Williams             std::make_pair(IPMI_CMD_OCC_RESET, sensorID),
46*d9c74acdSPatrick Williams             std::bind(&Host::commandStatusHandler, this, std::placeholders::_1,
4707655065SVishwanatha Subbanna                       std::placeholders::_2));
4807655065SVishwanatha Subbanna 
4907655065SVishwanatha Subbanna         return ipmid_send_cmd_to_host(std::move(cmd));
5007655065SVishwanatha Subbanna     }
5107655065SVishwanatha Subbanna     return;
5207655065SVishwanatha Subbanna }
5307655065SVishwanatha Subbanna 
5407655065SVishwanatha Subbanna // Called into by Command Manager
commandStatusHandler(IpmiCmdData cmd,bool status)5507655065SVishwanatha Subbanna void Host::commandStatusHandler(IpmiCmdData cmd, bool status)
5607655065SVishwanatha Subbanna {
5707655065SVishwanatha Subbanna     // Need to convert <cmd> to the equivalent one mentioned in spec
5807655065SVishwanatha Subbanna     auto value = status ? Result::Success : Result::Failure;
5907655065SVishwanatha Subbanna 
6007655065SVishwanatha Subbanna     // Fire a signal
6107655065SVishwanatha Subbanna     this->commandComplete(intfCommand.at(std::get<0>(cmd)), value);
6207655065SVishwanatha Subbanna }
6307655065SVishwanatha Subbanna 
6407655065SVishwanatha Subbanna } // namespace command
6507655065SVishwanatha Subbanna } // namespace host
6602261c0cSPatrick Venture } // namespace open_power
67