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