xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision 9d424669)
1 #pragma once
2 
3 #include <app.hpp>
4 #include <registries/privilege_registry.hpp>
5 #include <utils/fw_utils.hpp>
6 namespace redfish
7 {
8 /**
9  * BiosService class supports handle get method for bios.
10  */
11 inline void
12     handleBiosServiceGet(const crow::Request&,
13                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14 {
15     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
16     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
17     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
18     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
19     asyncResp->res.jsonValue["Id"] = "BIOS";
20     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
21         {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
22 
23     // Get the ActiveSoftwareImage and SoftwareImages
24     fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "",
25                                          true);
26 }
27 inline void requestRoutesBiosService(App& app)
28 {
29     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
30         .privileges(redfish::privileges::getBios)
31         .methods(boost::beast::http::verb::get)(handleBiosServiceGet);
32 }
33 
34 /**
35  * BiosReset class supports handle POST method for Reset bios.
36  * The class retrieves and sends data directly to D-Bus.
37  *
38  * Function handles POST method request.
39  * Analyzes POST body message before sends Reset request data to D-Bus.
40  */
41 inline void
42     handleBiosResetPost(const crow::Request&,
43                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
44 {
45     crow::connections::systemBus->async_method_call(
46         [asyncResp](const boost::system::error_code ec) {
47             if (ec)
48             {
49                 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
50                 messages::internalError(asyncResp->res);
51                 return;
52             }
53         },
54         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
55         "xyz.openbmc_project.Common.FactoryReset", "Reset");
56 }
57 
58 inline void requestRoutesBiosReset(App& app)
59 {
60     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
61         .privileges({{"redfish::privileges::postBios"}})
62         .methods(boost::beast::http::verb::post)(handleBiosResetPost);
63 }
64 
65 } // namespace redfish
66