blob: 7b64d42af50a4a8f1aa52fbfecd9f69fc2e9321a [file] [log] [blame]
Vernon Mauerye08fbff2019-04-03 09:19:34 -07001#include <ipmid/api.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07002#include <ipmid/utils.hpp>
George Liuffd5f042024-07-19 09:32:15 +08003#include <phosphor-logging/lg2.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07004#include <xyz/openbmc_project/State/BMC/server.hpp>
5
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05006#include <string>
7
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06008static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
9static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
10static constexpr auto reqTransition = "RequestedBMCTransition";
11static constexpr auto match = "bmc0";
12
Willy Tu523e2d12023-09-05 11:36:48 -070013using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC;
Williamcb8ac882015-12-31 19:15:17 +080014
George Liu5087b072025-03-11 19:28:17 +080015void registerNetFnGlobalFunctions() __attribute__((constructor));
Williamcb8ac882015-12-31 19:15:17 +080016
anil kumar appanae9e99d92019-04-28 23:47:24 +000017/** @brief implements cold and warm reset commands
18 * @param - None
19 * @returns IPMI completion code.
20 */
George Liu082de3c2025-03-03 20:33:30 +080021ipmi::RspType<> ipmiGlobalReset(ipmi::Context::ptr ctx)
Williamcb8ac882015-12-31 19:15:17 +080022{
George Liu082de3c2025-03-03 20:33:30 +080023 ipmi::DbusObjectInfo bmcStateObj;
24 boost::system::error_code ec = ipmi::getDbusObject(
25 ctx, bmcStateIntf, bmcStateRoot, match, bmcStateObj);
26 if (!ec)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060027 {
George Liu082de3c2025-03-03 20:33:30 +080028 std::string service;
29 ec = ipmi::getService(ctx, bmcStateIntf, bmcStateObj.first, service);
30 if (!ec)
31 {
32 ec = ipmi::setDbusProperty(
33 ctx, service, bmcStateObj.first, bmcStateIntf, reqTransition,
34 convertForMessage(BMC::Transition::Reboot));
35 }
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060036 }
George Liu082de3c2025-03-03 20:33:30 +080037 if (ec)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060038 {
George Liu082de3c2025-03-03 20:33:30 +080039 lg2::error("Exception in Global Reset: {ERROR}", "ERROR", ec.message());
anil kumar appanae9e99d92019-04-28 23:47:24 +000040 return ipmi::responseUnspecifiedError();
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060041 }
Nan Libc759882016-08-22 15:00:21 +080042
43 // Status code.
anil kumar appanae9e99d92019-04-28 23:47:24 +000044 return ipmi::responseSuccess();
Nan Libc759882016-08-22 15:00:21 +080045}
Williamcb8ac882015-12-31 19:15:17 +080046
George Liu5087b072025-03-11 19:28:17 +080047void registerNetFnGlobalFunctions()
Williamcb8ac882015-12-31 19:15:17 +080048{
Tom05732372016-09-06 17:21:23 +053049 // Cold Reset
anil kumar appanae9e99d92019-04-28 23:47:24 +000050 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
51 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
52 ipmiGlobalReset);
Ratan Guptaeedf4f52016-02-25 18:53:52 +053053 return;
Williamcb8ac882015-12-31 19:15:17 +080054}