1e08fbffcSVernon Mauery #include <ipmid/api.hpp>
26a98fe7fSVernon Mauery #include <ipmid/utils.hpp>
3ffd5f042SGeorge Liu #include <phosphor-logging/lg2.hpp>
40b02be92SPatrick Venture #include <xyz/openbmc_project/State/BMC/server.hpp>
50b02be92SPatrick Venture
6fbc6c9d7SPatrick Williams #include <string>
7fbc6c9d7SPatrick Williams
834e3d3f1SNagaraju Goruganti static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
934e3d3f1SNagaraju Goruganti static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
1034e3d3f1SNagaraju Goruganti static constexpr auto reqTransition = "RequestedBMCTransition";
1134e3d3f1SNagaraju Goruganti static constexpr auto match = "bmc0";
1234e3d3f1SNagaraju Goruganti
13523e2d1bSWilly Tu using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC;
1498a23840SMatthew Barth
155087b075SGeorge Liu void registerNetFnGlobalFunctions() __attribute__((constructor));
1698a23840SMatthew Barth
17e9e99d93Sanil kumar appana /** @brief implements cold and warm reset commands
18e9e99d93Sanil kumar appana * @param - None
19e9e99d93Sanil kumar appana * @returns IPMI completion code.
20e9e99d93Sanil kumar appana */
ipmiGlobalReset(ipmi::Context::ptr ctx)21*082de3c9SGeorge Liu ipmi::RspType<> ipmiGlobalReset(ipmi::Context::ptr ctx)
2298a23840SMatthew Barth {
23*082de3c9SGeorge Liu ipmi::DbusObjectInfo bmcStateObj;
24*082de3c9SGeorge Liu boost::system::error_code ec = ipmi::getDbusObject(
25*082de3c9SGeorge Liu ctx, bmcStateIntf, bmcStateRoot, match, bmcStateObj);
26*082de3c9SGeorge Liu if (!ec)
27bc759884SNan Li {
28*082de3c9SGeorge Liu std::string service;
29*082de3c9SGeorge Liu ec = ipmi::getService(ctx, bmcStateIntf, bmcStateObj.first, service);
30*082de3c9SGeorge Liu if (!ec)
31*082de3c9SGeorge Liu {
32*082de3c9SGeorge Liu ec = ipmi::setDbusProperty(
33*082de3c9SGeorge Liu ctx, service, bmcStateObj.first, bmcStateIntf, reqTransition,
34*082de3c9SGeorge Liu convertForMessage(BMC::Transition::Reboot));
3534e3d3f1SNagaraju Goruganti }
36*082de3c9SGeorge Liu }
37*082de3c9SGeorge Liu if (ec)
3834e3d3f1SNagaraju Goruganti {
39*082de3c9SGeorge Liu lg2::error("Exception in Global Reset: {ERROR}", "ERROR", ec.message());
40e9e99d93Sanil kumar appana return ipmi::responseUnspecifiedError();
4134e3d3f1SNagaraju Goruganti }
42bc759884SNan Li
43bc759884SNan Li // Status code.
44e9e99d93Sanil kumar appana return ipmi::responseSuccess();
45bc759884SNan Li }
4698a23840SMatthew Barth
registerNetFnGlobalFunctions()475087b075SGeorge Liu void registerNetFnGlobalFunctions()
4898a23840SMatthew Barth {
490573237fSTom // Cold Reset
50e9e99d93Sanil kumar appana ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
51e9e99d93Sanil kumar appana ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
52e9e99d93Sanil kumar appana ipmiGlobalReset);
5398a23840SMatthew Barth return;
5498a23840SMatthew Barth }
55