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> 22e37f8451SRapkiewicz, Pawel #include <boost/container/flat_map.hpp> 23ed398213SEd Tanous #include <registries/privilege_registry.hpp> 2402f6ff19SGunnar Mills #include <utils/collection.hpp> 251214b7e7SGunnar Mills 26abf2add6SEd Tanous #include <variant> 27e37f8451SRapkiewicz, Pawel 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 { 40beeca0aeSGunnar Mills crow::connections::systemBus->async_method_call( 41beeca0aeSGunnar Mills [aResp{std::move(aResp)}]( 42beeca0aeSGunnar Mills const boost::system::error_code ec, 43beeca0aeSGunnar Mills const std::variant<std::string>& chassisState) { 44beeca0aeSGunnar Mills if (ec) 45beeca0aeSGunnar Mills { 46beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 47beeca0aeSGunnar Mills messages::internalError(aResp->res); 48beeca0aeSGunnar Mills return; 49beeca0aeSGunnar Mills } 50beeca0aeSGunnar Mills 51beeca0aeSGunnar Mills const std::string* s = std::get_if<std::string>(&chassisState); 52beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "Chassis state: " << *s; 53beeca0aeSGunnar Mills if (s != nullptr) 54beeca0aeSGunnar Mills { 55beeca0aeSGunnar Mills // Verify Chassis State 56beeca0aeSGunnar Mills if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") 57beeca0aeSGunnar Mills { 58beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 59beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Enabled"; 60beeca0aeSGunnar Mills } 61beeca0aeSGunnar Mills else if (*s == 62beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis.PowerState.Off") 63beeca0aeSGunnar Mills { 64beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "Off"; 65beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; 66beeca0aeSGunnar Mills } 67beeca0aeSGunnar Mills } 68beeca0aeSGunnar Mills }, 69beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", 70beeca0aeSGunnar Mills "/xyz/openbmc_project/state/chassis0", 71beeca0aeSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 72beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); 73beeca0aeSGunnar Mills } 74beeca0aeSGunnar Mills 75beeca0aeSGunnar Mills /** 76e37f8451SRapkiewicz, Pawel * DBus types primitives for several generic DBus interfaces 77e37f8451SRapkiewicz, Pawel * TODO(Pawel) consider move this to separate file into boost::dbus 78e37f8451SRapkiewicz, Pawel */ 7955c7b7a2SEd Tanous // Note, this is not a very useful Variant, but because it isn't used to get 80aa2e59c1SEd Tanous // values, it should be as simple as possible 81aa2e59c1SEd Tanous // TODO(ed) invent a nullvariant type 825fd7ba65SCheng C Yang using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>; 83aa2e59c1SEd Tanous using ManagedObjectsType = std::vector<std::pair< 84aa2e59c1SEd Tanous sdbusplus::message::object_path, 85aa2e59c1SEd Tanous std::vector<std::pair<std::string, 86aa2e59c1SEd Tanous std::vector<std::pair<std::string, VariantType>>>>>>; 87e37f8451SRapkiewicz, Pawel 88aa2e59c1SEd Tanous using PropertiesType = boost::container::flat_map<std::string, VariantType>; 89e37f8451SRapkiewicz, Pawel 908d1b46d7Szhanghch05 inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 91c181942fSQiang XU const std::string& service, 92c181942fSQiang XU const std::string& objPath) 93c181942fSQiang XU { 94c181942fSQiang XU BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; 95c181942fSQiang XU 96c181942fSQiang XU crow::connections::systemBus->async_method_call( 97c181942fSQiang XU [aResp{std::move(aResp)}](const boost::system::error_code ec, 98c181942fSQiang XU const std::variant<std::string>& value) { 99c181942fSQiang XU if (ec) 100c181942fSQiang XU { 1014e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 102c181942fSQiang XU // mandatory property 103c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; 104c181942fSQiang XU return; 105c181942fSQiang XU } 106c181942fSQiang XU 107c181942fSQiang XU const std::string* status = std::get_if<std::string>(&value); 108c181942fSQiang XU 109c181942fSQiang XU if (status == nullptr) 110c181942fSQiang XU { 111c181942fSQiang XU BMCWEB_LOG_ERROR << "intrusion status read error \n"; 112c181942fSQiang XU return; 113c181942fSQiang XU } 114c181942fSQiang XU 115c181942fSQiang XU aResp->res.jsonValue["PhysicalSecurity"] = { 116c181942fSQiang XU {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}}; 117c181942fSQiang XU }, 118c181942fSQiang XU service, objPath, "org.freedesktop.DBus.Properties", "Get", 119c181942fSQiang XU "xyz.openbmc_project.Chassis.Intrusion", "Status"); 120c181942fSQiang XU } 121c181942fSQiang XU 122c181942fSQiang XU /** 123c181942fSQiang XU * Retrieves physical security properties over dbus 124c181942fSQiang XU */ 1258d1b46d7Szhanghch05 inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) 126c181942fSQiang XU { 127c181942fSQiang XU crow::connections::systemBus->async_method_call( 128c181942fSQiang XU [aResp{std::move(aResp)}]( 129c181942fSQiang XU const boost::system::error_code ec, 130c181942fSQiang XU const std::vector<std::pair< 131c181942fSQiang XU std::string, 1321214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1331214b7e7SGunnar Mills subtree) { 134c181942fSQiang XU if (ec) 135c181942fSQiang XU { 1364e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 137c181942fSQiang XU // mandatory property 13854fbf177SAndrew Geissler BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec 139c181942fSQiang XU << "\n"; 140c181942fSQiang XU return; 141c181942fSQiang XU } 142c181942fSQiang XU // Iterate over all retrieved ObjectPaths. 143c181942fSQiang XU for (const auto& object : subtree) 144c181942fSQiang XU { 145c181942fSQiang XU for (const auto& service : object.second) 146c181942fSQiang XU { 147c181942fSQiang XU getIntrusionByService(aResp, service.first, object.first); 148c181942fSQiang XU return; 149c181942fSQiang XU } 150c181942fSQiang XU } 151c181942fSQiang XU }, 152c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", 153c181942fSQiang XU "/xyz/openbmc_project/object_mapper", 154c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", "GetSubTree", 155271584abSEd Tanous "/xyz/openbmc_project/Intrusion", 1, 156c181942fSQiang XU std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); 157c181942fSQiang XU } 158c181942fSQiang XU 159e37f8451SRapkiewicz, Pawel /** 160e37f8451SRapkiewicz, Pawel * ChassisCollection derived class for delivering Chassis Collection Schema 161e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 162e37f8451SRapkiewicz, Pawel */ 1637e860f15SJohn Edward Broadbent inline void requestRoutesChassisCollection(App& app) 1641abe55efSEd Tanous { 1657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") 166ed398213SEd Tanous .privileges(redfish::privileges::getChassisCollection) 1677e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 1687e860f15SJohn Edward Broadbent [](const crow::Request&, 1697e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1708d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1718d1b46d7Szhanghch05 "#ChassisCollection.ChassisCollection"; 1728d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; 1738d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 174e37f8451SRapkiewicz, Pawel 17502f6ff19SGunnar Mills collection_util::getCollectionMembers( 17602f6ff19SGunnar Mills asyncResp, "/redfish/v1/Chassis", 17702f6ff19SGunnar Mills {"xyz.openbmc_project.Inventory.Item.Board", 17802f6ff19SGunnar Mills "xyz.openbmc_project.Inventory.Item.Chassis"}); 1797e860f15SJohn Edward Broadbent }); 18062d5e2e4SEd Tanous } 181e37f8451SRapkiewicz, Pawel 182308f70c7SWilly Tu inline void 183308f70c7SWilly Tu getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 184308f70c7SWilly Tu const std::string& connectionName, 185308f70c7SWilly Tu const std::string& path) 186308f70c7SWilly Tu { 187308f70c7SWilly Tu crow::connections::systemBus->async_method_call( 188308f70c7SWilly Tu [asyncResp](const boost::system::error_code ec, 189308f70c7SWilly Tu const std::variant<std::string>& property) { 190308f70c7SWilly Tu if (ec) 191308f70c7SWilly Tu { 192*0fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error for Location"; 193308f70c7SWilly Tu messages::internalError(asyncResp->res); 194308f70c7SWilly Tu return; 195308f70c7SWilly Tu } 196308f70c7SWilly Tu 197308f70c7SWilly Tu const std::string* value = std::get_if<std::string>(&property); 198308f70c7SWilly Tu if (value == nullptr) 199308f70c7SWilly Tu { 200*0fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "Null value returned for locaton code"; 201308f70c7SWilly Tu messages::internalError(asyncResp->res); 202308f70c7SWilly Tu return; 203308f70c7SWilly Tu } 204308f70c7SWilly Tu asyncResp->res 205308f70c7SWilly Tu .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = *value; 206308f70c7SWilly Tu }, 207308f70c7SWilly Tu connectionName, path, "org.freedesktop.DBus.Properties", "Get", 208308f70c7SWilly Tu "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode"); 209308f70c7SWilly Tu } 210308f70c7SWilly Tu 211308f70c7SWilly Tu inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 212308f70c7SWilly Tu const std::string& connectionName, 213308f70c7SWilly Tu const std::string& path) 214308f70c7SWilly Tu { 215308f70c7SWilly Tu crow::connections::systemBus->async_method_call( 216308f70c7SWilly Tu [asyncResp](const boost::system::error_code ec, 217308f70c7SWilly Tu const std::variant<std::string>& chassisUUID) { 218308f70c7SWilly Tu if (ec) 219308f70c7SWilly Tu { 220*0fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error for UUID"; 221308f70c7SWilly Tu messages::internalError(asyncResp->res); 222308f70c7SWilly Tu return; 223308f70c7SWilly Tu } 224308f70c7SWilly Tu const std::string* value = std::get_if<std::string>(&chassisUUID); 225308f70c7SWilly Tu if (value == nullptr) 226308f70c7SWilly Tu { 227*0fda0f12SGeorge Liu BMCWEB_LOG_DEBUG << "Null value returned for UUID"; 228308f70c7SWilly Tu messages::internalError(asyncResp->res); 229308f70c7SWilly Tu return; 230308f70c7SWilly Tu } 231308f70c7SWilly Tu asyncResp->res.jsonValue["UUID"] = *value; 232308f70c7SWilly Tu }, 233308f70c7SWilly Tu connectionName, path, "org.freedesktop.DBus.Properties", "Get", 234308f70c7SWilly Tu "xyz.openbmc_project.Common.UUID", "UUID"); 235308f70c7SWilly Tu } 236308f70c7SWilly Tu 237e37f8451SRapkiewicz, Pawel /** 238e37f8451SRapkiewicz, Pawel * Chassis override class for delivering Chassis Schema 239e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 240e37f8451SRapkiewicz, Pawel */ 2417e860f15SJohn Edward Broadbent inline void requestRoutesChassis(App& app) 2421abe55efSEd Tanous { 2437e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 244ed398213SEd Tanous .privileges(redfish::privileges::getChassis) 2457e860f15SJohn Edward Broadbent .methods( 2467e860f15SJohn Edward Broadbent boost::beast::http::verb::get)([](const crow::Request&, 2477e860f15SJohn Edward Broadbent const std::shared_ptr< 2487e860f15SJohn Edward Broadbent bmcweb::AsyncResp>& asyncResp, 2497e860f15SJohn Edward Broadbent const std::string& chassisId) { 250adc4f0dbSShawn McCarney const std::array<const char*, 2> interfaces = { 251734bfe90SGunnar Mills "xyz.openbmc_project.Inventory.Item.Board", 252adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.Chassis"}; 253734bfe90SGunnar Mills 25455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 25562d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 25662d5e2e4SEd Tanous const boost::system::error_code ec, 2571c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 25862d5e2e4SEd Tanous if (ec) 2591abe55efSEd Tanous { 260f12894f8SJason M. Bills messages::internalError(asyncResp->res); 261daf36e2eSEd Tanous return; 262daf36e2eSEd Tanous } 263daf36e2eSEd Tanous // Iterate over all retrieved ObjectPaths. 2641abe55efSEd Tanous for (const std::pair< 2651abe55efSEd Tanous std::string, 2667e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 2677e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 2681214b7e7SGunnar Mills object : subtree) 2691abe55efSEd Tanous { 270daf36e2eSEd Tanous const std::string& path = object.first; 2711abe55efSEd Tanous const std::vector< 2721214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 2731214b7e7SGunnar Mills connectionNames = object.second; 2747e860f15SJohn Edward Broadbent 275997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 276997093ebSGeorge Liu if (objPath.filename() != chassisId) 2771abe55efSEd Tanous { 278daf36e2eSEd Tanous continue; 279daf36e2eSEd Tanous } 28026f03899SShawn McCarney 2817e860f15SJohn Edward Broadbent auto health = 2827e860f15SJohn Edward Broadbent std::make_shared<HealthPopulate>(asyncResp); 283b49ac873SJames Feist 284b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2857e860f15SJohn Edward Broadbent [health]( 2867e860f15SJohn Edward Broadbent const boost::system::error_code ec2, 287b49ac873SJames Feist std::variant<std::vector<std::string>>& resp) { 28823a21a1cSEd Tanous if (ec2) 289b49ac873SJames Feist { 290b49ac873SJames Feist return; // no sensors = no failures 291b49ac873SJames Feist } 292b49ac873SJames Feist std::vector<std::string>* data = 2937e860f15SJohn Edward Broadbent std::get_if<std::vector<std::string>>( 2947e860f15SJohn Edward Broadbent &resp); 295b49ac873SJames Feist if (data == nullptr) 296b49ac873SJames Feist { 297b49ac873SJames Feist return; 298b49ac873SJames Feist } 299b49ac873SJames Feist health->inventory = std::move(*data); 300b49ac873SJames Feist }, 301b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 302b49ac873SJames Feist path + "/all_sensors", 303b49ac873SJames Feist "org.freedesktop.DBus.Properties", "Get", 304b49ac873SJames Feist "xyz.openbmc_project.Association", "endpoints"); 305b49ac873SJames Feist 306b49ac873SJames Feist health->populate(); 307b49ac873SJames Feist 3081abe55efSEd Tanous if (connectionNames.size() < 1) 3091abe55efSEd Tanous { 3101c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 311e0d918bcSEd Tanous continue; 312daf36e2eSEd Tanous } 313e0d918bcSEd Tanous 31449c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.type"] = 3159f8bfa7cSGunnar Mills "#Chassis.v1_14_0.Chassis"; 31649c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.id"] = 31749c53ac9SJohnathan Mantey "/redfish/v1/Chassis/" + chassisId; 31849c53ac9SJohnathan Mantey asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 31949c53ac9SJohnathan Mantey asyncResp->res.jsonValue["ChassisType"] = "RackMount"; 3207e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = 3217e860f15SJohn Edward Broadbent {{"target", "/redfish/v1/Chassis/" + chassisId + 322dd99e04bSP.K. Lee "/Actions/Chassis.Reset"}, 3231cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + 3241cb1a9e6SAppaRao Puli chassisId + 3251cb1a9e6SAppaRao Puli "/ResetActionInfo"}}; 326adbe192aSJason M. Bills asyncResp->res.jsonValue["PCIeDevices"] = { 327adbe192aSJason M. Bills {"@odata.id", 328adbe192aSJason M. Bills "/redfish/v1/Systems/system/PCIeDevices"}}; 32949c53ac9SJohnathan Mantey 33049c53ac9SJohnathan Mantey const std::string& connectionName = 33149c53ac9SJohnathan Mantey connectionNames[0].first; 3321c8fba97SJames Feist 33323a21a1cSEd Tanous const std::vector<std::string>& interfaces2 = 3341c8fba97SJames Feist connectionNames[0].second; 3351c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 3361c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 337*0fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 3381c8fba97SJames Feist 339476b9cc5STejas Patil const std::string assetTagInterface = 340*0fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.AssetTag"; 341476b9cc5STejas Patil if (std::find(interfaces2.begin(), interfaces2.end(), 342476b9cc5STejas Patil assetTagInterface) != interfaces2.end()) 343476b9cc5STejas Patil { 344476b9cc5STejas Patil crow::connections::systemBus->async_method_call( 345476b9cc5STejas Patil [asyncResp, chassisId(std::string(chassisId))]( 346476b9cc5STejas Patil const boost::system::error_code ec, 347476b9cc5STejas Patil const std::variant<std::string>& property) { 348476b9cc5STejas Patil if (ec) 349476b9cc5STejas Patil { 350476b9cc5STejas Patil BMCWEB_LOG_DEBUG 351*0fda0f12SGeorge Liu << "DBus response error for AssetTag"; 352476b9cc5STejas Patil messages::internalError(asyncResp->res); 353476b9cc5STejas Patil return; 354476b9cc5STejas Patil } 355476b9cc5STejas Patil 356476b9cc5STejas Patil const std::string* assetTag = 357476b9cc5STejas Patil std::get_if<std::string>(&property); 358476b9cc5STejas Patil if (assetTag == nullptr) 359476b9cc5STejas Patil { 360476b9cc5STejas Patil BMCWEB_LOG_DEBUG 361*0fda0f12SGeorge Liu << "Null value returned for Chassis AssetTag"; 362476b9cc5STejas Patil messages::internalError(asyncResp->res); 363476b9cc5STejas Patil return; 364476b9cc5STejas Patil } 365476b9cc5STejas Patil asyncResp->res.jsonValue["AssetTag"] = 366476b9cc5STejas Patil *assetTag; 367476b9cc5STejas Patil }, 368476b9cc5STejas Patil connectionName, path, 369476b9cc5STejas Patil "org.freedesktop.DBus.Properties", "Get", 370476b9cc5STejas Patil assetTagInterface, "AssetTag"); 371476b9cc5STejas Patil } 372476b9cc5STejas Patil 3731c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 3741c8fba97SJames Feist { 3757e860f15SJohn Edward Broadbent if (std::find(interfaces2.begin(), 3767e860f15SJohn Edward Broadbent interfaces2.end(), 37723a21a1cSEd Tanous interface) != interfaces2.end()) 3781c8fba97SJames Feist { 3791c8fba97SJames Feist getIndicatorLedState(asyncResp); 3809f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 3811c8fba97SJames Feist break; 3821c8fba97SJames Feist } 3831c8fba97SJames Feist } 3841c8fba97SJames Feist 38555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 38662d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 38790728b54SEd Tanous const boost::system::error_code /*ec2*/, 3887e860f15SJohn Edward Broadbent const std::vector< 3897e860f15SJohn Edward Broadbent std::pair<std::string, VariantType>>& 3907e860f15SJohn Edward Broadbent propertiesList) { 3911214b7e7SGunnar Mills for (const std::pair<std::string, VariantType>& 3921214b7e7SGunnar Mills property : propertiesList) 3931abe55efSEd Tanous { 3947e860f15SJohn Edward Broadbent // Store DBus properties that are also 3957e860f15SJohn Edward Broadbent // Redfish properties with same name and a 3967e860f15SJohn Edward Broadbent // string value 39799cffd7fSShawn McCarney const std::string& propertyName = 39899cffd7fSShawn McCarney property.first; 39999cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 40099cffd7fSShawn McCarney (propertyName == "SerialNumber") || 40199cffd7fSShawn McCarney (propertyName == "Manufacturer") || 40299cffd7fSShawn McCarney (propertyName == "Model")) 40399cffd7fSShawn McCarney { 404daf36e2eSEd Tanous const std::string* value = 40599cffd7fSShawn McCarney std::get_if<std::string>( 40699cffd7fSShawn McCarney &property.second); 4071abe55efSEd Tanous if (value != nullptr) 4081abe55efSEd Tanous { 4097e860f15SJohn Edward Broadbent asyncResp->res 4107e860f15SJohn Edward Broadbent .jsonValue[propertyName] = 41162d5e2e4SEd Tanous *value; 412daf36e2eSEd Tanous } 413daf36e2eSEd Tanous } 41499cffd7fSShawn McCarney } 41562d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 41662d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 4170256b694Szhanghch05 #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL 41862d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 4191abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 4201abe55efSEd Tanous chassisId + "/Thermal"}}; 4212474adfaSEd Tanous // Power object 4222474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 4232474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 4242474adfaSEd Tanous chassisId + "/Power"}}; 4250256b694Szhanghch05 #endif 42695a3ecadSAnthony Wilson // SensorCollection 42795a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 42895a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 42995a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 430029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 431029573d4SEd Tanous {"State", "Enabled"}, 432029573d4SEd Tanous }; 4332474adfaSEd Tanous 434029573d4SEd Tanous asyncResp->res 435029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 4367e860f15SJohn Edward Broadbent {{"@odata.id", 4377e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"}}}; 4387e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["ManagedBy"] = 4397e860f15SJohn Edward Broadbent {{{"@odata.id", 4407e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc"}}}; 441beeca0aeSGunnar Mills getChassisState(asyncResp); 442daf36e2eSEd Tanous }, 4437e860f15SJohn Edward Broadbent connectionName, path, 4447e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 4451abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 4462c37b4b0SSharad Yadav 447308f70c7SWilly Tu for (const auto& interface : interfaces2) 4482c37b4b0SSharad Yadav { 449308f70c7SWilly Tu if (interface == "xyz.openbmc_project.Common.UUID") 4502c37b4b0SSharad Yadav { 451308f70c7SWilly Tu getChassisUUID(asyncResp, connectionName, path); 4522c37b4b0SSharad Yadav } 453*0fda0f12SGeorge Liu else if ( 454*0fda0f12SGeorge Liu interface == 455*0fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 4562c37b4b0SSharad Yadav { 457308f70c7SWilly Tu getChassisLocationCode(asyncResp, 458308f70c7SWilly Tu connectionName, path); 4592c37b4b0SSharad Yadav } 4602c37b4b0SSharad Yadav } 4612c37b4b0SSharad Yadav 462daf36e2eSEd Tanous return; 463daf36e2eSEd Tanous } 464e0d918bcSEd Tanous 465daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 466f12894f8SJason M. Bills messages::resourceNotFound( 4679f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 468daf36e2eSEd Tanous }, 469daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 470daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 471daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 472271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 473c181942fSQiang XU 474c181942fSQiang XU getPhysicalSecurityData(asyncResp); 4757e860f15SJohn Edward Broadbent }); 4761c8fba97SJames Feist 4777e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 478ed398213SEd Tanous .privileges(redfish::privileges::patchChassis) 4797e860f15SJohn Edward Broadbent .methods( 4807e860f15SJohn Edward Broadbent boost::beast::http::verb:: 4817e860f15SJohn Edward Broadbent patch)([](const crow::Request& req, 4827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4837e860f15SJohn Edward Broadbent const std::string& param) { 4849f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 4851c8fba97SJames Feist std::optional<std::string> indicatorLed; 4861c8fba97SJames Feist 4877e860f15SJohn Edward Broadbent if (param.empty()) 4881c8fba97SJames Feist { 4891c8fba97SJames Feist return; 4901c8fba97SJames Feist } 4911c8fba97SJames Feist 4927e860f15SJohn Edward Broadbent if (!json_util::readJson( 4937e860f15SJohn Edward Broadbent req, asyncResp->res, "LocationIndicatorActive", 4947e860f15SJohn Edward Broadbent locationIndicatorActive, "IndicatorLED", indicatorLed)) 4951c8fba97SJames Feist { 4961c8fba97SJames Feist return; 4971c8fba97SJames Feist } 4981c8fba97SJames Feist 4999f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 5009f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 5011c8fba97SJames Feist { 5021c8fba97SJames Feist return; // delete this when we support more patch properties 5031c8fba97SJames Feist } 504d6aa0093SGunnar Mills if (indicatorLed) 505d6aa0093SGunnar Mills { 5067e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 5077e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 508*0fda0f12SGeorge Liu "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); 509d6aa0093SGunnar Mills } 5101c8fba97SJames Feist 5111c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 5121c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 5131c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 5141c8fba97SJames Feist 5157e860f15SJohn Edward Broadbent const std::string& chassisId = param; 5161c8fba97SJames Feist 5171c8fba97SJames Feist crow::connections::systemBus->async_method_call( 5189f8bfa7cSGunnar Mills [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( 5191c8fba97SJames Feist const boost::system::error_code ec, 5201c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 5211c8fba97SJames Feist if (ec) 5221c8fba97SJames Feist { 5231c8fba97SJames Feist messages::internalError(asyncResp->res); 5241c8fba97SJames Feist return; 5251c8fba97SJames Feist } 5261c8fba97SJames Feist 5271c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 5281c8fba97SJames Feist for (const std::pair< 5291c8fba97SJames Feist std::string, 5307e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 5317e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 5321214b7e7SGunnar Mills object : subtree) 5331c8fba97SJames Feist { 5341c8fba97SJames Feist const std::string& path = object.first; 5351c8fba97SJames Feist const std::vector< 5361214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 5371214b7e7SGunnar Mills connectionNames = object.second; 5381c8fba97SJames Feist 539997093ebSGeorge Liu sdbusplus::message::object_path objPath(path); 540997093ebSGeorge Liu if (objPath.filename() != chassisId) 5411c8fba97SJames Feist { 5421c8fba97SJames Feist continue; 5431c8fba97SJames Feist } 5441c8fba97SJames Feist 5451c8fba97SJames Feist if (connectionNames.size() < 1) 5461c8fba97SJames Feist { 5471c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 5481c8fba97SJames Feist continue; 5491c8fba97SJames Feist } 5501c8fba97SJames Feist 55123a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 5521c8fba97SJames Feist connectionNames[0].second; 5531c8fba97SJames Feist 5541c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 5551c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 556*0fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 5571c8fba97SJames Feist bool indicatorChassis = false; 5581c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 5591c8fba97SJames Feist { 5607e860f15SJohn Edward Broadbent if (std::find(interfaces3.begin(), 5617e860f15SJohn Edward Broadbent interfaces3.end(), 56223a21a1cSEd Tanous interface) != interfaces3.end()) 5631c8fba97SJames Feist { 5641c8fba97SJames Feist indicatorChassis = true; 5651c8fba97SJames Feist break; 5661c8fba97SJames Feist } 5671c8fba97SJames Feist } 5689f8bfa7cSGunnar Mills if (locationIndicatorActive) 5699f8bfa7cSGunnar Mills { 5709f8bfa7cSGunnar Mills if (indicatorChassis) 5719f8bfa7cSGunnar Mills { 5729f8bfa7cSGunnar Mills setLocationIndicatorActive( 5739f8bfa7cSGunnar Mills asyncResp, *locationIndicatorActive); 5749f8bfa7cSGunnar Mills } 5759f8bfa7cSGunnar Mills else 5769f8bfa7cSGunnar Mills { 5779f8bfa7cSGunnar Mills messages::propertyUnknown( 5789f8bfa7cSGunnar Mills asyncResp->res, "LocationIndicatorActive"); 5799f8bfa7cSGunnar Mills } 5809f8bfa7cSGunnar Mills } 5819f8bfa7cSGunnar Mills if (indicatorLed) 5829f8bfa7cSGunnar Mills { 5831c8fba97SJames Feist if (indicatorChassis) 5841c8fba97SJames Feist { 585f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 5861c8fba97SJames Feist } 5871c8fba97SJames Feist else 5881c8fba97SJames Feist { 5891c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 5901c8fba97SJames Feist "IndicatorLED"); 5911c8fba97SJames Feist } 5921c8fba97SJames Feist } 5931c8fba97SJames Feist return; 5941c8fba97SJames Feist } 5951c8fba97SJames Feist 5961c8fba97SJames Feist messages::resourceNotFound( 5979f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 5981c8fba97SJames Feist }, 5991c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 6001c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 6011c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 6021c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 6037e860f15SJohn Edward Broadbent }); 6041c8fba97SJames Feist } 605dd99e04bSP.K. Lee 6068d1b46d7Szhanghch05 inline void 6078d1b46d7Szhanghch05 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 608dd99e04bSP.K. Lee { 609c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 610c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 611c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 612c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 613c3b3c92aSVijay Khemka 614c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 615c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 616c3b3c92aSVijay Khemka 617c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 618c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 619c3b3c92aSVijay Khemka [asyncResp](const boost::system::error_code ec, 620c3b3c92aSVijay Khemka const std::vector<std::string>& chassisList) { 621c3b3c92aSVijay Khemka if (ec) 622c3b3c92aSVijay Khemka { 623c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 624c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 625c3b3c92aSVijay Khemka return; 626c3b3c92aSVijay Khemka } 627c3b3c92aSVijay Khemka 628dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 629dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 630dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 631dd99e04bSP.K. Lee const std::string propertyValue = 632dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 633c3b3c92aSVijay Khemka std::string objectPath = 634c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 635c3b3c92aSVijay Khemka 636c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 637c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 638c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 639c3b3c92aSVijay Khemka { 640c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 641c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 642c3b3c92aSVijay Khemka */ 643c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 644c3b3c92aSVijay Khemka } 645dd99e04bSP.K. Lee 646dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 647dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 648dd99e04bSP.K. Lee // Use "Set" method to set the property value. 649dd99e04bSP.K. Lee if (ec) 650dd99e04bSP.K. Lee { 651c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 652c3b3c92aSVijay Khemka << ec; 653dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 654dd99e04bSP.K. Lee return; 655dd99e04bSP.K. Lee } 656dd99e04bSP.K. Lee 657dd99e04bSP.K. Lee messages::success(asyncResp->res); 658dd99e04bSP.K. Lee }, 659c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 660c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 661c3b3c92aSVijay Khemka std::variant<std::string>{propertyValue}); 662c3b3c92aSVijay Khemka }, 663c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 664dd99e04bSP.K. Lee } 665dd99e04bSP.K. Lee 666dd99e04bSP.K. Lee /** 667dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 668dd99e04bSP.K. Lee * action. 669dd99e04bSP.K. Lee * Function handles POST method request. 670dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 671dd99e04bSP.K. Lee */ 6727e860f15SJohn Edward Broadbent 6737e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetAction(App& app) 674dd99e04bSP.K. Lee { 6757e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") 676ed398213SEd Tanous .privileges(redfish::privileges::postChassis) 6777e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 6787e860f15SJohn Edward Broadbent [](const crow::Request& req, 6797e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6807e860f15SJohn Edward Broadbent const std::string&) { 681dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 682dd99e04bSP.K. Lee 683dd99e04bSP.K. Lee std::string resetType; 684dd99e04bSP.K. Lee 6857e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 6867e860f15SJohn Edward Broadbent resetType)) 687dd99e04bSP.K. Lee { 688dd99e04bSP.K. Lee return; 689dd99e04bSP.K. Lee } 690dd99e04bSP.K. Lee 691dd99e04bSP.K. Lee if (resetType != "PowerCycle") 692dd99e04bSP.K. Lee { 693dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 694dd99e04bSP.K. Lee << resetType; 6957e860f15SJohn Edward Broadbent messages::actionParameterNotSupported( 6967e860f15SJohn Edward Broadbent asyncResp->res, resetType, "ResetType"); 697dd99e04bSP.K. Lee 698dd99e04bSP.K. Lee return; 699dd99e04bSP.K. Lee } 700dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 7017e860f15SJohn Edward Broadbent }); 702dd99e04bSP.K. Lee } 7031cb1a9e6SAppaRao Puli 7041cb1a9e6SAppaRao Puli /** 7051cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 7061cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 7071cb1a9e6SAppaRao Puli */ 7087e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetActionInfo(App& app) 7091cb1a9e6SAppaRao Puli { 7107e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") 711ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 7127e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 7137e860f15SJohn Edward Broadbent [](const crow::Request&, 7147e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7157e860f15SJohn Edward Broadbent const std::string& chassisId) 7161cb1a9e6SAppaRao Puli 7171cb1a9e6SAppaRao Puli { 7188d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 7198d1b46d7Szhanghch05 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 7208d1b46d7Szhanghch05 {"@odata.id", 7218d1b46d7Szhanghch05 "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"}, 7221cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 7231cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 7241cb1a9e6SAppaRao Puli {"Parameters", 7251cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 7261cb1a9e6SAppaRao Puli {"Required", true}, 7271cb1a9e6SAppaRao Puli {"DataType", "String"}, 7281cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 7297e860f15SJohn Edward Broadbent }); 7301cb1a9e6SAppaRao Puli } 7311cb1a9e6SAppaRao Puli 732e37f8451SRapkiewicz, Pawel } // namespace redfish 733