1e37f8451SRapkiewicz, Pawel /* 2e37f8451SRapkiewicz, Pawel // Copyright (c) 2018 Intel Corporation 3e37f8451SRapkiewicz, Pawel // 4e37f8451SRapkiewicz, Pawel // Licensed under the Apache License, Version 2.0 (the "License"); 5e37f8451SRapkiewicz, Pawel // you may not use this file except in compliance with the License. 6e37f8451SRapkiewicz, Pawel // You may obtain a copy of the License at 7e37f8451SRapkiewicz, Pawel // 8e37f8451SRapkiewicz, Pawel // http://www.apache.org/licenses/LICENSE-2.0 9e37f8451SRapkiewicz, Pawel // 10e37f8451SRapkiewicz, Pawel // Unless required by applicable law or agreed to in writing, software 11e37f8451SRapkiewicz, Pawel // distributed under the License is distributed on an "AS IS" BASIS, 12e37f8451SRapkiewicz, Pawel // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e37f8451SRapkiewicz, Pawel // See the License for the specific language governing permissions and 14e37f8451SRapkiewicz, Pawel // limitations under the License. 15e37f8451SRapkiewicz, Pawel */ 16e37f8451SRapkiewicz, Pawel #pragma once 17e37f8451SRapkiewicz, Pawel 183ccb3adbSEd Tanous #include "app.hpp" 197a1dbc48SGeorge Liu #include "dbus_utility.hpp" 20*539d8c6bSEd Tanous #include "generated/enums/action_info.hpp" 21*539d8c6bSEd Tanous #include "generated/enums/chassis.hpp" 22*539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 231c8fba97SJames Feist #include "led.hpp" 243ccb3adbSEd Tanous #include "query.hpp" 257164bc62SChau Ly #include "redfish_util.hpp" 263ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 273ccb3adbSEd Tanous #include "utils/collection.hpp" 283ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 29cf7eba09SNan Zhou #include "utils/json_utils.hpp" 301abe55efSEd Tanous 31e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 32ef4c65b7SEd Tanous #include <boost/url/format.hpp> 331e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 34fc903b3dSAndrew Geissler #include <sdbusplus/message.hpp> 3586d89ed7SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 361214b7e7SGunnar Mills 377a1dbc48SGeorge Liu #include <array> 383544d2a7SEd Tanous #include <ranges> 397a1dbc48SGeorge Liu #include <string_view> 407a1dbc48SGeorge Liu 411abe55efSEd Tanous namespace redfish 421abe55efSEd Tanous { 43e37f8451SRapkiewicz, Pawel 44e37f8451SRapkiewicz, Pawel /** 455e577bc1SWilly Tu * @brief Retrieves resources over dbus to link to the chassis 465e577bc1SWilly Tu * 475e577bc1SWilly Tu * @param[in] asyncResp - Shared pointer for completing asynchronous 485e577bc1SWilly Tu * calls 495e577bc1SWilly Tu * @param[in] path - Chassis dbus path to look for the storage. 505e577bc1SWilly Tu * 515e577bc1SWilly Tu * Calls the Association endpoints on the path + "/storage" and add the link of 525e577bc1SWilly Tu * json["Links"]["Storage@odata.count"] = 535e577bc1SWilly Tu * {"@odata.id", "/redfish/v1/Storage/" + resourceId} 545e577bc1SWilly Tu * 555e577bc1SWilly Tu * @return None. 565e577bc1SWilly Tu */ 575e577bc1SWilly Tu inline void getStorageLink(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 585e577bc1SWilly Tu const sdbusplus::message::object_path& path) 595e577bc1SWilly Tu { 605e577bc1SWilly Tu sdbusplus::asio::getProperty<std::vector<std::string>>( 615e577bc1SWilly Tu *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper", 625e577bc1SWilly Tu (path / "storage").str, "xyz.openbmc_project.Association", "endpoints", 63d4b054c1SWilly Tu [asyncResp](const boost::system::error_code& ec, 645e577bc1SWilly Tu const std::vector<std::string>& storageList) { 655e577bc1SWilly Tu if (ec) 665e577bc1SWilly Tu { 6762598e31SEd Tanous BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error"); 685e577bc1SWilly Tu return; 695e577bc1SWilly Tu } 705e577bc1SWilly Tu 715e577bc1SWilly Tu nlohmann::json::array_t storages; 725e577bc1SWilly Tu for (const std::string& storagePath : storageList) 735e577bc1SWilly Tu { 745e577bc1SWilly Tu std::string id = 755e577bc1SWilly Tu sdbusplus::message::object_path(storagePath).filename(); 765e577bc1SWilly Tu if (id.empty()) 775e577bc1SWilly Tu { 785e577bc1SWilly Tu continue; 795e577bc1SWilly Tu } 805e577bc1SWilly Tu 815e577bc1SWilly Tu nlohmann::json::object_t storage; 82253f11b8SEd Tanous storage["@odata.id"] = 83253f11b8SEd Tanous boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", 84253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME, id); 855e577bc1SWilly Tu storages.emplace_back(std::move(storage)); 865e577bc1SWilly Tu } 875e577bc1SWilly Tu asyncResp->res.jsonValue["Links"]["Storage@odata.count"] = 885e577bc1SWilly Tu storages.size(); 895e577bc1SWilly Tu asyncResp->res.jsonValue["Links"]["Storage"] = std::move(storages); 905e577bc1SWilly Tu }); 915e577bc1SWilly Tu } 925e577bc1SWilly Tu 935e577bc1SWilly Tu /** 94beeca0aeSGunnar Mills * @brief Retrieves chassis state properties over dbus 95beeca0aeSGunnar Mills * 96ac106bf6SEd Tanous * @param[in] asyncResp - Shared pointer for completing asynchronous calls. 97beeca0aeSGunnar Mills * 98beeca0aeSGunnar Mills * @return None. 99beeca0aeSGunnar Mills */ 100ac106bf6SEd Tanous inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> asyncResp) 101beeca0aeSGunnar Mills { 1021e1e598dSJonathan Doman // crow::connections::systemBus->async_method_call( 1031e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 1041e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", 1051e1e598dSJonathan Doman "/xyz/openbmc_project/state/chassis0", 1061e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "CurrentPowerState", 107ac106bf6SEd Tanous [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec, 1081e1e598dSJonathan Doman const std::string& chassisState) { 109beeca0aeSGunnar Mills if (ec) 110beeca0aeSGunnar Mills { 111a6e5e0abSCarson Labrado if (ec == boost::system::errc::host_unreachable) 112a6e5e0abSCarson Labrado { 113a6e5e0abSCarson Labrado // Service not available, no error, just don't return 114a6e5e0abSCarson Labrado // chassis state info 11562598e31SEd Tanous BMCWEB_LOG_DEBUG("Service not available {}", ec); 116a6e5e0abSCarson Labrado return; 117a6e5e0abSCarson Labrado } 11862598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error {}", ec); 119ac106bf6SEd Tanous messages::internalError(asyncResp->res); 120beeca0aeSGunnar Mills return; 121beeca0aeSGunnar Mills } 122beeca0aeSGunnar Mills 12362598e31SEd Tanous BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState); 124beeca0aeSGunnar Mills // Verify Chassis State 125002d39b4SEd Tanous if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On") 126beeca0aeSGunnar Mills { 127*539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; 128*539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 129*539d8c6bSEd Tanous resource::State::Enabled; 130beeca0aeSGunnar Mills } 1311e1e598dSJonathan Doman else if (chassisState == 132beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis.PowerState.Off") 133beeca0aeSGunnar Mills { 134*539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; 135*539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 136*539d8c6bSEd Tanous resource::State::StandbyOffline; 137beeca0aeSGunnar Mills } 1381e1e598dSJonathan Doman }); 139beeca0aeSGunnar Mills } 140beeca0aeSGunnar Mills 141c181942fSQiang XU /** 142c181942fSQiang XU * Retrieves physical security properties over dbus 143c181942fSQiang XU */ 1447164bc62SChau Ly inline void handlePhysicalSecurityGetSubTree( 1457164bc62SChau Ly const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 146e99073f5SGeorge Liu const boost::system::error_code& ec, 1477164bc62SChau Ly const dbus::utility::MapperGetSubTreeResponse& subtree) 1487164bc62SChau Ly { 149c181942fSQiang XU if (ec) 150c181942fSQiang XU { 1514e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 152c181942fSQiang XU // mandatory property 15362598e31SEd Tanous BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec); 154c181942fSQiang XU return; 155c181942fSQiang XU } 156c181942fSQiang XU // Iterate over all retrieved ObjectPaths. 157c181942fSQiang XU for (const auto& object : subtree) 158c181942fSQiang XU { 159840a9ffcSPatrick Williams if (!object.second.empty()) 160c181942fSQiang XU { 16189144a3aSEd Tanous const auto& service = object.second.front(); 1627164bc62SChau Ly 1637164bc62SChau Ly BMCWEB_LOG_DEBUG("Get intrusion status by service "); 1647164bc62SChau Ly 1657164bc62SChau Ly sdbusplus::asio::getProperty<std::string>( 1667164bc62SChau Ly *crow::connections::systemBus, service.first, object.first, 1677164bc62SChau Ly "xyz.openbmc_project.Chassis.Intrusion", "Status", 1687164bc62SChau Ly [asyncResp](const boost::system::error_code& ec1, 1697164bc62SChau Ly const std::string& value) { 1707164bc62SChau Ly if (ec1) 1717164bc62SChau Ly { 1727164bc62SChau Ly // do not add err msg in redfish response, because this is 1737164bc62SChau Ly // not 1747164bc62SChau Ly // mandatory property 1757164bc62SChau Ly BMCWEB_LOG_ERROR("DBUS response error {}", ec1); 1767164bc62SChau Ly return; 1777164bc62SChau Ly } 1787164bc62SChau Ly asyncResp->res 1797164bc62SChau Ly .jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1; 1807164bc62SChau Ly asyncResp->res 1817164bc62SChau Ly .jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value; 1827164bc62SChau Ly }); 1837164bc62SChau Ly 184c181942fSQiang XU return; 185c181942fSQiang XU } 186c181942fSQiang XU } 187c181942fSQiang XU } 188c181942fSQiang XU 189cf7eba09SNan Zhou inline void handleChassisCollectionGet( 190cf7eba09SNan Zhou App& app, const crow::Request& req, 191cf7eba09SNan Zhou const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1921abe55efSEd Tanous { 1933ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 19445ca1b86SEd Tanous { 19545ca1b86SEd Tanous return; 19645ca1b86SEd Tanous } 1978d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1988d1b46d7Szhanghch05 "#ChassisCollection.ChassisCollection"; 1998d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; 2008d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 201e37f8451SRapkiewicz, Pawel 2027a1dbc48SGeorge Liu constexpr std::array<std::string_view, 2> interfaces{ 2037a1dbc48SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board", 2047a1dbc48SGeorge Liu "xyz.openbmc_project.Inventory.Item.Chassis"}; 20502f6ff19SGunnar Mills collection_util::getCollectionMembers( 20636b5f1edSLakshmi Yadlapati asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces, 20736b5f1edSLakshmi Yadlapati "/xyz/openbmc_project/inventory"); 208cf7eba09SNan Zhou } 209cf7eba09SNan Zhou 210a5617496SJie Yang inline void getChassisContainedBy( 211a5617496SJie Yang const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 212a5617496SJie Yang const std::string& chassisId, const boost::system::error_code& ec, 21328ee563eSMyung Bae const dbus::utility::MapperGetSubTreePathsResponse& upstreamChassisPaths) 214a5617496SJie Yang { 215a5617496SJie Yang if (ec) 216a5617496SJie Yang { 217a5617496SJie Yang if (ec.value() != EBADR) 218a5617496SJie Yang { 21962598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 220a5617496SJie Yang messages::internalError(asyncResp->res); 221a5617496SJie Yang } 222a5617496SJie Yang return; 223a5617496SJie Yang } 224a5617496SJie Yang if (upstreamChassisPaths.empty()) 225a5617496SJie Yang { 226a5617496SJie Yang return; 227a5617496SJie Yang } 228a5617496SJie Yang if (upstreamChassisPaths.size() > 1) 229a5617496SJie Yang { 2308ece0e45SEd Tanous BMCWEB_LOG_ERROR("{} is contained by multiple chassis", chassisId); 231a5617496SJie Yang messages::internalError(asyncResp->res); 232a5617496SJie Yang return; 233a5617496SJie Yang } 234a5617496SJie Yang 235a5617496SJie Yang sdbusplus::message::object_path upstreamChassisPath( 236a5617496SJie Yang upstreamChassisPaths[0]); 237a5617496SJie Yang std::string upstreamChassis = upstreamChassisPath.filename(); 238a5617496SJie Yang if (upstreamChassis.empty()) 239a5617496SJie Yang { 24062598e31SEd Tanous BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}", 24162598e31SEd Tanous upstreamChassisPath.str, chassisId); 242a5617496SJie Yang return; 243a5617496SJie Yang } 244a5617496SJie Yang 245a5617496SJie Yang asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] = 246a5617496SJie Yang boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis); 247a5617496SJie Yang } 248a5617496SJie Yang 249a5617496SJie Yang inline void getChassisContains( 250a5617496SJie Yang const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 251a5617496SJie Yang const std::string& chassisId, const boost::system::error_code& ec, 25228ee563eSMyung Bae const dbus::utility::MapperGetSubTreePathsResponse& downstreamChassisPaths) 253a5617496SJie Yang { 254a5617496SJie Yang if (ec) 255a5617496SJie Yang { 256a5617496SJie Yang if (ec.value() != EBADR) 257a5617496SJie Yang { 25862598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 259a5617496SJie Yang messages::internalError(asyncResp->res); 260a5617496SJie Yang } 261a5617496SJie Yang return; 262a5617496SJie Yang } 263a5617496SJie Yang if (downstreamChassisPaths.empty()) 264a5617496SJie Yang { 265a5617496SJie Yang return; 266a5617496SJie Yang } 267a5617496SJie Yang nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"]; 268a5617496SJie Yang if (!jValue.is_array()) 269a5617496SJie Yang { 270a5617496SJie Yang // Create the array if it was empty 271a5617496SJie Yang jValue = nlohmann::json::array(); 272a5617496SJie Yang } 273a5617496SJie Yang for (const auto& p : downstreamChassisPaths) 274a5617496SJie Yang { 275a5617496SJie Yang sdbusplus::message::object_path downstreamChassisPath(p); 276a5617496SJie Yang std::string downstreamChassis = downstreamChassisPath.filename(); 277a5617496SJie Yang if (downstreamChassis.empty()) 278a5617496SJie Yang { 27962598e31SEd Tanous BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}", 28062598e31SEd Tanous downstreamChassisPath.str, chassisId); 281a5617496SJie Yang continue; 282a5617496SJie Yang } 283a5617496SJie Yang nlohmann::json link; 284a5617496SJie Yang link["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}", 285a5617496SJie Yang downstreamChassis); 286a5617496SJie Yang jValue.push_back(std::move(link)); 287a5617496SJie Yang } 288a5617496SJie Yang asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size(); 289a5617496SJie Yang } 290a5617496SJie Yang 291a5617496SJie Yang inline void 292a5617496SJie Yang getChassisConnectivity(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 293a5617496SJie Yang const std::string& chassisId, 294a5617496SJie Yang const std::string& chassisPath) 295a5617496SJie Yang { 29662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get chassis connectivity"); 297a5617496SJie Yang 29828ee563eSMyung Bae constexpr std::array<std::string_view, 2> interfaces{ 29928ee563eSMyung Bae "xyz.openbmc_project.Inventory.Item.Board", 30028ee563eSMyung Bae "xyz.openbmc_project.Inventory.Item.Chassis"}; 30128ee563eSMyung Bae 30228ee563eSMyung Bae dbus::utility::getAssociatedSubTreePaths( 303a5617496SJie Yang chassisPath + "/contained_by", 30428ee563eSMyung Bae sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0, 30528ee563eSMyung Bae interfaces, 306a5617496SJie Yang std::bind_front(getChassisContainedBy, asyncResp, chassisId)); 307a5617496SJie Yang 30828ee563eSMyung Bae dbus::utility::getAssociatedSubTreePaths( 309a5617496SJie Yang chassisPath + "/containing", 31028ee563eSMyung Bae sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0, 31128ee563eSMyung Bae interfaces, std::bind_front(getChassisContains, asyncResp, chassisId)); 312a5617496SJie Yang } 313a5617496SJie Yang 314cf7eba09SNan Zhou /** 315cf7eba09SNan Zhou * ChassisCollection derived class for delivering Chassis Collection Schema 316cf7eba09SNan Zhou * Functions triggers appropriate requests on DBus 317cf7eba09SNan Zhou */ 318cf7eba09SNan Zhou inline void requestRoutesChassisCollection(App& app) 319cf7eba09SNan Zhou { 320cf7eba09SNan Zhou BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") 321cf7eba09SNan Zhou .privileges(redfish::privileges::getChassisCollection) 322cf7eba09SNan Zhou .methods(boost::beast::http::verb::get)( 323cf7eba09SNan Zhou std::bind_front(handleChassisCollectionGet, std::ref(app))); 32462d5e2e4SEd Tanous } 325e37f8451SRapkiewicz, Pawel 326308f70c7SWilly Tu inline void 327308f70c7SWilly Tu getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 328308f70c7SWilly Tu const std::string& connectionName, 329308f70c7SWilly Tu const std::string& path) 330308f70c7SWilly Tu { 3311e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 3321e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 3331e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 3345e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 3351e1e598dSJonathan Doman const std::string& property) { 336308f70c7SWilly Tu if (ec) 337308f70c7SWilly Tu { 33862598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error for Location"); 339308f70c7SWilly Tu messages::internalError(asyncResp->res); 340308f70c7SWilly Tu return; 341308f70c7SWilly Tu } 342308f70c7SWilly Tu 343002d39b4SEd Tanous asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 3441e1e598dSJonathan Doman property; 3451e1e598dSJonathan Doman }); 346308f70c7SWilly Tu } 347308f70c7SWilly Tu 348308f70c7SWilly Tu inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 349308f70c7SWilly Tu const std::string& connectionName, 350308f70c7SWilly Tu const std::string& path) 351308f70c7SWilly Tu { 3521e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 3531e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 3541e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 3555e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 3561e1e598dSJonathan Doman const std::string& chassisUUID) { 357308f70c7SWilly Tu if (ec) 358308f70c7SWilly Tu { 35962598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error for UUID"); 360308f70c7SWilly Tu messages::internalError(asyncResp->res); 361308f70c7SWilly Tu return; 362308f70c7SWilly Tu } 3631e1e598dSJonathan Doman asyncResp->res.jsonValue["UUID"] = chassisUUID; 3641e1e598dSJonathan Doman }); 365308f70c7SWilly Tu } 366308f70c7SWilly Tu 3677164bc62SChau Ly inline void handleDecoratorAssetProperties( 36845ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 3697164bc62SChau Ly const std::string& chassisId, const std::string& path, 3707164bc62SChau Ly const dbus::utility::DBusPropertiesMap& propertiesList) 371cf7eba09SNan Zhou { 3727164bc62SChau Ly const std::string* partNumber = nullptr; 3737164bc62SChau Ly const std::string* serialNumber = nullptr; 3747164bc62SChau Ly const std::string* manufacturer = nullptr; 3757164bc62SChau Ly const std::string* model = nullptr; 3767164bc62SChau Ly const std::string* sparePartNumber = nullptr; 3777164bc62SChau Ly 3787164bc62SChau Ly const bool success = sdbusplus::unpackPropertiesNoThrow( 3797164bc62SChau Ly dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", 3807164bc62SChau Ly partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, 3817164bc62SChau Ly "Model", model, "SparePartNumber", sparePartNumber); 3827164bc62SChau Ly 3837164bc62SChau Ly if (!success) 38445ca1b86SEd Tanous { 3857164bc62SChau Ly messages::internalError(asyncResp->res); 38645ca1b86SEd Tanous return; 38745ca1b86SEd Tanous } 388734bfe90SGunnar Mills 3897164bc62SChau Ly if (partNumber != nullptr) 3907164bc62SChau Ly { 3917164bc62SChau Ly asyncResp->res.jsonValue["PartNumber"] = *partNumber; 3927164bc62SChau Ly } 3937164bc62SChau Ly 3947164bc62SChau Ly if (serialNumber != nullptr) 3957164bc62SChau Ly { 3967164bc62SChau Ly asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 3977164bc62SChau Ly } 3987164bc62SChau Ly 3997164bc62SChau Ly if (manufacturer != nullptr) 4007164bc62SChau Ly { 4017164bc62SChau Ly asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 4027164bc62SChau Ly } 4037164bc62SChau Ly 4047164bc62SChau Ly if (model != nullptr) 4057164bc62SChau Ly { 4067164bc62SChau Ly asyncResp->res.jsonValue["Model"] = *model; 4077164bc62SChau Ly } 4087164bc62SChau Ly 4097164bc62SChau Ly // SparePartNumber is optional on D-Bus 4107164bc62SChau Ly // so skip if it is empty 4117164bc62SChau Ly if (sparePartNumber != nullptr && !sparePartNumber->empty()) 4127164bc62SChau Ly { 4137164bc62SChau Ly asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 4147164bc62SChau Ly } 4157164bc62SChau Ly 4167164bc62SChau Ly asyncResp->res.jsonValue["Name"] = chassisId; 4177164bc62SChau Ly asyncResp->res.jsonValue["Id"] = chassisId; 41825b54dbaSEd Tanous 41925b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL) 42025b54dbaSEd Tanous { 4217164bc62SChau Ly asyncResp->res.jsonValue["Thermal"]["@odata.id"] = 4227164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId); 4237164bc62SChau Ly // Power object 4247164bc62SChau Ly asyncResp->res.jsonValue["Power"]["@odata.id"] = 4257164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId); 42625b54dbaSEd Tanous } 42725b54dbaSEd Tanous 42825b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM) 42925b54dbaSEd Tanous { 4307164bc62SChau Ly asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = 4317164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem", 4327164bc62SChau Ly chassisId); 4337164bc62SChau Ly asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = 43425b54dbaSEd Tanous boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", 43525b54dbaSEd Tanous chassisId); 4367164bc62SChau Ly asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = 4377164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics", 4387164bc62SChau Ly chassisId); 43925b54dbaSEd Tanous } 4407164bc62SChau Ly // SensorCollection 4417164bc62SChau Ly asyncResp->res.jsonValue["Sensors"]["@odata.id"] = 4427164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId); 443*539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 4447164bc62SChau Ly 4457164bc62SChau Ly nlohmann::json::array_t computerSystems; 4467164bc62SChau Ly nlohmann::json::object_t system; 447253f11b8SEd Tanous system["@odata.id"] = std::format("/redfish/v1/Systems/{}", 448253f11b8SEd Tanous BMCWEB_REDFISH_SYSTEM_URI_NAME); 4497164bc62SChau Ly computerSystems.emplace_back(std::move(system)); 4507164bc62SChau Ly asyncResp->res.jsonValue["Links"]["ComputerSystems"] = 4517164bc62SChau Ly std::move(computerSystems); 4527164bc62SChau Ly 4537164bc62SChau Ly nlohmann::json::array_t managedBy; 4547164bc62SChau Ly nlohmann::json::object_t manager; 455253f11b8SEd Tanous manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}", 456253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 4577164bc62SChau Ly managedBy.emplace_back(std::move(manager)); 4587164bc62SChau Ly asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); 4597164bc62SChau Ly getChassisState(asyncResp); 4607164bc62SChau Ly getStorageLink(asyncResp, path); 4617164bc62SChau Ly } 4627164bc62SChau Ly 4637164bc62SChau Ly inline void handleChassisGetSubTree( 4647164bc62SChau Ly const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4657164bc62SChau Ly const std::string& chassisId, const boost::system::error_code& ec, 4667164bc62SChau Ly const dbus::utility::MapperGetSubTreeResponse& subtree) 4677164bc62SChau Ly { 46862d5e2e4SEd Tanous if (ec) 4691abe55efSEd Tanous { 47062598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 471f12894f8SJason M. Bills messages::internalError(asyncResp->res); 472daf36e2eSEd Tanous return; 473daf36e2eSEd Tanous } 474daf36e2eSEd Tanous // Iterate over all retrieved ObjectPaths. 475cf7eba09SNan Zhou for (const std::pair< 476cf7eba09SNan Zhou std::string, 477cf7eba09SNan Zhou std::vector<std::pair<std::string, std::vector<std::string>>>>& 4781214b7e7SGunnar Mills object : subtree) 4791abe55efSEd Tanous { 480daf36e2eSEd Tanous const std::string& path = object.first; 481cf7eba09SNan Zhou const std::vector<std::pair<std::string, std::vector<std::string>>>& 4821214b7e7SGunnar Mills connectionNames = object.second; 4837e860f15SJohn Edward Broadbent 484997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 485997093ebSGeorge Liu if (objPath.filename() != chassisId) 4861abe55efSEd Tanous { 487daf36e2eSEd Tanous continue; 488daf36e2eSEd Tanous } 48926f03899SShawn McCarney 490a5617496SJie Yang getChassisConnectivity(asyncResp, chassisId, path); 491a5617496SJie Yang 49226f6976fSEd Tanous if (connectionNames.empty()) 4931abe55efSEd Tanous { 49462598e31SEd Tanous BMCWEB_LOG_ERROR("Got 0 Connection names"); 495e0d918bcSEd Tanous continue; 496daf36e2eSEd Tanous } 497e0d918bcSEd Tanous 4987164bc62SChau Ly asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis"; 49949c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.id"] = 500ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 50149c53ac9SJohnathan Mantey asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 502*539d8c6bSEd Tanous asyncResp->res.jsonValue["ChassisType"] = 503*539d8c6bSEd Tanous chassis::ChassisType::RackMount; 504cf7eba09SNan Zhou asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] = 5057164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset", 5067164bc62SChau Ly chassisId); 5071476687dSEd Tanous asyncResp->res 508cf7eba09SNan Zhou .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] = 509ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo", 510ef4c65b7SEd Tanous chassisId); 5116c3e9451SGeorge Liu dbus::utility::getAssociationEndPoints( 5126c3e9451SGeorge Liu path + "/drive", 5137164bc62SChau Ly [asyncResp, chassisId](const boost::system::error_code& ec3, 5146c3e9451SGeorge Liu const dbus::utility::MapperEndPoints& resp) { 51592903bd4SJohn Edward Broadbent if (ec3 || resp.empty()) 51692903bd4SJohn Edward Broadbent { 51792903bd4SJohn Edward Broadbent return; // no drives = no failures 51892903bd4SJohn Edward Broadbent } 51992903bd4SJohn Edward Broadbent 52092903bd4SJohn Edward Broadbent nlohmann::json reference; 5217164bc62SChau Ly reference["@odata.id"] = 5227164bc62SChau Ly boost::urls::format("/redfish/v1/Chassis/{}/Drives", chassisId); 52392903bd4SJohn Edward Broadbent asyncResp->res.jsonValue["Drives"] = std::move(reference); 52492903bd4SJohn Edward Broadbent }); 52592903bd4SJohn Edward Broadbent 526002d39b4SEd Tanous const std::string& connectionName = connectionNames[0].first; 5271c8fba97SJames Feist 5287164bc62SChau Ly const std::vector<std::string>& interfaces2 = connectionNames[0].second; 529e5ae9c1cSGeorge Liu const std::array<const char*, 3> hasIndicatorLed = { 530e5ae9c1cSGeorge Liu "xyz.openbmc_project.Inventory.Item.Chassis", 5311c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 5320fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 5331c8fba97SJames Feist 534476b9cc5STejas Patil const std::string assetTagInterface = 5350fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.AssetTag"; 536523d4868SLogananth Sundararaj const std::string replaceableInterface = 537523d4868SLogananth Sundararaj "xyz.openbmc_project.Inventory.Decorator.Replaceable"; 538b4d593f1SCarson Labrado const std::string revisionInterface = 539b4d593f1SCarson Labrado "xyz.openbmc_project.Inventory.Decorator.Revision"; 540523d4868SLogananth Sundararaj for (const auto& interface : interfaces2) 541523d4868SLogananth Sundararaj { 542523d4868SLogananth Sundararaj if (interface == assetTagInterface) 543476b9cc5STejas Patil { 5441e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 545002d39b4SEd Tanous *crow::connections::systemBus, connectionName, path, 546002d39b4SEd Tanous assetTagInterface, "AssetTag", 5477164bc62SChau Ly [asyncResp, chassisId](const boost::system::error_code& ec2, 5481e1e598dSJonathan Doman const std::string& property) { 5498a592810SEd Tanous if (ec2) 550476b9cc5STejas Patil { 5517164bc62SChau Ly BMCWEB_LOG_ERROR("DBus response error for AssetTag: {}", 5527164bc62SChau Ly ec2); 553476b9cc5STejas Patil messages::internalError(asyncResp->res); 554476b9cc5STejas Patil return; 555476b9cc5STejas Patil } 556002d39b4SEd Tanous asyncResp->res.jsonValue["AssetTag"] = property; 5571e1e598dSJonathan Doman }); 558476b9cc5STejas Patil } 559523d4868SLogananth Sundararaj else if (interface == replaceableInterface) 560523d4868SLogananth Sundararaj { 561523d4868SLogananth Sundararaj sdbusplus::asio::getProperty<bool>( 562523d4868SLogananth Sundararaj *crow::connections::systemBus, connectionName, path, 563523d4868SLogananth Sundararaj replaceableInterface, "HotPluggable", 5647164bc62SChau Ly [asyncResp, chassisId](const boost::system::error_code& ec2, 565523d4868SLogananth Sundararaj const bool property) { 566523d4868SLogananth Sundararaj if (ec2) 567523d4868SLogananth Sundararaj { 56862598e31SEd Tanous BMCWEB_LOG_ERROR( 5697164bc62SChau Ly "DBus response error for HotPluggable: {}", ec2); 570523d4868SLogananth Sundararaj messages::internalError(asyncResp->res); 571523d4868SLogananth Sundararaj return; 572523d4868SLogananth Sundararaj } 573523d4868SLogananth Sundararaj asyncResp->res.jsonValue["HotPluggable"] = property; 574523d4868SLogananth Sundararaj }); 575523d4868SLogananth Sundararaj } 576b4d593f1SCarson Labrado else if (interface == revisionInterface) 577b4d593f1SCarson Labrado { 578b4d593f1SCarson Labrado sdbusplus::asio::getProperty<std::string>( 579b4d593f1SCarson Labrado *crow::connections::systemBus, connectionName, path, 580b4d593f1SCarson Labrado revisionInterface, "Version", 581b4d593f1SCarson Labrado [asyncResp, chassisId](const boost::system::error_code& ec2, 582b4d593f1SCarson Labrado const std::string& property) { 583b4d593f1SCarson Labrado if (ec2) 584b4d593f1SCarson Labrado { 585b4d593f1SCarson Labrado BMCWEB_LOG_ERROR("DBus response error for Version: {}", 586b4d593f1SCarson Labrado ec2); 587b4d593f1SCarson Labrado messages::internalError(asyncResp->res); 588b4d593f1SCarson Labrado return; 589b4d593f1SCarson Labrado } 590b4d593f1SCarson Labrado asyncResp->res.jsonValue["Version"] = property; 591b4d593f1SCarson Labrado }); 592b4d593f1SCarson Labrado } 593523d4868SLogananth Sundararaj } 594476b9cc5STejas Patil 5951c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 5961c8fba97SJames Feist { 5977164bc62SChau Ly if (std::ranges::find(interfaces2, interface) != interfaces2.end()) 5981c8fba97SJames Feist { 5991c8fba97SJames Feist getIndicatorLedState(asyncResp); 60059a17e4fSGeorge Liu getSystemLocationIndicatorActive(asyncResp); 6011c8fba97SJames Feist break; 6021c8fba97SJames Feist } 6031c8fba97SJames Feist } 6041c8fba97SJames Feist 60586d89ed7SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 60686d89ed7SKrzysztof Grobelny *crow::connections::systemBus, connectionName, path, 60786d89ed7SKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 6087164bc62SChau Ly [asyncResp, chassisId, 6097164bc62SChau Ly path](const boost::system::error_code&, 610cf7eba09SNan Zhou const dbus::utility::DBusPropertiesMap& propertiesList) { 6117164bc62SChau Ly handleDecoratorAssetProperties(asyncResp, chassisId, path, 6127164bc62SChau Ly propertiesList); 61386d89ed7SKrzysztof Grobelny }); 6142c37b4b0SSharad Yadav 615308f70c7SWilly Tu for (const auto& interface : interfaces2) 6162c37b4b0SSharad Yadav { 617308f70c7SWilly Tu if (interface == "xyz.openbmc_project.Common.UUID") 6182c37b4b0SSharad Yadav { 619308f70c7SWilly Tu getChassisUUID(asyncResp, connectionName, path); 6202c37b4b0SSharad Yadav } 621cf7eba09SNan Zhou else if (interface == 6220fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 6232c37b4b0SSharad Yadav { 624002d39b4SEd Tanous getChassisLocationCode(asyncResp, connectionName, path); 6252c37b4b0SSharad Yadav } 6262c37b4b0SSharad Yadav } 6272c37b4b0SSharad Yadav 628daf36e2eSEd Tanous return; 629daf36e2eSEd Tanous } 630e0d918bcSEd Tanous 631daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 632d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 6337164bc62SChau Ly } 634c181942fSQiang XU 6357164bc62SChau Ly inline void 6367164bc62SChau Ly handleChassisGet(App& app, const crow::Request& req, 6377164bc62SChau Ly const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6387164bc62SChau Ly const std::string& chassisId) 6397164bc62SChau Ly { 6407164bc62SChau Ly if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 6417164bc62SChau Ly { 6427164bc62SChau Ly return; 6437164bc62SChau Ly } 6447164bc62SChau Ly constexpr std::array<std::string_view, 2> interfaces = { 6457164bc62SChau Ly "xyz.openbmc_project.Inventory.Item.Board", 6467164bc62SChau Ly "xyz.openbmc_project.Inventory.Item.Chassis"}; 6477164bc62SChau Ly 6487164bc62SChau Ly dbus::utility::getSubTree( 6497164bc62SChau Ly "/xyz/openbmc_project/inventory", 0, interfaces, 6507164bc62SChau Ly std::bind_front(handleChassisGetSubTree, asyncResp, chassisId)); 6517164bc62SChau Ly 6527164bc62SChau Ly constexpr std::array<std::string_view, 1> interfaces2 = { 6537164bc62SChau Ly "xyz.openbmc_project.Chassis.Intrusion"}; 6547164bc62SChau Ly 6557164bc62SChau Ly dbus::utility::getSubTree( 6567164bc62SChau Ly "/xyz/openbmc_project", 0, interfaces2, 6577164bc62SChau Ly std::bind_front(handlePhysicalSecurityGetSubTree, asyncResp)); 658cf7eba09SNan Zhou } 6591c8fba97SJames Feist 660cf7eba09SNan Zhou inline void 661cf7eba09SNan Zhou handleChassisPatch(App& app, const crow::Request& req, 6627e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 663cf7eba09SNan Zhou const std::string& param) 664cf7eba09SNan Zhou { 6653ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 66645ca1b86SEd Tanous { 66745ca1b86SEd Tanous return; 66845ca1b86SEd Tanous } 6699f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 6701c8fba97SJames Feist std::optional<std::string> indicatorLed; 6711c8fba97SJames Feist 6727e860f15SJohn Edward Broadbent if (param.empty()) 6731c8fba97SJames Feist { 6741c8fba97SJames Feist return; 6751c8fba97SJames Feist } 6761c8fba97SJames Feist 67715ed6780SWilly Tu if (!json_util::readJsonPatch( 6787e860f15SJohn Edward Broadbent req, asyncResp->res, "LocationIndicatorActive", 6797e860f15SJohn Edward Broadbent locationIndicatorActive, "IndicatorLED", indicatorLed)) 6801c8fba97SJames Feist { 6811c8fba97SJames Feist return; 6821c8fba97SJames Feist } 6831c8fba97SJames Feist 6849f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 6859f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 6861c8fba97SJames Feist { 6871c8fba97SJames Feist return; // delete this when we support more patch properties 6881c8fba97SJames Feist } 689d6aa0093SGunnar Mills if (indicatorLed) 690d6aa0093SGunnar Mills { 6917e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 6927e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 6930fda0f12SGeorge Liu "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); 694d6aa0093SGunnar Mills } 6951c8fba97SJames Feist 696e99073f5SGeorge Liu constexpr std::array<std::string_view, 2> interfaces = { 6971c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 6981c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 6991c8fba97SJames Feist 7007e860f15SJohn Edward Broadbent const std::string& chassisId = param; 7011c8fba97SJames Feist 702e99073f5SGeorge Liu dbus::utility::getSubTree( 703e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 704cf7eba09SNan Zhou [asyncResp, chassisId, locationIndicatorActive, 7055e7e2dc5SEd Tanous indicatorLed](const boost::system::error_code& ec, 706b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 7071c8fba97SJames Feist if (ec) 7081c8fba97SJames Feist { 70962598e31SEd Tanous BMCWEB_LOG_ERROR("DBUS response error {}", ec); 7101c8fba97SJames Feist messages::internalError(asyncResp->res); 7111c8fba97SJames Feist return; 7121c8fba97SJames Feist } 7131c8fba97SJames Feist 7141c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 715cf7eba09SNan Zhou for (const std::pair< 716cf7eba09SNan Zhou std::string, 717cf7eba09SNan Zhou std::vector<std::pair<std::string, std::vector<std::string>>>>& 7181214b7e7SGunnar Mills object : subtree) 7191c8fba97SJames Feist { 7201c8fba97SJames Feist const std::string& path = object.first; 721cf7eba09SNan Zhou const std::vector<std::pair<std::string, std::vector<std::string>>>& 7221214b7e7SGunnar Mills connectionNames = object.second; 7231c8fba97SJames Feist 724997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 725997093ebSGeorge Liu if (objPath.filename() != chassisId) 7261c8fba97SJames Feist { 7271c8fba97SJames Feist continue; 7281c8fba97SJames Feist } 7291c8fba97SJames Feist 73026f6976fSEd Tanous if (connectionNames.empty()) 7311c8fba97SJames Feist { 73262598e31SEd Tanous BMCWEB_LOG_ERROR("Got 0 Connection names"); 7331c8fba97SJames Feist continue; 7341c8fba97SJames Feist } 7351c8fba97SJames Feist 73623a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 7371c8fba97SJames Feist connectionNames[0].second; 7381c8fba97SJames Feist 739e5ae9c1cSGeorge Liu const std::array<const char*, 3> hasIndicatorLed = { 740e5ae9c1cSGeorge Liu "xyz.openbmc_project.Inventory.Item.Chassis", 7411c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 7420fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 7431c8fba97SJames Feist bool indicatorChassis = false; 7441c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 7451c8fba97SJames Feist { 7463544d2a7SEd Tanous if (std::ranges::find(interfaces3, interface) != 7473544d2a7SEd Tanous interfaces3.end()) 7481c8fba97SJames Feist { 7491c8fba97SJames Feist indicatorChassis = true; 7501c8fba97SJames Feist break; 7511c8fba97SJames Feist } 7521c8fba97SJames Feist } 7539f8bfa7cSGunnar Mills if (locationIndicatorActive) 7549f8bfa7cSGunnar Mills { 7559f8bfa7cSGunnar Mills if (indicatorChassis) 7569f8bfa7cSGunnar Mills { 75759a17e4fSGeorge Liu setSystemLocationIndicatorActive(asyncResp, 758002d39b4SEd Tanous *locationIndicatorActive); 7599f8bfa7cSGunnar Mills } 7609f8bfa7cSGunnar Mills else 7619f8bfa7cSGunnar Mills { 762002d39b4SEd Tanous messages::propertyUnknown(asyncResp->res, 763002d39b4SEd Tanous "LocationIndicatorActive"); 7649f8bfa7cSGunnar Mills } 7659f8bfa7cSGunnar Mills } 7669f8bfa7cSGunnar Mills if (indicatorLed) 7679f8bfa7cSGunnar Mills { 7681c8fba97SJames Feist if (indicatorChassis) 7691c8fba97SJames Feist { 770f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 7711c8fba97SJames Feist } 7721c8fba97SJames Feist else 7731c8fba97SJames Feist { 774cf7eba09SNan Zhou messages::propertyUnknown(asyncResp->res, "IndicatorLED"); 7751c8fba97SJames Feist } 7761c8fba97SJames Feist } 7771c8fba97SJames Feist return; 7781c8fba97SJames Feist } 7791c8fba97SJames Feist 780d8a5d5d8SJiaqing Zhao messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 781e99073f5SGeorge Liu }); 782cf7eba09SNan Zhou } 783cf7eba09SNan Zhou 784cf7eba09SNan Zhou /** 785cf7eba09SNan Zhou * Chassis override class for delivering Chassis Schema 786cf7eba09SNan Zhou * Functions triggers appropriate requests on DBus 787cf7eba09SNan Zhou */ 788cf7eba09SNan Zhou inline void requestRoutesChassis(App& app) 789cf7eba09SNan Zhou { 790cf7eba09SNan Zhou BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 791cf7eba09SNan Zhou .privileges(redfish::privileges::getChassis) 792cf7eba09SNan Zhou .methods(boost::beast::http::verb::get)( 793cf7eba09SNan Zhou std::bind_front(handleChassisGet, std::ref(app))); 794cf7eba09SNan Zhou 795cf7eba09SNan Zhou BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 796cf7eba09SNan Zhou .privileges(redfish::privileges::patchChassis) 797cf7eba09SNan Zhou .methods(boost::beast::http::verb::patch)( 798cf7eba09SNan Zhou std::bind_front(handleChassisPatch, std::ref(app))); 7991c8fba97SJames Feist } 800dd99e04bSP.K. Lee 8018d1b46d7Szhanghch05 inline void 8028d1b46d7Szhanghch05 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 803dd99e04bSP.K. Lee { 8047a1dbc48SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 805c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 806c3b3c92aSVijay Khemka 807c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 8087a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 8097a1dbc48SGeorge Liu "/", 0, interfaces, 810b9d36b47SEd Tanous [asyncResp]( 8117a1dbc48SGeorge Liu const boost::system::error_code& ec, 812b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { 813c3b3c92aSVijay Khemka if (ec) 814c3b3c92aSVijay Khemka { 81562598e31SEd Tanous BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec); 816c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 817c3b3c92aSVijay Khemka return; 818c3b3c92aSVijay Khemka } 819c3b3c92aSVijay Khemka 820dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 821dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 822dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 823dd99e04bSP.K. Lee const std::string propertyValue = 824dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 825002d39b4SEd Tanous std::string objectPath = "/xyz/openbmc_project/state/chassis_system0"; 826c3b3c92aSVijay Khemka 827c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 8283544d2a7SEd Tanous if ((std::ranges::find(chassisList, objectPath)) == chassisList.end()) 829c3b3c92aSVijay Khemka { 830c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 831c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 832c3b3c92aSVijay Khemka */ 833c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 834c3b3c92aSVijay Khemka } 835dd99e04bSP.K. Lee 836e93abac6SGinu George setDbusProperty(asyncResp, "ResetType", processName, objectPath, 837e93abac6SGinu George interfaceName, destProperty, propertyValue); 8387a1dbc48SGeorge Liu }); 839dd99e04bSP.K. Lee } 840dd99e04bSP.K. Lee 841cf7eba09SNan Zhou inline void handleChassisResetActionInfoPost( 842cf7eba09SNan Zhou App& app, const crow::Request& req, 8437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 844cf7eba09SNan Zhou const std::string& /*chassisId*/) 845cf7eba09SNan Zhou { 8463ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 84745ca1b86SEd Tanous { 84845ca1b86SEd Tanous return; 84945ca1b86SEd Tanous } 85062598e31SEd Tanous BMCWEB_LOG_DEBUG("Post Chassis Reset."); 851dd99e04bSP.K. Lee 852dd99e04bSP.K. Lee std::string resetType; 853dd99e04bSP.K. Lee 854cf7eba09SNan Zhou if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) 855dd99e04bSP.K. Lee { 856dd99e04bSP.K. Lee return; 857dd99e04bSP.K. Lee } 858dd99e04bSP.K. Lee 859dd99e04bSP.K. Lee if (resetType != "PowerCycle") 860dd99e04bSP.K. Lee { 86162598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType); 862002d39b4SEd Tanous messages::actionParameterNotSupported(asyncResp->res, resetType, 863002d39b4SEd Tanous "ResetType"); 864dd99e04bSP.K. Lee 865dd99e04bSP.K. Lee return; 866dd99e04bSP.K. Lee } 867dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 868dd99e04bSP.K. Lee } 8691cb1a9e6SAppaRao Puli 8701cb1a9e6SAppaRao Puli /** 871cf7eba09SNan Zhou * ChassisResetAction class supports the POST method for the Reset 872cf7eba09SNan Zhou * action. 873cf7eba09SNan Zhou * Function handles POST method request. 874cf7eba09SNan Zhou * Analyzes POST body before sending Reset request data to D-Bus. 8751cb1a9e6SAppaRao Puli */ 876cf7eba09SNan Zhou 877cf7eba09SNan Zhou inline void requestRoutesChassisResetAction(App& app) 8781cb1a9e6SAppaRao Puli { 879cf7eba09SNan Zhou BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") 880cf7eba09SNan Zhou .privileges(redfish::privileges::postChassis) 881cf7eba09SNan Zhou .methods(boost::beast::http::verb::post)( 882cf7eba09SNan Zhou std::bind_front(handleChassisResetActionInfoPost, std::ref(app))); 883cf7eba09SNan Zhou } 884cf7eba09SNan Zhou 885cf7eba09SNan Zhou inline void handleChassisResetActionInfoGet( 886cf7eba09SNan Zhou App& app, const crow::Request& req, 8877e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 888cf7eba09SNan Zhou const std::string& chassisId) 889cf7eba09SNan Zhou { 8903ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 8911cb1a9e6SAppaRao Puli { 89245ca1b86SEd Tanous return; 89345ca1b86SEd Tanous } 894cf7eba09SNan Zhou asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; 895ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 896ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId); 8971476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 8981476687dSEd Tanous 8991476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 9005b9e95a1SNan Zhou nlohmann::json::array_t parameters; 9015b9e95a1SNan Zhou nlohmann::json::object_t parameter; 9025b9e95a1SNan Zhou parameter["Name"] = "ResetType"; 9035b9e95a1SNan Zhou parameter["Required"] = true; 904*539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String; 9051476687dSEd Tanous nlohmann::json::array_t allowed; 906ad539545SPatrick Williams allowed.emplace_back("PowerCycle"); 9075b9e95a1SNan Zhou parameter["AllowableValues"] = std::move(allowed); 908ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 9095b9e95a1SNan Zhou 9101476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 911cf7eba09SNan Zhou } 912cf7eba09SNan Zhou 913cf7eba09SNan Zhou /** 914cf7eba09SNan Zhou * ChassisResetActionInfo derived class for delivering Chassis 915cf7eba09SNan Zhou * ResetType AllowableValues using ResetInfo schema. 916cf7eba09SNan Zhou */ 917cf7eba09SNan Zhou inline void requestRoutesChassisResetActionInfo(App& app) 918cf7eba09SNan Zhou { 919cf7eba09SNan Zhou BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") 920cf7eba09SNan Zhou .privileges(redfish::privileges::getActionInfo) 921cf7eba09SNan Zhou .methods(boost::beast::http::verb::get)( 922cf7eba09SNan Zhou std::bind_front(handleChassisResetActionInfoGet, std::ref(app))); 9231cb1a9e6SAppaRao Puli } 9241cb1a9e6SAppaRao Puli 925e37f8451SRapkiewicz, Pawel } // namespace redfish 926