1c5b2abe0SLewanczyk, Dawid /* 2c5b2abe0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation 3c5b2abe0SLewanczyk, Dawid // 4c5b2abe0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License"); 5c5b2abe0SLewanczyk, Dawid // you may not use this file except in compliance with the License. 6c5b2abe0SLewanczyk, Dawid // You may obtain a copy of the License at 7c5b2abe0SLewanczyk, Dawid // 8c5b2abe0SLewanczyk, Dawid // http://www.apache.org/licenses/LICENSE-2.0 9c5b2abe0SLewanczyk, Dawid // 10c5b2abe0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software 11c5b2abe0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS, 12c5b2abe0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c5b2abe0SLewanczyk, Dawid // See the License for the specific language governing permissions and 14c5b2abe0SLewanczyk, Dawid // limitations under the License. 15c5b2abe0SLewanczyk, Dawid */ 16c5b2abe0SLewanczyk, Dawid #pragma once 17c5b2abe0SLewanczyk, Dawid 18b49ac873SJames Feist #include "health.hpp" 19*f5c9f8bdSJason M. Bills #include "pcie.hpp" 20c5d03ff4SJennifer Lee #include "redfish_util.hpp" 21c5d03ff4SJennifer Lee 229712f8acSEd Tanous #include <boost/container/flat_map.hpp> 239712f8acSEd Tanous #include <node.hpp> 24cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 25c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 26abf2add6SEd Tanous #include <variant> 27c5b2abe0SLewanczyk, Dawid 281abe55efSEd Tanous namespace redfish 291abe55efSEd Tanous { 30c5b2abe0SLewanczyk, Dawid 31c5b2abe0SLewanczyk, Dawid /** 32c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 33c5b2abe0SLewanczyk, Dawid * 34c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 35c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 36c5b2abe0SLewanczyk, Dawid * 37c5b2abe0SLewanczyk, Dawid * @return None. 38c5b2abe0SLewanczyk, Dawid */ 39029573d4SEd Tanous void getComputerSystem(std::shared_ptr<AsyncResp> aResp) 401abe55efSEd Tanous { 4155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 4255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 43c5d03ff4SJennifer Lee [aResp]( 44c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 45c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 466c34de48SEd Tanous std::string, 476c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 48c5b2abe0SLewanczyk, Dawid &subtree) { 491abe55efSEd Tanous if (ec) 501abe55efSEd Tanous { 5155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 52f12894f8SJason M. Bills messages::internalError(aResp->res); 53c5b2abe0SLewanczyk, Dawid return; 54c5b2abe0SLewanczyk, Dawid } 55c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 566c34de48SEd Tanous for (const std::pair<std::string, 576c34de48SEd Tanous std::vector<std::pair< 586c34de48SEd Tanous std::string, std::vector<std::string>>>> 591abe55efSEd Tanous &object : subtree) 601abe55efSEd Tanous { 61c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 6255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 631abe55efSEd Tanous const std::vector< 641abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 65c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 661abe55efSEd Tanous if (connectionNames.size() < 1) 671abe55efSEd Tanous { 68c5b2abe0SLewanczyk, Dawid continue; 69c5b2abe0SLewanczyk, Dawid } 70029573d4SEd Tanous 716c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 726c34de48SEd Tanous // BiosVer 7304a258f4SEd Tanous for (const auto &connection : connectionNames) 741abe55efSEd Tanous { 7504a258f4SEd Tanous for (const auto &interfaceName : connection.second) 761abe55efSEd Tanous { 7704a258f4SEd Tanous if (interfaceName == 7804a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 791abe55efSEd Tanous { 801abe55efSEd Tanous BMCWEB_LOG_DEBUG 8104a258f4SEd Tanous << "Found Dimm, now get its properties."; 8255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 83029573d4SEd Tanous [aResp](const boost::system::error_code ec, 846c34de48SEd Tanous const std::vector< 856c34de48SEd Tanous std::pair<std::string, VariantType>> 861abe55efSEd Tanous &properties) { 871abe55efSEd Tanous if (ec) 881abe55efSEd Tanous { 891abe55efSEd Tanous BMCWEB_LOG_ERROR 906c34de48SEd Tanous << "DBUS response error " << ec; 91f12894f8SJason M. Bills messages::internalError(aResp->res); 92c5b2abe0SLewanczyk, Dawid return; 93c5b2abe0SLewanczyk, Dawid } 946c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 956c34de48SEd Tanous << properties.size() 96c5b2abe0SLewanczyk, Dawid << "Dimm properties."; 9704a258f4SEd Tanous for (const std::pair<std::string, 9804a258f4SEd Tanous VariantType> 9904a258f4SEd Tanous &property : properties) 1001abe55efSEd Tanous { 101029573d4SEd Tanous if (property.first == "MemorySizeInKb") 1021abe55efSEd Tanous { 10304a258f4SEd Tanous const uint64_t *value = 104029573d4SEd Tanous sdbusplus::message::variant_ns:: 105029573d4SEd Tanous get_if<uint64_t>( 1061b6b96c5SEd Tanous &property.second); 10704a258f4SEd Tanous if (value != nullptr) 1081abe55efSEd Tanous { 1091abe55efSEd Tanous aResp->res.jsonValue 1106c34de48SEd Tanous ["TotalSystemMemoryGi" 1116c34de48SEd Tanous "B"] += 11204a258f4SEd Tanous *value / (1024 * 1024); 113029573d4SEd Tanous aResp->res 114029573d4SEd Tanous .jsonValue["MemorySummary"] 115029573d4SEd Tanous ["Status"] 116029573d4SEd Tanous ["State"] = 1171abe55efSEd Tanous "Enabled"; 118c5b2abe0SLewanczyk, Dawid } 119c5b2abe0SLewanczyk, Dawid } 120c5b2abe0SLewanczyk, Dawid } 121c5b2abe0SLewanczyk, Dawid }, 12204a258f4SEd Tanous connection.first, path, 1236c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 1246c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 1251abe55efSEd Tanous } 12604a258f4SEd Tanous else if (interfaceName == 12704a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 1281abe55efSEd Tanous { 1291abe55efSEd Tanous BMCWEB_LOG_DEBUG 13004a258f4SEd Tanous << "Found Cpu, now get its properties."; 131a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 132029573d4SEd Tanous [aResp](const boost::system::error_code ec, 1336c34de48SEd Tanous const std::vector< 1346c34de48SEd Tanous std::pair<std::string, VariantType>> 1351abe55efSEd Tanous &properties) { 1361abe55efSEd Tanous if (ec) 1371abe55efSEd Tanous { 1381abe55efSEd Tanous BMCWEB_LOG_ERROR 1396c34de48SEd Tanous << "DBUS response error " << ec; 140f12894f8SJason M. Bills messages::internalError(aResp->res); 141c5b2abe0SLewanczyk, Dawid return; 142c5b2abe0SLewanczyk, Dawid } 1436c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 1446c34de48SEd Tanous << properties.size() 145c5b2abe0SLewanczyk, Dawid << "Cpu properties."; 14604a258f4SEd Tanous for (const auto &property : properties) 1471abe55efSEd Tanous { 148029573d4SEd Tanous if (property.first == "ProcessorFamily") 1491abe55efSEd Tanous { 150a0803efaSEd Tanous const std::string *value = 151029573d4SEd Tanous sdbusplus::message::variant_ns:: 152029573d4SEd Tanous get_if<std::string>( 1531b6b96c5SEd Tanous &property.second); 1541abe55efSEd Tanous if (value != nullptr) 1551abe55efSEd Tanous { 156029573d4SEd Tanous nlohmann::json &procSummary = 1571abe55efSEd Tanous aResp->res.jsonValue 1586c34de48SEd Tanous ["ProcessorSumm" 15904a258f4SEd Tanous "ary"]; 16004a258f4SEd Tanous nlohmann::json &procCount = 16104a258f4SEd Tanous procSummary["Count"]; 16204a258f4SEd Tanous 16304a258f4SEd Tanous procCount = 164029573d4SEd Tanous procCount.get<int>() + 1; 165029573d4SEd Tanous procSummary["Status"]["State"] = 166c5b2abe0SLewanczyk, Dawid "Enabled"; 167029573d4SEd Tanous procSummary["Model"] = *value; 168c5b2abe0SLewanczyk, Dawid } 169c5b2abe0SLewanczyk, Dawid } 170c5b2abe0SLewanczyk, Dawid } 171c5b2abe0SLewanczyk, Dawid }, 17204a258f4SEd Tanous connection.first, path, 1736c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 1746c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 1751abe55efSEd Tanous } 17604a258f4SEd Tanous else if (interfaceName == 17704a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 1781abe55efSEd Tanous { 1791abe55efSEd Tanous BMCWEB_LOG_DEBUG 18004a258f4SEd Tanous << "Found UUID, now get its properties."; 18155c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 182029573d4SEd Tanous [aResp](const boost::system::error_code ec, 1836c34de48SEd Tanous const std::vector< 1846c34de48SEd Tanous std::pair<std::string, VariantType>> 1851abe55efSEd Tanous &properties) { 1861abe55efSEd Tanous if (ec) 1871abe55efSEd Tanous { 1881abe55efSEd Tanous BMCWEB_LOG_DEBUG 1896c34de48SEd Tanous << "DBUS response error " << ec; 190f12894f8SJason M. Bills messages::internalError(aResp->res); 191c5b2abe0SLewanczyk, Dawid return; 192c5b2abe0SLewanczyk, Dawid } 1936c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 1946c34de48SEd Tanous << properties.size() 195c5b2abe0SLewanczyk, Dawid << "UUID properties."; 1961abe55efSEd Tanous for (const std::pair<std::string, 19704a258f4SEd Tanous VariantType> 19804a258f4SEd Tanous &property : properties) 1991abe55efSEd Tanous { 20004a258f4SEd Tanous if (property.first == "UUID") 2011abe55efSEd Tanous { 202c5b2abe0SLewanczyk, Dawid const std::string *value = 203029573d4SEd Tanous sdbusplus::message::variant_ns:: 204029573d4SEd Tanous get_if<std::string>( 2051b6b96c5SEd Tanous &property.second); 20604a258f4SEd Tanous 2071abe55efSEd Tanous if (value != nullptr) 2081abe55efSEd Tanous { 209029573d4SEd Tanous std::string valueStr = *value; 21004a258f4SEd Tanous if (valueStr.size() == 32) 2111abe55efSEd Tanous { 212029573d4SEd Tanous valueStr.insert(8, 1, '-'); 213029573d4SEd Tanous valueStr.insert(13, 1, '-'); 214029573d4SEd Tanous valueStr.insert(18, 1, '-'); 215029573d4SEd Tanous valueStr.insert(23, 1, '-'); 21604a258f4SEd Tanous } 217029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 21804a258f4SEd Tanous << valueStr; 219029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 22004a258f4SEd Tanous valueStr; 221c5b2abe0SLewanczyk, Dawid } 222c5b2abe0SLewanczyk, Dawid } 223c5b2abe0SLewanczyk, Dawid } 224c5b2abe0SLewanczyk, Dawid }, 22504a258f4SEd Tanous connection.first, path, 2266c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2271abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 228c5b2abe0SLewanczyk, Dawid } 229029573d4SEd Tanous else if (interfaceName == 230029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 2311abe55efSEd Tanous { 232029573d4SEd Tanous crow::connections::systemBus->async_method_call( 233029573d4SEd Tanous [aResp](const boost::system::error_code ec, 234029573d4SEd Tanous const std::vector< 235029573d4SEd Tanous std::pair<std::string, VariantType>> 236029573d4SEd Tanous &propertiesList) { 237029573d4SEd Tanous if (ec) 238029573d4SEd Tanous { 239e4a4b9a9SJames Feist // doesn't have to include this 240e4a4b9a9SJames Feist // interface 241029573d4SEd Tanous return; 242029573d4SEd Tanous } 243029573d4SEd Tanous BMCWEB_LOG_DEBUG << "Got " 244029573d4SEd Tanous << propertiesList.size() 245029573d4SEd Tanous << "properties for system"; 246029573d4SEd Tanous for (const std::pair<std::string, 247029573d4SEd Tanous VariantType> 248029573d4SEd Tanous &property : propertiesList) 249029573d4SEd Tanous { 250fc5afcf9Sbeccabroek const std::string &propertyName = 251fc5afcf9Sbeccabroek property.first; 252fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 253fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 254fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 255fc5afcf9Sbeccabroek (propertyName == "Model")) 256fc5afcf9Sbeccabroek { 257029573d4SEd Tanous const std::string *value = 258fc5afcf9Sbeccabroek std::get_if<std::string>( 259029573d4SEd Tanous &property.second); 260029573d4SEd Tanous if (value != nullptr) 261029573d4SEd Tanous { 262029573d4SEd Tanous aResp->res 263fc5afcf9Sbeccabroek .jsonValue[propertyName] = 264029573d4SEd Tanous *value; 265029573d4SEd Tanous } 266029573d4SEd Tanous } 267fc5afcf9Sbeccabroek } 268029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 269029573d4SEd Tanous aResp->res.jsonValue["Id"] = 270029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 271cb7e1e7bSAndrew Geissler // Grab the bios version 272cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 273cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 274cb7e1e7bSAndrew Geissler "BiosVersion"); 275029573d4SEd Tanous }, 276029573d4SEd Tanous connection.first, path, 277029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 278029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 279029573d4SEd Tanous "Asset"); 280e4a4b9a9SJames Feist 281e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 282e4a4b9a9SJames Feist [aResp]( 283e4a4b9a9SJames Feist const boost::system::error_code ec, 284e4a4b9a9SJames Feist const std::variant<std::string> &property) { 285e4a4b9a9SJames Feist if (ec) 286e4a4b9a9SJames Feist { 287e4a4b9a9SJames Feist // doesn't have to include this 288e4a4b9a9SJames Feist // interface 289e4a4b9a9SJames Feist return; 290e4a4b9a9SJames Feist } 291e4a4b9a9SJames Feist 292e4a4b9a9SJames Feist const std::string *value = 293e4a4b9a9SJames Feist std::get_if<std::string>(&property); 294e4a4b9a9SJames Feist if (value != nullptr) 295e4a4b9a9SJames Feist { 296e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 297e4a4b9a9SJames Feist *value; 298e4a4b9a9SJames Feist } 299e4a4b9a9SJames Feist }, 300e4a4b9a9SJames Feist connection.first, path, 301e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 302e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 303e4a4b9a9SJames Feist "AssetTag", 304e4a4b9a9SJames Feist "AssetTag"); 305029573d4SEd Tanous } 306029573d4SEd Tanous } 307029573d4SEd Tanous } 308c5b2abe0SLewanczyk, Dawid } 309c5b2abe0SLewanczyk, Dawid }, 310c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 311c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 312c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 3136617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 3146617338dSEd Tanous std::array<const char *, 5>{ 3156617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 3166617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 3176617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 3186617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 3196617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 3206617338dSEd Tanous }); 321c5b2abe0SLewanczyk, Dawid } 322c5b2abe0SLewanczyk, Dawid 323c5b2abe0SLewanczyk, Dawid /** 324c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 325c5b2abe0SLewanczyk, Dawid * 326491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 327c5b2abe0SLewanczyk, Dawid * @param[in] callback Callback for process retrieved data. 328c5b2abe0SLewanczyk, Dawid * 329c5b2abe0SLewanczyk, Dawid * @return None. 330c5b2abe0SLewanczyk, Dawid */ 331c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 332a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp, 3331abe55efSEd Tanous CallbackFunc &&callback) 3341abe55efSEd Tanous { 33555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 33655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 337c5d03ff4SJennifer Lee [aResp, 3386617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code &ec, 3391abe55efSEd Tanous const ManagedObjectsType &resp) { 3401abe55efSEd Tanous if (ec) 3411abe55efSEd Tanous { 34255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 343f12894f8SJason M. Bills messages::internalError(aResp->res); 344c5b2abe0SLewanczyk, Dawid return; 345c5b2abe0SLewanczyk, Dawid } 3466c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects."; 3471abe55efSEd Tanous for (const auto &objPath : resp) 3481abe55efSEd Tanous { 349c5b2abe0SLewanczyk, Dawid const std::string &path = objPath.first; 3501abe55efSEd Tanous if (path.rfind("enclosure_identify") != std::string::npos) 3511abe55efSEd Tanous { 3521abe55efSEd Tanous for (const auto &interface : objPath.second) 3531abe55efSEd Tanous { 3546c34de48SEd Tanous if (interface.first == "xyz.openbmc_project.Led.Group") 3551abe55efSEd Tanous { 3561abe55efSEd Tanous for (const auto &property : interface.second) 3571abe55efSEd Tanous { 3581abe55efSEd Tanous if (property.first == "Asserted") 3591abe55efSEd Tanous { 360c5b2abe0SLewanczyk, Dawid const bool *asserted = 361abf2add6SEd Tanous std::get_if<bool>(&property.second); 3621abe55efSEd Tanous if (nullptr != asserted) 3631abe55efSEd Tanous { 364c5b2abe0SLewanczyk, Dawid callback(*asserted, aResp); 3651abe55efSEd Tanous } 3661abe55efSEd Tanous else 3671abe55efSEd Tanous { 368c5b2abe0SLewanczyk, Dawid callback(false, aResp); 369c5b2abe0SLewanczyk, Dawid } 370c5b2abe0SLewanczyk, Dawid } 371c5b2abe0SLewanczyk, Dawid } 372c5b2abe0SLewanczyk, Dawid } 373c5b2abe0SLewanczyk, Dawid } 374c5b2abe0SLewanczyk, Dawid } 375c5b2abe0SLewanczyk, Dawid } 376c5b2abe0SLewanczyk, Dawid }, 377c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 3786c34de48SEd Tanous "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager", 3796c34de48SEd Tanous "GetManagedObjects"); 380c5b2abe0SLewanczyk, Dawid } 381c5b2abe0SLewanczyk, Dawid 382c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 3836c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback) 3841abe55efSEd Tanous { 38555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get identify led properties"; 38655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 3876617338dSEd Tanous [aResp, 3886617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code ec, 389c5b2abe0SLewanczyk, Dawid const PropertiesType &properties) { 3901abe55efSEd Tanous if (ec) 3911abe55efSEd Tanous { 39255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 393f12894f8SJason M. Bills messages::internalError(aResp->res); 394c5b2abe0SLewanczyk, Dawid return; 395c5b2abe0SLewanczyk, Dawid } 3961abe55efSEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 3971abe55efSEd Tanous << "led properties."; 398c5b2abe0SLewanczyk, Dawid std::string output; 3991abe55efSEd Tanous for (const auto &property : properties) 4001abe55efSEd Tanous { 4011abe55efSEd Tanous if (property.first == "State") 4021abe55efSEd Tanous { 403c5b2abe0SLewanczyk, Dawid const std::string *s = 404abf2add6SEd Tanous std::get_if<std::string>(&property.second); 4051abe55efSEd Tanous if (nullptr != s) 4061abe55efSEd Tanous { 40755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Identify Led State: " << *s; 408c5b2abe0SLewanczyk, Dawid const auto pos = s->rfind('.'); 4091abe55efSEd Tanous if (pos != std::string::npos) 4101abe55efSEd Tanous { 411c5b2abe0SLewanczyk, Dawid auto led = s->substr(pos + 1); 4121abe55efSEd Tanous for (const std::pair<const char *, const char *> 4131abe55efSEd Tanous &p : 4141abe55efSEd Tanous std::array< 4156c34de48SEd Tanous std::pair<const char *, const char *>, 3>{ 4166c34de48SEd Tanous {{"On", "Lit"}, 417c5b2abe0SLewanczyk, Dawid {"Blink", "Blinking"}, 4181abe55efSEd Tanous {"Off", "Off"}}}) 4191abe55efSEd Tanous { 4201abe55efSEd Tanous if (led == p.first) 4211abe55efSEd Tanous { 422c5b2abe0SLewanczyk, Dawid output = p.second; 423c5b2abe0SLewanczyk, Dawid } 424c5b2abe0SLewanczyk, Dawid } 425c5b2abe0SLewanczyk, Dawid } 426c5b2abe0SLewanczyk, Dawid } 427c5b2abe0SLewanczyk, Dawid } 428c5b2abe0SLewanczyk, Dawid } 429c5b2abe0SLewanczyk, Dawid callback(output, aResp); 430c5b2abe0SLewanczyk, Dawid }, 431c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 432c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 433c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "GetAll", 434c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical"); 435c5b2abe0SLewanczyk, Dawid } 436c5b2abe0SLewanczyk, Dawid /** 437c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 438c5b2abe0SLewanczyk, Dawid * 439c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 440c5b2abe0SLewanczyk, Dawid * 441c5b2abe0SLewanczyk, Dawid * @return None. 442c5b2abe0SLewanczyk, Dawid */ 443a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 4441abe55efSEd Tanous { 44555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 44655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 447c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 448abf2add6SEd Tanous const std::variant<std::string> &hostState) { 4491abe55efSEd Tanous if (ec) 4501abe55efSEd Tanous { 45155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 452f12894f8SJason M. Bills messages::internalError(aResp->res); 453c5b2abe0SLewanczyk, Dawid return; 454c5b2abe0SLewanczyk, Dawid } 4556617338dSEd Tanous 456abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 45755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 4586617338dSEd Tanous if (s != nullptr) 4591abe55efSEd Tanous { 460c5b2abe0SLewanczyk, Dawid // Verify Host State 46194732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 4621abe55efSEd Tanous { 46355c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 4646617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 4651abe55efSEd Tanous } 4661abe55efSEd Tanous else 4671abe55efSEd Tanous { 46855c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 4696617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 470c5b2abe0SLewanczyk, Dawid } 471c5b2abe0SLewanczyk, Dawid } 472c5b2abe0SLewanczyk, Dawid }, 4736c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 4746617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 4756617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 476c5b2abe0SLewanczyk, Dawid } 477c5b2abe0SLewanczyk, Dawid 478c5b2abe0SLewanczyk, Dawid /** 479491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 480491d8ee7SSantosh Puranik * 481491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 482491d8ee7SSantosh Puranik * 483491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 484491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 485491d8ee7SSantosh Puranik */ 486491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 487491d8ee7SSantosh Puranik { 488491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 489491d8ee7SSantosh Puranik { 490491d8ee7SSantosh Puranik return "None"; 491491d8ee7SSantosh Puranik } 492491d8ee7SSantosh Puranik else if (dbusSource == 493491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 494491d8ee7SSantosh Puranik { 495491d8ee7SSantosh Puranik return "Hdd"; 496491d8ee7SSantosh Puranik } 497491d8ee7SSantosh Puranik else if (dbusSource == 498a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 499491d8ee7SSantosh Puranik { 500491d8ee7SSantosh Puranik return "Cd"; 501491d8ee7SSantosh Puranik } 502491d8ee7SSantosh Puranik else if (dbusSource == 503491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 504491d8ee7SSantosh Puranik { 505491d8ee7SSantosh Puranik return "Pxe"; 506491d8ee7SSantosh Puranik } 5079f16b2c1SJennifer Lee else if (dbusSource == 5089f16b2c1SJennifer Lee "xyz.openbmc_project.Control.Boot.Source.Sources.Removable") 5099f16b2c1SJennifer Lee { 5109f16b2c1SJennifer Lee return "Usb"; 5119f16b2c1SJennifer Lee } 512491d8ee7SSantosh Puranik else 513491d8ee7SSantosh Puranik { 514491d8ee7SSantosh Puranik return ""; 515491d8ee7SSantosh Puranik } 516491d8ee7SSantosh Puranik } 517491d8ee7SSantosh Puranik 518491d8ee7SSantosh Puranik /** 519491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 520491d8ee7SSantosh Puranik * 521491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 522491d8ee7SSantosh Puranik * 523491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 524491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 525491d8ee7SSantosh Puranik */ 526491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 527491d8ee7SSantosh Puranik { 528491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 529491d8ee7SSantosh Puranik { 530491d8ee7SSantosh Puranik return "None"; 531491d8ee7SSantosh Puranik } 532491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 533491d8ee7SSantosh Puranik { 534491d8ee7SSantosh Puranik return "Diags"; 535491d8ee7SSantosh Puranik } 536491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 537491d8ee7SSantosh Puranik { 538491d8ee7SSantosh Puranik return "BiosSetup"; 539491d8ee7SSantosh Puranik } 540491d8ee7SSantosh Puranik else 541491d8ee7SSantosh Puranik { 542491d8ee7SSantosh Puranik return ""; 543491d8ee7SSantosh Puranik } 544491d8ee7SSantosh Puranik } 545491d8ee7SSantosh Puranik 546491d8ee7SSantosh Puranik /** 547491d8ee7SSantosh Puranik * @brief Traslates boot source from Redfish to DBUS property value. 548491d8ee7SSantosh Puranik * 549491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 550491d8ee7SSantosh Puranik * 551491d8ee7SSantosh Puranik * @return Returns as a string, the boot source as expected by DBUS. 552491d8ee7SSantosh Puranik * If translation cannot be done, returns an empty string. 553491d8ee7SSantosh Puranik */ 554491d8ee7SSantosh Puranik static std::string rfToDbusBootSource(const std::string &rfSource) 555491d8ee7SSantosh Puranik { 556491d8ee7SSantosh Puranik if (rfSource == "None") 557491d8ee7SSantosh Puranik { 558491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 559491d8ee7SSantosh Puranik } 560491d8ee7SSantosh Puranik else if (rfSource == "Hdd") 561491d8ee7SSantosh Puranik { 562491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 563491d8ee7SSantosh Puranik } 564491d8ee7SSantosh Puranik else if (rfSource == "Cd") 565491d8ee7SSantosh Puranik { 566a71dc0b7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 567491d8ee7SSantosh Puranik } 568491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 569491d8ee7SSantosh Puranik { 570491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 571491d8ee7SSantosh Puranik } 5729f16b2c1SJennifer Lee else if (rfSource == "Usb") 5739f16b2c1SJennifer Lee { 5749f16b2c1SJennifer Lee return "xyz.openbmc_project.Control.Boot.Source.Sources.Removable"; 5759f16b2c1SJennifer Lee } 576491d8ee7SSantosh Puranik else 577491d8ee7SSantosh Puranik { 578491d8ee7SSantosh Puranik return ""; 579491d8ee7SSantosh Puranik } 580491d8ee7SSantosh Puranik } 581491d8ee7SSantosh Puranik 582491d8ee7SSantosh Puranik /** 583491d8ee7SSantosh Puranik * @brief Traslates boot mode from Redfish to DBUS property value. 584491d8ee7SSantosh Puranik * 585491d8ee7SSantosh Puranik * @param[in] rfMode The boot mode in Redfish. 586491d8ee7SSantosh Puranik * 587491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode as expected by DBUS. 588491d8ee7SSantosh Puranik * If translation cannot be done, returns an empty string. 589491d8ee7SSantosh Puranik */ 590491d8ee7SSantosh Puranik static std::string rfToDbusBootMode(const std::string &rfMode) 591491d8ee7SSantosh Puranik { 592491d8ee7SSantosh Puranik if (rfMode == "None") 593491d8ee7SSantosh Puranik { 594491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 595491d8ee7SSantosh Puranik } 596491d8ee7SSantosh Puranik else if (rfMode == "Diags") 597491d8ee7SSantosh Puranik { 598491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 599491d8ee7SSantosh Puranik } 600491d8ee7SSantosh Puranik else if (rfMode == "BiosSetup") 601491d8ee7SSantosh Puranik { 602491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 603491d8ee7SSantosh Puranik } 604491d8ee7SSantosh Puranik else 605491d8ee7SSantosh Puranik { 606491d8ee7SSantosh Puranik return ""; 607491d8ee7SSantosh Puranik } 608491d8ee7SSantosh Puranik } 609491d8ee7SSantosh Puranik 610491d8ee7SSantosh Puranik /** 611491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 612491d8ee7SSantosh Puranik * 613491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 614491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 615491d8ee7SSantosh Puranik * 616491d8ee7SSantosh Puranik * @return None. 617491d8ee7SSantosh Puranik */ 618491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 619491d8ee7SSantosh Puranik std::string bootDbusObj) 620491d8ee7SSantosh Puranik { 621491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 622491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 623491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 624491d8ee7SSantosh Puranik if (ec) 625491d8ee7SSantosh Puranik { 626491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 627491d8ee7SSantosh Puranik messages::internalError(aResp->res); 628491d8ee7SSantosh Puranik return; 629491d8ee7SSantosh Puranik } 630491d8ee7SSantosh Puranik 631491d8ee7SSantosh Puranik const std::string *bootModeStr = 632491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 633491d8ee7SSantosh Puranik 634491d8ee7SSantosh Puranik if (!bootModeStr) 635491d8ee7SSantosh Puranik { 636491d8ee7SSantosh Puranik messages::internalError(aResp->res); 637491d8ee7SSantosh Puranik return; 638491d8ee7SSantosh Puranik } 639491d8ee7SSantosh Puranik 640491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 641491d8ee7SSantosh Puranik 642491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 643491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 644491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 645491d8ee7SSantosh Puranik "AllowableValues"] = { 646491d8ee7SSantosh Puranik "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup"}; 647491d8ee7SSantosh Puranik 648491d8ee7SSantosh Puranik if (*bootModeStr != 649491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 650491d8ee7SSantosh Puranik { 651491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 652491d8ee7SSantosh Puranik if (!rfMode.empty()) 653491d8ee7SSantosh Puranik { 654491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 655491d8ee7SSantosh Puranik rfMode; 656491d8ee7SSantosh Puranik } 657491d8ee7SSantosh Puranik } 658491d8ee7SSantosh Puranik 659491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 660491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 661491d8ee7SSantosh Puranik // overrides are disabled 662491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 663491d8ee7SSantosh Puranik "None") 664491d8ee7SSantosh Puranik { 665491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 666491d8ee7SSantosh Puranik "Disabled"; 667491d8ee7SSantosh Puranik } 668491d8ee7SSantosh Puranik }, 669491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 670491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 671491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 672491d8ee7SSantosh Puranik } 673491d8ee7SSantosh Puranik 674491d8ee7SSantosh Puranik /** 675491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 676491d8ee7SSantosh Puranik * 677491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 678491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 679491d8ee7SSantosh Puranik * 680491d8ee7SSantosh Puranik * @return None. 681491d8ee7SSantosh Puranik */ 682491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 683491d8ee7SSantosh Puranik { 684491d8ee7SSantosh Puranik std::string bootDbusObj = 685491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 686491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 687491d8ee7SSantosh Puranik 688491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 689491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 690491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 691491d8ee7SSantosh Puranik 692491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 693491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 694491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 695491d8ee7SSantosh Puranik if (ec) 696491d8ee7SSantosh Puranik { 697491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 698491d8ee7SSantosh Puranik messages::internalError(aResp->res); 699491d8ee7SSantosh Puranik return; 700491d8ee7SSantosh Puranik } 701491d8ee7SSantosh Puranik 702491d8ee7SSantosh Puranik const std::string *bootSourceStr = 703491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 704491d8ee7SSantosh Puranik 705491d8ee7SSantosh Puranik if (!bootSourceStr) 706491d8ee7SSantosh Puranik { 707491d8ee7SSantosh Puranik messages::internalError(aResp->res); 708491d8ee7SSantosh Puranik return; 709491d8ee7SSantosh Puranik } 710491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 711491d8ee7SSantosh Puranik 712491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 713491d8ee7SSantosh Puranik if (!rfSource.empty()) 714491d8ee7SSantosh Puranik { 715491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 716491d8ee7SSantosh Puranik rfSource; 717491d8ee7SSantosh Puranik } 718491d8ee7SSantosh Puranik }, 719491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 720491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 721491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 722491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 723491d8ee7SSantosh Puranik } 724491d8ee7SSantosh Puranik 725491d8ee7SSantosh Puranik /** 726491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 727491d8ee7SSantosh Puranik * get boot source and boot mode. 728491d8ee7SSantosh Puranik * 729491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 730491d8ee7SSantosh Puranik * 731491d8ee7SSantosh Puranik * @return None. 732491d8ee7SSantosh Puranik */ 733491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 734491d8ee7SSantosh Puranik { 735491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 736491d8ee7SSantosh Puranik 737491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 738c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 739491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 740491d8ee7SSantosh Puranik if (ec) 741491d8ee7SSantosh Puranik { 742491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 743491d8ee7SSantosh Puranik messages::internalError(aResp->res); 744491d8ee7SSantosh Puranik return; 745491d8ee7SSantosh Puranik } 746491d8ee7SSantosh Puranik 747491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 748491d8ee7SSantosh Puranik 749491d8ee7SSantosh Puranik if (!oneTimePtr) 750491d8ee7SSantosh Puranik { 751491d8ee7SSantosh Puranik messages::internalError(aResp->res); 752491d8ee7SSantosh Puranik return; 753491d8ee7SSantosh Puranik } 754491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 755491d8ee7SSantosh Puranik }, 756491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 757491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 758491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 759491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 760491d8ee7SSantosh Puranik } 761491d8ee7SSantosh Puranik 762491d8ee7SSantosh Puranik /** 763491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 764491d8ee7SSantosh Puranik * 765491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 766491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 767491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 768491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 769491d8ee7SSantosh Puranik * 770491d8ee7SSantosh Puranik * @return None. 771491d8ee7SSantosh Puranik */ 772491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 773491d8ee7SSantosh Puranik bool oneTimeEnabled, 774491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 775491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 776491d8ee7SSantosh Puranik { 777491d8ee7SSantosh Puranik if (bootEnable && (bootEnable != "Once") && (bootEnable != "Continuous") && 778491d8ee7SSantosh Puranik (bootEnable != "Disabled")) 779491d8ee7SSantosh Puranik { 780491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for BootSourceOverrideEnabled: " 781491d8ee7SSantosh Puranik << *bootEnable; 782491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 783491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 784491d8ee7SSantosh Puranik return; 785491d8ee7SSantosh Puranik } 786491d8ee7SSantosh Puranik 787491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 788491d8ee7SSantosh Puranik // Validate incoming parameters 789491d8ee7SSantosh Puranik if (bootEnable) 790491d8ee7SSantosh Puranik { 791491d8ee7SSantosh Puranik if (*bootEnable == "Once") 792491d8ee7SSantosh Puranik { 793491d8ee7SSantosh Puranik oneTimeSetting = true; 794491d8ee7SSantosh Puranik } 795491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 796491d8ee7SSantosh Puranik { 797491d8ee7SSantosh Puranik oneTimeSetting = false; 798491d8ee7SSantosh Puranik } 799491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 800491d8ee7SSantosh Puranik { 801491d8ee7SSantosh Puranik oneTimeSetting = false; 802491d8ee7SSantosh Puranik } 803491d8ee7SSantosh Puranik else 804491d8ee7SSantosh Puranik { 805491d8ee7SSantosh Puranik 806491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 807491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 808491d8ee7SSantosh Puranik << *bootEnable; 809491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 810491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 811491d8ee7SSantosh Puranik return; 812491d8ee7SSantosh Puranik } 813491d8ee7SSantosh Puranik } 814491d8ee7SSantosh Puranik std::string bootSourceStr; 815491d8ee7SSantosh Puranik std::string bootModeStr; 816491d8ee7SSantosh Puranik if (bootSource) 817491d8ee7SSantosh Puranik { 818491d8ee7SSantosh Puranik bootSourceStr = rfToDbusBootSource(*bootSource); 819491d8ee7SSantosh Puranik bootModeStr = rfToDbusBootMode(*bootSource); 820491d8ee7SSantosh Puranik 821491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 822491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 823491d8ee7SSantosh Puranik 824491d8ee7SSantosh Puranik if (bootSourceStr.empty() && bootModeStr.empty()) 825491d8ee7SSantosh Puranik { 826491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Invalid property value for " 827491d8ee7SSantosh Puranik "BootSourceOverrideTarget: " 828491d8ee7SSantosh Puranik << *bootSource; 829491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 830491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 831491d8ee7SSantosh Puranik return; 832491d8ee7SSantosh Puranik } 833491d8ee7SSantosh Puranik } 834491d8ee7SSantosh Puranik const char *bootObj = 835491d8ee7SSantosh Puranik oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 836491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 837491d8ee7SSantosh Puranik // Figure out what properties to set 838491d8ee7SSantosh Puranik if (bootEnable && (*bootEnable == "Disabled")) 839491d8ee7SSantosh Puranik { 840491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 841491d8ee7SSantosh Puranik // Request to only turn OFF/ON enabled, if turning enabled OFF, need 842491d8ee7SSantosh Puranik // to reset the source and mode too. If turning it ON, we only need 843491d8ee7SSantosh Puranik // to set the enabled property 844491d8ee7SSantosh Puranik bootSourceStr = 845491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 846491d8ee7SSantosh Puranik bootModeStr = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 847491d8ee7SSantosh Puranik } 848491d8ee7SSantosh Puranik else if (bootSource) 849491d8ee7SSantosh Puranik { 850491d8ee7SSantosh Puranik // Source target specified 851491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 852491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 853491d8ee7SSantosh Puranik bootSourceStr = rfToDbusBootSource(*bootSource); 854491d8ee7SSantosh Puranik bootModeStr = rfToDbusBootMode(*bootSource); 855491d8ee7SSantosh Puranik 856491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 857491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 858491d8ee7SSantosh Puranik 859491d8ee7SSantosh Puranik if (bootSourceStr.empty() && bootModeStr.empty()) 860491d8ee7SSantosh Puranik { 861491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Invalid property value for " 862491d8ee7SSantosh Puranik "BootSourceOverrideTarget: " 863491d8ee7SSantosh Puranik << *bootSource; 864491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 865491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 866491d8ee7SSantosh Puranik return; 867491d8ee7SSantosh Puranik } 868491d8ee7SSantosh Puranik 869491d8ee7SSantosh Puranik if (!bootSourceStr.empty()) 870491d8ee7SSantosh Puranik { 871491d8ee7SSantosh Puranik // If setting to anything other than default, also reset boot 872491d8ee7SSantosh Puranik // mode property 873491d8ee7SSantosh Puranik if (bootSourceStr != 874491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 875491d8ee7SSantosh Puranik { 876491d8ee7SSantosh Puranik bootModeStr = 877491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 878491d8ee7SSantosh Puranik } 879491d8ee7SSantosh Puranik } 880491d8ee7SSantosh Puranik else // if (!bootModeStr.empty()) 881491d8ee7SSantosh Puranik { 882491d8ee7SSantosh Puranik // If setting to anything other than default, also reset boot 883491d8ee7SSantosh Puranik // source property 884491d8ee7SSantosh Puranik if (bootModeStr != 885491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 886491d8ee7SSantosh Puranik { 887491d8ee7SSantosh Puranik bootSourceStr = 888491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 889491d8ee7SSantosh Puranik } 890491d8ee7SSantosh Puranik } 891491d8ee7SSantosh Puranik } 892491d8ee7SSantosh Puranik if (!bootSourceStr.empty()) 893491d8ee7SSantosh Puranik { 894491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 895491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 896491d8ee7SSantosh Puranik if (ec) 897491d8ee7SSantosh Puranik { 898491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 899491d8ee7SSantosh Puranik messages::internalError(aResp->res); 900491d8ee7SSantosh Puranik return; 901491d8ee7SSantosh Puranik } 902491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 903491d8ee7SSantosh Puranik }, 904491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 905491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 906491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 907491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 908491d8ee7SSantosh Puranik } 909491d8ee7SSantosh Puranik if (!bootModeStr.empty()) 910491d8ee7SSantosh Puranik { 911491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 912491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 913491d8ee7SSantosh Puranik if (ec) 914491d8ee7SSantosh Puranik { 915491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 916491d8ee7SSantosh Puranik messages::internalError(aResp->res); 917491d8ee7SSantosh Puranik return; 918491d8ee7SSantosh Puranik } 919491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 920491d8ee7SSantosh Puranik }, 921491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 922491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 923491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 924491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 925491d8ee7SSantosh Puranik } 926491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 927491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 928491d8ee7SSantosh Puranik if (ec) 929491d8ee7SSantosh Puranik { 930491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 931491d8ee7SSantosh Puranik messages::internalError(aResp->res); 932491d8ee7SSantosh Puranik return; 933491d8ee7SSantosh Puranik } 934491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 935491d8ee7SSantosh Puranik }, 936491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 937491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 938491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 939491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 940491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 941491d8ee7SSantosh Puranik } 942491d8ee7SSantosh Puranik 943491d8ee7SSantosh Puranik /** 944491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 945491d8ee7SSantosh Puranik * set boot source/boot mode properties. 946491d8ee7SSantosh Puranik * 947491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 948491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 949491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 950491d8ee7SSantosh Puranik * 951491d8ee7SSantosh Puranik * @return None. 952491d8ee7SSantosh Puranik */ 953491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 954491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 955491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 956491d8ee7SSantosh Puranik { 957491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 958491d8ee7SSantosh Puranik 959491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 960491d8ee7SSantosh Puranik [aResp{std::move(aResp)}, bootSource{std::move(bootSource)}, 961491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 962491d8ee7SSantosh Puranik const boost::system::error_code ec, 963491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 964491d8ee7SSantosh Puranik if (ec) 965491d8ee7SSantosh Puranik { 966491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 967491d8ee7SSantosh Puranik messages::internalError(aResp->res); 968491d8ee7SSantosh Puranik return; 969491d8ee7SSantosh Puranik } 970491d8ee7SSantosh Puranik 971491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 972491d8ee7SSantosh Puranik 973491d8ee7SSantosh Puranik if (!oneTimePtr) 974491d8ee7SSantosh Puranik { 975491d8ee7SSantosh Puranik messages::internalError(aResp->res); 976491d8ee7SSantosh Puranik return; 977491d8ee7SSantosh Puranik } 978491d8ee7SSantosh Puranik 979491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 980491d8ee7SSantosh Puranik 981491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 982491d8ee7SSantosh Puranik std::move(bootEnable)); 983491d8ee7SSantosh Puranik }, 984491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 985491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 986491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 987491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 988491d8ee7SSantosh Puranik } 989491d8ee7SSantosh Puranik 990491d8ee7SSantosh Puranik /** 991c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 992c5b2abe0SLewanczyk, Dawid * Schema 993c5b2abe0SLewanczyk, Dawid */ 9941abe55efSEd Tanous class SystemsCollection : public Node 9951abe55efSEd Tanous { 996c5b2abe0SLewanczyk, Dawid public: 9971abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 9981abe55efSEd Tanous { 999c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1000c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1001c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1002c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1003c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1004c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1005c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1006c5b2abe0SLewanczyk, Dawid } 1007c5b2abe0SLewanczyk, Dawid 1008c5b2abe0SLewanczyk, Dawid private: 100955c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 10101abe55efSEd Tanous const std::vector<std::string> ¶ms) override 10111abe55efSEd Tanous { 10120f74e643SEd Tanous res.jsonValue["@odata.type"] = 10130f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 10140f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 10150f74e643SEd Tanous res.jsonValue["@odata.context"] = 10160f74e643SEd Tanous "/redfish/v1/" 10170f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 10180f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1019029573d4SEd Tanous res.jsonValue["Members"] = { 1020029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 1021029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 1022029573d4SEd Tanous res.end(); 1023c5b2abe0SLewanczyk, Dawid } 1024c5b2abe0SLewanczyk, Dawid }; 1025c5b2abe0SLewanczyk, Dawid 1026c5b2abe0SLewanczyk, Dawid /** 1027cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1028cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1029cc340dd9SEd Tanous */ 1030cc340dd9SEd Tanous class SystemActionsReset : public Node 1031cc340dd9SEd Tanous { 1032cc340dd9SEd Tanous public: 1033cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1034029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1035cc340dd9SEd Tanous { 1036cc340dd9SEd Tanous entityPrivileges = { 1037cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1038cc340dd9SEd Tanous } 1039cc340dd9SEd Tanous 1040cc340dd9SEd Tanous private: 1041cc340dd9SEd Tanous /** 1042cc340dd9SEd Tanous * Function handles POST method request. 1043cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1044cc340dd9SEd Tanous */ 1045cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1046cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1047cc340dd9SEd Tanous { 1048cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1049cc340dd9SEd Tanous 10509712f8acSEd Tanous std::string resetType; 10519712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1052cc340dd9SEd Tanous { 1053cc340dd9SEd Tanous return; 1054cc340dd9SEd Tanous } 1055cc340dd9SEd Tanous 1056d22c8396SJason M. Bills // Get the command and host vs. chassis 1057cc340dd9SEd Tanous std::string command; 1058d22c8396SJason M. Bills bool hostCommand; 10599712f8acSEd Tanous if (resetType == "On") 1060cc340dd9SEd Tanous { 1061cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1062d22c8396SJason M. Bills hostCommand = true; 1063d22c8396SJason M. Bills } 1064d22c8396SJason M. Bills else if (resetType == "ForceOff") 1065d22c8396SJason M. Bills { 1066d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1067d22c8396SJason M. Bills hostCommand = false; 1068d22c8396SJason M. Bills } 1069d22c8396SJason M. Bills else if (resetType == "ForceOn") 1070d22c8396SJason M. Bills { 1071d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1072d22c8396SJason M. Bills hostCommand = true; 1073d22c8396SJason M. Bills } 1074d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1075d22c8396SJason M. Bills { 1076d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Reset"; 1077d22c8396SJason M. Bills hostCommand = false; 1078cc340dd9SEd Tanous } 10799712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1080cc340dd9SEd Tanous { 1081cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1082d22c8396SJason M. Bills hostCommand = true; 1083cc340dd9SEd Tanous } 10849712f8acSEd Tanous else if (resetType == "GracefulRestart") 1085cc340dd9SEd Tanous { 10869712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1087d22c8396SJason M. Bills hostCommand = true; 1088d22c8396SJason M. Bills } 1089d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1090d22c8396SJason M. Bills { 1091d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 1092d22c8396SJason M. Bills hostCommand = false; 1093cc340dd9SEd Tanous } 1094bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1095bfd5b826SLakshminarayana R. Kammath { 1096bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1097bfd5b826SLakshminarayana R. Kammath return; 1098bfd5b826SLakshminarayana R. Kammath } 1099cc340dd9SEd Tanous else 1100cc340dd9SEd Tanous { 1101f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1102cc340dd9SEd Tanous return; 1103cc340dd9SEd Tanous } 1104cc340dd9SEd Tanous 1105d22c8396SJason M. Bills if (hostCommand) 1106d22c8396SJason M. Bills { 1107cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1108d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1109cc340dd9SEd Tanous if (ec) 1110cc340dd9SEd Tanous { 1111cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1112d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1113d22c8396SJason M. Bills { 1114d22c8396SJason M. Bills messages::actionParameterNotSupported( 1115d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1116d22c8396SJason M. Bills } 1117d22c8396SJason M. Bills else 1118d22c8396SJason M. Bills { 1119f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1120d22c8396SJason M. Bills } 1121cc340dd9SEd Tanous return; 1122cc340dd9SEd Tanous } 1123f12894f8SJason M. Bills messages::success(asyncResp->res); 1124cc340dd9SEd Tanous }, 1125cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1126cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1127cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 11289712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1129abf2add6SEd Tanous std::variant<std::string>{command}); 1130cc340dd9SEd Tanous } 1131d22c8396SJason M. Bills else 1132d22c8396SJason M. Bills { 1133d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1134d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1135d22c8396SJason M. Bills if (ec) 1136d22c8396SJason M. Bills { 1137d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1138d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1139d22c8396SJason M. Bills { 1140d22c8396SJason M. Bills messages::actionParameterNotSupported( 1141d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1142d22c8396SJason M. Bills } 1143d22c8396SJason M. Bills else 1144d22c8396SJason M. Bills { 1145d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1146d22c8396SJason M. Bills } 1147d22c8396SJason M. Bills return; 1148d22c8396SJason M. Bills } 1149d22c8396SJason M. Bills messages::success(asyncResp->res); 1150d22c8396SJason M. Bills }, 1151d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1152d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1153d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1154d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1155d22c8396SJason M. Bills std::variant<std::string>{command}); 1156d22c8396SJason M. Bills } 1157d22c8396SJason M. Bills } 1158bfd5b826SLakshminarayana R. Kammath /** 1159bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1160bfd5b826SLakshminarayana R. Kammath */ 1161bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1162bfd5b826SLakshminarayana R. Kammath { 1163bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1164bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1165bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1166bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1167bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1168bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1169bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1170bfd5b826SLakshminarayana R. Kammath 1171bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1172bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1173bfd5b826SLakshminarayana R. Kammath if (ec) 1174bfd5b826SLakshminarayana R. Kammath { 1175bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1176bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1177bfd5b826SLakshminarayana R. Kammath return; 1178bfd5b826SLakshminarayana R. Kammath } 1179bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1180bfd5b826SLakshminarayana R. Kammath }, 1181bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1182bfd5b826SLakshminarayana R. Kammath } 1183cc340dd9SEd Tanous }; 1184cc340dd9SEd Tanous 1185cc340dd9SEd Tanous /** 11866617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1187c5b2abe0SLewanczyk, Dawid */ 11881abe55efSEd Tanous class Systems : public Node 11891abe55efSEd Tanous { 1190c5b2abe0SLewanczyk, Dawid public: 1191c5b2abe0SLewanczyk, Dawid /* 1192c5b2abe0SLewanczyk, Dawid * Default Constructor 1193c5b2abe0SLewanczyk, Dawid */ 1194029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 11951abe55efSEd Tanous { 1196c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1197c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1198c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1199c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1200c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1201c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1202c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1203c5b2abe0SLewanczyk, Dawid } 1204c5b2abe0SLewanczyk, Dawid 1205c5b2abe0SLewanczyk, Dawid private: 1206c5b2abe0SLewanczyk, Dawid /** 1207c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1208c5b2abe0SLewanczyk, Dawid */ 120955c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 12101abe55efSEd Tanous const std::vector<std::string> ¶ms) override 12111abe55efSEd Tanous { 1212491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 12130f74e643SEd Tanous res.jsonValue["@odata.context"] = 12140f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1215029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1216029573d4SEd Tanous res.jsonValue["Id"] = "system"; 12170f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 12180f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 12190f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 12200f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 12210f74e643SEd Tanous res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0); 12220f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1223029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 122404a258f4SEd Tanous 1225443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1226029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1227443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1228029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1229029573d4SEd Tanous 1230cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1231cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1232cc340dd9SEd Tanous {"target", 1233029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1234cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1235d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1236bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1237c5b2abe0SLewanczyk, Dawid 1238c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1239029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1240c4bf6374SJason M. Bills 1241c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1242c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1243c5d03ff4SJennifer Lee 1244c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1245c5d03ff4SJennifer Lee {"Health", "OK"}, 1246c5d03ff4SJennifer Lee {"State", "Enabled"}, 1247c5d03ff4SJennifer Lee }; 1248a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1249c5b2abe0SLewanczyk, Dawid 1250b49ac873SJames Feist constexpr const std::array<const char *, 2> inventoryForSystems = { 1251b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 1252b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu"}; 1253b49ac873SJames Feist 1254b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1255b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1256b49ac873SJames Feist [health](const boost::system::error_code ec, 1257b49ac873SJames Feist std::vector<std::string> &resp) { 1258b49ac873SJames Feist if (ec) 1259b49ac873SJames Feist { 1260b49ac873SJames Feist // no inventory 1261b49ac873SJames Feist return; 1262b49ac873SJames Feist } 1263b49ac873SJames Feist 1264b49ac873SJames Feist health->inventory = std::move(resp); 1265b49ac873SJames Feist }, 1266b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1267b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1268b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1269b49ac873SJames Feist int32_t(0), inventoryForSystems); 1270b49ac873SJames Feist 1271b49ac873SJames Feist health->populate(); 1272b49ac873SJames Feist 1273c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1274c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1275c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1276c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1277c5d03ff4SJennifer Lee }); 12786c34de48SEd Tanous getLedGroupIdentify( 1279a0803efaSEd Tanous asyncResp, 1280c5d03ff4SJennifer Lee [](const bool &asserted, const std::shared_ptr<AsyncResp> aRsp) { 12811abe55efSEd Tanous if (asserted) 12821abe55efSEd Tanous { 1283c5b2abe0SLewanczyk, Dawid // If led group is asserted, then another call is needed to 1284c5b2abe0SLewanczyk, Dawid // get led status 12856c34de48SEd Tanous getLedIdentify( 1286c5d03ff4SJennifer Lee aRsp, [](const std::string &ledStatus, 1287c5d03ff4SJennifer Lee const std::shared_ptr<AsyncResp> aRsp) { 12881abe55efSEd Tanous if (!ledStatus.empty()) 12891abe55efSEd Tanous { 1290c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = ledStatus; 1291c5b2abe0SLewanczyk, Dawid } 1292c5b2abe0SLewanczyk, Dawid }); 12931abe55efSEd Tanous } 12941abe55efSEd Tanous else 12951abe55efSEd Tanous { 1296c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = "Off"; 1297c5b2abe0SLewanczyk, Dawid } 1298c5b2abe0SLewanczyk, Dawid }); 1299029573d4SEd Tanous getComputerSystem(asyncResp); 13006c34de48SEd Tanous getHostState(asyncResp); 1301491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1302*f5c9f8bdSJason M. Bills getPCIeDeviceList(asyncResp); 1303c5b2abe0SLewanczyk, Dawid } 1304c5b2abe0SLewanczyk, Dawid 130555c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 13061abe55efSEd Tanous const std::vector<std::string> ¶ms) override 13071abe55efSEd Tanous { 1308cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1309491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1310491d8ee7SSantosh Puranik if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1311491d8ee7SSantosh Puranik bootProps)) 13126617338dSEd Tanous { 13136617338dSEd Tanous return; 13146617338dSEd Tanous } 1315491d8ee7SSantosh Puranik 1316029573d4SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1317d573bb2aSJennifer Lee asyncResp->res.result(boost::beast::http::status::no_content); 1318491d8ee7SSantosh Puranik 1319491d8ee7SSantosh Puranik if (bootProps) 1320491d8ee7SSantosh Puranik { 1321491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1322491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1323491d8ee7SSantosh Puranik 1324491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1325491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1326491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1327491d8ee7SSantosh Puranik { 1328491d8ee7SSantosh Puranik return; 1329491d8ee7SSantosh Puranik } 1330491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1331491d8ee7SSantosh Puranik std::move(bootEnable)); 1332491d8ee7SSantosh Puranik } 13339712f8acSEd Tanous if (indicatorLed) 13346617338dSEd Tanous { 13359712f8acSEd Tanous std::string dbusLedState; 1336d573bb2aSJennifer Lee if (*indicatorLed == "Lit") 13379712f8acSEd Tanous { 1338d573bb2aSJennifer Lee dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On"; 13396617338dSEd Tanous } 13405c6221acSGunnar Mills else if (*indicatorLed == "Blinking") 13416617338dSEd Tanous { 13425c6221acSGunnar Mills dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink"; 13436617338dSEd Tanous } 13449712f8acSEd Tanous else if (*indicatorLed == "Off") 13456617338dSEd Tanous { 13469712f8acSEd Tanous dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off"; 13476617338dSEd Tanous } 13486617338dSEd Tanous else 13496617338dSEd Tanous { 1350a08b46ccSJason M. Bills messages::propertyValueNotInList(res, *indicatorLed, 1351a08b46ccSJason M. Bills "IndicatorLED"); 13526617338dSEd Tanous return; 13536617338dSEd Tanous } 13546617338dSEd Tanous 1355c5b2abe0SLewanczyk, Dawid // Update led group 135655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led group."; 135755c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1358cde19e5fSSantosh Puranik [asyncResp](const boost::system::error_code ec) { 13591abe55efSEd Tanous if (ec) 13601abe55efSEd Tanous { 136155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1362f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1363c5b2abe0SLewanczyk, Dawid return; 1364c5b2abe0SLewanczyk, Dawid } 136555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led group update done."; 1366c5b2abe0SLewanczyk, Dawid }, 1367c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 1368c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/groups/enclosure_identify", 1369c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1370c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Group", "Asserted", 1371abf2add6SEd Tanous std::variant<bool>( 13726617338dSEd Tanous (dbusLedState == 13736617338dSEd Tanous "xyz.openbmc_project.Led.Physical.Action.Off" 13746617338dSEd Tanous ? false 13756617338dSEd Tanous : true))); 1376c5b2abe0SLewanczyk, Dawid // Update identify led status 137755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection."; 137855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 13796617338dSEd Tanous [asyncResp{std::move(asyncResp)}, 13809712f8acSEd Tanous indicatorLed{std::move(*indicatorLed)}]( 1381c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec) { 13821abe55efSEd Tanous if (ec) 13831abe55efSEd Tanous { 138455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1385f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1386c5b2abe0SLewanczyk, Dawid return; 1387c5b2abe0SLewanczyk, Dawid } 138855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led state update done."; 1389c5b2abe0SLewanczyk, Dawid }, 1390c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 1391c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 1392c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1393c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical", "State", 1394abf2add6SEd Tanous std::variant<std::string>(dbusLedState)); 13956617338dSEd Tanous } 1396c5b2abe0SLewanczyk, Dawid } 1397c5b2abe0SLewanczyk, Dawid }; 1398c5b2abe0SLewanczyk, Dawid } // namespace redfish 1399