1d82a3acdSCarol Wang #pragma once 2d82a3acdSCarol Wang 33ccb3adbSEd Tanous #include "app.hpp" 43ccb3adbSEd Tanous #include "query.hpp" 53ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 63ccb3adbSEd Tanous #include "utils/sw_utils.hpp" 745ca1b86SEd Tanous 8*253f11b8SEd Tanous #include <boost/url/format.hpp> 9*253f11b8SEd Tanous 10d82a3acdSCarol Wang namespace redfish 11d82a3acdSCarol Wang { 12d82a3acdSCarol Wang /** 13d82a3acdSCarol Wang * BiosService class supports handle get method for bios. 14d82a3acdSCarol Wang */ 1558eaf5f0SJohn Edward Broadbent inline void 1645ca1b86SEd Tanous handleBiosServiceGet(crow::App& app, const crow::Request& req, 1722d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1822d268cbSEd Tanous const std::string& systemName) 1958eaf5f0SJohn Edward Broadbent { 203ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2145ca1b86SEd Tanous { 2245ca1b86SEd Tanous return; 2345ca1b86SEd Tanous } 2425b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 257f3e84a1SEd Tanous { 267f3e84a1SEd Tanous // Option currently returns no systems. TBD 277f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 287f3e84a1SEd Tanous systemName); 297f3e84a1SEd Tanous return; 307f3e84a1SEd Tanous } 31*253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 3222d268cbSEd Tanous { 3322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 3422d268cbSEd Tanous systemName); 3522d268cbSEd Tanous return; 3622d268cbSEd Tanous } 37*253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = std::format( 38*253f11b8SEd Tanous "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); 3958eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; 4058eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; 4158eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; 4258eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "BIOS"; 4358eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = { 44*253f11b8SEd Tanous {"target", 45*253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios", 46*253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME)}}; 4758eaf5f0SJohn Edward Broadbent 4858eaf5f0SJohn Edward Broadbent // Get the ActiveSoftwareImage and SoftwareImages 49eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "", 5058eaf5f0SJohn Edward Broadbent true); 5158eaf5f0SJohn Edward Broadbent } 5245ca1b86SEd Tanous 537e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app) 54d82a3acdSCarol Wang { 5522d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/") 56ed398213SEd Tanous .privileges(redfish::privileges::getBios) 5745ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 5845ca1b86SEd Tanous std::bind_front(handleBiosServiceGet, std::ref(app))); 59d82a3acdSCarol Wang } 6058eaf5f0SJohn Edward Broadbent 61d82a3acdSCarol Wang /** 62d82a3acdSCarol Wang * BiosReset class supports handle POST method for Reset bios. 63d82a3acdSCarol Wang * The class retrieves and sends data directly to D-Bus. 647e860f15SJohn Edward Broadbent * 65d82a3acdSCarol Wang * Function handles POST method request. 66d82a3acdSCarol Wang * Analyzes POST body message before sends Reset request data to D-Bus. 67d82a3acdSCarol Wang */ 6858eaf5f0SJohn Edward Broadbent inline void 6945ca1b86SEd Tanous handleBiosResetPost(crow::App& app, const crow::Request& req, 7022d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7122d268cbSEd Tanous const std::string& systemName) 727e860f15SJohn Edward Broadbent { 733ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 7445ca1b86SEd Tanous { 7545ca1b86SEd Tanous return; 7645ca1b86SEd Tanous } 7722d268cbSEd Tanous 7825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 797f3e84a1SEd Tanous { 807f3e84a1SEd Tanous // Option currently returns no systems. TBD 817f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 827f3e84a1SEd Tanous systemName); 837f3e84a1SEd Tanous return; 847f3e84a1SEd Tanous } 857f3e84a1SEd Tanous 86*253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 8722d268cbSEd Tanous { 8822d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 8922d268cbSEd Tanous systemName); 9022d268cbSEd Tanous return; 9122d268cbSEd Tanous } 9222d268cbSEd Tanous 93d82a3acdSCarol Wang crow::connections::systemBus->async_method_call( 945e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 95d82a3acdSCarol Wang if (ec) 96d82a3acdSCarol Wang { 9762598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec); 98d82a3acdSCarol Wang messages::internalError(asyncResp->res); 99d82a3acdSCarol Wang return; 100d82a3acdSCarol Wang } 101d82a3acdSCarol Wang }, 10258eaf5f0SJohn Edward Broadbent "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software", 103d82a3acdSCarol Wang "xyz.openbmc_project.Common.FactoryReset", "Reset"); 104d82a3acdSCarol Wang } 10558eaf5f0SJohn Edward Broadbent 10658eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app) 10758eaf5f0SJohn Edward Broadbent { 10822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/") 109b7ff3445SJohn Edward Broadbent .privileges(redfish::privileges::postBios) 11045ca1b86SEd Tanous .methods(boost::beast::http::verb::post)( 11145ca1b86SEd Tanous std::bind_front(handleBiosResetPost, std::ref(app))); 11258eaf5f0SJohn Edward Broadbent } 11358eaf5f0SJohn Edward Broadbent 114d82a3acdSCarol Wang } // namespace redfish 115