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