140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3d82a3acdSCarol Wang #pragma once 4d82a3acdSCarol Wang 5d7857201SEd Tanous #include "bmcweb_config.h" 6d7857201SEd Tanous 73ccb3adbSEd Tanous #include "app.hpp" 8d7857201SEd Tanous #include "async_resp.hpp" 9*177612aaSEd Tanous #include "dbus_utility.hpp" 10d7857201SEd Tanous #include "error_messages.hpp" 11d7857201SEd Tanous #include "http_request.hpp" 12d7857201SEd Tanous #include "logging.hpp" 133ccb3adbSEd Tanous #include "query.hpp" 143ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 153ccb3adbSEd Tanous #include "utils/sw_utils.hpp" 1645ca1b86SEd Tanous 17d7857201SEd Tanous #include <boost/beast/http/verb.hpp> 18d7857201SEd Tanous 19d7857201SEd Tanous #include <format> 20d7857201SEd Tanous #include <functional> 21d7857201SEd Tanous #include <memory> 22d7857201SEd Tanous #include <string> 23253f11b8SEd Tanous 24d82a3acdSCarol Wang namespace redfish 25d82a3acdSCarol Wang { 26d82a3acdSCarol Wang /** 27d82a3acdSCarol Wang * BiosService class supports handle get method for bios. 28d82a3acdSCarol Wang */ 29504af5a0SPatrick Williams inline void handleBiosServiceGet( 30504af5a0SPatrick Williams crow::App& app, const crow::Request& req, 3122d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3222d268cbSEd Tanous const std::string& systemName) 3358eaf5f0SJohn Edward Broadbent { 343ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3545ca1b86SEd Tanous { 3645ca1b86SEd Tanous return; 3745ca1b86SEd Tanous } 3825b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 397f3e84a1SEd Tanous { 407f3e84a1SEd Tanous // Option currently returns no systems. TBD 417f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 427f3e84a1SEd Tanous systemName); 437f3e84a1SEd Tanous return; 447f3e84a1SEd Tanous } 45253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 4622d268cbSEd Tanous { 4722d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 4822d268cbSEd Tanous systemName); 4922d268cbSEd Tanous return; 5022d268cbSEd Tanous } 51253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = std::format( 52253f11b8SEd Tanous "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); 5358eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; 5458eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; 5558eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; 5658eaf5f0SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "BIOS"; 5720fa6a2cSEd Tanous asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] = 58253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios", 5920fa6a2cSEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 6058eaf5f0SJohn Edward Broadbent 6158eaf5f0SJohn Edward Broadbent // Get the ActiveSoftwareImage and SoftwareImages 62eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "", 6358eaf5f0SJohn Edward Broadbent true); 6458eaf5f0SJohn Edward Broadbent } 6545ca1b86SEd Tanous 667e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app) 67d82a3acdSCarol Wang { 6822d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/") 69ed398213SEd Tanous .privileges(redfish::privileges::getBios) 7045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 7145ca1b86SEd Tanous std::bind_front(handleBiosServiceGet, std::ref(app))); 72d82a3acdSCarol Wang } 7358eaf5f0SJohn Edward Broadbent 74d82a3acdSCarol Wang /** 75d82a3acdSCarol Wang * BiosReset class supports handle POST method for Reset bios. 76d82a3acdSCarol Wang * The class retrieves and sends data directly to D-Bus. 777e860f15SJohn Edward Broadbent * 78d82a3acdSCarol Wang * Function handles POST method request. 79d82a3acdSCarol Wang * Analyzes POST body message before sends Reset request data to D-Bus. 80d82a3acdSCarol Wang */ 81504af5a0SPatrick Williams inline void handleBiosResetPost( 82504af5a0SPatrick Williams crow::App& app, const crow::Request& req, 8322d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 8422d268cbSEd Tanous const std::string& systemName) 857e860f15SJohn Edward Broadbent { 863ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 8745ca1b86SEd Tanous { 8845ca1b86SEd Tanous return; 8945ca1b86SEd Tanous } 9022d268cbSEd Tanous 9125b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 927f3e84a1SEd Tanous { 937f3e84a1SEd Tanous // Option currently returns no systems. TBD 947f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 957f3e84a1SEd Tanous systemName); 967f3e84a1SEd Tanous return; 977f3e84a1SEd Tanous } 987f3e84a1SEd Tanous 99253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 10022d268cbSEd Tanous { 10122d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 10222d268cbSEd Tanous systemName); 10322d268cbSEd Tanous return; 10422d268cbSEd Tanous } 10522d268cbSEd Tanous 106*177612aaSEd Tanous dbus::utility::async_method_call( 107*177612aaSEd Tanous asyncResp, 1085e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 109d82a3acdSCarol Wang if (ec) 110d82a3acdSCarol Wang { 11162598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec); 112d82a3acdSCarol Wang messages::internalError(asyncResp->res); 113d82a3acdSCarol Wang return; 114d82a3acdSCarol Wang } 115d82a3acdSCarol Wang }, 11658eaf5f0SJohn Edward Broadbent "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software", 117d82a3acdSCarol Wang "xyz.openbmc_project.Common.FactoryReset", "Reset"); 118d82a3acdSCarol Wang } 11958eaf5f0SJohn Edward Broadbent 12058eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app) 12158eaf5f0SJohn Edward Broadbent { 12222d268cbSEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/") 123b7ff3445SJohn Edward Broadbent .privileges(redfish::privileges::postBios) 12445ca1b86SEd Tanous .methods(boost::beast::http::verb::post)( 12545ca1b86SEd Tanous std::bind_front(handleBiosResetPost, std::ref(app))); 12658eaf5f0SJohn Edward Broadbent } 12758eaf5f0SJohn Edward Broadbent 128d82a3acdSCarol Wang } // namespace redfish 129