blob: 55761b4344c9bb53d163c4c8cc1d9051806e95df [file] [log] [blame]
Williamcb8ac882015-12-31 19:15:17 +08001#include "globalhandler.h"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Williamcb8ac882015-12-31 19:15:17 +08003#include <stdio.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07004
5#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -06007#include <string>
8#include <utils.hpp>
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
12#include "host-ipmid/ipmid-api.h"
Williamcb8ac882015-12-31 19:15:17 +080013
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060014static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
15static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
16static constexpr auto reqTransition = "RequestedBMCTransition";
17static constexpr auto match = "bmc0";
18
19using namespace phosphor::logging;
20using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Williamcb8ac882015-12-31 19:15:17 +080021
Williamcb8ac882015-12-31 19:15:17 +080022void register_netfn_global_functions() __attribute__((constructor));
23
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060024void resetBMC()
Williamcb8ac882015-12-31 19:15:17 +080025{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060026 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Williamcb8ac882015-12-31 19:15:17 +080027
Patrick Venture0b02be92018-08-31 11:55:55 -070028 auto bmcStateObj =
29 ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);
Williamcb8ac882015-12-31 19:15:17 +080030
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060031 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);
Williamcb8ac882015-12-31 19:15:17 +080032
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060033 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
Patrick Venture0b02be92018-08-31 11:55:55 -070034 reqTransition,
35 convertForMessage(BMC::Transition::Reboot));
Williamcb8ac882015-12-31 19:15:17 +080036}
37
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060038ipmi_ret_t ipmi_global_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
39 ipmi_request_t request, ipmi_response_t response,
40 ipmi_data_len_t data_len, ipmi_context_t context)
Williamcb8ac882015-12-31 19:15:17 +080041{
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060042 try
43 {
44 resetBMC();
45 }
46 catch (std::exception& e)
47 {
48 log<level::ERR>(e.what());
49 return IPMI_CC_UNSPECIFIED_ERROR;
50 }
Nan Libc759882016-08-22 15:00:21 +080051
52 // Status code.
53 ipmi_ret_t rc = IPMI_CC_OK;
54 *data_len = 0;
55 return rc;
56}
Williamcb8ac882015-12-31 19:15:17 +080057
58void register_netfn_global_functions()
59{
Tom05732372016-09-06 17:21:23 +053060 // Cold Reset
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060061 ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL,
62 ipmi_global_reset, PRIVILEGE_ADMIN);
Nan Libc759882016-08-22 15:00:21 +080063
Tom05732372016-09-06 17:21:23 +053064 // <Warm Reset>
Nagaraju Goruganti34e3d3f2018-03-01 22:44:38 -060065 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL,
66 ipmi_global_reset, PRIVILEGE_ADMIN);
Williamcb8ac882015-12-31 19:15:17 +080067
Ratan Guptaeedf4f52016-02-25 18:53:52 +053068 return;
Williamcb8ac882015-12-31 19:15:17 +080069}