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