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 18b49ac873SJames Feist #include "health.hpp" 191c8fba97SJames Feist #include "led.hpp" 201abe55efSEd Tanous 217e860f15SJohn Edward Broadbent #include <app.hpp> 22168e20c1SEd Tanous #include <dbus_utility.hpp> 23*45ca1b86SEd Tanous #include <query.hpp> 24ed398213SEd Tanous #include <registries/privilege_registry.hpp> 251e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 2602f6ff19SGunnar Mills #include <utils/collection.hpp> 271214b7e7SGunnar Mills 281abe55efSEd Tanous namespace redfish 291abe55efSEd Tanous { 30e37f8451SRapkiewicz, Pawel 31e37f8451SRapkiewicz, Pawel /** 32beeca0aeSGunnar Mills * @brief Retrieves chassis state properties over dbus 33beeca0aeSGunnar Mills * 34beeca0aeSGunnar Mills * @param[in] aResp - Shared pointer for completing asynchronous calls. 35beeca0aeSGunnar Mills * 36beeca0aeSGunnar Mills * @return None. 37beeca0aeSGunnar Mills */ 388d1b46d7Szhanghch05 inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) 39beeca0aeSGunnar Mills { 401e1e598dSJonathan Doman // crow::connections::systemBus->async_method_call( 411e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 421e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", 431e1e598dSJonathan Doman "/xyz/openbmc_project/state/chassis0", 441e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis", "CurrentPowerState", 451e1e598dSJonathan Doman [aResp{std::move(aResp)}](const boost::system::error_code ec, 461e1e598dSJonathan Doman const std::string& chassisState) { 47beeca0aeSGunnar Mills if (ec) 48beeca0aeSGunnar Mills { 49a6e5e0abSCarson Labrado if (ec == boost::system::errc::host_unreachable) 50a6e5e0abSCarson Labrado { 51a6e5e0abSCarson Labrado // Service not available, no error, just don't return 52a6e5e0abSCarson Labrado // chassis state info 53a6e5e0abSCarson Labrado BMCWEB_LOG_DEBUG << "Service not available " << ec; 54a6e5e0abSCarson Labrado return; 55a6e5e0abSCarson Labrado } 56beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 57beeca0aeSGunnar Mills messages::internalError(aResp->res); 58beeca0aeSGunnar Mills return; 59beeca0aeSGunnar Mills } 60beeca0aeSGunnar Mills 611e1e598dSJonathan Doman BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState; 62beeca0aeSGunnar Mills // Verify Chassis State 631e1e598dSJonathan Doman if (chassisState == 641e1e598dSJonathan Doman "xyz.openbmc_project.State.Chassis.PowerState.On") 65beeca0aeSGunnar Mills { 66beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 67beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Enabled"; 68beeca0aeSGunnar Mills } 691e1e598dSJonathan Doman else if (chassisState == 70beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis.PowerState.Off") 71beeca0aeSGunnar Mills { 72beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "Off"; 73beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; 74beeca0aeSGunnar Mills } 751e1e598dSJonathan Doman }); 76beeca0aeSGunnar Mills } 77beeca0aeSGunnar Mills 788d1b46d7Szhanghch05 inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 79c181942fSQiang XU const std::string& service, 80c181942fSQiang XU const std::string& objPath) 81c181942fSQiang XU { 82c181942fSQiang XU BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; 83c181942fSQiang XU 841e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 851e1e598dSJonathan Doman *crow::connections::systemBus, service, objPath, 861e1e598dSJonathan Doman "xyz.openbmc_project.Chassis.Intrusion", "Status", 87c181942fSQiang XU [aResp{std::move(aResp)}](const boost::system::error_code ec, 881e1e598dSJonathan Doman const std::string& value) { 89c181942fSQiang XU if (ec) 90c181942fSQiang XU { 914e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 92c181942fSQiang XU // mandatory property 93c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; 94c181942fSQiang XU return; 95c181942fSQiang XU } 96c181942fSQiang XU 97c181942fSQiang XU aResp->res.jsonValue["PhysicalSecurity"] = { 981e1e598dSJonathan Doman {"IntrusionSensorNumber", 1}, {"IntrusionSensor", value}}; 991e1e598dSJonathan Doman }); 100c181942fSQiang XU } 101c181942fSQiang XU 102c181942fSQiang XU /** 103c181942fSQiang XU * Retrieves physical security properties over dbus 104c181942fSQiang XU */ 1058d1b46d7Szhanghch05 inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) 106c181942fSQiang XU { 107c181942fSQiang XU crow::connections::systemBus->async_method_call( 108c181942fSQiang XU [aResp{std::move(aResp)}]( 109c181942fSQiang XU const boost::system::error_code ec, 110b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 111c181942fSQiang XU if (ec) 112c181942fSQiang XU { 1134e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 114c181942fSQiang XU // mandatory property 11554fbf177SAndrew Geissler BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec 116c181942fSQiang XU << "\n"; 117c181942fSQiang XU return; 118c181942fSQiang XU } 119c181942fSQiang XU // Iterate over all retrieved ObjectPaths. 120c181942fSQiang XU for (const auto& object : subtree) 121c181942fSQiang XU { 122c181942fSQiang XU for (const auto& service : object.second) 123c181942fSQiang XU { 124c181942fSQiang XU getIntrusionByService(aResp, service.first, object.first); 125c181942fSQiang XU return; 126c181942fSQiang XU } 127c181942fSQiang XU } 128c181942fSQiang XU }, 129c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", 130c181942fSQiang XU "/xyz/openbmc_project/object_mapper", 131c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", "GetSubTree", 132271584abSEd Tanous "/xyz/openbmc_project/Intrusion", 1, 133c181942fSQiang XU std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); 134c181942fSQiang XU } 135c181942fSQiang XU 136e37f8451SRapkiewicz, Pawel /** 137e37f8451SRapkiewicz, Pawel * ChassisCollection derived class for delivering Chassis Collection Schema 138e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 139e37f8451SRapkiewicz, Pawel */ 1407e860f15SJohn Edward Broadbent inline void requestRoutesChassisCollection(App& app) 1411abe55efSEd Tanous { 1427e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") 143ed398213SEd Tanous .privileges(redfish::privileges::getChassisCollection) 1447e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 145*45ca1b86SEd Tanous [&app](const crow::Request& req, 1467e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 147*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 148*45ca1b86SEd Tanous { 149*45ca1b86SEd Tanous return; 150*45ca1b86SEd Tanous } 1518d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1528d1b46d7Szhanghch05 "#ChassisCollection.ChassisCollection"; 1538d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; 1548d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 155e37f8451SRapkiewicz, Pawel 15602f6ff19SGunnar Mills collection_util::getCollectionMembers( 15702f6ff19SGunnar Mills asyncResp, "/redfish/v1/Chassis", 15802f6ff19SGunnar Mills {"xyz.openbmc_project.Inventory.Item.Board", 15902f6ff19SGunnar Mills "xyz.openbmc_project.Inventory.Item.Chassis"}); 1607e860f15SJohn Edward Broadbent }); 16162d5e2e4SEd Tanous } 162e37f8451SRapkiewicz, Pawel 163308f70c7SWilly Tu inline void 164308f70c7SWilly Tu getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 165308f70c7SWilly Tu const std::string& connectionName, 166308f70c7SWilly Tu const std::string& path) 167308f70c7SWilly Tu { 1681e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 1691e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 1701e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 171308f70c7SWilly Tu [asyncResp](const boost::system::error_code ec, 1721e1e598dSJonathan Doman const std::string& property) { 173308f70c7SWilly Tu if (ec) 174308f70c7SWilly Tu { 1750fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error for Location"; 176308f70c7SWilly Tu messages::internalError(asyncResp->res); 177308f70c7SWilly Tu return; 178308f70c7SWilly Tu } 179308f70c7SWilly Tu 180308f70c7SWilly Tu asyncResp->res 1811e1e598dSJonathan Doman .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 1821e1e598dSJonathan Doman property; 1831e1e598dSJonathan Doman }); 184308f70c7SWilly Tu } 185308f70c7SWilly Tu 186308f70c7SWilly Tu inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 187308f70c7SWilly Tu const std::string& connectionName, 188308f70c7SWilly Tu const std::string& path) 189308f70c7SWilly Tu { 1901e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 1911e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 1921e1e598dSJonathan Doman "xyz.openbmc_project.Common.UUID", "UUID", 193308f70c7SWilly Tu [asyncResp](const boost::system::error_code ec, 1941e1e598dSJonathan Doman const std::string& chassisUUID) { 195308f70c7SWilly Tu if (ec) 196308f70c7SWilly Tu { 1970fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error for UUID"; 198308f70c7SWilly Tu messages::internalError(asyncResp->res); 199308f70c7SWilly Tu return; 200308f70c7SWilly Tu } 2011e1e598dSJonathan Doman asyncResp->res.jsonValue["UUID"] = chassisUUID; 2021e1e598dSJonathan Doman }); 203308f70c7SWilly Tu } 204308f70c7SWilly Tu 205e37f8451SRapkiewicz, Pawel /** 206e37f8451SRapkiewicz, Pawel * Chassis override class for delivering Chassis Schema 207e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 208e37f8451SRapkiewicz, Pawel */ 2097e860f15SJohn Edward Broadbent inline void requestRoutesChassis(App& app) 2101abe55efSEd Tanous { 2117e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 212ed398213SEd Tanous .privileges(redfish::privileges::getChassis) 2137e860f15SJohn Edward Broadbent .methods( 214*45ca1b86SEd Tanous boost::beast::http::verb:: 215*45ca1b86SEd Tanous get)([&app](const crow::Request& req, 216*45ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2177e860f15SJohn Edward Broadbent const std::string& chassisId) { 218*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 219*45ca1b86SEd Tanous { 220*45ca1b86SEd Tanous return; 221*45ca1b86SEd Tanous } 222adc4f0dbSShawn McCarney const std::array<const char*, 2> interfaces = { 223734bfe90SGunnar Mills "xyz.openbmc_project.Inventory.Item.Board", 224adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.Chassis"}; 225734bfe90SGunnar Mills 22655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 22762d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 22862d5e2e4SEd Tanous const boost::system::error_code ec, 229b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 23062d5e2e4SEd Tanous if (ec) 2311abe55efSEd Tanous { 232f12894f8SJason M. Bills messages::internalError(asyncResp->res); 233daf36e2eSEd Tanous return; 234daf36e2eSEd Tanous } 235daf36e2eSEd Tanous // Iterate over all retrieved ObjectPaths. 2361abe55efSEd Tanous for (const std::pair< 2371abe55efSEd Tanous std::string, 2387e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 2397e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 2401214b7e7SGunnar Mills object : subtree) 2411abe55efSEd Tanous { 242daf36e2eSEd Tanous const std::string& path = object.first; 2431abe55efSEd Tanous const std::vector< 2441214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 2451214b7e7SGunnar Mills connectionNames = object.second; 2467e860f15SJohn Edward Broadbent 247997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 248997093ebSGeorge Liu if (objPath.filename() != chassisId) 2491abe55efSEd Tanous { 250daf36e2eSEd Tanous continue; 251daf36e2eSEd Tanous } 25226f03899SShawn McCarney 2537e860f15SJohn Edward Broadbent auto health = 2547e860f15SJohn Edward Broadbent std::make_shared<HealthPopulate>(asyncResp); 255b49ac873SJames Feist 2561e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::vector<std::string>>( 2571e1e598dSJonathan Doman *crow::connections::systemBus, 2581e1e598dSJonathan Doman "xyz.openbmc_project.ObjectMapper", 2591e1e598dSJonathan Doman path + "/all_sensors", 2601e1e598dSJonathan Doman "xyz.openbmc_project.Association", "endpoints", 261168e20c1SEd Tanous [health](const boost::system::error_code ec2, 2621e1e598dSJonathan Doman const std::vector<std::string>& resp) { 26323a21a1cSEd Tanous if (ec2) 264b49ac873SJames Feist { 265b49ac873SJames Feist return; // no sensors = no failures 266b49ac873SJames Feist } 2671e1e598dSJonathan Doman health->inventory = resp; 2681e1e598dSJonathan Doman }); 269b49ac873SJames Feist 270b49ac873SJames Feist health->populate(); 271b49ac873SJames Feist 27226f6976fSEd Tanous if (connectionNames.empty()) 2731abe55efSEd Tanous { 2741c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 275e0d918bcSEd Tanous continue; 276daf36e2eSEd Tanous } 277e0d918bcSEd Tanous 27849c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.type"] = 2795ac5a2f4SGunnar Mills "#Chassis.v1_16_0.Chassis"; 28049c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.id"] = 28149c53ac9SJohnathan Mantey "/redfish/v1/Chassis/" + chassisId; 28249c53ac9SJohnathan Mantey asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 28349c53ac9SJohnathan Mantey asyncResp->res.jsonValue["ChassisType"] = "RackMount"; 2847e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = 2857e860f15SJohn Edward Broadbent {{"target", "/redfish/v1/Chassis/" + chassisId + 286dd99e04bSP.K. Lee "/Actions/Chassis.Reset"}, 2871cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + 2881cb1a9e6SAppaRao Puli chassisId + 2891cb1a9e6SAppaRao Puli "/ResetActionInfo"}}; 290adbe192aSJason M. Bills asyncResp->res.jsonValue["PCIeDevices"] = { 291adbe192aSJason M. Bills {"@odata.id", 292adbe192aSJason M. Bills "/redfish/v1/Systems/system/PCIeDevices"}}; 29349c53ac9SJohnathan Mantey 29449c53ac9SJohnathan Mantey const std::string& connectionName = 29549c53ac9SJohnathan Mantey connectionNames[0].first; 2961c8fba97SJames Feist 29723a21a1cSEd Tanous const std::vector<std::string>& interfaces2 = 2981c8fba97SJames Feist connectionNames[0].second; 2991c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 3001c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 3010fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 3021c8fba97SJames Feist 303476b9cc5STejas Patil const std::string assetTagInterface = 3040fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.AssetTag"; 305476b9cc5STejas Patil if (std::find(interfaces2.begin(), interfaces2.end(), 306476b9cc5STejas Patil assetTagInterface) != interfaces2.end()) 307476b9cc5STejas Patil { 3081e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 3091e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, 3101e1e598dSJonathan Doman path, assetTagInterface, "AssetTag", 311476b9cc5STejas Patil [asyncResp, chassisId(std::string(chassisId))]( 312476b9cc5STejas Patil const boost::system::error_code ec, 3131e1e598dSJonathan Doman const std::string& property) { 314476b9cc5STejas Patil if (ec) 315476b9cc5STejas Patil { 316476b9cc5STejas Patil BMCWEB_LOG_DEBUG 3170fda0f12SGeorge Liu << "DBus response error for AssetTag"; 318476b9cc5STejas Patil messages::internalError(asyncResp->res); 319476b9cc5STejas Patil return; 320476b9cc5STejas Patil } 321476b9cc5STejas Patil asyncResp->res.jsonValue["AssetTag"] = 3221e1e598dSJonathan Doman property; 3231e1e598dSJonathan Doman }); 324476b9cc5STejas Patil } 325476b9cc5STejas Patil 3261c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 3271c8fba97SJames Feist { 3287e860f15SJohn Edward Broadbent if (std::find(interfaces2.begin(), 3297e860f15SJohn Edward Broadbent interfaces2.end(), 33023a21a1cSEd Tanous interface) != interfaces2.end()) 3311c8fba97SJames Feist { 3321c8fba97SJames Feist getIndicatorLedState(asyncResp); 3339f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 3341c8fba97SJames Feist break; 3351c8fba97SJames Feist } 3361c8fba97SJames Feist } 3371c8fba97SJames Feist 33855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 33962d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 34090728b54SEd Tanous const boost::system::error_code /*ec2*/, 341b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 3427e860f15SJohn Edward Broadbent propertiesList) { 343168e20c1SEd Tanous for (const std::pair< 344168e20c1SEd Tanous std::string, 345168e20c1SEd Tanous dbus::utility::DbusVariantType>& 3461214b7e7SGunnar Mills property : propertiesList) 3471abe55efSEd Tanous { 3487e860f15SJohn Edward Broadbent // Store DBus properties that are also 3497e860f15SJohn Edward Broadbent // Redfish properties with same name and a 3507e860f15SJohn Edward Broadbent // string value 35199cffd7fSShawn McCarney const std::string& propertyName = 35299cffd7fSShawn McCarney property.first; 35399cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 35499cffd7fSShawn McCarney (propertyName == "SerialNumber") || 35599cffd7fSShawn McCarney (propertyName == "Manufacturer") || 356caa11f7aSAlpana Kumari (propertyName == "Model") || 357caa11f7aSAlpana Kumari (propertyName == "SparePartNumber")) 35899cffd7fSShawn McCarney { 359daf36e2eSEd Tanous const std::string* value = 36099cffd7fSShawn McCarney std::get_if<std::string>( 36199cffd7fSShawn McCarney &property.second); 362caa11f7aSAlpana Kumari if (value == nullptr) 3631abe55efSEd Tanous { 364caa11f7aSAlpana Kumari BMCWEB_LOG_ERROR 365caa11f7aSAlpana Kumari << "Null value returned for " 366caa11f7aSAlpana Kumari << propertyName; 367caa11f7aSAlpana Kumari messages::internalError( 368caa11f7aSAlpana Kumari asyncResp->res); 369caa11f7aSAlpana Kumari return; 370daf36e2eSEd Tanous } 371caa11f7aSAlpana Kumari // SparePartNumber is optional on D-Bus 372caa11f7aSAlpana Kumari // so skip if it is empty 373caa11f7aSAlpana Kumari if (propertyName == "SparePartNumber") 374caa11f7aSAlpana Kumari { 37526f6976fSEd Tanous if (value->empty()) 376caa11f7aSAlpana Kumari { 377caa11f7aSAlpana Kumari continue; 378caa11f7aSAlpana Kumari } 379caa11f7aSAlpana Kumari } 380caa11f7aSAlpana Kumari asyncResp->res.jsonValue[propertyName] = 381caa11f7aSAlpana Kumari *value; 382daf36e2eSEd Tanous } 38399cffd7fSShawn McCarney } 38462d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 38562d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 3860256b694Szhanghch05 #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL 38762d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 3881abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3891abe55efSEd Tanous chassisId + "/Thermal"}}; 3902474adfaSEd Tanous // Power object 3912474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 3922474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3932474adfaSEd Tanous chassisId + "/Power"}}; 3940256b694Szhanghch05 #endif 39595a3ecadSAnthony Wilson // SensorCollection 39695a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 39795a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 39895a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 399029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 400029573d4SEd Tanous {"State", "Enabled"}, 401029573d4SEd Tanous }; 4022474adfaSEd Tanous 403029573d4SEd Tanous asyncResp->res 404029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 4057e860f15SJohn Edward Broadbent {{"@odata.id", 4067e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"}}}; 4077e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["ManagedBy"] = 4087e860f15SJohn Edward Broadbent {{{"@odata.id", 4097e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc"}}}; 410beeca0aeSGunnar Mills getChassisState(asyncResp); 411daf36e2eSEd Tanous }, 4127e860f15SJohn Edward Broadbent connectionName, path, 4137e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 4141abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 4152c37b4b0SSharad Yadav 416308f70c7SWilly Tu for (const auto& interface : interfaces2) 4172c37b4b0SSharad Yadav { 418308f70c7SWilly Tu if (interface == "xyz.openbmc_project.Common.UUID") 4192c37b4b0SSharad Yadav { 420308f70c7SWilly Tu getChassisUUID(asyncResp, connectionName, path); 4212c37b4b0SSharad Yadav } 4220fda0f12SGeorge Liu else if ( 4230fda0f12SGeorge Liu interface == 4240fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 4252c37b4b0SSharad Yadav { 426308f70c7SWilly Tu getChassisLocationCode(asyncResp, 427308f70c7SWilly Tu connectionName, path); 4282c37b4b0SSharad Yadav } 4292c37b4b0SSharad Yadav } 4302c37b4b0SSharad Yadav 431daf36e2eSEd Tanous return; 432daf36e2eSEd Tanous } 433e0d918bcSEd Tanous 434daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 435f12894f8SJason M. Bills messages::resourceNotFound( 4365ac5a2f4SGunnar Mills asyncResp->res, "#Chassis.v1_16_0.Chassis", chassisId); 437daf36e2eSEd Tanous }, 438daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 439daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 440daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 441271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 442c181942fSQiang XU 443c181942fSQiang XU getPhysicalSecurityData(asyncResp); 4447e860f15SJohn Edward Broadbent }); 4451c8fba97SJames Feist 4467e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 447ed398213SEd Tanous .privileges(redfish::privileges::patchChassis) 4487e860f15SJohn Edward Broadbent .methods( 4497e860f15SJohn Edward Broadbent boost::beast::http::verb:: 450*45ca1b86SEd Tanous patch)([&app]( 451*45ca1b86SEd Tanous const crow::Request& req, 4527e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4537e860f15SJohn Edward Broadbent const std::string& param) { 454*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 455*45ca1b86SEd Tanous { 456*45ca1b86SEd Tanous return; 457*45ca1b86SEd Tanous } 4589f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 4591c8fba97SJames Feist std::optional<std::string> indicatorLed; 4601c8fba97SJames Feist 4617e860f15SJohn Edward Broadbent if (param.empty()) 4621c8fba97SJames Feist { 4631c8fba97SJames Feist return; 4641c8fba97SJames Feist } 4651c8fba97SJames Feist 46615ed6780SWilly Tu if (!json_util::readJsonPatch( 4677e860f15SJohn Edward Broadbent req, asyncResp->res, "LocationIndicatorActive", 4687e860f15SJohn Edward Broadbent locationIndicatorActive, "IndicatorLED", indicatorLed)) 4691c8fba97SJames Feist { 4701c8fba97SJames Feist return; 4711c8fba97SJames Feist } 4721c8fba97SJames Feist 4739f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 4749f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 4751c8fba97SJames Feist { 4761c8fba97SJames Feist return; // delete this when we support more patch properties 4771c8fba97SJames Feist } 478d6aa0093SGunnar Mills if (indicatorLed) 479d6aa0093SGunnar Mills { 4807e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 4817e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 4820fda0f12SGeorge Liu "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); 483d6aa0093SGunnar Mills } 4841c8fba97SJames Feist 4851c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 4861c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 4871c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 4881c8fba97SJames Feist 4897e860f15SJohn Edward Broadbent const std::string& chassisId = param; 4901c8fba97SJames Feist 4911c8fba97SJames Feist crow::connections::systemBus->async_method_call( 4929f8bfa7cSGunnar Mills [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( 4931c8fba97SJames Feist const boost::system::error_code ec, 494b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 4951c8fba97SJames Feist if (ec) 4961c8fba97SJames Feist { 4971c8fba97SJames Feist messages::internalError(asyncResp->res); 4981c8fba97SJames Feist return; 4991c8fba97SJames Feist } 5001c8fba97SJames Feist 5011c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 5021c8fba97SJames Feist for (const std::pair< 5031c8fba97SJames Feist std::string, 5047e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 5057e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 5061214b7e7SGunnar Mills object : subtree) 5071c8fba97SJames Feist { 5081c8fba97SJames Feist const std::string& path = object.first; 5091c8fba97SJames Feist const std::vector< 5101214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 5111214b7e7SGunnar Mills connectionNames = object.second; 5121c8fba97SJames Feist 513997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 514997093ebSGeorge Liu if (objPath.filename() != chassisId) 5151c8fba97SJames Feist { 5161c8fba97SJames Feist continue; 5171c8fba97SJames Feist } 5181c8fba97SJames Feist 51926f6976fSEd Tanous if (connectionNames.empty()) 5201c8fba97SJames Feist { 5211c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 5221c8fba97SJames Feist continue; 5231c8fba97SJames Feist } 5241c8fba97SJames Feist 52523a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 5261c8fba97SJames Feist connectionNames[0].second; 5271c8fba97SJames Feist 5281c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 5291c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 5300fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 5311c8fba97SJames Feist bool indicatorChassis = false; 5321c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 5331c8fba97SJames Feist { 5347e860f15SJohn Edward Broadbent if (std::find(interfaces3.begin(), 5357e860f15SJohn Edward Broadbent interfaces3.end(), 53623a21a1cSEd Tanous interface) != interfaces3.end()) 5371c8fba97SJames Feist { 5381c8fba97SJames Feist indicatorChassis = true; 5391c8fba97SJames Feist break; 5401c8fba97SJames Feist } 5411c8fba97SJames Feist } 5429f8bfa7cSGunnar Mills if (locationIndicatorActive) 5439f8bfa7cSGunnar Mills { 5449f8bfa7cSGunnar Mills if (indicatorChassis) 5459f8bfa7cSGunnar Mills { 5469f8bfa7cSGunnar Mills setLocationIndicatorActive( 5479f8bfa7cSGunnar Mills asyncResp, *locationIndicatorActive); 5489f8bfa7cSGunnar Mills } 5499f8bfa7cSGunnar Mills else 5509f8bfa7cSGunnar Mills { 5519f8bfa7cSGunnar Mills messages::propertyUnknown( 5529f8bfa7cSGunnar Mills asyncResp->res, "LocationIndicatorActive"); 5539f8bfa7cSGunnar Mills } 5549f8bfa7cSGunnar Mills } 5559f8bfa7cSGunnar Mills if (indicatorLed) 5569f8bfa7cSGunnar Mills { 5571c8fba97SJames Feist if (indicatorChassis) 5581c8fba97SJames Feist { 559f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 5601c8fba97SJames Feist } 5611c8fba97SJames Feist else 5621c8fba97SJames Feist { 5631c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 5641c8fba97SJames Feist "IndicatorLED"); 5651c8fba97SJames Feist } 5661c8fba97SJames Feist } 5671c8fba97SJames Feist return; 5681c8fba97SJames Feist } 5691c8fba97SJames Feist 5701c8fba97SJames Feist messages::resourceNotFound( 5719f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 5721c8fba97SJames Feist }, 5731c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 5741c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 5751c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5761c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 5777e860f15SJohn Edward Broadbent }); 5781c8fba97SJames Feist } 579dd99e04bSP.K. Lee 5808d1b46d7Szhanghch05 inline void 5818d1b46d7Szhanghch05 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 582dd99e04bSP.K. Lee { 583c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 584c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 585c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 586c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 587c3b3c92aSVijay Khemka 588c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 589c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 590c3b3c92aSVijay Khemka 591c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 592c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 593b9d36b47SEd Tanous [asyncResp]( 594b9d36b47SEd Tanous const boost::system::error_code ec, 595b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { 596c3b3c92aSVijay Khemka if (ec) 597c3b3c92aSVijay Khemka { 598c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 599c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 600c3b3c92aSVijay Khemka return; 601c3b3c92aSVijay Khemka } 602c3b3c92aSVijay Khemka 603dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 604dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 605dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 606dd99e04bSP.K. Lee const std::string propertyValue = 607dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 608c3b3c92aSVijay Khemka std::string objectPath = 609c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 610c3b3c92aSVijay Khemka 611c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 612c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 613c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 614c3b3c92aSVijay Khemka { 615c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 616c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 617c3b3c92aSVijay Khemka */ 618c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 619c3b3c92aSVijay Khemka } 620dd99e04bSP.K. Lee 621dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 622dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 623dd99e04bSP.K. Lee // Use "Set" method to set the property value. 624dd99e04bSP.K. Lee if (ec) 625dd99e04bSP.K. Lee { 626c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 627c3b3c92aSVijay Khemka << ec; 628dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 629dd99e04bSP.K. Lee return; 630dd99e04bSP.K. Lee } 631dd99e04bSP.K. Lee 632dd99e04bSP.K. Lee messages::success(asyncResp->res); 633dd99e04bSP.K. Lee }, 634c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 635c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 636168e20c1SEd Tanous dbus::utility::DbusVariantType{propertyValue}); 637c3b3c92aSVijay Khemka }, 638c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 639dd99e04bSP.K. Lee } 640dd99e04bSP.K. Lee 641dd99e04bSP.K. Lee /** 642dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 643dd99e04bSP.K. Lee * action. 644dd99e04bSP.K. Lee * Function handles POST method request. 645dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 646dd99e04bSP.K. Lee */ 6477e860f15SJohn Edward Broadbent 6487e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetAction(App& app) 649dd99e04bSP.K. Lee { 6507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") 651ed398213SEd Tanous .privileges(redfish::privileges::postChassis) 6527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 653*45ca1b86SEd Tanous [&app](const crow::Request& req, 6547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6557e860f15SJohn Edward Broadbent const std::string&) { 656*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 657*45ca1b86SEd Tanous { 658*45ca1b86SEd Tanous return; 659*45ca1b86SEd Tanous } 660dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 661dd99e04bSP.K. Lee 662dd99e04bSP.K. Lee std::string resetType; 663dd99e04bSP.K. Lee 66415ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 6657e860f15SJohn Edward Broadbent resetType)) 666dd99e04bSP.K. Lee { 667dd99e04bSP.K. Lee return; 668dd99e04bSP.K. Lee } 669dd99e04bSP.K. Lee 670dd99e04bSP.K. Lee if (resetType != "PowerCycle") 671dd99e04bSP.K. Lee { 672dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 673dd99e04bSP.K. Lee << resetType; 6747e860f15SJohn Edward Broadbent messages::actionParameterNotSupported( 6757e860f15SJohn Edward Broadbent asyncResp->res, resetType, "ResetType"); 676dd99e04bSP.K. Lee 677dd99e04bSP.K. Lee return; 678dd99e04bSP.K. Lee } 679dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 6807e860f15SJohn Edward Broadbent }); 681dd99e04bSP.K. Lee } 6821cb1a9e6SAppaRao Puli 6831cb1a9e6SAppaRao Puli /** 6841cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 6851cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 6861cb1a9e6SAppaRao Puli */ 6877e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetActionInfo(App& app) 6881cb1a9e6SAppaRao Puli { 6897e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") 690ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 6917e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 692*45ca1b86SEd Tanous [&app](const crow::Request& req, 6937e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 694*45ca1b86SEd Tanous const std::string& chassisId) { 695*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 6961cb1a9e6SAppaRao Puli { 697*45ca1b86SEd Tanous return; 698*45ca1b86SEd Tanous } 6998d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 7008d1b46d7Szhanghch05 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 7018d1b46d7Szhanghch05 {"@odata.id", 7028d1b46d7Szhanghch05 "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"}, 7031cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 7041cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 7051cb1a9e6SAppaRao Puli {"Parameters", 7061cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 7071cb1a9e6SAppaRao Puli {"Required", true}, 7081cb1a9e6SAppaRao Puli {"DataType", "String"}, 7091cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 7107e860f15SJohn Edward Broadbent }); 7111cb1a9e6SAppaRao Puli } 7121cb1a9e6SAppaRao Puli 713e37f8451SRapkiewicz, Pawel } // namespace redfish 714