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" 20e37f8451SRapkiewicz, Pawel #include "node.hpp" 211abe55efSEd Tanous 22e37f8451SRapkiewicz, Pawel #include <boost/container/flat_map.hpp> 2302f6ff19SGunnar Mills #include <utils/collection.hpp> 241214b7e7SGunnar Mills 25abf2add6SEd Tanous #include <variant> 26e37f8451SRapkiewicz, Pawel 271abe55efSEd Tanous namespace redfish 281abe55efSEd Tanous { 29e37f8451SRapkiewicz, Pawel 30e37f8451SRapkiewicz, Pawel /** 31beeca0aeSGunnar Mills * @brief Retrieves chassis state properties over dbus 32beeca0aeSGunnar Mills * 33beeca0aeSGunnar Mills * @param[in] aResp - Shared pointer for completing asynchronous calls. 34beeca0aeSGunnar Mills * 35beeca0aeSGunnar Mills * @return None. 36beeca0aeSGunnar Mills */ 3723a21a1cSEd Tanous inline void getChassisState(std::shared_ptr<AsyncResp> aResp) 38beeca0aeSGunnar Mills { 39beeca0aeSGunnar Mills crow::connections::systemBus->async_method_call( 40beeca0aeSGunnar Mills [aResp{std::move(aResp)}]( 41beeca0aeSGunnar Mills const boost::system::error_code ec, 42beeca0aeSGunnar Mills const std::variant<std::string>& chassisState) { 43beeca0aeSGunnar Mills if (ec) 44beeca0aeSGunnar Mills { 45beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 46beeca0aeSGunnar Mills messages::internalError(aResp->res); 47beeca0aeSGunnar Mills return; 48beeca0aeSGunnar Mills } 49beeca0aeSGunnar Mills 50beeca0aeSGunnar Mills const std::string* s = std::get_if<std::string>(&chassisState); 51beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "Chassis state: " << *s; 52beeca0aeSGunnar Mills if (s != nullptr) 53beeca0aeSGunnar Mills { 54beeca0aeSGunnar Mills // Verify Chassis State 55beeca0aeSGunnar Mills if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") 56beeca0aeSGunnar Mills { 57beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 58beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Enabled"; 59beeca0aeSGunnar Mills } 60beeca0aeSGunnar Mills else if (*s == 61beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis.PowerState.Off") 62beeca0aeSGunnar Mills { 63beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "Off"; 64beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; 65beeca0aeSGunnar Mills } 66beeca0aeSGunnar Mills } 67beeca0aeSGunnar Mills }, 68beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", 69beeca0aeSGunnar Mills "/xyz/openbmc_project/state/chassis0", 70beeca0aeSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 71beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); 72beeca0aeSGunnar Mills } 73beeca0aeSGunnar Mills 74beeca0aeSGunnar Mills /** 75e37f8451SRapkiewicz, Pawel * DBus types primitives for several generic DBus interfaces 76e37f8451SRapkiewicz, Pawel * TODO(Pawel) consider move this to separate file into boost::dbus 77e37f8451SRapkiewicz, Pawel */ 7855c7b7a2SEd Tanous // Note, this is not a very useful Variant, but because it isn't used to get 79aa2e59c1SEd Tanous // values, it should be as simple as possible 80aa2e59c1SEd Tanous // TODO(ed) invent a nullvariant type 815fd7ba65SCheng C Yang using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>; 82aa2e59c1SEd Tanous using ManagedObjectsType = std::vector<std::pair< 83aa2e59c1SEd Tanous sdbusplus::message::object_path, 84aa2e59c1SEd Tanous std::vector<std::pair<std::string, 85aa2e59c1SEd Tanous std::vector<std::pair<std::string, VariantType>>>>>>; 86e37f8451SRapkiewicz, Pawel 87aa2e59c1SEd Tanous using PropertiesType = boost::container::flat_map<std::string, VariantType>; 88e37f8451SRapkiewicz, Pawel 8923a21a1cSEd Tanous inline void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, 90c181942fSQiang XU const std::string& service, 91c181942fSQiang XU const std::string& objPath) 92c181942fSQiang XU { 93c181942fSQiang XU BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; 94c181942fSQiang XU 95c181942fSQiang XU crow::connections::systemBus->async_method_call( 96c181942fSQiang XU [aResp{std::move(aResp)}](const boost::system::error_code ec, 97c181942fSQiang XU const std::variant<std::string>& value) { 98c181942fSQiang XU if (ec) 99c181942fSQiang XU { 1004e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 101c181942fSQiang XU // mandatory property 102c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; 103c181942fSQiang XU return; 104c181942fSQiang XU } 105c181942fSQiang XU 106c181942fSQiang XU const std::string* status = std::get_if<std::string>(&value); 107c181942fSQiang XU 108c181942fSQiang XU if (status == nullptr) 109c181942fSQiang XU { 110c181942fSQiang XU BMCWEB_LOG_ERROR << "intrusion status read error \n"; 111c181942fSQiang XU return; 112c181942fSQiang XU } 113c181942fSQiang XU 114c181942fSQiang XU aResp->res.jsonValue["PhysicalSecurity"] = { 115c181942fSQiang XU {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}}; 116c181942fSQiang XU }, 117c181942fSQiang XU service, objPath, "org.freedesktop.DBus.Properties", "Get", 118c181942fSQiang XU "xyz.openbmc_project.Chassis.Intrusion", "Status"); 119c181942fSQiang XU } 120c181942fSQiang XU 121c181942fSQiang XU /** 122c181942fSQiang XU * Retrieves physical security properties over dbus 123c181942fSQiang XU */ 12423a21a1cSEd Tanous inline void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp) 125c181942fSQiang XU { 126c181942fSQiang XU crow::connections::systemBus->async_method_call( 127c181942fSQiang XU [aResp{std::move(aResp)}]( 128c181942fSQiang XU const boost::system::error_code ec, 129c181942fSQiang XU const std::vector<std::pair< 130c181942fSQiang XU std::string, 1311214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1321214b7e7SGunnar Mills subtree) { 133c181942fSQiang XU if (ec) 134c181942fSQiang XU { 1354e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 136c181942fSQiang XU // mandatory property 137c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS error: no matched iface " << ec 138c181942fSQiang XU << "\n"; 139c181942fSQiang XU return; 140c181942fSQiang XU } 141c181942fSQiang XU // Iterate over all retrieved ObjectPaths. 142c181942fSQiang XU for (const auto& object : subtree) 143c181942fSQiang XU { 144c181942fSQiang XU for (const auto& service : object.second) 145c181942fSQiang XU { 146c181942fSQiang XU getIntrusionByService(aResp, service.first, object.first); 147c181942fSQiang XU return; 148c181942fSQiang XU } 149c181942fSQiang XU } 150c181942fSQiang XU }, 151c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", 152c181942fSQiang XU "/xyz/openbmc_project/object_mapper", 153c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", "GetSubTree", 154271584abSEd Tanous "/xyz/openbmc_project/Intrusion", 1, 155c181942fSQiang XU std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); 156c181942fSQiang XU } 157c181942fSQiang XU 158e37f8451SRapkiewicz, Pawel /** 159e37f8451SRapkiewicz, Pawel * ChassisCollection derived class for delivering Chassis Collection Schema 160e37f8451SRapkiewicz, Pawel */ 1611abe55efSEd Tanous class ChassisCollection : public Node 1621abe55efSEd Tanous { 163e37f8451SRapkiewicz, Pawel public: 16452cc112dSEd Tanous ChassisCollection(App& app) : Node(app, "/redfish/v1/Chassis/") 1651abe55efSEd Tanous { 166e0d918bcSEd Tanous entityPrivileges = { 167e0d918bcSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 168e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 169e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 170e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 171e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 172e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 173e37f8451SRapkiewicz, Pawel } 174e37f8451SRapkiewicz, Pawel 175e37f8451SRapkiewicz, Pawel private: 176e37f8451SRapkiewicz, Pawel /** 177e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 178e37f8451SRapkiewicz, Pawel */ 179cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 180cb13a392SEd Tanous const std::vector<std::string>&) override 1811abe55efSEd Tanous { 1820f74e643SEd Tanous res.jsonValue["@odata.type"] = "#ChassisCollection.ChassisCollection"; 1830f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; 1840f74e643SEd Tanous res.jsonValue["Name"] = "Chassis Collection"; 1850f74e643SEd Tanous 18662d5e2e4SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 187e37f8451SRapkiewicz, Pawel 18802f6ff19SGunnar Mills collection_util::getCollectionMembers( 18902f6ff19SGunnar Mills asyncResp, "/redfish/v1/Chassis", 19002f6ff19SGunnar Mills {"xyz.openbmc_project.Inventory.Item.Board", 19102f6ff19SGunnar Mills "xyz.openbmc_project.Inventory.Item.Chassis"}); 19262d5e2e4SEd Tanous } 193e37f8451SRapkiewicz, Pawel }; 194e37f8451SRapkiewicz, Pawel 195e37f8451SRapkiewicz, Pawel /** 196e37f8451SRapkiewicz, Pawel * Chassis override class for delivering Chassis Schema 197e37f8451SRapkiewicz, Pawel */ 1981abe55efSEd Tanous class Chassis : public Node 1991abe55efSEd Tanous { 200e37f8451SRapkiewicz, Pawel public: 20152cc112dSEd Tanous Chassis(App& app) : Node(app, "/redfish/v1/Chassis/<str>/", std::string()) 2021abe55efSEd Tanous { 203e0d918bcSEd Tanous entityPrivileges = { 204e0d918bcSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 205e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 206e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 207e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 208e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 209e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 210e37f8451SRapkiewicz, Pawel } 211e37f8451SRapkiewicz, Pawel 212e37f8451SRapkiewicz, Pawel private: 213e37f8451SRapkiewicz, Pawel /** 214e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 215e37f8451SRapkiewicz, Pawel */ 216cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 2171abe55efSEd Tanous const std::vector<std::string>& params) override 2181abe55efSEd Tanous { 219adc4f0dbSShawn McCarney const std::array<const char*, 2> interfaces = { 220734bfe90SGunnar Mills "xyz.openbmc_project.Inventory.Item.Board", 221adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.Chassis"}; 222734bfe90SGunnar Mills 223e37f8451SRapkiewicz, Pawel // Check if there is required param, truly entering this shall be 224e37f8451SRapkiewicz, Pawel // impossible. 2251abe55efSEd Tanous if (params.size() != 1) 2261abe55efSEd Tanous { 227f12894f8SJason M. Bills messages::internalError(res); 228e37f8451SRapkiewicz, Pawel res.end(); 229e37f8451SRapkiewicz, Pawel return; 230e37f8451SRapkiewicz, Pawel } 23199cffd7fSShawn McCarney const std::string& chassisId = params[0]; 232e37f8451SRapkiewicz, Pawel 23362d5e2e4SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 23455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 23562d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 23662d5e2e4SEd Tanous const boost::system::error_code ec, 2371c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 23862d5e2e4SEd Tanous if (ec) 2391abe55efSEd Tanous { 240f12894f8SJason M. Bills messages::internalError(asyncResp->res); 241daf36e2eSEd Tanous return; 242daf36e2eSEd Tanous } 243daf36e2eSEd Tanous // Iterate over all retrieved ObjectPaths. 2441abe55efSEd Tanous for (const std::pair< 2451abe55efSEd Tanous std::string, 2461abe55efSEd Tanous std::vector< 2471214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>>& 2481214b7e7SGunnar Mills object : subtree) 2491abe55efSEd Tanous { 250daf36e2eSEd Tanous const std::string& path = object.first; 2511abe55efSEd Tanous const std::vector< 2521214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 2531214b7e7SGunnar Mills connectionNames = object.second; 254e0d918bcSEd Tanous 2551abe55efSEd Tanous if (!boost::ends_with(path, chassisId)) 2561abe55efSEd Tanous { 257daf36e2eSEd Tanous continue; 258daf36e2eSEd Tanous } 25926f03899SShawn McCarney 260b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 261b49ac873SJames Feist 262b49ac873SJames Feist crow::connections::systemBus->async_method_call( 26323a21a1cSEd Tanous [health](const boost::system::error_code ec2, 264b49ac873SJames Feist std::variant<std::vector<std::string>>& resp) { 26523a21a1cSEd Tanous if (ec2) 266b49ac873SJames Feist { 267b49ac873SJames Feist return; // no sensors = no failures 268b49ac873SJames Feist } 269b49ac873SJames Feist std::vector<std::string>* data = 270b49ac873SJames Feist std::get_if<std::vector<std::string>>(&resp); 271b49ac873SJames Feist if (data == nullptr) 272b49ac873SJames Feist { 273b49ac873SJames Feist return; 274b49ac873SJames Feist } 275b49ac873SJames Feist health->inventory = std::move(*data); 276b49ac873SJames Feist }, 277b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 278b49ac873SJames Feist path + "/all_sensors", 279b49ac873SJames Feist "org.freedesktop.DBus.Properties", "Get", 280b49ac873SJames Feist "xyz.openbmc_project.Association", "endpoints"); 281b49ac873SJames Feist 282b49ac873SJames Feist health->populate(); 283b49ac873SJames Feist 2841abe55efSEd Tanous if (connectionNames.size() < 1) 2851abe55efSEd Tanous { 2861c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 287e0d918bcSEd Tanous continue; 288daf36e2eSEd Tanous } 289e0d918bcSEd Tanous 29049c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.type"] = 2919f8bfa7cSGunnar Mills "#Chassis.v1_14_0.Chassis"; 29249c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.id"] = 29349c53ac9SJohnathan Mantey "/redfish/v1/Chassis/" + chassisId; 29449c53ac9SJohnathan Mantey asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 29549c53ac9SJohnathan Mantey asyncResp->res.jsonValue["ChassisType"] = "RackMount"; 296dd99e04bSP.K. Lee asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = { 297dd99e04bSP.K. Lee {"target", "/redfish/v1/Chassis/" + chassisId + 298dd99e04bSP.K. Lee "/Actions/Chassis.Reset"}, 2991cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + 3001cb1a9e6SAppaRao Puli chassisId + 3011cb1a9e6SAppaRao Puli "/ResetActionInfo"}}; 302adbe192aSJason M. Bills asyncResp->res.jsonValue["PCIeDevices"] = { 303adbe192aSJason M. Bills {"@odata.id", 304adbe192aSJason M. Bills "/redfish/v1/Systems/system/PCIeDevices"}}; 30549c53ac9SJohnathan Mantey 30649c53ac9SJohnathan Mantey const std::string& connectionName = 30749c53ac9SJohnathan Mantey connectionNames[0].first; 3081c8fba97SJames Feist 30923a21a1cSEd Tanous const std::vector<std::string>& interfaces2 = 3101c8fba97SJames Feist connectionNames[0].second; 3111c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 3121c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 3131c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; 3141c8fba97SJames Feist 3151c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 3161c8fba97SJames Feist { 31723a21a1cSEd Tanous if (std::find(interfaces2.begin(), interfaces2.end(), 31823a21a1cSEd Tanous interface) != interfaces2.end()) 3191c8fba97SJames Feist { 3201c8fba97SJames Feist getIndicatorLedState(asyncResp); 3219f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 3221c8fba97SJames Feist break; 3231c8fba97SJames Feist } 3241c8fba97SJames Feist } 3251c8fba97SJames Feist 326*88ad7f03SSunnySrivastava1984 const std::string locationInterface = 327*88ad7f03SSunnySrivastava1984 "xyz.openbmc_project.Inventory.Decorator.LocationCode"; 328*88ad7f03SSunnySrivastava1984 if (std::find(interfaces2.begin(), interfaces2.end(), 329*88ad7f03SSunnySrivastava1984 locationInterface) != interfaces2.end()) 330*88ad7f03SSunnySrivastava1984 { 331*88ad7f03SSunnySrivastava1984 crow::connections::systemBus->async_method_call( 332*88ad7f03SSunnySrivastava1984 [asyncResp, chassisId(std::string(chassisId))]( 333*88ad7f03SSunnySrivastava1984 const boost::system::error_code ec, 334*88ad7f03SSunnySrivastava1984 const std::variant<std::string>& property) { 335*88ad7f03SSunnySrivastava1984 if (ec) 336*88ad7f03SSunnySrivastava1984 { 337*88ad7f03SSunnySrivastava1984 BMCWEB_LOG_DEBUG 338*88ad7f03SSunnySrivastava1984 << "DBUS response error for Location"; 339*88ad7f03SSunnySrivastava1984 messages::internalError(asyncResp->res); 340*88ad7f03SSunnySrivastava1984 return; 341*88ad7f03SSunnySrivastava1984 } 342*88ad7f03SSunnySrivastava1984 343*88ad7f03SSunnySrivastava1984 const std::string* value = 344*88ad7f03SSunnySrivastava1984 std::get_if<std::string>(&property); 345*88ad7f03SSunnySrivastava1984 if (value == nullptr) 346*88ad7f03SSunnySrivastava1984 { 347*88ad7f03SSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Null value returned " 348*88ad7f03SSunnySrivastava1984 "for locaton code"; 349*88ad7f03SSunnySrivastava1984 messages::internalError(asyncResp->res); 350*88ad7f03SSunnySrivastava1984 return; 351*88ad7f03SSunnySrivastava1984 } 352*88ad7f03SSunnySrivastava1984 asyncResp->res 353*88ad7f03SSunnySrivastava1984 .jsonValue["Location"]["PartLocation"] 354*88ad7f03SSunnySrivastava1984 ["ServiceLabel"] = *value; 355*88ad7f03SSunnySrivastava1984 }, 356*88ad7f03SSunnySrivastava1984 connectionName, path, 357*88ad7f03SSunnySrivastava1984 "org.freedesktop.DBus.Properties", "Get", 358*88ad7f03SSunnySrivastava1984 locationInterface, "LocationCode"); 359*88ad7f03SSunnySrivastava1984 } 360*88ad7f03SSunnySrivastava1984 36155c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 36262d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 36390728b54SEd Tanous const boost::system::error_code /*ec2*/, 3641abe55efSEd Tanous const std::vector<std::pair< 3651abe55efSEd Tanous std::string, VariantType>>& propertiesList) { 3661214b7e7SGunnar Mills for (const std::pair<std::string, VariantType>& 3671214b7e7SGunnar Mills property : propertiesList) 3681abe55efSEd Tanous { 36999cffd7fSShawn McCarney // Store DBus properties that are also Redfish 37099cffd7fSShawn McCarney // properties with same name and a string value 37199cffd7fSShawn McCarney const std::string& propertyName = 37299cffd7fSShawn McCarney property.first; 37399cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 37499cffd7fSShawn McCarney (propertyName == "SerialNumber") || 37599cffd7fSShawn McCarney (propertyName == "Manufacturer") || 37699cffd7fSShawn McCarney (propertyName == "Model")) 37799cffd7fSShawn McCarney { 378daf36e2eSEd Tanous const std::string* value = 37999cffd7fSShawn McCarney std::get_if<std::string>( 38099cffd7fSShawn McCarney &property.second); 3811abe55efSEd Tanous if (value != nullptr) 3821abe55efSEd Tanous { 38399cffd7fSShawn McCarney asyncResp->res.jsonValue[propertyName] = 38462d5e2e4SEd Tanous *value; 385daf36e2eSEd Tanous } 386daf36e2eSEd Tanous } 38799cffd7fSShawn McCarney } 38862d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 38962d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 39062d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 3911abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3921abe55efSEd Tanous chassisId + "/Thermal"}}; 3932474adfaSEd Tanous // Power object 3942474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 3952474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3962474adfaSEd Tanous chassisId + "/Power"}}; 39795a3ecadSAnthony Wilson // SensorCollection 39895a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 39995a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 40095a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 401029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 402029573d4SEd Tanous {"State", "Enabled"}, 403029573d4SEd Tanous }; 4042474adfaSEd Tanous 405029573d4SEd Tanous asyncResp->res 406029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 407029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 408029573d4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 409029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 410beeca0aeSGunnar Mills getChassisState(asyncResp); 411daf36e2eSEd Tanous }, 412daf36e2eSEd Tanous connectionName, path, "org.freedesktop.DBus.Properties", 4131abe55efSEd Tanous "GetAll", 4141abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 415daf36e2eSEd Tanous return; 416daf36e2eSEd Tanous } 417e0d918bcSEd Tanous 418daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 419f12894f8SJason M. Bills messages::resourceNotFound( 4209f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 421daf36e2eSEd Tanous }, 422daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 423daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 424daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 425271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 426c181942fSQiang XU 427c181942fSQiang XU getPhysicalSecurityData(asyncResp); 428e37f8451SRapkiewicz, Pawel } 4291c8fba97SJames Feist 4301c8fba97SJames Feist void doPatch(crow::Response& res, const crow::Request& req, 4311c8fba97SJames Feist const std::vector<std::string>& params) override 4321c8fba97SJames Feist { 4339f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 4341c8fba97SJames Feist std::optional<std::string> indicatorLed; 4351c8fba97SJames Feist auto asyncResp = std::make_shared<AsyncResp>(res); 4361c8fba97SJames Feist 4371c8fba97SJames Feist if (params.size() != 1) 4381c8fba97SJames Feist { 4391c8fba97SJames Feist return; 4401c8fba97SJames Feist } 4411c8fba97SJames Feist 4429f8bfa7cSGunnar Mills if (!json_util::readJson(req, res, "LocationIndicatorActive", 4439f8bfa7cSGunnar Mills locationIndicatorActive, "IndicatorLED", 4449f8bfa7cSGunnar Mills indicatorLed)) 4451c8fba97SJames Feist { 4461c8fba97SJames Feist return; 4471c8fba97SJames Feist } 4481c8fba97SJames Feist 4499f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 4509f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 4511c8fba97SJames Feist { 4521c8fba97SJames Feist return; // delete this when we support more patch properties 4531c8fba97SJames Feist } 454d6aa0093SGunnar Mills if (indicatorLed) 455d6aa0093SGunnar Mills { 456d6aa0093SGunnar Mills res.addHeader(boost::beast::http::field::warning, 457d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 458d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 459d6aa0093SGunnar Mills } 4601c8fba97SJames Feist 4611c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 4621c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 4631c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 4641c8fba97SJames Feist 4651c8fba97SJames Feist const std::string& chassisId = params[0]; 4661c8fba97SJames Feist 4671c8fba97SJames Feist crow::connections::systemBus->async_method_call( 4689f8bfa7cSGunnar Mills [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( 4691c8fba97SJames Feist const boost::system::error_code ec, 4701c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 4711c8fba97SJames Feist if (ec) 4721c8fba97SJames Feist { 4731c8fba97SJames Feist messages::internalError(asyncResp->res); 4741c8fba97SJames Feist return; 4751c8fba97SJames Feist } 4761c8fba97SJames Feist 4771c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 4781c8fba97SJames Feist for (const std::pair< 4791c8fba97SJames Feist std::string, 4801c8fba97SJames Feist std::vector< 4811214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>>& 4821214b7e7SGunnar Mills object : subtree) 4831c8fba97SJames Feist { 4841c8fba97SJames Feist const std::string& path = object.first; 4851c8fba97SJames Feist const std::vector< 4861214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 4871214b7e7SGunnar Mills connectionNames = object.second; 4881c8fba97SJames Feist 4891c8fba97SJames Feist if (!boost::ends_with(path, chassisId)) 4901c8fba97SJames Feist { 4911c8fba97SJames Feist continue; 4921c8fba97SJames Feist } 4931c8fba97SJames Feist 4941c8fba97SJames Feist if (connectionNames.size() < 1) 4951c8fba97SJames Feist { 4961c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 4971c8fba97SJames Feist continue; 4981c8fba97SJames Feist } 4991c8fba97SJames Feist 50023a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 5011c8fba97SJames Feist connectionNames[0].second; 5021c8fba97SJames Feist 5031c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 5041c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 5051c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board." 5061c8fba97SJames Feist "Motherboard"}; 5071c8fba97SJames Feist bool indicatorChassis = false; 5081c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 5091c8fba97SJames Feist { 5109f8bfa7cSGunnar Mills if (std::find(interfaces3.begin(), interfaces3.end(), 51123a21a1cSEd Tanous interface) != interfaces3.end()) 5121c8fba97SJames Feist { 5131c8fba97SJames Feist indicatorChassis = true; 5141c8fba97SJames Feist break; 5151c8fba97SJames Feist } 5161c8fba97SJames Feist } 5179f8bfa7cSGunnar Mills if (locationIndicatorActive) 5189f8bfa7cSGunnar Mills { 5199f8bfa7cSGunnar Mills if (indicatorChassis) 5209f8bfa7cSGunnar Mills { 5219f8bfa7cSGunnar Mills setLocationIndicatorActive( 5229f8bfa7cSGunnar Mills asyncResp, *locationIndicatorActive); 5239f8bfa7cSGunnar Mills } 5249f8bfa7cSGunnar Mills else 5259f8bfa7cSGunnar Mills { 5269f8bfa7cSGunnar Mills messages::propertyUnknown( 5279f8bfa7cSGunnar Mills asyncResp->res, "LocationIndicatorActive"); 5289f8bfa7cSGunnar Mills } 5299f8bfa7cSGunnar Mills } 5309f8bfa7cSGunnar Mills if (indicatorLed) 5319f8bfa7cSGunnar Mills { 5321c8fba97SJames Feist if (indicatorChassis) 5331c8fba97SJames Feist { 534f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 5351c8fba97SJames Feist } 5361c8fba97SJames Feist else 5371c8fba97SJames Feist { 5381c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 5391c8fba97SJames Feist "IndicatorLED"); 5401c8fba97SJames Feist } 5411c8fba97SJames Feist } 5421c8fba97SJames Feist return; 5431c8fba97SJames Feist } 5441c8fba97SJames Feist 5451c8fba97SJames Feist messages::resourceNotFound( 5469f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 5471c8fba97SJames Feist }, 5481c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 5491c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 5501c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5511c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 5521c8fba97SJames Feist } 55362d5e2e4SEd Tanous }; 554dd99e04bSP.K. Lee 555b5a76932SEd Tanous inline void doChassisPowerCycle(const std::shared_ptr<AsyncResp>& asyncResp) 556dd99e04bSP.K. Lee { 557c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 558c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 559c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 560c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 561c3b3c92aSVijay Khemka 562c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 563c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 564c3b3c92aSVijay Khemka 565c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 566c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 567c3b3c92aSVijay Khemka [asyncResp](const boost::system::error_code ec, 568c3b3c92aSVijay Khemka const std::vector<std::string>& chassisList) { 569c3b3c92aSVijay Khemka if (ec) 570c3b3c92aSVijay Khemka { 571c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 572c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 573c3b3c92aSVijay Khemka return; 574c3b3c92aSVijay Khemka } 575c3b3c92aSVijay Khemka 576dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 577dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 578dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 579dd99e04bSP.K. Lee const std::string propertyValue = 580dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 581c3b3c92aSVijay Khemka std::string objectPath = 582c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 583c3b3c92aSVijay Khemka 584c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 585c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 586c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 587c3b3c92aSVijay Khemka { 588c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 589c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 590c3b3c92aSVijay Khemka */ 591c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 592c3b3c92aSVijay Khemka } 593dd99e04bSP.K. Lee 594dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 595dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 596dd99e04bSP.K. Lee // Use "Set" method to set the property value. 597dd99e04bSP.K. Lee if (ec) 598dd99e04bSP.K. Lee { 599c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 600c3b3c92aSVijay Khemka << ec; 601dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 602dd99e04bSP.K. Lee return; 603dd99e04bSP.K. Lee } 604dd99e04bSP.K. Lee 605dd99e04bSP.K. Lee messages::success(asyncResp->res); 606dd99e04bSP.K. Lee }, 607c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 608c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 609c3b3c92aSVijay Khemka std::variant<std::string>{propertyValue}); 610c3b3c92aSVijay Khemka }, 611c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 612dd99e04bSP.K. Lee } 613dd99e04bSP.K. Lee 614dd99e04bSP.K. Lee /** 615dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 616dd99e04bSP.K. Lee * action. 617dd99e04bSP.K. Lee */ 618dd99e04bSP.K. Lee class ChassisResetAction : public Node 619dd99e04bSP.K. Lee { 620dd99e04bSP.K. Lee public: 62152cc112dSEd Tanous ChassisResetAction(App& app) : 622dd99e04bSP.K. Lee Node(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/", 623dd99e04bSP.K. Lee std::string()) 624dd99e04bSP.K. Lee { 625dd99e04bSP.K. Lee entityPrivileges = { 626dd99e04bSP.K. Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 627dd99e04bSP.K. Lee } 628dd99e04bSP.K. Lee 629dd99e04bSP.K. Lee private: 630dd99e04bSP.K. Lee /** 631dd99e04bSP.K. Lee * Function handles POST method request. 632dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 633dd99e04bSP.K. Lee */ 634dd99e04bSP.K. Lee void doPost(crow::Response& res, const crow::Request& req, 635cb13a392SEd Tanous const std::vector<std::string>&) override 636dd99e04bSP.K. Lee { 637dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 638dd99e04bSP.K. Lee 639dd99e04bSP.K. Lee std::string resetType; 640dd99e04bSP.K. Lee auto asyncResp = std::make_shared<AsyncResp>(res); 641dd99e04bSP.K. Lee 642dd99e04bSP.K. Lee if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType)) 643dd99e04bSP.K. Lee { 644dd99e04bSP.K. Lee return; 645dd99e04bSP.K. Lee } 646dd99e04bSP.K. Lee 647dd99e04bSP.K. Lee if (resetType != "PowerCycle") 648dd99e04bSP.K. Lee { 649dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 650dd99e04bSP.K. Lee << resetType; 651dd99e04bSP.K. Lee messages::actionParameterNotSupported(asyncResp->res, resetType, 652dd99e04bSP.K. Lee "ResetType"); 653dd99e04bSP.K. Lee 654dd99e04bSP.K. Lee return; 655dd99e04bSP.K. Lee } 656dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 657dd99e04bSP.K. Lee } 658dd99e04bSP.K. Lee }; 6591cb1a9e6SAppaRao Puli 6601cb1a9e6SAppaRao Puli /** 6611cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 6621cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 6631cb1a9e6SAppaRao Puli */ 6641cb1a9e6SAppaRao Puli class ChassisResetActionInfo : public Node 6651cb1a9e6SAppaRao Puli { 6661cb1a9e6SAppaRao Puli public: 6671cb1a9e6SAppaRao Puli /* 6681cb1a9e6SAppaRao Puli * Default Constructor 6691cb1a9e6SAppaRao Puli */ 67052cc112dSEd Tanous ChassisResetActionInfo(App& app) : 6711cb1a9e6SAppaRao Puli Node(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/", std::string()) 6721cb1a9e6SAppaRao Puli { 6731cb1a9e6SAppaRao Puli entityPrivileges = { 6741cb1a9e6SAppaRao Puli {boost::beast::http::verb::get, {{"Login"}}}, 6751cb1a9e6SAppaRao Puli {boost::beast::http::verb::head, {{"Login"}}}, 6761cb1a9e6SAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 6771cb1a9e6SAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 6781cb1a9e6SAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 6791cb1a9e6SAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 6801cb1a9e6SAppaRao Puli } 6811cb1a9e6SAppaRao Puli 6821cb1a9e6SAppaRao Puli private: 6831cb1a9e6SAppaRao Puli /** 6841cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 6851cb1a9e6SAppaRao Puli */ 686cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 6871cb1a9e6SAppaRao Puli const std::vector<std::string>& params) override 6881cb1a9e6SAppaRao Puli { 6891cb1a9e6SAppaRao Puli if (params.size() != 1) 6901cb1a9e6SAppaRao Puli { 6911cb1a9e6SAppaRao Puli messages::internalError(res); 6921cb1a9e6SAppaRao Puli res.end(); 6931cb1a9e6SAppaRao Puli return; 6941cb1a9e6SAppaRao Puli } 6951cb1a9e6SAppaRao Puli const std::string& chassisId = params[0]; 6961cb1a9e6SAppaRao Puli 6971cb1a9e6SAppaRao Puli res.jsonValue = {{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 6981cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Chassis/" + chassisId + 6991cb1a9e6SAppaRao Puli "/ResetActionInfo"}, 7001cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 7011cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 7021cb1a9e6SAppaRao Puli {"Parameters", 7031cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 7041cb1a9e6SAppaRao Puli {"Required", true}, 7051cb1a9e6SAppaRao Puli {"DataType", "String"}, 7061cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 7071cb1a9e6SAppaRao Puli res.end(); 7081cb1a9e6SAppaRao Puli } 7091cb1a9e6SAppaRao Puli }; 7101cb1a9e6SAppaRao Puli 711e37f8451SRapkiewicz, Pawel } // namespace redfish 712