Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 8 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "async_resp.hpp" |
| 10 | #include "dbus_singleton.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 11 | #include "dbus_utility.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "error_messages.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 13 | #include "generated/enums/action_info.hpp" |
| 14 | #include "generated/enums/manager.hpp" |
| 15 | #include "generated/enums/resource.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 16 | #include "http_request.hpp" |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 17 | #include "led.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 18 | #include "logging.hpp" |
| 19 | #include "persistent_data.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 20 | #include "query.hpp" |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 21 | #include "redfish.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 22 | #include "redfish_util.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 23 | #include "registries/privilege_registry.hpp" |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 24 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 25 | #include "utils/json_utils.hpp" |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame] | 26 | #include "utils/manager_utils.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 27 | #include "utils/sw_utils.hpp" |
| 28 | #include "utils/systemd_utils.hpp" |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 29 | #include "utils/time_utils.hpp" |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 30 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 31 | #include <systemd/sd-bus.h> |
| 32 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 33 | #include <boost/beast/http/status.hpp> |
| 34 | #include <boost/beast/http/verb.hpp> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 35 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 36 | #include <boost/url/format.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 37 | #include <boost/url/url.hpp> |
| 38 | #include <nlohmann/json.hpp> |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 39 | #include <sdbusplus/asio/property.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 40 | #include <sdbusplus/message.hpp> |
| 41 | #include <sdbusplus/message/native_types.hpp> |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 42 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 43 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 44 | #include <array> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 45 | #include <cstddef> |
Gunnar Mills | 4bfefa7 | 2020-07-30 13:54:29 -0500 | [diff] [blame] | 46 | #include <cstdint> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 47 | #include <format> |
| 48 | #include <functional> |
| 49 | #include <map> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 50 | #include <memory> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 51 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 52 | #include <ranges> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 53 | #include <string> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 54 | #include <string_view> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 55 | #include <utility> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 56 | #include <vector> |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | namespace redfish |
| 59 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 60 | |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 61 | inline 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 | */ |
| 105 | inline 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 Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 118 | inline 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 | |
| 127 | inline 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 Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 136 | /** |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 137 | * Function reboots the BMC. |
| 138 | * |
| 139 | * @param[in] asyncResp - Shared pointer for completing asynchronous calls |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 140 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 141 | inline void doBMCGracefulRestart( |
| 142 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 143 | { |
| 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 Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 152 | sdbusplus::asio::setProperty( |
| 153 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 154 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 155 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 156 | // 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 Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 163 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 164 | messages::success(asyncResp->res); |
| 165 | }); |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 168 | inline void doBMCForceRestart( |
| 169 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 170 | { |
| 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 Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 179 | sdbusplus::asio::setProperty( |
| 180 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 181 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 182 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 183 | // 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 Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 190 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 191 | messages::success(asyncResp->res); |
| 192 | }); |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 195 | /** |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 196 | * 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 Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 199 | */ |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 200 | |
| 201 | inline void handleManagerResetAction( |
| 202 | crow::App& app, const crow::Request& req, |
| 203 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 204 | const std::string& managerId) |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 205 | { |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 206 | 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 Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 215 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 216 | BMCWEB_LOG_DEBUG("Post Manager Reset."); |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 217 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 218 | std::string resetType; |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 219 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 220 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) |
| 221 | { |
| 222 | return; |
| 223 | } |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 224 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 225 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 240 | } |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 241 | |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 242 | /** |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 243 | * 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 Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 252 | */ |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 253 | |
| 254 | inline void handleManagerResetToDefaultsAction( |
| 255 | crow::App& app, const crow::Request& req, |
| 256 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 257 | const std::string& managerId) |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 258 | { |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 259 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 260 | { |
| 261 | return; |
| 262 | } |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 263 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 264 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 265 | { |
| 266 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 267 | return; |
| 268 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 269 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 270 | BMCWEB_LOG_DEBUG("Post ResetToDefaults."); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 271 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 272 | std::optional<std::string> resetType; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 273 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 274 | if (!json_util::readJsonAction( // |
| 275 | req, asyncResp->res, // |
| 276 | "ResetType", resetType // |
| 277 | )) |
| 278 | { |
| 279 | BMCWEB_LOG_DEBUG("Missing property ResetType."); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 280 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 281 | messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", |
| 282 | "ResetType"); |
| 283 | return; |
| 284 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 285 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 286 | 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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 294 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 295 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 309 | } |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 310 | |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 311 | /** |
| 312 | * ManagerResetActionInfo derived class for delivering Manager |
| 313 | * ResetType AllowableValues using ResetInfo schema. |
| 314 | */ |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 315 | inline void handleManagerResetActionInfo( |
| 316 | crow::App& app, const crow::Request& req, |
| 317 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 318 | const std::string& managerId) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 319 | { |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 320 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 321 | { |
| 322 | return; |
| 323 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 324 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 325 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 326 | { |
| 327 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 328 | return; |
| 329 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 330 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 331 | 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 Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 341 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 342 | nlohmann::json::array_t allowableValues; |
| 343 | allowableValues.emplace_back("GracefulRestart"); |
| 344 | allowableValues.emplace_back("ForceRestart"); |
| 345 | parameter["AllowableValues"] = std::move(allowableValues); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 346 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 347 | nlohmann::json::array_t parameters; |
| 348 | parameters.emplace_back(std::move(parameter)); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 349 | |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 350 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 351 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 352 | |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 353 | /** |
| 354 | * @brief Retrieves BMC manager location data over DBus |
| 355 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 356 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 357 | * @param[in] connectionName - service name |
| 358 | * @param[in] path - object path |
| 359 | * @return none |
| 360 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 361 | inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 362 | const std::string& connectionName, |
| 363 | const std::string& path) |
| 364 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 365 | BMCWEB_LOG_DEBUG("Get BMC manager Location data."); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 366 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 367 | dbus::utility::getProperty<std::string>( |
| 368 | connectionName, path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 369 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 370 | [asyncResp](const boost::system::error_code& ec, |
| 371 | const std::string& property) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 372 | if (ec) |
| 373 | { |
| 374 | BMCWEB_LOG_DEBUG("DBUS response error for " |
| 375 | "Location"); |
| 376 | messages::internalError(asyncResp->res); |
| 377 | return; |
| 378 | } |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 379 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 380 | asyncResp->res |
| 381 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 382 | property; |
| 383 | }); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 384 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 385 | // avoid name collision systems.hpp |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 386 | inline void managerGetLastResetTime( |
| 387 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 388 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 389 | BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 390 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 391 | dbus::utility::getProperty<uint64_t>( |
| 392 | "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", |
| 393 | "xyz.openbmc_project.State.BMC", "LastRebootTime", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 394 | [asyncResp](const boost::system::error_code& ec, |
| 395 | const uint64_t lastResetTime) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 396 | if (ec) |
| 397 | { |
| 398 | BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); |
| 399 | return; |
| 400 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 401 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 402 | // 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 405 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 406 | // Convert to ISO 8601 standard |
| 407 | asyncResp->res.jsonValue["LastResetTime"] = |
| 408 | redfish::time_utils::getDateTimeUint(lastResetTimeStamp); |
| 409 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
| 413 | * @brief Set the running firmware image |
| 414 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 415 | * @param[i,o] asyncResp - Async response object |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 416 | * @param[i] runningFirmwareTarget - Image to make the running image |
| 417 | * |
| 418 | * @return void |
| 419 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 420 | inline void setActiveFirmwareImage( |
| 421 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 422 | const std::string& runningFirmwareTarget) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 423 | { |
| 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 428 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 429 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 430 | BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | idPos++; |
| 434 | if (idPos >= runningFirmwareTarget.size()) |
| 435 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 436 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 437 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 438 | BMCWEB_LOG_DEBUG("Invalid firmware ID."); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | std::string firmwareId = runningFirmwareTarget.substr(idPos); |
| 442 | |
| 443 | // Make sure the image is valid before setting priority |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 444 | sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); |
| 445 | dbus::utility::getManagedObjects( |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 446 | getBMCUpdateServiceName(), objPath, |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 447 | [asyncResp, firmwareId, runningFirmwareTarget]( |
| 448 | const boost::system::error_code& ec, |
| 449 | const dbus::utility::ManagedObjectType& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 450 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 451 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 452 | BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 453 | messages::internalError(asyncResp->res); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 454 | return; |
| 455 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 456 | |
| 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 Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 504 | *crow::connections::systemBus, getBMCUpdateServiceName(), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 505 | "/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 Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 517 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 518 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 519 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 520 | inline void afterSetDateTime( |
| 521 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 522 | const boost::system::error_code& ec, const sdbusplus::message_t& msg) |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 523 | { |
| 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 | |
| 548 | inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 549 | const std::string& datetime) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 550 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 551 | BMCWEB_LOG_DEBUG("Set date time: {}", datetime); |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 552 | |
Ed Tanous | c2e3200 | 2023-01-07 22:05:08 -0800 | [diff] [blame] | 553 | std::optional<redfish::time_utils::usSinceEpoch> us = |
| 554 | redfish::time_utils::dateStringToEpoch(datetime); |
| 555 | if (!us) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 556 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 557 | messages::propertyValueFormatError(asyncResp->res, datetime, |
| 558 | "DateTime"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 559 | return; |
| 560 | } |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 561 | // 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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 567 | afterSetDateTime(asyncResp, ec, msg); |
| 568 | }, |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 569 | "org.freedesktop.timedate1", "/org/freedesktop/timedate1", |
| 570 | "org.freedesktop.timedate1", "SetTime", us->count(), relative, |
| 571 | interactive); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 574 | inline void checkForQuiesced( |
| 575 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 576 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 577 | dbus::utility::getProperty<std::string>( |
| 578 | "org.freedesktop.systemd1", |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 579 | "/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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 583 | if (!ec) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 584 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 585 | 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 Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 593 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 594 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
| 595 | asyncResp->res.jsonValue["Status"]["State"] = |
| 596 | resource::State::Enabled; |
| 597 | }); |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Janet Adkins | e2cdf06 | 2025-06-18 11:17:35 -0500 | [diff] [blame] | 600 | inline 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 | |
| 654 | inline 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 Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 682 | else if (interfaceName == |
| 683 | "xyz.openbmc_project.Association.Definitions") |
| 684 | { |
| 685 | getLocationIndicatorActive(asyncResp, managerPath); |
| 686 | } |
Janet Adkins | e2cdf06 | 2025-06-18 11:17:35 -0500 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | inline 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 | |
| 721 | inline 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 Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 739 | inline void handleManagerGet( |
| 740 | App& app, const crow::Request& req, |
| 741 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 742 | const std::string& managerId) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 743 | { |
Myung Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 744 | 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 755 | std::string uuid = persistent_data::getConfig().systemUuid; |
| 756 | |
Myung Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 757 | 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 | |
| 895 | inline 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 | |
| 965 | inline 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 | |
| 987 | inline void requestRoutesManager(App& app) |
| 988 | { |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 989 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 990 | .privileges(redfish::privileges::getManager) |
Myung Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 991 | .methods(boost::beast::http::verb::get)( |
| 992 | std::bind_front(handleManagerGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 993 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 994 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 995 | .privileges(redfish::privileges::patchManager) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 996 | .methods(boost::beast::http::verb::patch)( |
Myung Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 997 | std::bind_front(handleManagerPatch, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 998 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 999 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1000 | .privileges(redfish::privileges::getManagerCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1001 | .methods(boost::beast::http::verb::get)( |
Myung Bae | 96153bd | 2025-08-20 15:20:49 -0400 | [diff] [blame] | 1002 | std::bind_front(handleManagerCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1003 | } |
Myung Bae | 64acd26 | 2025-08-21 15:51:21 -0400 | [diff] [blame] | 1004 | |
| 1005 | inline 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 Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1024 | } // namespace redfish |