xref: /openbmc/phosphor-host-ipmid/globalhandler.cpp (revision b1f1f1163b2313c04ea5e96e7897d801ad3ff8f8)
1 #include <ipmid/api.hpp>
2 #include <ipmid/utils.hpp>
3 #include <phosphor-logging/lg2.hpp>
4 #include <xyz/openbmc_project/State/BMC/server.hpp>
5 
6 #include <string>
7 
8 using BMCState = sdbusplus::server::xyz::openbmc_project::state::BMC;
9 
10 void registerNetFnGlobalFunctions() __attribute__((constructor));
11 
12 /** @brief implements cold and warm reset commands
13  *  @param - None
14  *  @returns IPMI completion code.
15  */
ipmiGlobalReset(ipmi::Context::ptr ctx)16 ipmi::RspType<> ipmiGlobalReset(ipmi::Context::ptr ctx)
17 {
18     ipmi::DbusObjectInfo bmcStateObj;
19     boost::system::error_code ec = ipmi::getDbusObject(
20         ctx, BMCState::interface, BMCState::namespace_path::value,
21         BMCState::namespace_path::bmc, bmcStateObj);
22     if (!ec)
23     {
24         std::string service;
25         ec = ipmi::getService(ctx, BMCState::interface, bmcStateObj.first,
26                               service);
27         if (!ec)
28         {
29             ec = ipmi::setDbusProperty(
30                 ctx, service, bmcStateObj.first, BMCState::interface,
31                 BMCState::property_names::requested_bmc_transition,
32                 convertForMessage(BMCState::Transition::Reboot));
33         }
34     }
35     if (ec)
36     {
37         lg2::error("Exception in Global Reset: {ERROR}", "ERROR", ec.message());
38         return ipmi::responseUnspecifiedError();
39     }
40 
41     // Status code.
42     return ipmi::responseSuccess();
43 }
44 
registerNetFnGlobalFunctions()45 void registerNetFnGlobalFunctions()
46 {
47     // Cold Reset
48     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
49                           ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
50                           ipmiGlobalReset);
51     return;
52 }
53