Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "node.hpp" |
| 4 | |
Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame^] | 5 | #include <utils/fw_utils.hpp> |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 6 | namespace redfish |
| 7 | { |
| 8 | /** |
| 9 | * BiosService class supports handle get method for bios. |
| 10 | */ |
| 11 | class BiosService : public Node |
| 12 | { |
| 13 | public: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 14 | BiosService(CrowApp& app) : Node(app, "/redfish/v1/Systems/system/Bios/") |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 15 | { |
| 16 | entityPrivileges = {{boost::beast::http::verb::get, {{"Login"}}}}; |
| 17 | } |
| 18 | |
| 19 | private: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 20 | void doGet(crow::Response& res, const crow::Request& req, |
| 21 | const std::vector<std::string>& params) override |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 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"}}; |
Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame^] | 34 | |
| 35 | // Get the ActiveSoftwareImage |
| 36 | fw_util::getActiveFwVersion(asyncResp, fw_util::biosPurpose, "", true); |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 37 | } |
| 38 | }; |
| 39 | /** |
| 40 | * BiosReset class supports handle POST method for Reset bios. |
| 41 | * The class retrieves and sends data directly to D-Bus. |
| 42 | */ |
| 43 | class BiosReset : public Node |
| 44 | { |
| 45 | public: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 46 | BiosReset(CrowApp& app) : |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 47 | 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 Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 58 | void doPost(crow::Response& res, const crow::Request& req, |
| 59 | const std::vector<std::string>& params) override |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 60 | { |
| 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 Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame^] | 77 | } // namespace redfish |