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