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 32655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 32762d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 32890728b54SEd Tanous const boost::system::error_code /*ec2*/, 3291abe55efSEd Tanous const std::vector<std::pair< 3301abe55efSEd Tanous std::string, VariantType>>& propertiesList) { 3311214b7e7SGunnar Mills for (const std::pair<std::string, VariantType>& 3321214b7e7SGunnar Mills property : propertiesList) 3331abe55efSEd Tanous { 33499cffd7fSShawn McCarney // Store DBus properties that are also Redfish 33599cffd7fSShawn McCarney // properties with same name and a string value 33699cffd7fSShawn McCarney const std::string& propertyName = 33799cffd7fSShawn McCarney property.first; 33899cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 33999cffd7fSShawn McCarney (propertyName == "SerialNumber") || 34099cffd7fSShawn McCarney (propertyName == "Manufacturer") || 34199cffd7fSShawn McCarney (propertyName == "Model")) 34299cffd7fSShawn McCarney { 343daf36e2eSEd Tanous const std::string* value = 34499cffd7fSShawn McCarney std::get_if<std::string>( 34599cffd7fSShawn McCarney &property.second); 3461abe55efSEd Tanous if (value != nullptr) 3471abe55efSEd Tanous { 34899cffd7fSShawn McCarney asyncResp->res.jsonValue[propertyName] = 34962d5e2e4SEd Tanous *value; 350daf36e2eSEd Tanous } 351daf36e2eSEd Tanous } 35299cffd7fSShawn McCarney } 35362d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 35462d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 35562d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 3561abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3571abe55efSEd Tanous chassisId + "/Thermal"}}; 3582474adfaSEd Tanous // Power object 3592474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 3602474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3612474adfaSEd Tanous chassisId + "/Power"}}; 36295a3ecadSAnthony Wilson // SensorCollection 36395a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 36495a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 36595a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 366029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 367029573d4SEd Tanous {"State", "Enabled"}, 368029573d4SEd Tanous }; 3692474adfaSEd Tanous 370029573d4SEd Tanous asyncResp->res 371029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 372029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 373029573d4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 374029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 375beeca0aeSGunnar Mills getChassisState(asyncResp); 376daf36e2eSEd Tanous }, 377daf36e2eSEd Tanous connectionName, path, "org.freedesktop.DBus.Properties", 3781abe55efSEd Tanous "GetAll", 3791abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 380daf36e2eSEd Tanous return; 381daf36e2eSEd Tanous } 382e0d918bcSEd Tanous 383daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 384f12894f8SJason M. Bills messages::resourceNotFound( 3859f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 386daf36e2eSEd Tanous }, 387daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 388daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 389daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 390271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 391c181942fSQiang XU 392c181942fSQiang XU getPhysicalSecurityData(asyncResp); 393e37f8451SRapkiewicz, Pawel } 3941c8fba97SJames Feist 3951c8fba97SJames Feist void doPatch(crow::Response& res, const crow::Request& req, 3961c8fba97SJames Feist const std::vector<std::string>& params) override 3971c8fba97SJames Feist { 3989f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 3991c8fba97SJames Feist std::optional<std::string> indicatorLed; 4001c8fba97SJames Feist auto asyncResp = std::make_shared<AsyncResp>(res); 4011c8fba97SJames Feist 4021c8fba97SJames Feist if (params.size() != 1) 4031c8fba97SJames Feist { 4041c8fba97SJames Feist return; 4051c8fba97SJames Feist } 4061c8fba97SJames Feist 4079f8bfa7cSGunnar Mills if (!json_util::readJson(req, res, "LocationIndicatorActive", 4089f8bfa7cSGunnar Mills locationIndicatorActive, "IndicatorLED", 4099f8bfa7cSGunnar Mills indicatorLed)) 4101c8fba97SJames Feist { 4111c8fba97SJames Feist return; 4121c8fba97SJames Feist } 4131c8fba97SJames Feist 4149f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 4159f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 4161c8fba97SJames Feist { 4171c8fba97SJames Feist return; // delete this when we support more patch properties 4181c8fba97SJames Feist } 419*d6aa0093SGunnar Mills if (indicatorLed) 420*d6aa0093SGunnar Mills { 421*d6aa0093SGunnar Mills res.addHeader(boost::beast::http::field::warning, 422*d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 423*d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 424*d6aa0093SGunnar Mills } 4251c8fba97SJames Feist 4261c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 4271c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 4281c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 4291c8fba97SJames Feist 4301c8fba97SJames Feist const std::string& chassisId = params[0]; 4311c8fba97SJames Feist 4321c8fba97SJames Feist crow::connections::systemBus->async_method_call( 4339f8bfa7cSGunnar Mills [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( 4341c8fba97SJames Feist const boost::system::error_code ec, 4351c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 4361c8fba97SJames Feist if (ec) 4371c8fba97SJames Feist { 4381c8fba97SJames Feist messages::internalError(asyncResp->res); 4391c8fba97SJames Feist return; 4401c8fba97SJames Feist } 4411c8fba97SJames Feist 4421c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 4431c8fba97SJames Feist for (const std::pair< 4441c8fba97SJames Feist std::string, 4451c8fba97SJames Feist std::vector< 4461214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>>& 4471214b7e7SGunnar Mills object : subtree) 4481c8fba97SJames Feist { 4491c8fba97SJames Feist const std::string& path = object.first; 4501c8fba97SJames Feist const std::vector< 4511214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 4521214b7e7SGunnar Mills connectionNames = object.second; 4531c8fba97SJames Feist 4541c8fba97SJames Feist if (!boost::ends_with(path, chassisId)) 4551c8fba97SJames Feist { 4561c8fba97SJames Feist continue; 4571c8fba97SJames Feist } 4581c8fba97SJames Feist 4591c8fba97SJames Feist if (connectionNames.size() < 1) 4601c8fba97SJames Feist { 4611c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 4621c8fba97SJames Feist continue; 4631c8fba97SJames Feist } 4641c8fba97SJames Feist 46523a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 4661c8fba97SJames Feist connectionNames[0].second; 4671c8fba97SJames Feist 4681c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 4691c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 4701c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board." 4711c8fba97SJames Feist "Motherboard"}; 4721c8fba97SJames Feist bool indicatorChassis = false; 4731c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 4741c8fba97SJames Feist { 4759f8bfa7cSGunnar Mills if (std::find(interfaces3.begin(), interfaces3.end(), 47623a21a1cSEd Tanous interface) != interfaces3.end()) 4771c8fba97SJames Feist { 4781c8fba97SJames Feist indicatorChassis = true; 4791c8fba97SJames Feist break; 4801c8fba97SJames Feist } 4811c8fba97SJames Feist } 4829f8bfa7cSGunnar Mills if (locationIndicatorActive) 4839f8bfa7cSGunnar Mills { 4849f8bfa7cSGunnar Mills if (indicatorChassis) 4859f8bfa7cSGunnar Mills { 4869f8bfa7cSGunnar Mills setLocationIndicatorActive( 4879f8bfa7cSGunnar Mills asyncResp, *locationIndicatorActive); 4889f8bfa7cSGunnar Mills } 4899f8bfa7cSGunnar Mills else 4909f8bfa7cSGunnar Mills { 4919f8bfa7cSGunnar Mills messages::propertyUnknown( 4929f8bfa7cSGunnar Mills asyncResp->res, "LocationIndicatorActive"); 4939f8bfa7cSGunnar Mills } 4949f8bfa7cSGunnar Mills } 4959f8bfa7cSGunnar Mills if (indicatorLed) 4969f8bfa7cSGunnar Mills { 4971c8fba97SJames Feist if (indicatorChassis) 4981c8fba97SJames Feist { 499f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 5001c8fba97SJames Feist } 5011c8fba97SJames Feist else 5021c8fba97SJames Feist { 5031c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 5041c8fba97SJames Feist "IndicatorLED"); 5051c8fba97SJames Feist } 5061c8fba97SJames Feist } 5071c8fba97SJames Feist return; 5081c8fba97SJames Feist } 5091c8fba97SJames Feist 5101c8fba97SJames Feist messages::resourceNotFound( 5119f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 5121c8fba97SJames Feist }, 5131c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 5141c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 5151c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5161c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 5171c8fba97SJames Feist } 51862d5e2e4SEd Tanous }; 519dd99e04bSP.K. Lee 520b5a76932SEd Tanous inline void doChassisPowerCycle(const std::shared_ptr<AsyncResp>& asyncResp) 521dd99e04bSP.K. Lee { 522c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 523c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 524c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 525c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 526c3b3c92aSVijay Khemka 527c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 528c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 529c3b3c92aSVijay Khemka 530c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 531c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 532c3b3c92aSVijay Khemka [asyncResp](const boost::system::error_code ec, 533c3b3c92aSVijay Khemka const std::vector<std::string>& chassisList) { 534c3b3c92aSVijay Khemka if (ec) 535c3b3c92aSVijay Khemka { 536c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 537c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 538c3b3c92aSVijay Khemka return; 539c3b3c92aSVijay Khemka } 540c3b3c92aSVijay Khemka 541dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 542dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 543dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 544dd99e04bSP.K. Lee const std::string propertyValue = 545dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 546c3b3c92aSVijay Khemka std::string objectPath = 547c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 548c3b3c92aSVijay Khemka 549c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 550c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 551c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 552c3b3c92aSVijay Khemka { 553c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 554c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 555c3b3c92aSVijay Khemka */ 556c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 557c3b3c92aSVijay Khemka } 558dd99e04bSP.K. Lee 559dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 560dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 561dd99e04bSP.K. Lee // Use "Set" method to set the property value. 562dd99e04bSP.K. Lee if (ec) 563dd99e04bSP.K. Lee { 564c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 565c3b3c92aSVijay Khemka << ec; 566dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 567dd99e04bSP.K. Lee return; 568dd99e04bSP.K. Lee } 569dd99e04bSP.K. Lee 570dd99e04bSP.K. Lee messages::success(asyncResp->res); 571dd99e04bSP.K. Lee }, 572c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 573c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 574c3b3c92aSVijay Khemka std::variant<std::string>{propertyValue}); 575c3b3c92aSVijay Khemka }, 576c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 577dd99e04bSP.K. Lee } 578dd99e04bSP.K. Lee 579dd99e04bSP.K. Lee /** 580dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 581dd99e04bSP.K. Lee * action. 582dd99e04bSP.K. Lee */ 583dd99e04bSP.K. Lee class ChassisResetAction : public Node 584dd99e04bSP.K. Lee { 585dd99e04bSP.K. Lee public: 58652cc112dSEd Tanous ChassisResetAction(App& app) : 587dd99e04bSP.K. Lee Node(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/", 588dd99e04bSP.K. Lee std::string()) 589dd99e04bSP.K. Lee { 590dd99e04bSP.K. Lee entityPrivileges = { 591dd99e04bSP.K. Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 592dd99e04bSP.K. Lee } 593dd99e04bSP.K. Lee 594dd99e04bSP.K. Lee private: 595dd99e04bSP.K. Lee /** 596dd99e04bSP.K. Lee * Function handles POST method request. 597dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 598dd99e04bSP.K. Lee */ 599dd99e04bSP.K. Lee void doPost(crow::Response& res, const crow::Request& req, 600cb13a392SEd Tanous const std::vector<std::string>&) override 601dd99e04bSP.K. Lee { 602dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 603dd99e04bSP.K. Lee 604dd99e04bSP.K. Lee std::string resetType; 605dd99e04bSP.K. Lee auto asyncResp = std::make_shared<AsyncResp>(res); 606dd99e04bSP.K. Lee 607dd99e04bSP.K. Lee if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType)) 608dd99e04bSP.K. Lee { 609dd99e04bSP.K. Lee return; 610dd99e04bSP.K. Lee } 611dd99e04bSP.K. Lee 612dd99e04bSP.K. Lee if (resetType != "PowerCycle") 613dd99e04bSP.K. Lee { 614dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 615dd99e04bSP.K. Lee << resetType; 616dd99e04bSP.K. Lee messages::actionParameterNotSupported(asyncResp->res, resetType, 617dd99e04bSP.K. Lee "ResetType"); 618dd99e04bSP.K. Lee 619dd99e04bSP.K. Lee return; 620dd99e04bSP.K. Lee } 621dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 622dd99e04bSP.K. Lee } 623dd99e04bSP.K. Lee }; 6241cb1a9e6SAppaRao Puli 6251cb1a9e6SAppaRao Puli /** 6261cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 6271cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 6281cb1a9e6SAppaRao Puli */ 6291cb1a9e6SAppaRao Puli class ChassisResetActionInfo : public Node 6301cb1a9e6SAppaRao Puli { 6311cb1a9e6SAppaRao Puli public: 6321cb1a9e6SAppaRao Puli /* 6331cb1a9e6SAppaRao Puli * Default Constructor 6341cb1a9e6SAppaRao Puli */ 63552cc112dSEd Tanous ChassisResetActionInfo(App& app) : 6361cb1a9e6SAppaRao Puli Node(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/", std::string()) 6371cb1a9e6SAppaRao Puli { 6381cb1a9e6SAppaRao Puli entityPrivileges = { 6391cb1a9e6SAppaRao Puli {boost::beast::http::verb::get, {{"Login"}}}, 6401cb1a9e6SAppaRao Puli {boost::beast::http::verb::head, {{"Login"}}}, 6411cb1a9e6SAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 6421cb1a9e6SAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 6431cb1a9e6SAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 6441cb1a9e6SAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 6451cb1a9e6SAppaRao Puli } 6461cb1a9e6SAppaRao Puli 6471cb1a9e6SAppaRao Puli private: 6481cb1a9e6SAppaRao Puli /** 6491cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 6501cb1a9e6SAppaRao Puli */ 651cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 6521cb1a9e6SAppaRao Puli const std::vector<std::string>& params) override 6531cb1a9e6SAppaRao Puli { 6541cb1a9e6SAppaRao Puli if (params.size() != 1) 6551cb1a9e6SAppaRao Puli { 6561cb1a9e6SAppaRao Puli messages::internalError(res); 6571cb1a9e6SAppaRao Puli res.end(); 6581cb1a9e6SAppaRao Puli return; 6591cb1a9e6SAppaRao Puli } 6601cb1a9e6SAppaRao Puli const std::string& chassisId = params[0]; 6611cb1a9e6SAppaRao Puli 6621cb1a9e6SAppaRao Puli res.jsonValue = {{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 6631cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Chassis/" + chassisId + 6641cb1a9e6SAppaRao Puli "/ResetActionInfo"}, 6651cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 6661cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 6671cb1a9e6SAppaRao Puli {"Parameters", 6681cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 6691cb1a9e6SAppaRao Puli {"Required", true}, 6701cb1a9e6SAppaRao Puli {"DataType", "String"}, 6711cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 6721cb1a9e6SAppaRao Puli res.end(); 6731cb1a9e6SAppaRao Puli } 6741cb1a9e6SAppaRao Puli }; 6751cb1a9e6SAppaRao Puli 676e37f8451SRapkiewicz, Pawel } // namespace redfish 677