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 | |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 3 | #include "utils.hpp" |
| 4 | |
| 5 | #include <host-ipmid/ipmid-api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | |
| 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/log.hpp> |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 9 | #include <string> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Common/error.hpp> |
| 11 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
| 12 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 13 | static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state"; |
| 14 | static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC"; |
| 15 | static constexpr auto reqTransition = "RequestedBMCTransition"; |
| 16 | static constexpr auto match = "bmc0"; |
| 17 | |
| 18 | using namespace phosphor::logging; |
| 19 | using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 20 | |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 21 | void register_netfn_global_functions() __attribute__((constructor)); |
| 22 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 23 | void resetBMC() |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 24 | { |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 25 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 26 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 27 | auto bmcStateObj = |
| 28 | ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 29 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 30 | auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 31 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 32 | ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 33 | reqTransition, |
| 34 | convertForMessage(BMC::Transition::Reboot)); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 35 | } |
| 36 | |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 37 | ipmi_ret_t ipmi_global_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 38 | ipmi_request_t request, ipmi_response_t response, |
| 39 | ipmi_data_len_t data_len, ipmi_context_t context) |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 40 | { |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 41 | try |
| 42 | { |
| 43 | resetBMC(); |
| 44 | } |
| 45 | catch (std::exception& e) |
| 46 | { |
| 47 | log<level::ERR>(e.what()); |
| 48 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 49 | } |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 50 | |
| 51 | // Status code. |
| 52 | ipmi_ret_t rc = IPMI_CC_OK; |
| 53 | *data_len = 0; |
| 54 | return rc; |
| 55 | } |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 56 | |
| 57 | void register_netfn_global_functions() |
| 58 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 59 | // Cold Reset |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 60 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL, |
| 61 | ipmi_global_reset, PRIVILEGE_ADMIN); |
Nan Li | bc75988 | 2016-08-22 15:00:21 +0800 | [diff] [blame] | 62 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 63 | // <Warm Reset> |
Nagaraju Goruganti | 34e3d3f | 2018-03-01 22:44:38 -0600 | [diff] [blame] | 64 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL, |
| 65 | ipmi_global_reset, PRIVILEGE_ADMIN); |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 66 | |
Ratan Gupta | eedf4f5 | 2016-02-25 18:53:52 +0530 | [diff] [blame] | 67 | return; |
William | cb8ac88 | 2015-12-31 19:15:17 +0800 | [diff] [blame] | 68 | } |