blob: 0a0effa565cfaf4afd510b8ce23c2f3e0ae284ea [file] [log] [blame]
Carol Wangd82a3ac2019-11-21 13:56:38 +08001#pragma once
2
3#include "node.hpp"
4
Gunnar Mills72d566d2020-07-21 12:44:00 -05005#include <utils/fw_utils.hpp>
Carol Wangd82a3ac2019-11-21 13:56:38 +08006namespace redfish
7{
8/**
9 * BiosService class supports handle get method for bios.
10 */
11class BiosService : public Node
12{
13 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -050014 BiosService(CrowApp& app) : Node(app, "/redfish/v1/Systems/system/Bios/")
Carol Wangd82a3ac2019-11-21 13:56:38 +080015 {
16 entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}};
17 }
18
19 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -050020 void doGet(crow::Response& res, const crow::Request& req,
21 const std::vector<std::string>& params) override
Carol Wangd82a3ac2019-11-21 13:56:38 +080022 {
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"}};
Gunnar Mills72d566d2020-07-21 12:44:00 -050034
35 // Get the ActiveSoftwareImage
36 fw_util::getActiveFwVersion(asyncResp, fw_util::biosPurpose, "", true);
Carol Wangd82a3ac2019-11-21 13:56:38 +080037 }
38};
39/**
40 * BiosReset class supports handle POST method for Reset bios.
41 * The class retrieves and sends data directly to D-Bus.
42 */
43class BiosReset : public Node
44{
45 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -050046 BiosReset(CrowApp& app) :
Carol Wangd82a3ac2019-11-21 13:56:38 +080047 Node(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
48 {
49 entityPrivileges = {
50 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
51 }
52
53 private:
54 /**
55 * Function handles POST method request.
56 * Analyzes POST body message before sends Reset request data to D-Bus.
57 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -050058 void doPost(crow::Response& res, const crow::Request& req,
59 const std::vector<std::string>& params) override
Carol Wangd82a3ac2019-11-21 13:56:38 +080060 {
61 auto asyncResp = std::make_shared<AsyncResp>(res);
62
63 crow::connections::systemBus->async_method_call(
64 [asyncResp](const boost::system::error_code ec) {
65 if (ec)
66 {
67 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
68 messages::internalError(asyncResp->res);
69 return;
70 }
71 },
72 "org.open_power.Software.Host.Updater",
73 "/xyz/openbmc_project/software",
74 "xyz.openbmc_project.Common.FactoryReset", "Reset");
75 }
76};
Gunnar Mills72d566d2020-07-21 12:44:00 -050077} // namespace redfish