/src/bmcweb/redfish-core/lib/bios.hpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
3 | | #pragma once |
4 | | |
5 | | #include "bmcweb_config.h" |
6 | | |
7 | | #include "app.hpp" |
8 | | #include "async_resp.hpp" |
9 | | #include "dbus_utility.hpp" |
10 | | #include "error_messages.hpp" |
11 | | #include "http_request.hpp" |
12 | | #include "logging.hpp" |
13 | | #include "query.hpp" |
14 | | #include "registries/privilege_registry.hpp" |
15 | | #include "utils/sw_utils.hpp" |
16 | | |
17 | | #include <boost/beast/http/verb.hpp> |
18 | | #include <boost/url/format.hpp> |
19 | | |
20 | | #include <format> |
21 | | #include <functional> |
22 | | #include <memory> |
23 | | #include <string> |
24 | | |
25 | | namespace redfish |
26 | | { |
27 | | /** |
28 | | * BiosService class supports handle get method for bios. |
29 | | */ |
30 | | inline void handleBiosServiceGet( |
31 | | crow::App& app, const crow::Request& req, |
32 | | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
33 | | const std::string& systemName) |
34 | 0 | { |
35 | 0 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
36 | 0 | { |
37 | 0 | return; |
38 | 0 | } |
39 | | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
40 | | { |
41 | | // Option currently returns no systems. TBD |
42 | | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
43 | | systemName); |
44 | | return; |
45 | | } |
46 | 0 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
47 | 0 | { |
48 | 0 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
49 | 0 | systemName); |
50 | 0 | return; |
51 | 0 | } |
52 | 0 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
53 | 0 | "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
54 | 0 | asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios"; |
55 | 0 | asyncResp->res.jsonValue["Name"] = "BIOS Configuration"; |
56 | 0 | asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service"; |
57 | 0 | asyncResp->res.jsonValue["Id"] = "BIOS"; |
58 | 0 | asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] = |
59 | 0 | boost::urls::format( |
60 | 0 | "/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios", |
61 | 0 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
62 | | |
63 | | // Get the ActiveSoftwareImage and SoftwareImages |
64 | 0 | sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "", |
65 | 0 | true); |
66 | 0 | } |
67 | | |
68 | | inline void requestRoutesBiosService(App& app) |
69 | 6.88k | { |
70 | 6.88k | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/") |
71 | 6.88k | .privileges(redfish::privileges::getBios) |
72 | 6.88k | .methods(boost::beast::http::verb::get)( |
73 | 6.88k | std::bind_front(handleBiosServiceGet, std::ref(app))); |
74 | 6.88k | } |
75 | | |
76 | | /** |
77 | | * BiosReset class supports handle POST method for Reset bios. |
78 | | * The class retrieves and sends data directly to D-Bus. |
79 | | * |
80 | | * Function handles POST method request. |
81 | | * Analyzes POST body message before sends Reset request data to D-Bus. |
82 | | */ |
83 | | inline void handleBiosResetPost( |
84 | | crow::App& app, const crow::Request& req, |
85 | | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
86 | | const std::string& systemName) |
87 | 0 | { |
88 | 0 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
89 | 0 | { |
90 | 0 | return; |
91 | 0 | } |
92 | | |
93 | | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
94 | | { |
95 | | // Option currently returns no systems. TBD |
96 | | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
97 | | systemName); |
98 | | return; |
99 | | } |
100 | |
|
101 | 0 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
102 | 0 | { |
103 | 0 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
104 | 0 | systemName); |
105 | 0 | return; |
106 | 0 | } |
107 | | |
108 | 0 | dbus::utility::async_method_call( |
109 | 0 | asyncResp, |
110 | 0 | [asyncResp](const boost::system::error_code& ec) { |
111 | 0 | if (ec) |
112 | 0 | { |
113 | 0 | BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec); |
114 | 0 | messages::internalError(asyncResp->res); |
115 | 0 | return; |
116 | 0 | } |
117 | 0 | }, |
118 | 0 | "xyz.openbmc_project.Software.Host.Updater0", |
119 | 0 | "/xyz/openbmc_project/software", |
120 | 0 | "xyz.openbmc_project.Common.FactoryReset", "Reset"); |
121 | 0 | } |
122 | | |
123 | | inline void requestRoutesBiosReset(App& app) |
124 | 6.88k | { |
125 | 6.88k | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/") |
126 | 6.88k | .privileges(redfish::privileges::postBios) |
127 | 6.88k | .methods(boost::beast::http::verb::post)( |
128 | 6.88k | std::bind_front(handleBiosResetPost, std::ref(app))); |
129 | 6.88k | } |
130 | | |
131 | | } // namespace redfish |