xref: /openbmc/bmcweb/redfish-core/lib/fabric_adapters.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
33179105bSSunny Srivastava #pragma once
43179105bSSunny Srivastava 
53179105bSSunny Srivastava #include "app.hpp"
63179105bSSunny Srivastava #include "dbus_utility.hpp"
7539d8c6bSEd Tanous #include "generated/enums/resource.hpp"
8a8e884fcSEd Tanous #include "query.hpp"
9a8e884fcSEd Tanous #include "registries/privilege_registry.hpp"
103179105bSSunny Srivastava #include "utils/collection.hpp"
116177a301SLakshmi Yadlapati #include "utils/dbus_utils.hpp"
123179105bSSunny Srivastava #include "utils/json_utils.hpp"
133179105bSSunny Srivastava 
143179105bSSunny Srivastava #include <boost/system/error_code.hpp>
15ef4c65b7SEd Tanous #include <boost/url/format.hpp>
16f05e9169SGunnar Mills #include <sdbusplus/asio/property.hpp>
176177a301SLakshmi Yadlapati #include <sdbusplus/unpack_properties.hpp>
183179105bSSunny Srivastava 
193179105bSSunny Srivastava #include <array>
203179105bSSunny Srivastava #include <functional>
213179105bSSunny Srivastava #include <memory>
2278c90203SMyung Bae #include <optional>
233179105bSSunny Srivastava #include <string>
243179105bSSunny Srivastava #include <string_view>
253179105bSSunny Srivastava 
263179105bSSunny Srivastava namespace redfish
273179105bSSunny Srivastava {
283179105bSSunny Srivastava 
getFabricAdapterLocation(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & serviceName,const std::string & fabricAdapterPath)29ac106bf6SEd Tanous inline void getFabricAdapterLocation(
30ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
31ac106bf6SEd Tanous     const std::string& serviceName, const std::string& fabricAdapterPath)
3253ffeca5SLakshmi Yadlapati {
33deae6a78SEd Tanous     dbus::utility::getProperty<std::string>(
34deae6a78SEd Tanous         serviceName, fabricAdapterPath,
3553ffeca5SLakshmi Yadlapati         "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
36ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
3753ffeca5SLakshmi Yadlapati                     const std::string& property) {
3853ffeca5SLakshmi Yadlapati             if (ec)
3953ffeca5SLakshmi Yadlapati             {
4053ffeca5SLakshmi Yadlapati                 if (ec.value() != EBADR)
4153ffeca5SLakshmi Yadlapati                 {
4262598e31SEd Tanous                     BMCWEB_LOG_ERROR("DBUS response error for Location");
43ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
4453ffeca5SLakshmi Yadlapati                 }
4553ffeca5SLakshmi Yadlapati                 return;
4653ffeca5SLakshmi Yadlapati             }
4753ffeca5SLakshmi Yadlapati 
48bd79bce8SPatrick Williams             asyncResp->res
49bd79bce8SPatrick Williams                 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
5053ffeca5SLakshmi Yadlapati                 property;
5153ffeca5SLakshmi Yadlapati         });
5253ffeca5SLakshmi Yadlapati }
5353ffeca5SLakshmi Yadlapati 
getFabricAdapterAsset(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & serviceName,const std::string & fabricAdapterPath)54bd79bce8SPatrick Williams inline void getFabricAdapterAsset(
55bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
56bd79bce8SPatrick Williams     const std::string& serviceName, const std::string& fabricAdapterPath)
576369421dSLakshmi Yadlapati {
58deae6a78SEd Tanous     dbus::utility::getAllProperties(
59deae6a78SEd Tanous         serviceName, fabricAdapterPath,
606369421dSLakshmi Yadlapati         "xyz.openbmc_project.Inventory.Decorator.Asset",
61ac106bf6SEd Tanous         [fabricAdapterPath, asyncResp{asyncResp}](
62ac106bf6SEd Tanous             const boost::system::error_code& ec,
636369421dSLakshmi Yadlapati             const dbus::utility::DBusPropertiesMap& propertiesList) {
646369421dSLakshmi Yadlapati             if (ec)
656369421dSLakshmi Yadlapati             {
666369421dSLakshmi Yadlapati                 if (ec.value() != EBADR)
676369421dSLakshmi Yadlapati                 {
6862598e31SEd Tanous                     BMCWEB_LOG_ERROR("DBUS response error for Properties");
69ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
706369421dSLakshmi Yadlapati                 }
716369421dSLakshmi Yadlapati                 return;
726369421dSLakshmi Yadlapati             }
736369421dSLakshmi Yadlapati 
746369421dSLakshmi Yadlapati             const std::string* serialNumber = nullptr;
756369421dSLakshmi Yadlapati             const std::string* model = nullptr;
766369421dSLakshmi Yadlapati             const std::string* partNumber = nullptr;
776369421dSLakshmi Yadlapati             const std::string* sparePartNumber = nullptr;
786369421dSLakshmi Yadlapati 
796369421dSLakshmi Yadlapati             const bool success = sdbusplus::unpackPropertiesNoThrow(
80bd79bce8SPatrick Williams                 dbus_utils::UnpackErrorPrinter(), propertiesList,
81bd79bce8SPatrick Williams                 "SerialNumber", serialNumber, "Model", model, "PartNumber",
82bd79bce8SPatrick Williams                 partNumber, "SparePartNumber", sparePartNumber);
836369421dSLakshmi Yadlapati 
846369421dSLakshmi Yadlapati             if (!success)
856369421dSLakshmi Yadlapati             {
86ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
876369421dSLakshmi Yadlapati                 return;
886369421dSLakshmi Yadlapati             }
896369421dSLakshmi Yadlapati 
906369421dSLakshmi Yadlapati             if (serialNumber != nullptr)
916369421dSLakshmi Yadlapati             {
92ac106bf6SEd Tanous                 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
936369421dSLakshmi Yadlapati             }
946369421dSLakshmi Yadlapati 
956369421dSLakshmi Yadlapati             if (model != nullptr)
966369421dSLakshmi Yadlapati             {
97ac106bf6SEd Tanous                 asyncResp->res.jsonValue["Model"] = *model;
986369421dSLakshmi Yadlapati             }
996369421dSLakshmi Yadlapati 
1006369421dSLakshmi Yadlapati             if (partNumber != nullptr)
1016369421dSLakshmi Yadlapati             {
102ac106bf6SEd Tanous                 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
1036369421dSLakshmi Yadlapati             }
1046369421dSLakshmi Yadlapati 
1056369421dSLakshmi Yadlapati             if (sparePartNumber != nullptr && !sparePartNumber->empty())
1066369421dSLakshmi Yadlapati             {
107ac106bf6SEd Tanous                 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
1086369421dSLakshmi Yadlapati             }
1096369421dSLakshmi Yadlapati         });
1106369421dSLakshmi Yadlapati }
1116369421dSLakshmi Yadlapati 
getFabricAdapterState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & serviceName,const std::string & fabricAdapterPath)112bd79bce8SPatrick Williams inline void getFabricAdapterState(
113bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
114bd79bce8SPatrick Williams     const std::string& serviceName, const std::string& fabricAdapterPath)
115cd7af44fSLakshmi Yadlapati {
116deae6a78SEd Tanous     dbus::utility::getProperty<bool>(
117deae6a78SEd Tanous         serviceName, fabricAdapterPath, "xyz.openbmc_project.Inventory.Item",
118deae6a78SEd Tanous         "Present",
119ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool present) {
120cd7af44fSLakshmi Yadlapati             if (ec)
121cd7af44fSLakshmi Yadlapati             {
122cd7af44fSLakshmi Yadlapati                 if (ec.value() != EBADR)
123cd7af44fSLakshmi Yadlapati                 {
12462598e31SEd Tanous                     BMCWEB_LOG_ERROR("DBUS response error for State");
125ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
126cd7af44fSLakshmi Yadlapati                 }
127cd7af44fSLakshmi Yadlapati                 return;
128cd7af44fSLakshmi Yadlapati             }
129cd7af44fSLakshmi Yadlapati 
130cd7af44fSLakshmi Yadlapati             if (!present)
131cd7af44fSLakshmi Yadlapati             {
132539d8c6bSEd Tanous                 asyncResp->res.jsonValue["Status"]["State"] =
133539d8c6bSEd Tanous                     resource::State::Absent;
134cd7af44fSLakshmi Yadlapati             }
135cd7af44fSLakshmi Yadlapati         });
136cd7af44fSLakshmi Yadlapati }
137cd7af44fSLakshmi Yadlapati 
getFabricAdapterHealth(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & serviceName,const std::string & fabricAdapterPath)138bd79bce8SPatrick Williams inline void getFabricAdapterHealth(
139bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
140bd79bce8SPatrick Williams     const std::string& serviceName, const std::string& fabricAdapterPath)
1417da847b6SLakshmi Yadlapati {
142deae6a78SEd Tanous     dbus::utility::getProperty<bool>(
143deae6a78SEd Tanous         serviceName, fabricAdapterPath,
1447da847b6SLakshmi Yadlapati         "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
145ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec,
146ac106bf6SEd Tanous                     const bool functional) {
1477da847b6SLakshmi Yadlapati             if (ec)
1487da847b6SLakshmi Yadlapati             {
1497da847b6SLakshmi Yadlapati                 if (ec.value() != EBADR)
1507da847b6SLakshmi Yadlapati                 {
15162598e31SEd Tanous                     BMCWEB_LOG_ERROR("DBUS response error for Health");
152ac106bf6SEd Tanous                     messages::internalError(asyncResp->res);
1537da847b6SLakshmi Yadlapati                 }
1547da847b6SLakshmi Yadlapati                 return;
1557da847b6SLakshmi Yadlapati             }
1567da847b6SLakshmi Yadlapati 
1577da847b6SLakshmi Yadlapati             if (!functional)
1587da847b6SLakshmi Yadlapati             {
159539d8c6bSEd Tanous                 asyncResp->res.jsonValue["Status"]["Health"] =
160539d8c6bSEd Tanous                     resource::Health::Critical;
1617da847b6SLakshmi Yadlapati             }
1627da847b6SLakshmi Yadlapati         });
1637da847b6SLakshmi Yadlapati }
1647da847b6SLakshmi Yadlapati 
doAdapterGet(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & adapterId,const std::string & fabricAdapterPath,const std::string & serviceName)165bd79bce8SPatrick Williams inline void doAdapterGet(
166bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
167bd79bce8SPatrick Williams     const std::string& systemName, const std::string& adapterId,
168bd79bce8SPatrick Williams     const std::string& fabricAdapterPath, const std::string& serviceName)
1693179105bSSunny Srivastava {
170ac106bf6SEd Tanous     asyncResp->res.addHeader(
1713179105bSSunny Srivastava         boost::beast::http::field::link,
1723179105bSSunny Srivastava         "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
173ac106bf6SEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
174ac106bf6SEd Tanous         "#FabricAdapter.v1_4_0.FabricAdapter";
175ac106bf6SEd Tanous     asyncResp->res.jsonValue["Name"] = "Fabric Adapter";
176ac106bf6SEd Tanous     asyncResp->res.jsonValue["Id"] = adapterId;
177ac106bf6SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
178ef4c65b7SEd Tanous         "/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId);
17953ffeca5SLakshmi Yadlapati 
180539d8c6bSEd Tanous     asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
181539d8c6bSEd Tanous     asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
182cd7af44fSLakshmi Yadlapati 
183ac106bf6SEd Tanous     getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath);
184ac106bf6SEd Tanous     getFabricAdapterAsset(asyncResp, serviceName, fabricAdapterPath);
185ac106bf6SEd Tanous     getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath);
186ac106bf6SEd Tanous     getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath);
1873179105bSSunny Srivastava }
1883179105bSSunny Srivastava 
afterGetValidFabricAdapterPath(const std::string & adapterId,std::function<void (const boost::system::error_code &,const std::string & fabricAdapterPath,const std::string & serviceName)> & callback,const boost::system::error_code & ec,const dbus::utility::MapperGetSubTreeResponse & subtree)18978c90203SMyung Bae inline void afterGetValidFabricAdapterPath(
19078c90203SMyung Bae     const std::string& adapterId,
19178c90203SMyung Bae     std::function<void(const boost::system::error_code&,
19278c90203SMyung Bae                        const std::string& fabricAdapterPath,
19378c90203SMyung Bae                        const std::string& serviceName)>& callback,
19478c90203SMyung Bae     const boost::system::error_code& ec,
19578c90203SMyung Bae     const dbus::utility::MapperGetSubTreeResponse& subtree)
19678c90203SMyung Bae {
19778c90203SMyung Bae     std::string fabricAdapterPath;
19878c90203SMyung Bae     std::string serviceName;
19978c90203SMyung Bae     if (ec)
20078c90203SMyung Bae     {
20178c90203SMyung Bae         callback(ec, fabricAdapterPath, serviceName);
20278c90203SMyung Bae         return;
20378c90203SMyung Bae     }
20478c90203SMyung Bae 
20578c90203SMyung Bae     for (const auto& [adapterPath, serviceMap] : subtree)
2063179105bSSunny Srivastava     {
2073179105bSSunny Srivastava         std::string fabricAdapterName =
2083179105bSSunny Srivastava             sdbusplus::message::object_path(adapterPath).filename();
20978c90203SMyung Bae         if (fabricAdapterName == adapterId)
21078c90203SMyung Bae         {
21178c90203SMyung Bae             fabricAdapterPath = adapterPath;
21278c90203SMyung Bae             serviceName = serviceMap.begin()->first;
21378c90203SMyung Bae             break;
21478c90203SMyung Bae         }
21578c90203SMyung Bae     }
21678c90203SMyung Bae     callback(ec, fabricAdapterPath, serviceName);
2173179105bSSunny Srivastava }
2183179105bSSunny Srivastava 
getValidFabricAdapterPath(const std::string & adapterId,std::function<void (const boost::system::error_code & ec,const std::string & fabricAdapterPath,const std::string & serviceName)> && callback)2193179105bSSunny Srivastava inline void getValidFabricAdapterPath(
22078c90203SMyung Bae     const std::string& adapterId,
22178c90203SMyung Bae     std::function<void(const boost::system::error_code& ec,
22278c90203SMyung Bae                        const std::string& fabricAdapterPath,
2233179105bSSunny Srivastava                        const std::string& serviceName)>&& callback)
2243179105bSSunny Srivastava {
2253179105bSSunny Srivastava     constexpr std::array<std::string_view, 1> interfaces{
2263179105bSSunny Srivastava         "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
22778c90203SMyung Bae     dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces,
22878c90203SMyung Bae                               std::bind_front(afterGetValidFabricAdapterPath,
22978c90203SMyung Bae                                               adapterId, std::move(callback)));
23078c90203SMyung Bae }
2313179105bSSunny Srivastava 
afterHandleFabricAdapterGet(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & adapterId,const boost::system::error_code & ec,const std::string & fabricAdapterPath,const std::string & serviceName)23278c90203SMyung Bae inline void afterHandleFabricAdapterGet(
23378c90203SMyung Bae     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23478c90203SMyung Bae     const std::string& systemName, const std::string& adapterId,
23578c90203SMyung Bae     const boost::system::error_code& ec, const std::string& fabricAdapterPath,
23678c90203SMyung Bae     const std::string& serviceName)
23778c90203SMyung Bae {
2383179105bSSunny Srivastava     if (ec)
2393179105bSSunny Srivastava     {
24078c90203SMyung Bae         if (ec.value() == boost::system::errc::io_error)
24178c90203SMyung Bae         {
24278c90203SMyung Bae             messages::resourceNotFound(asyncResp->res, "FabricAdapter",
24378c90203SMyung Bae                                        adapterId);
2443179105bSSunny Srivastava             return;
2453179105bSSunny Srivastava         }
24678c90203SMyung Bae 
24778c90203SMyung Bae         BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
24878c90203SMyung Bae         messages::internalError(asyncResp->res);
2493179105bSSunny Srivastava         return;
2503179105bSSunny Srivastava     }
25178c90203SMyung Bae     if (fabricAdapterPath.empty() || serviceName.empty())
25278c90203SMyung Bae     {
25362598e31SEd Tanous         BMCWEB_LOG_WARNING("Adapter not found");
254ac106bf6SEd Tanous         messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
25578c90203SMyung Bae         return;
25678c90203SMyung Bae     }
25778c90203SMyung Bae     doAdapterGet(asyncResp, systemName, adapterId, fabricAdapterPath,
25878c90203SMyung Bae                  serviceName);
2593179105bSSunny Srivastava }
2603179105bSSunny Srivastava 
handleFabricAdapterGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & adapterId)261bd79bce8SPatrick Williams inline void handleFabricAdapterGet(
262bd79bce8SPatrick Williams     App& app, const crow::Request& req,
263ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
264bd79bce8SPatrick Williams     const std::string& systemName, const std::string& adapterId)
2653179105bSSunny Srivastava {
266ac106bf6SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2673179105bSSunny Srivastava     {
2683179105bSSunny Srivastava         return;
2693179105bSSunny Srivastava     }
27025b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2717f3e84a1SEd Tanous     {
2727f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
2737f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2747f3e84a1SEd Tanous                                    systemName);
2757f3e84a1SEd Tanous         return;
2767f3e84a1SEd Tanous     }
277253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
27878c90203SMyung Bae     {
27978c90203SMyung Bae         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
28078c90203SMyung Bae                                    systemName);
28178c90203SMyung Bae         return;
28278c90203SMyung Bae     }
2833179105bSSunny Srivastava     getValidFabricAdapterPath(
28478c90203SMyung Bae         adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp,
28578c90203SMyung Bae                                    systemName, adapterId));
2863179105bSSunny Srivastava }
2873179105bSSunny Srivastava 
handleFabricAdapterCollectionGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)2883179105bSSunny Srivastava inline void handleFabricAdapterCollectionGet(
2893179105bSSunny Srivastava     crow::App& app, const crow::Request& req,
290ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2913179105bSSunny Srivastava     const std::string& systemName)
2923179105bSSunny Srivastava {
293ac106bf6SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2943179105bSSunny Srivastava     {
2953179105bSSunny Srivastava         return;
2963179105bSSunny Srivastava     }
29725b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
2987f3e84a1SEd Tanous     {
2997f3e84a1SEd Tanous         // Option currently returns no systems. TBD
3007f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3017f3e84a1SEd Tanous                                    systemName);
3027f3e84a1SEd Tanous         return;
3037f3e84a1SEd Tanous     }
304253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3053179105bSSunny Srivastava     {
306ac106bf6SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
307ac106bf6SEd Tanous                                    systemName);
3083179105bSSunny Srivastava         return;
3093179105bSSunny Srivastava     }
3103179105bSSunny Srivastava 
311ac106bf6SEd Tanous     asyncResp->res.addHeader(
3123179105bSSunny Srivastava         boost::beast::http::field::link,
3133179105bSSunny Srivastava         "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
314ac106bf6SEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
3153179105bSSunny Srivastava         "#FabricAdapterCollection.FabricAdapterCollection";
316ac106bf6SEd Tanous     asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection";
317ac106bf6SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
318ef4c65b7SEd Tanous         "/redfish/v1/Systems/{}/FabricAdapters", systemName);
3193179105bSSunny Srivastava 
3203179105bSSunny Srivastava     constexpr std::array<std::string_view, 1> interfaces{
3213179105bSSunny Srivastava         "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
3223179105bSSunny Srivastava     collection_util::getCollectionMembers(
323ac106bf6SEd Tanous         asyncResp,
324253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters",
325253f11b8SEd Tanous                             BMCWEB_REDFISH_SYSTEM_URI_NAME),
32636b5f1edSLakshmi Yadlapati         interfaces, "/xyz/openbmc_project/inventory");
3273179105bSSunny Srivastava }
3283179105bSSunny Srivastava 
handleFabricAdapterCollectionHead(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)3293179105bSSunny Srivastava inline void handleFabricAdapterCollectionHead(
3303179105bSSunny Srivastava     crow::App& app, const crow::Request& req,
331ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3323179105bSSunny Srivastava     const std::string& systemName)
3333179105bSSunny Srivastava {
334ac106bf6SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3353179105bSSunny Srivastava     {
3363179105bSSunny Srivastava         return;
3373179105bSSunny Srivastava     }
33825b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
3397f3e84a1SEd Tanous     {
3407f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
3417f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3427f3e84a1SEd Tanous                                    systemName);
3437f3e84a1SEd Tanous         return;
3447f3e84a1SEd Tanous     }
345253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3463179105bSSunny Srivastava     {
347ac106bf6SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
348ac106bf6SEd Tanous                                    systemName);
3493179105bSSunny Srivastava         return;
3503179105bSSunny Srivastava     }
351ac106bf6SEd Tanous     asyncResp->res.addHeader(
3523179105bSSunny Srivastava         boost::beast::http::field::link,
3533179105bSSunny Srivastava         "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
3543179105bSSunny Srivastava }
3553179105bSSunny Srivastava 
afterHandleFabricAdapterHead(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & adapterId,const boost::system::error_code & ec,const std::string & fabricAdapterPath,const std::string & serviceName)35678c90203SMyung Bae inline void afterHandleFabricAdapterHead(
35778c90203SMyung Bae     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
35878c90203SMyung Bae     const std::string& adapterId, const boost::system::error_code& ec,
35978c90203SMyung Bae     const std::string& fabricAdapterPath, const std::string& serviceName)
36078c90203SMyung Bae {
36178c90203SMyung Bae     if (ec)
36278c90203SMyung Bae     {
36378c90203SMyung Bae         if (ec.value() == boost::system::errc::io_error)
36478c90203SMyung Bae         {
36578c90203SMyung Bae             messages::resourceNotFound(asyncResp->res, "FabricAdapter",
36678c90203SMyung Bae                                        adapterId);
36778c90203SMyung Bae             return;
36878c90203SMyung Bae         }
36978c90203SMyung Bae 
37078c90203SMyung Bae         BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
37178c90203SMyung Bae         messages::internalError(asyncResp->res);
37278c90203SMyung Bae         return;
37378c90203SMyung Bae     }
37478c90203SMyung Bae     if (fabricAdapterPath.empty() || serviceName.empty())
37578c90203SMyung Bae     {
37678c90203SMyung Bae         BMCWEB_LOG_WARNING("Adapter not found");
37778c90203SMyung Bae         messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
37878c90203SMyung Bae         return;
37978c90203SMyung Bae     }
38078c90203SMyung Bae     asyncResp->res.addHeader(
38178c90203SMyung Bae         boost::beast::http::field::link,
38278c90203SMyung Bae         "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
38378c90203SMyung Bae }
38478c90203SMyung Bae 
handleFabricAdapterHead(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName,const std::string & adapterId)385bd79bce8SPatrick Williams inline void handleFabricAdapterHead(
386bd79bce8SPatrick Williams     crow::App& app, const crow::Request& req,
387ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
388bd79bce8SPatrick Williams     const std::string& systemName, const std::string& adapterId)
3893179105bSSunny Srivastava {
390ac106bf6SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3913179105bSSunny Srivastava     {
3923179105bSSunny Srivastava         return;
3933179105bSSunny Srivastava     }
3943179105bSSunny Srivastava 
39525b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
3967f3e84a1SEd Tanous     {
3977f3e84a1SEd Tanous         // Option currently returns no systems. TBD
3987f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3997f3e84a1SEd Tanous                                    systemName);
4007f3e84a1SEd Tanous         return;
4017f3e84a1SEd Tanous     }
402253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
40378c90203SMyung Bae     {
40478c90203SMyung Bae         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
40578c90203SMyung Bae                                    systemName);
40678c90203SMyung Bae         return;
40778c90203SMyung Bae     }
40878c90203SMyung Bae     getValidFabricAdapterPath(
40978c90203SMyung Bae         adapterId,
41078c90203SMyung Bae         std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId));
4113179105bSSunny Srivastava }
4123179105bSSunny Srivastava 
requestRoutesFabricAdapterCollection(App & app)4133179105bSSunny Srivastava inline void requestRoutesFabricAdapterCollection(App& app)
4143179105bSSunny Srivastava {
4153179105bSSunny Srivastava     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
4163179105bSSunny Srivastava         .privileges(redfish::privileges::getFabricAdapterCollection)
4173179105bSSunny Srivastava         .methods(boost::beast::http::verb::get)(
4183179105bSSunny Srivastava             std::bind_front(handleFabricAdapterCollectionGet, std::ref(app)));
4193179105bSSunny Srivastava 
4203179105bSSunny Srivastava     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/")
4213179105bSSunny Srivastava         .privileges(redfish::privileges::headFabricAdapterCollection)
4223179105bSSunny Srivastava         .methods(boost::beast::http::verb::head)(
4233179105bSSunny Srivastava             std::bind_front(handleFabricAdapterCollectionHead, std::ref(app)));
4243179105bSSunny Srivastava }
4253179105bSSunny Srivastava 
requestRoutesFabricAdapters(App & app)4263179105bSSunny Srivastava inline void requestRoutesFabricAdapters(App& app)
4273179105bSSunny Srivastava {
4283179105bSSunny Srivastava     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
4293179105bSSunny Srivastava         .privileges(redfish::privileges::getFabricAdapter)
4303179105bSSunny Srivastava         .methods(boost::beast::http::verb::get)(
4313179105bSSunny Srivastava             std::bind_front(handleFabricAdapterGet, std::ref(app)));
4323179105bSSunny Srivastava 
4333179105bSSunny Srivastava     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/")
4343179105bSSunny Srivastava         .privileges(redfish::privileges::headFabricAdapter)
4353179105bSSunny Srivastava         .methods(boost::beast::http::verb::head)(
4363179105bSSunny Srivastava             std::bind_front(handleFabricAdapterHead, std::ref(app)));
4373179105bSSunny Srivastava }
4383179105bSSunny Srivastava } // namespace redfish
439