blob: 32f2bc61e181972ddb094532f99911b702d46c0a [file] [log] [blame]
Williamcb8ac882015-12-31 19:15:17 +08001#include "globalhandler.h"
Patrick Williams37af7332016-09-02 21:21:42 -05002#include "host-ipmid/ipmid-api.h"
Williamcb8ac882015-12-31 19:15:17 +08003#include <stdio.h>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06004#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"
Williamcb8ac882015-12-31 19:15:17 +080010
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
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060025 auto bmcStateObj = ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot,
26 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,
31 reqTransition, convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080032}
33
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060034
35ipmi_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}