blob: 27409c2801ef1bd7c16885c66b3d0c23d69b0d18 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "globalhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Vernon Mauerye08fbff2019-04-03 09:19:34 -07003#include <ipmid/api.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -07004#include <ipmid/utils.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -07005#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06007#include <string>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <xyz/openbmc_project/Common/error.hpp>
9#include <xyz/openbmc_project/State/BMC/server.hpp>
10
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060011static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
12static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
13static constexpr auto reqTransition = "RequestedBMCTransition";
14static constexpr auto match = "bmc0";
15
16using namespace phosphor::logging;
17using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080018
Williamcb8ac882015-12-31 19:15:17 +080019void register_netfn_global_functions() __attribute__((constructor));
20
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060021void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080022{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060023 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080024
Patrick Venture0b02be92018-08-31 11:55:55 -070025 auto bmcStateObj =
26 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080027
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060028 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080029
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060030 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070031 reqTransition,
32 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080033}
34
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060035ipmi_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)
Williamcb8ac882015-12-31 19:15:17 +080038{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060039 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 Libc759882016-08-22 15:00:21 +080048
49 // Status code.
50 ipmi_ret_t rc = IPMI_CC_OK;
51 *data_len = 0;
52 return rc;
53}
Williamcb8ac882015-12-31 19:15:17 +080054
55void register_netfn_global_functions()
56{
Tom05732372016-09-06 17:21:23 +053057 // Cold Reset
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060058 ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL,
59 ipmi_global_reset, PRIVILEGE_ADMIN);
Nan Libc759882016-08-22 15:00:21 +080060
Tom05732372016-09-06 17:21:23 +053061 // <Warm Reset>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060062 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL,
63 ipmi_global_reset, PRIVILEGE_ADMIN);
Williamcb8ac882015-12-31 19:15:17 +080064
Ratan Guptaeedf4f52016-02-25 18:53:52 +053065 return;
Williamcb8ac882015-12-31 19:15:17 +080066}