summaryrefslogtreecommitdiffstats
path: root/globalhandler.cpp
blob: c192cbb677e2976ea98373bac11bcf1c44123af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "globalhandler.hpp"

#include <ipmid/api.hpp>
#include <ipmid/utils.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <string>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/State/BMC/server.hpp>

static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state";
static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC";
static constexpr auto reqTransition = "RequestedBMCTransition";
static constexpr auto match = "bmc0";

using namespace phosphor::logging;
using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;

void register_netfn_global_functions() __attribute__((constructor));

void resetBMC()
{
    sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};

    auto bmcStateObj =
        ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match);

    auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first);

    ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf,
                          reqTransition,
                          convertForMessage(BMC::Transition::Reboot));
}

/** @brief implements cold and warm reset commands
 *  @param - None
 *  @returns IPMI completion code.
 */
ipmi::RspType<> ipmiGlobalReset()
{
    try
    {
        resetBMC();
    }
    catch (std::exception& e)
    {
        log<level::ERR>(e.what());
        return ipmi::responseUnspecifiedError();
    }

    // Status code.
    return ipmi::responseSuccess();
}

void register_netfn_global_functions()
{

    // Cold Reset
    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
                          ipmi::app::cmdColdReset, ipmi::Privilege::Admin,
                          ipmiGlobalReset);
    return;
}
OpenPOWER on IntegriCloud