1 #include "globalhandler.hpp"
2
3 #include <ipmid/api.hpp>
4 #include <ipmid/utils.hpp>
5 #include <phosphor-logging/lg2.hpp>
6 #include <xyz/openbmc_project/State/BMC/server.hpp>
7
8 #include <string>
9
10 static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
11 static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
12 static constexpr auto reqTransition = "RequestedBMCTransition";
13 static constexpr auto match = "bmc0";
14
15 using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC;
16
17 void register_netfn_global_functions() __attribute__((constructor));
18
resetBMC()19 void resetBMC()
20 {
21 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
22
23 auto bmcStateObj =
24 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
25
26 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
27
28 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
29 reqTransition,
30 convertForMessage(BMC::Transition::Reboot));
31 }
32
33 /** @brief implements cold and warm reset commands
34 * @param - None
35 * @returns IPMI completion code.
36 */
ipmiGlobalReset()37 ipmi::RspType<> ipmiGlobalReset()
38 {
39 try
40 {
41 resetBMC();
42 }
43 catch (const std::exception& e)
44 {
45 lg2::error("Exception in Global Reset: {ERROR}", "ERROR", e);
46 return ipmi::responseUnspecifiedError();
47 }
48
49 // Status code.
50 return ipmi::responseSuccess();
51 }
52
register_netfn_global_functions()53 void register_netfn_global_functions()
54 {
55 // Cold Reset
56 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
57 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
58 ipmiGlobalReset);
59 return;
60 }
61