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