blob: 04d57afc486fc6b61523bb86d5ba2f5409c1b793 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "globalhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Patrick Venture46470a32018-09-07 19:26:25 -07003#include "utils.hpp"
4
William A. Kennington III194375f2018-12-14 02:14:33 -08005#include <ipmid/api.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07006
7#include <phosphor-logging/elog-errors.hpp>
8#include <phosphor-logging/log.hpp>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06009#include <string>
Patrick Venture0b02be92018-08-31 11:55:55 -070010#include <xyz/openbmc_project/Common/error.hpp>
11#include <xyz/openbmc_project/State/BMC/server.hpp>
12
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060013static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
14static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
15static constexpr auto reqTransition = "RequestedBMCTransition";
16static constexpr auto match = "bmc0";
17
18using namespace phosphor::logging;
19using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080020
Williamcb8ac882015-12-31 19:15:17 +080021void register_netfn_global_functions() __attribute__((constructor));
22
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060023void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080024{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060025 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080026
Patrick Venture0b02be92018-08-31 11:55:55 -070027 auto bmcStateObj =
28 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080029
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060030 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080031
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060032 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070033 reqTransition,
34 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080035}
36
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060037ipmi_ret_t ipmi_global_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
38 ipmi_request_t request, ipmi_response_t response,
39 ipmi_data_len_t data_len, ipmi_context_t context)
Williamcb8ac882015-12-31 19:15:17 +080040{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060041 try
42 {
43 resetBMC();
44 }
45 catch (std::exception& e)
46 {
47 log<level::ERR>(e.what());
48 return IPMI_CC_UNSPECIFIED_ERROR;
49 }
Nan Libc759882016-08-22 15:00:21 +080050
51 // Status code.
52 ipmi_ret_t rc = IPMI_CC_OK;
53 *data_len = 0;
54 return rc;
55}
Williamcb8ac882015-12-31 19:15:17 +080056
57void register_netfn_global_functions()
58{
Tom05732372016-09-06 17:21:23 +053059 // Cold Reset
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060060 ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL,
61 ipmi_global_reset, PRIVILEGE_ADMIN);
Nan Libc759882016-08-22 15:00:21 +080062
Tom05732372016-09-06 17:21:23 +053063 // <Warm Reset>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060064 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL,
65 ipmi_global_reset, PRIVILEGE_ADMIN);
Williamcb8ac882015-12-31 19:15:17 +080066
Ratan Guptaeedf4f52016-02-25 18:53:52 +053067 return;
Williamcb8ac882015-12-31 19:15:17 +080068}