1 #pragma once 2 3 #include "app.hpp" 4 #include "query.hpp" 5 #include "registries/privilege_registry.hpp" 6 #include "utils/sw_utils.hpp" 7 8 namespace redfish 9 { 10 /** 11 * BiosService class supports handle get method for bios. 12 */ 13 inline void 14 handleBiosServiceGet(crow::App& app, const crow::Request& req, 15 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16 const std::string& systemName) 17 { 18 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 19 { 20 return; 21 } 22 if (systemName != "system") 23 { 24 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 25 systemName); 26 return; 27 } 28 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios"; 29 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; 30 asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; 31 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; 32 asyncResp->res.jsonValue["Id"] = "BIOS"; 33 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = { 34 {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}}; 35 36 // Get the ActiveSoftwareImage and SoftwareImages 37 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "", 38 true); 39 } 40 41 inline void requestRoutesBiosService(App& app) 42 { 43 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/") 44 .privileges(redfish::privileges::getBios) 45 .methods(boost::beast::http::verb::get)( 46 std::bind_front(handleBiosServiceGet, std::ref(app))); 47 } 48 49 /** 50 * BiosReset class supports handle POST method for Reset bios. 51 * The class retrieves and sends data directly to D-Bus. 52 * 53 * Function handles POST method request. 54 * Analyzes POST body message before sends Reset request data to D-Bus. 55 */ 56 inline void 57 handleBiosResetPost(crow::App& app, const crow::Request& req, 58 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 59 const std::string& systemName) 60 { 61 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 62 { 63 return; 64 } 65 66 if (systemName != "system") 67 { 68 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 69 systemName); 70 return; 71 } 72 73 crow::connections::systemBus->async_method_call( 74 [asyncResp](const boost::system::error_code& ec) { 75 if (ec) 76 { 77 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec; 78 messages::internalError(asyncResp->res); 79 return; 80 } 81 }, 82 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software", 83 "xyz.openbmc_project.Common.FactoryReset", "Reset"); 84 } 85 86 inline void requestRoutesBiosReset(App& app) 87 { 88 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/") 89 .privileges(redfish::privileges::postBios) 90 .methods(boost::beast::http::verb::post)( 91 std::bind_front(handleBiosResetPost, std::ref(app))); 92 } 93 94 } // namespace redfish 95