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