blob: 816198800b316c4620b1a328c92d4eacb4da4151 [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>
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07007#include <xyz/openbmc_project/Common/error.hpp>
8#include <xyz/openbmc_project/State/BMC/server.hpp>
9
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050010#include <string>
11
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060012static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
13static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
14static constexpr auto reqTransition = "RequestedBMCTransition";
15static constexpr auto match = "bmc0";
16
17using namespace phosphor::logging;
18using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080019
Williamcb8ac882015-12-31 19:15:17 +080020void register_netfn_global_functions() __attribute__((constructor));
21
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060022void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080023{
Patrick Williams5d82f472022-07-22 19:26:53 -050024 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080025
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050026 auto bmcStateObj = ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot,
27 match);
Williamcb8ac882015-12-31 19:15:17 +080028
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060029 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080030
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060031 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070032 reqTransition,
33 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080034}
35
anil kumar appanae9e99d92019-04-28 23:47:24 +000036/** @brief implements cold and warm reset commands
37 * @param - None
38 * @returns IPMI completion code.
39 */
40ipmi::RspType<> ipmiGlobalReset()
Williamcb8ac882015-12-31 19:15:17 +080041{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060042 try
43 {
44 resetBMC();
45 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -050046 catch (const std::exception& e)
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060047 {
48 log<level::ERR>(e.what());
anil kumar appanae9e99d92019-04-28 23:47:24 +000049 return ipmi::responseUnspecifiedError();
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060050 }
Nan Libc759882016-08-22 15:00:21 +080051
52 // Status code.
anil kumar appanae9e99d92019-04-28 23:47:24 +000053 return ipmi::responseSuccess();
Nan Libc759882016-08-22 15:00:21 +080054}
Williamcb8ac882015-12-31 19:15:17 +080055
56void register_netfn_global_functions()
57{
Tom05732372016-09-06 17:21:23 +053058 // Cold Reset
anil kumar appanae9e99d92019-04-28 23:47:24 +000059 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
60 ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
61 ipmiGlobalReset);
Ratan Guptaeedf4f52016-02-25 18:53:52 +053062 return;
Williamcb8ac882015-12-31 19:15:17 +080063}