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