blob: 36cf0a48d6401e1e7be5e827622b62306eec5407 [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
Alexander Hansenb1f1f112025-11-07 16:36:43 +01008using BMCState = sdbusplus::server::xyz::openbmc_project::state::BMC;
Williamcb8ac882015-12-31 19:15:17 +08009
George Liu5087b072025-03-11 19:28:17 +080010void registerNetFnGlobalFunctions() __attribute__((constructor));
Williamcb8ac882015-12-31 19:15:17 +080011
anil kumar appanae9e99d92019-04-28 23:47:24 +000012/** @brief implements cold and warm reset commands
13 * @param - None
14 * @returns IPMI completion code.
15 */
George Liu082de3c2025-03-03 20:33:30 +080016ipmi::RspType<> ipmiGlobalReset(ipmi::Context::ptr ctx)
Williamcb8ac882015-12-31 19:15:17 +080017{
George Liu082de3c2025-03-03 20:33:30 +080018 ipmi::DbusObjectInfo bmcStateObj;
19 boost::system::error_code ec = ipmi::getDbusObject(
Alexander Hansenb1f1f112025-11-07 16:36:43 +010020 ctx, BMCState::interface, BMCState::namespace_path::value,
21 BMCState::namespace_path::bmc, bmcStateObj);
George Liu082de3c2025-03-03 20:33:30 +080022 if (!ec)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060023 {
George Liu082de3c2025-03-03 20:33:30 +080024 std::string service;
Alexander Hansenb1f1f112025-11-07 16:36:43 +010025 ec = ipmi::getService(ctx, BMCState::interface, bmcStateObj.first,
26 service);
George Liu082de3c2025-03-03 20:33:30 +080027 if (!ec)
28 {
29 ec = ipmi::setDbusProperty(
Alexander Hansenb1f1f112025-11-07 16:36:43 +010030 ctx, service, bmcStateObj.first, BMCState::interface,
31 BMCState::property_names::requested_bmc_transition,
32 convertForMessage(BMCState::Transition::Reboot));
George Liu082de3c2025-03-03 20:33:30 +080033 }
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060034 }
George Liu082de3c2025-03-03 20:33:30 +080035 if (ec)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060036 {
George Liu082de3c2025-03-03 20:33:30 +080037 lg2::error("Exception in Global Reset: {ERROR}", "ERROR", ec.message());
anil kumar appanae9e99d92019-04-28 23:47:24 +000038 return ipmi::responseUnspecifiedError();
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060039 }
Nan Libc759882016-08-22 15:00:21 +080040
41 // Status code.
anil kumar appanae9e99d92019-04-28 23:47:24 +000042 return ipmi::responseSuccess();
Nan Libc759882016-08-22 15:00:21 +080043}
Williamcb8ac882015-12-31 19:15:17 +080044
George Liu5087b072025-03-11 19:28:17 +080045void registerNetFnGlobalFunctions()
Williamcb8ac882015-12-31 19:15:17 +080046{
Tom05732372016-09-06 17:21:23 +053047 // Cold Reset
anil kumar appanae9e99d92019-04-28 23:47:24 +000048 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
49 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
50 ipmiGlobalReset);
Ratan Guptaeedf4f52016-02-25 18:53:52 +053051 return;
Williamcb8ac882015-12-31 19:15:17 +080052}