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 | |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 3 | #include <ipmid/api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 5 | #include <ipmid/utils.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | #include <phosphor-logging/elog-errors.hpp> |
| 7 | #include <phosphor-logging/log.hpp> |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 8 | #include <string> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/error.hpp> |
| 10 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
| 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; |
| 18 | using BMC = sdbusplus::xyz::openbmc_project::State::server::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 | { |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 24 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 25 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 26 | auto bmcStateObj = |
| 27 | ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, 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 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 36 | ipmi_ret_t ipmi_global_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 37 | ipmi_request_t request, ipmi_response_t response, |
| 38 | ipmi_data_len_t data_len, ipmi_context_t context) |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 39 | { |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 40 | try |
| 41 | { |
| 42 | resetBMC(); |
| 43 | } |
| 44 | catch (std::exception& e) |
| 45 | { |
| 46 | log<level::ERR>(e.what()); |
| 47 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 48 | } |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 49 | |
| 50 | // Status code. |
| 51 | ipmi_ret_t rc = IPMI_CC_OK; |
| 52 | *data_len = 0; |
| 53 | return rc; |
| 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 |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 59 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL, |
| 60 | ipmi_global_reset, PRIVILEGE_ADMIN); |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 61 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 62 | // <Warm Reset> |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 63 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL, |
| 64 | ipmi_global_reset, PRIVILEGE_ADMIN); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 65 | |
Ratan Gupta | eedf4f5 | 2016-02-25 18:53:52 +0530 | [diff] [blame] | 66 | return; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 67 | } |