blob: c164a204d28f209acd2f1623e9e242706a5cb24a [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "globalhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Vernon Mauerye08fbff2019-04-03 09:19:34 -07003#include <ipmid/api.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07004#include <ipmid/utils.hpp>
George Liuffd5f042024-07-19 09:32:15 +08005#include <phosphor-logging/lg2.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include <xyz/openbmc_project/State/BMC/server.hpp>
7
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05008#include <string>
9
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060010static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
11static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
12static constexpr auto reqTransition = "RequestedBMCTransition";
13static constexpr auto match = "bmc0";
14
Willy Tu523e2d12023-09-05 11:36:48 -070015using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC;
Williamcb8ac882015-12-31 19:15:17 +080016
Williamcb8ac882015-12-31 19:15:17 +080017void register_netfn_global_functions() __attribute__((constructor));
18
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060019void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080020{
Patrick Williams5d82f472022-07-22 19:26:53 -050021 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080022
Patrick Williams1318a5e2024-08-16 15:19:54 -040023 auto bmcStateObj =
24 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080025
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060026 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080027
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060028 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070029 reqTransition,
30 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080031}
32
anil kumar appanae9e99d92019-04-28 23:47:24 +000033/** @brief implements cold and warm reset commands
34 * @param - None
35 * @returns IPMI completion code.
36 */
37ipmi::RspType<> ipmiGlobalReset()
Williamcb8ac882015-12-31 19:15:17 +080038{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060039 try
40 {
41 resetBMC();
42 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -050043 catch (const std::exception& e)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060044 {
George Liuffd5f042024-07-19 09:32:15 +080045 lg2::error("Exception in Global Reset: {ERROR}", "ERROR", e);
anil kumar appanae9e99d92019-04-28 23:47:24 +000046 return ipmi::responseUnspecifiedError();
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060047 }
Nan Libc759882016-08-22 15:00:21 +080048
49 // Status code.
anil kumar appanae9e99d92019-04-28 23:47:24 +000050 return ipmi::responseSuccess();
Nan Libc759882016-08-22 15:00:21 +080051}
Williamcb8ac882015-12-31 19:15:17 +080052
53void register_netfn_global_functions()
54{
Tom05732372016-09-06 17:21:23 +053055 // Cold Reset
anil kumar appanae9e99d92019-04-28 23:47:24 +000056 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
57 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
58 ipmiGlobalReset);
Ratan Guptaeedf4f52016-02-25 18:53:52 +053059 return;
Williamcb8ac882015-12-31 19:15:17 +080060}