blob: 5467f582961a284fb4f02f0d4b16d301dad447ea [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
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +01004#pragma once
5
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
10#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080011#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/chassis.hpp"
15#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080016#include "http_request.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080017#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080018#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080019#include "query.hpp"
20#include "registries/privilege_registry.hpp"
Myung Baef7e62c12025-09-07 14:02:08 -050021#include "utils/asset_utils.hpp"
Myung Bae3f95a272024-03-13 07:32:02 -070022#include "utils/chassis_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "utils/collection.hpp"
24#include "utils/dbus_utils.hpp"
Nan Zhoucf7eba02022-07-21 23:53:20 +000025#include "utils/json_utils.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070026
Ed Tanousd7857202025-01-28 15:32:26 -080027#include <asm-generic/errno.h>
28
29#include <boost/beast/http/field.hpp>
30#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080031#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070032#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080033#include <boost/url/url.hpp>
34#include <nlohmann/json.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080035#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +020036#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050037
Ed Tanousd7857202025-01-28 15:32:26 -080038#include <algorithm>
George Liu7a1dbc42022-12-07 16:03:22 +080039#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080040#include <format>
41#include <functional>
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -070042#include <memory>
Ed Tanousd7857202025-01-28 15:32:26 -080043#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070044#include <ranges>
Ed Tanousd7857202025-01-28 15:32:26 -080045#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080046#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080047#include <utility>
48#include <vector>
George Liu7a1dbc42022-12-07 16:03:22 +080049
Ed Tanous1abe55e2018-09-05 08:30:59 -070050namespace redfish
51{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010052
Patrick Williams504af5a2025-02-03 14:29:03 -050053inline chassis::ChassisType translateChassisTypeToRedfish(
54 const std::string_view& chassisType)
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -070055{
56 if (chassisType ==
57 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Blade")
58 {
59 return chassis::ChassisType::Blade;
60 }
61 if (chassisType ==
62 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Component")
63 {
64 return chassis::ChassisType::Component;
65 }
66 if (chassisType ==
67 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Enclosure")
68 {
69 return chassis::ChassisType::Enclosure;
70 }
71 if (chassisType ==
72 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Module")
73 {
74 return chassis::ChassisType::Module;
75 }
76 if (chassisType ==
77 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.RackMount")
78 {
79 return chassis::ChassisType::RackMount;
80 }
81 if (chassisType ==
82 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StandAlone")
83 {
84 return chassis::ChassisType::StandAlone;
85 }
86 if (chassisType ==
87 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StorageEnclosure")
88 {
89 return chassis::ChassisType::StorageEnclosure;
90 }
91 if (chassisType ==
92 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Zone")
93 {
94 return chassis::ChassisType::Zone;
95 }
96 return chassis::ChassisType::Invalid;
97}
98
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010099/**
Willy Tu5e577bc2022-07-26 00:41:55 +0000100 * @brief Retrieves resources over dbus to link to the chassis
101 *
102 * @param[in] asyncResp - Shared pointer for completing asynchronous
103 * calls
104 * @param[in] path - Chassis dbus path to look for the storage.
105 *
106 * Calls the Association endpoints on the path + "/storage" and add the link of
107 * json["Links"]["Storage@odata.count"] =
108 * {"@odata.id", "/redfish/v1/Storage/" + resourceId}
109 *
110 * @return None.
111 */
112inline void getStorageLink(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
113 const sdbusplus::message::object_path& path)
114{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800115 dbus::utility::getProperty<std::vector<std::string>>(
116 "xyz.openbmc_project.ObjectMapper", (path / "storage").str,
117 "xyz.openbmc_project.Association", "endpoints",
Willy Tud4b054c2023-06-12 15:18:45 -0700118 [asyncResp](const boost::system::error_code& ec,
Willy Tu5e577bc2022-07-26 00:41:55 +0000119 const std::vector<std::string>& storageList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400120 if (ec)
Willy Tu5e577bc2022-07-26 00:41:55 +0000121 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400122 BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error");
123 return;
Willy Tu5e577bc2022-07-26 00:41:55 +0000124 }
125
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400126 nlohmann::json::array_t storages;
127 for (const std::string& storagePath : storageList)
128 {
129 std::string id =
130 sdbusplus::message::object_path(storagePath).filename();
131 if (id.empty())
132 {
133 continue;
134 }
135
136 nlohmann::json::object_t storage;
137 storage["@odata.id"] =
138 boost::urls::format("/redfish/v1/Systems/{}/Storage/{}",
139 BMCWEB_REDFISH_SYSTEM_URI_NAME, id);
140 storages.emplace_back(std::move(storage));
141 }
142 asyncResp->res.jsonValue["Links"]["Storage@odata.count"] =
143 storages.size();
144 asyncResp->res.jsonValue["Links"]["Storage"] = std::move(storages);
145 });
Willy Tu5e577bc2022-07-26 00:41:55 +0000146}
147
148/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600149 * @brief Retrieves chassis state properties over dbus
150 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700151 * @param[in] asyncResp - Shared pointer for completing asynchronous calls.
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600152 *
153 * @return None.
154 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700155inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> asyncResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600156{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800157 dbus::utility::getProperty<std::string>(
158 "xyz.openbmc_project.State.Chassis",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700159 "/xyz/openbmc_project/state/chassis0",
160 "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec,
162 const std::string& chassisState) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400163 if (ec)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600164 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400165 if (ec == boost::system::errc::host_unreachable)
166 {
167 // Service not available, no error, just don't return
168 // chassis state info
169 BMCWEB_LOG_DEBUG("Service not available {}", ec);
170 return;
171 }
172 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
173 messages::internalError(asyncResp->res);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600174 return;
175 }
176
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400177 BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState);
178 // Verify Chassis State
179 if (chassisState ==
180 "xyz.openbmc_project.State.Chassis.PowerState.On")
181 {
182 asyncResp->res.jsonValue["PowerState"] =
183 resource::PowerState::On;
184 asyncResp->res.jsonValue["Status"]["State"] =
185 resource::State::Enabled;
186 }
187 else if (chassisState ==
188 "xyz.openbmc_project.State.Chassis.PowerState.Off")
189 {
190 asyncResp->res.jsonValue["PowerState"] =
191 resource::PowerState::Off;
192 asyncResp->res.jsonValue["Status"]["State"] =
193 resource::State::StandbyOffline;
194 }
195 });
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600196}
197
Qiang XUc1819422019-02-27 13:51:32 +0800198/**
199 * Retrieves physical security properties over dbus
200 */
Chau Ly7164bc62023-10-15 14:55:30 +0000201inline void handlePhysicalSecurityGetSubTree(
202 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
203 const boost::system::error_code& ec,
204 const dbus::utility::MapperGetSubTreeResponse& subtree)
Qiang XUc1819422019-02-27 13:51:32 +0800205{
Chau Ly7164bc62023-10-15 14:55:30 +0000206 if (ec)
207 {
208 // do not add err msg in redfish response, because this is not
209 // mandatory property
210 BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec);
211 return;
212 }
213 // Iterate over all retrieved ObjectPaths.
214 for (const auto& object : subtree)
215 {
216 if (!object.second.empty())
Ed Tanous002d39b2022-05-31 08:59:27 -0700217 {
Ed Tanous89144a32024-04-08 17:27:04 -0700218 const auto& service = object.second.front();
Chau Ly7164bc62023-10-15 14:55:30 +0000219
220 BMCWEB_LOG_DEBUG("Get intrusion status by service ");
221
Ed Tanousdeae6a72024-11-11 21:58:57 -0800222 dbus::utility::getProperty<std::string>(
223 service.first, object.first,
Chau Ly7164bc62023-10-15 14:55:30 +0000224 "xyz.openbmc_project.Chassis.Intrusion", "Status",
225 [asyncResp](const boost::system::error_code& ec1,
226 const std::string& value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400227 if (ec1)
228 {
229 // do not add err msg in redfish response, because this
230 // is not
231 // mandatory property
232 BMCWEB_LOG_ERROR("DBUS response error {}", ec1);
233 return;
234 }
235 asyncResp->res.jsonValue["PhysicalSecurity"]
236 ["IntrusionSensorNumber"] = 1;
237 asyncResp->res
238 .jsonValue["PhysicalSecurity"]["IntrusionSensor"] =
239 value;
240 });
Chau Ly7164bc62023-10-15 14:55:30 +0000241
Ed Tanous002d39b2022-05-31 08:59:27 -0700242 return;
243 }
Chau Ly7164bc62023-10-15 14:55:30 +0000244 }
Qiang XUc1819422019-02-27 13:51:32 +0800245}
246
Nan Zhoucf7eba02022-07-21 23:53:20 +0000247inline void handleChassisCollectionGet(
248 App& app, const crow::Request& req,
249 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
250{
251 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
252 {
253 return;
254 }
255 asyncResp->res.jsonValue["@odata.type"] =
256 "#ChassisCollection.ChassisCollection";
257 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
258 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
259
260 collection_util::getCollectionMembers(
Myung Bae3f95a272024-03-13 07:32:02 -0700261 asyncResp, boost::urls::url("/redfish/v1/Chassis"), chassisInterfaces,
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500262 "/xyz/openbmc_project/inventory");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000263}
264
Jie Yanga5617492021-06-29 12:59:14 -0700265inline void getChassisContainedBy(
266 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
267 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500268 const dbus::utility::MapperGetSubTreePathsResponse& upstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700269{
270 if (ec)
271 {
272 if (ec.value() != EBADR)
273 {
Ed Tanous62598e32023-07-17 17:06:25 -0700274 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700275 messages::internalError(asyncResp->res);
276 }
277 return;
278 }
279 if (upstreamChassisPaths.empty())
280 {
281 return;
282 }
283 if (upstreamChassisPaths.size() > 1)
284 {
Ed Tanous8ece0e42024-01-02 13:16:50 -0800285 BMCWEB_LOG_ERROR("{} is contained by multiple chassis", chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700286 messages::internalError(asyncResp->res);
287 return;
288 }
289
290 sdbusplus::message::object_path upstreamChassisPath(
291 upstreamChassisPaths[0]);
292 std::string upstreamChassis = upstreamChassisPath.filename();
293 if (upstreamChassis.empty())
294 {
Ed Tanous62598e32023-07-17 17:06:25 -0700295 BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}",
296 upstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700297 return;
298 }
299
300 asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] =
301 boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis);
302}
303
304inline void getChassisContains(
305 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
306 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500307 const dbus::utility::MapperGetSubTreePathsResponse& downstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700308{
309 if (ec)
310 {
311 if (ec.value() != EBADR)
312 {
Ed Tanous62598e32023-07-17 17:06:25 -0700313 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700314 messages::internalError(asyncResp->res);
315 }
316 return;
317 }
318 if (downstreamChassisPaths.empty())
319 {
320 return;
321 }
322 nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"];
323 if (!jValue.is_array())
324 {
325 // Create the array if it was empty
326 jValue = nlohmann::json::array();
327 }
328 for (const auto& p : downstreamChassisPaths)
329 {
330 sdbusplus::message::object_path downstreamChassisPath(p);
331 std::string downstreamChassis = downstreamChassisPath.filename();
332 if (downstreamChassis.empty())
333 {
Ed Tanous62598e32023-07-17 17:06:25 -0700334 BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}",
335 downstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700336 continue;
337 }
338 nlohmann::json link;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400339 link["@odata.id"] =
340 boost::urls::format("/redfish/v1/Chassis/{}", downstreamChassis);
Jie Yanga5617492021-06-29 12:59:14 -0700341 jValue.push_back(std::move(link));
342 }
343 asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size();
344}
345
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400346inline void getChassisConnectivity(
347 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
348 const std::string& chassisId, const std::string& chassisPath)
Jie Yanga5617492021-06-29 12:59:14 -0700349{
Ed Tanous62598e32023-07-17 17:06:25 -0700350 BMCWEB_LOG_DEBUG("Get chassis connectivity");
Jie Yanga5617492021-06-29 12:59:14 -0700351
Myung Bae28ee5632024-05-24 13:10:04 -0500352 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700353 chassisPath + "/contained_by",
Myung Bae28ee5632024-05-24 13:10:04 -0500354 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700355 chassisInterfaces,
Jie Yanga5617492021-06-29 12:59:14 -0700356 std::bind_front(getChassisContainedBy, asyncResp, chassisId));
357
Myung Bae28ee5632024-05-24 13:10:04 -0500358 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700359 chassisPath + "/containing",
Myung Bae28ee5632024-05-24 13:10:04 -0500360 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700361 chassisInterfaces,
362 std::bind_front(getChassisContains, asyncResp, chassisId));
Jie Yanga5617492021-06-29 12:59:14 -0700363}
364
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100365/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100366 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700367 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100368 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700369inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700370{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700371 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700372 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700373 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000374 std::bind_front(handleChassisCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700375}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100376
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400377inline void getChassisLocationCode(
378 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
379 const std::string& connectionName, const std::string& path)
Willy Tu308f70c2021-09-28 20:24:52 -0700380{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800381 dbus::utility::getProperty<std::string>(
382 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700383 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800384 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700385 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400386 if (ec)
387 {
388 BMCWEB_LOG_ERROR("DBUS response error for Location");
389 messages::internalError(asyncResp->res);
390 return;
391 }
Willy Tu308f70c2021-09-28 20:24:52 -0700392
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400393 asyncResp->res
394 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
395 property;
396 });
Willy Tu308f70c2021-09-28 20:24:52 -0700397}
398
399inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
400 const std::string& connectionName,
401 const std::string& path)
402{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800403 dbus::utility::getProperty<std::string>(
404 connectionName, path, "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800405 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700406 const std::string& chassisUUID) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400407 if (ec)
408 {
409 BMCWEB_LOG_ERROR("DBUS response error for UUID");
410 messages::internalError(asyncResp->res);
411 return;
412 }
413 asyncResp->res.jsonValue["UUID"] = chassisUUID;
414 });
Willy Tu308f70c2021-09-28 20:24:52 -0700415}
416
Chau Ly7164bc62023-10-15 14:55:30 +0000417inline void handleDecoratorAssetProperties(
418 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
419 const std::string& chassisId, const std::string& path,
420 const dbus::utility::DBusPropertiesMap& propertiesList)
421{
Myung Baef7e62c12025-09-07 14:02:08 -0500422 asset_utils::extractAssetInfo(asyncResp, ""_json_pointer, propertiesList,
423 true);
Chau Ly7164bc62023-10-15 14:55:30 +0000424
425 asyncResp->res.jsonValue["Name"] = chassisId;
426 asyncResp->res.jsonValue["Id"] = chassisId;
Ed Tanous25b54db2024-04-17 15:40:31 -0700427
428 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL)
429 {
430 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
431 boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId);
432 // Power object
433 asyncResp->res.jsonValue["Power"]["@odata.id"] =
434 boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId);
435 }
436
437 if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM)
438 {
439 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
440 boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem",
441 chassisId);
442 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
443 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem",
444 chassisId);
445 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
446 boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics",
447 chassisId);
448 }
SunnySrivastava198483237dd2021-01-11 12:12:17 -0600449
450 asyncResp->res.jsonValue["Assembly"]["@odata.id"] =
451 boost::urls::format("/redfish/v1/Chassis/{}/Assembly", chassisId);
452
Chau Ly7164bc62023-10-15 14:55:30 +0000453 // SensorCollection
454 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
455 boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -0700456 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
Chau Ly7164bc62023-10-15 14:55:30 +0000457
458 nlohmann::json::array_t computerSystems;
459 nlohmann::json::object_t system;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400460 system["@odata.id"] =
461 std::format("/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000462 computerSystems.emplace_back(std::move(system));
463 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
464 std::move(computerSystems);
465
466 nlohmann::json::array_t managedBy;
467 nlohmann::json::object_t manager;
Ed Tanous253f11b2024-05-16 09:38:31 -0700468 manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
469 BMCWEB_REDFISH_MANAGER_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000470 managedBy.emplace_back(std::move(manager));
471 asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
472 getChassisState(asyncResp);
473 getStorageLink(asyncResp, path);
474}
475
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700476inline void handleChassisProperties(
477 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
478 const dbus::utility::DBusPropertiesMap& propertiesList)
479{
480 const std::string* type = nullptr;
481
482 const bool success = sdbusplus::unpackPropertiesNoThrow(
483 dbus_utils::UnpackErrorPrinter(), propertiesList, "Type", type);
484
485 if (!success)
486 {
487 messages::internalError(asyncResp->res);
488 return;
489 }
490
Gunnar Mills19ea2862024-12-10 09:02:03 -0600491 // Chassis Type is a required property in Redfish
492 // If there is an error or some enum we don't support just sit it to Rack
493 // Mount
494 asyncResp->res.jsonValue["ChassisType"] = chassis::ChassisType::RackMount;
495
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700496 if (type != nullptr)
497 {
498 auto chassisType = translateChassisTypeToRedfish(*type);
499 if (chassisType != chassis::ChassisType::Invalid)
500 {
501 asyncResp->res.jsonValue["ChassisType"] = chassisType;
502 }
503 }
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700504}
505
Chau Ly7164bc62023-10-15 14:55:30 +0000506inline void handleChassisGetSubTree(
507 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
508 const std::string& chassisId, const boost::system::error_code& ec,
509 const dbus::utility::MapperGetSubTreeResponse& subtree)
510{
511 if (ec)
512 {
513 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
514 messages::internalError(asyncResp->res);
515 return;
516 }
517 // Iterate over all retrieved ObjectPaths.
518 for (const std::pair<
519 std::string,
520 std::vector<std::pair<std::string, std::vector<std::string>>>>&
521 object : subtree)
522 {
523 const std::string& path = object.first;
524 const std::vector<std::pair<std::string, std::vector<std::string>>>&
525 connectionNames = object.second;
526
527 sdbusplus::message::object_path objPath(path);
528 if (objPath.filename() != chassisId)
529 {
530 continue;
531 }
532
533 getChassisConnectivity(asyncResp, chassisId, path);
534
Chau Ly7164bc62023-10-15 14:55:30 +0000535 if (connectionNames.empty())
536 {
537 BMCWEB_LOG_ERROR("Got 0 Connection names");
538 continue;
539 }
540
541 asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis";
542 asyncResp->res.jsonValue["@odata.id"] =
543 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
544 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
Chau Ly7164bc62023-10-15 14:55:30 +0000545 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
546 boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset",
547 chassisId);
548 asyncResp->res
549 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
550 boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo",
551 chassisId);
Chau Ly7164bc62023-10-15 14:55:30 +0000552 dbus::utility::getAssociationEndPoints(
553 path + "/drive",
554 [asyncResp, chassisId](const boost::system::error_code& ec3,
555 const dbus::utility::MapperEndPoints& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400556 if (ec3 || resp.empty())
557 {
558 return; // no drives = no failures
559 }
Chau Ly7164bc62023-10-15 14:55:30 +0000560
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400561 nlohmann::json reference;
562 reference["@odata.id"] = boost::urls::format(
563 "/redfish/v1/Chassis/{}/Drives", chassisId);
564 asyncResp->res.jsonValue["Drives"] = std::move(reference);
565 });
Chau Ly7164bc62023-10-15 14:55:30 +0000566
567 const std::string& connectionName = connectionNames[0].first;
568
569 const std::vector<std::string>& interfaces2 = connectionNames[0].second;
George Liue5ae9c12021-11-16 10:31:23 +0800570 const std::array<const char*, 3> hasIndicatorLed = {
571 "xyz.openbmc_project.Inventory.Item.Chassis",
Chau Ly7164bc62023-10-15 14:55:30 +0000572 "xyz.openbmc_project.Inventory.Item.Panel",
573 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
574
575 const std::string assetTagInterface =
576 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
577 const std::string replaceableInterface =
578 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
Carson Labradob4d593f2024-02-16 22:34:32 +0000579 const std::string revisionInterface =
580 "xyz.openbmc_project.Inventory.Decorator.Revision";
Chau Ly7164bc62023-10-15 14:55:30 +0000581 for (const auto& interface : interfaces2)
582 {
583 if (interface == assetTagInterface)
584 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800585 dbus::utility::getProperty<std::string>(
586 connectionName, path, assetTagInterface, "AssetTag",
Chau Ly7164bc62023-10-15 14:55:30 +0000587 [asyncResp, chassisId](const boost::system::error_code& ec2,
588 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400589 if (ec2)
590 {
591 BMCWEB_LOG_ERROR(
592 "DBus response error for AssetTag: {}", ec2);
593 messages::internalError(asyncResp->res);
594 return;
595 }
596 asyncResp->res.jsonValue["AssetTag"] = property;
597 });
Chau Ly7164bc62023-10-15 14:55:30 +0000598 }
599 else if (interface == replaceableInterface)
600 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800601 dbus::utility::getProperty<bool>(
602 connectionName, path, replaceableInterface, "HotPluggable",
Chau Ly7164bc62023-10-15 14:55:30 +0000603 [asyncResp, chassisId](const boost::system::error_code& ec2,
604 const bool property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400605 if (ec2)
606 {
607 BMCWEB_LOG_ERROR(
608 "DBus response error for HotPluggable: {}",
609 ec2);
610 messages::internalError(asyncResp->res);
611 return;
612 }
613 asyncResp->res.jsonValue["HotPluggable"] = property;
614 });
Chau Ly7164bc62023-10-15 14:55:30 +0000615 }
Carson Labradob4d593f2024-02-16 22:34:32 +0000616 else if (interface == revisionInterface)
617 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800618 dbus::utility::getProperty<std::string>(
619 connectionName, path, revisionInterface, "Version",
Carson Labradob4d593f2024-02-16 22:34:32 +0000620 [asyncResp, chassisId](const boost::system::error_code& ec2,
621 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400622 if (ec2)
623 {
624 BMCWEB_LOG_ERROR(
625 "DBus response error for Version: {}", ec2);
626 messages::internalError(asyncResp->res);
627 return;
628 }
629 asyncResp->res.jsonValue["Version"] = property;
630 });
Carson Labradob4d593f2024-02-16 22:34:32 +0000631 }
Chau Ly7164bc62023-10-15 14:55:30 +0000632 }
633
634 for (const char* interface : hasIndicatorLed)
635 {
636 if (std::ranges::find(interfaces2, interface) != interfaces2.end())
637 {
Janet Adkinsf664fd82025-07-23 14:01:43 -0500638 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED)
639 {
640 getIndicatorLedState(asyncResp);
641 }
Janet Adkinsde8e5142025-04-17 10:30:43 -0500642 getLocationIndicatorActive(asyncResp, objPath);
Chau Ly7164bc62023-10-15 14:55:30 +0000643 break;
644 }
645 }
646
Ed Tanousdeae6a72024-11-11 21:58:57 -0800647 dbus::utility::getAllProperties(
Chau Ly7164bc62023-10-15 14:55:30 +0000648 *crow::connections::systemBus, connectionName, path,
649 "xyz.openbmc_project.Inventory.Decorator.Asset",
650 [asyncResp, chassisId,
651 path](const boost::system::error_code&,
652 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400653 handleDecoratorAssetProperties(asyncResp, chassisId, path,
654 propertiesList);
655 });
Chau Ly7164bc62023-10-15 14:55:30 +0000656
Ed Tanous46f780f2025-02-09 09:35:23 -0800657 dbus::utility::getAllProperties(
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700658 *crow::connections::systemBus, connectionName, path,
659 "xyz.openbmc_project.Inventory.Item.Chassis",
660 [asyncResp](
661 const boost::system::error_code&,
662 const dbus::utility::DBusPropertiesMap& propertiesList) {
663 handleChassisProperties(asyncResp, propertiesList);
664 });
665
Chau Ly7164bc62023-10-15 14:55:30 +0000666 for (const auto& interface : interfaces2)
667 {
668 if (interface == "xyz.openbmc_project.Common.UUID")
669 {
670 getChassisUUID(asyncResp, connectionName, path);
671 }
672 else if (interface ==
673 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
674 {
675 getChassisLocationCode(asyncResp, connectionName, path);
676 }
677 }
678
679 return;
680 }
681
682 // Couldn't find an object with that name. return an error
683 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
684}
685
Patrick Williams504af5a2025-02-03 14:29:03 -0500686inline void handleChassisGet(
687 App& app, const crow::Request& req,
688 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
689 const std::string& chassisId)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000690{
691 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
692 {
693 return;
694 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000695
George Liue99073f2022-12-09 11:06:16 +0800696 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700697 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Chau Ly7164bc62023-10-15 14:55:30 +0000698 std::bind_front(handleChassisGetSubTree, asyncResp, chassisId));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000699
Chau Ly7164bc62023-10-15 14:55:30 +0000700 constexpr std::array<std::string_view, 1> interfaces2 = {
701 "xyz.openbmc_project.Chassis.Intrusion"};
Nan Zhoucf7eba02022-07-21 23:53:20 +0000702
Chau Ly7164bc62023-10-15 14:55:30 +0000703 dbus::utility::getSubTree(
704 "/xyz/openbmc_project", 0, interfaces2,
705 std::bind_front(handlePhysicalSecurityGetSubTree, asyncResp));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000706}
707
Patrick Williams504af5a2025-02-03 14:29:03 -0500708inline void handleChassisPatch(
709 App& app, const crow::Request& req,
710 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
711 const std::string& param)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000712{
713 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
714 {
715 return;
716 }
717 std::optional<bool> locationIndicatorActive;
718 std::optional<std::string> indicatorLed;
719
720 if (param.empty())
721 {
722 return;
723 }
724
Patrick Williams504af5a2025-02-03 14:29:03 -0500725 if (!json_util::readJsonPatch( //
726 req, asyncResp->res, //
727 "IndicatorLED", indicatorLed, //
Myung Baeafc474a2024-10-09 00:53:29 -0700728 "LocationIndicatorActive", locationIndicatorActive //
729 ))
Nan Zhoucf7eba02022-07-21 23:53:20 +0000730 {
731 return;
732 }
733
Nan Zhoucf7eba02022-07-21 23:53:20 +0000734 if (!locationIndicatorActive && !indicatorLed)
735 {
736 return; // delete this when we support more patch properties
737 }
738 if (indicatorLed)
739 {
Janet Adkinsf664fd82025-07-23 14:01:43 -0500740 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED)
741 {
742 asyncResp->res.addHeader(
743 boost::beast::http::field::warning,
744 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
745 }
746 else
747 {
748 messages::propertyUnknown(asyncResp->res, "IndicatorLED");
749 return;
750 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000751 }
752
Nan Zhoucf7eba02022-07-21 23:53:20 +0000753 const std::string& chassisId = param;
754
George Liue99073f2022-12-09 11:06:16 +0800755 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700756 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000757 [asyncResp, chassisId, locationIndicatorActive,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800758 indicatorLed](const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000759 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400760 if (ec)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000761 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400762 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
763 messages::internalError(asyncResp->res);
764 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000765 }
766
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400767 // Iterate over all retrieved ObjectPaths.
768 for (const std::pair<std::string,
769 std::vector<std::pair<
770 std::string, std::vector<std::string>>>>&
771 object : subtree)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000772 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400773 const std::string& path = object.first;
774 const std::vector<
775 std::pair<std::string, std::vector<std::string>>>&
776 connectionNames = object.second;
777
778 sdbusplus::message::object_path objPath(path);
779 if (objPath.filename() != chassisId)
780 {
781 continue;
782 }
783
784 if (connectionNames.empty())
785 {
786 BMCWEB_LOG_ERROR("Got 0 Connection names");
787 continue;
788 }
789
790 const std::vector<std::string>& interfaces3 =
791 connectionNames[0].second;
792
793 const std::array<const char*, 3> hasIndicatorLed = {
794 "xyz.openbmc_project.Inventory.Item.Chassis",
795 "xyz.openbmc_project.Inventory.Item.Panel",
796 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
797 bool indicatorChassis = false;
798 for (const char* interface : hasIndicatorLed)
799 {
800 if (std::ranges::find(interfaces3, interface) !=
801 interfaces3.end())
802 {
803 indicatorChassis = true;
804 break;
805 }
806 }
807 if (locationIndicatorActive)
808 {
809 if (indicatorChassis)
810 {
Janet Adkinsde8e5142025-04-17 10:30:43 -0500811 setLocationIndicatorActive(asyncResp, path,
812 *locationIndicatorActive);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400813 }
814 else
815 {
816 messages::propertyUnknown(asyncResp->res,
817 "LocationIndicatorActive");
818 }
819 }
Janet Adkinsf664fd82025-07-23 14:01:43 -0500820 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400821 {
Janet Adkinsf664fd82025-07-23 14:01:43 -0500822 if (indicatorLed)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400823 {
Janet Adkinsf664fd82025-07-23 14:01:43 -0500824 if (indicatorChassis)
825 {
826 setIndicatorLedState(asyncResp, *indicatorLed);
827 }
828 else
829 {
830 messages::propertyUnknown(asyncResp->res,
831 "IndicatorLED");
832 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400833 }
834 }
835 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000836 }
837
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400838 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
839 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000840}
841
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100842/**
843 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700844 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100845 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700846inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700847{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700848 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700849 .privileges(redfish::privileges::getChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700850 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000851 std::bind_front(handleChassisGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700852
853 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700854 .privileges(redfish::privileges::patchChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700855 .methods(boost::beast::http::verb::patch)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000856 std::bind_front(handleChassisPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700857}
P.K. Leedd99e042020-06-17 19:43:16 +0800858
Patrick Williams504af5a2025-02-03 14:29:03 -0500859inline void doChassisPowerCycle(
860 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800861{
George Liu7a1dbc42022-12-07 16:03:22 +0800862 constexpr std::array<std::string_view, 1> interfaces = {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700863 "xyz.openbmc_project.State.Chassis"};
864
865 // Use mapper to get subtree paths.
George Liu7a1dbc42022-12-07 16:03:22 +0800866 dbus::utility::getSubTreePaths(
867 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800868 [asyncResp](
George Liu7a1dbc42022-12-07 16:03:22 +0800869 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800870 const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400871 if (ec)
872 {
873 BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec);
874 messages::internalError(asyncResp->res);
875 return;
876 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700877
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400878 const char* processName = "xyz.openbmc_project.State.Chassis";
879 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
880 const char* destProperty = "RequestedPowerTransition";
881 const std::string propertyValue =
882 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
883 std::string objectPath =
884 "/xyz/openbmc_project/state/chassis_system0";
Ed Tanous002d39b2022-05-31 08:59:27 -0700885
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400886 /* Look for system reset chassis path */
887 if ((std::ranges::find(chassisList, objectPath)) ==
888 chassisList.end())
889 {
890 /* We prefer to reset the full chassis_system, but if it doesn't
891 * exist on some platforms, fall back to a host-only power reset
892 */
893 objectPath = "/xyz/openbmc_project/state/chassis0";
894 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700895
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400896 setDbusProperty(asyncResp, "ResetType", processName, objectPath,
897 interfaceName, destProperty, propertyValue);
898 });
P.K. Leedd99e042020-06-17 19:43:16 +0800899}
900
Nan Zhoucf7eba02022-07-21 23:53:20 +0000901inline void handleChassisResetActionInfoPost(
902 App& app, const crow::Request& req,
903 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
904 const std::string& /*chassisId*/)
905{
906 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
907 {
908 return;
909 }
Ed Tanous62598e32023-07-17 17:06:25 -0700910 BMCWEB_LOG_DEBUG("Post Chassis Reset.");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000911
912 std::string resetType;
913
914 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
915 {
916 return;
917 }
918
919 if (resetType != "PowerCycle")
920 {
Ed Tanous62598e32023-07-17 17:06:25 -0700921 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000922 messages::actionParameterNotSupported(asyncResp->res, resetType,
923 "ResetType");
924
925 return;
926 }
927 doChassisPowerCycle(asyncResp);
928}
929
P.K. Leedd99e042020-06-17 19:43:16 +0800930/**
931 * ChassisResetAction class supports the POST method for the Reset
932 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700933 * Function handles POST method request.
934 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800935 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700936
937inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800938{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700939 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700940 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700941 .methods(boost::beast::http::verb::post)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000942 std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
943}
P.K. Leedd99e042020-06-17 19:43:16 +0800944
Nan Zhoucf7eba02022-07-21 23:53:20 +0000945inline void handleChassisResetActionInfoGet(
946 App& app, const crow::Request& req,
947 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
948 const std::string& chassisId)
949{
950 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
951 {
952 return;
953 }
954 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700955 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
956 "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000957 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
P.K. Leedd99e042020-06-17 19:43:16 +0800958
Nan Zhoucf7eba02022-07-21 23:53:20 +0000959 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
960 nlohmann::json::array_t parameters;
961 nlohmann::json::object_t parameter;
962 parameter["Name"] = "ResetType";
963 parameter["Required"] = true;
Ed Tanous539d8c62024-06-19 14:38:27 -0700964 parameter["DataType"] = action_info::ParameterTypes::String;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000965 nlohmann::json::array_t allowed;
Patrick Williamsad539542023-05-12 10:10:08 -0500966 allowed.emplace_back("PowerCycle");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000967 parameter["AllowableValues"] = std::move(allowed);
Patrick Williamsad539542023-05-12 10:10:08 -0500968 parameters.emplace_back(std::move(parameter));
P.K. Leedd99e042020-06-17 19:43:16 +0800969
Nan Zhoucf7eba02022-07-21 23:53:20 +0000970 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700971}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530972
973/**
974 * ChassisResetActionInfo derived class for delivering Chassis
975 * ResetType AllowableValues using ResetInfo schema.
976 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700977inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530978{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700979 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700980 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700981 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000982 std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700983}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530984
Ed Tanous1abe55e2018-09-05 08:30:59 -0700985} // namespace redfish