146470a38SPatrick Venture #include "globalhandler.hpp" 20b02be92SPatrick Venture 3e08fbffcSVernon Mauery #include <ipmid/api.hpp> 46a98fe7fSVernon Mauery #include <ipmid/utils.hpp> 5*ffd5f042SGeorge Liu #include <phosphor-logging/lg2.hpp> 60b02be92SPatrick Venture #include <xyz/openbmc_project/State/BMC/server.hpp> 70b02be92SPatrick Venture 8fbc6c9d7SPatrick Williams #include <string> 9fbc6c9d7SPatrick Williams 1034e3d3f1SNagaraju Goruganti static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state"; 1134e3d3f1SNagaraju Goruganti static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC"; 1234e3d3f1SNagaraju Goruganti static constexpr auto reqTransition = "RequestedBMCTransition"; 1334e3d3f1SNagaraju Goruganti static constexpr auto match = "bmc0"; 1434e3d3f1SNagaraju Goruganti 15523e2d1bSWilly Tu using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC; 1698a23840SMatthew Barth 1798a23840SMatthew Barth void register_netfn_global_functions() __attribute__((constructor)); 1898a23840SMatthew Barth 1934e3d3f1SNagaraju Goruganti void resetBMC() 2098a23840SMatthew Barth { 215d82f474SPatrick Williams sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; 2298a23840SMatthew Barth 23fbc6c9d7SPatrick Williams auto bmcStateObj = ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, 24fbc6c9d7SPatrick Williams match); 2534e3d3f1SNagaraju Goruganti 2634e3d3f1SNagaraju Goruganti auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first); 2734e3d3f1SNagaraju Goruganti 2834e3d3f1SNagaraju Goruganti ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf, 290b02be92SPatrick Venture reqTransition, 300b02be92SPatrick Venture convertForMessage(BMC::Transition::Reboot)); 3198a23840SMatthew Barth } 3298a23840SMatthew Barth 33e9e99d93Sanil kumar appana /** @brief implements cold and warm reset commands 34e9e99d93Sanil kumar appana * @param - None 35e9e99d93Sanil kumar appana * @returns IPMI completion code. 36e9e99d93Sanil kumar appana */ 37e9e99d93Sanil kumar appana ipmi::RspType<> ipmiGlobalReset() 3898a23840SMatthew Barth { 3934e3d3f1SNagaraju Goruganti try 40bc759884SNan Li { 4134e3d3f1SNagaraju Goruganti resetBMC(); 4234e3d3f1SNagaraju Goruganti } 43a2ad2da8SPatrick Williams catch (const std::exception& e) 4434e3d3f1SNagaraju Goruganti { 45*ffd5f042SGeorge Liu lg2::error("Exception in Global Reset: {ERROR}", "ERROR", e); 46e9e99d93Sanil kumar appana return ipmi::responseUnspecifiedError(); 4734e3d3f1SNagaraju Goruganti } 48bc759884SNan Li 49bc759884SNan Li // Status code. 50e9e99d93Sanil kumar appana return ipmi::responseSuccess(); 51bc759884SNan Li } 5298a23840SMatthew Barth 5398a23840SMatthew Barth void register_netfn_global_functions() 5498a23840SMatthew Barth { 550573237fSTom // Cold Reset 56e9e99d93Sanil kumar appana ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, 57e9e99d93Sanil kumar appana ipmi::app::cmdColdReset, ipmi::Privilege::Admin, 58e9e99d93Sanil kumar appana ipmiGlobalReset); 5998a23840SMatthew Barth return; 6098a23840SMatthew Barth } 61