blob: 40848f400af6d8d58bd4930b2848f1d8d896f53d [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"
Sui Chena51fc2d2022-07-14 17:21:53 -070026#include "utils/sw_utils.hpp"
27#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070028#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010029
Ed Tanousd7857202025-01-28 15:32:26 -080030#include <systemd/sd-bus.h>
31
Ed Tanousd7857202025-01-28 15:32:26 -080032#include <boost/beast/http/status.hpp>
33#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080034#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070035#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080036#include <boost/url/url.hpp>
37#include <nlohmann/json.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020038#include <sdbusplus/asio/property.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080039#include <sdbusplus/message.hpp>
40#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020041#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050042
George Liue99073f2022-12-09 11:06:16 +080043#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080044#include <cstddef>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050045#include <cstdint>
Ed Tanousd7857202025-01-28 15:32:26 -080046#include <format>
47#include <functional>
48#include <map>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050049#include <memory>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030050#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070051#include <ranges>
Konstantin Aladyshev9970e932024-02-20 09:51:29 +030052#include <string>
George Liue99073f2022-12-09 11:06:16 +080053#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080054#include <utility>
Ed Tanousd7857202025-01-28 15:32:26 -080055#include <vector>
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
George Liu79f3b6a2021-05-13 18:08:44 +080060inline 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
98/**
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{
108 // 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));
115}
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/**
195 * ManagerResetAction class supports the POST method for the Reset (reboot)
196 * action.
197 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700198inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700199{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700200 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700201 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500202 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000203 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700204 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700205
Ed Tanous253f11b2024-05-16 09:38:31 -0700206 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700207 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700208 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700209 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700210 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
211 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400212 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
213 {
214 return;
215 }
216 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
217 {
218 messages::resourceNotFound(asyncResp->res, "Manager",
219 managerId);
220 return;
221 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700222
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400223 BMCWEB_LOG_DEBUG("Post Manager Reset.");
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500224
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400225 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700226
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400227 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
228 resetType))
229 {
230 return;
231 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500232
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400233 if (resetType == "GracefulRestart")
234 {
235 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
236 doBMCGracefulRestart(asyncResp);
237 return;
238 }
239 if (resetType == "ForceRestart")
240 {
241 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
242 doBMCForceRestart(asyncResp);
243 return;
244 }
245 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
246 resetType);
247 messages::actionParameterNotSupported(asyncResp->res, resetType,
248 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700249
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400250 return;
251 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700252}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700253
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500254/**
255 * ManagerResetToDefaultsAction class supports POST method for factory reset
256 * action.
257 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700258inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500259{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500260 /**
261 * Function handles ResetToDefaults POST method request.
262 *
263 * Analyzes POST body message and factory resets BMC by calling
264 * BMC code updater factory reset followed by a BMC reboot.
265 *
266 * BMC code updater factory reset wipes the whole BMC read-write
267 * filesystem which includes things like the network settings.
268 *
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500269 * OpenBMC only supports ResetType "ResetAll".
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500270 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500271
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700272 BMCWEB_ROUTE(app,
Ed Tanous253f11b2024-05-16 09:38:31 -0700273 "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700274 .privileges(redfish::privileges::postManager)
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500275 .methods(boost::beast::http::verb::post)(
276 [&app](const crow::Request& req,
277 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
278 const std::string& managerId) {
279 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
280 {
281 return;
282 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400283
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500284 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
285 {
286 messages::resourceNotFound(asyncResp->res, "Manager",
287 managerId);
288 return;
289 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400290
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500291 BMCWEB_LOG_DEBUG("Post ResetToDefaults.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400292
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500293 std::optional<std::string> resetType;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400294
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500295 if (!json_util::readJsonAction( //
296 req, asyncResp->res, //
297 "ResetType", resetType //
298 ))
299 {
300 BMCWEB_LOG_DEBUG("Missing property ResetType.");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400301
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500302 messages::actionParameterMissing(
303 asyncResp->res, "ResetToDefaults", "ResetType");
304 return;
305 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400306
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500307 if (resetType != "ResetAll")
308 {
309 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
310 *resetType);
311 messages::actionParameterNotSupported(
312 asyncResp->res, *resetType, "ResetType");
313 return;
314 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400315
Gunnar Mills18bf4bf2025-05-09 08:22:38 -0500316 crow::connections::systemBus->async_method_call(
317 [asyncResp](const boost::system::error_code& ec) {
318 if (ec)
319 {
320 BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}",
321 ec);
322 messages::internalError(asyncResp->res);
323 return;
324 }
325 // Factory Reset doesn't actually happen until a reboot
326 // Can't erase what the BMC is running on
327 doBMCGracefulRestart(asyncResp);
328 },
329 getBMCUpdateServiceName(), getBMCUpdateServicePath(),
330 "xyz.openbmc_project.Common.FactoryReset", "Reset");
331 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700332}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500333
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530334/**
335 * ManagerResetActionInfo derived class for delivering Manager
336 * ResetType AllowableValues using ResetInfo schema.
337 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700338inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530339{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530340 /**
341 * Functions triggers appropriate requests on DBus
342 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700343
Ed Tanous253f11b2024-05-16 09:38:31 -0700344 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700345 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700346 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700347 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700348 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
349 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400350 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
351 {
352 return;
353 }
Ed Tanous14766872022-03-15 10:44:42 -0700354
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400355 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
356 {
357 messages::resourceNotFound(asyncResp->res, "Manager",
358 managerId);
359 return;
360 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700361
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400362 asyncResp->res.jsonValue["@odata.type"] =
363 "#ActionInfo.v1_1_2.ActionInfo";
364 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
365 "/redfish/v1/Managers/{}/ResetActionInfo",
366 BMCWEB_REDFISH_MANAGER_URI_NAME);
367 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
368 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
369 nlohmann::json::object_t parameter;
370 parameter["Name"] = "ResetType";
371 parameter["Required"] = true;
372 parameter["DataType"] = action_info::ParameterTypes::String;
Ed Tanous14766872022-03-15 10:44:42 -0700373
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400374 nlohmann::json::array_t allowableValues;
375 allowableValues.emplace_back("GracefulRestart");
376 allowableValues.emplace_back("ForceRestart");
377 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700378
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400379 nlohmann::json::array_t parameters;
380 parameters.emplace_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700381
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400382 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
383 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700384}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530385
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500386/**
387 * @brief Retrieves BMC manager location data over DBus
388 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700389 * @param[in] asyncResp Shared pointer for completing asynchronous calls
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500390 * @param[in] connectionName - service name
391 * @param[in] path - object path
392 * @return none
393 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700394inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500395 const std::string& connectionName,
396 const std::string& path)
397{
Ed Tanous62598e32023-07-17 17:06:25 -0700398 BMCWEB_LOG_DEBUG("Get BMC manager Location data.");
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500399
Ed Tanousdeae6a72024-11-11 21:58:57 -0800400 dbus::utility::getProperty<std::string>(
401 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700402 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -0700403 [asyncResp](const boost::system::error_code& ec,
404 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400405 if (ec)
406 {
407 BMCWEB_LOG_DEBUG("DBUS response error for "
408 "Location");
409 messages::internalError(asyncResp->res);
410 return;
411 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500412
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400413 asyncResp->res
414 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
415 property;
416 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -0500417}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700418// avoid name collision systems.hpp
Patrick Williams504af5a2025-02-03 14:29:03 -0500419inline void managerGetLastResetTime(
420 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700421{
Ed Tanous62598e32023-07-17 17:06:25 -0700422 BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time");
Ed Tanous52cc1122020-07-18 13:51:21 -0700423
Ed Tanousdeae6a72024-11-11 21:58:57 -0800424 dbus::utility::getProperty<uint64_t>(
425 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
426 "xyz.openbmc_project.State.BMC", "LastRebootTime",
Ed Tanousac106bf2023-06-07 09:24:59 -0700427 [asyncResp](const boost::system::error_code& ec,
428 const uint64_t lastResetTime) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400429 if (ec)
430 {
431 BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
432 return;
433 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700434
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400435 // LastRebootTime is epoch time, in milliseconds
436 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
437 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700438
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400439 // Convert to ISO 8601 standard
440 asyncResp->res.jsonValue["LastResetTime"] =
441 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
442 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700443}
444
445/**
446 * @brief Set the running firmware image
447 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700448 * @param[i,o] asyncResp - Async response object
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700449 * @param[i] runningFirmwareTarget - Image to make the running image
450 *
451 * @return void
452 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500453inline void setActiveFirmwareImage(
454 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
455 const std::string& runningFirmwareTarget)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700456{
457 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
458 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
459 if (idPos == std::string::npos)
460 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700461 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700462 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700463 BMCWEB_LOG_DEBUG("Can't parse firmware ID!");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700464 return;
465 }
466 idPos++;
467 if (idPos >= runningFirmwareTarget.size())
468 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700469 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700470 "@odata.id");
Ed Tanous62598e32023-07-17 17:06:25 -0700471 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700472 return;
473 }
474 std::string firmwareId = runningFirmwareTarget.substr(idPos);
475
476 // Make sure the image is valid before setting priority
George Liu5eb468d2023-06-20 17:03:24 +0800477 sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
478 dbus::utility::getManagedObjects(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700479 getBMCUpdateServiceName(), objPath,
George Liu5eb468d2023-06-20 17:03:24 +0800480 [asyncResp, firmwareId, runningFirmwareTarget](
481 const boost::system::error_code& ec,
482 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400483 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700484 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400485 BMCWEB_LOG_DEBUG("D-Bus response error getting objects.");
Ed Tanousac106bf2023-06-07 09:24:59 -0700486 messages::internalError(asyncResp->res);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700487 return;
488 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400489
490 if (subtree.empty())
491 {
492 BMCWEB_LOG_DEBUG("Can't find image!");
493 messages::internalError(asyncResp->res);
494 return;
495 }
496
497 bool foundImage = false;
498 for (const auto& object : subtree)
499 {
500 const std::string& path =
501 static_cast<const std::string&>(object.first);
502 std::size_t idPos2 = path.rfind('/');
503
504 if (idPos2 == std::string::npos)
505 {
506 continue;
507 }
508
509 idPos2++;
510 if (idPos2 >= path.size())
511 {
512 continue;
513 }
514
515 if (path.substr(idPos2) == firmwareId)
516 {
517 foundImage = true;
518 break;
519 }
520 }
521
522 if (!foundImage)
523 {
524 messages::propertyValueNotInList(
525 asyncResp->res, runningFirmwareTarget, "@odata.id");
526 BMCWEB_LOG_DEBUG("Invalid firmware ID.");
527 return;
528 }
529
530 BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.",
531 firmwareId);
532
533 // Only support Immediate
534 // An addition could be a Redfish Setting like
535 // ActiveSoftwareImageApplyTime and support OnReset
536 sdbusplus::asio::setProperty(
Jagpal Singh Gilld27c31e2024-10-15 15:10:19 -0700537 *crow::connections::systemBus, getBMCUpdateServiceName(),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400538 "/xyz/openbmc_project/software/" + firmwareId,
539 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
540 static_cast<uint8_t>(0),
541 [asyncResp](const boost::system::error_code& ec2) {
542 if (ec2)
543 {
544 BMCWEB_LOG_DEBUG("D-Bus response error setting.");
545 messages::internalError(asyncResp->res);
546 return;
547 }
548 doBMCGracefulRestart(asyncResp);
549 });
George Liu5eb468d2023-06-20 17:03:24 +0800550 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700551}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700552
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400553inline void afterSetDateTime(
554 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
555 const boost::system::error_code& ec, const sdbusplus::message_t& msg)
Ed Tanousc51afd52024-03-07 10:13:14 -0800556{
557 if (ec)
558 {
559 BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}",
560 ec);
561 const sd_bus_error* dbusError = msg.get_error();
562 if (dbusError != nullptr)
563 {
564 std::string_view errorName(dbusError->name);
565 if (errorName ==
566 "org.freedesktop.timedate1.AutomaticTimeSyncEnabled")
567 {
568 BMCWEB_LOG_DEBUG("Setting conflict");
569 messages::propertyValueConflict(
570 asyncResp->res, "DateTime",
571 "Managers/NetworkProtocol/NTPProcotolEnabled");
572 return;
573 }
574 }
575 messages::internalError(asyncResp->res);
576 return;
577 }
578 asyncResp->res.result(boost::beast::http::status::no_content);
579}
580
581inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
582 const std::string& datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700583{
Ed Tanous62598e32023-07-17 17:06:25 -0700584 BMCWEB_LOG_DEBUG("Set date time: {}", datetime);
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100585
Ed Tanousc2e32002023-01-07 22:05:08 -0800586 std::optional<redfish::time_utils::usSinceEpoch> us =
587 redfish::time_utils::dateStringToEpoch(datetime);
588 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700589 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700590 messages::propertyValueFormatError(asyncResp->res, datetime,
591 "DateTime");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700592 return;
593 }
Ed Tanousc51afd52024-03-07 10:13:14 -0800594 // Set the absolute datetime
595 bool relative = false;
596 bool interactive = false;
597 crow::connections::systemBus->async_method_call(
598 [asyncResp](const boost::system::error_code& ec,
599 const sdbusplus::message_t& msg) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400600 afterSetDateTime(asyncResp, ec, msg);
601 },
Ed Tanousc51afd52024-03-07 10:13:14 -0800602 "org.freedesktop.timedate1", "/org/freedesktop/timedate1",
603 "org.freedesktop.timedate1", "SetTime", us->count(), relative,
604 interactive);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700605}
606
Patrick Williams504af5a2025-02-03 14:29:03 -0500607inline void checkForQuiesced(
608 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous75815e52022-10-05 17:21:13 -0700609{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800610 dbus::utility::getProperty<std::string>(
611 "org.freedesktop.systemd1",
Ed Tanous75815e52022-10-05 17:21:13 -0700612 "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
613 "org.freedesktop.systemd1.Unit", "ActiveState",
614 [asyncResp](const boost::system::error_code& ec,
615 const std::string& val) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400616 if (!ec)
Ed Tanous75815e52022-10-05 17:21:13 -0700617 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400618 if (val == "active")
619 {
620 asyncResp->res.jsonValue["Status"]["Health"] =
621 resource::Health::Critical;
622 asyncResp->res.jsonValue["Status"]["State"] =
623 resource::State::Quiesced;
624 return;
625 }
Ed Tanous75815e52022-10-05 17:21:13 -0700626 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400627 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
628 asyncResp->res.jsonValue["Status"]["State"] =
629 resource::State::Enabled;
630 });
Ed Tanous75815e52022-10-05 17:21:13 -0700631}
632
Janet Adkinse2cdf062025-06-18 11:17:35 -0500633inline void getPhysicalAssets(
634 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
635 const boost::system::error_code& ec,
636 const dbus::utility::DBusPropertiesMap& propertiesList)
637{
638 if (ec)
639 {
640 BMCWEB_LOG_DEBUG("Can't get bmc asset!");
641 return;
642 }
643
644 const std::string* partNumber = nullptr;
645 const std::string* serialNumber = nullptr;
646 const std::string* manufacturer = nullptr;
647 const std::string* model = nullptr;
648 const std::string* sparePartNumber = nullptr;
649
650 const bool success = sdbusplus::unpackPropertiesNoThrow(
651 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
652 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
653 "Model", model, "SparePartNumber", sparePartNumber);
654
655 if (!success)
656 {
657 messages::internalError(asyncResp->res);
658 return;
659 }
660
661 if (partNumber != nullptr)
662 {
663 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
664 }
665
666 if (serialNumber != nullptr)
667 {
668 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
669 }
670
671 if (manufacturer != nullptr)
672 {
673 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
674 }
675
676 if (model != nullptr)
677 {
678 asyncResp->res.jsonValue["Model"] = *model;
679 }
680
681 if (sparePartNumber != nullptr)
682 {
683 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
684 }
685}
686
687inline void getManagerData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
688 const std::string& managerPath,
689 const dbus::utility::MapperServiceMap& serviceMap)
690{
691 if (managerPath.empty() || serviceMap.size() != 1)
692 {
693 BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!");
694 messages::internalError(asyncResp->res);
695 return;
696 }
697
698 for (const auto& [connectionName, interfaces] : serviceMap)
699 {
700 for (const auto& interfaceName : interfaces)
701 {
702 if (interfaceName ==
703 "xyz.openbmc_project.Inventory.Decorator.Asset")
704 {
705 dbus::utility::getAllProperties(
706 *crow::connections::systemBus, connectionName, managerPath,
707 "xyz.openbmc_project.Inventory.Decorator.Asset",
708 std::bind_front(getPhysicalAssets, asyncResp));
709 }
710 else if (interfaceName ==
711 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
712 {
713 getLocation(asyncResp, connectionName, managerPath);
714 }
George Liu79f3b6a2021-05-13 18:08:44 +0800715 else if (interfaceName ==
716 "xyz.openbmc_project.Association.Definitions")
717 {
718 getLocationIndicatorActive(asyncResp, managerPath);
719 }
Janet Adkinse2cdf062025-06-18 11:17:35 -0500720 }
721 }
722}
723
724inline void afterGetManagerObject(
725 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
726 const boost::system::error_code& ec,
727 const dbus::utility::MapperGetSubTreeResponse& subtree,
728 const std::function<
729 void(const std::string& managerPath,
730 const dbus::utility::MapperServiceMap& serviceMap)>& callback)
731{
732 if (ec)
733 {
734 BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec);
735 return;
736 }
737 if (subtree.empty())
738 {
739 BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!");
740 return;
741 }
742 // Assume only 1 bmc D-Bus object
743 // Throw an error if there is more than 1
744 if (subtree.size() > 1)
745 {
746 BMCWEB_LOG_ERROR("Found more than 1 bmc D-Bus object!");
747 messages::internalError(asyncResp->res);
748 return;
749 }
750
751 callback(subtree[0].first, subtree[0].second);
752}
753
754inline void getManagerObject(
755 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
756 const std::string& /* managerId */,
757 std::function<void(const std::string& managerPath,
758 const dbus::utility::MapperServiceMap& serviceMap)>&&
759 callback)
760{
761 constexpr std::array<std::string_view, 1> interfaces = {
762 "xyz.openbmc_project.Inventory.Item.Bmc"};
763 dbus::utility::getSubTree(
764 "/xyz/openbmc_project/inventory", 0, interfaces,
765 [asyncResp, callback{std::move(callback)}](
766 const boost::system::error_code& ec,
767 const dbus::utility::MapperGetSubTreeResponse& subtree) {
768 afterGetManagerObject(asyncResp, ec, subtree, callback);
769 });
770}
771
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700772inline void requestRoutesManager(App& app)
773{
774 std::string uuid = persistent_data::getConfig().systemUuid;
775
Ed Tanous253f11b2024-05-16 09:38:31 -0700776 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700777 .privileges(redfish::privileges::getManager)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400778 .methods(
779 boost::beast::http::verb::
780 get)([&app,
781 uuid](const crow::Request& req,
782 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
783 const std::string& managerId) {
784 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
785 {
786 return;
787 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700788
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400789 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
790 {
791 messages::resourceNotFound(asyncResp->res, "Manager",
792 managerId);
793 return;
794 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700795
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400796 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
797 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
798 asyncResp->res.jsonValue["@odata.type"] =
799 "#Manager.v1_14_0.Manager";
800 asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME;
801 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
802 asyncResp->res.jsonValue["Description"] =
803 "Baseboard Management Controller";
804 asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On;
Ed Tanous14766872022-03-15 10:44:42 -0700805
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400806 asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC;
807 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
808 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
809 asyncResp->res.jsonValue["Model"] =
810 "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700811
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400812 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
813 boost::urls::format("/redfish/v1/Managers/{}/LogServices",
Ed Tanous253f11b2024-05-16 09:38:31 -0700814 BMCWEB_REDFISH_MANAGER_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400815 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
816 boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol",
817 BMCWEB_REDFISH_MANAGER_URI_NAME);
818 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
819 boost::urls::format(
820 "/redfish/v1/Managers/{}/EthernetInterfaces",
821 BMCWEB_REDFISH_MANAGER_URI_NAME);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700822
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400823 if constexpr (BMCWEB_VM_NBDPROXY)
Ed Tanous75815e52022-10-05 17:21:13 -0700824 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400825 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
826 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia",
827 BMCWEB_REDFISH_MANAGER_URI_NAME);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700828 }
829
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400830 // Manager.Reset (an action) can be many values, OpenBMC only
831 // supports BMC reboot.
832 nlohmann::json& managerReset =
833 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
834 managerReset["target"] = boost::urls::format(
835 "/redfish/v1/Managers/{}/Actions/Manager.Reset",
836 BMCWEB_REDFISH_MANAGER_URI_NAME);
837 managerReset["@Redfish.ActionInfo"] =
838 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
839 BMCWEB_REDFISH_MANAGER_URI_NAME);
840
841 // ResetToDefaults (Factory Reset) has values like
842 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
843 // on OpenBMC
844 nlohmann::json& resetToDefaults =
845 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
846 resetToDefaults["target"] = boost::urls::format(
847 "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults",
848 BMCWEB_REDFISH_MANAGER_URI_NAME);
849 resetToDefaults["ResetType@Redfish.AllowableValues"] =
850 nlohmann::json::array_t({"ResetAll"});
851
852 std::pair<std::string, std::string> redfishDateTimeOffset =
853 redfish::time_utils::getDateTimeOffsetNow();
854
855 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
856 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
857 redfishDateTimeOffset.second;
858
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400859 if constexpr (BMCWEB_KVM)
Ed Tanous002d39b2022-05-31 08:59:27 -0700860 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400861 // Fill in GraphicalConsole info
862 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] =
863 true;
864 asyncResp->res
865 .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4;
866 asyncResp->res
867 .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
868 nlohmann::json::array_t({"KVMIP"});
869 }
870 if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
871 {
872 asyncResp->res
873 .jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
874
875 nlohmann::json::array_t managerForServers;
876 nlohmann::json::object_t manager;
877 manager["@odata.id"] = std::format(
878 "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
879 managerForServers.emplace_back(std::move(manager));
880
881 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
882 std::move(managerForServers);
Ed Tanous002d39b2022-05-31 08:59:27 -0700883 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700884
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400885 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
886 "FirmwareVersion", true);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700887
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400888 managerGetLastResetTime(asyncResp);
889
890 // ManagerDiagnosticData is added for all BMCs.
891 nlohmann::json& managerDiagnosticData =
892 asyncResp->res.jsonValue["ManagerDiagnosticData"];
893 managerDiagnosticData["@odata.id"] = boost::urls::format(
894 "/redfish/v1/Managers/{}/ManagerDiagnosticData",
895 BMCWEB_REDFISH_MANAGER_URI_NAME);
896
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400897 getMainChassisId(asyncResp, [](const std::string& chassisId,
898 const std::shared_ptr<
899 bmcweb::AsyncResp>& aRsp) {
900 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] =
901 1;
902 nlohmann::json::array_t managerForChassis;
903 nlohmann::json::object_t managerObj;
904 boost::urls::url chassiUrl =
905 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
906 managerObj["@odata.id"] = chassiUrl;
907 managerForChassis.emplace_back(std::move(managerObj));
908 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
909 std::move(managerForChassis);
910 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
911 chassiUrl;
912 });
913
Ed Tanousdeae6a72024-11-11 21:58:57 -0800914 dbus::utility::getProperty<double>(
915 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
916 "org.freedesktop.systemd1.Manager", "Progress",
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400917 [asyncResp](const boost::system::error_code& ec, double val) {
918 if (ec)
919 {
920 BMCWEB_LOG_ERROR("Error while getting progress");
921 messages::internalError(asyncResp->res);
922 return;
923 }
924 if (val < 1.0)
925 {
926 asyncResp->res.jsonValue["Status"]["Health"] =
927 resource::Health::OK;
928 asyncResp->res.jsonValue["Status"]["State"] =
929 resource::State::Starting;
930 return;
931 }
932 checkForQuiesced(asyncResp);
933 });
934
Janet Adkinse2cdf062025-06-18 11:17:35 -0500935 getManagerObject(asyncResp, managerId,
936 std::bind_front(getManagerData, asyncResp));
rohitpaic1a75eb2025-01-03 19:13:36 +0530937
938 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700939 });
940
Ed Tanous253f11b2024-05-16 09:38:31 -0700941 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700942 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700943 .methods(boost::beast::http::verb::patch)(
944 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -0700945 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
946 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400947 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
948 {
949 return;
950 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700951
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400952 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
953 {
954 messages::resourceNotFound(asyncResp->res, "Manager",
955 managerId);
956 return;
957 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700958
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400959 std::optional<std::string> activeSoftwareImageOdataId;
960 std::optional<std::string> datetime;
George Liu79f3b6a2021-05-13 18:08:44 +0800961 std::optional<bool> locationIndicatorActive;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400962 std::optional<nlohmann::json::object_t> pidControllers;
963 std::optional<nlohmann::json::object_t> fanControllers;
964 std::optional<nlohmann::json::object_t> fanZones;
965 std::optional<nlohmann::json::object_t> stepwiseControllers;
966 std::optional<std::string> profile;
Ed Tanous002d39b2022-05-31 08:59:27 -0700967
Patrick Williams504af5a2025-02-03 14:29:03 -0500968 if (!json_util::readJsonPatch( //
969 req, asyncResp->res, //
970 "DateTime", datetime, //
Myung Baeafc474a2024-10-09 00:53:29 -0700971 "Links/ActiveSoftwareImage/@odata.id",
Patrick Williams504af5a2025-02-03 14:29:03 -0500972 activeSoftwareImageOdataId, //
George Liu79f3b6a2021-05-13 18:08:44 +0800973 "LocationIndicatorActive",
974 locationIndicatorActive, //
Myung Baeafc474a2024-10-09 00:53:29 -0700975 "Oem/OpenBmc/Fan/FanControllers", fanControllers, //
Patrick Williams504af5a2025-02-03 14:29:03 -0500976 "Oem/OpenBmc/Fan/FanZones", fanZones, //
Myung Baeafc474a2024-10-09 00:53:29 -0700977 "Oem/OpenBmc/Fan/PidControllers", pidControllers, //
Patrick Williams504af5a2025-02-03 14:29:03 -0500978 "Oem/OpenBmc/Fan/Profile", profile, //
Myung Baeafc474a2024-10-09 00:53:29 -0700979 "Oem/OpenBmc/Fan/StepwiseControllers",
Patrick Williams504af5a2025-02-03 14:29:03 -0500980 stepwiseControllers //
Myung Baeafc474a2024-10-09 00:53:29 -0700981 ))
982 {
983 return;
984 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700985
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400986 if (activeSoftwareImageOdataId)
987 {
988 setActiveFirmwareImage(asyncResp,
989 *activeSoftwareImageOdataId);
990 }
Ed Tanous9e9b6042024-03-06 14:18:28 -0800991
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400992 if (datetime)
993 {
994 setDateTime(asyncResp, *datetime);
995 }
rohitpai84aad242025-01-28 09:23:53 +0530996
George Liu79f3b6a2021-05-13 18:08:44 +0800997 if (locationIndicatorActive)
998 {
999 setLocationIndicatorActiveState(
1000 asyncResp, *locationIndicatorActive, managerId);
1001 }
1002
rohitpai84aad242025-01-28 09:23:53 +05301003 RedfishService::getInstance(app).handleSubRoute(req, asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001004 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001005}
1006
1007inline void requestRoutesManagerCollection(App& app)
1008{
1009 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07001010 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001011 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001012 [&app](const crow::Request& req,
1013 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001014 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1015 {
1016 return;
1017 }
1018 // Collections don't include the static data added by SubRoute
1019 // because it has a duplicate entry for members
1020 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
1021 asyncResp->res.jsonValue["@odata.type"] =
1022 "#ManagerCollection.ManagerCollection";
1023 asyncResp->res.jsonValue["Name"] = "Manager Collection";
1024 asyncResp->res.jsonValue["Members@odata.count"] = 1;
1025 nlohmann::json::array_t members;
1026 nlohmann::json& bmc = members.emplace_back();
1027 bmc["@odata.id"] = boost::urls::format(
1028 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
1029 asyncResp->res.jsonValue["Members"] = std::move(members);
1030 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001031}
Ed Tanous1abe55e2018-09-05 08:30:59 -07001032} // namespace redfish