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