xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision 735ef6d8)
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 requestRoutesBiosService(App& app)
12 {
13     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
14         .privileges(redfish::privileges::getBios)
15         .methods(boost::beast::http::verb::get)(
16             [](const crow::Request&,
17                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
18                 asyncResp->res.jsonValue["@odata.id"] =
19                     "/redfish/v1/Systems/system/Bios";
20                 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
21                 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
22                 asyncResp->res.jsonValue["Description"] =
23                     "BIOS Configuration Service";
24                 asyncResp->res.jsonValue["Id"] = "BIOS";
25                 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
26                     {"target",
27                      "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
28 
29                 // Get the ActiveSoftwareImage and SoftwareImages
30                 fw_util::populateFirmwareInformation(
31                     asyncResp, fw_util::biosPurpose, "", true);
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 
42 inline void requestRoutesBiosReset(App& app)
43 {
44     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
45         // Incorrect Privilege;  Should be ConfigureComponents
46         //.privileges(redfish::privileges::postBios)
47         .privileges({{"ConfigureManager"}})
48         .methods(boost::beast::http::verb::post)(
49             [](const crow::Request&,
50                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
51                 crow::connections::systemBus->async_method_call(
52                     [asyncResp](const boost::system::error_code ec) {
53                         if (ec)
54                         {
55                             BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
56                             messages::internalError(asyncResp->res);
57                             return;
58                         }
59                     },
60                     "org.open_power.Software.Host.Updater",
61                     "/xyz/openbmc_project/software",
62                     "xyz.openbmc_project.Common.FactoryReset", "Reset");
63             });
64 }
65 } // namespace redfish
66