blob: 52213c722a4a7934b7ef9ce2316af2e0853d687e [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
Ed Tanousac106bf2023-06-07 09:24:59 -0700194 getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath);
195 getFabricAdapterAsset(asyncResp, serviceName, fabricAdapterPath);
196 getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath);
197 getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath);
Myung Baebe1384e2024-08-20 12:07:10 -0500198 getLocationIndicatorActive(asyncResp, fabricAdapterPath);
Sunny Srivastava31791052021-03-12 10:39:16 -0600199}
200
Myung Bae78c90202024-02-19 13:39:56 -0500201inline void afterGetValidFabricAdapterPath(
202 const std::string& adapterId,
203 std::function<void(const boost::system::error_code&,
204 const std::string& fabricAdapterPath,
205 const std::string& serviceName)>& callback,
206 const boost::system::error_code& ec,
207 const dbus::utility::MapperGetSubTreeResponse& subtree)
Sunny Srivastava31791052021-03-12 10:39:16 -0600208{
Myung Bae78c90202024-02-19 13:39:56 -0500209 std::string fabricAdapterPath;
210 std::string serviceName;
211 if (ec)
212 {
213 callback(ec, fabricAdapterPath, serviceName);
214 return;
215 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600216
Myung Bae78c90202024-02-19 13:39:56 -0500217 for (const auto& [adapterPath, serviceMap] : subtree)
218 {
219 std::string fabricAdapterName =
220 sdbusplus::message::object_path(adapterPath).filename();
221 if (fabricAdapterName == adapterId)
222 {
223 fabricAdapterPath = adapterPath;
224 serviceName = serviceMap.begin()->first;
225 break;
226 }
227 }
228 callback(ec, fabricAdapterPath, serviceName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600229}
230
231inline void getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500232 const std::string& adapterId,
233 std::function<void(const boost::system::error_code& ec,
234 const std::string& fabricAdapterPath,
Sunny Srivastava31791052021-03-12 10:39:16 -0600235 const std::string& serviceName)>&& callback)
236{
Sunny Srivastava31791052021-03-12 10:39:16 -0600237 constexpr std::array<std::string_view, 1> interfaces{
238 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
Myung Bae78c90202024-02-19 13:39:56 -0500239 dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces,
240 std::bind_front(afterGetValidFabricAdapterPath,
241 adapterId, std::move(callback)));
242}
Sunny Srivastava31791052021-03-12 10:39:16 -0600243
Myung Bae78c90202024-02-19 13:39:56 -0500244inline void afterHandleFabricAdapterGet(
245 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
246 const std::string& systemName, const std::string& adapterId,
247 const boost::system::error_code& ec, const std::string& fabricAdapterPath,
248 const std::string& serviceName)
249{
250 if (ec)
251 {
252 if (ec.value() == boost::system::errc::io_error)
Sunny Srivastava31791052021-03-12 10:39:16 -0600253 {
Myung Bae78c90202024-02-19 13:39:56 -0500254 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
255 adapterId);
Sunny Srivastava31791052021-03-12 10:39:16 -0600256 return;
257 }
Myung Bae78c90202024-02-19 13:39:56 -0500258
259 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
260 messages::internalError(asyncResp->res);
261 return;
262 }
263 if (fabricAdapterPath.empty() || serviceName.empty())
264 {
Ed Tanous62598e32023-07-17 17:06:25 -0700265 BMCWEB_LOG_WARNING("Adapter not found");
Ed Tanousac106bf2023-06-07 09:24:59 -0700266 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
Myung Bae78c90202024-02-19 13:39:56 -0500267 return;
268 }
269 doAdapterGet(asyncResp, systemName, adapterId, fabricAdapterPath,
270 serviceName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600271}
272
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400273inline void handleFabricAdapterGet(
274 App& app, const crow::Request& req,
275 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
276 const std::string& systemName, const std::string& adapterId)
Sunny Srivastava31791052021-03-12 10:39:16 -0600277{
Ed Tanousac106bf2023-06-07 09:24:59 -0700278 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600279 {
280 return;
281 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700282 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800283 {
284 // Option currently returns no systems. TBD
285 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
286 systemName);
287 return;
288 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700289 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500290 {
291 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
292 systemName);
293 return;
294 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600295 getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500296 adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp,
297 systemName, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600298}
299
Myung Baebe1384e2024-08-20 12:07:10 -0500300inline void afterHandleFabricAdapterPatch(
301 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
302 const std::string& adapterId, std::optional<bool> locationIndicatorActive,
303 const boost::system::error_code& ec, const std::string& fabricAdapterPath,
304 const std::string& serviceName)
305{
306 if (ec)
307 {
308 if (ec.value() == boost::system::errc::io_error)
309 {
310 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
311 adapterId);
312 return;
313 }
314
315 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
316 messages::internalError(asyncResp->res);
317 return;
318 }
319 if (fabricAdapterPath.empty() || serviceName.empty())
320 {
321 BMCWEB_LOG_WARNING("Adapter {} not found", adapterId);
322 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
323 return;
324 }
325
326 if (locationIndicatorActive)
327 {
328 setLocationIndicatorActive(asyncResp, fabricAdapterPath,
329 *locationIndicatorActive);
330 }
331}
332
333inline void handleFabricAdapterPatch(
334 App& app, const crow::Request& req,
335 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
336 const std::string& systemName, const std::string& adapterId)
337{
338 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
339 {
340 return;
341 }
342 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
343 {
344 // Option currently returns no systems. TBD
345 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
346 systemName);
347 return;
348 }
349 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
350 {
351 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
352 systemName);
353 return;
354 }
355
356 std::optional<bool> locationIndicatorActive;
357
358 if (!json_util::readJsonPatch(req, asyncResp->res,
359 "LocationIndicatorActive",
360 locationIndicatorActive))
361 {
362 return;
363 }
364
365 getValidFabricAdapterPath(
366 adapterId, std::bind_front(afterHandleFabricAdapterPatch, asyncResp,
367 adapterId, locationIndicatorActive));
368}
369
Sunny Srivastava31791052021-03-12 10:39:16 -0600370inline void handleFabricAdapterCollectionGet(
371 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700372 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600373 const std::string& systemName)
374{
Ed Tanousac106bf2023-06-07 09:24:59 -0700375 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600376 {
377 return;
378 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700379 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800380 {
381 // Option currently returns no systems. TBD
382 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
383 systemName);
384 return;
385 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700386 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600387 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700388 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
389 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600390 return;
391 }
392
Ed Tanousac106bf2023-06-07 09:24:59 -0700393 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600394 boost::beast::http::field::link,
395 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
Ed Tanousac106bf2023-06-07 09:24:59 -0700396 asyncResp->res.jsonValue["@odata.type"] =
Sunny Srivastava31791052021-03-12 10:39:16 -0600397 "#FabricAdapterCollection.FabricAdapterCollection";
Ed Tanousac106bf2023-06-07 09:24:59 -0700398 asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection";
399 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanousef4c65b2023-04-24 15:28:50 -0700400 "/redfish/v1/Systems/{}/FabricAdapters", systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600401
402 constexpr std::array<std::string_view, 1> interfaces{
403 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
404 collection_util::getCollectionMembers(
Ed Tanousac106bf2023-06-07 09:24:59 -0700405 asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -0700406 boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters",
407 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500408 interfaces, "/xyz/openbmc_project/inventory");
Sunny Srivastava31791052021-03-12 10:39:16 -0600409}
410
411inline void handleFabricAdapterCollectionHead(
412 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700413 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600414 const std::string& systemName)
415{
Ed Tanousac106bf2023-06-07 09:24:59 -0700416 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600417 {
418 return;
419 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700420 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800421 {
422 // Option currently returns no systems. TBD
423 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
424 systemName);
425 return;
426 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700427 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600428 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700429 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
430 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600431 return;
432 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700433 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600434 boost::beast::http::field::link,
435 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
436}
437
Myung Bae78c90202024-02-19 13:39:56 -0500438inline void afterHandleFabricAdapterHead(
439 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
440 const std::string& adapterId, const boost::system::error_code& ec,
441 const std::string& fabricAdapterPath, const std::string& serviceName)
442{
443 if (ec)
444 {
445 if (ec.value() == boost::system::errc::io_error)
446 {
447 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
448 adapterId);
449 return;
450 }
451
452 BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
453 messages::internalError(asyncResp->res);
454 return;
455 }
456 if (fabricAdapterPath.empty() || serviceName.empty())
457 {
458 BMCWEB_LOG_WARNING("Adapter not found");
459 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
460 return;
461 }
462 asyncResp->res.addHeader(
463 boost::beast::http::field::link,
464 "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
465}
466
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400467inline void handleFabricAdapterHead(
468 crow::App& app, const crow::Request& req,
469 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
470 const std::string& systemName, const std::string& adapterId)
Sunny Srivastava31791052021-03-12 10:39:16 -0600471{
Ed Tanousac106bf2023-06-07 09:24:59 -0700472 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600473 {
474 return;
475 }
476
Ed Tanous25b54db2024-04-17 15:40:31 -0700477 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800478 {
479 // Option currently returns no systems. TBD
480 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
481 systemName);
482 return;
483 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700484 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500485 {
486 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
487 systemName);
488 return;
489 }
490 getValidFabricAdapterPath(
491 adapterId,
492 std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600493}
494
495inline void requestRoutesFabricAdapterCollection(App& app)
496{
497 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
498 .privileges(redfish::privileges::getFabricAdapterCollection)
499 .methods(boost::beast::http::verb::get)(
500 std::bind_front(handleFabricAdapterCollectionGet, std::ref(app)));
501
502 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
503 .privileges(redfish::privileges::headFabricAdapterCollection)
504 .methods(boost::beast::http::verb::head)(
505 std::bind_front(handleFabricAdapterCollectionHead, std::ref(app)));
506}
507
508inline void requestRoutesFabricAdapters(App& app)
509{
510 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
511 .privileges(redfish::privileges::getFabricAdapter)
512 .methods(boost::beast::http::verb::get)(
513 std::bind_front(handleFabricAdapterGet, std::ref(app)));
514
515 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
516 .privileges(redfish::privileges::headFabricAdapter)
517 .methods(boost::beast::http::verb::head)(
518 std::bind_front(handleFabricAdapterHead, std::ref(app)));
Myung Baebe1384e2024-08-20 12:07:10 -0500519
520 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
521 .privileges(redfish::privileges::patchFabricAdapter)
522 .methods(boost::beast::http::verb::patch)(
523 std::bind_front(handleFabricAdapterPatch, std::ref(app)));
Sunny Srivastava31791052021-03-12 10:39:16 -0600524}
525} // namespace redfish