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