1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation 4a25aeccfSNikhil Potade #pragma once 5a25aeccfSNikhil Potade 613451e39SWilly Tu #include "bmcweb_config.h" 713451e39SWilly Tu 83ccb3adbSEd Tanous #include "app.hpp" 97a1dbc48SGeorge Liu #include "dbus_utility.hpp" 10e5029d88SJohn Edward Broadbent #include "generated/enums/drive.hpp" 11dde9bc12SGeorge Liu #include "generated/enums/protocol.hpp" 12539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 13a8e884fcSEd Tanous #include "human_sort.hpp" 143ccb3adbSEd Tanous #include "query.hpp" 15a8e884fcSEd Tanous #include "redfish_util.hpp" 163ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 175e577bc1SWilly Tu #include "utils/collection.hpp" 183ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 192ad9c2f6SJames Feist 20e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 21ef4c65b7SEd Tanous #include <boost/url/format.hpp> 221e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 23d1bde9e5SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 24a25aeccfSNikhil Potade 257a1dbc48SGeorge Liu #include <array> 263544d2a7SEd Tanous #include <ranges> 277a1dbc48SGeorge Liu #include <string_view> 287a1dbc48SGeorge Liu 29a25aeccfSNikhil Potade namespace redfish 30a25aeccfSNikhil Potade { 3136d52334SEd Tanous 3236d52334SEd Tanous inline void handleSystemsStorageCollectionGet( 3336d52334SEd Tanous App& app, const crow::Request& req, 3422d268cbSEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3536d52334SEd Tanous const std::string& systemName) 3636d52334SEd Tanous { 373ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 3845ca1b86SEd Tanous { 3945ca1b86SEd Tanous return; 4045ca1b86SEd Tanous } 41253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 4222d268cbSEd Tanous { 4322d268cbSEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 4422d268cbSEd Tanous systemName); 4522d268cbSEd Tanous return; 4622d268cbSEd Tanous } 4722d268cbSEd Tanous 488d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 498d1b46d7Szhanghch05 "#StorageCollection.StorageCollection"; 50253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = std::format( 51253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME); 528d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Storage Collection"; 535e577bc1SWilly Tu 545e577bc1SWilly Tu constexpr std::array<std::string_view, 1> interface{ 555a39f77aSPatrick Williams "xyz.openbmc_project.Inventory.Item.Storage"}; 565e577bc1SWilly Tu collection_util::getCollectionMembers( 57253f11b8SEd Tanous asyncResp, 58253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage", 59253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME), 6036b5f1edSLakshmi Yadlapati interface, "/xyz/openbmc_project/inventory"); 615e577bc1SWilly Tu } 625e577bc1SWilly Tu 635e577bc1SWilly Tu inline void handleStorageCollectionGet( 645e577bc1SWilly Tu App& app, const crow::Request& req, 655e577bc1SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 665e577bc1SWilly Tu { 675e577bc1SWilly Tu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 685e577bc1SWilly Tu { 695e577bc1SWilly Tu return; 705e577bc1SWilly Tu } 715e577bc1SWilly Tu asyncResp->res.jsonValue["@odata.type"] = 725e577bc1SWilly Tu "#StorageCollection.StorageCollection"; 735e577bc1SWilly Tu asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Storage"; 745e577bc1SWilly Tu asyncResp->res.jsonValue["Name"] = "Storage Collection"; 755e577bc1SWilly Tu constexpr std::array<std::string_view, 1> interface{ 765a39f77aSPatrick Williams "xyz.openbmc_project.Inventory.Item.Storage"}; 775e577bc1SWilly Tu collection_util::getCollectionMembers( 7836b5f1edSLakshmi Yadlapati asyncResp, boost::urls::format("/redfish/v1/Storage"), interface, 7936b5f1edSLakshmi Yadlapati "/xyz/openbmc_project/inventory"); 80a25aeccfSNikhil Potade } 81a25aeccfSNikhil Potade 8236d52334SEd Tanous inline void requestRoutesStorageCollection(App& app) 83a25aeccfSNikhil Potade { 8436d52334SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/") 8536d52334SEd Tanous .privileges(redfish::privileges::getStorageCollection) 8636d52334SEd Tanous .methods(boost::beast::http::verb::get)( 8736d52334SEd Tanous std::bind_front(handleSystemsStorageCollectionGet, std::ref(app))); 885e577bc1SWilly Tu BMCWEB_ROUTE(app, "/redfish/v1/Storage/") 895e577bc1SWilly Tu .privileges(redfish::privileges::getStorageCollection) 905e577bc1SWilly Tu .methods(boost::beast::http::verb::get)( 915e577bc1SWilly Tu std::bind_front(handleStorageCollectionGet, std::ref(app))); 9236d52334SEd Tanous } 9336d52334SEd Tanous 9436d52334SEd Tanous inline void afterChassisDriveCollectionSubtree( 9536d52334SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 967a1dbc48SGeorge Liu const boost::system::error_code& ec, 9736d52334SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& driveList) 9836d52334SEd Tanous { 99a25aeccfSNikhil Potade if (ec) 100a25aeccfSNikhil Potade { 10162598e31SEd Tanous BMCWEB_LOG_ERROR("Drive mapper call error"); 102a25aeccfSNikhil Potade messages::internalError(asyncResp->res); 103a25aeccfSNikhil Potade return; 104a25aeccfSNikhil Potade } 1052ad9c2f6SJames Feist 106a85afbe1SWilly Tu nlohmann::json& driveArray = asyncResp->res.jsonValue["Drives"]; 107a85afbe1SWilly Tu driveArray = nlohmann::json::array(); 108a85afbe1SWilly Tu auto& count = asyncResp->res.jsonValue["Drives@odata.count"]; 109a85afbe1SWilly Tu count = 0; 1102ad9c2f6SJames Feist 111a85afbe1SWilly Tu for (const std::string& drive : driveList) 112a25aeccfSNikhil Potade { 113a85afbe1SWilly Tu sdbusplus::message::object_path object(drive); 114a85afbe1SWilly Tu if (object.filename().empty()) 115a25aeccfSNikhil Potade { 11662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find filename in {}", drive); 117a85afbe1SWilly Tu return; 118a25aeccfSNikhil Potade } 119a85afbe1SWilly Tu 120a85afbe1SWilly Tu nlohmann::json::object_t driveJson; 121ef4c65b7SEd Tanous driveJson["@odata.id"] = boost::urls::format( 122253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage/1/Drives/{}", 123253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, object.filename()); 124b2ba3072SPatrick Williams driveArray.emplace_back(std::move(driveJson)); 125a25aeccfSNikhil Potade } 126a25aeccfSNikhil Potade 127a85afbe1SWilly Tu count = driveArray.size(); 12836d52334SEd Tanous } 1297ac13cc9SGunnar Mills inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 13036d52334SEd Tanous { 13136d52334SEd Tanous const std::array<std::string_view, 1> interfaces = { 13236d52334SEd Tanous "xyz.openbmc_project.Inventory.Item.Drive"}; 13336d52334SEd Tanous dbus::utility::getSubTreePaths( 13436d52334SEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces, 1357ac13cc9SGunnar Mills std::bind_front(afterChassisDriveCollectionSubtree, asyncResp)); 136a85afbe1SWilly Tu } 137e284a7c1SJames Feist 1385e577bc1SWilly Tu inline void afterSystemsStorageGetSubtree( 1395e577bc1SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1405e577bc1SWilly Tu const std::string& storageId, const boost::system::error_code& ec, 1415e577bc1SWilly Tu const dbus::utility::MapperGetSubTreeResponse& subtree) 142a85afbe1SWilly Tu { 1435e577bc1SWilly Tu if (ec) 144a85afbe1SWilly Tu { 14562598e31SEd Tanous BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); 1465e577bc1SWilly Tu messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", 1475e577bc1SWilly Tu storageId); 148a85afbe1SWilly Tu return; 149a85afbe1SWilly Tu } 1503544d2a7SEd Tanous auto storage = std::ranges::find_if( 1513544d2a7SEd Tanous subtree, 1525e577bc1SWilly Tu [&storageId](const std::pair<std::string, 1535e577bc1SWilly Tu dbus::utility::MapperServiceMap>& object) { 1545e577bc1SWilly Tu return sdbusplus::message::object_path(object.first).filename() == 1555e577bc1SWilly Tu storageId; 1565e577bc1SWilly Tu }); 1575e577bc1SWilly Tu if (storage == subtree.end()) 1585e577bc1SWilly Tu { 1595e577bc1SWilly Tu messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", 1605e577bc1SWilly Tu storageId); 1615e577bc1SWilly Tu return; 1625e577bc1SWilly Tu } 1635e577bc1SWilly Tu 16461b1eb21SWilly Tu asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; 165a85afbe1SWilly Tu asyncResp->res.jsonValue["@odata.id"] = 166253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", 167253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); 168a85afbe1SWilly Tu asyncResp->res.jsonValue["Name"] = "Storage"; 1695e577bc1SWilly Tu asyncResp->res.jsonValue["Id"] = storageId; 170539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 171a85afbe1SWilly Tu 1727ac13cc9SGunnar Mills getDrives(asyncResp); 173253f11b8SEd Tanous asyncResp->res.jsonValue["Controllers"]["@odata.id"] = 174253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/{}/Controllers", 175253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); 1765e577bc1SWilly Tu } 1775e577bc1SWilly Tu 178bd79bce8SPatrick Williams inline void handleSystemsStorageGet( 179bd79bce8SPatrick Williams App& app, const crow::Request& req, 1805e577bc1SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 181bd79bce8SPatrick Williams const std::string& systemName, const std::string& storageId) 1825e577bc1SWilly Tu { 1835e577bc1SWilly Tu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 1845e577bc1SWilly Tu { 1855e577bc1SWilly Tu return; 1865e577bc1SWilly Tu } 18725b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 1887f3e84a1SEd Tanous { 1897f3e84a1SEd Tanous // Option currently returns no systems. TBD 1907f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 1917f3e84a1SEd Tanous systemName); 1927f3e84a1SEd Tanous return; 1937f3e84a1SEd Tanous } 1945e577bc1SWilly Tu 1955e577bc1SWilly Tu constexpr std::array<std::string_view, 1> interfaces = { 1965e577bc1SWilly Tu "xyz.openbmc_project.Inventory.Item.Storage"}; 1975e577bc1SWilly Tu dbus::utility::getSubTree( 1985e577bc1SWilly Tu "/xyz/openbmc_project/inventory", 0, interfaces, 1995e577bc1SWilly Tu std::bind_front(afterSystemsStorageGetSubtree, asyncResp, storageId)); 2005e577bc1SWilly Tu } 2015e577bc1SWilly Tu 2025e577bc1SWilly Tu inline void afterSubtree(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2035e577bc1SWilly Tu const std::string& storageId, 2045e577bc1SWilly Tu const boost::system::error_code& ec, 2055e577bc1SWilly Tu const dbus::utility::MapperGetSubTreeResponse& subtree) 2065e577bc1SWilly Tu { 2075e577bc1SWilly Tu if (ec) 2085e577bc1SWilly Tu { 20962598e31SEd Tanous BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); 2105e577bc1SWilly Tu messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", 2115e577bc1SWilly Tu storageId); 2125e577bc1SWilly Tu return; 2135e577bc1SWilly Tu } 2143544d2a7SEd Tanous auto storage = std::ranges::find_if( 2153544d2a7SEd Tanous subtree, 2165e577bc1SWilly Tu [&storageId](const std::pair<std::string, 2175e577bc1SWilly Tu dbus::utility::MapperServiceMap>& object) { 2185e577bc1SWilly Tu return sdbusplus::message::object_path(object.first).filename() == 2195e577bc1SWilly Tu storageId; 2205e577bc1SWilly Tu }); 2215e577bc1SWilly Tu if (storage == subtree.end()) 2225e577bc1SWilly Tu { 2235e577bc1SWilly Tu messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", 2245e577bc1SWilly Tu storageId); 2255e577bc1SWilly Tu return; 2265e577bc1SWilly Tu } 2275e577bc1SWilly Tu 2285e577bc1SWilly Tu asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; 2295e577bc1SWilly Tu asyncResp->res.jsonValue["@odata.id"] = 2305e577bc1SWilly Tu boost::urls::format("/redfish/v1/Storage/{}", storageId); 2315e577bc1SWilly Tu asyncResp->res.jsonValue["Name"] = "Storage"; 2325e577bc1SWilly Tu asyncResp->res.jsonValue["Id"] = storageId; 233539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 2345e577bc1SWilly Tu 2355e577bc1SWilly Tu // Storage subsystem to Storage link. 2365e577bc1SWilly Tu nlohmann::json::array_t storageServices; 2375e577bc1SWilly Tu nlohmann::json::object_t storageService; 2385e577bc1SWilly Tu storageService["@odata.id"] = 239253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", 240253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); 2415e577bc1SWilly Tu storageServices.emplace_back(storageService); 2425e577bc1SWilly Tu asyncResp->res.jsonValue["Links"]["StorageServices"] = 2435e577bc1SWilly Tu std::move(storageServices); 2445e577bc1SWilly Tu asyncResp->res.jsonValue["Links"]["StorageServices@odata.count"] = 1; 2455e577bc1SWilly Tu } 2465e577bc1SWilly Tu 2475e577bc1SWilly Tu inline void 2485e577bc1SWilly Tu handleStorageGet(App& app, const crow::Request& req, 2495e577bc1SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2505e577bc1SWilly Tu const std::string& storageId) 2515e577bc1SWilly Tu { 2525e577bc1SWilly Tu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2535e577bc1SWilly Tu { 25462598e31SEd Tanous BMCWEB_LOG_DEBUG("requestRoutesStorage setUpRedfishRoute failed"); 2555e577bc1SWilly Tu return; 2565e577bc1SWilly Tu } 2575e577bc1SWilly Tu 2585e577bc1SWilly Tu constexpr std::array<std::string_view, 1> interfaces = { 2595e577bc1SWilly Tu "xyz.openbmc_project.Inventory.Item.Storage"}; 2605e577bc1SWilly Tu dbus::utility::getSubTree( 2615e577bc1SWilly Tu "/xyz/openbmc_project/inventory", 0, interfaces, 2625e577bc1SWilly Tu std::bind_front(afterSubtree, asyncResp, storageId)); 26336d52334SEd Tanous } 26436d52334SEd Tanous 26536d52334SEd Tanous inline void requestRoutesStorage(App& app) 26636d52334SEd Tanous { 2677f3e84a1SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/<str>/") 26836d52334SEd Tanous .privileges(redfish::privileges::getStorage) 26936d52334SEd Tanous .methods(boost::beast::http::verb::get)( 27036d52334SEd Tanous std::bind_front(handleSystemsStorageGet, std::ref(app))); 2715e577bc1SWilly Tu 2725e577bc1SWilly Tu BMCWEB_ROUTE(app, "/redfish/v1/Storage/<str>/") 2735e577bc1SWilly Tu .privileges(redfish::privileges::getStorage) 2745e577bc1SWilly Tu .methods(boost::beast::http::verb::get)( 2755e577bc1SWilly Tu std::bind_front(handleStorageGet, std::ref(app))); 2767e860f15SJohn Edward Broadbent } 2777e860f15SJohn Edward Broadbent 27803913171SWilly Tu inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27903913171SWilly Tu const std::string& connectionName, 28003913171SWilly Tu const std::string& path) 28103913171SWilly Tu { 282deae6a78SEd Tanous dbus::utility::getAllProperties( 283deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.Inventory.Decorator.Asset", 2845e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 285168e20c1SEd Tanous const std::vector< 286168e20c1SEd Tanous std::pair<std::string, dbus::utility::DbusVariantType>>& 28703913171SWilly Tu propertiesList) { 28803913171SWilly Tu if (ec) 28903913171SWilly Tu { 29003913171SWilly Tu // this interface isn't necessary 29103913171SWilly Tu return; 29203913171SWilly Tu } 293d1bde9e5SKrzysztof Grobelny 294d1bde9e5SKrzysztof Grobelny const std::string* partNumber = nullptr; 295d1bde9e5SKrzysztof Grobelny const std::string* serialNumber = nullptr; 296d1bde9e5SKrzysztof Grobelny const std::string* manufacturer = nullptr; 297d1bde9e5SKrzysztof Grobelny const std::string* model = nullptr; 298d1bde9e5SKrzysztof Grobelny 299d1bde9e5SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 300d1bde9e5SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", 301d1bde9e5SKrzysztof Grobelny partNumber, "SerialNumber", serialNumber, "Manufacturer", 302d1bde9e5SKrzysztof Grobelny manufacturer, "Model", model); 303d1bde9e5SKrzysztof Grobelny 304d1bde9e5SKrzysztof Grobelny if (!success) 30503913171SWilly Tu { 30603913171SWilly Tu messages::internalError(asyncResp->res); 30703913171SWilly Tu return; 30803913171SWilly Tu } 309d1bde9e5SKrzysztof Grobelny 310d1bde9e5SKrzysztof Grobelny if (partNumber != nullptr) 311d1bde9e5SKrzysztof Grobelny { 312d1bde9e5SKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = *partNumber; 31303913171SWilly Tu } 314d1bde9e5SKrzysztof Grobelny 315d1bde9e5SKrzysztof Grobelny if (serialNumber != nullptr) 316d1bde9e5SKrzysztof Grobelny { 317d1bde9e5SKrzysztof Grobelny asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 31803913171SWilly Tu } 319d1bde9e5SKrzysztof Grobelny 320d1bde9e5SKrzysztof Grobelny if (manufacturer != nullptr) 321d1bde9e5SKrzysztof Grobelny { 322d1bde9e5SKrzysztof Grobelny asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 323d1bde9e5SKrzysztof Grobelny } 324d1bde9e5SKrzysztof Grobelny 325d1bde9e5SKrzysztof Grobelny if (model != nullptr) 326d1bde9e5SKrzysztof Grobelny { 327d1bde9e5SKrzysztof Grobelny asyncResp->res.jsonValue["Model"] = *model; 328d1bde9e5SKrzysztof Grobelny } 329d1bde9e5SKrzysztof Grobelny }); 33003913171SWilly Tu } 33103913171SWilly Tu 33203913171SWilly Tu inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 33303913171SWilly Tu const std::string& connectionName, 33403913171SWilly Tu const std::string& path) 33503913171SWilly Tu { 336deae6a78SEd Tanous dbus::utility::getProperty<bool>( 337deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.Inventory.Item", "Present", 338bd79bce8SPatrick Williams [asyncResp, 339bd79bce8SPatrick Williams path](const boost::system::error_code& ec, const bool isPresent) { 34003913171SWilly Tu // this interface isn't necessary, only check it if 34103913171SWilly Tu // we get a good return 34203913171SWilly Tu if (ec) 34303913171SWilly Tu { 34403913171SWilly Tu return; 34503913171SWilly Tu } 34603913171SWilly Tu 347cef57e85SWilly Tu if (!isPresent) 34803913171SWilly Tu { 349539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 350539d8c6bSEd Tanous resource::State::Absent; 35103913171SWilly Tu } 3521e1e598dSJonathan Doman }); 35303913171SWilly Tu } 35403913171SWilly Tu 35503913171SWilly Tu inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 35603913171SWilly Tu const std::string& connectionName, 35703913171SWilly Tu const std::string& path) 35803913171SWilly Tu { 359deae6a78SEd Tanous dbus::utility::getProperty<bool>( 360deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.State.Drive", "Rebuilding", 3615e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, const bool updating) { 36203913171SWilly Tu // this interface isn't necessary, only check it 36303913171SWilly Tu // if we get a good return 36403913171SWilly Tu if (ec) 36503913171SWilly Tu { 36603913171SWilly Tu return; 36703913171SWilly Tu } 36803913171SWilly Tu 36903913171SWilly Tu // updating and disabled in the backend shouldn't be 37003913171SWilly Tu // able to be set at the same time, so we don't need 37103913171SWilly Tu // to check for the race condition of these two 37203913171SWilly Tu // calls 3731e1e598dSJonathan Doman if (updating) 37403913171SWilly Tu { 375539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 376539d8c6bSEd Tanous resource::State::Updating; 37703913171SWilly Tu } 3781e1e598dSJonathan Doman }); 37903913171SWilly Tu } 38003913171SWilly Tu 381dde9bc12SGeorge Liu inline std::optional<drive::MediaType> convertDriveType(std::string_view type) 38219b8e9a0SWilly Tu { 38319b8e9a0SWilly Tu if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.HDD") 38419b8e9a0SWilly Tu { 385dde9bc12SGeorge Liu return drive::MediaType::HDD; 38619b8e9a0SWilly Tu } 38719b8e9a0SWilly Tu if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.SSD") 38819b8e9a0SWilly Tu { 389dde9bc12SGeorge Liu return drive::MediaType::SSD; 39019b8e9a0SWilly Tu } 391dde9bc12SGeorge Liu if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.Unknown") 392dde9bc12SGeorge Liu { 39319b8e9a0SWilly Tu return std::nullopt; 39419b8e9a0SWilly Tu } 39519b8e9a0SWilly Tu 396dde9bc12SGeorge Liu return drive::MediaType::Invalid; 397dde9bc12SGeorge Liu } 398dde9bc12SGeorge Liu 399dde9bc12SGeorge Liu inline std::optional<protocol::Protocol> 400dde9bc12SGeorge Liu convertDriveProtocol(std::string_view proto) 40119b8e9a0SWilly Tu { 40219b8e9a0SWilly Tu if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SAS") 40319b8e9a0SWilly Tu { 404dde9bc12SGeorge Liu return protocol::Protocol::SAS; 40519b8e9a0SWilly Tu } 40619b8e9a0SWilly Tu if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SATA") 40719b8e9a0SWilly Tu { 408dde9bc12SGeorge Liu return protocol::Protocol::SATA; 40919b8e9a0SWilly Tu } 41019b8e9a0SWilly Tu if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.NVMe") 41119b8e9a0SWilly Tu { 412dde9bc12SGeorge Liu return protocol::Protocol::NVMe; 41319b8e9a0SWilly Tu } 41419b8e9a0SWilly Tu if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.FC") 41519b8e9a0SWilly Tu { 416dde9bc12SGeorge Liu return protocol::Protocol::FC; 417dde9bc12SGeorge Liu } 418dde9bc12SGeorge Liu if (proto == 419dde9bc12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.Unknown") 420dde9bc12SGeorge Liu { 421dde9bc12SGeorge Liu return std::nullopt; 42219b8e9a0SWilly Tu } 42319b8e9a0SWilly Tu 424dde9bc12SGeorge Liu return protocol::Protocol::Invalid; 42519b8e9a0SWilly Tu } 42619b8e9a0SWilly Tu 427bd79bce8SPatrick Williams inline void getDriveItemProperties( 428bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 429bd79bce8SPatrick Williams const std::string& connectionName, const std::string& path) 43019b8e9a0SWilly Tu { 431deae6a78SEd Tanous dbus::utility::getAllProperties( 432deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.Inventory.Item.Drive", 4335e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 43419b8e9a0SWilly Tu const std::vector< 43519b8e9a0SWilly Tu std::pair<std::string, dbus::utility::DbusVariantType>>& 43619b8e9a0SWilly Tu propertiesList) { 43719b8e9a0SWilly Tu if (ec) 43819b8e9a0SWilly Tu { 43919b8e9a0SWilly Tu // this interface isn't required 44019b8e9a0SWilly Tu return; 44119b8e9a0SWilly Tu } 442e5029d88SJohn Edward Broadbent const std::string* encryptionStatus = nullptr; 443e5029d88SJohn Edward Broadbent const bool* isLocked = nullptr; 44419b8e9a0SWilly Tu for (const std::pair<std::string, dbus::utility::DbusVariantType>& 44519b8e9a0SWilly Tu property : propertiesList) 44619b8e9a0SWilly Tu { 44719b8e9a0SWilly Tu const std::string& propertyName = property.first; 44819b8e9a0SWilly Tu if (propertyName == "Type") 44919b8e9a0SWilly Tu { 45019b8e9a0SWilly Tu const std::string* value = 45119b8e9a0SWilly Tu std::get_if<std::string>(&property.second); 45219b8e9a0SWilly Tu if (value == nullptr) 45319b8e9a0SWilly Tu { 45419b8e9a0SWilly Tu // illegal property 45562598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal property: Type"); 45619b8e9a0SWilly Tu messages::internalError(asyncResp->res); 45719b8e9a0SWilly Tu return; 45819b8e9a0SWilly Tu } 45919b8e9a0SWilly Tu 460dde9bc12SGeorge Liu std::optional<drive::MediaType> mediaType = 461dde9bc12SGeorge Liu convertDriveType(*value); 46219b8e9a0SWilly Tu if (!mediaType) 46319b8e9a0SWilly Tu { 46462598e31SEd Tanous BMCWEB_LOG_WARNING("UnknownDriveType Interface: {}", 46562598e31SEd Tanous *value); 466dde9bc12SGeorge Liu continue; 467dde9bc12SGeorge Liu } 468dde9bc12SGeorge Liu if (*mediaType == drive::MediaType::Invalid) 469dde9bc12SGeorge Liu { 47019b8e9a0SWilly Tu messages::internalError(asyncResp->res); 47119b8e9a0SWilly Tu return; 47219b8e9a0SWilly Tu } 47319b8e9a0SWilly Tu 47419b8e9a0SWilly Tu asyncResp->res.jsonValue["MediaType"] = *mediaType; 47519b8e9a0SWilly Tu } 47619b8e9a0SWilly Tu else if (propertyName == "Capacity") 47719b8e9a0SWilly Tu { 47819b8e9a0SWilly Tu const uint64_t* capacity = 47919b8e9a0SWilly Tu std::get_if<uint64_t>(&property.second); 48019b8e9a0SWilly Tu if (capacity == nullptr) 48119b8e9a0SWilly Tu { 48262598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal property: Capacity"); 48319b8e9a0SWilly Tu messages::internalError(asyncResp->res); 48419b8e9a0SWilly Tu return; 48519b8e9a0SWilly Tu } 48619b8e9a0SWilly Tu if (*capacity == 0) 48719b8e9a0SWilly Tu { 48819b8e9a0SWilly Tu // drive capacity not known 48919b8e9a0SWilly Tu continue; 49019b8e9a0SWilly Tu } 49119b8e9a0SWilly Tu 49219b8e9a0SWilly Tu asyncResp->res.jsonValue["CapacityBytes"] = *capacity; 49319b8e9a0SWilly Tu } 49419b8e9a0SWilly Tu else if (propertyName == "Protocol") 49519b8e9a0SWilly Tu { 49619b8e9a0SWilly Tu const std::string* value = 49719b8e9a0SWilly Tu std::get_if<std::string>(&property.second); 49819b8e9a0SWilly Tu if (value == nullptr) 49919b8e9a0SWilly Tu { 50062598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal property: Protocol"); 50119b8e9a0SWilly Tu messages::internalError(asyncResp->res); 50219b8e9a0SWilly Tu return; 50319b8e9a0SWilly Tu } 50419b8e9a0SWilly Tu 505dde9bc12SGeorge Liu std::optional<protocol::Protocol> proto = 506dde9bc12SGeorge Liu convertDriveProtocol(*value); 50719b8e9a0SWilly Tu if (!proto) 50819b8e9a0SWilly Tu { 509bd79bce8SPatrick Williams BMCWEB_LOG_WARNING( 510bd79bce8SPatrick Williams "Unknown DrivePrototype Interface: {}", *value); 511dde9bc12SGeorge Liu continue; 512dde9bc12SGeorge Liu } 513dde9bc12SGeorge Liu if (*proto == protocol::Protocol::Invalid) 514dde9bc12SGeorge Liu { 51519b8e9a0SWilly Tu messages::internalError(asyncResp->res); 51619b8e9a0SWilly Tu return; 51719b8e9a0SWilly Tu } 51819b8e9a0SWilly Tu asyncResp->res.jsonValue["Protocol"] = *proto; 51919b8e9a0SWilly Tu } 5203fe4d5ccSJohn Edward Broadbent else if (propertyName == "PredictedMediaLifeLeftPercent") 5213fe4d5ccSJohn Edward Broadbent { 5223fe4d5ccSJohn Edward Broadbent const uint8_t* lifeLeft = 5233fe4d5ccSJohn Edward Broadbent std::get_if<uint8_t>(&property.second); 5243fe4d5ccSJohn Edward Broadbent if (lifeLeft == nullptr) 5253fe4d5ccSJohn Edward Broadbent { 52662598e31SEd Tanous BMCWEB_LOG_ERROR( 52762598e31SEd Tanous "Illegal property: PredictedMediaLifeLeftPercent"); 5283fe4d5ccSJohn Edward Broadbent messages::internalError(asyncResp->res); 5293fe4d5ccSJohn Edward Broadbent return; 5303fe4d5ccSJohn Edward Broadbent } 5313fe4d5ccSJohn Edward Broadbent // 255 means reading the value is not supported 5323fe4d5ccSJohn Edward Broadbent if (*lifeLeft != 255) 5333fe4d5ccSJohn Edward Broadbent { 534bd79bce8SPatrick Williams asyncResp->res 535bd79bce8SPatrick Williams .jsonValue["PredictedMediaLifeLeftPercent"] = 5363fe4d5ccSJohn Edward Broadbent *lifeLeft; 5373fe4d5ccSJohn Edward Broadbent } 5383fe4d5ccSJohn Edward Broadbent } 539e5029d88SJohn Edward Broadbent else if (propertyName == "EncryptionStatus") 540e5029d88SJohn Edward Broadbent { 541bd79bce8SPatrick Williams encryptionStatus = 542bd79bce8SPatrick Williams std::get_if<std::string>(&property.second); 543e5029d88SJohn Edward Broadbent if (encryptionStatus == nullptr) 544e5029d88SJohn Edward Broadbent { 54562598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal property: EncryptionStatus"); 546e5029d88SJohn Edward Broadbent messages::internalError(asyncResp->res); 547e5029d88SJohn Edward Broadbent return; 54819b8e9a0SWilly Tu } 549e5029d88SJohn Edward Broadbent } 550e5029d88SJohn Edward Broadbent else if (propertyName == "Locked") 551e5029d88SJohn Edward Broadbent { 552e5029d88SJohn Edward Broadbent isLocked = std::get_if<bool>(&property.second); 553e5029d88SJohn Edward Broadbent if (isLocked == nullptr) 554e5029d88SJohn Edward Broadbent { 55562598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal property: Locked"); 556e5029d88SJohn Edward Broadbent messages::internalError(asyncResp->res); 557e5029d88SJohn Edward Broadbent return; 558e5029d88SJohn Edward Broadbent } 559e5029d88SJohn Edward Broadbent } 560e5029d88SJohn Edward Broadbent } 561e5029d88SJohn Edward Broadbent 562e5029d88SJohn Edward Broadbent if (encryptionStatus == nullptr || isLocked == nullptr || 563e5029d88SJohn Edward Broadbent *encryptionStatus == 564a684c226SKonda Reddy Kachana "xyz.openbmc_project.Inventory.Item.Drive.DriveEncryptionState.Unknown") 565e5029d88SJohn Edward Broadbent { 566e5029d88SJohn Edward Broadbent return; 567e5029d88SJohn Edward Broadbent } 568e5029d88SJohn Edward Broadbent if (*encryptionStatus != 569a684c226SKonda Reddy Kachana "xyz.openbmc_project.Inventory.Item.Drive.DriveEncryptionState.Encrypted") 570e5029d88SJohn Edward Broadbent { 571e5029d88SJohn Edward Broadbent //"The drive is not currently encrypted." 572e5029d88SJohn Edward Broadbent asyncResp->res.jsonValue["EncryptionStatus"] = 573e5029d88SJohn Edward Broadbent drive::EncryptionStatus::Unencrypted; 574e5029d88SJohn Edward Broadbent return; 575e5029d88SJohn Edward Broadbent } 576e5029d88SJohn Edward Broadbent if (*isLocked) 577e5029d88SJohn Edward Broadbent { 578e5029d88SJohn Edward Broadbent //"The drive is currently encrypted and the data is not 579e5029d88SJohn Edward Broadbent // accessible to the user." 580e5029d88SJohn Edward Broadbent asyncResp->res.jsonValue["EncryptionStatus"] = 581e5029d88SJohn Edward Broadbent drive::EncryptionStatus::Locked; 582e5029d88SJohn Edward Broadbent return; 583e5029d88SJohn Edward Broadbent } 584e5029d88SJohn Edward Broadbent // if not locked 585e5029d88SJohn Edward Broadbent // "The drive is currently encrypted but the data is accessible 586e5029d88SJohn Edward Broadbent // to the user in unencrypted form." 587e5029d88SJohn Edward Broadbent asyncResp->res.jsonValue["EncryptionStatus"] = 588e5029d88SJohn Edward Broadbent drive::EncryptionStatus::Unlocked; 58919b8e9a0SWilly Tu }); 59019b8e9a0SWilly Tu } 59119b8e9a0SWilly Tu 5924ff0f1f4SEd Tanous inline void addAllDriveInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 593b53dcd9dSNan Zhou const std::string& connectionName, 594b53dcd9dSNan Zhou const std::string& path, 595e56ed6b9SJohn Edward Broadbent const std::vector<std::string>& interfaces) 596e56ed6b9SJohn Edward Broadbent { 597e56ed6b9SJohn Edward Broadbent for (const std::string& interface : interfaces) 598e56ed6b9SJohn Edward Broadbent { 599e56ed6b9SJohn Edward Broadbent if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") 600e56ed6b9SJohn Edward Broadbent { 601e56ed6b9SJohn Edward Broadbent getDriveAsset(asyncResp, connectionName, path); 602e56ed6b9SJohn Edward Broadbent } 603e56ed6b9SJohn Edward Broadbent else if (interface == "xyz.openbmc_project.Inventory.Item") 604e56ed6b9SJohn Edward Broadbent { 605e56ed6b9SJohn Edward Broadbent getDrivePresent(asyncResp, connectionName, path); 606e56ed6b9SJohn Edward Broadbent } 607e56ed6b9SJohn Edward Broadbent else if (interface == "xyz.openbmc_project.State.Drive") 608e56ed6b9SJohn Edward Broadbent { 609e56ed6b9SJohn Edward Broadbent getDriveState(asyncResp, connectionName, path); 610e56ed6b9SJohn Edward Broadbent } 611e56ed6b9SJohn Edward Broadbent else if (interface == "xyz.openbmc_project.Inventory.Item.Drive") 612e56ed6b9SJohn Edward Broadbent { 613e56ed6b9SJohn Edward Broadbent getDriveItemProperties(asyncResp, connectionName, path); 614e56ed6b9SJohn Edward Broadbent } 615e56ed6b9SJohn Edward Broadbent } 616e56ed6b9SJohn Edward Broadbent } 617e56ed6b9SJohn Edward Broadbent 61836d52334SEd Tanous inline void afterGetSubtreeSystemsStorageDrive( 61945ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 62036d52334SEd Tanous const std::string& driveId, const boost::system::error_code& ec, 62136d52334SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) 62245ca1b86SEd Tanous { 6237e860f15SJohn Edward Broadbent if (ec) 6247e860f15SJohn Edward Broadbent { 62562598e31SEd Tanous BMCWEB_LOG_ERROR("Drive mapper call error"); 6267e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 6277e860f15SJohn Edward Broadbent return; 6287e860f15SJohn Edward Broadbent } 6297e860f15SJohn Edward Broadbent 6303544d2a7SEd Tanous auto drive = std::ranges::find_if( 6313544d2a7SEd Tanous subtree, 63236d52334SEd Tanous [&driveId](const std::pair<std::string, 6338cb65f8aSNan Zhou dbus::utility::MapperServiceMap>& object) { 63436d52334SEd Tanous return sdbusplus::message::object_path(object.first).filename() == 63536d52334SEd Tanous driveId; 6367e860f15SJohn Edward Broadbent }); 6377e860f15SJohn Edward Broadbent 63803913171SWilly Tu if (drive == subtree.end()) 6397e860f15SJohn Edward Broadbent { 640002d39b4SEd Tanous messages::resourceNotFound(asyncResp->res, "Drive", driveId); 6417e860f15SJohn Edward Broadbent return; 6427e860f15SJohn Edward Broadbent } 6437e860f15SJohn Edward Broadbent 64403913171SWilly Tu const std::string& path = drive->first; 64536d52334SEd Tanous const dbus::utility::MapperServiceMap& connectionNames = drive->second; 6467e860f15SJohn Edward Broadbent 647002d39b4SEd Tanous asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; 648253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 649253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Drives/{}", 650253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, driveId); 6517e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = driveId; 6527e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = driveId; 6537e860f15SJohn Edward Broadbent 6547e860f15SJohn Edward Broadbent if (connectionNames.size() != 1) 6557e860f15SJohn Edward Broadbent { 65662598e31SEd Tanous BMCWEB_LOG_ERROR("Connection size {}, not equal to 1", 65762598e31SEd Tanous connectionNames.size()); 6587e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 6597e860f15SJohn Edward Broadbent return; 6607e860f15SJohn Edward Broadbent } 6617e860f15SJohn Edward Broadbent 662bd79bce8SPatrick Williams getMainChassisId( 663bd79bce8SPatrick Williams asyncResp, [](const std::string& chassisId, 6647e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 665002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["Chassis"]["@odata.id"] = 666ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 6677e860f15SJohn Edward Broadbent }); 6687e860f15SJohn Edward Broadbent 669a25aeccfSNikhil Potade // default it to Enabled 670539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 671a25aeccfSNikhil Potade 672e56ed6b9SJohn Edward Broadbent addAllDriveInfo(asyncResp, connectionNames[0].first, path, 673e56ed6b9SJohn Edward Broadbent connectionNames[0].second); 674a25aeccfSNikhil Potade } 67592903bd4SJohn Edward Broadbent 67636d52334SEd Tanous inline void handleSystemsStorageDriveGet( 67736d52334SEd Tanous App& app, const crow::Request& req, 67892903bd4SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 67936d52334SEd Tanous const std::string& systemName, const std::string& driveId) 68092903bd4SJohn Edward Broadbent { 6813ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 68292903bd4SJohn Edward Broadbent { 68392903bd4SJohn Edward Broadbent return; 68492903bd4SJohn Edward Broadbent } 68525b54dbaSEd Tanous if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 6867f3e84a1SEd Tanous { 6877f3e84a1SEd Tanous // Option currently returns no systems. TBD 6887f3e84a1SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 6897f3e84a1SEd Tanous systemName); 6907f3e84a1SEd Tanous return; 6917f3e84a1SEd Tanous } 6927f3e84a1SEd Tanous 693253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 69436d52334SEd Tanous { 69536d52334SEd Tanous messages::resourceNotFound(asyncResp->res, "ComputerSystem", 69636d52334SEd Tanous systemName); 69736d52334SEd Tanous return; 69836d52334SEd Tanous } 69992903bd4SJohn Edward Broadbent 70036d52334SEd Tanous constexpr std::array<std::string_view, 1> interfaces = { 70136d52334SEd Tanous "xyz.openbmc_project.Inventory.Item.Drive"}; 702e99073f5SGeorge Liu dbus::utility::getSubTree( 703e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 70436d52334SEd Tanous std::bind_front(afterGetSubtreeSystemsStorageDrive, asyncResp, 70536d52334SEd Tanous driveId)); 70636d52334SEd Tanous } 70736d52334SEd Tanous 70836d52334SEd Tanous inline void requestRoutesDrive(App& app) 70936d52334SEd Tanous { 71036d52334SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Drives/<str>/") 71136d52334SEd Tanous .privileges(redfish::privileges::getDrive) 71236d52334SEd Tanous .methods(boost::beast::http::verb::get)( 71336d52334SEd Tanous std::bind_front(handleSystemsStorageDriveGet, std::ref(app))); 71436d52334SEd Tanous } 71536d52334SEd Tanous 71636d52334SEd Tanous inline void afterChassisDriveCollectionSubtreeGet( 71736d52334SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 71836d52334SEd Tanous const std::string& chassisId, const boost::system::error_code& ec, 71936d52334SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) 72036d52334SEd Tanous { 72192903bd4SJohn Edward Broadbent if (ec) 72292903bd4SJohn Edward Broadbent { 72392903bd4SJohn Edward Broadbent if (ec == boost::system::errc::host_unreachable) 72492903bd4SJohn Edward Broadbent { 72536d52334SEd Tanous messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 72692903bd4SJohn Edward Broadbent return; 72792903bd4SJohn Edward Broadbent } 72892903bd4SJohn Edward Broadbent messages::internalError(asyncResp->res); 72992903bd4SJohn Edward Broadbent return; 73092903bd4SJohn Edward Broadbent } 73192903bd4SJohn Edward Broadbent 73292903bd4SJohn Edward Broadbent // Iterate over all retrieved ObjectPaths. 7338cb65f8aSNan Zhou for (const auto& [path, connectionNames] : subtree) 73492903bd4SJohn Edward Broadbent { 73592903bd4SJohn Edward Broadbent sdbusplus::message::object_path objPath(path); 73692903bd4SJohn Edward Broadbent if (objPath.filename() != chassisId) 73792903bd4SJohn Edward Broadbent { 73892903bd4SJohn Edward Broadbent continue; 73992903bd4SJohn Edward Broadbent } 74092903bd4SJohn Edward Broadbent 74192903bd4SJohn Edward Broadbent if (connectionNames.empty()) 74292903bd4SJohn Edward Broadbent { 74362598e31SEd Tanous BMCWEB_LOG_ERROR("Got 0 Connection names"); 74492903bd4SJohn Edward Broadbent continue; 74592903bd4SJohn Edward Broadbent } 74692903bd4SJohn Edward Broadbent 74792903bd4SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 74892903bd4SJohn Edward Broadbent "#DriveCollection.DriveCollection"; 74992903bd4SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = 750ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}/Drives", chassisId); 75192903bd4SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "Drive Collection"; 75292903bd4SJohn Edward Broadbent 75392903bd4SJohn Edward Broadbent // Association lambda 7546c3e9451SGeorge Liu dbus::utility::getAssociationEndPoints( 7556c3e9451SGeorge Liu path + "/drive", 75636d52334SEd Tanous [asyncResp, chassisId](const boost::system::error_code& ec3, 7576c3e9451SGeorge Liu const dbus::utility::MapperEndPoints& resp) { 75892903bd4SJohn Edward Broadbent if (ec3) 75992903bd4SJohn Edward Broadbent { 76062598e31SEd Tanous BMCWEB_LOG_ERROR("Error in chassis Drive association "); 76192903bd4SJohn Edward Broadbent } 76292903bd4SJohn Edward Broadbent nlohmann::json& members = asyncResp->res.jsonValue["Members"]; 76392903bd4SJohn Edward Broadbent // important if array is empty 76492903bd4SJohn Edward Broadbent members = nlohmann::json::array(); 76592903bd4SJohn Edward Broadbent 76692903bd4SJohn Edward Broadbent std::vector<std::string> leafNames; 76792903bd4SJohn Edward Broadbent for (const auto& drive : resp) 76892903bd4SJohn Edward Broadbent { 7698a592810SEd Tanous sdbusplus::message::object_path drivePath(drive); 7708a592810SEd Tanous leafNames.push_back(drivePath.filename()); 77192903bd4SJohn Edward Broadbent } 77292903bd4SJohn Edward Broadbent 7733544d2a7SEd Tanous std::ranges::sort(leafNames, AlphanumLess<std::string>()); 77492903bd4SJohn Edward Broadbent 77592903bd4SJohn Edward Broadbent for (const auto& leafName : leafNames) 77692903bd4SJohn Edward Broadbent { 77792903bd4SJohn Edward Broadbent nlohmann::json::object_t member; 778bd79bce8SPatrick Williams member["@odata.id"] = 779bd79bce8SPatrick Williams boost::urls::format("/redfish/v1/Chassis/{}/Drives/{}", 780bd79bce8SPatrick Williams chassisId, leafName); 781b2ba3072SPatrick Williams members.emplace_back(std::move(member)); 78292903bd4SJohn Edward Broadbent // navigation links will be registered in next patch set 78392903bd4SJohn Edward Broadbent } 78492903bd4SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"] = resp.size(); 78592903bd4SJohn Edward Broadbent }); // end association lambda 78692903bd4SJohn Edward Broadbent 78792903bd4SJohn Edward Broadbent } // end Iterate over all retrieved ObjectPaths 78836d52334SEd Tanous } 78936d52334SEd Tanous /** 79036d52334SEd Tanous * Chassis drives, this URL will show all the DriveCollection 79136d52334SEd Tanous * information 79236d52334SEd Tanous */ 79336d52334SEd Tanous inline void chassisDriveCollectionGet( 79436d52334SEd Tanous crow::App& app, const crow::Request& req, 79536d52334SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 79636d52334SEd Tanous const std::string& chassisId) 79736d52334SEd Tanous { 79836d52334SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 79936d52334SEd Tanous { 80036d52334SEd Tanous return; 80136d52334SEd Tanous } 80236d52334SEd Tanous 80336d52334SEd Tanous // mapper call lambda 80436d52334SEd Tanous constexpr std::array<std::string_view, 2> interfaces = { 80536d52334SEd Tanous "xyz.openbmc_project.Inventory.Item.Board", 80636d52334SEd Tanous "xyz.openbmc_project.Inventory.Item.Chassis"}; 80736d52334SEd Tanous dbus::utility::getSubTree( 80836d52334SEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces, 80936d52334SEd Tanous std::bind_front(afterChassisDriveCollectionSubtreeGet, asyncResp, 81036d52334SEd Tanous chassisId)); 81192903bd4SJohn Edward Broadbent } 81292903bd4SJohn Edward Broadbent 81392903bd4SJohn Edward Broadbent inline void requestRoutesChassisDrive(App& app) 81492903bd4SJohn Edward Broadbent { 81592903bd4SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/") 81692903bd4SJohn Edward Broadbent .privileges(redfish::privileges::getDriveCollection) 81792903bd4SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 81892903bd4SJohn Edward Broadbent std::bind_front(chassisDriveCollectionGet, std::ref(app))); 81992903bd4SJohn Edward Broadbent } 82092903bd4SJohn Edward Broadbent 821b53dcd9dSNan Zhou inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 822b53dcd9dSNan Zhou const std::string& chassisId, 823b53dcd9dSNan Zhou const std::string& driveName, 8245e7e2dc5SEd Tanous const boost::system::error_code& ec, 825e56ed6b9SJohn Edward Broadbent const dbus::utility::MapperGetSubTreeResponse& subtree) 826e56ed6b9SJohn Edward Broadbent { 827e56ed6b9SJohn Edward Broadbent if (ec) 828e56ed6b9SJohn Edward Broadbent { 82962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 830e56ed6b9SJohn Edward Broadbent messages::internalError(asyncResp->res); 831e56ed6b9SJohn Edward Broadbent return; 832e56ed6b9SJohn Edward Broadbent } 833e56ed6b9SJohn Edward Broadbent 834e56ed6b9SJohn Edward Broadbent // Iterate over all retrieved ObjectPaths. 8358cb65f8aSNan Zhou for (const auto& [path, connectionNames] : subtree) 836e56ed6b9SJohn Edward Broadbent { 837e56ed6b9SJohn Edward Broadbent sdbusplus::message::object_path objPath(path); 838e56ed6b9SJohn Edward Broadbent if (objPath.filename() != driveName) 839e56ed6b9SJohn Edward Broadbent { 840e56ed6b9SJohn Edward Broadbent continue; 841e56ed6b9SJohn Edward Broadbent } 842e56ed6b9SJohn Edward Broadbent 843e56ed6b9SJohn Edward Broadbent if (connectionNames.empty()) 844e56ed6b9SJohn Edward Broadbent { 84562598e31SEd Tanous BMCWEB_LOG_ERROR("Got 0 Connection names"); 846e56ed6b9SJohn Edward Broadbent continue; 847e56ed6b9SJohn Edward Broadbent } 848e56ed6b9SJohn Edward Broadbent 849ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 850ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/Drives/{}", chassisId, driveName); 851e56ed6b9SJohn Edward Broadbent 852e56ed6b9SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; 853a0cb40cbSJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = driveName; 854e56ed6b9SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = driveName; 855e56ed6b9SJohn Edward Broadbent // default it to Enabled 856539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 857e56ed6b9SJohn Edward Broadbent 858e56ed6b9SJohn Edward Broadbent nlohmann::json::object_t linkChassisNav; 859e56ed6b9SJohn Edward Broadbent linkChassisNav["@odata.id"] = 860ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 861e56ed6b9SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["Chassis"] = linkChassisNav; 862e56ed6b9SJohn Edward Broadbent 863e56ed6b9SJohn Edward Broadbent addAllDriveInfo(asyncResp, connectionNames[0].first, path, 864e56ed6b9SJohn Edward Broadbent connectionNames[0].second); 865e56ed6b9SJohn Edward Broadbent } 866e56ed6b9SJohn Edward Broadbent } 867e56ed6b9SJohn Edward Broadbent 868bd79bce8SPatrick Williams inline void matchAndFillDrive( 869bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 870bd79bce8SPatrick Williams const std::string& chassisId, const std::string& driveName, 871e56ed6b9SJohn Edward Broadbent const std::vector<std::string>& resp) 872e56ed6b9SJohn Edward Broadbent { 873e56ed6b9SJohn Edward Broadbent for (const std::string& drivePath : resp) 874e56ed6b9SJohn Edward Broadbent { 875e56ed6b9SJohn Edward Broadbent sdbusplus::message::object_path path(drivePath); 876e56ed6b9SJohn Edward Broadbent std::string leaf = path.filename(); 877e56ed6b9SJohn Edward Broadbent if (leaf != driveName) 878e56ed6b9SJohn Edward Broadbent { 879e56ed6b9SJohn Edward Broadbent continue; 880e56ed6b9SJohn Edward Broadbent } 881e56ed6b9SJohn Edward Broadbent // mapper call drive 882e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> driveInterface = { 883e56ed6b9SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Drive"}; 884e99073f5SGeorge Liu dbus::utility::getSubTree( 885e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, driveInterface, 886e56ed6b9SJohn Edward Broadbent [asyncResp, chassisId, driveName]( 887e99073f5SGeorge Liu const boost::system::error_code& ec, 888e56ed6b9SJohn Edward Broadbent const dbus::utility::MapperGetSubTreeResponse& subtree) { 889e56ed6b9SJohn Edward Broadbent buildDrive(asyncResp, chassisId, driveName, ec, subtree); 890e99073f5SGeorge Liu }); 891e56ed6b9SJohn Edward Broadbent } 892e56ed6b9SJohn Edward Broadbent } 893e56ed6b9SJohn Edward Broadbent 894bd79bce8SPatrick Williams inline void handleChassisDriveGet( 895bd79bce8SPatrick Williams crow::App& app, const crow::Request& req, 896e56ed6b9SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 897bd79bce8SPatrick Williams const std::string& chassisId, const std::string& driveName) 898e56ed6b9SJohn Edward Broadbent { 89903810a11SMichal Orzel if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 900e56ed6b9SJohn Edward Broadbent { 901e56ed6b9SJohn Edward Broadbent return; 902e56ed6b9SJohn Edward Broadbent } 903e99073f5SGeorge Liu constexpr std::array<std::string_view, 2> interfaces = { 904e56ed6b9SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Board", 905e56ed6b9SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Chassis"}; 906e56ed6b9SJohn Edward Broadbent 907e56ed6b9SJohn Edward Broadbent // mapper call chassis 908e99073f5SGeorge Liu dbus::utility::getSubTree( 909e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 910e56ed6b9SJohn Edward Broadbent [asyncResp, chassisId, 911e99073f5SGeorge Liu driveName](const boost::system::error_code& ec, 912e56ed6b9SJohn Edward Broadbent const dbus::utility::MapperGetSubTreeResponse& subtree) { 913e56ed6b9SJohn Edward Broadbent if (ec) 914e56ed6b9SJohn Edward Broadbent { 915e56ed6b9SJohn Edward Broadbent messages::internalError(asyncResp->res); 916e56ed6b9SJohn Edward Broadbent return; 917e56ed6b9SJohn Edward Broadbent } 918e56ed6b9SJohn Edward Broadbent 919e56ed6b9SJohn Edward Broadbent // Iterate over all retrieved ObjectPaths. 9208cb65f8aSNan Zhou for (const auto& [path, connectionNames] : subtree) 921e56ed6b9SJohn Edward Broadbent { 922e56ed6b9SJohn Edward Broadbent sdbusplus::message::object_path objPath(path); 923e56ed6b9SJohn Edward Broadbent if (objPath.filename() != chassisId) 924e56ed6b9SJohn Edward Broadbent { 925e56ed6b9SJohn Edward Broadbent continue; 926e56ed6b9SJohn Edward Broadbent } 927e56ed6b9SJohn Edward Broadbent 928e56ed6b9SJohn Edward Broadbent if (connectionNames.empty()) 929e56ed6b9SJohn Edward Broadbent { 93062598e31SEd Tanous BMCWEB_LOG_ERROR("Got 0 Connection names"); 931e56ed6b9SJohn Edward Broadbent continue; 932e56ed6b9SJohn Edward Broadbent } 933e56ed6b9SJohn Edward Broadbent 9346c3e9451SGeorge Liu dbus::utility::getAssociationEndPoints( 9356c3e9451SGeorge Liu path + "/drive", 936e56ed6b9SJohn Edward Broadbent [asyncResp, chassisId, 9375e7e2dc5SEd Tanous driveName](const boost::system::error_code& ec3, 9386c3e9451SGeorge Liu const dbus::utility::MapperEndPoints& resp) { 939e56ed6b9SJohn Edward Broadbent if (ec3) 940e56ed6b9SJohn Edward Broadbent { 941e56ed6b9SJohn Edward Broadbent return; // no drives = no failures 942e56ed6b9SJohn Edward Broadbent } 943bd79bce8SPatrick Williams matchAndFillDrive(asyncResp, chassisId, driveName, 944bd79bce8SPatrick Williams resp); 945e56ed6b9SJohn Edward Broadbent }); 946e56ed6b9SJohn Edward Broadbent break; 947e56ed6b9SJohn Edward Broadbent } 948e99073f5SGeorge Liu }); 949e56ed6b9SJohn Edward Broadbent } 950e56ed6b9SJohn Edward Broadbent 951e56ed6b9SJohn Edward Broadbent /** 952e56ed6b9SJohn Edward Broadbent * This URL will show the drive interface for the specific drive in the chassis 953e56ed6b9SJohn Edward Broadbent */ 954e56ed6b9SJohn Edward Broadbent inline void requestRoutesChassisDriveName(App& app) 955e56ed6b9SJohn Edward Broadbent { 956e56ed6b9SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/<str>/") 957e56ed6b9SJohn Edward Broadbent .privileges(redfish::privileges::getChassis) 958e56ed6b9SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 959e56ed6b9SJohn Edward Broadbent std::bind_front(handleChassisDriveGet, std::ref(app))); 960e56ed6b9SJohn Edward Broadbent } 961e56ed6b9SJohn Edward Broadbent 96261b1eb21SWilly Tu inline void getStorageControllerAsset( 96361b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 96461b1eb21SWilly Tu const boost::system::error_code& ec, 96561b1eb21SWilly Tu const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& 96661b1eb21SWilly Tu propertiesList) 96761b1eb21SWilly Tu { 96861b1eb21SWilly Tu if (ec) 96961b1eb21SWilly Tu { 97061b1eb21SWilly Tu // this interface isn't necessary 97162598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to get StorageControllerAsset"); 97261b1eb21SWilly Tu return; 97361b1eb21SWilly Tu } 97461b1eb21SWilly Tu 97561b1eb21SWilly Tu const std::string* partNumber = nullptr; 97661b1eb21SWilly Tu const std::string* serialNumber = nullptr; 97761b1eb21SWilly Tu const std::string* manufacturer = nullptr; 97861b1eb21SWilly Tu const std::string* model = nullptr; 97961b1eb21SWilly Tu if (!sdbusplus::unpackPropertiesNoThrow( 98061b1eb21SWilly Tu dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", 98161b1eb21SWilly Tu partNumber, "SerialNumber", serialNumber, "Manufacturer", 98261b1eb21SWilly Tu manufacturer, "Model", model)) 98361b1eb21SWilly Tu { 98461b1eb21SWilly Tu messages::internalError(asyncResp->res); 98561b1eb21SWilly Tu return; 98661b1eb21SWilly Tu } 98761b1eb21SWilly Tu 98861b1eb21SWilly Tu if (partNumber != nullptr) 98961b1eb21SWilly Tu { 99061b1eb21SWilly Tu asyncResp->res.jsonValue["PartNumber"] = *partNumber; 99161b1eb21SWilly Tu } 99261b1eb21SWilly Tu 99361b1eb21SWilly Tu if (serialNumber != nullptr) 99461b1eb21SWilly Tu { 99561b1eb21SWilly Tu asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 99661b1eb21SWilly Tu } 99761b1eb21SWilly Tu 99861b1eb21SWilly Tu if (manufacturer != nullptr) 99961b1eb21SWilly Tu { 100061b1eb21SWilly Tu asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 100161b1eb21SWilly Tu } 100261b1eb21SWilly Tu 100361b1eb21SWilly Tu if (model != nullptr) 100461b1eb21SWilly Tu { 100561b1eb21SWilly Tu asyncResp->res.jsonValue["Model"] = *model; 100661b1eb21SWilly Tu } 100761b1eb21SWilly Tu } 100861b1eb21SWilly Tu 100961b1eb21SWilly Tu inline void populateStorageController( 101061b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 101161b1eb21SWilly Tu const std::string& controllerId, const std::string& connectionName, 101261b1eb21SWilly Tu const std::string& path) 101361b1eb21SWilly Tu { 101461b1eb21SWilly Tu asyncResp->res.jsonValue["@odata.type"] = 101561b1eb21SWilly Tu "#StorageController.v1_6_0.StorageController"; 1016253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1017253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Controllers/{}", 1018253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, controllerId); 101961b1eb21SWilly Tu asyncResp->res.jsonValue["Name"] = controllerId; 102061b1eb21SWilly Tu asyncResp->res.jsonValue["Id"] = controllerId; 1021539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 102261b1eb21SWilly Tu 1023deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1024deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.Inventory.Item", "Present", 102561b1eb21SWilly Tu [asyncResp](const boost::system::error_code& ec, bool isPresent) { 102661b1eb21SWilly Tu // this interface isn't necessary, only check it 102761b1eb21SWilly Tu // if we get a good return 102861b1eb21SWilly Tu if (ec) 102961b1eb21SWilly Tu { 103062598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to get Present property"); 103161b1eb21SWilly Tu return; 103261b1eb21SWilly Tu } 103361b1eb21SWilly Tu if (!isPresent) 103461b1eb21SWilly Tu { 1035539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 1036539d8c6bSEd Tanous resource::State::Absent; 103761b1eb21SWilly Tu } 103861b1eb21SWilly Tu }); 103961b1eb21SWilly Tu 1040deae6a78SEd Tanous dbus::utility::getAllProperties( 1041deae6a78SEd Tanous connectionName, path, "xyz.openbmc_project.Inventory.Decorator.Asset", 104261b1eb21SWilly Tu [asyncResp](const boost::system::error_code& ec, 104361b1eb21SWilly Tu const std::vector< 104461b1eb21SWilly Tu std::pair<std::string, dbus::utility::DbusVariantType>>& 104561b1eb21SWilly Tu propertiesList) { 104661b1eb21SWilly Tu getStorageControllerAsset(asyncResp, ec, propertiesList); 104761b1eb21SWilly Tu }); 104861b1eb21SWilly Tu } 104961b1eb21SWilly Tu 105061b1eb21SWilly Tu inline void getStorageControllerHandler( 105161b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 105261b1eb21SWilly Tu const std::string& controllerId, const boost::system::error_code& ec, 105361b1eb21SWilly Tu const dbus::utility::MapperGetSubTreeResponse& subtree) 105461b1eb21SWilly Tu { 105561b1eb21SWilly Tu if (ec || subtree.empty()) 105661b1eb21SWilly Tu { 105761b1eb21SWilly Tu // doesn't have to be there 105862598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to handle StorageController"); 105961b1eb21SWilly Tu return; 106061b1eb21SWilly Tu } 106161b1eb21SWilly Tu 106261b1eb21SWilly Tu for (const auto& [path, interfaceDict] : subtree) 106361b1eb21SWilly Tu { 106461b1eb21SWilly Tu sdbusplus::message::object_path object(path); 106561b1eb21SWilly Tu std::string id = object.filename(); 106661b1eb21SWilly Tu if (id.empty()) 106761b1eb21SWilly Tu { 106862598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find filename in {}", path); 106961b1eb21SWilly Tu return; 107061b1eb21SWilly Tu } 107161b1eb21SWilly Tu if (id != controllerId) 107261b1eb21SWilly Tu { 107361b1eb21SWilly Tu continue; 107461b1eb21SWilly Tu } 107561b1eb21SWilly Tu 107661b1eb21SWilly Tu if (interfaceDict.size() != 1) 107761b1eb21SWilly Tu { 107862598e31SEd Tanous BMCWEB_LOG_ERROR("Connection size {}, greater than 1", 107962598e31SEd Tanous interfaceDict.size()); 108061b1eb21SWilly Tu messages::internalError(asyncResp->res); 108161b1eb21SWilly Tu return; 108261b1eb21SWilly Tu } 108361b1eb21SWilly Tu 108461b1eb21SWilly Tu const std::string& connectionName = interfaceDict.front().first; 108561b1eb21SWilly Tu populateStorageController(asyncResp, controllerId, connectionName, 108661b1eb21SWilly Tu path); 108761b1eb21SWilly Tu } 108861b1eb21SWilly Tu } 108961b1eb21SWilly Tu 109061b1eb21SWilly Tu inline void populateStorageControllerCollection( 109161b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 109261b1eb21SWilly Tu const boost::system::error_code& ec, 109361b1eb21SWilly Tu const dbus::utility::MapperGetSubTreePathsResponse& controllerList) 109461b1eb21SWilly Tu { 109561b1eb21SWilly Tu nlohmann::json::array_t members; 109661b1eb21SWilly Tu if (ec || controllerList.empty()) 109761b1eb21SWilly Tu { 109861b1eb21SWilly Tu asyncResp->res.jsonValue["Members"] = std::move(members); 109961b1eb21SWilly Tu asyncResp->res.jsonValue["Members@odata.count"] = 0; 110062598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to find any StorageController"); 110161b1eb21SWilly Tu return; 110261b1eb21SWilly Tu } 110361b1eb21SWilly Tu 110461b1eb21SWilly Tu for (const std::string& path : controllerList) 110561b1eb21SWilly Tu { 110661b1eb21SWilly Tu std::string id = sdbusplus::message::object_path(path).filename(); 110761b1eb21SWilly Tu if (id.empty()) 110861b1eb21SWilly Tu { 110962598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find filename in {}", path); 111061b1eb21SWilly Tu return; 111161b1eb21SWilly Tu } 111261b1eb21SWilly Tu nlohmann::json::object_t member; 111361b1eb21SWilly Tu member["@odata.id"] = boost::urls::format( 1114253f11b8SEd Tanous "/redfish/v1/Systems/{}/Storage/1/Controllers/{}", 1115253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, id); 111661b1eb21SWilly Tu members.emplace_back(member); 111761b1eb21SWilly Tu } 111861b1eb21SWilly Tu asyncResp->res.jsonValue["Members@odata.count"] = members.size(); 111961b1eb21SWilly Tu asyncResp->res.jsonValue["Members"] = std::move(members); 112061b1eb21SWilly Tu } 112161b1eb21SWilly Tu 112236d52334SEd Tanous inline void handleSystemsStorageControllerCollectionGet( 112361b1eb21SWilly Tu App& app, const crow::Request& req, 112461b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 112561b1eb21SWilly Tu const std::string& systemName) 112661b1eb21SWilly Tu { 112761b1eb21SWilly Tu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 112861b1eb21SWilly Tu { 112962598e31SEd Tanous BMCWEB_LOG_DEBUG( 113062598e31SEd Tanous "Failed to setup Redfish Route for StorageController Collection"); 113161b1eb21SWilly Tu return; 113261b1eb21SWilly Tu } 1133253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 113461b1eb21SWilly Tu { 113561b1eb21SWilly Tu messages::resourceNotFound(asyncResp->res, "ComputerSystem", 113661b1eb21SWilly Tu systemName); 113762598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); 113861b1eb21SWilly Tu return; 113961b1eb21SWilly Tu } 114061b1eb21SWilly Tu 114161b1eb21SWilly Tu asyncResp->res.jsonValue["@odata.type"] = 114261b1eb21SWilly Tu "#StorageControllerCollection.StorageControllerCollection"; 114361b1eb21SWilly Tu asyncResp->res.jsonValue["@odata.id"] = 1144253f11b8SEd Tanous std::format("/redfish/v1/Systems/{}/Storage/1/Controllers", 1145253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 114661b1eb21SWilly Tu asyncResp->res.jsonValue["Name"] = "Storage Controller Collection"; 114761b1eb21SWilly Tu 114861b1eb21SWilly Tu constexpr std::array<std::string_view, 1> interfaces = { 114961b1eb21SWilly Tu "xyz.openbmc_project.Inventory.Item.StorageController"}; 115061b1eb21SWilly Tu dbus::utility::getSubTreePaths( 115161b1eb21SWilly Tu "/xyz/openbmc_project/inventory", 0, interfaces, 115261b1eb21SWilly Tu [asyncResp](const boost::system::error_code& ec, 115361b1eb21SWilly Tu const dbus::utility::MapperGetSubTreePathsResponse& 115461b1eb21SWilly Tu controllerList) { 115561b1eb21SWilly Tu populateStorageControllerCollection(asyncResp, ec, controllerList); 115661b1eb21SWilly Tu }); 115761b1eb21SWilly Tu } 115861b1eb21SWilly Tu 115936d52334SEd Tanous inline void handleSystemsStorageControllerGet( 116061b1eb21SWilly Tu App& app, const crow::Request& req, 116161b1eb21SWilly Tu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 116261b1eb21SWilly Tu const std::string& systemName, const std::string& controllerId) 116361b1eb21SWilly Tu { 116461b1eb21SWilly Tu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 116561b1eb21SWilly Tu { 116662598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to setup Redfish Route for StorageController"); 116761b1eb21SWilly Tu return; 116861b1eb21SWilly Tu } 1169253f11b8SEd Tanous if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) 117061b1eb21SWilly Tu { 117161b1eb21SWilly Tu messages::resourceNotFound(asyncResp->res, "ComputerSystem", 117261b1eb21SWilly Tu systemName); 117362598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); 117461b1eb21SWilly Tu return; 117561b1eb21SWilly Tu } 117661b1eb21SWilly Tu constexpr std::array<std::string_view, 1> interfaces = { 117761b1eb21SWilly Tu "xyz.openbmc_project.Inventory.Item.StorageController"}; 117861b1eb21SWilly Tu dbus::utility::getSubTree( 117961b1eb21SWilly Tu "/xyz/openbmc_project/inventory", 0, interfaces, 118061b1eb21SWilly Tu [asyncResp, 118161b1eb21SWilly Tu controllerId](const boost::system::error_code& ec, 118261b1eb21SWilly Tu const dbus::utility::MapperGetSubTreeResponse& subtree) { 118361b1eb21SWilly Tu getStorageControllerHandler(asyncResp, controllerId, ec, subtree); 118461b1eb21SWilly Tu }); 118561b1eb21SWilly Tu } 118661b1eb21SWilly Tu 118761b1eb21SWilly Tu inline void requestRoutesStorageControllerCollection(App& app) 118861b1eb21SWilly Tu { 118961b1eb21SWilly Tu BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/") 119061b1eb21SWilly Tu .privileges(redfish::privileges::getStorageControllerCollection) 119136d52334SEd Tanous .methods(boost::beast::http::verb::get)(std::bind_front( 119236d52334SEd Tanous handleSystemsStorageControllerCollectionGet, std::ref(app))); 119361b1eb21SWilly Tu } 119461b1eb21SWilly Tu 119561b1eb21SWilly Tu inline void requestRoutesStorageController(App& app) 119661b1eb21SWilly Tu { 119761b1eb21SWilly Tu BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/<str>") 119861b1eb21SWilly Tu .privileges(redfish::privileges::getStorageController) 119961b1eb21SWilly Tu .methods(boost::beast::http::verb::get)( 120036d52334SEd Tanous std::bind_front(handleSystemsStorageControllerGet, std::ref(app))); 120161b1eb21SWilly Tu } 120261b1eb21SWilly Tu 1203a25aeccfSNikhil Potade } // namespace redfish 1204