1*46470a38SPatrick Venture #include "globalhandler.hpp" 20b02be92SPatrick Venture 3*46470a38SPatrick Venture #include "utils.hpp" 4*46470a38SPatrick Venture 5*46470a38SPatrick Venture #include <host-ipmid/ipmid-api.h> 698a23840SMatthew Barth #include <stdio.h> 70b02be92SPatrick Venture 80b02be92SPatrick Venture #include <phosphor-logging/elog-errors.hpp> 90b02be92SPatrick Venture #include <phosphor-logging/log.hpp> 1034e3d3f1SNagaraju Goruganti #include <string> 110b02be92SPatrick Venture #include <xyz/openbmc_project/Common/error.hpp> 120b02be92SPatrick Venture #include <xyz/openbmc_project/State/BMC/server.hpp> 130b02be92SPatrick Venture 1434e3d3f1SNagaraju Goruganti static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state"; 1534e3d3f1SNagaraju Goruganti static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC"; 1634e3d3f1SNagaraju Goruganti static constexpr auto reqTransition = "RequestedBMCTransition"; 1734e3d3f1SNagaraju Goruganti static constexpr auto match = "bmc0"; 1834e3d3f1SNagaraju Goruganti 1934e3d3f1SNagaraju Goruganti using namespace phosphor::logging; 2034e3d3f1SNagaraju Goruganti using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC; 2198a23840SMatthew Barth 2298a23840SMatthew Barth void register_netfn_global_functions() __attribute__((constructor)); 2398a23840SMatthew Barth 2434e3d3f1SNagaraju Goruganti void resetBMC() 2598a23840SMatthew Barth { 2634e3d3f1SNagaraju Goruganti sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; 2798a23840SMatthew Barth 280b02be92SPatrick Venture auto bmcStateObj = 290b02be92SPatrick Venture ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, match); 3034e3d3f1SNagaraju Goruganti 3134e3d3f1SNagaraju Goruganti auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first); 3234e3d3f1SNagaraju Goruganti 3334e3d3f1SNagaraju Goruganti ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf, 340b02be92SPatrick Venture reqTransition, 350b02be92SPatrick Venture convertForMessage(BMC::Transition::Reboot)); 3698a23840SMatthew Barth } 3798a23840SMatthew Barth 3834e3d3f1SNagaraju Goruganti ipmi_ret_t ipmi_global_reset(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 3998a23840SMatthew Barth ipmi_request_t request, ipmi_response_t response, 4098a23840SMatthew Barth ipmi_data_len_t data_len, ipmi_context_t context) 4198a23840SMatthew Barth { 4234e3d3f1SNagaraju Goruganti try 43bc759884SNan Li { 4434e3d3f1SNagaraju Goruganti resetBMC(); 4534e3d3f1SNagaraju Goruganti } 4634e3d3f1SNagaraju Goruganti catch (std::exception& e) 4734e3d3f1SNagaraju Goruganti { 4834e3d3f1SNagaraju Goruganti log<level::ERR>(e.what()); 4934e3d3f1SNagaraju Goruganti return IPMI_CC_UNSPECIFIED_ERROR; 5034e3d3f1SNagaraju Goruganti } 51bc759884SNan Li 52bc759884SNan Li // Status code. 53bc759884SNan Li ipmi_ret_t rc = IPMI_CC_OK; 54bc759884SNan Li *data_len = 0; 55bc759884SNan Li return rc; 56bc759884SNan Li } 5798a23840SMatthew Barth 5898a23840SMatthew Barth void register_netfn_global_functions() 5998a23840SMatthew Barth { 600573237fSTom // Cold Reset 6134e3d3f1SNagaraju Goruganti ipmi_register_callback(NETFUN_APP, IPMI_CMD_COLD_RESET, NULL, 6234e3d3f1SNagaraju Goruganti ipmi_global_reset, PRIVILEGE_ADMIN); 63bc759884SNan Li 640573237fSTom // <Warm Reset> 6534e3d3f1SNagaraju Goruganti ipmi_register_callback(NETFUN_APP, IPMI_CMD_WARM_RESET, NULL, 6634e3d3f1SNagaraju Goruganti ipmi_global_reset, PRIVILEGE_ADMIN); 6798a23840SMatthew Barth 6898a23840SMatthew Barth return; 6998a23840SMatthew Barth } 70