blob: 5932eb9b5041e959d454bdf676f76b0db3ec11ae [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
Gunnar Mills0fa34182025-09-08 10:22:07 -050044#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>
James Feist5b4aa862018-08-16 14:07:01 -070056
Ed Tanous1abe55e2018-09-05 08:30:59 -070057namespace redfish
58{
Jennifer Leeed5befb2018-08-10 11:29:45 -070059
Gunnar Mills0fa34182025-09-08 10:22:07 -050060inline void handleSetLocationIndicatorActive(
61 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
62 bool locationIndicatorActive, const std::string& managerId,
63 const boost::system::error_code& ec,
64 const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths)
65{
66 if (ec)
67 {
68 if (ec == boost::system::errc::io_error)
69 {
70 // Not found
71 BMCWEB_LOG_WARNING("Manager {} not found", managerId);
72 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
73 return;
74 }
75 BMCWEB_LOG_ERROR("D-Bus response error {}", ec.value());
76 messages::internalError(asyncResp->res);
77 return;
78 }
79 if (subtreePaths.empty())
80 {
81 BMCWEB_LOG_WARNING("Manager {} not found", managerId);
82 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
83 return;
84 }
85 // Assume only 1 bmc D-Bus object
86 // Throw an error if there is more than 1
87 if (subtreePaths.size() != 1)
88 {
89 BMCWEB_LOG_ERROR("Found {} Bmc D-Bus paths", subtreePaths.size());
90 messages::internalError(asyncResp->res);
91 return;
92 }
93
94 setLocationIndicatorActive(asyncResp, subtreePaths[0],
95 locationIndicatorActive);
96}
97
George Liu79f3b6a2021-05-13 18:08:44 +080098/**
99 * Set the locationIndicatorActive.
100 *
101 * @param[in,out] asyncResp Async HTTP response.
102 * @param[in] locationIndicatorActive Value of the property
103 */
104inline void setLocationIndicatorActiveState(
105 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
106 bool locationIndicatorActive, const std::string& managerId)
107{
Gunnar Mills0fa34182025-09-08 10:22:07 -0500108 // GetSubTree on all interfaces which provide info about a Manager
109 constexpr std::array<std::string_view, 1> interfaces = {
110 "xyz.openbmc_project.Inventory.Item.Bmc"};
111 dbus::utility::getSubTreePaths(
112 "/xyz/openbmc_project/inventory", 0, interfaces,
113 std::bind_front(handleSetLocationIndicatorActive, asyncResp,
114 locationIndicatorActive, managerId));
George Liu79f3b6a2021-05-13 18:08:44 +0800115}
116
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700117inline std::string getBMCUpdateServiceName()
118{
119 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
120 {
121 return "xyz.openbmc_project.Software.Manager";
122 }
123 return "xyz.openbmc_project.Software.BMC.Updater";
124}
125
126inline std::string getBMCUpdateServicePath()
127{
128 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
129 {
130 return "/xyz/openbmc_project/software/bmc";
131 }
132 return "/xyz/openbmc_project/software";
133}
134
Jennifer Leeed5befb2018-08-10 11:29:45 -0700135/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500136 * Function reboots the BMC.
137 *
138 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -0700139 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500140inline void doBMCGracefulRestart(
141 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500142{
143 const char* processName = "xyz.openbmc_project.State.BMC";
144 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
145 const char* interfaceName = "xyz.openbmc_project.State.BMC";
146 const std::string& propertyValue =
147 "xyz.openbmc_project.State.BMC.Transition.Reboot";
148 const char* destProperty = "RequestedBMCTransition";
149
150 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +0800151 sdbusplus::asio::setProperty(
152 *crow::connections::systemBus, processName, objectPath, interfaceName,
153 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800154 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400155 // Use "Set" method to set the property value.
156 if (ec)
157 {
158 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
159 messages::internalError(asyncResp->res);
160 return;
161 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500162
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400163 messages::success(asyncResp->res);
164 });
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500165}
166
Patrick Williams504af5a2025-02-03 14:29:03 -0500167inline void doBMCForceRestart(
168 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000169{
170 const char* processName = "xyz.openbmc_project.State.BMC";
171 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
172 const char* interfaceName = "xyz.openbmc_project.State.BMC";
173 const std::string& propertyValue =
174 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
175 const char* destProperty = "RequestedBMCTransition";
176
177 // Create the D-Bus variant for D-Bus call.
George Liu9ae226f2023-06-21 17:56:46 +0800178 sdbusplus::asio::setProperty(
179 *crow::connections::systemBus, processName, objectPath, interfaceName,
180 destProperty, propertyValue,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800181 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400182 // Use "Set" method to set the property value.
183 if (ec)
184 {
185 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
186 messages::internalError(asyncResp->res);
187 return;
188 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000189
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400190 messages::success(asyncResp->res);
191 });
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000192}
193
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500194/**
Myung Bae64acd262025-08-21 15:51:21 -0400195 * ManagerResetAction handles POST method request.
196 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
197 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500198 */
Myung Bae64acd262025-08-21 15:51:21 -0400199
200inline void handleManagerResetAction(
201 crow::App& app, const crow::Request& req,
202 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
203 const std::string& managerId)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700204{
Myung Bae64acd262025-08-21 15:51:21 -0400205 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
206 {
207 return;
208 }
209 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
210 {
211 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
212 return;
213 }
Jennifer Leeed5befb2018-08-10 11:29:45 -0700214
Myung Bae64acd262025-08-21 15:51:21 -0400215 BMCWEB_LOG_DEBUG("Post Manager Reset.");
Ed Tanous253f11b2024-05-16 09:38:31 -0700216
Myung Bae64acd262025-08-21 15:51:21 -0400217 std::string resetType;
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500218
Myung Bae64acd262025-08-21 15:51:21 -0400219 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
220 {
221 return;
222 }
Jennifer Leeed5befb2018-08-10 11:29:45 -0700223
Myung Bae64acd262025-08-21 15:51:21 -0400224 if (resetType == "GracefulRestart")
225 {
226 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
227 doBMCGracefulRestart(asyncResp);
228 return;
229 }
230 if (resetType == "ForceRestart")
231 {
232 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
233 doBMCForceRestart(asyncResp);
234 return;
235 }
236 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
237 messages::actionParameterNotSupported(asyncResp->res, resetType,
238 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700239}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700240
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500241/**
Myung Bae64acd262025-08-21 15:51:21 -0400242 * Function handles ResetToDefaults POST method request.
243 *
244 * Analyzes POST body message and factory resets BMC by calling
245 * BMC code updater factory reset followed by a BMC reboot.
246 *
247 * BMC code updater factory reset wipes the whole BMC read-write
248 * filesystem which includes things like the network settings.
249 *
250 * OpenBMC only supports ResetType "ResetAll".
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500251 */
Myung Bae64acd262025-08-21 15:51:21 -0400252
253inline void handleManagerResetToDefaultsAction(
254 crow::App& app, const crow::Request& req,
255 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
256 const std::string& managerId)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500257{
Myung Bae64acd262025-08-21 15:51:21 -0400258 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
259 {
260 return;
261 }
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500262
Myung Bae64acd262025-08-21 15:51:21 -0400263 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
264 {
265 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
266 return;
267 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400268
Myung Bae64acd262025-08-21 15:51:21 -0400269 BMCWEB_LOG_DEBUG("Post ResetToDefaults.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400270
Myung Bae64acd262025-08-21 15:51:21 -0400271 std::optional<std::string> resetType;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400272
Myung Bae64acd262025-08-21 15:51:21 -0400273 if (!json_util::readJsonAction( //
274 req, asyncResp->res, //
275 "ResetType", resetType //
276 ))
277 {
278 BMCWEB_LOG_DEBUG("Missing property ResetType.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400279
Myung Bae64acd262025-08-21 15:51:21 -0400280 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
281 "ResetType");
282 return;
283 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400284
Myung Bae64acd262025-08-21 15:51:21 -0400285 if (resetType.value_or("") != "ResetAll")
286 {
287 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
288 resetType.value_or(""));
289 messages::actionParameterNotSupported(
290 asyncResp->res, resetType.value_or(""), "ResetType");
291 return;
292 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400293
Myung Bae64acd262025-08-21 15:51:21 -0400294 crow::connections::systemBus->async_method_call(
295 [asyncResp](const boost::system::error_code& ec) {
296 if (ec)
297 {
298 BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec);
299 messages::internalError(asyncResp->res);
300 return;
301 }
302 // Factory Reset doesn't actually happen until a reboot
303 // Can't erase what the BMC is running on
304 doBMCGracefulRestart(asyncResp);
305 },
306 getBMCUpdateServiceName(), getBMCUpdateServicePath(),
307 "xyz.openbmc_project.Common.FactoryReset", "Reset");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700308}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500309
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530310/**
311 * ManagerResetActionInfo derived class for delivering Manager
312 * ResetType AllowableValues using ResetInfo schema.
313 */
Myung Bae64acd262025-08-21 15:51:21 -0400314inline void handleManagerResetActionInfo(
315 crow::App& app, const crow::Request& req,
316 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
317 const std::string& managerId)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530318{
Myung Bae64acd262025-08-21 15:51:21 -0400319 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
320 {
321 return;
322 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700323
Myung Bae64acd262025-08-21 15:51:21 -0400324 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
325 {
326 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
327 return;
328 }
Ed Tanous14766872022-03-15 10:44:42 -0700329
Myung Bae64acd262025-08-21 15:51:21 -0400330 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
331 asyncResp->res.jsonValue["@odata.id"] =
332 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
333 BMCWEB_REDFISH_MANAGER_URI_NAME);
334 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
335 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
336 nlohmann::json::object_t parameter;
337 parameter["Name"] = "ResetType";
338 parameter["Required"] = true;
339 parameter["DataType"] = action_info::ParameterTypes::String;
Ed Tanous253f11b2024-05-16 09:38:31 -0700340
Myung Bae64acd262025-08-21 15:51:21 -0400341 nlohmann::json::array_t allowableValues;
342 allowableValues.emplace_back("GracefulRestart");
343 allowableValues.emplace_back("ForceRestart");
344 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700345
Myung Bae64acd262025-08-21 15:51:21 -0400346 nlohmann::json::array_t parameters;
347 parameters.emplace_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700348
Myung Bae64acd262025-08-21 15:51:21 -0400349 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700350}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530351
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500352/**
353 * @brief Retrieves BMC manager location data over DBus
354 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700355 * @param[in] asyncResp Shared pointer for completing asynchronous calls
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500356 * @param[in] connectionName - service name
357 * @param[in] path - object path
358 * @return none
359 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700360inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500361 const std::string& connectionName,
362 const std::string& path)
363{
Ed Tanous62598e32023-07-17 17:06:25 -0700364 BMCWEB_LOG_DEBUG("Get BMC manager Location data.");
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500365
Ed Tanousdeae6a72024-11-11 21:58:57 -0800366 dbus::utility::getProperty<std::string>(
367 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700368 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700369 [asyncResp](const boost::system::error_code& ec,
370 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400371 if (ec)
372 {
373 BMCWEB_LOG_DEBUG("DBUS response error for "
374 "Location");
375 messages::internalError(asyncResp->res);
376 return;
377 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500378
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400379 asyncResp->res
380 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
381 property;
382 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500383}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700384// avoid name collision systems.hpp
Patrick Williams504af5a2025-02-03 14:29:03 -0500385inline void managerGetLastResetTime(
386 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700387{
Ed Tanous62598e32023-07-17 17:06:25 -0700388 BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time");
Ed Tanous52cc1122020-07-18 13:51:21 -0700389
Ed Tanousdeae6a72024-11-11 21:58:57 -0800390 dbus::utility::getProperty<uint64_t>(
391 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
392 "xyz.openbmc_project.State.BMC", "LastRebootTime",
Ed Tanousac106bf2023-06-07 09:24:59 -0700393 [asyncResp](const boost::system::error_code& ec,
394 const uint64_t lastResetTime) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400395 if (ec)
396 {
397 BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
398 return;
399 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700400
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400401 // LastRebootTime is epoch time, in milliseconds
402 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
403 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700404
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400405 // Convert to ISO 8601 standard
406 asyncResp->res.jsonValue["LastResetTime"] =
407 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
408 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700409}
410
411/**
412 * @brief Set the running firmware image
413 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700414 * @param[i,o] asyncResp - Async response object
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700415 * @param[i] runningFirmwareTarget - Image to make the running image
416 *
417 * @return void
418 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500419inline void setActiveFirmwareImage(
420 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
421 const std::string& runningFirmwareTarget)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700422{
423 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
424 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
425 if (idPos == std::string::npos)
426 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700427 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700428 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700429 BMCWEB_LOG_DEBUG("Can't parse firmware ID!");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700430 return;
431 }
432 idPos++;
433 if (idPos >= runningFirmwareTarget.size())
434 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700435 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700436 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700437 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700438 return;
439 }
440 std::string firmwareId = runningFirmwareTarget.substr(idPos);
441
442 // Make sure the image is valid before setting priority
George Liu5eb468d2023-06-20 17:03:24 +0800443 sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
444 dbus::utility::getManagedObjects(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700445 getBMCUpdateServiceName(), objPath,
George Liu5eb468d2023-06-20 17:03:24 +0800446 [asyncResp, firmwareId, runningFirmwareTarget](
447 const boost::system::error_code& ec,
448 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400449 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700450 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400451 BMCWEB_LOG_DEBUG("D-Bus response error getting objects.");
Ed Tanousac106bf2023-06-07 09:24:59 -0700452 messages::internalError(asyncResp->res);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700453 return;
454 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400455
456 if (subtree.empty())
457 {
458 BMCWEB_LOG_DEBUG("Can't find image!");
459 messages::internalError(asyncResp->res);
460 return;
461 }
462
463 bool foundImage = false;
464 for (const auto& object : subtree)
465 {
466 const std::string& path =
467 static_cast<const std::string&>(object.first);
468 std::size_t idPos2 = path.rfind('/');
469
470 if (idPos2 == std::string::npos)
471 {
472 continue;
473 }
474
475 idPos2++;
476 if (idPos2 >= path.size())
477 {
478 continue;
479 }
480
481 if (path.substr(idPos2) == firmwareId)
482 {
483 foundImage = true;
484 break;
485 }
486 }
487
488 if (!foundImage)
489 {
490 messages::propertyValueNotInList(
491 asyncResp->res, runningFirmwareTarget, "@odata.id");
492 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
493 return;
494 }
495
496 BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.",
497 firmwareId);
498
499 // Only support Immediate
500 // An addition could be a Redfish Setting like
501 // ActiveSoftwareImageApplyTime and support OnReset
502 sdbusplus::asio::setProperty(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700503 *crow::connections::systemBus, getBMCUpdateServiceName(),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400504 "/xyz/openbmc_project/software/" + firmwareId,
505 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
506 static_cast<uint8_t>(0),
507 [asyncResp](const boost::system::error_code& ec2) {
508 if (ec2)
509 {
510 BMCWEB_LOG_DEBUG("D-Bus response error setting.");
511 messages::internalError(asyncResp->res);
512 return;
513 }
514 doBMCGracefulRestart(asyncResp);
515 });
George Liu5eb468d2023-06-20 17:03:24 +0800516 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700517}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700518
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400519inline void afterSetDateTime(
520 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
521 const boost::system::error_code& ec, const sdbusplus::message_t& msg)
Ed Tanousc51afd52024-03-07 10:13:14 -0800522{
523 if (ec)
524 {
525 BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}",
526 ec);
527 const sd_bus_error* dbusError = msg.get_error();
528 if (dbusError != nullptr)
529 {
530 std::string_view errorName(dbusError->name);
531 if (errorName ==
532 "org.freedesktop.timedate1.AutomaticTimeSyncEnabled")
533 {
534 BMCWEB_LOG_DEBUG("Setting conflict");
535 messages::propertyValueConflict(
536 asyncResp->res, "DateTime",
537 "Managers/NetworkProtocol/NTPProcotolEnabled");
538 return;
539 }
540 }
541 messages::internalError(asyncResp->res);
542 return;
543 }
544 asyncResp->res.result(boost::beast::http::status::no_content);
545}
546
547inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
548 const std::string& datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700549{
Ed Tanous62598e32023-07-17 17:06:25 -0700550 BMCWEB_LOG_DEBUG("Set date time: {}", datetime);
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100551
Ed Tanousc2e32002023-01-07 22:05:08 -0800552 std::optional<redfish::time_utils::usSinceEpoch> us =
553 redfish::time_utils::dateStringToEpoch(datetime);
554 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700555 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700556 messages::propertyValueFormatError(asyncResp->res, datetime,
557 "DateTime");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700558 return;
559 }
Ed Tanousc51afd52024-03-07 10:13:14 -0800560 // Set the absolute datetime
561 bool relative = false;
562 bool interactive = false;
563 crow::connections::systemBus->async_method_call(
564 [asyncResp](const boost::system::error_code& ec,
565 const sdbusplus::message_t& msg) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400566 afterSetDateTime(asyncResp, ec, msg);
567 },
Ed Tanousc51afd52024-03-07 10:13:14 -0800568 "org.freedesktop.timedate1", "/org/freedesktop/timedate1",
569 "org.freedesktop.timedate1", "SetTime", us->count(), relative,
570 interactive);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700571}
572
Patrick Williams504af5a2025-02-03 14:29:03 -0500573inline void checkForQuiesced(
574 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous75815e52022-10-05 17:21:13 -0700575{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800576 dbus::utility::getProperty<std::string>(
577 "org.freedesktop.systemd1",
Ed Tanous75815e52022-10-05 17:21:13 -0700578 "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
579 "org.freedesktop.systemd1.Unit", "ActiveState",
580 [asyncResp](const boost::system::error_code& ec,
581 const std::string& val) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400582 if (!ec)
Ed Tanous75815e52022-10-05 17:21:13 -0700583 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400584 if (val == "active")
585 {
586 asyncResp->res.jsonValue["Status"]["Health"] =
587 resource::Health::Critical;
588 asyncResp->res.jsonValue["Status"]["State"] =
589 resource::State::Quiesced;
590 return;
591 }
Ed Tanous75815e52022-10-05 17:21:13 -0700592 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400593 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
594 asyncResp->res.jsonValue["Status"]["State"] =
595 resource::State::Enabled;
596 });
Ed Tanous75815e52022-10-05 17:21:13 -0700597}
598
Janet Adkinse2cdf062025-06-18 11:17:35 -0500599inline void getPhysicalAssets(
600 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
601 const boost::system::error_code& ec,
602 const dbus::utility::DBusPropertiesMap& propertiesList)
603{
604 if (ec)
605 {
606 BMCWEB_LOG_DEBUG("Can't get bmc asset!");
607 return;
608 }
609
610 const std::string* partNumber = nullptr;
611 const std::string* serialNumber = nullptr;
612 const std::string* manufacturer = nullptr;
613 const std::string* model = nullptr;
614 const std::string* sparePartNumber = nullptr;
615
616 const bool success = sdbusplus::unpackPropertiesNoThrow(
617 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
618 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
619 "Model", model, "SparePartNumber", sparePartNumber);
620
621 if (!success)
622 {
623 messages::internalError(asyncResp->res);
624 return;
625 }
626
627 if (partNumber != nullptr)
628 {
629 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
630 }
631
632 if (serialNumber != nullptr)
633 {
634 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
635 }
636
637 if (manufacturer != nullptr)
638 {
639 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
640 }
641
642 if (model != nullptr)
643 {
644 asyncResp->res.jsonValue["Model"] = *model;
645 }
646
647 if (sparePartNumber != nullptr)
648 {
649 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
650 }
651}
652
653inline void getManagerData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
654 const std::string& managerPath,
655 const dbus::utility::MapperServiceMap& serviceMap)
656{
657 if (managerPath.empty() || serviceMap.size() != 1)
658 {
659 BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!");
660 messages::internalError(asyncResp->res);
661 return;
662 }
663
Gunnar Mills0fa34182025-09-08 10:22:07 -0500664 for (const auto& [connectionName, interfaces] : serviceMap)
665 {
666 for (const auto& interfaceName : interfaces)
667 {
668 if (interfaceName ==
669 "xyz.openbmc_project.Inventory.Decorator.Asset")
670 {
671 dbus::utility::getAllProperties(
672 *crow::connections::systemBus, connectionName, managerPath,
673 "xyz.openbmc_project.Inventory.Decorator.Asset",
674 std::bind_front(getPhysicalAssets, asyncResp));
675 }
676 else if (interfaceName ==
677 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
678 {
679 getLocation(asyncResp, connectionName, managerPath);
680 }
681 else if (interfaceName ==
682 "xyz.openbmc_project.Association.Definitions")
683 {
684 getLocationIndicatorActive(asyncResp, managerPath);
685 }
686 }
687 }
688}
689
690inline void afterGetManagerObject(
691 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
692 const boost::system::error_code& ec,
693 const dbus::utility::MapperGetSubTreeResponse& subtree,
694 const std::function<
695 void(const std::string& managerPath,
696 const dbus::utility::MapperServiceMap& serviceMap)>& callback)
697{
698 if (ec)
699 {
700 BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec);
701 return;
702 }
703 if (subtree.empty())
704 {
705 BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!");
706 return;
707 }
708 // Assume only 1 bmc D-Bus object
709 // Throw an error if there is more than 1
710 if (subtree.size() > 1)
711 {
712 BMCWEB_LOG_ERROR("Found more than 1 bmc D-Bus object!");
713 messages::internalError(asyncResp->res);
714 return;
715 }
716
717 callback(subtree[0].first, subtree[0].second);
718}
719
720inline void getManagerObject(
721 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
722 const std::string& /* managerId */,
723 std::function<void(const std::string& managerPath,
724 const dbus::utility::MapperServiceMap& serviceMap)>&&
725 callback)
726{
727 constexpr std::array<std::string_view, 1> interfaces = {
728 "xyz.openbmc_project.Inventory.Item.Bmc"};
729 dbus::utility::getSubTree(
730 "/xyz/openbmc_project/inventory", 0, interfaces,
731 [asyncResp, callback{std::move(callback)}](
732 const boost::system::error_code& ec,
733 const dbus::utility::MapperGetSubTreeResponse& subtree) {
734 afterGetManagerObject(asyncResp, ec, subtree, callback);
735 });
736}
737
738inline void handleManagerGet(
739 App& app, const crow::Request& req,
740 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
741 const std::string& managerId)
742{
743 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
744 {
745 return;
746 }
747
748 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
749 {
750 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
751 return;
752 }
753
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700754 std::string uuid = persistent_data::getConfig().systemUuid;
755
Gunnar Mills0fa34182025-09-08 10:22:07 -0500756 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
757 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400758 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_15_0.Manager";
Gunnar Mills0fa34182025-09-08 10:22:07 -0500759 asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME;
Myung Bae96153bd2025-08-20 15:20:49 -0400760 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
761 asyncResp->res.jsonValue["Description"] = "Baseboard Management Controller";
762 asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On;
763
764 asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC;
765 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
766 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
767 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
768
Gunnar Mills0fa34182025-09-08 10:22:07 -0500769 asyncResp->res.jsonValue["LogServices"]["@odata.id"] = boost::urls::format(
770 "/redfish/v1/Managers/{}/LogServices", BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400771 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
772 boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol",
Gunnar Mills0fa34182025-09-08 10:22:07 -0500773 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400774 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
775 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces",
Gunnar Mills0fa34182025-09-08 10:22:07 -0500776 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400777
778 manager_utils::getServiceIdentification(asyncResp, false);
779
780 if constexpr (BMCWEB_VM_NBDPROXY)
781 {
782 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
783 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia",
Gunnar Mills0fa34182025-09-08 10:22:07 -0500784 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400785 }
786
787 // Manager.Reset (an action) can be many values, OpenBMC only
788 // supports BMC reboot.
789 nlohmann::json& managerReset =
790 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
Gunnar Mills0fa34182025-09-08 10:22:07 -0500791 managerReset["target"] =
792 boost::urls::format("/redfish/v1/Managers/{}/Actions/Manager.Reset",
793 BMCWEB_REDFISH_MANAGER_URI_NAME);
794 managerReset["@Redfish.ActionInfo"] =
795 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
796 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400797
798 // ResetToDefaults (Factory Reset) has values like
799 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
800 // on OpenBMC
801 nlohmann::json& resetToDefaults =
802 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
803 resetToDefaults["target"] = boost::urls::format(
Gunnar Mills0fa34182025-09-08 10:22:07 -0500804 "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults",
805 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400806 resetToDefaults["ResetType@Redfish.AllowableValues"] =
807 nlohmann::json::array_t({"ResetAll"});
808
809 std::pair<std::string, std::string> redfishDateTimeOffset =
810 redfish::time_utils::getDateTimeOffsetNow();
811
812 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
813 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
814 redfishDateTimeOffset.second;
815
816 if constexpr (BMCWEB_KVM)
817 {
818 // Fill in GraphicalConsole info
819 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
820 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
821 4;
822 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
823 nlohmann::json::array_t({"KVMIP"});
824 }
825 if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
826 {
827 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
828
829 nlohmann::json::array_t managerForServers;
830 nlohmann::json::object_t manager;
831 manager["@odata.id"] = std::format("/redfish/v1/Systems/{}",
832 BMCWEB_REDFISH_SYSTEM_URI_NAME);
833 managerForServers.emplace_back(std::move(manager));
834
835 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
836 std::move(managerForServers);
837 }
838
839 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
840 "FirmwareVersion", true);
841
842 managerGetLastResetTime(asyncResp);
843
844 // ManagerDiagnosticData is added for all BMCs.
845 nlohmann::json& managerDiagnosticData =
846 asyncResp->res.jsonValue["ManagerDiagnosticData"];
Gunnar Mills0fa34182025-09-08 10:22:07 -0500847 managerDiagnosticData["@odata.id"] =
848 boost::urls::format("/redfish/v1/Managers/{}/ManagerDiagnosticData",
849 BMCWEB_REDFISH_MANAGER_URI_NAME);
Myung Bae96153bd2025-08-20 15:20:49 -0400850
851 getMainChassisId(
852 asyncResp, [](const std::string& chassisId,
853 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
854 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
855 nlohmann::json::array_t managerForChassis;
856 nlohmann::json::object_t managerObj;
857 boost::urls::url chassiUrl =
858 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
859 managerObj["@odata.id"] = chassiUrl;
860 managerForChassis.emplace_back(std::move(managerObj));
861 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
862 std::move(managerForChassis);
863 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
864 chassiUrl;
865 });
866
867 dbus::utility::getProperty<double>(
868 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
869 "org.freedesktop.systemd1.Manager", "Progress",
870 [asyncResp](const boost::system::error_code& ec, double val) {
871 if (ec)
872 {
873 BMCWEB_LOG_ERROR("Error while getting progress");
874 messages::internalError(asyncResp->res);
875 return;
876 }
877 if (val < 1.0)
878 {
879 asyncResp->res.jsonValue["Status"]["Health"] =
880 resource::Health::OK;
881 asyncResp->res.jsonValue["Status"]["State"] =
882 resource::State::Starting;
883 return;
884 }
885 checkForQuiesced(asyncResp);
886 });
887
Gunnar Mills0fa34182025-09-08 10:22:07 -0500888 getManagerObject(asyncResp, managerId,
889 std::bind_front(getManagerData, asyncResp));
Myung Bae96153bd2025-08-20 15:20:49 -0400890
891 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
892}
893
894inline void handleManagerPatch(
895 App& app, const crow::Request& req,
896 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
897 const std::string& managerId)
898{
899 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
900 {
901 return;
902 }
903
904 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
905 {
906 messages::resourceNotFound(asyncResp->res, "Manager", managerId);
907 return;
908 }
909
910 std::optional<std::string> activeSoftwareImageOdataId;
911 std::optional<std::string> datetime;
912 std::optional<bool> locationIndicatorActive;
913 std::optional<nlohmann::json::object_t> pidControllers;
914 std::optional<nlohmann::json::object_t> fanControllers;
915 std::optional<nlohmann::json::object_t> fanZones;
916 std::optional<nlohmann::json::object_t> stepwiseControllers;
917 std::optional<std::string> profile;
918 std::optional<std::string> serviceIdentification;
919
920 if (!json_util::readJsonPatch( //
921 req, asyncResp->res, //
922 "DateTime", datetime, //
923 "Links/ActiveSoftwareImage/@odata.id",
924 activeSoftwareImageOdataId, //
925 "LocationIndicatorActive",
926 locationIndicatorActive, //
927 "Oem/OpenBmc/Fan/FanControllers", fanControllers, //
928 "Oem/OpenBmc/Fan/FanZones", fanZones, //
929 "Oem/OpenBmc/Fan/PidControllers", pidControllers, //
930 "Oem/OpenBmc/Fan/Profile", profile, //
931 "Oem/OpenBmc/Fan/StepwiseControllers",
932 stepwiseControllers, //
933 "ServiceIdentification", serviceIdentification //
934 ))
935 {
936 return;
937 }
938
939 if (activeSoftwareImageOdataId)
940 {
941 setActiveFirmwareImage(asyncResp, *activeSoftwareImageOdataId);
942 }
943
944 if (datetime)
945 {
946 setDateTime(asyncResp, *datetime);
947 }
948
949 if (locationIndicatorActive)
950 {
951 setLocationIndicatorActiveState(asyncResp, *locationIndicatorActive,
952 managerId);
953 }
954
955 if (serviceIdentification)
956 {
957 manager_utils::setServiceIdentification(asyncResp,
958 serviceIdentification.value());
959 }
960
961 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
962}
963
964inline void handleManagerCollectionGet(
965 crow::App& app, const crow::Request& req,
966 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
967{
968 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
969 {
970 return;
971 }
972 // Collections don't include the static data added by SubRoute
973 // because it has a duplicate entry for members
974 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
975 asyncResp->res.jsonValue["@odata.type"] =
976 "#ManagerCollection.ManagerCollection";
977 asyncResp->res.jsonValue["Name"] = "Manager Collection";
978 asyncResp->res.jsonValue["Members@odata.count"] = 1;
979 nlohmann::json::array_t members;
980 nlohmann::json& bmc = members.emplace_back();
981 bmc["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
982 BMCWEB_REDFISH_MANAGER_URI_NAME);
983 asyncResp->res.jsonValue["Members"] = std::move(members);
984}
985
986inline void requestRoutesManager(App& app)
987{
Ed Tanous253f11b2024-05-16 09:38:31 -0700988 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700989 .privileges(redfish::privileges::getManager)
Myung Bae96153bd2025-08-20 15:20:49 -0400990 .methods(boost::beast::http::verb::get)(
991 std::bind_front(handleManagerGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700992
Ed Tanous253f11b2024-05-16 09:38:31 -0700993 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700994 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700995 .methods(boost::beast::http::verb::patch)(
Myung Bae96153bd2025-08-20 15:20:49 -0400996 std::bind_front(handleManagerPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700997
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700998 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -0700999 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001000 .methods(boost::beast::http::verb::get)(
Myung Bae96153bd2025-08-20 15:20:49 -04001001 std::bind_front(handleManagerCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001002}
Myung Bae64acd262025-08-21 15:51:21 -04001003
1004inline void requestRoutesManagerResetAction(App& app)
1005{
1006 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/")
1007 .privileges(redfish::privileges::postManager)
1008 .methods(boost::beast::http::verb::post)(
1009 std::bind_front(handleManagerResetAction, std::ref(app)));
1010
1011 BMCWEB_ROUTE(app,
1012 "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/")
1013 .privileges(redfish::privileges::postManager)
1014 .methods(boost::beast::http::verb::post)(
1015 std::bind_front(handleManagerResetToDefaultsAction, std::ref(app)));
1016
1017 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/")
1018 .privileges(redfish::privileges::getActionInfo)
1019 .methods(boost::beast::http::verb::get)(
1020 std::bind_front(handleManagerResetActionInfo, std::ref(app)));
1021}
1022
Ed Tanous1abe55e2018-09-05 08:30:59 -07001023} // namespace redfish