Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3 | #include <app.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 4 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 5 | #include <registries/privilege_registry.hpp> |
Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame] | 6 | #include <utils/fw_utils.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 7 | |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 8 | namespace redfish |
| 9 | { |
| 10 | /** |
| 11 | * BiosService class supports handle get method for bios. |
| 12 | */ |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 13 | inline void |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 14 | handleBiosServiceGet(crow::App& app, const crow::Request& req, |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 15 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 16 | { |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 17 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 18 | { |
| 19 | return; |
| 20 | } |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 21 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios"; |
| 22 | asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; |
| 23 | asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; |
| 24 | asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; |
| 25 | asyncResp->res.jsonValue["Id"] = "BIOS"; |
| 26 | asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = { |
| 27 | {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}}; |
| 28 | |
| 29 | // Get the ActiveSoftwareImage and SoftwareImages |
| 30 | fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "", |
| 31 | true); |
| 32 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 33 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 34 | inline void requestRoutesBiosService(App& app) |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 35 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 36 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 37 | .privileges(redfish::privileges::getBios) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 38 | .methods(boost::beast::http::verb::get)( |
| 39 | std::bind_front(handleBiosServiceGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 40 | } |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 41 | |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 42 | /** |
| 43 | * BiosReset class supports handle POST method for Reset bios. |
| 44 | * The class retrieves and sends data directly to D-Bus. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 45 | * |
| 46 | * Function handles POST method request. |
| 47 | * Analyzes POST body message before sends Reset request data to D-Bus. |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 48 | */ |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 49 | inline void |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 50 | handleBiosResetPost(crow::App& app, const crow::Request& req, |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 51 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 52 | { |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 53 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 54 | { |
| 55 | return; |
| 56 | } |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 57 | crow::connections::systemBus->async_method_call( |
| 58 | [asyncResp](const boost::system::error_code ec) { |
| 59 | if (ec) |
| 60 | { |
| 61 | BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec; |
| 62 | messages::internalError(asyncResp->res); |
| 63 | return; |
| 64 | } |
| 65 | }, |
| 66 | "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software", |
| 67 | "xyz.openbmc_project.Common.FactoryReset", "Reset"); |
| 68 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 69 | |
| 70 | inline void requestRoutesBiosReset(App& app) |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 71 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 72 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/") |
John Edward Broadbent | b7ff344 | 2021-10-04 09:45:42 -0700 | [diff] [blame] | 73 | .privileges(redfish::privileges::postBios) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 74 | .methods(boost::beast::http::verb::post)( |
| 75 | std::bind_front(handleBiosResetPost, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 76 | } |
John Edward Broadbent | 58eaf5f | 2021-07-02 10:15:48 -0700 | [diff] [blame] | 77 | |
Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame] | 78 | } // namespace redfish |