1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "bmcweb_config.h" 6 7 #include "app.hpp" 8 #include "async_resp.hpp" 9 #include "dbus_utility.hpp" 10 #include "error_messages.hpp" 11 #include "http_request.hpp" 12 #include "logging.hpp" 13 #include "query.hpp" 14 #include "registries/privilege_registry.hpp" 15 #include "utils/sw_utils.hpp" 16 17 #include <boost/beast/http/verb.hpp> 18 19 #include <format> 20 #include <functional> 21 #include <memory> 22 #include <string> 23 24 namespace redfish 25 { 26 /** 27 * BiosService class supports handle get method for bios. 28 */ 29 inline void handleBiosServiceGet( 30 crow::App& app, const crow::Request& req, 31 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 32 const std::string& systemName) 33 { 34 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 35 { 36 return; 37 } 38 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 39 { 40 // Option currently returns no systems. TBD 41 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 42 systemName); 43 return; 44 } 45 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 46 { 47 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 48 systemName); 49 return; 50 } 51 asyncResp->res.jsonValue["@odata.id"] = std::format( 52 "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); 53 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; 54 asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; 55 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; 56 asyncResp->res.jsonValue["Id"] = "BIOS"; 57 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] = 58 std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios", 59 BMCWEB_REDFISH_SYSTEM_URI_NAME); 60 61 // Get the ActiveSoftwareImage and SoftwareImages 62 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "", 63 true); 64 } 65 66 inline void requestRoutesBiosService(App& app) 67 { 68 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/") 69 .privileges(redfish::privileges::getBios) 70 .methods(boost::beast::http::verb::get)( 71 std::bind_front(handleBiosServiceGet, std::ref(app))); 72 } 73 74 /** 75 * BiosReset class supports handle POST method for Reset bios. 76 * The class retrieves and sends data directly to D-Bus. 77 * 78 * Function handles POST method request. 79 * Analyzes POST body message before sends Reset request data to D-Bus. 80 */ 81 inline void handleBiosResetPost( 82 crow::App& app, const crow::Request& req, 83 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 84 const std::string& systemName) 85 { 86 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 87 { 88 return; 89 } 90 91 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 92 { 93 // Option currently returns no systems. TBD 94 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 95 systemName); 96 return; 97 } 98 99 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 100 { 101 messages::resourceNotFound(asyncResp->res, "ComputerSystem", 102 systemName); 103 return; 104 } 105 106 dbus::utility::async_method_call( 107 asyncResp, 108 [asyncResp](const boost::system::error_code& ec) { 109 if (ec) 110 { 111 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec); 112 messages::internalError(asyncResp->res); 113 return; 114 } 115 }, 116 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software", 117 "xyz.openbmc_project.Common.FactoryReset", "Reset"); 118 } 119 120 inline void requestRoutesBiosReset(App& app) 121 { 122 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/") 123 .privileges(redfish::privileges::postBios) 124 .methods(boost::beast::http::verb::post)( 125 std::bind_front(handleBiosResetPost, std::ref(app))); 126 } 127 128 } // namespace redfish 129