blob: 2c3107723b64d20b3e6627bdaedbe28f08d304ed [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:
Ed Tanous52cc1122020-07-18 13:51:21 -070014 BiosService(App& 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:
Ed Tanouscb13a392020-07-25 19:02:03 +000020 void doGet(crow::Response& res, const crow::Request&,
21 const std::vector<std::string>&) 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
Gunnar Millsf97ddba2020-08-20 15:57:40 -050035 // Get the ActiveSoftwareImage and SoftwareImages
36 fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose,
37 "", true);
Carol Wangd82a3ac2019-11-21 13:56:38 +080038 }
39};
40/**
41 * BiosReset class supports handle POST method for Reset bios.
42 * The class retrieves and sends data directly to D-Bus.
43 */
44class BiosReset : public Node
45{
46 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070047 BiosReset(App& app) :
Carol Wangd82a3ac2019-11-21 13:56:38 +080048 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 */
Ed Tanouscb13a392020-07-25 19:02:03 +000059 void doPost(crow::Response& res, const crow::Request&,
60 const std::vector<std::string>&) override
Carol Wangd82a3ac2019-11-21 13:56:38 +080061 {
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};
Gunnar Mills72d566d2020-07-21 12:44:00 -050078} // namespace redfish