blob: 32dcff1c89038ed8a62868b6c54eaa63d04f4c1e [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"
George Liu79f3b6a2021-05-13 18:08:44 +080017#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080018#include "logging.hpp"
19#include "persistent_data.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070020#include "query.hpp"
rohitpaic1a75eb2025-01-03 19:13:36 +053021#include "redfish.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080022#include "redfish_util.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070023#include "registries/privilege_registry.hpp"
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020024#include "utils/dbus_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080025#include "utils/json_utils.hpp"
Corey Ethingtone30d3342025-06-24 11:25:11 -040026#include "utils/manager_utils.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070027#include "utils/sw_utils.hpp"
28#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070029#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010030
Ed Tanousd7857202025-01-28 15:32:26 -080031#include <systemd/sd-bus.h>
32
Ed Tanousd7857202025-01-28 15:32:26 -080033#include <boost/beast/http/status.hpp>
34#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080035#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070036#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080037#include <boost/url/url.hpp>
38#include <nlohmann/json.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020039#include <sdbusplus/asio/property.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080040#include <sdbusplus/message.hpp>
41#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020042#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050043
George Liue99073f2022-12-09 11:06:16 +080044#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080045#include <cstddef>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050046#include <cstdint>
Ed Tanousd7857202025-01-28 15:32:26 -080047#include <format>
48#include <functional>
49#include <map>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050050#include <memory>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030051#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070052#include <ranges>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030053#include <string>
George Liue99073f2022-12-09 11:06:16 +080054#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080055#include <utility>
Ed Tanousd7857202025-01-28 15:32:26 -080056#include <vector>
James Feist5b4aa862018-08-16 14:07:01 -070057
Ed Tanous1abe55e2018-09-05 08:30:59 -070058namespace redfish
59{
Jennifer Leeed5befb2018-08-10 11:29:45 -070060
George Liu79f3b6a2021-05-13 18:08:44 +080061inline void handleSetLocationIndicatorActive(
62 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
63 bool locationIndicatorActive, const std::string& managerId,
64 const boost::system::error_code& ec,
65 const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths)
66{
67 if (ec)
68 {
69 if (ec == boost::system::errc::io_error)
70 {
71 // Not found
72 BMCWEB_LOG_WARNING("Manager {} not found", managerId);
73 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
74 return;
75 }
76 BMCWEB_LOG_ERROR("D-Bus response error {}", ec.value());
77 messages::internalError(asyncResp->res);
78 return;
79 }
80 if (subtreePaths.empty())
81 {
82 BMCWEB_LOG_WARNING("Manager {} not found", managerId);
83 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
84 return;
85 }
86 // Assume only 1 bmc D-Bus object
87 // Throw an error if there is more than 1
88 if (subtreePaths.size() != 1)
89 {
90 BMCWEB_LOG_ERROR("Found {} Bmc D-Bus paths", subtreePaths.size());
91 messages::internalError(asyncResp->res);
92 return;
93 }
94
95 setLocationIndicatorActive(asyncResp, subtreePaths[0],
96 locationIndicatorActive);
97}
98
99/**
100 * Set the locationIndicatorActive.
101 *
102 * @param[in,out] asyncResp Async HTTP response.
103 * @param[in] locationIndicatorActive Value of the property
104 */
105inline void setLocationIndicatorActiveState(
106 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
107 bool locationIndicatorActive, const std::string& managerId)
108{
109 // GetSubTree on all interfaces which provide info about a Manager
110 constexpr std::array<std::string_view, 1> interfaces = {
111 "xyz.openbmc_project.Inventory.Item.Bmc"};
112 dbus::utility::getSubTreePaths(
113 "/xyz/openbmc_project/inventory", 0, interfaces,
114 std::bind_front(handleSetLocationIndicatorActive, asyncResp,
115 locationIndicatorActive, managerId));
116}
117
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700118inline std::string getBMCUpdateServiceName()
119{
120 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
121 {
122 return "xyz.openbmc_project.Software.Manager";
123 }
124 return "xyz.openbmc_project.Software.BMC.Updater";
125}
126
127inline std::string getBMCUpdateServicePath()
128{
129 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
130 {
131 return "/xyz/openbmc_project/software/bmc";
132 }
133 return "/xyz/openbmc_project/software";
134}
135
Jennifer Leeed5befb2018-08-10 11:29:45 -0700136/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500137 * Function reboots the BMC.
138 *
139 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -0700140 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500141inline void doBMCGracefulRestart(
142 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500143{
144 const char* processName = "xyz.openbmc_project.State.BMC";
145 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
146 const char* interfaceName = "xyz.openbmc_project.State.BMC";
147 const std::string& propertyValue =
148 "xyz.openbmc_project.State.BMC.Transition.Reboot";
149 const char* destProperty = "RequestedBMCTransition";
150
151 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +0800152 sdbusplus::asio::setProperty(
153 *crow::connections::systemBus, processName, objectPath, interfaceName,
154 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800155 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400156 // Use "Set" method to set the property value.
157 if (ec)
158 {
159 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
160 messages::internalError(asyncResp->res);
161 return;
162 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500163
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400164 messages::success(asyncResp->res);
165 });
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500166}
167
Patrick Williams504af5a2025-02-03 14:29:03 -0500168inline void doBMCForceRestart(
169 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000170{
171 const char* processName = "xyz.openbmc_project.State.BMC";
172 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
173 const char* interfaceName = "xyz.openbmc_project.State.BMC";
174 const std::string& propertyValue =
175 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
176 const char* destProperty = "RequestedBMCTransition";
177
178 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +0800179 sdbusplus::asio::setProperty(
180 *crow::connections::systemBus, processName, objectPath, interfaceName,
181 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800182 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400183 // Use "Set" method to set the property value.
184 if (ec)
185 {
186 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
187 messages::internalError(asyncResp->res);
188 return;
189 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000190
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400191 messages::success(asyncResp->res);
192 });
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000193}
194
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500195/**
Myung Bae64acd262025-08-21 15:51:21 -0400196 * ManagerResetAction handles POST method request.
197 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
198 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500199 */
Myung Bae64acd262025-08-21 15:51:21 -0400200
201inline void handleManagerResetAction(
202 crow::App& app, const crow::Request& req,
203 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
204 const std::string& managerId)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700205{
Myung Bae64acd262025-08-21 15:51:21 -0400206 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
207 {
208 return;
209 }
210 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
211 {
212 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
213 return;
214 }
Jennifer Leeed5befb2018-08-10 11:29:45 -0700215
Myung Bae64acd262025-08-21 15:51:21 -0400216 BMCWEB_LOG_DEBUG("Post Manager Reset.");
Ed Tanous253f11b2024-05-16 09:38:31 -0700217
Myung Bae64acd262025-08-21 15:51:21 -0400218 std::string resetType;
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500219
Myung Bae64acd262025-08-21 15:51:21 -0400220 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
221 {
222 return;
223 }
Jennifer Leeed5befb2018-08-10 11:29:45 -0700224
Myung Bae64acd262025-08-21 15:51:21 -0400225 if (resetType == "GracefulRestart")
226 {
227 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
228 doBMCGracefulRestart(asyncResp);
229 return;
230 }
231 if (resetType == "ForceRestart")
232 {
233 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
234 doBMCForceRestart(asyncResp);
235 return;
236 }
237 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
238 messages::actionParameterNotSupported(asyncResp->res, resetType,
239 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700240}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700241
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500242/**
Myung Bae64acd262025-08-21 15:51:21 -0400243 * Function handles ResetToDefaults POST method request.
244 *
245 * Analyzes POST body message and factory resets BMC by calling
246 * BMC code updater factory reset followed by a BMC reboot.
247 *
248 * BMC code updater factory reset wipes the whole BMC read-write
249 * filesystem which includes things like the network settings.
250 *
251 * OpenBMC only supports ResetType "ResetAll".
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500252 */
Myung Bae64acd262025-08-21 15:51:21 -0400253
254inline void handleManagerResetToDefaultsAction(
255 crow::App& app, const crow::Request& req,
256 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
257 const std::string& managerId)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500258{
Myung Bae64acd262025-08-21 15:51:21 -0400259 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
260 {
261 return;
262 }
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500263
Myung Bae64acd262025-08-21 15:51:21 -0400264 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
265 {
266 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
267 return;
268 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400269
Myung Bae64acd262025-08-21 15:51:21 -0400270 BMCWEB_LOG_DEBUG("Post ResetToDefaults.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400271
Myung Bae64acd262025-08-21 15:51:21 -0400272 std::optional<std::string> resetType;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400273
Myung Bae64acd262025-08-21 15:51:21 -0400274 if (!json_util::readJsonAction( //
275 req, asyncResp->res, //
276 "ResetType", resetType //
277 ))
278 {
279 BMCWEB_LOG_DEBUG("Missing property ResetType.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400280
Myung Bae64acd262025-08-21 15:51:21 -0400281 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
282 "ResetType");
283 return;
284 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400285
Myung Bae64acd262025-08-21 15:51:21 -0400286 if (resetType.value_or("") != "ResetAll")
287 {
288 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
289 resetType.value_or(""));
290 messages::actionParameterNotSupported(
291 asyncResp->res, resetType.value_or(""), "ResetType");
292 return;
293 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400294
Myung Bae64acd262025-08-21 15:51:21 -0400295 crow::connections::systemBus->async_method_call(
296 [asyncResp](const boost::system::error_code& ec) {
297 if (ec)
298 {
299 BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec);
300 messages::internalError(asyncResp->res);
301 return;
302 }
303 // Factory Reset doesn't actually happen until a reboot
304 // Can't erase what the BMC is running on
305 doBMCGracefulRestart(asyncResp);
306 },
307 getBMCUpdateServiceName(), getBMCUpdateServicePath(),
308 "xyz.openbmc_project.Common.FactoryReset", "Reset");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700309}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500310
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530311/**
312 * ManagerResetActionInfo derived class for delivering Manager
313 * ResetType AllowableValues using ResetInfo schema.
314 */
Myung Bae64acd262025-08-21 15:51:21 -0400315inline void handleManagerResetActionInfo(
316 crow::App& app, const crow::Request& req,
317 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
318 const std::string& managerId)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530319{
Myung Bae64acd262025-08-21 15:51:21 -0400320 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
321 {
322 return;
323 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700324
Myung Bae64acd262025-08-21 15:51:21 -0400325 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
326 {
327 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
328 return;
329 }
Ed Tanous14766872022-03-15 10:44:42 -0700330
Myung Bae64acd262025-08-21 15:51:21 -0400331 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
332 asyncResp->res.jsonValue["@odata.id"] =
333 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
334 BMCWEB_REDFISH_MANAGER_URI_NAME);
335 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
336 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
337 nlohmann::json::object_t parameter;
338 parameter["Name"] = "ResetType";
339 parameter["Required"] = true;
340 parameter["DataType"] = action_info::ParameterTypes::String;
Ed Tanous253f11b2024-05-16 09:38:31 -0700341
Myung Bae64acd262025-08-21 15:51:21 -0400342 nlohmann::json::array_t allowableValues;
343 allowableValues.emplace_back("GracefulRestart");
344 allowableValues.emplace_back("ForceRestart");
345 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700346
Myung Bae64acd262025-08-21 15:51:21 -0400347 nlohmann::json::array_t parameters;
348 parameters.emplace_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700349
Myung Bae64acd262025-08-21 15:51:21 -0400350 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700351}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530352
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500353/**
354 * @brief Retrieves BMC manager location data over DBus
355 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700356 * @param[in] asyncResp Shared pointer for completing asynchronous calls
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500357 * @param[in] connectionName - service name
358 * @param[in] path - object path
359 * @return none
360 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700361inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500362 const std::string& connectionName,
363 const std::string& path)
364{
Ed Tanous62598e32023-07-17 17:06:25 -0700365 BMCWEB_LOG_DEBUG("Get BMC manager Location data.");
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500366
Ed Tanousdeae6a72024-11-11 21:58:57 -0800367 dbus::utility::getProperty<std::string>(
368 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700369 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700370 [asyncResp](const boost::system::error_code& ec,
371 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400372 if (ec)
373 {
374 BMCWEB_LOG_DEBUG("DBUS response error for "
375 "Location");
376 messages::internalError(asyncResp->res);
377 return;
378 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500379
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400380 asyncResp->res
381 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
382 property;
383 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500384}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700385// avoid name collision systems.hpp
Patrick Williams504af5a2025-02-03 14:29:03 -0500386inline void managerGetLastResetTime(
387 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700388{
Ed Tanous62598e32023-07-17 17:06:25 -0700389 BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time");
Ed Tanous52cc1122020-07-18 13:51:21 -0700390
Ed Tanousdeae6a72024-11-11 21:58:57 -0800391 dbus::utility::getProperty<uint64_t>(
392 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
393 "xyz.openbmc_project.State.BMC", "LastRebootTime",
Ed Tanousac106bf2023-06-07 09:24:59 -0700394 [asyncResp](const boost::system::error_code& ec,
395 const uint64_t lastResetTime) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400396 if (ec)
397 {
398 BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
399 return;
400 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700401
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400402 // LastRebootTime is epoch time, in milliseconds
403 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
404 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700405
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400406 // Convert to ISO 8601 standard
407 asyncResp->res.jsonValue["LastResetTime"] =
408 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
409 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700410}
411
412/**
413 * @brief Set the running firmware image
414 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700415 * @param[i,o] asyncResp - Async response object
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700416 * @param[i] runningFirmwareTarget - Image to make the running image
417 *
418 * @return void
419 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500420inline void setActiveFirmwareImage(
421 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
422 const std::string& runningFirmwareTarget)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700423{
424 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
425 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
426 if (idPos == std::string::npos)
427 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700428 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700429 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700430 BMCWEB_LOG_DEBUG("Can't parse firmware ID!");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700431 return;
432 }
433 idPos++;
434 if (idPos >= runningFirmwareTarget.size())
435 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700436 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700437 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700438 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700439 return;
440 }
441 std::string firmwareId = runningFirmwareTarget.substr(idPos);
442
443 // Make sure the image is valid before setting priority
George Liu5eb468d2023-06-20 17:03:24 +0800444 sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
445 dbus::utility::getManagedObjects(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700446 getBMCUpdateServiceName(), objPath,
George Liu5eb468d2023-06-20 17:03:24 +0800447 [asyncResp, firmwareId, runningFirmwareTarget](
448 const boost::system::error_code& ec,
449 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400450 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700451 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400452 BMCWEB_LOG_DEBUG("D-Bus response error getting objects.");
Ed Tanousac106bf2023-06-07 09:24:59 -0700453 messages::internalError(asyncResp->res);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700454 return;
455 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400456
457 if (subtree.empty())
458 {
459 BMCWEB_LOG_DEBUG("Can't find image!");
460 messages::internalError(asyncResp->res);
461 return;
462 }
463
464 bool foundImage = false;
465 for (const auto& object : subtree)
466 {
467 const std::string& path =
468 static_cast<const std::string&>(object.first);
469 std::size_t idPos2 = path.rfind('/');
470
471 if (idPos2 == std::string::npos)
472 {
473 continue;
474 }
475
476 idPos2++;
477 if (idPos2 >= path.size())
478 {
479 continue;
480 }
481
482 if (path.substr(idPos2) == firmwareId)
483 {
484 foundImage = true;
485 break;
486 }
487 }
488
489 if (!foundImage)
490 {
491 messages::propertyValueNotInList(
492 asyncResp->res, runningFirmwareTarget, "@odata.id");
493 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
494 return;
495 }
496
497 BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.",
498 firmwareId);
499
500 // Only support Immediate
501 // An addition could be a Redfish Setting like
502 // ActiveSoftwareImageApplyTime and support OnReset
503 sdbusplus::asio::setProperty(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700504 *crow::connections::systemBus, getBMCUpdateServiceName(),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400505 "/xyz/openbmc_project/software/" + firmwareId,
506 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
507 static_cast<uint8_t>(0),
508 [asyncResp](const boost::system::error_code& ec2) {
509 if (ec2)
510 {
511 BMCWEB_LOG_DEBUG("D-Bus response error setting.");
512 messages::internalError(asyncResp->res);
513 return;
514 }
515 doBMCGracefulRestart(asyncResp);
516 });
George Liu5eb468d2023-06-20 17:03:24 +0800517 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700518}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700519
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400520inline void afterSetDateTime(
521 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
522 const boost::system::error_code& ec, const sdbusplus::message_t& msg)
Ed Tanousc51afd52024-03-07 10:13:14 -0800523{
524 if (ec)
525 {
526 BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}",
527 ec);
528 const sd_bus_error* dbusError = msg.get_error();
529 if (dbusError != nullptr)
530 {
531 std::string_view errorName(dbusError->name);
532 if (errorName ==
533 "org.freedesktop.timedate1.AutomaticTimeSyncEnabled")
534 {
535 BMCWEB_LOG_DEBUG("Setting conflict");
536 messages::propertyValueConflict(
537 asyncResp->res, "DateTime",
538 "Managers/NetworkProtocol/NTPProcotolEnabled");
539 return;
540 }
541 }
542 messages::internalError(asyncResp->res);
543 return;
544 }
545 asyncResp->res.result(boost::beast::http::status::no_content);
546}
547
548inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
549 const std::string& datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700550{
Ed Tanous62598e32023-07-17 17:06:25 -0700551 BMCWEB_LOG_DEBUG("Set date time: {}", datetime);
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100552
Ed Tanousc2e32002023-01-07 22:05:08 -0800553 std::optional<redfish::time_utils::usSinceEpoch> us =
554 redfish::time_utils::dateStringToEpoch(datetime);
555 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700556 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700557 messages::propertyValueFormatError(asyncResp->res, datetime,
558 "DateTime");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700559 return;
560 }
Ed Tanousc51afd52024-03-07 10:13:14 -0800561 // Set the absolute datetime
562 bool relative = false;
563 bool interactive = false;
564 crow::connections::systemBus->async_method_call(
565 [asyncResp](const boost::system::error_code& ec,
566 const sdbusplus::message_t& msg) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400567 afterSetDateTime(asyncResp, ec, msg);
568 },
Ed Tanousc51afd52024-03-07 10:13:14 -0800569 "org.freedesktop.timedate1", "/org/freedesktop/timedate1",
570 "org.freedesktop.timedate1", "SetTime", us->count(), relative,
571 interactive);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700572}
573
Patrick Williams504af5a2025-02-03 14:29:03 -0500574inline void checkForQuiesced(
575 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous75815e52022-10-05 17:21:13 -0700576{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800577 dbus::utility::getProperty<std::string>(
578 "org.freedesktop.systemd1",
Ed Tanous75815e52022-10-05 17:21:13 -0700579 "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
580 "org.freedesktop.systemd1.Unit", "ActiveState",
581 [asyncResp](const boost::system::error_code& ec,
582 const std::string& val) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400583 if (!ec)
Ed Tanous75815e52022-10-05 17:21:13 -0700584 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400585 if (val == "active")
586 {
587 asyncResp->res.jsonValue["Status"]["Health"] =
588 resource::Health::Critical;
589 asyncResp->res.jsonValue["Status"]["State"] =
590 resource::State::Quiesced;
591 return;
592 }
Ed Tanous75815e52022-10-05 17:21:13 -0700593 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400594 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
595 asyncResp->res.jsonValue["Status"]["State"] =
596 resource::State::Enabled;
597 });
Ed Tanous75815e52022-10-05 17:21:13 -0700598}
599
Janet Adkinse2cdf062025-06-18 11:17:35 -0500600inline void getPhysicalAssets(
601 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
602 const boost::system::error_code& ec,
603 const dbus::utility::DBusPropertiesMap& propertiesList)
604{
605 if (ec)
606 {
607 BMCWEB_LOG_DEBUG("Can't get bmc asset!");
608 return;
609 }
610
611 const std::string* partNumber = nullptr;
612 const std::string* serialNumber = nullptr;
613 const std::string* manufacturer = nullptr;
614 const std::string* model = nullptr;
615 const std::string* sparePartNumber = nullptr;
616
617 const bool success = sdbusplus::unpackPropertiesNoThrow(
618 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
619 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
620 "Model", model, "SparePartNumber", sparePartNumber);
621
622 if (!success)
623 {
624 messages::internalError(asyncResp->res);
625 return;
626 }
627
628 if (partNumber != nullptr)
629 {
630 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
631 }
632
633 if (serialNumber != nullptr)
634 {
635 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
636 }
637
638 if (manufacturer != nullptr)
639 {
640 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
641 }
642
643 if (model != nullptr)
644 {
645 asyncResp->res.jsonValue["Model"] = *model;
646 }
647
648 if (sparePartNumber != nullptr)
649 {
650 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
651 }
652}
653
654inline void getManagerData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
655 const std::string& managerPath,
656 const dbus::utility::MapperServiceMap& serviceMap)
657{
658 if (managerPath.empty() || serviceMap.size() != 1)
659 {
660 BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!");
661 messages::internalError(asyncResp->res);
662 return;
663 }
664
665 for (const auto& [connectionName, interfaces] : serviceMap)
666 {
667 for (const auto& interfaceName : interfaces)
668 {
669 if (interfaceName ==
670 "xyz.openbmc_project.Inventory.Decorator.Asset")
671 {
672 dbus::utility::getAllProperties(
673 *crow::connections::systemBus, connectionName, managerPath,
674 "xyz.openbmc_project.Inventory.Decorator.Asset",
675 std::bind_front(getPhysicalAssets, asyncResp));
676 }
677 else if (interfaceName ==
678 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
679 {
680 getLocation(asyncResp, connectionName, managerPath);
681 }
George Liu79f3b6a2021-05-13 18:08:44 +0800682 else if (interfaceName ==
683 "xyz.openbmc_project.Association.Definitions")
684 {
685 getLocationIndicatorActive(asyncResp, managerPath);
686 }
Janet Adkinse2cdf062025-06-18 11:17:35 -0500687 }
688 }
689}
690
691inline void afterGetManagerObject(
692 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
693 const boost::system::error_code& ec,
694 const dbus::utility::MapperGetSubTreeResponse& subtree,
695 const std::function<
696 void(const std::string& managerPath,
697 const dbus::utility::MapperServiceMap& serviceMap)>& callback)
698{
699 if (ec)
700 {
701 BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec);
702 return;
703 }
704 if (subtree.empty())
705 {
706 BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!");
707 return;
708 }
709 // Assume only 1 bmc D-Bus object
710 // Throw an error if there is more than 1
711 if (subtree.size() > 1)
712 {
713 BMCWEB_LOG_ERROR("Found more than 1 bmc D-Bus object!");
714 messages::internalError(asyncResp->res);
715 return;
716 }
717
718 callback(subtree[0].first, subtree[0].second);
719}
720
721inline void getManagerObject(
722 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
723 const std::string& /* managerId */,
724 std::function<void(const std::string& managerPath,
725 const dbus::utility::MapperServiceMap& serviceMap)>&&
726 callback)
727{
728 constexpr std::array<std::string_view, 1> interfaces = {
729 "xyz.openbmc_project.Inventory.Item.Bmc"};
730 dbus::utility::getSubTree(
731 "/xyz/openbmc_project/inventory", 0, interfaces,
732 [asyncResp, callback{std::move(callback)}](
733 const boost::system::error_code& ec,
734 const dbus::utility::MapperGetSubTreeResponse& subtree) {
735 afterGetManagerObject(asyncResp, ec, subtree, callback);
736 });
737}
738
Myung Bae96153bd2025-08-20 15:20:49 -0400739inline void handleManagerGet(
740 App& app, const crow::Request& req,
741 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
742 const std::string& managerId)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700743{
Myung Bae96153bd2025-08-20 15:20:49 -0400744 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
745 {
746 return;
747 }
748
749 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
750 {
751 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
752 return;
753 }
754
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700755 std::string uuid = persistent_data::getConfig().systemUuid;
756
Myung Bae96153bd2025-08-20 15:20:49 -0400757 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
758 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
759 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_15_0.Manager";
760 asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME;
761 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
762 asyncResp->res.jsonValue["Description"] = "Baseboard Management Controller";
763 asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On;
764
765 asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC;
766 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
767 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
768 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
769
770 asyncResp->res.jsonValue["LogServices"]["@odata.id"] = boost::urls::format(
771 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
772 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
773 boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol",
774 BMCWEB_REDFISH_MANAGER_URI_NAME);
775 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
776 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces",
777 BMCWEB_REDFISH_MANAGER_URI_NAME);
778
779 manager_utils::getServiceIdentification(asyncResp, false);
780
781 if constexpr (BMCWEB_VM_NBDPROXY)
782 {
783 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
784 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia",
785 BMCWEB_REDFISH_MANAGER_URI_NAME);
786 }
787
788 // Manager.Reset (an action) can be many values, OpenBMC only
789 // supports BMC reboot.
790 nlohmann::json& managerReset =
791 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
792 managerReset["target"] =
793 boost::urls::format("/redfish/v1/Managers/{}/Actions/Manager.Reset",
794 BMCWEB_REDFISH_MANAGER_URI_NAME);
795 managerReset["@Redfish.ActionInfo"] =
796 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
797 BMCWEB_REDFISH_MANAGER_URI_NAME);
798
799 // ResetToDefaults (Factory Reset) has values like
800 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
801 // on OpenBMC
802 nlohmann::json& resetToDefaults =
803 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
804 resetToDefaults["target"] = boost::urls::format(
805 "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults",
806 BMCWEB_REDFISH_MANAGER_URI_NAME);
807 resetToDefaults["ResetType@Redfish.AllowableValues"] =
808 nlohmann::json::array_t({"ResetAll"});
809
810 std::pair<std::string, std::string> redfishDateTimeOffset =
811 redfish::time_utils::getDateTimeOffsetNow();
812
813 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
814 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
815 redfishDateTimeOffset.second;
816
817 if constexpr (BMCWEB_KVM)
818 {
819 // Fill in GraphicalConsole info
820 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
821 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
822 4;
823 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
824 nlohmann::json::array_t({"KVMIP"});
825 }
826 if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
827 {
828 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
829
830 nlohmann::json::array_t managerForServers;
831 nlohmann::json::object_t manager;
832 manager["@odata.id"] = std::format("/redfish/v1/Systems/{}",
833 BMCWEB_REDFISH_SYSTEM_URI_NAME);
834 managerForServers.emplace_back(std::move(manager));
835
836 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
837 std::move(managerForServers);
838 }
839
840 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
841 "FirmwareVersion", true);
842
843 managerGetLastResetTime(asyncResp);
844
845 // ManagerDiagnosticData is added for all BMCs.
846 nlohmann::json& managerDiagnosticData =
847 asyncResp->res.jsonValue["ManagerDiagnosticData"];
848 managerDiagnosticData["@odata.id"] =
849 boost::urls::format("/redfish/v1/Managers/{}/ManagerDiagnosticData",
850 BMCWEB_REDFISH_MANAGER_URI_NAME);
851
852 getMainChassisId(
853 asyncResp, [](const std::string& chassisId,
854 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
855 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
856 nlohmann::json::array_t managerForChassis;
857 nlohmann::json::object_t managerObj;
858 boost::urls::url chassiUrl =
859 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
860 managerObj["@odata.id"] = chassiUrl;
861 managerForChassis.emplace_back(std::move(managerObj));
862 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
863 std::move(managerForChassis);
864 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
865 chassiUrl;
866 });
867
868 dbus::utility::getProperty<double>(
869 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
870 "org.freedesktop.systemd1.Manager", "Progress",
871 [asyncResp](const boost::system::error_code& ec, double val) {
872 if (ec)
873 {
874 BMCWEB_LOG_ERROR("Error while getting progress");
875 messages::internalError(asyncResp->res);
876 return;
877 }
878 if (val < 1.0)
879 {
880 asyncResp->res.jsonValue["Status"]["Health"] =
881 resource::Health::OK;
882 asyncResp->res.jsonValue["Status"]["State"] =
883 resource::State::Starting;
884 return;
885 }
886 checkForQuiesced(asyncResp);
887 });
888
889 getManagerObject(asyncResp, managerId,
890 std::bind_front(getManagerData, asyncResp));
891
892 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
893}
894
895inline void handleManagerPatch(
896 App& app, const crow::Request& req,
897 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
898 const std::string& managerId)
899{
900 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
901 {
902 return;
903 }
904
905 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
906 {
907 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
908 return;
909 }
910
911 std::optional<std::string> activeSoftwareImageOdataId;
912 std::optional<std::string> datetime;
913 std::optional<bool> locationIndicatorActive;
914 std::optional<nlohmann::json::object_t> pidControllers;
915 std::optional<nlohmann::json::object_t> fanControllers;
916 std::optional<nlohmann::json::object_t> fanZones;
917 std::optional<nlohmann::json::object_t> stepwiseControllers;
918 std::optional<std::string> profile;
919 std::optional<std::string> serviceIdentification;
920
921 if (!json_util::readJsonPatch( //
922 req, asyncResp->res, //
923 "DateTime", datetime, //
924 "Links/ActiveSoftwareImage/@odata.id",
925 activeSoftwareImageOdataId, //
926 "LocationIndicatorActive",
927 locationIndicatorActive, //
928 "Oem/OpenBmc/Fan/FanControllers", fanControllers, //
929 "Oem/OpenBmc/Fan/FanZones", fanZones, //
930 "Oem/OpenBmc/Fan/PidControllers", pidControllers, //
931 "Oem/OpenBmc/Fan/Profile", profile, //
932 "Oem/OpenBmc/Fan/StepwiseControllers",
933 stepwiseControllers, //
934 "ServiceIdentification", serviceIdentification //
935 ))
936 {
937 return;
938 }
939
940 if (activeSoftwareImageOdataId)
941 {
942 setActiveFirmwareImage(asyncResp, *activeSoftwareImageOdataId);
943 }
944
945 if (datetime)
946 {
947 setDateTime(asyncResp, *datetime);
948 }
949
950 if (locationIndicatorActive)
951 {
952 setLocationIndicatorActiveState(asyncResp, *locationIndicatorActive,
953 managerId);
954 }
955
956 if (serviceIdentification)
957 {
958 manager_utils::setServiceIdentification(asyncResp,
959 serviceIdentification.value());
960 }
961
962 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
963}
964
965inline void handleManagerCollectionGet(
966 crow::App& app, const crow::Request& req,
967 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
968{
969 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
970 {
971 return;
972 }
973 // Collections don't include the static data added by SubRoute
974 // because it has a duplicate entry for members
975 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
976 asyncResp->res.jsonValue["@odata.type"] =
977 "#ManagerCollection.ManagerCollection";
978 asyncResp->res.jsonValue["Name"] = "Manager Collection";
979 asyncResp->res.jsonValue["Members@odata.count"] = 1;
980 nlohmann::json::array_t members;
981 nlohmann::json& bmc = members.emplace_back();
982 bmc["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
983 BMCWEB_REDFISH_MANAGER_URI_NAME);
984 asyncResp->res.jsonValue["Members"] = std::move(members);
985}
986
987inline void requestRoutesManager(App& app)
988{
Ed Tanous253f11b2024-05-16 09:38:31 -0700989 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700990 .privileges(redfish::privileges::getManager)
Myung Bae96153bd2025-08-20 15:20:49 -0400991 .methods(boost::beast::http::verb::get)(
992 std::bind_front(handleManagerGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700993
Ed Tanous253f11b2024-05-16 09:38:31 -0700994 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700995 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700996 .methods(boost::beast::http::verb::patch)(
Myung Bae96153bd2025-08-20 15:20:49 -0400997 std::bind_front(handleManagerPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700998
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700999 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07001000 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001001 .methods(boost::beast::http::verb::get)(
Myung Bae96153bd2025-08-20 15:20:49 -04001002 std::bind_front(handleManagerCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001003}
Myung Bae64acd262025-08-21 15:51:21 -04001004
1005inline void requestRoutesManagerResetAction(App& app)
1006{
1007 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/")
1008 .privileges(redfish::privileges::postManager)
1009 .methods(boost::beast::http::verb::post)(
1010 std::bind_front(handleManagerResetAction, std::ref(app)));
1011
1012 BMCWEB_ROUTE(app,
1013 "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/")
1014 .privileges(redfish::privileges::postManager)
1015 .methods(boost::beast::http::verb::post)(
1016 std::bind_front(handleManagerResetToDefaultsAction, std::ref(app)));
1017
1018 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/")
1019 .privileges(redfish::privileges::getActionInfo)
1020 .methods(boost::beast::http::verb::get)(
1021 std::bind_front(handleManagerResetActionInfo, std::ref(app)));
1022}
1023
Ed Tanous1abe55e2018-09-05 08:30:59 -07001024} // namespace redfish