1 #include "globalhandler.hpp" 2 3 #include <ipmid/api.hpp> 4 #include <ipmid/utils.hpp> 5 #include <phosphor-logging/elog-errors.hpp> 6 #include <phosphor-logging/log.hpp> 7 #include <xyz/openbmc_project/Common/error.hpp> 8 #include <xyz/openbmc_project/State/BMC/server.hpp> 9 10 #include <string> 11 12 static constexpr auto bmcStateRoot = "/xyz/openbmc_project/state"; 13 static constexpr auto bmcStateIntf = "xyz.openbmc_project.State.BMC"; 14 static constexpr auto reqTransition = "RequestedBMCTransition"; 15 static constexpr auto match = "bmc0"; 16 17 using namespace phosphor::logging; 18 using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC; 19 20 void register_netfn_global_functions() __attribute__((constructor)); 21 22 void resetBMC() 23 { 24 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; 25 26 auto bmcStateObj = ipmi::getDbusObject(bus, bmcStateIntf, bmcStateRoot, 27 match); 28 29 auto service = ipmi::getService(bus, bmcStateIntf, bmcStateObj.first); 30 31 ipmi::setDbusProperty(bus, service, bmcStateObj.first, bmcStateIntf, 32 reqTransition, 33 convertForMessage(BMC::Transition::Reboot)); 34 } 35 36 /** @brief implements cold and warm reset commands 37 * @param - None 38 * @returns IPMI completion code. 39 */ 40 ipmi::RspType<> ipmiGlobalReset() 41 { 42 try 43 { 44 resetBMC(); 45 } 46 catch (const std::exception& e) 47 { 48 log<level::ERR>(e.what()); 49 return ipmi::responseUnspecifiedError(); 50 } 51 52 // Status code. 53 return ipmi::responseSuccess(); 54 } 55 56 void register_netfn_global_functions() 57 { 58 // Cold Reset 59 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, 60 ipmi::app::cmdColdReset, ipmi::Privilege::Admin, 61 ipmiGlobalReset); 62 return; 63 } 64