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"] = 291adbe192aSJason M. Bills "#Chassis.v1_10_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); 3211c8fba97SJames Feist break; 3221c8fba97SJames Feist } 3231c8fba97SJames Feist } 3241c8fba97SJames Feist 32555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 32662d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 32790728b54SEd Tanous const boost::system::error_code /*ec2*/, 3281abe55efSEd Tanous const std::vector<std::pair< 3291abe55efSEd Tanous std::string, VariantType>>& propertiesList) { 3301214b7e7SGunnar Mills for (const std::pair<std::string, VariantType>& 3311214b7e7SGunnar Mills property : propertiesList) 3321abe55efSEd Tanous { 33399cffd7fSShawn McCarney // Store DBus properties that are also Redfish 33499cffd7fSShawn McCarney // properties with same name and a string value 33599cffd7fSShawn McCarney const std::string& propertyName = 33699cffd7fSShawn McCarney property.first; 33799cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 33899cffd7fSShawn McCarney (propertyName == "SerialNumber") || 33999cffd7fSShawn McCarney (propertyName == "Manufacturer") || 34099cffd7fSShawn McCarney (propertyName == "Model")) 34199cffd7fSShawn McCarney { 342daf36e2eSEd Tanous const std::string* value = 34399cffd7fSShawn McCarney std::get_if<std::string>( 34499cffd7fSShawn McCarney &property.second); 3451abe55efSEd Tanous if (value != nullptr) 3461abe55efSEd Tanous { 34799cffd7fSShawn McCarney asyncResp->res.jsonValue[propertyName] = 34862d5e2e4SEd Tanous *value; 349daf36e2eSEd Tanous } 350daf36e2eSEd Tanous } 35199cffd7fSShawn McCarney } 35262d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 35362d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 35462d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 3551abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3561abe55efSEd Tanous chassisId + "/Thermal"}}; 3572474adfaSEd Tanous // Power object 3582474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 3592474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3602474adfaSEd Tanous chassisId + "/Power"}}; 36195a3ecadSAnthony Wilson // SensorCollection 36295a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 36395a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 36495a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 365029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 366029573d4SEd Tanous {"State", "Enabled"}, 367029573d4SEd Tanous }; 3682474adfaSEd Tanous 369029573d4SEd Tanous asyncResp->res 370029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 371029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 372029573d4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 373029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 374beeca0aeSGunnar Mills getChassisState(asyncResp); 375daf36e2eSEd Tanous }, 376daf36e2eSEd Tanous connectionName, path, "org.freedesktop.DBus.Properties", 3771abe55efSEd Tanous "GetAll", 3781abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 379daf36e2eSEd Tanous return; 380daf36e2eSEd Tanous } 381e0d918bcSEd Tanous 382daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 383f12894f8SJason M. Bills messages::resourceNotFound( 384adbe192aSJason M. Bills asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); 385daf36e2eSEd Tanous }, 386daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 387daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 388daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 389271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 390c181942fSQiang XU 391c181942fSQiang XU getPhysicalSecurityData(asyncResp); 392e37f8451SRapkiewicz, Pawel } 3931c8fba97SJames Feist 3941c8fba97SJames Feist void doPatch(crow::Response& res, const crow::Request& req, 3951c8fba97SJames Feist const std::vector<std::string>& params) override 3961c8fba97SJames Feist { 3971c8fba97SJames Feist std::optional<std::string> indicatorLed; 3981c8fba97SJames Feist auto asyncResp = std::make_shared<AsyncResp>(res); 3991c8fba97SJames Feist 4001c8fba97SJames Feist if (params.size() != 1) 4011c8fba97SJames Feist { 4021c8fba97SJames Feist return; 4031c8fba97SJames Feist } 4041c8fba97SJames Feist 4051c8fba97SJames Feist if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed)) 4061c8fba97SJames Feist { 4071c8fba97SJames Feist return; 4081c8fba97SJames Feist } 4091c8fba97SJames Feist 4101c8fba97SJames Feist if (!indicatorLed) 4111c8fba97SJames Feist { 4121c8fba97SJames Feist return; // delete this when we support more patch properties 4131c8fba97SJames Feist } 4141c8fba97SJames Feist 4151c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 4161c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 4171c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 4181c8fba97SJames Feist 4191c8fba97SJames Feist const std::string& chassisId = params[0]; 4201c8fba97SJames Feist 4211c8fba97SJames Feist crow::connections::systemBus->async_method_call( 4221c8fba97SJames Feist [asyncResp, chassisId, indicatorLed]( 4231c8fba97SJames Feist const boost::system::error_code ec, 4241c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 4251c8fba97SJames Feist if (ec) 4261c8fba97SJames Feist { 4271c8fba97SJames Feist messages::internalError(asyncResp->res); 4281c8fba97SJames Feist return; 4291c8fba97SJames Feist } 4301c8fba97SJames Feist 4311c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 4321c8fba97SJames Feist for (const std::pair< 4331c8fba97SJames Feist std::string, 4341c8fba97SJames Feist std::vector< 4351214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>>& 4361214b7e7SGunnar Mills object : subtree) 4371c8fba97SJames Feist { 4381c8fba97SJames Feist const std::string& path = object.first; 4391c8fba97SJames Feist const std::vector< 4401214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 4411214b7e7SGunnar Mills connectionNames = object.second; 4421c8fba97SJames Feist 4431c8fba97SJames Feist if (!boost::ends_with(path, chassisId)) 4441c8fba97SJames Feist { 4451c8fba97SJames Feist continue; 4461c8fba97SJames Feist } 4471c8fba97SJames Feist 4481c8fba97SJames Feist if (connectionNames.size() < 1) 4491c8fba97SJames Feist { 4501c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 4511c8fba97SJames Feist continue; 4521c8fba97SJames Feist } 4531c8fba97SJames Feist 45423a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 4551c8fba97SJames Feist connectionNames[0].second; 4561c8fba97SJames Feist 4571c8fba97SJames Feist if (indicatorLed) 4581c8fba97SJames Feist { 4591c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 4601c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 4611c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board." 4621c8fba97SJames Feist "Motherboard"}; 4631c8fba97SJames Feist bool indicatorChassis = false; 4641c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 4651c8fba97SJames Feist { 46623a21a1cSEd Tanous if (std::find(interfaces3.begin(), 46723a21a1cSEd Tanous interfaces3.end(), 46823a21a1cSEd Tanous interface) != interfaces3.end()) 4691c8fba97SJames Feist { 4701c8fba97SJames Feist indicatorChassis = true; 4711c8fba97SJames Feist break; 4721c8fba97SJames Feist } 4731c8fba97SJames Feist } 4741c8fba97SJames Feist if (indicatorChassis) 4751c8fba97SJames Feist { 476*f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 4771c8fba97SJames Feist } 4781c8fba97SJames Feist else 4791c8fba97SJames Feist { 4801c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 4811c8fba97SJames Feist "IndicatorLED"); 4821c8fba97SJames Feist } 4831c8fba97SJames Feist } 4841c8fba97SJames Feist return; 4851c8fba97SJames Feist } 4861c8fba97SJames Feist 4871c8fba97SJames Feist messages::resourceNotFound( 4881c8fba97SJames Feist asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); 4891c8fba97SJames Feist }, 4901c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 4911c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 4921c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 4931c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 4941c8fba97SJames Feist } 49562d5e2e4SEd Tanous }; 496dd99e04bSP.K. Lee 497b5a76932SEd Tanous inline void doChassisPowerCycle(const std::shared_ptr<AsyncResp>& asyncResp) 498dd99e04bSP.K. Lee { 499c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 500c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 501c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 502c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 503c3b3c92aSVijay Khemka 504c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 505c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 506c3b3c92aSVijay Khemka 507c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 508c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 509c3b3c92aSVijay Khemka [asyncResp](const boost::system::error_code ec, 510c3b3c92aSVijay Khemka const std::vector<std::string>& chassisList) { 511c3b3c92aSVijay Khemka if (ec) 512c3b3c92aSVijay Khemka { 513c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 514c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 515c3b3c92aSVijay Khemka return; 516c3b3c92aSVijay Khemka } 517c3b3c92aSVijay Khemka 518dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 519dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 520dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 521dd99e04bSP.K. Lee const std::string propertyValue = 522dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 523c3b3c92aSVijay Khemka std::string objectPath = 524c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 525c3b3c92aSVijay Khemka 526c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 527c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 528c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 529c3b3c92aSVijay Khemka { 530c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 531c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 532c3b3c92aSVijay Khemka */ 533c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 534c3b3c92aSVijay Khemka } 535dd99e04bSP.K. Lee 536dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 537dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 538dd99e04bSP.K. Lee // Use "Set" method to set the property value. 539dd99e04bSP.K. Lee if (ec) 540dd99e04bSP.K. Lee { 541c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 542c3b3c92aSVijay Khemka << ec; 543dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 544dd99e04bSP.K. Lee return; 545dd99e04bSP.K. Lee } 546dd99e04bSP.K. Lee 547dd99e04bSP.K. Lee messages::success(asyncResp->res); 548dd99e04bSP.K. Lee }, 549c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 550c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 551c3b3c92aSVijay Khemka std::variant<std::string>{propertyValue}); 552c3b3c92aSVijay Khemka }, 553c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 554dd99e04bSP.K. Lee } 555dd99e04bSP.K. Lee 556dd99e04bSP.K. Lee /** 557dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 558dd99e04bSP.K. Lee * action. 559dd99e04bSP.K. Lee */ 560dd99e04bSP.K. Lee class ChassisResetAction : public Node 561dd99e04bSP.K. Lee { 562dd99e04bSP.K. Lee public: 56352cc112dSEd Tanous ChassisResetAction(App& app) : 564dd99e04bSP.K. Lee Node(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/", 565dd99e04bSP.K. Lee std::string()) 566dd99e04bSP.K. Lee { 567dd99e04bSP.K. Lee entityPrivileges = { 568dd99e04bSP.K. Lee {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 569dd99e04bSP.K. Lee } 570dd99e04bSP.K. Lee 571dd99e04bSP.K. Lee private: 572dd99e04bSP.K. Lee /** 573dd99e04bSP.K. Lee * Function handles POST method request. 574dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 575dd99e04bSP.K. Lee */ 576dd99e04bSP.K. Lee void doPost(crow::Response& res, const crow::Request& req, 577cb13a392SEd Tanous const std::vector<std::string>&) override 578dd99e04bSP.K. Lee { 579dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 580dd99e04bSP.K. Lee 581dd99e04bSP.K. Lee std::string resetType; 582dd99e04bSP.K. Lee auto asyncResp = std::make_shared<AsyncResp>(res); 583dd99e04bSP.K. Lee 584dd99e04bSP.K. Lee if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType)) 585dd99e04bSP.K. Lee { 586dd99e04bSP.K. Lee return; 587dd99e04bSP.K. Lee } 588dd99e04bSP.K. Lee 589dd99e04bSP.K. Lee if (resetType != "PowerCycle") 590dd99e04bSP.K. Lee { 591dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 592dd99e04bSP.K. Lee << resetType; 593dd99e04bSP.K. Lee messages::actionParameterNotSupported(asyncResp->res, resetType, 594dd99e04bSP.K. Lee "ResetType"); 595dd99e04bSP.K. Lee 596dd99e04bSP.K. Lee return; 597dd99e04bSP.K. Lee } 598dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 599dd99e04bSP.K. Lee } 600dd99e04bSP.K. Lee }; 6011cb1a9e6SAppaRao Puli 6021cb1a9e6SAppaRao Puli /** 6031cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 6041cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 6051cb1a9e6SAppaRao Puli */ 6061cb1a9e6SAppaRao Puli class ChassisResetActionInfo : public Node 6071cb1a9e6SAppaRao Puli { 6081cb1a9e6SAppaRao Puli public: 6091cb1a9e6SAppaRao Puli /* 6101cb1a9e6SAppaRao Puli * Default Constructor 6111cb1a9e6SAppaRao Puli */ 61252cc112dSEd Tanous ChassisResetActionInfo(App& app) : 6131cb1a9e6SAppaRao Puli Node(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/", std::string()) 6141cb1a9e6SAppaRao Puli { 6151cb1a9e6SAppaRao Puli entityPrivileges = { 6161cb1a9e6SAppaRao Puli {boost::beast::http::verb::get, {{"Login"}}}, 6171cb1a9e6SAppaRao Puli {boost::beast::http::verb::head, {{"Login"}}}, 6181cb1a9e6SAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 6191cb1a9e6SAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 6201cb1a9e6SAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 6211cb1a9e6SAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 6221cb1a9e6SAppaRao Puli } 6231cb1a9e6SAppaRao Puli 6241cb1a9e6SAppaRao Puli private: 6251cb1a9e6SAppaRao Puli /** 6261cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 6271cb1a9e6SAppaRao Puli */ 628cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 6291cb1a9e6SAppaRao Puli const std::vector<std::string>& params) override 6301cb1a9e6SAppaRao Puli { 6311cb1a9e6SAppaRao Puli if (params.size() != 1) 6321cb1a9e6SAppaRao Puli { 6331cb1a9e6SAppaRao Puli messages::internalError(res); 6341cb1a9e6SAppaRao Puli res.end(); 6351cb1a9e6SAppaRao Puli return; 6361cb1a9e6SAppaRao Puli } 6371cb1a9e6SAppaRao Puli const std::string& chassisId = params[0]; 6381cb1a9e6SAppaRao Puli 6391cb1a9e6SAppaRao Puli res.jsonValue = {{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 6401cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Chassis/" + chassisId + 6411cb1a9e6SAppaRao Puli "/ResetActionInfo"}, 6421cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 6431cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 6441cb1a9e6SAppaRao Puli {"Parameters", 6451cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 6461cb1a9e6SAppaRao Puli {"Required", true}, 6471cb1a9e6SAppaRao Puli {"DataType", "String"}, 6481cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 6491cb1a9e6SAppaRao Puli res.end(); 6501cb1a9e6SAppaRao Puli } 6511cb1a9e6SAppaRao Puli }; 6521cb1a9e6SAppaRao Puli 653e37f8451SRapkiewicz, Pawel } // namespace redfish 654