Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 1 | #include "globalhandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2 | |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 3 | #include <ipmid/api.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 4 | #include <ipmid/utils.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include <phosphor-logging/elog-errors.hpp> |
| 6 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Common/error.hpp> |
| 8 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
| 9 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 12 | static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state"; |
| 13 | static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC"; |
| 14 | static constexpr auto reqTransition = "RequestedBMCTransition"; |
| 15 | static constexpr auto match = "bmc0"; |
| 16 | |
| 17 | using namespace phosphor::logging; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 18 | using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 19 | |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 20 | void register_netfn_global_functions() __attribute__((constructor)); |
| 21 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 22 | void resetBMC() |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 23 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 24 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 25 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 26 | auto bmcStateObj = ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, |
| 27 | match); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 28 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 29 | auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 30 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 31 | ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 32 | reqTransition, |
| 33 | convertForMessage(BMC::Transition::Reboot)); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 34 | } |
| 35 | |
anil kumar appana | e9e99d9 | 2019-04-28 23:47:24 +0000 | [diff] [blame] | 36 | /** @brief implements cold and warm reset commands |
| 37 | * @param - None |
| 38 | * @returns IPMI completion code. |
| 39 | */ |
| 40 | ipmi::RspType<> ipmiGlobalReset() |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 41 | { |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 42 | try |
| 43 | { |
| 44 | resetBMC(); |
| 45 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 46 | catch (const std::exception& e) |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 47 | { |
| 48 | log<level::ERR>(e.what()); |
anil kumar appana | e9e99d9 | 2019-04-28 23:47:24 +0000 | [diff] [blame] | 49 | return ipmi::responseUnspecifiedError(); |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 50 | } |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 51 | |
| 52 | // Status code. |
anil kumar appana | e9e99d9 | 2019-04-28 23:47:24 +0000 | [diff] [blame] | 53 | return ipmi::responseSuccess(); |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 54 | } |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 55 | |
| 56 | void register_netfn_global_functions() |
| 57 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 58 | // Cold Reset |
anil kumar appana | e9e99d9 | 2019-04-28 23:47:24 +0000 | [diff] [blame] | 59 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 60 | ipmi::app::cmdColdReset, ipmi::Privilege::Admin, |
| 61 | ipmiGlobalReset); |
Ratan Gupta | eedf4f5 | 2016-02-25 18:53:52 +0530 | [diff] [blame] | 62 | return; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 63 | } |