blob: 85b4044470d4431a439c7c93288fb7e00b00c746 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01004#pragma once
5
Willy Tu13451e32023-05-24 16:08:18 -07006#include "bmcweb_config.h"
7
Sui Chena51fc2d2022-07-14 17:21:53 -07008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
10#include "dbus_singleton.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070011#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070013#include "generated/enums/action_info.hpp"
14#include "generated/enums/manager.hpp"
15#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080016#include "http_request.hpp"
17#include "logging.hpp"
18#include "persistent_data.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070019#include "query.hpp"
rohitpaic1a75eb2025-01-03 19:13:36 +053020#include "redfish.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080021#include "redfish_util.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070022#include "registries/privilege_registry.hpp"
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020023#include "utils/dbus_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "utils/json_utils.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070025#include "utils/sw_utils.hpp"
26#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070027#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010028
Ed Tanousd7857202025-01-28 15:32:26 -080029#include <systemd/sd-bus.h>
30
Ed Tanousd7857202025-01-28 15:32:26 -080031#include <boost/beast/http/status.hpp>
32#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080033#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070034#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080035#include <boost/url/url.hpp>
36#include <nlohmann/json.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020037#include <sdbusplus/asio/property.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080038#include <sdbusplus/message.hpp>
39#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020040#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050041
George Liue99073f2022-12-09 11:06:16 +080042#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080043#include <cstddef>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050044#include <cstdint>
Ed Tanousd7857202025-01-28 15:32:26 -080045#include <format>
46#include <functional>
47#include <map>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050048#include <memory>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030049#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070050#include <ranges>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030051#include <string>
George Liue99073f2022-12-09 11:06:16 +080052#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080053#include <utility>
Ed Tanousd7857202025-01-28 15:32:26 -080054#include <vector>
James Feist5b4aa862018-08-16 14:07:01 -070055
Ed Tanous1abe55e2018-09-05 08:30:59 -070056namespace redfish
57{
Jennifer Leeed5befb2018-08-10 11:29:45 -070058
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -070059inline std::string getBMCUpdateServiceName()
60{
61 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
62 {
63 return "xyz.openbmc_project.Software.Manager";
64 }
65 return "xyz.openbmc_project.Software.BMC.Updater";
66}
67
68inline std::string getBMCUpdateServicePath()
69{
70 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
71 {
72 return "/xyz/openbmc_project/software/bmc";
73 }
74 return "/xyz/openbmc_project/software";
75}
76
Jennifer Leeed5befb2018-08-10 11:29:45 -070077/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050078 * Function reboots the BMC.
79 *
80 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070081 */
Patrick Williams504af5a2025-02-03 14:29:03 -050082inline void doBMCGracefulRestart(
83 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050084{
85 const char* processName = "xyz.openbmc_project.State.BMC";
86 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
87 const char* interfaceName = "xyz.openbmc_project.State.BMC";
88 const std::string& propertyValue =
89 "xyz.openbmc_project.State.BMC.Transition.Reboot";
90 const char* destProperty = "RequestedBMCTransition";
91
92 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +080093 sdbusplus::asio::setProperty(
94 *crow::connections::systemBus, processName, objectPath, interfaceName,
95 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080096 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040097 // Use "Set" method to set the property value.
98 if (ec)
99 {
100 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
101 messages::internalError(asyncResp->res);
102 return;
103 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500104
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400105 messages::success(asyncResp->res);
106 });
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500107}
108
Patrick Williams504af5a2025-02-03 14:29:03 -0500109inline void doBMCForceRestart(
110 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000111{
112 const char* processName = "xyz.openbmc_project.State.BMC";
113 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
114 const char* interfaceName = "xyz.openbmc_project.State.BMC";
115 const std::string& propertyValue =
116 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
117 const char* destProperty = "RequestedBMCTransition";
118
119 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +0800120 sdbusplus::asio::setProperty(
121 *crow::connections::systemBus, processName, objectPath, interfaceName,
122 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800123 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400124 // Use "Set" method to set the property value.
125 if (ec)
126 {
127 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
128 messages::internalError(asyncResp->res);
129 return;
130 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000131
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400132 messages::success(asyncResp->res);
133 });
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000134}
135
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500136/**
137 * ManagerResetAction class supports the POST method for the Reset (reboot)
138 * action.
139 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700140inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700141{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700142 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700143 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500144 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000145 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700146 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700147
Ed Tanous253f11b2024-05-16 09:38:31 -0700148 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700149 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700150 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700151 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700152 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
153 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400154 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
155 {
156 return;
157 }
158 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
159 {
160 messages::resourceNotFound(asyncResp->res, "Manager",
161 managerId);
162 return;
163 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700164
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400165 BMCWEB_LOG_DEBUG("Post Manager Reset.");
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500166
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400167 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700168
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400169 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
170 resetType))
171 {
172 return;
173 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500174
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400175 if (resetType == "GracefulRestart")
176 {
177 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
178 doBMCGracefulRestart(asyncResp);
179 return;
180 }
181 if (resetType == "ForceRestart")
182 {
183 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
184 doBMCForceRestart(asyncResp);
185 return;
186 }
187 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
188 resetType);
189 messages::actionParameterNotSupported(asyncResp->res, resetType,
190 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700191
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400192 return;
193 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700194}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700195
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500196/**
197 * ManagerResetToDefaultsAction class supports POST method for factory reset
198 * action.
199 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700200inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500201{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500202 /**
203 * Function handles ResetToDefaults POST method request.
204 *
205 * Analyzes POST body message and factory resets BMC by calling
206 * BMC code updater factory reset followed by a BMC reboot.
207 *
208 * BMC code updater factory reset wipes the whole BMC read-write
209 * filesystem which includes things like the network settings.
210 *
211 * OpenBMC only supports ResetToDefaultsType "ResetAll".
212 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500213
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700214 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -0700215 "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700216 .privileges(redfish::privileges::postManager)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400217 .methods(
218 boost::beast::http::verb::
219 post)([&app](
220 const crow::Request& req,
221 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
222 const std::string& managerId) {
223 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700224 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700225 return;
226 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400227
228 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
229 {
230 messages::resourceNotFound(asyncResp->res, "Manager",
231 managerId);
232 return;
233 }
234
235 BMCWEB_LOG_DEBUG("Post ResetToDefaults.");
236
237 std::optional<std::string> resetType;
238 std::optional<std::string> resetToDefaultsType;
239
Patrick Williams504af5a2025-02-03 14:29:03 -0500240 if (!json_util::readJsonAction( //
241 req, asyncResp->res, //
Myung Baeafc474a2024-10-09 00:53:29 -0700242 "ResetToDefaultsType", resetToDefaultsType, //
Patrick Williams504af5a2025-02-03 14:29:03 -0500243 "ResetType", resetType //
Myung Baeafc474a2024-10-09 00:53:29 -0700244 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400245 {
246 BMCWEB_LOG_DEBUG("Missing property ResetType.");
247
248 messages::actionParameterMissing(
249 asyncResp->res, "ResetToDefaults", "ResetType");
250 return;
251 }
252
253 if (resetToDefaultsType && !resetType)
254 {
255 BMCWEB_LOG_WARNING(
256 "Using deprecated ResetToDefaultsType, should be ResetType."
257 "Support for the ResetToDefaultsType will be dropped in 2Q24");
258 resetType = resetToDefaultsType;
259 }
260
261 if (resetType != "ResetAll")
262 {
263 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
264 *resetType);
265 messages::actionParameterNotSupported(asyncResp->res,
266 *resetType, "ResetType");
267 return;
268 }
269
270 crow::connections::systemBus->async_method_call(
271 [asyncResp](const boost::system::error_code& ec) {
272 if (ec)
273 {
274 BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec);
275 messages::internalError(asyncResp->res);
276 return;
277 }
278 // Factory Reset doesn't actually happen until a reboot
279 // Can't erase what the BMC is running on
280 doBMCGracefulRestart(asyncResp);
281 },
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700282 getBMCUpdateServiceName(), getBMCUpdateServicePath(),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400283 "xyz.openbmc_project.Common.FactoryReset", "Reset");
284 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700285}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500286
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530287/**
288 * ManagerResetActionInfo derived class for delivering Manager
289 * ResetType AllowableValues using ResetInfo schema.
290 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700291inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530292{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530293 /**
294 * Functions triggers appropriate requests on DBus
295 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700296
Ed Tanous253f11b2024-05-16 09:38:31 -0700297 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700298 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700299 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700300 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700301 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
302 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400303 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
304 {
305 return;
306 }
Ed Tanous14766872022-03-15 10:44:42 -0700307
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400308 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
309 {
310 messages::resourceNotFound(asyncResp->res, "Manager",
311 managerId);
312 return;
313 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700314
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400315 asyncResp->res.jsonValue["@odata.type"] =
316 "#ActionInfo.v1_1_2.ActionInfo";
317 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
318 "/redfish/v1/Managers/{}/ResetActionInfo",
319 BMCWEB_REDFISH_MANAGER_URI_NAME);
320 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
321 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
322 nlohmann::json::object_t parameter;
323 parameter["Name"] = "ResetType";
324 parameter["Required"] = true;
325 parameter["DataType"] = action_info::ParameterTypes::String;
Ed Tanous14766872022-03-15 10:44:42 -0700326
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400327 nlohmann::json::array_t allowableValues;
328 allowableValues.emplace_back("GracefulRestart");
329 allowableValues.emplace_back("ForceRestart");
330 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700331
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400332 nlohmann::json::array_t parameters;
333 parameters.emplace_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700334
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400335 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
336 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700337}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530338
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500339/**
340 * @brief Retrieves BMC manager location data over DBus
341 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700342 * @param[in] asyncResp Shared pointer for completing asynchronous calls
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500343 * @param[in] connectionName - service name
344 * @param[in] path - object path
345 * @return none
346 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700347inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500348 const std::string& connectionName,
349 const std::string& path)
350{
Ed Tanous62598e32023-07-17 17:06:25 -0700351 BMCWEB_LOG_DEBUG("Get BMC manager Location data.");
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500352
Ed Tanousdeae6a72024-11-11 21:58:57 -0800353 dbus::utility::getProperty<std::string>(
354 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700355 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700356 [asyncResp](const boost::system::error_code& ec,
357 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400358 if (ec)
359 {
360 BMCWEB_LOG_DEBUG("DBUS response error for "
361 "Location");
362 messages::internalError(asyncResp->res);
363 return;
364 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500365
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400366 asyncResp->res
367 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
368 property;
369 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500370}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700371// avoid name collision systems.hpp
Patrick Williams504af5a2025-02-03 14:29:03 -0500372inline void managerGetLastResetTime(
373 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700374{
Ed Tanous62598e32023-07-17 17:06:25 -0700375 BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time");
Ed Tanous52cc1122020-07-18 13:51:21 -0700376
Ed Tanousdeae6a72024-11-11 21:58:57 -0800377 dbus::utility::getProperty<uint64_t>(
378 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
379 "xyz.openbmc_project.State.BMC", "LastRebootTime",
Ed Tanousac106bf2023-06-07 09:24:59 -0700380 [asyncResp](const boost::system::error_code& ec,
381 const uint64_t lastResetTime) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400382 if (ec)
383 {
384 BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
385 return;
386 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700387
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400388 // LastRebootTime is epoch time, in milliseconds
389 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
390 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700391
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400392 // Convert to ISO 8601 standard
393 asyncResp->res.jsonValue["LastResetTime"] =
394 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
395 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700396}
397
398/**
399 * @brief Set the running firmware image
400 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700401 * @param[i,o] asyncResp - Async response object
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700402 * @param[i] runningFirmwareTarget - Image to make the running image
403 *
404 * @return void
405 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500406inline void setActiveFirmwareImage(
407 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
408 const std::string& runningFirmwareTarget)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700409{
410 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
411 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
412 if (idPos == std::string::npos)
413 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700414 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700415 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700416 BMCWEB_LOG_DEBUG("Can't parse firmware ID!");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700417 return;
418 }
419 idPos++;
420 if (idPos >= runningFirmwareTarget.size())
421 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700422 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700423 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700424 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700425 return;
426 }
427 std::string firmwareId = runningFirmwareTarget.substr(idPos);
428
429 // Make sure the image is valid before setting priority
George Liu5eb468d2023-06-20 17:03:24 +0800430 sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
431 dbus::utility::getManagedObjects(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700432 getBMCUpdateServiceName(), objPath,
George Liu5eb468d2023-06-20 17:03:24 +0800433 [asyncResp, firmwareId, runningFirmwareTarget](
434 const boost::system::error_code& ec,
435 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400436 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700437 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400438 BMCWEB_LOG_DEBUG("D-Bus response error getting objects.");
Ed Tanousac106bf2023-06-07 09:24:59 -0700439 messages::internalError(asyncResp->res);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700440 return;
441 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400442
443 if (subtree.empty())
444 {
445 BMCWEB_LOG_DEBUG("Can't find image!");
446 messages::internalError(asyncResp->res);
447 return;
448 }
449
450 bool foundImage = false;
451 for (const auto& object : subtree)
452 {
453 const std::string& path =
454 static_cast<const std::string&>(object.first);
455 std::size_t idPos2 = path.rfind('/');
456
457 if (idPos2 == std::string::npos)
458 {
459 continue;
460 }
461
462 idPos2++;
463 if (idPos2 >= path.size())
464 {
465 continue;
466 }
467
468 if (path.substr(idPos2) == firmwareId)
469 {
470 foundImage = true;
471 break;
472 }
473 }
474
475 if (!foundImage)
476 {
477 messages::propertyValueNotInList(
478 asyncResp->res, runningFirmwareTarget, "@odata.id");
479 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
480 return;
481 }
482
483 BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.",
484 firmwareId);
485
486 // Only support Immediate
487 // An addition could be a Redfish Setting like
488 // ActiveSoftwareImageApplyTime and support OnReset
489 sdbusplus::asio::setProperty(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700490 *crow::connections::systemBus, getBMCUpdateServiceName(),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400491 "/xyz/openbmc_project/software/" + firmwareId,
492 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
493 static_cast<uint8_t>(0),
494 [asyncResp](const boost::system::error_code& ec2) {
495 if (ec2)
496 {
497 BMCWEB_LOG_DEBUG("D-Bus response error setting.");
498 messages::internalError(asyncResp->res);
499 return;
500 }
501 doBMCGracefulRestart(asyncResp);
502 });
George Liu5eb468d2023-06-20 17:03:24 +0800503 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700504}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700505
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400506inline void afterSetDateTime(
507 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
508 const boost::system::error_code& ec, const sdbusplus::message_t& msg)
Ed Tanousc51afd52024-03-07 10:13:14 -0800509{
510 if (ec)
511 {
512 BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}",
513 ec);
514 const sd_bus_error* dbusError = msg.get_error();
515 if (dbusError != nullptr)
516 {
517 std::string_view errorName(dbusError->name);
518 if (errorName ==
519 "org.freedesktop.timedate1.AutomaticTimeSyncEnabled")
520 {
521 BMCWEB_LOG_DEBUG("Setting conflict");
522 messages::propertyValueConflict(
523 asyncResp->res, "DateTime",
524 "Managers/NetworkProtocol/NTPProcotolEnabled");
525 return;
526 }
527 }
528 messages::internalError(asyncResp->res);
529 return;
530 }
531 asyncResp->res.result(boost::beast::http::status::no_content);
532}
533
534inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
535 const std::string& datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700536{
Ed Tanous62598e32023-07-17 17:06:25 -0700537 BMCWEB_LOG_DEBUG("Set date time: {}", datetime);
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100538
Ed Tanousc2e32002023-01-07 22:05:08 -0800539 std::optional<redfish::time_utils::usSinceEpoch> us =
540 redfish::time_utils::dateStringToEpoch(datetime);
541 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700542 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700543 messages::propertyValueFormatError(asyncResp->res, datetime,
544 "DateTime");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700545 return;
546 }
Ed Tanousc51afd52024-03-07 10:13:14 -0800547 // Set the absolute datetime
548 bool relative = false;
549 bool interactive = false;
550 crow::connections::systemBus->async_method_call(
551 [asyncResp](const boost::system::error_code& ec,
552 const sdbusplus::message_t& msg) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400553 afterSetDateTime(asyncResp, ec, msg);
554 },
Ed Tanousc51afd52024-03-07 10:13:14 -0800555 "org.freedesktop.timedate1", "/org/freedesktop/timedate1",
556 "org.freedesktop.timedate1", "SetTime", us->count(), relative,
557 interactive);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700558}
559
Patrick Williams504af5a2025-02-03 14:29:03 -0500560inline void checkForQuiesced(
561 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous75815e52022-10-05 17:21:13 -0700562{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800563 dbus::utility::getProperty<std::string>(
564 "org.freedesktop.systemd1",
Ed Tanous75815e52022-10-05 17:21:13 -0700565 "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
566 "org.freedesktop.systemd1.Unit", "ActiveState",
567 [asyncResp](const boost::system::error_code& ec,
568 const std::string& val) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400569 if (!ec)
Ed Tanous75815e52022-10-05 17:21:13 -0700570 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400571 if (val == "active")
572 {
573 asyncResp->res.jsonValue["Status"]["Health"] =
574 resource::Health::Critical;
575 asyncResp->res.jsonValue["Status"]["State"] =
576 resource::State::Quiesced;
577 return;
578 }
Ed Tanous75815e52022-10-05 17:21:13 -0700579 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400580 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
581 asyncResp->res.jsonValue["Status"]["State"] =
582 resource::State::Enabled;
583 });
Ed Tanous75815e52022-10-05 17:21:13 -0700584}
585
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700586inline void requestRoutesManager(App& app)
587{
588 std::string uuid = persistent_data::getConfig().systemUuid;
589
Ed Tanous253f11b2024-05-16 09:38:31 -0700590 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700591 .privileges(redfish::privileges::getManager)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400592 .methods(
593 boost::beast::http::verb::
594 get)([&app,
595 uuid](const crow::Request& req,
596 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
597 const std::string& managerId) {
598 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
599 {
600 return;
601 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700602
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400603 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
604 {
605 messages::resourceNotFound(asyncResp->res, "Manager",
606 managerId);
607 return;
608 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700609
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400610 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
611 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
612 asyncResp->res.jsonValue["@odata.type"] =
613 "#Manager.v1_14_0.Manager";
614 asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME;
615 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
616 asyncResp->res.jsonValue["Description"] =
617 "Baseboard Management Controller";
618 asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On;
Ed Tanous14766872022-03-15 10:44:42 -0700619
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400620 asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC;
621 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
622 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
623 asyncResp->res.jsonValue["Model"] =
624 "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700625
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400626 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
627 boost::urls::format("/redfish/v1/Managers/{}/LogServices",
Ed Tanous253f11b2024-05-16 09:38:31 -0700628 BMCWEB_REDFISH_MANAGER_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400629 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
630 boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol",
631 BMCWEB_REDFISH_MANAGER_URI_NAME);
632 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
633 boost::urls::format(
634 "/redfish/v1/Managers/{}/EthernetInterfaces",
635 BMCWEB_REDFISH_MANAGER_URI_NAME);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700636
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400637 if constexpr (BMCWEB_VM_NBDPROXY)
Ed Tanous75815e52022-10-05 17:21:13 -0700638 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400639 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
640 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia",
641 BMCWEB_REDFISH_MANAGER_URI_NAME);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700642 }
643
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400644 // Manager.Reset (an action) can be many values, OpenBMC only
645 // supports BMC reboot.
646 nlohmann::json& managerReset =
647 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
648 managerReset["target"] = boost::urls::format(
649 "/redfish/v1/Managers/{}/Actions/Manager.Reset",
650 BMCWEB_REDFISH_MANAGER_URI_NAME);
651 managerReset["@Redfish.ActionInfo"] =
652 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
653 BMCWEB_REDFISH_MANAGER_URI_NAME);
654
655 // ResetToDefaults (Factory Reset) has values like
656 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
657 // on OpenBMC
658 nlohmann::json& resetToDefaults =
659 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
660 resetToDefaults["target"] = boost::urls::format(
661 "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults",
662 BMCWEB_REDFISH_MANAGER_URI_NAME);
663 resetToDefaults["ResetType@Redfish.AllowableValues"] =
664 nlohmann::json::array_t({"ResetAll"});
665
666 std::pair<std::string, std::string> redfishDateTimeOffset =
667 redfish::time_utils::getDateTimeOffsetNow();
668
669 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
670 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
671 redfishDateTimeOffset.second;
672
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400673 if constexpr (BMCWEB_KVM)
Ed Tanous002d39b2022-05-31 08:59:27 -0700674 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400675 // Fill in GraphicalConsole info
676 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] =
677 true;
678 asyncResp->res
679 .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4;
680 asyncResp->res
681 .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
682 nlohmann::json::array_t({"KVMIP"});
683 }
684 if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
685 {
686 asyncResp->res
687 .jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
688
689 nlohmann::json::array_t managerForServers;
690 nlohmann::json::object_t manager;
691 manager["@odata.id"] = std::format(
692 "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
693 managerForServers.emplace_back(std::move(manager));
694
695 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
696 std::move(managerForServers);
Ed Tanous002d39b2022-05-31 08:59:27 -0700697 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700698
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400699 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
700 "FirmwareVersion", true);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700701
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400702 managerGetLastResetTime(asyncResp);
703
704 // ManagerDiagnosticData is added for all BMCs.
705 nlohmann::json& managerDiagnosticData =
706 asyncResp->res.jsonValue["ManagerDiagnosticData"];
707 managerDiagnosticData["@odata.id"] = boost::urls::format(
708 "/redfish/v1/Managers/{}/ManagerDiagnosticData",
709 BMCWEB_REDFISH_MANAGER_URI_NAME);
710
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400711 getMainChassisId(asyncResp, [](const std::string& chassisId,
712 const std::shared_ptr<
713 bmcweb::AsyncResp>& aRsp) {
714 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] =
715 1;
716 nlohmann::json::array_t managerForChassis;
717 nlohmann::json::object_t managerObj;
718 boost::urls::url chassiUrl =
719 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
720 managerObj["@odata.id"] = chassiUrl;
721 managerForChassis.emplace_back(std::move(managerObj));
722 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
723 std::move(managerForChassis);
724 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
725 chassiUrl;
726 });
727
Ed Tanousdeae6a72024-11-11 21:58:57 -0800728 dbus::utility::getProperty<double>(
729 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
730 "org.freedesktop.systemd1.Manager", "Progress",
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400731 [asyncResp](const boost::system::error_code& ec, double val) {
732 if (ec)
733 {
734 BMCWEB_LOG_ERROR("Error while getting progress");
735 messages::internalError(asyncResp->res);
736 return;
737 }
738 if (val < 1.0)
739 {
740 asyncResp->res.jsonValue["Status"]["Health"] =
741 resource::Health::OK;
742 asyncResp->res.jsonValue["Status"]["State"] =
743 resource::State::Starting;
744 return;
745 }
746 checkForQuiesced(asyncResp);
747 });
748
749 constexpr std::array<std::string_view, 1> interfaces = {
750 "xyz.openbmc_project.Inventory.Item.Bmc"};
751 dbus::utility::getSubTree(
752 "/xyz/openbmc_project/inventory", 0, interfaces,
753 [asyncResp](
754 const boost::system::error_code& ec,
755 const dbus::utility::MapperGetSubTreeResponse& subtree) {
756 if (ec)
757 {
758 BMCWEB_LOG_DEBUG(
759 "D-Bus response error on GetSubTree {}", ec);
760 return;
761 }
762 if (subtree.empty())
763 {
764 BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!");
765 return;
766 }
767 // Assume only 1 bmc D-Bus object
768 // Throw an error if there is more than 1
769 if (subtree.size() > 1)
770 {
771 BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!");
772 messages::internalError(asyncResp->res);
773 return;
774 }
775
776 if (subtree[0].first.empty() ||
777 subtree[0].second.size() != 1)
778 {
779 BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!");
780 messages::internalError(asyncResp->res);
781 return;
782 }
783
784 const std::string& path = subtree[0].first;
785 const std::string& connectionName =
786 subtree[0].second[0].first;
787
788 for (const auto& interfaceName :
789 subtree[0].second[0].second)
790 {
791 if (interfaceName ==
792 "xyz.openbmc_project.Inventory.Decorator.Asset")
793 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800794 dbus::utility::getAllProperties(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400795 *crow::connections::systemBus, connectionName,
796 path,
797 "xyz.openbmc_project.Inventory.Decorator.Asset",
798 [asyncResp](
799 const boost::system::error_code& ec2,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800800 const dbus::utility::DBusPropertiesMap&
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700801 propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400802 if (ec2)
803 {
804 BMCWEB_LOG_DEBUG(
805 "Can't get bmc asset!");
806 return;
807 }
808
809 const std::string* partNumber = nullptr;
810 const std::string* serialNumber = nullptr;
811 const std::string* manufacturer = nullptr;
812 const std::string* model = nullptr;
813 const std::string* sparePartNumber =
814 nullptr;
815
816 const bool success =
817 sdbusplus::unpackPropertiesNoThrow(
818 dbus_utils::UnpackErrorPrinter(),
819 propertiesList, "PartNumber",
820 partNumber, "SerialNumber",
821 serialNumber, "Manufacturer",
822 manufacturer, "Model", model,
823 "SparePartNumber", sparePartNumber);
824
825 if (!success)
826 {
827 messages::internalError(asyncResp->res);
828 return;
829 }
830
831 if (partNumber != nullptr)
832 {
833 asyncResp->res.jsonValue["PartNumber"] =
834 *partNumber;
835 }
836
837 if (serialNumber != nullptr)
838 {
839 asyncResp->res
840 .jsonValue["SerialNumber"] =
841 *serialNumber;
842 }
843
844 if (manufacturer != nullptr)
845 {
846 asyncResp->res
847 .jsonValue["Manufacturer"] =
848 *manufacturer;
849 }
850
851 if (model != nullptr)
852 {
853 asyncResp->res.jsonValue["Model"] =
854 *model;
855 }
856
857 if (sparePartNumber != nullptr)
858 {
859 asyncResp->res
860 .jsonValue["SparePartNumber"] =
861 *sparePartNumber;
862 }
863 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700864 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400865 else if (
866 interfaceName ==
867 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +0200868 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400869 getLocation(asyncResp, connectionName, path);
Ed Tanous002d39b2022-05-31 08:59:27 -0700870 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400871 }
872 });
rohitpaic1a75eb2025-01-03 19:13:36 +0530873
874 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700875 });
876
Ed Tanous253f11b2024-05-16 09:38:31 -0700877 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700878 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700879 .methods(boost::beast::http::verb::patch)(
880 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700881 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
882 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400883 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
884 {
885 return;
886 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700887
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400888 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
889 {
890 messages::resourceNotFound(asyncResp->res, "Manager",
891 managerId);
892 return;
893 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700894
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400895 std::optional<std::string> activeSoftwareImageOdataId;
896 std::optional<std::string> datetime;
897 std::optional<nlohmann::json::object_t> pidControllers;
898 std::optional<nlohmann::json::object_t> fanControllers;
899 std::optional<nlohmann::json::object_t> fanZones;
900 std::optional<nlohmann::json::object_t> stepwiseControllers;
901 std::optional<std::string> profile;
Ed Tanous002d39b2022-05-31 08:59:27 -0700902
Patrick Williams504af5a2025-02-03 14:29:03 -0500903 if (!json_util::readJsonPatch( //
904 req, asyncResp->res, //
905 "DateTime", datetime, //
Myung Baeafc474a2024-10-09 00:53:29 -0700906 "Links/ActiveSoftwareImage/@odata.id",
Patrick Williams504af5a2025-02-03 14:29:03 -0500907 activeSoftwareImageOdataId, //
Myung Baeafc474a2024-10-09 00:53:29 -0700908 "Oem/OpenBmc/Fan/FanControllers", fanControllers, //
Patrick Williams504af5a2025-02-03 14:29:03 -0500909 "Oem/OpenBmc/Fan/FanZones", fanZones, //
Myung Baeafc474a2024-10-09 00:53:29 -0700910 "Oem/OpenBmc/Fan/PidControllers", pidControllers, //
Patrick Williams504af5a2025-02-03 14:29:03 -0500911 "Oem/OpenBmc/Fan/Profile", profile, //
Myung Baeafc474a2024-10-09 00:53:29 -0700912 "Oem/OpenBmc/Fan/StepwiseControllers",
Patrick Williams504af5a2025-02-03 14:29:03 -0500913 stepwiseControllers //
Myung Baeafc474a2024-10-09 00:53:29 -0700914 ))
915 {
916 return;
917 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700918
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400919 if (activeSoftwareImageOdataId)
920 {
921 setActiveFirmwareImage(asyncResp,
922 *activeSoftwareImageOdataId);
923 }
Ed Tanous9e9b6042024-03-06 14:18:28 -0800924
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400925 if (datetime)
926 {
927 setDateTime(asyncResp, *datetime);
928 }
rohitpai84aad242025-01-28 09:23:53 +0530929
930 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400931 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700932}
933
934inline void requestRoutesManagerCollection(App& app)
935{
936 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -0700937 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700938 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700939 [&app](const crow::Request& req,
940 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400941 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
942 {
943 return;
944 }
945 // Collections don't include the static data added by SubRoute
946 // because it has a duplicate entry for members
947 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
948 asyncResp->res.jsonValue["@odata.type"] =
949 "#ManagerCollection.ManagerCollection";
950 asyncResp->res.jsonValue["Name"] = "Manager Collection";
951 asyncResp->res.jsonValue["Members@odata.count"] = 1;
952 nlohmann::json::array_t members;
953 nlohmann::json& bmc = members.emplace_back();
954 bmc["@odata.id"] = boost::urls::format(
955 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
956 asyncResp->res.jsonValue["Members"] = std::move(members);
957 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700958}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700959} // namespace redfish