1e37f8451SRapkiewicz, Pawel /* 2e37f8451SRapkiewicz, Pawel // Copyright (c) 2018 Intel Corporation 3e37f8451SRapkiewicz, Pawel // 4e37f8451SRapkiewicz, Pawel // Licensed under the Apache License, Version 2.0 (the "License"); 5e37f8451SRapkiewicz, Pawel // you may not use this file except in compliance with the License. 6e37f8451SRapkiewicz, Pawel // You may obtain a copy of the License at 7e37f8451SRapkiewicz, Pawel // 8e37f8451SRapkiewicz, Pawel // http://www.apache.org/licenses/LICENSE-2.0 9e37f8451SRapkiewicz, Pawel // 10e37f8451SRapkiewicz, Pawel // Unless required by applicable law or agreed to in writing, software 11e37f8451SRapkiewicz, Pawel // distributed under the License is distributed on an "AS IS" BASIS, 12e37f8451SRapkiewicz, Pawel // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e37f8451SRapkiewicz, Pawel // See the License for the specific language governing permissions and 14e37f8451SRapkiewicz, Pawel // limitations under the License. 15e37f8451SRapkiewicz, Pawel */ 16e37f8451SRapkiewicz, Pawel #pragma once 17e37f8451SRapkiewicz, Pawel 18b49ac873SJames Feist #include "health.hpp" 191c8fba97SJames Feist #include "led.hpp" 201abe55efSEd Tanous 217e860f15SJohn Edward Broadbent #include <app.hpp> 22e37f8451SRapkiewicz, Pawel #include <boost/container/flat_map.hpp> 23*ed398213SEd Tanous #include <registries/privilege_registry.hpp> 2402f6ff19SGunnar Mills #include <utils/collection.hpp> 251214b7e7SGunnar Mills 26abf2add6SEd Tanous #include <variant> 27e37f8451SRapkiewicz, Pawel 281abe55efSEd Tanous namespace redfish 291abe55efSEd Tanous { 30e37f8451SRapkiewicz, Pawel 31e37f8451SRapkiewicz, Pawel /** 32beeca0aeSGunnar Mills * @brief Retrieves chassis state properties over dbus 33beeca0aeSGunnar Mills * 34beeca0aeSGunnar Mills * @param[in] aResp - Shared pointer for completing asynchronous calls. 35beeca0aeSGunnar Mills * 36beeca0aeSGunnar Mills * @return None. 37beeca0aeSGunnar Mills */ 388d1b46d7Szhanghch05 inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) 39beeca0aeSGunnar Mills { 40beeca0aeSGunnar Mills crow::connections::systemBus->async_method_call( 41beeca0aeSGunnar Mills [aResp{std::move(aResp)}]( 42beeca0aeSGunnar Mills const boost::system::error_code ec, 43beeca0aeSGunnar Mills const std::variant<std::string>& chassisState) { 44beeca0aeSGunnar Mills if (ec) 45beeca0aeSGunnar Mills { 46beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 47beeca0aeSGunnar Mills messages::internalError(aResp->res); 48beeca0aeSGunnar Mills return; 49beeca0aeSGunnar Mills } 50beeca0aeSGunnar Mills 51beeca0aeSGunnar Mills const std::string* s = std::get_if<std::string>(&chassisState); 52beeca0aeSGunnar Mills BMCWEB_LOG_DEBUG << "Chassis state: " << *s; 53beeca0aeSGunnar Mills if (s != nullptr) 54beeca0aeSGunnar Mills { 55beeca0aeSGunnar Mills // Verify Chassis State 56beeca0aeSGunnar Mills if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") 57beeca0aeSGunnar Mills { 58beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 59beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Enabled"; 60beeca0aeSGunnar Mills } 61beeca0aeSGunnar Mills else if (*s == 62beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis.PowerState.Off") 63beeca0aeSGunnar Mills { 64beeca0aeSGunnar Mills aResp->res.jsonValue["PowerState"] = "Off"; 65beeca0aeSGunnar Mills aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; 66beeca0aeSGunnar Mills } 67beeca0aeSGunnar Mills } 68beeca0aeSGunnar Mills }, 69beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", 70beeca0aeSGunnar Mills "/xyz/openbmc_project/state/chassis0", 71beeca0aeSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 72beeca0aeSGunnar Mills "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); 73beeca0aeSGunnar Mills } 74beeca0aeSGunnar Mills 75beeca0aeSGunnar Mills /** 76e37f8451SRapkiewicz, Pawel * DBus types primitives for several generic DBus interfaces 77e37f8451SRapkiewicz, Pawel * TODO(Pawel) consider move this to separate file into boost::dbus 78e37f8451SRapkiewicz, Pawel */ 7955c7b7a2SEd Tanous // Note, this is not a very useful Variant, but because it isn't used to get 80aa2e59c1SEd Tanous // values, it should be as simple as possible 81aa2e59c1SEd Tanous // TODO(ed) invent a nullvariant type 825fd7ba65SCheng C Yang using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>; 83aa2e59c1SEd Tanous using ManagedObjectsType = std::vector<std::pair< 84aa2e59c1SEd Tanous sdbusplus::message::object_path, 85aa2e59c1SEd Tanous std::vector<std::pair<std::string, 86aa2e59c1SEd Tanous std::vector<std::pair<std::string, VariantType>>>>>>; 87e37f8451SRapkiewicz, Pawel 88aa2e59c1SEd Tanous using PropertiesType = boost::container::flat_map<std::string, VariantType>; 89e37f8451SRapkiewicz, Pawel 908d1b46d7Szhanghch05 inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 91c181942fSQiang XU const std::string& service, 92c181942fSQiang XU const std::string& objPath) 93c181942fSQiang XU { 94c181942fSQiang XU BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; 95c181942fSQiang XU 96c181942fSQiang XU crow::connections::systemBus->async_method_call( 97c181942fSQiang XU [aResp{std::move(aResp)}](const boost::system::error_code ec, 98c181942fSQiang XU const std::variant<std::string>& value) { 99c181942fSQiang XU if (ec) 100c181942fSQiang XU { 1014e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 102c181942fSQiang XU // mandatory property 103c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; 104c181942fSQiang XU return; 105c181942fSQiang XU } 106c181942fSQiang XU 107c181942fSQiang XU const std::string* status = std::get_if<std::string>(&value); 108c181942fSQiang XU 109c181942fSQiang XU if (status == nullptr) 110c181942fSQiang XU { 111c181942fSQiang XU BMCWEB_LOG_ERROR << "intrusion status read error \n"; 112c181942fSQiang XU return; 113c181942fSQiang XU } 114c181942fSQiang XU 115c181942fSQiang XU aResp->res.jsonValue["PhysicalSecurity"] = { 116c181942fSQiang XU {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}}; 117c181942fSQiang XU }, 118c181942fSQiang XU service, objPath, "org.freedesktop.DBus.Properties", "Get", 119c181942fSQiang XU "xyz.openbmc_project.Chassis.Intrusion", "Status"); 120c181942fSQiang XU } 121c181942fSQiang XU 122c181942fSQiang XU /** 123c181942fSQiang XU * Retrieves physical security properties over dbus 124c181942fSQiang XU */ 1258d1b46d7Szhanghch05 inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) 126c181942fSQiang XU { 127c181942fSQiang XU crow::connections::systemBus->async_method_call( 128c181942fSQiang XU [aResp{std::move(aResp)}]( 129c181942fSQiang XU const boost::system::error_code ec, 130c181942fSQiang XU const std::vector<std::pair< 131c181942fSQiang XU std::string, 1321214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1331214b7e7SGunnar Mills subtree) { 134c181942fSQiang XU if (ec) 135c181942fSQiang XU { 1364e0453b1SGunnar Mills // do not add err msg in redfish response, because this is not 137c181942fSQiang XU // mandatory property 138c181942fSQiang XU BMCWEB_LOG_ERROR << "DBUS error: no matched iface " << ec 139c181942fSQiang XU << "\n"; 140c181942fSQiang XU return; 141c181942fSQiang XU } 142c181942fSQiang XU // Iterate over all retrieved ObjectPaths. 143c181942fSQiang XU for (const auto& object : subtree) 144c181942fSQiang XU { 145c181942fSQiang XU for (const auto& service : object.second) 146c181942fSQiang XU { 147c181942fSQiang XU getIntrusionByService(aResp, service.first, object.first); 148c181942fSQiang XU return; 149c181942fSQiang XU } 150c181942fSQiang XU } 151c181942fSQiang XU }, 152c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", 153c181942fSQiang XU "/xyz/openbmc_project/object_mapper", 154c181942fSQiang XU "xyz.openbmc_project.ObjectMapper", "GetSubTree", 155271584abSEd Tanous "/xyz/openbmc_project/Intrusion", 1, 156c181942fSQiang XU std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); 157c181942fSQiang XU } 158c181942fSQiang XU 159e37f8451SRapkiewicz, Pawel /** 160e37f8451SRapkiewicz, Pawel * ChassisCollection derived class for delivering Chassis Collection Schema 161e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 162e37f8451SRapkiewicz, Pawel */ 1637e860f15SJohn Edward Broadbent inline void requestRoutesChassisCollection(App& app) 1641abe55efSEd Tanous { 1657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") 166*ed398213SEd Tanous .privileges(redfish::privileges::getChassisCollection) 1677e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 1687e860f15SJohn Edward Broadbent [](const crow::Request&, 1697e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1708d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 1718d1b46d7Szhanghch05 "#ChassisCollection.ChassisCollection"; 1728d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; 1738d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 174e37f8451SRapkiewicz, Pawel 17502f6ff19SGunnar Mills collection_util::getCollectionMembers( 17602f6ff19SGunnar Mills asyncResp, "/redfish/v1/Chassis", 17702f6ff19SGunnar Mills {"xyz.openbmc_project.Inventory.Item.Board", 17802f6ff19SGunnar Mills "xyz.openbmc_project.Inventory.Item.Chassis"}); 1797e860f15SJohn Edward Broadbent }); 18062d5e2e4SEd Tanous } 181e37f8451SRapkiewicz, Pawel 182e37f8451SRapkiewicz, Pawel /** 183e37f8451SRapkiewicz, Pawel * Chassis override class for delivering Chassis Schema 184e37f8451SRapkiewicz, Pawel * Functions triggers appropriate requests on DBus 185e37f8451SRapkiewicz, Pawel */ 1867e860f15SJohn Edward Broadbent inline void requestRoutesChassis(App& app) 1871abe55efSEd Tanous { 1887e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 189*ed398213SEd Tanous .privileges(redfish::privileges::getChassis) 1907e860f15SJohn Edward Broadbent .methods( 1917e860f15SJohn Edward Broadbent boost::beast::http::verb::get)([](const crow::Request&, 1927e860f15SJohn Edward Broadbent const std::shared_ptr< 1937e860f15SJohn Edward Broadbent bmcweb::AsyncResp>& asyncResp, 1947e860f15SJohn Edward Broadbent const std::string& chassisId) { 195adc4f0dbSShawn McCarney const std::array<const char*, 2> interfaces = { 196734bfe90SGunnar Mills "xyz.openbmc_project.Inventory.Item.Board", 197adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.Chassis"}; 198734bfe90SGunnar Mills 19955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 20062d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 20162d5e2e4SEd Tanous const boost::system::error_code ec, 2021c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 20362d5e2e4SEd Tanous if (ec) 2041abe55efSEd Tanous { 205f12894f8SJason M. Bills messages::internalError(asyncResp->res); 206daf36e2eSEd Tanous return; 207daf36e2eSEd Tanous } 208daf36e2eSEd Tanous // Iterate over all retrieved ObjectPaths. 2091abe55efSEd Tanous for (const std::pair< 2101abe55efSEd Tanous std::string, 2117e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 2127e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 2131214b7e7SGunnar Mills object : subtree) 2141abe55efSEd Tanous { 215daf36e2eSEd Tanous const std::string& path = object.first; 2161abe55efSEd Tanous const std::vector< 2171214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 2181214b7e7SGunnar Mills connectionNames = object.second; 2197e860f15SJohn Edward Broadbent 2207e860f15SJohn Edward Broadbent if (!boost::ends_with(path, chassisId)) 2211abe55efSEd Tanous { 222daf36e2eSEd Tanous continue; 223daf36e2eSEd Tanous } 22426f03899SShawn McCarney 2257e860f15SJohn Edward Broadbent auto health = 2267e860f15SJohn Edward Broadbent std::make_shared<HealthPopulate>(asyncResp); 227b49ac873SJames Feist 228b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2297e860f15SJohn Edward Broadbent [health]( 2307e860f15SJohn Edward Broadbent const boost::system::error_code ec2, 231b49ac873SJames Feist std::variant<std::vector<std::string>>& resp) { 23223a21a1cSEd Tanous if (ec2) 233b49ac873SJames Feist { 234b49ac873SJames Feist return; // no sensors = no failures 235b49ac873SJames Feist } 236b49ac873SJames Feist std::vector<std::string>* data = 2377e860f15SJohn Edward Broadbent std::get_if<std::vector<std::string>>( 2387e860f15SJohn Edward Broadbent &resp); 239b49ac873SJames Feist if (data == nullptr) 240b49ac873SJames Feist { 241b49ac873SJames Feist return; 242b49ac873SJames Feist } 243b49ac873SJames Feist health->inventory = std::move(*data); 244b49ac873SJames Feist }, 245b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 246b49ac873SJames Feist path + "/all_sensors", 247b49ac873SJames Feist "org.freedesktop.DBus.Properties", "Get", 248b49ac873SJames Feist "xyz.openbmc_project.Association", "endpoints"); 249b49ac873SJames Feist 250b49ac873SJames Feist health->populate(); 251b49ac873SJames Feist 2521abe55efSEd Tanous if (connectionNames.size() < 1) 2531abe55efSEd Tanous { 2541c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 255e0d918bcSEd Tanous continue; 256daf36e2eSEd Tanous } 257e0d918bcSEd Tanous 25849c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.type"] = 2599f8bfa7cSGunnar Mills "#Chassis.v1_14_0.Chassis"; 26049c53ac9SJohnathan Mantey asyncResp->res.jsonValue["@odata.id"] = 26149c53ac9SJohnathan Mantey "/redfish/v1/Chassis/" + chassisId; 26249c53ac9SJohnathan Mantey asyncResp->res.jsonValue["Name"] = "Chassis Collection"; 26349c53ac9SJohnathan Mantey asyncResp->res.jsonValue["ChassisType"] = "RackMount"; 2647e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = 2657e860f15SJohn Edward Broadbent {{"target", "/redfish/v1/Chassis/" + chassisId + 266dd99e04bSP.K. Lee "/Actions/Chassis.Reset"}, 2671cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + 2681cb1a9e6SAppaRao Puli chassisId + 2691cb1a9e6SAppaRao Puli "/ResetActionInfo"}}; 270adbe192aSJason M. Bills asyncResp->res.jsonValue["PCIeDevices"] = { 271adbe192aSJason M. Bills {"@odata.id", 272adbe192aSJason M. Bills "/redfish/v1/Systems/system/PCIeDevices"}}; 27349c53ac9SJohnathan Mantey 27449c53ac9SJohnathan Mantey const std::string& connectionName = 27549c53ac9SJohnathan Mantey connectionNames[0].first; 2761c8fba97SJames Feist 27723a21a1cSEd Tanous const std::vector<std::string>& interfaces2 = 2781c8fba97SJames Feist connectionNames[0].second; 2791c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 2801c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 2817e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Board." 2827e860f15SJohn Edward Broadbent "Motherboard"}; 2831c8fba97SJames Feist 2841c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 2851c8fba97SJames Feist { 2867e860f15SJohn Edward Broadbent if (std::find(interfaces2.begin(), 2877e860f15SJohn Edward Broadbent interfaces2.end(), 28823a21a1cSEd Tanous interface) != interfaces2.end()) 2891c8fba97SJames Feist { 2901c8fba97SJames Feist getIndicatorLedState(asyncResp); 2919f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 2921c8fba97SJames Feist break; 2931c8fba97SJames Feist } 2941c8fba97SJames Feist } 2951c8fba97SJames Feist 29688ad7f03SSunnySrivastava1984 const std::string locationInterface = 2977e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator." 2987e860f15SJohn Edward Broadbent "LocationCode"; 29988ad7f03SSunnySrivastava1984 if (std::find(interfaces2.begin(), interfaces2.end(), 30088ad7f03SSunnySrivastava1984 locationInterface) != interfaces2.end()) 30188ad7f03SSunnySrivastava1984 { 30288ad7f03SSunnySrivastava1984 crow::connections::systemBus->async_method_call( 30388ad7f03SSunnySrivastava1984 [asyncResp, chassisId(std::string(chassisId))]( 30488ad7f03SSunnySrivastava1984 const boost::system::error_code ec, 30588ad7f03SSunnySrivastava1984 const std::variant<std::string>& property) { 30688ad7f03SSunnySrivastava1984 if (ec) 30788ad7f03SSunnySrivastava1984 { 30888ad7f03SSunnySrivastava1984 BMCWEB_LOG_DEBUG 3097e860f15SJohn Edward Broadbent << "DBUS response error for " 3107e860f15SJohn Edward Broadbent "Location"; 31188ad7f03SSunnySrivastava1984 messages::internalError(asyncResp->res); 31288ad7f03SSunnySrivastava1984 return; 31388ad7f03SSunnySrivastava1984 } 31488ad7f03SSunnySrivastava1984 31588ad7f03SSunnySrivastava1984 const std::string* value = 31688ad7f03SSunnySrivastava1984 std::get_if<std::string>(&property); 31788ad7f03SSunnySrivastava1984 if (value == nullptr) 31888ad7f03SSunnySrivastava1984 { 3197e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 3207e860f15SJohn Edward Broadbent << "Null value returned " 32188ad7f03SSunnySrivastava1984 "for locaton code"; 32288ad7f03SSunnySrivastava1984 messages::internalError(asyncResp->res); 32388ad7f03SSunnySrivastava1984 return; 32488ad7f03SSunnySrivastava1984 } 32588ad7f03SSunnySrivastava1984 asyncResp->res 32688ad7f03SSunnySrivastava1984 .jsonValue["Location"]["PartLocation"] 32788ad7f03SSunnySrivastava1984 ["ServiceLabel"] = *value; 32888ad7f03SSunnySrivastava1984 }, 32988ad7f03SSunnySrivastava1984 connectionName, path, 33088ad7f03SSunnySrivastava1984 "org.freedesktop.DBus.Properties", "Get", 33188ad7f03SSunnySrivastava1984 locationInterface, "LocationCode"); 33288ad7f03SSunnySrivastava1984 } 33388ad7f03SSunnySrivastava1984 33455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 33562d5e2e4SEd Tanous [asyncResp, chassisId(std::string(chassisId))]( 33690728b54SEd Tanous const boost::system::error_code /*ec2*/, 3377e860f15SJohn Edward Broadbent const std::vector< 3387e860f15SJohn Edward Broadbent std::pair<std::string, VariantType>>& 3397e860f15SJohn Edward Broadbent propertiesList) { 3401214b7e7SGunnar Mills for (const std::pair<std::string, VariantType>& 3411214b7e7SGunnar Mills property : propertiesList) 3421abe55efSEd Tanous { 3437e860f15SJohn Edward Broadbent // Store DBus properties that are also 3447e860f15SJohn Edward Broadbent // Redfish properties with same name and a 3457e860f15SJohn Edward Broadbent // string value 34699cffd7fSShawn McCarney const std::string& propertyName = 34799cffd7fSShawn McCarney property.first; 34899cffd7fSShawn McCarney if ((propertyName == "PartNumber") || 34999cffd7fSShawn McCarney (propertyName == "SerialNumber") || 35099cffd7fSShawn McCarney (propertyName == "Manufacturer") || 35199cffd7fSShawn McCarney (propertyName == "Model")) 35299cffd7fSShawn McCarney { 353daf36e2eSEd Tanous const std::string* value = 35499cffd7fSShawn McCarney std::get_if<std::string>( 35599cffd7fSShawn McCarney &property.second); 3561abe55efSEd Tanous if (value != nullptr) 3571abe55efSEd Tanous { 3587e860f15SJohn Edward Broadbent asyncResp->res 3597e860f15SJohn Edward Broadbent .jsonValue[propertyName] = 36062d5e2e4SEd Tanous *value; 361daf36e2eSEd Tanous } 362daf36e2eSEd Tanous } 36399cffd7fSShawn McCarney } 36462d5e2e4SEd Tanous asyncResp->res.jsonValue["Name"] = chassisId; 36562d5e2e4SEd Tanous asyncResp->res.jsonValue["Id"] = chassisId; 3660256b694Szhanghch05 #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL 36762d5e2e4SEd Tanous asyncResp->res.jsonValue["Thermal"] = { 3681abe55efSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3691abe55efSEd Tanous chassisId + "/Thermal"}}; 3702474adfaSEd Tanous // Power object 3712474adfaSEd Tanous asyncResp->res.jsonValue["Power"] = { 3722474adfaSEd Tanous {"@odata.id", "/redfish/v1/Chassis/" + 3732474adfaSEd Tanous chassisId + "/Power"}}; 3740256b694Szhanghch05 #endif 37595a3ecadSAnthony Wilson // SensorCollection 37695a3ecadSAnthony Wilson asyncResp->res.jsonValue["Sensors"] = { 37795a3ecadSAnthony Wilson {"@odata.id", "/redfish/v1/Chassis/" + 37895a3ecadSAnthony Wilson chassisId + "/Sensors"}}; 379029573d4SEd Tanous asyncResp->res.jsonValue["Status"] = { 380029573d4SEd Tanous {"State", "Enabled"}, 381029573d4SEd Tanous }; 3822474adfaSEd Tanous 383029573d4SEd Tanous asyncResp->res 384029573d4SEd Tanous .jsonValue["Links"]["ComputerSystems"] = { 3857e860f15SJohn Edward Broadbent {{"@odata.id", 3867e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"}}}; 3877e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["ManagedBy"] = 3887e860f15SJohn Edward Broadbent {{{"@odata.id", 3897e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc"}}}; 390beeca0aeSGunnar Mills getChassisState(asyncResp); 391daf36e2eSEd Tanous }, 3927e860f15SJohn Edward Broadbent connectionName, path, 3937e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 3941abe55efSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset"); 3952c37b4b0SSharad Yadav 3962c37b4b0SSharad Yadav // Chassis UUID 3972c37b4b0SSharad Yadav const std::string uuidInterface = 3982c37b4b0SSharad Yadav "xyz.openbmc_project.Common.UUID"; 3992c37b4b0SSharad Yadav if (std::find(interfaces2.begin(), interfaces2.end(), 4002c37b4b0SSharad Yadav uuidInterface) != interfaces2.end()) 4012c37b4b0SSharad Yadav { 4022c37b4b0SSharad Yadav crow::connections::systemBus->async_method_call( 4032c37b4b0SSharad Yadav [asyncResp](const boost::system::error_code ec, 4042c37b4b0SSharad Yadav const std::variant<std::string>& 4052c37b4b0SSharad Yadav chassisUUID) { 4062c37b4b0SSharad Yadav if (ec) 4072c37b4b0SSharad Yadav { 4082c37b4b0SSharad Yadav BMCWEB_LOG_DEBUG 4092c37b4b0SSharad Yadav << "DBUS response error for " 4102c37b4b0SSharad Yadav "UUID"; 4112c37b4b0SSharad Yadav messages::internalError(asyncResp->res); 4122c37b4b0SSharad Yadav return; 4132c37b4b0SSharad Yadav } 4142c37b4b0SSharad Yadav const std::string* value = 4152c37b4b0SSharad Yadav std::get_if<std::string>(&chassisUUID); 4162c37b4b0SSharad Yadav if (value == nullptr) 4172c37b4b0SSharad Yadav { 4182c37b4b0SSharad Yadav BMCWEB_LOG_DEBUG 4192c37b4b0SSharad Yadav << "Null value returned " 4202c37b4b0SSharad Yadav "for UUID"; 4212c37b4b0SSharad Yadav messages::internalError(asyncResp->res); 4222c37b4b0SSharad Yadav return; 4232c37b4b0SSharad Yadav } 4242c37b4b0SSharad Yadav asyncResp->res.jsonValue["UUID"] = *value; 4252c37b4b0SSharad Yadav }, 4262c37b4b0SSharad Yadav connectionName, path, 4272c37b4b0SSharad Yadav "org.freedesktop.DBus.Properties", "Get", 4282c37b4b0SSharad Yadav uuidInterface, "UUID"); 4292c37b4b0SSharad Yadav } 4302c37b4b0SSharad Yadav 431daf36e2eSEd Tanous return; 432daf36e2eSEd Tanous } 433e0d918bcSEd Tanous 434daf36e2eSEd Tanous // Couldn't find an object with that name. return an error 435f12894f8SJason M. Bills messages::resourceNotFound( 4369f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 437daf36e2eSEd Tanous }, 438daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", 439daf36e2eSEd Tanous "/xyz/openbmc_project/object_mapper", 440daf36e2eSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", 441271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 442c181942fSQiang XU 443c181942fSQiang XU getPhysicalSecurityData(asyncResp); 4447e860f15SJohn Edward Broadbent }); 4451c8fba97SJames Feist 4467e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") 447*ed398213SEd Tanous .privileges(redfish::privileges::patchChassis) 4487e860f15SJohn Edward Broadbent .methods( 4497e860f15SJohn Edward Broadbent boost::beast::http::verb:: 4507e860f15SJohn Edward Broadbent patch)([](const crow::Request& req, 4517e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 4527e860f15SJohn Edward Broadbent const std::string& param) { 4539f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 4541c8fba97SJames Feist std::optional<std::string> indicatorLed; 4551c8fba97SJames Feist 4567e860f15SJohn Edward Broadbent if (param.empty()) 4571c8fba97SJames Feist { 4581c8fba97SJames Feist return; 4591c8fba97SJames Feist } 4601c8fba97SJames Feist 4617e860f15SJohn Edward Broadbent if (!json_util::readJson( 4627e860f15SJohn Edward Broadbent req, asyncResp->res, "LocationIndicatorActive", 4637e860f15SJohn Edward Broadbent locationIndicatorActive, "IndicatorLED", indicatorLed)) 4641c8fba97SJames Feist { 4651c8fba97SJames Feist return; 4661c8fba97SJames Feist } 4671c8fba97SJames Feist 4689f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 4699f8bfa7cSGunnar Mills if (!locationIndicatorActive && !indicatorLed) 4701c8fba97SJames Feist { 4711c8fba97SJames Feist return; // delete this when we support more patch properties 4721c8fba97SJames Feist } 473d6aa0093SGunnar Mills if (indicatorLed) 474d6aa0093SGunnar Mills { 4757e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 4767e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 477d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 478d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 479d6aa0093SGunnar Mills } 4801c8fba97SJames Feist 4811c8fba97SJames Feist const std::array<const char*, 2> interfaces = { 4821c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board", 4831c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Chassis"}; 4841c8fba97SJames Feist 4857e860f15SJohn Edward Broadbent const std::string& chassisId = param; 4861c8fba97SJames Feist 4871c8fba97SJames Feist crow::connections::systemBus->async_method_call( 4889f8bfa7cSGunnar Mills [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( 4891c8fba97SJames Feist const boost::system::error_code ec, 4901c8fba97SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 4911c8fba97SJames Feist if (ec) 4921c8fba97SJames Feist { 4931c8fba97SJames Feist messages::internalError(asyncResp->res); 4941c8fba97SJames Feist return; 4951c8fba97SJames Feist } 4961c8fba97SJames Feist 4971c8fba97SJames Feist // Iterate over all retrieved ObjectPaths. 4981c8fba97SJames Feist for (const std::pair< 4991c8fba97SJames Feist std::string, 5007e860f15SJohn Edward Broadbent std::vector<std::pair<std::string, 5017e860f15SJohn Edward Broadbent std::vector<std::string>>>>& 5021214b7e7SGunnar Mills object : subtree) 5031c8fba97SJames Feist { 5041c8fba97SJames Feist const std::string& path = object.first; 5051c8fba97SJames Feist const std::vector< 5061214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 5071214b7e7SGunnar Mills connectionNames = object.second; 5081c8fba97SJames Feist 5091c8fba97SJames Feist if (!boost::ends_with(path, chassisId)) 5101c8fba97SJames Feist { 5111c8fba97SJames Feist continue; 5121c8fba97SJames Feist } 5131c8fba97SJames Feist 5141c8fba97SJames Feist if (connectionNames.size() < 1) 5151c8fba97SJames Feist { 5161c8fba97SJames Feist BMCWEB_LOG_ERROR << "Got 0 Connection names"; 5171c8fba97SJames Feist continue; 5181c8fba97SJames Feist } 5191c8fba97SJames Feist 52023a21a1cSEd Tanous const std::vector<std::string>& interfaces3 = 5211c8fba97SJames Feist connectionNames[0].second; 5221c8fba97SJames Feist 5231c8fba97SJames Feist const std::array<const char*, 2> hasIndicatorLed = { 5241c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Panel", 5251c8fba97SJames Feist "xyz.openbmc_project.Inventory.Item.Board." 5261c8fba97SJames Feist "Motherboard"}; 5271c8fba97SJames Feist bool indicatorChassis = false; 5281c8fba97SJames Feist for (const char* interface : hasIndicatorLed) 5291c8fba97SJames Feist { 5307e860f15SJohn Edward Broadbent if (std::find(interfaces3.begin(), 5317e860f15SJohn Edward Broadbent interfaces3.end(), 53223a21a1cSEd Tanous interface) != interfaces3.end()) 5331c8fba97SJames Feist { 5341c8fba97SJames Feist indicatorChassis = true; 5351c8fba97SJames Feist break; 5361c8fba97SJames Feist } 5371c8fba97SJames Feist } 5389f8bfa7cSGunnar Mills if (locationIndicatorActive) 5399f8bfa7cSGunnar Mills { 5409f8bfa7cSGunnar Mills if (indicatorChassis) 5419f8bfa7cSGunnar Mills { 5429f8bfa7cSGunnar Mills setLocationIndicatorActive( 5439f8bfa7cSGunnar Mills asyncResp, *locationIndicatorActive); 5449f8bfa7cSGunnar Mills } 5459f8bfa7cSGunnar Mills else 5469f8bfa7cSGunnar Mills { 5479f8bfa7cSGunnar Mills messages::propertyUnknown( 5489f8bfa7cSGunnar Mills asyncResp->res, "LocationIndicatorActive"); 5499f8bfa7cSGunnar Mills } 5509f8bfa7cSGunnar Mills } 5519f8bfa7cSGunnar Mills if (indicatorLed) 5529f8bfa7cSGunnar Mills { 5531c8fba97SJames Feist if (indicatorChassis) 5541c8fba97SJames Feist { 555f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 5561c8fba97SJames Feist } 5571c8fba97SJames Feist else 5581c8fba97SJames Feist { 5591c8fba97SJames Feist messages::propertyUnknown(asyncResp->res, 5601c8fba97SJames Feist "IndicatorLED"); 5611c8fba97SJames Feist } 5621c8fba97SJames Feist } 5631c8fba97SJames Feist return; 5641c8fba97SJames Feist } 5651c8fba97SJames Feist 5661c8fba97SJames Feist messages::resourceNotFound( 5679f8bfa7cSGunnar Mills asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); 5681c8fba97SJames Feist }, 5691c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", 5701c8fba97SJames Feist "/xyz/openbmc_project/object_mapper", 5711c8fba97SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5721c8fba97SJames Feist "/xyz/openbmc_project/inventory", 0, interfaces); 5737e860f15SJohn Edward Broadbent }); 5741c8fba97SJames Feist } 575dd99e04bSP.K. Lee 5768d1b46d7Szhanghch05 inline void 5778d1b46d7Szhanghch05 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 578dd99e04bSP.K. Lee { 579c3b3c92aSVijay Khemka const char* busName = "xyz.openbmc_project.ObjectMapper"; 580c3b3c92aSVijay Khemka const char* path = "/xyz/openbmc_project/object_mapper"; 581c3b3c92aSVijay Khemka const char* interface = "xyz.openbmc_project.ObjectMapper"; 582c3b3c92aSVijay Khemka const char* method = "GetSubTreePaths"; 583c3b3c92aSVijay Khemka 584c3b3c92aSVijay Khemka const std::array<const char*, 1> interfaces = { 585c3b3c92aSVijay Khemka "xyz.openbmc_project.State.Chassis"}; 586c3b3c92aSVijay Khemka 587c3b3c92aSVijay Khemka // Use mapper to get subtree paths. 588c3b3c92aSVijay Khemka crow::connections::systemBus->async_method_call( 589c3b3c92aSVijay Khemka [asyncResp](const boost::system::error_code ec, 590c3b3c92aSVijay Khemka const std::vector<std::string>& chassisList) { 591c3b3c92aSVijay Khemka if (ec) 592c3b3c92aSVijay Khemka { 593c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; 594c3b3c92aSVijay Khemka messages::internalError(asyncResp->res); 595c3b3c92aSVijay Khemka return; 596c3b3c92aSVijay Khemka } 597c3b3c92aSVijay Khemka 598dd99e04bSP.K. Lee const char* processName = "xyz.openbmc_project.State.Chassis"; 599dd99e04bSP.K. Lee const char* interfaceName = "xyz.openbmc_project.State.Chassis"; 600dd99e04bSP.K. Lee const char* destProperty = "RequestedPowerTransition"; 601dd99e04bSP.K. Lee const std::string propertyValue = 602dd99e04bSP.K. Lee "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 603c3b3c92aSVijay Khemka std::string objectPath = 604c3b3c92aSVijay Khemka "/xyz/openbmc_project/state/chassis_system0"; 605c3b3c92aSVijay Khemka 606c3b3c92aSVijay Khemka /* Look for system reset chassis path */ 607c3b3c92aSVijay Khemka if ((std::find(chassisList.begin(), chassisList.end(), 608c3b3c92aSVijay Khemka objectPath)) == chassisList.end()) 609c3b3c92aSVijay Khemka { 610c3b3c92aSVijay Khemka /* We prefer to reset the full chassis_system, but if it doesn't 611c3b3c92aSVijay Khemka * exist on some platforms, fall back to a host-only power reset 612c3b3c92aSVijay Khemka */ 613c3b3c92aSVijay Khemka objectPath = "/xyz/openbmc_project/state/chassis0"; 614c3b3c92aSVijay Khemka } 615dd99e04bSP.K. Lee 616dd99e04bSP.K. Lee crow::connections::systemBus->async_method_call( 617dd99e04bSP.K. Lee [asyncResp](const boost::system::error_code ec) { 618dd99e04bSP.K. Lee // Use "Set" method to set the property value. 619dd99e04bSP.K. Lee if (ec) 620dd99e04bSP.K. Lee { 621c3b3c92aSVijay Khemka BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " 622c3b3c92aSVijay Khemka << ec; 623dd99e04bSP.K. Lee messages::internalError(asyncResp->res); 624dd99e04bSP.K. Lee return; 625dd99e04bSP.K. Lee } 626dd99e04bSP.K. Lee 627dd99e04bSP.K. Lee messages::success(asyncResp->res); 628dd99e04bSP.K. Lee }, 629c3b3c92aSVijay Khemka processName, objectPath, "org.freedesktop.DBus.Properties", 630c3b3c92aSVijay Khemka "Set", interfaceName, destProperty, 631c3b3c92aSVijay Khemka std::variant<std::string>{propertyValue}); 632c3b3c92aSVijay Khemka }, 633c3b3c92aSVijay Khemka busName, path, interface, method, "/", 0, interfaces); 634dd99e04bSP.K. Lee } 635dd99e04bSP.K. Lee 636dd99e04bSP.K. Lee /** 637dd99e04bSP.K. Lee * ChassisResetAction class supports the POST method for the Reset 638dd99e04bSP.K. Lee * action. 639dd99e04bSP.K. Lee * Function handles POST method request. 640dd99e04bSP.K. Lee * Analyzes POST body before sending Reset request data to D-Bus. 641dd99e04bSP.K. Lee */ 6427e860f15SJohn Edward Broadbent 6437e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetAction(App& app) 644dd99e04bSP.K. Lee { 6457e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") 646*ed398213SEd Tanous .privileges(redfish::privileges::postChassis) 6477e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 6487e860f15SJohn Edward Broadbent [](const crow::Request& req, 6497e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6507e860f15SJohn Edward Broadbent const std::string&) { 651dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Post Chassis Reset."; 652dd99e04bSP.K. Lee 653dd99e04bSP.K. Lee std::string resetType; 654dd99e04bSP.K. Lee 6557e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 6567e860f15SJohn Edward Broadbent resetType)) 657dd99e04bSP.K. Lee { 658dd99e04bSP.K. Lee return; 659dd99e04bSP.K. Lee } 660dd99e04bSP.K. Lee 661dd99e04bSP.K. Lee if (resetType != "PowerCycle") 662dd99e04bSP.K. Lee { 663dd99e04bSP.K. Lee BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 664dd99e04bSP.K. Lee << resetType; 6657e860f15SJohn Edward Broadbent messages::actionParameterNotSupported( 6667e860f15SJohn Edward Broadbent asyncResp->res, resetType, "ResetType"); 667dd99e04bSP.K. Lee 668dd99e04bSP.K. Lee return; 669dd99e04bSP.K. Lee } 670dd99e04bSP.K. Lee doChassisPowerCycle(asyncResp); 6717e860f15SJohn Edward Broadbent }); 672dd99e04bSP.K. Lee } 6731cb1a9e6SAppaRao Puli 6741cb1a9e6SAppaRao Puli /** 6751cb1a9e6SAppaRao Puli * ChassisResetActionInfo derived class for delivering Chassis 6761cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 6771cb1a9e6SAppaRao Puli */ 6787e860f15SJohn Edward Broadbent inline void requestRoutesChassisResetActionInfo(App& app) 6791cb1a9e6SAppaRao Puli { 6807e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") 681*ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 6827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 6837e860f15SJohn Edward Broadbent [](const crow::Request&, 6847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6857e860f15SJohn Edward Broadbent const std::string& chassisId) 6861cb1a9e6SAppaRao Puli 6871cb1a9e6SAppaRao Puli { 6888d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 6898d1b46d7Szhanghch05 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 6908d1b46d7Szhanghch05 {"@odata.id", 6918d1b46d7Szhanghch05 "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"}, 6921cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 6931cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 6941cb1a9e6SAppaRao Puli {"Parameters", 6951cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 6961cb1a9e6SAppaRao Puli {"Required", true}, 6971cb1a9e6SAppaRao Puli {"DataType", "String"}, 6981cb1a9e6SAppaRao Puli {"AllowableValues", {"PowerCycle"}}}}}}; 6997e860f15SJohn Edward Broadbent }); 7001cb1a9e6SAppaRao Puli } 7011cb1a9e6SAppaRao Puli 702e37f8451SRapkiewicz, Pawel } // namespace redfish 703