blob: e268fd17e799401fb9c99f22455c21512b5d8471 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "globalhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
William A. Kennington III194375f2018-12-14 02:14:33 -08003#include <ipmid/api.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Vernon Mauery6a98fe72019-03-11 15:57:48 -07005#include <ipmid/utils.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include <phosphor-logging/elog-errors.hpp>
7#include <phosphor-logging/log.hpp>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06008#include <string>
Patrick Venture0b02be92018-08-31 11:55:55 -07009#include <xyz/openbmc_project/Common/error.hpp>
10#include <xyz/openbmc_project/State/BMC/server.hpp>
11
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060012static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
13static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
14static constexpr auto reqTransition = "RequestedBMCTransition";
15static constexpr auto match = "bmc0";
16
17using namespace phosphor::logging;
18using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080019
Williamcb8ac882015-12-31 19:15:17 +080020void register_netfn_global_functions() __attribute__((constructor));
21
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060022void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080023{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060024 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080025
Patrick Venture0b02be92018-08-31 11:55:55 -070026 auto bmcStateObj =
27 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080028
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060029 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080030
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060031 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070032 reqTransition,
33 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080034}
35
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060036ipmi_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)
Williamcb8ac882015-12-31 19:15:17 +080039{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060040 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 Libc759882016-08-22 15:00:21 +080049
50 // Status code.
51 ipmi_ret_t rc = IPMI_CC_OK;
52 *data_len = 0;
53 return rc;
54}
Williamcb8ac882015-12-31 19:15:17 +080055
56void register_netfn_global_functions()
57{
Tom05732372016-09-06 17:21:23 +053058 // Cold Reset
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060059 ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL,
60 ipmi_global_reset, PRIVILEGE_ADMIN);
Nan Libc759882016-08-22 15:00:21 +080061
Tom05732372016-09-06 17:21:23 +053062 // <Warm Reset>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060063 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL,
64 ipmi_global_reset, PRIVILEGE_ADMIN);
Williamcb8ac882015-12-31 19:15:17 +080065
Ratan Guptaeedf4f52016-02-25 18:53:52 +053066 return;
Williamcb8ac882015-12-31 19:15:17 +080067}