blob: f6b24ac8a310d0a9bacef78557c551f50c0e714a [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "globalhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Vernon Mauerye08fbff2019-04-03 09:19:34 -07003#include <ipmid/api.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07004#include <ipmid/utils.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06007#include <string>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <xyz/openbmc_project/Common/error.hpp>
9#include <xyz/openbmc_project/State/BMC/server.hpp>
10
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060011static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
12static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
13static constexpr auto reqTransition = "RequestedBMCTransition";
14static constexpr auto match = "bmc0";
15
16using namespace phosphor::logging;
17using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080018
Williamcb8ac882015-12-31 19:15:17 +080019void register_netfn_global_functions() __attribute__((constructor));
20
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060021void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080022{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060023 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080024
Patrick Venture0b02be92018-08-31 11:55:55 -070025 auto bmcStateObj =
26 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080027
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060028 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080029
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060030 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070031 reqTransition,
32 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080033}
34
anil kumar appanae9e99d92019-04-28 23:47:24 +000035/** @brief implements cold and warm reset commands
36 * @param - None
37 * @returns IPMI completion code.
38 */
39ipmi::RspType<> ipmiGlobalReset()
Williamcb8ac882015-12-31 19:15:17 +080040{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060041 try
42 {
43 resetBMC();
44 }
45 catch (std::exception& e)
46 {
47 log<level::ERR>(e.what());
anil kumar appanae9e99d92019-04-28 23:47:24 +000048 return ipmi::responseUnspecifiedError();
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060049 }
Nan Libc759882016-08-22 15:00:21 +080050
51 // Status code.
anil kumar appanae9e99d92019-04-28 23:47:24 +000052 return ipmi::responseSuccess();
Nan Libc759882016-08-22 15:00:21 +080053}
Williamcb8ac882015-12-31 19:15:17 +080054
55void register_netfn_global_functions()
56{
anil kumar appanae9e99d92019-04-28 23:47:24 +000057
Tom05732372016-09-06 17:21:23 +053058 // Cold Reset
anil kumar appanae9e99d92019-04-28 23:47:24 +000059 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
60 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
61 ipmiGlobalReset);
62 // Warm Reset
63 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
64 ipmi::app::cmdWarmReset, ipmi::Privilege::Admin,
65 ipmiGlobalReset);
Ratan Guptaeedf4f52016-02-25 18:53:52 +053066 return;
Williamcb8ac882015-12-31 19:15:17 +080067}