blob: 532da5fb140d1f712932974c5f71f1b3ca8dbef8 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Sunny Srivastava31791052021-03-12 10:39:16 -06003#pragma once
4
Ed Tanousd7857202025-01-28 15:32:26 -08005#include "bmcweb_config.h"
6
Sunny Srivastava31791052021-03-12 10:39:16 -06007#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08008#include "async_resp.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -06009#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080010#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070011#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "http_request.hpp"
Myung Baebe1384e2024-08-20 12:07:10 -050013#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080014#include "logging.hpp"
Ed Tanousa8e884f2023-01-13 17:40:03 -080015#include "query.hpp"
16#include "registries/privilege_registry.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -060017#include "utils/collection.hpp"
Lakshmi Yadlapati6177a302023-02-17 10:29:34 -060018#include "utils/dbus_utils.hpp"
Myung Baebe1384e2024-08-20 12:07:10 -050019#include "utils/json_utils.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -060020
Ed Tanousd7857202025-01-28 15:32:26 -080021#include <asm-generic/errno.h>
22
23#include <boost/beast/http/field.hpp>
24#include <boost/beast/http/verb.hpp>
Sunny Srivastava31791052021-03-12 10:39:16 -060025#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070026#include <boost/url/format.hpp>
Lakshmi Yadlapati6177a302023-02-17 10:29:34 -060027#include <sdbusplus/unpack_properties.hpp>
Sunny Srivastava31791052021-03-12 10:39:16 -060028
29#include <array>
30#include <functional>
31#include <memory>
Myung Baebe1384e2024-08-20 12:07:10 -050032#include <optional>
Sunny Srivastava31791052021-03-12 10:39:16 -060033#include <string>
34#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080035#include <utility>
Sunny Srivastava31791052021-03-12 10:39:16 -060036
37namespace redfish
38{
39
Ed Tanousac106bf2023-06-07 09:24:59 -070040inline void getFabricAdapterLocation(
41 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
42 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060043{
Ed Tanousdeae6a72024-11-11 21:58:57 -080044 dbus::utility::getProperty<std::string>(
45 serviceName, fabricAdapterPath,
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060046 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -070047 [asyncResp](const boost::system::error_code& ec,
48 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040049 if (ec)
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060050 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040051 if (ec.value() != EBADR)
52 {
53 BMCWEB_LOG_ERROR("DBUS response error for Location");
54 messages::internalError(asyncResp->res);
55 }
56 return;
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060057 }
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060058
Patrick Williamsbd79bce2024-08-16 15:22:20 -040059 asyncResp->res
60 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
61 property;
62 });
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060063}
64
Patrick Williamsbd79bce2024-08-16 15:22:20 -040065inline void getFabricAdapterAsset(
66 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
67 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060068{
Ed Tanousdeae6a72024-11-11 21:58:57 -080069 dbus::utility::getAllProperties(
70 serviceName, fabricAdapterPath,
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060071 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanousac106bf2023-06-07 09:24:59 -070072 [fabricAdapterPath, asyncResp{asyncResp}](
73 const boost::system::error_code& ec,
74 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040075 if (ec)
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060076 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040077 if (ec.value() != EBADR)
78 {
79 BMCWEB_LOG_ERROR("DBUS response error for Properties");
80 messages::internalError(asyncResp->res);
81 }
82 return;
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060083 }
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060084
Patrick Williamsbd79bce2024-08-16 15:22:20 -040085 const std::string* serialNumber = nullptr;
86 const std::string* model = nullptr;
87 const std::string* partNumber = nullptr;
88 const std::string* sparePartNumber = nullptr;
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060089
Patrick Williamsbd79bce2024-08-16 15:22:20 -040090 const bool success = sdbusplus::unpackPropertiesNoThrow(
91 dbus_utils::UnpackErrorPrinter(), propertiesList,
92 "SerialNumber", serialNumber, "Model", model, "PartNumber",
93 partNumber, "SparePartNumber", sparePartNumber);
Lakshmi Yadlapati63694212023-01-27 16:35:22 -060094
Patrick Williamsbd79bce2024-08-16 15:22:20 -040095 if (!success)
96 {
97 messages::internalError(asyncResp->res);
98 return;
99 }
Lakshmi Yadlapati63694212023-01-27 16:35:22 -0600100
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400101 if (serialNumber != nullptr)
102 {
103 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
104 }
Lakshmi Yadlapati63694212023-01-27 16:35:22 -0600105
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400106 if (model != nullptr)
107 {
108 asyncResp->res.jsonValue["Model"] = *model;
109 }
Lakshmi Yadlapati63694212023-01-27 16:35:22 -0600110
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400111 if (partNumber != nullptr)
112 {
113 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
114 }
Lakshmi Yadlapati63694212023-01-27 16:35:22 -0600115
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400116 if (sparePartNumber != nullptr && !sparePartNumber->empty())
117 {
118 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
119 }
120 });
Lakshmi Yadlapati63694212023-01-27 16:35:22 -0600121}
122
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400123inline void getFabricAdapterState(
124 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
125 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600126{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800127 dbus::utility::getProperty<bool>(
128 serviceName, fabricAdapterPath, "xyz.openbmc_project.Inventory.Item",
129 "Present",
Ed Tanousac106bf2023-06-07 09:24:59 -0700130 [asyncResp](const boost::system::error_code& ec, const bool present) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400131 if (ec)
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600132 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400133 if (ec.value() != EBADR)
134 {
135 BMCWEB_LOG_ERROR("DBUS response error for State");
136 messages::internalError(asyncResp->res);
137 }
138 return;
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600139 }
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600140
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400141 if (!present)
142 {
143 asyncResp->res.jsonValue["Status"]["State"] =
144 resource::State::Absent;
145 }
146 });
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600147}
148
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400149inline void getFabricAdapterHealth(
150 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
151 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600152{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800153 dbus::utility::getProperty<bool>(
154 serviceName, fabricAdapterPath,
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600155 "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
Ed Tanousac106bf2023-06-07 09:24:59 -0700156 [asyncResp](const boost::system::error_code& ec,
157 const bool functional) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400158 if (ec)
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600159 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400160 if (ec.value() != EBADR)
161 {
162 BMCWEB_LOG_ERROR("DBUS response error for Health");
163 messages::internalError(asyncResp->res);
164 }
165 return;
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600166 }
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600167
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400168 if (!functional)
169 {
170 asyncResp->res.jsonValue["Status"]["Health"] =
171 resource::Health::Critical;
172 }
173 });
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600174}
175
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400176inline void doAdapterGet(
177 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
178 const std::string& systemName, const std::string& adapterId,
179 const std::string& fabricAdapterPath, const std::string& serviceName)
Sunny Srivastava31791052021-03-12 10:39:16 -0600180{
Ed Tanousac106bf2023-06-07 09:24:59 -0700181 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600182 boost::beast::http::field::link,
183 "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
Ed Tanousac106bf2023-06-07 09:24:59 -0700184 asyncResp->res.jsonValue["@odata.type"] =
185 "#FabricAdapter.v1_4_0.FabricAdapter";
186 asyncResp->res.jsonValue["Name"] = "Fabric Adapter";
187 asyncResp->res.jsonValue["Id"] = adapterId;
188 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanousef4c65b2023-04-24 15:28:50 -0700189 "/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId);
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -0600190
Ed Tanous539d8c62024-06-19 14:38:27 -0700191 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
192 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600193
George Liu37937d52023-02-21 18:02:26 +0800194 asyncResp->res.jsonValue["Ports"]["@odata.id"] =
195 boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters/{}/Ports",
196 systemName, adapterId);
197
Ed Tanousac106bf2023-06-07 09:24:59 -0700198 getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath);
199 getFabricAdapterAsset(asyncResp, serviceName, fabricAdapterPath);
200 getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath);
201 getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath);
Myung Baebe1384e2024-08-20 12:07:10 -0500202 getLocationIndicatorActive(asyncResp, fabricAdapterPath);
Sunny Srivastava31791052021-03-12 10:39:16 -0600203}
204
Myung Bae78c90202024-02-19 13:39:56 -0500205inline void afterGetValidFabricAdapterPath(
206 const std::string& adapterId,
207 std::function<void(const boost::system::error_code&,
208 const std::string& fabricAdapterPath,
209 const std::string& serviceName)>& callback,
210 const boost::system::error_code& ec,
211 const dbus::utility::MapperGetSubTreeResponse& subtree)
Sunny Srivastava31791052021-03-12 10:39:16 -0600212{
Myung Bae78c90202024-02-19 13:39:56 -0500213 std::string fabricAdapterPath;
214 std::string serviceName;
215 if (ec)
216 {
217 callback(ec, fabricAdapterPath, serviceName);
218 return;
219 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600220
Myung Bae78c90202024-02-19 13:39:56 -0500221 for (const auto& [adapterPath, serviceMap] : subtree)
222 {
223 std::string fabricAdapterName =
224 sdbusplus::message::object_path(adapterPath).filename();
225 if (fabricAdapterName == adapterId)
226 {
227 fabricAdapterPath = adapterPath;
228 serviceName = serviceMap.begin()->first;
229 break;
230 }
231 }
232 callback(ec, fabricAdapterPath, serviceName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600233}
234
235inline void getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500236 const std::string& adapterId,
237 std::function<void(const boost::system::error_code& ec,
238 const std::string& fabricAdapterPath,
Sunny Srivastava31791052021-03-12 10:39:16 -0600239 const std::string& serviceName)>&& callback)
240{
Sunny Srivastava31791052021-03-12 10:39:16 -0600241 constexpr std::array<std::string_view, 1> interfaces{
242 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
Myung Bae78c90202024-02-19 13:39:56 -0500243 dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces,
244 std::bind_front(afterGetValidFabricAdapterPath,
245 adapterId, std::move(callback)));
246}
Sunny Srivastava31791052021-03-12 10:39:16 -0600247
Myung Bae78c90202024-02-19 13:39:56 -0500248inline void afterHandleFabricAdapterGet(
249 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
250 const std::string& systemName, const std::string& adapterId,
251 const boost::system::error_code& ec, const std::string& fabricAdapterPath,
252 const std::string& serviceName)
253{
254 if (ec)
255 {
256 if (ec.value() == boost::system::errc::io_error)
Sunny Srivastava31791052021-03-12 10:39:16 -0600257 {
Myung Bae78c90202024-02-19 13:39:56 -0500258 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
259 adapterId);
Sunny Srivastava31791052021-03-12 10:39:16 -0600260 return;
261 }
Myung Bae78c90202024-02-19 13:39:56 -0500262
263 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
264 messages::internalError(asyncResp->res);
265 return;
266 }
267 if (fabricAdapterPath.empty() || serviceName.empty())
268 {
Ed Tanous62598e32023-07-17 17:06:25 -0700269 BMCWEB_LOG_WARNING("Adapter not found");
Ed Tanousac106bf2023-06-07 09:24:59 -0700270 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
Myung Bae78c90202024-02-19 13:39:56 -0500271 return;
272 }
273 doAdapterGet(asyncResp, systemName, adapterId, fabricAdapterPath,
274 serviceName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600275}
276
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400277inline void handleFabricAdapterGet(
278 App& app, const crow::Request& req,
279 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
280 const std::string& systemName, const std::string& adapterId)
Sunny Srivastava31791052021-03-12 10:39:16 -0600281{
Ed Tanousac106bf2023-06-07 09:24:59 -0700282 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600283 {
284 return;
285 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700286 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800287 {
288 // Option currently returns no systems. TBD
289 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
290 systemName);
291 return;
292 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700293 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500294 {
295 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
296 systemName);
297 return;
298 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600299 getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500300 adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp,
301 systemName, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600302}
303
Myung Baebe1384e2024-08-20 12:07:10 -0500304inline void afterHandleFabricAdapterPatch(
305 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
306 const std::string& adapterId, std::optional<bool> locationIndicatorActive,
307 const boost::system::error_code& ec, const std::string& fabricAdapterPath,
308 const std::string& serviceName)
309{
310 if (ec)
311 {
312 if (ec.value() == boost::system::errc::io_error)
313 {
314 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
315 adapterId);
316 return;
317 }
318
319 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
320 messages::internalError(asyncResp->res);
321 return;
322 }
323 if (fabricAdapterPath.empty() || serviceName.empty())
324 {
325 BMCWEB_LOG_WARNING("Adapter {} not found", adapterId);
326 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
327 return;
328 }
329
330 if (locationIndicatorActive)
331 {
332 setLocationIndicatorActive(asyncResp, fabricAdapterPath,
333 *locationIndicatorActive);
334 }
335}
336
337inline void handleFabricAdapterPatch(
338 App& app, const crow::Request& req,
339 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
340 const std::string& systemName, const std::string& adapterId)
341{
342 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
343 {
344 return;
345 }
346 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
347 {
348 // Option currently returns no systems. TBD
349 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
350 systemName);
351 return;
352 }
353 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
354 {
355 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
356 systemName);
357 return;
358 }
359
360 std::optional<bool> locationIndicatorActive;
361
362 if (!json_util::readJsonPatch(req, asyncResp->res,
363 "LocationIndicatorActive",
364 locationIndicatorActive))
365 {
366 return;
367 }
368
369 getValidFabricAdapterPath(
370 adapterId, std::bind_front(afterHandleFabricAdapterPatch, asyncResp,
371 adapterId, locationIndicatorActive));
372}
373
Sunny Srivastava31791052021-03-12 10:39:16 -0600374inline void handleFabricAdapterCollectionGet(
375 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700376 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600377 const std::string& systemName)
378{
Ed Tanousac106bf2023-06-07 09:24:59 -0700379 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600380 {
381 return;
382 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700383 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800384 {
385 // Option currently returns no systems. TBD
386 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
387 systemName);
388 return;
389 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700390 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600391 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700392 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
393 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600394 return;
395 }
396
Ed Tanousac106bf2023-06-07 09:24:59 -0700397 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600398 boost::beast::http::field::link,
399 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
Ed Tanousac106bf2023-06-07 09:24:59 -0700400 asyncResp->res.jsonValue["@odata.type"] =
Sunny Srivastava31791052021-03-12 10:39:16 -0600401 "#FabricAdapterCollection.FabricAdapterCollection";
Ed Tanousac106bf2023-06-07 09:24:59 -0700402 asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection";
403 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanousef4c65b2023-04-24 15:28:50 -0700404 "/redfish/v1/Systems/{}/FabricAdapters", systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600405
406 constexpr std::array<std::string_view, 1> interfaces{
407 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
408 collection_util::getCollectionMembers(
Ed Tanousac106bf2023-06-07 09:24:59 -0700409 asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -0700410 boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters",
411 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500412 interfaces, "/xyz/openbmc_project/inventory");
Sunny Srivastava31791052021-03-12 10:39:16 -0600413}
414
415inline void handleFabricAdapterCollectionHead(
416 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700417 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600418 const std::string& systemName)
419{
Ed Tanousac106bf2023-06-07 09:24:59 -0700420 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600421 {
422 return;
423 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700424 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800425 {
426 // Option currently returns no systems. TBD
427 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
428 systemName);
429 return;
430 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700431 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600432 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700433 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
434 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600435 return;
436 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700437 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600438 boost::beast::http::field::link,
439 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
440}
441
Myung Bae78c90202024-02-19 13:39:56 -0500442inline void afterHandleFabricAdapterHead(
443 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
444 const std::string& adapterId, const boost::system::error_code& ec,
445 const std::string& fabricAdapterPath, const std::string& serviceName)
446{
447 if (ec)
448 {
449 if (ec.value() == boost::system::errc::io_error)
450 {
451 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
452 adapterId);
453 return;
454 }
455
456 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
457 messages::internalError(asyncResp->res);
458 return;
459 }
460 if (fabricAdapterPath.empty() || serviceName.empty())
461 {
462 BMCWEB_LOG_WARNING("Adapter not found");
463 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
464 return;
465 }
466 asyncResp->res.addHeader(
467 boost::beast::http::field::link,
468 "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
469}
470
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400471inline void handleFabricAdapterHead(
472 crow::App& app, const crow::Request& req,
473 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
474 const std::string& systemName, const std::string& adapterId)
Sunny Srivastava31791052021-03-12 10:39:16 -0600475{
Ed Tanousac106bf2023-06-07 09:24:59 -0700476 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600477 {
478 return;
479 }
480
Ed Tanous25b54db2024-04-17 15:40:31 -0700481 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800482 {
483 // Option currently returns no systems. TBD
484 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
485 systemName);
486 return;
487 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700488 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500489 {
490 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
491 systemName);
492 return;
493 }
494 getValidFabricAdapterPath(
495 adapterId,
496 std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600497}
498
499inline void requestRoutesFabricAdapterCollection(App& app)
500{
501 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
502 .privileges(redfish::privileges::getFabricAdapterCollection)
503 .methods(boost::beast::http::verb::get)(
504 std::bind_front(handleFabricAdapterCollectionGet, std::ref(app)));
505
506 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
507 .privileges(redfish::privileges::headFabricAdapterCollection)
508 .methods(boost::beast::http::verb::head)(
509 std::bind_front(handleFabricAdapterCollectionHead, std::ref(app)));
510}
511
512inline void requestRoutesFabricAdapters(App& app)
513{
514 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
515 .privileges(redfish::privileges::getFabricAdapter)
516 .methods(boost::beast::http::verb::get)(
517 std::bind_front(handleFabricAdapterGet, std::ref(app)));
518
519 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
520 .privileges(redfish::privileges::headFabricAdapter)
521 .methods(boost::beast::http::verb::head)(
522 std::bind_front(handleFabricAdapterHead, std::ref(app)));
Myung Baebe1384e2024-08-20 12:07:10 -0500523
524 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
525 .privileges(redfish::privileges::patchFabricAdapter)
526 .methods(boost::beast::http::verb::patch)(
527 std::bind_front(handleFabricAdapterPatch, std::ref(app)));
Sunny Srivastava31791052021-03-12 10:39:16 -0600528}
529} // namespace redfish