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 189712f8acSEd Tanous #include <boost/container/flat_map.hpp> 199712f8acSEd Tanous #include <node.hpp> 20cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 21c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 22abf2add6SEd Tanous #include <variant> 23c5b2abe0SLewanczyk, Dawid 241abe55efSEd Tanous namespace redfish 251abe55efSEd Tanous { 26c5b2abe0SLewanczyk, Dawid 27c5b2abe0SLewanczyk, Dawid /** 28c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 29c5b2abe0SLewanczyk, Dawid * 30c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 31c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 32c5b2abe0SLewanczyk, Dawid * 33c5b2abe0SLewanczyk, Dawid * @return None. 34c5b2abe0SLewanczyk, Dawid */ 35029573d4SEd Tanous void getComputerSystem(std::shared_ptr<AsyncResp> aResp) 361abe55efSEd Tanous { 3755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 3855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 39029573d4SEd Tanous [aResp{std::move(aResp)}]( 40c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 41c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 426c34de48SEd Tanous std::string, 436c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 44c5b2abe0SLewanczyk, Dawid &subtree) { 451abe55efSEd Tanous if (ec) 461abe55efSEd Tanous { 4755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 48f12894f8SJason M. Bills messages::internalError(aResp->res); 49c5b2abe0SLewanczyk, Dawid return; 50c5b2abe0SLewanczyk, Dawid } 51c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 526c34de48SEd Tanous for (const std::pair<std::string, 536c34de48SEd Tanous std::vector<std::pair< 546c34de48SEd Tanous std::string, std::vector<std::string>>>> 551abe55efSEd Tanous &object : subtree) 561abe55efSEd Tanous { 57c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 5855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 591abe55efSEd Tanous const std::vector< 601abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 61c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 621abe55efSEd Tanous if (connectionNames.size() < 1) 631abe55efSEd Tanous { 64c5b2abe0SLewanczyk, Dawid continue; 65c5b2abe0SLewanczyk, Dawid } 66029573d4SEd Tanous 676c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 686c34de48SEd Tanous // BiosVer 6904a258f4SEd Tanous for (const auto &connection : connectionNames) 701abe55efSEd Tanous { 7104a258f4SEd Tanous for (const auto &interfaceName : connection.second) 721abe55efSEd Tanous { 7304a258f4SEd Tanous if (interfaceName == 7404a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 751abe55efSEd Tanous { 761abe55efSEd Tanous BMCWEB_LOG_DEBUG 7704a258f4SEd Tanous << "Found Dimm, now get its properties."; 7855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 79029573d4SEd Tanous [aResp](const boost::system::error_code ec, 806c34de48SEd Tanous const std::vector< 816c34de48SEd Tanous std::pair<std::string, VariantType>> 821abe55efSEd Tanous &properties) { 831abe55efSEd Tanous if (ec) 841abe55efSEd Tanous { 851abe55efSEd Tanous BMCWEB_LOG_ERROR 866c34de48SEd Tanous << "DBUS response error " << ec; 87f12894f8SJason M. Bills messages::internalError(aResp->res); 88c5b2abe0SLewanczyk, Dawid return; 89c5b2abe0SLewanczyk, Dawid } 906c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 916c34de48SEd Tanous << properties.size() 92c5b2abe0SLewanczyk, Dawid << "Dimm properties."; 9304a258f4SEd Tanous for (const std::pair<std::string, 9404a258f4SEd Tanous VariantType> 9504a258f4SEd Tanous &property : properties) 961abe55efSEd Tanous { 97029573d4SEd Tanous if (property.first == "MemorySizeInKb") 981abe55efSEd Tanous { 9904a258f4SEd Tanous const uint64_t *value = 100029573d4SEd Tanous sdbusplus::message::variant_ns:: 101029573d4SEd Tanous get_if<uint64_t>( 1021b6b96c5SEd Tanous &property.second); 10304a258f4SEd Tanous if (value != nullptr) 1041abe55efSEd Tanous { 1051abe55efSEd Tanous aResp->res.jsonValue 1066c34de48SEd Tanous ["TotalSystemMemoryGi" 1076c34de48SEd Tanous "B"] += 10804a258f4SEd Tanous *value / (1024 * 1024); 109029573d4SEd Tanous aResp->res 110029573d4SEd Tanous .jsonValue["MemorySummary"] 111029573d4SEd Tanous ["Status"] 112029573d4SEd Tanous ["State"] = 1131abe55efSEd Tanous "Enabled"; 114c5b2abe0SLewanczyk, Dawid } 115c5b2abe0SLewanczyk, Dawid } 116c5b2abe0SLewanczyk, Dawid } 117c5b2abe0SLewanczyk, Dawid }, 11804a258f4SEd Tanous connection.first, path, 1196c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 1206c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 1211abe55efSEd Tanous } 12204a258f4SEd Tanous else if (interfaceName == 12304a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 1241abe55efSEd Tanous { 1251abe55efSEd Tanous BMCWEB_LOG_DEBUG 12604a258f4SEd Tanous << "Found Cpu, now get its properties."; 127a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 128029573d4SEd Tanous [aResp](const boost::system::error_code ec, 1296c34de48SEd Tanous const std::vector< 1306c34de48SEd Tanous std::pair<std::string, VariantType>> 1311abe55efSEd Tanous &properties) { 1321abe55efSEd Tanous if (ec) 1331abe55efSEd Tanous { 1341abe55efSEd Tanous BMCWEB_LOG_ERROR 1356c34de48SEd Tanous << "DBUS response error " << ec; 136f12894f8SJason M. Bills messages::internalError(aResp->res); 137c5b2abe0SLewanczyk, Dawid return; 138c5b2abe0SLewanczyk, Dawid } 1396c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 1406c34de48SEd Tanous << properties.size() 141c5b2abe0SLewanczyk, Dawid << "Cpu properties."; 14204a258f4SEd Tanous for (const auto &property : properties) 1431abe55efSEd Tanous { 144029573d4SEd Tanous if (property.first == "ProcessorFamily") 1451abe55efSEd Tanous { 146a0803efaSEd Tanous const std::string *value = 147029573d4SEd Tanous sdbusplus::message::variant_ns:: 148029573d4SEd Tanous get_if<std::string>( 1491b6b96c5SEd Tanous &property.second); 1501abe55efSEd Tanous if (value != nullptr) 1511abe55efSEd Tanous { 152029573d4SEd Tanous nlohmann::json &procSummary = 1531abe55efSEd Tanous aResp->res.jsonValue 1546c34de48SEd Tanous ["ProcessorSumm" 15504a258f4SEd Tanous "ary"]; 15604a258f4SEd Tanous nlohmann::json &procCount = 15704a258f4SEd Tanous procSummary["Count"]; 15804a258f4SEd Tanous 15904a258f4SEd Tanous procCount = 160029573d4SEd Tanous procCount.get<int>() + 1; 161029573d4SEd Tanous procSummary["Status"]["State"] = 162c5b2abe0SLewanczyk, Dawid "Enabled"; 163029573d4SEd Tanous procSummary["Model"] = *value; 164c5b2abe0SLewanczyk, Dawid } 165c5b2abe0SLewanczyk, Dawid } 166c5b2abe0SLewanczyk, Dawid } 167c5b2abe0SLewanczyk, Dawid }, 16804a258f4SEd Tanous connection.first, path, 1696c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 1706c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 1711abe55efSEd Tanous } 17204a258f4SEd Tanous else if (interfaceName == 17304a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 1741abe55efSEd Tanous { 1751abe55efSEd Tanous BMCWEB_LOG_DEBUG 17604a258f4SEd Tanous << "Found UUID, now get its properties."; 17755c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 178029573d4SEd Tanous [aResp](const boost::system::error_code ec, 1796c34de48SEd Tanous const std::vector< 1806c34de48SEd Tanous std::pair<std::string, VariantType>> 1811abe55efSEd Tanous &properties) { 1821abe55efSEd Tanous if (ec) 1831abe55efSEd Tanous { 1841abe55efSEd Tanous BMCWEB_LOG_DEBUG 1856c34de48SEd Tanous << "DBUS response error " << ec; 186f12894f8SJason M. Bills messages::internalError(aResp->res); 187c5b2abe0SLewanczyk, Dawid return; 188c5b2abe0SLewanczyk, Dawid } 1896c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 1906c34de48SEd Tanous << properties.size() 191c5b2abe0SLewanczyk, Dawid << "UUID properties."; 1921abe55efSEd Tanous for (const std::pair<std::string, 19304a258f4SEd Tanous VariantType> 19404a258f4SEd Tanous &property : properties) 1951abe55efSEd Tanous { 19604a258f4SEd Tanous if (property.first == "UUID") 1971abe55efSEd Tanous { 198c5b2abe0SLewanczyk, Dawid const std::string *value = 199029573d4SEd Tanous sdbusplus::message::variant_ns:: 200029573d4SEd Tanous get_if<std::string>( 2011b6b96c5SEd Tanous &property.second); 20204a258f4SEd Tanous 2031abe55efSEd Tanous if (value != nullptr) 2041abe55efSEd Tanous { 205029573d4SEd Tanous std::string valueStr = *value; 20604a258f4SEd Tanous if (valueStr.size() == 32) 2071abe55efSEd Tanous { 208029573d4SEd Tanous valueStr.insert(8, 1, '-'); 209029573d4SEd Tanous valueStr.insert(13, 1, '-'); 210029573d4SEd Tanous valueStr.insert(18, 1, '-'); 211029573d4SEd Tanous valueStr.insert(23, 1, '-'); 21204a258f4SEd Tanous } 213029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 21404a258f4SEd Tanous << valueStr; 215029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 21604a258f4SEd Tanous valueStr; 217c5b2abe0SLewanczyk, Dawid } 218c5b2abe0SLewanczyk, Dawid } 219c5b2abe0SLewanczyk, Dawid } 220c5b2abe0SLewanczyk, Dawid }, 22104a258f4SEd Tanous connection.first, path, 2226c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2231abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 224c5b2abe0SLewanczyk, Dawid } 225029573d4SEd Tanous else if (interfaceName == 226029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 2271abe55efSEd Tanous { 228029573d4SEd Tanous crow::connections::systemBus->async_method_call( 229029573d4SEd Tanous [aResp](const boost::system::error_code ec, 230029573d4SEd Tanous const std::vector< 231029573d4SEd Tanous std::pair<std::string, VariantType>> 232029573d4SEd Tanous &propertiesList) { 233029573d4SEd Tanous if (ec) 234029573d4SEd Tanous { 235029573d4SEd Tanous BMCWEB_LOG_ERROR 236029573d4SEd Tanous << "DBUS response error: " << ec; 237f12894f8SJason M. Bills messages::internalError(aResp->res); 238029573d4SEd Tanous return; 239029573d4SEd Tanous } 240029573d4SEd Tanous BMCWEB_LOG_DEBUG << "Got " 241029573d4SEd Tanous << propertiesList.size() 242029573d4SEd Tanous << "properties for system"; 243029573d4SEd Tanous for (const std::pair<std::string, 244029573d4SEd Tanous VariantType> 245029573d4SEd Tanous &property : propertiesList) 246029573d4SEd Tanous { 247fc5afcf9Sbeccabroek const std::string &propertyName = 248fc5afcf9Sbeccabroek property.first; 249fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 250fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 251fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 252fc5afcf9Sbeccabroek (propertyName == "Model")) 253fc5afcf9Sbeccabroek { 254029573d4SEd Tanous const std::string *value = 255fc5afcf9Sbeccabroek std::get_if<std::string>( 256029573d4SEd Tanous &property.second); 257029573d4SEd Tanous if (value != nullptr) 258029573d4SEd Tanous { 259029573d4SEd Tanous aResp->res 260fc5afcf9Sbeccabroek .jsonValue[propertyName] = 261029573d4SEd Tanous *value; 262029573d4SEd Tanous } 263029573d4SEd Tanous } 264fc5afcf9Sbeccabroek } 265029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 266029573d4SEd Tanous aResp->res.jsonValue["Id"] = 267029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 268cb7e1e7bSAndrew Geissler // Grab the bios version 269cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 270cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 271cb7e1e7bSAndrew Geissler "BiosVersion"); 272029573d4SEd Tanous }, 273029573d4SEd Tanous connection.first, path, 274029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 275029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 276029573d4SEd Tanous "Asset"); 277029573d4SEd Tanous } 278029573d4SEd Tanous } 279029573d4SEd Tanous } 280c5b2abe0SLewanczyk, Dawid } 281c5b2abe0SLewanczyk, Dawid }, 282c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 283c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 284c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 2856617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 2866617338dSEd Tanous std::array<const char *, 5>{ 2876617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 2886617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 2896617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 2906617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 2916617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 2926617338dSEd Tanous }); 293c5b2abe0SLewanczyk, Dawid } 294c5b2abe0SLewanczyk, Dawid 295c5b2abe0SLewanczyk, Dawid /** 296c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 297c5b2abe0SLewanczyk, Dawid * 298491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 299c5b2abe0SLewanczyk, Dawid * @param[in] callback Callback for process retrieved data. 300c5b2abe0SLewanczyk, Dawid * 301c5b2abe0SLewanczyk, Dawid * @return None. 302c5b2abe0SLewanczyk, Dawid */ 303c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 304a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp, 3051abe55efSEd Tanous CallbackFunc &&callback) 3061abe55efSEd Tanous { 30755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 30855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 3091abe55efSEd Tanous [aResp{std::move(aResp)}, 3106617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code &ec, 3111abe55efSEd Tanous const ManagedObjectsType &resp) { 3121abe55efSEd Tanous if (ec) 3131abe55efSEd Tanous { 31455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 315f12894f8SJason M. Bills messages::internalError(aResp->res); 316c5b2abe0SLewanczyk, Dawid return; 317c5b2abe0SLewanczyk, Dawid } 3186c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects."; 3191abe55efSEd Tanous for (const auto &objPath : resp) 3201abe55efSEd Tanous { 321c5b2abe0SLewanczyk, Dawid const std::string &path = objPath.first; 3221abe55efSEd Tanous if (path.rfind("enclosure_identify") != std::string::npos) 3231abe55efSEd Tanous { 3241abe55efSEd Tanous for (const auto &interface : objPath.second) 3251abe55efSEd Tanous { 3266c34de48SEd Tanous if (interface.first == "xyz.openbmc_project.Led.Group") 3271abe55efSEd Tanous { 3281abe55efSEd Tanous for (const auto &property : interface.second) 3291abe55efSEd Tanous { 3301abe55efSEd Tanous if (property.first == "Asserted") 3311abe55efSEd Tanous { 332c5b2abe0SLewanczyk, Dawid const bool *asserted = 333abf2add6SEd Tanous std::get_if<bool>(&property.second); 3341abe55efSEd Tanous if (nullptr != asserted) 3351abe55efSEd Tanous { 336c5b2abe0SLewanczyk, Dawid callback(*asserted, aResp); 3371abe55efSEd Tanous } 3381abe55efSEd Tanous else 3391abe55efSEd Tanous { 340c5b2abe0SLewanczyk, Dawid callback(false, aResp); 341c5b2abe0SLewanczyk, Dawid } 342c5b2abe0SLewanczyk, Dawid } 343c5b2abe0SLewanczyk, Dawid } 344c5b2abe0SLewanczyk, Dawid } 345c5b2abe0SLewanczyk, Dawid } 346c5b2abe0SLewanczyk, Dawid } 347c5b2abe0SLewanczyk, Dawid } 348c5b2abe0SLewanczyk, Dawid }, 349c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 3506c34de48SEd Tanous "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager", 3516c34de48SEd Tanous "GetManagedObjects"); 352c5b2abe0SLewanczyk, Dawid } 353c5b2abe0SLewanczyk, Dawid 354c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 3556c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback) 3561abe55efSEd Tanous { 35755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get identify led properties"; 35855c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 3596617338dSEd Tanous [aResp, 3606617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code ec, 361c5b2abe0SLewanczyk, Dawid const PropertiesType &properties) { 3621abe55efSEd Tanous if (ec) 3631abe55efSEd Tanous { 36455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 365f12894f8SJason M. Bills messages::internalError(aResp->res); 366c5b2abe0SLewanczyk, Dawid return; 367c5b2abe0SLewanczyk, Dawid } 3681abe55efSEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 3691abe55efSEd Tanous << "led properties."; 370c5b2abe0SLewanczyk, Dawid std::string output; 3711abe55efSEd Tanous for (const auto &property : properties) 3721abe55efSEd Tanous { 3731abe55efSEd Tanous if (property.first == "State") 3741abe55efSEd Tanous { 375c5b2abe0SLewanczyk, Dawid const std::string *s = 376abf2add6SEd Tanous std::get_if<std::string>(&property.second); 3771abe55efSEd Tanous if (nullptr != s) 3781abe55efSEd Tanous { 37955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Identify Led State: " << *s; 380c5b2abe0SLewanczyk, Dawid const auto pos = s->rfind('.'); 3811abe55efSEd Tanous if (pos != std::string::npos) 3821abe55efSEd Tanous { 383c5b2abe0SLewanczyk, Dawid auto led = s->substr(pos + 1); 3841abe55efSEd Tanous for (const std::pair<const char *, const char *> 3851abe55efSEd Tanous &p : 3861abe55efSEd Tanous std::array< 3876c34de48SEd Tanous std::pair<const char *, const char *>, 3>{ 3886c34de48SEd Tanous {{"On", "Lit"}, 389c5b2abe0SLewanczyk, Dawid {"Blink", "Blinking"}, 3901abe55efSEd Tanous {"Off", "Off"}}}) 3911abe55efSEd Tanous { 3921abe55efSEd Tanous if (led == p.first) 3931abe55efSEd Tanous { 394c5b2abe0SLewanczyk, Dawid output = p.second; 395c5b2abe0SLewanczyk, Dawid } 396c5b2abe0SLewanczyk, Dawid } 397c5b2abe0SLewanczyk, Dawid } 398c5b2abe0SLewanczyk, Dawid } 399c5b2abe0SLewanczyk, Dawid } 400c5b2abe0SLewanczyk, Dawid } 401c5b2abe0SLewanczyk, Dawid callback(output, aResp); 402c5b2abe0SLewanczyk, Dawid }, 403c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 404c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 405c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "GetAll", 406c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical"); 407c5b2abe0SLewanczyk, Dawid } 408c5b2abe0SLewanczyk, Dawid 409c5b2abe0SLewanczyk, Dawid /** 410c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 411c5b2abe0SLewanczyk, Dawid * 412c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 413c5b2abe0SLewanczyk, Dawid * 414c5b2abe0SLewanczyk, Dawid * @return None. 415c5b2abe0SLewanczyk, Dawid */ 416a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 4171abe55efSEd Tanous { 41855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 41955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 420abf2add6SEd Tanous [aResp{std::move(aResp)}](const boost::system::error_code ec, 421abf2add6SEd Tanous const std::variant<std::string> &hostState) { 4221abe55efSEd Tanous if (ec) 4231abe55efSEd Tanous { 42455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 425f12894f8SJason M. Bills messages::internalError(aResp->res); 426c5b2abe0SLewanczyk, Dawid return; 427c5b2abe0SLewanczyk, Dawid } 4286617338dSEd Tanous 429abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 43055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 4316617338dSEd Tanous if (s != nullptr) 4321abe55efSEd Tanous { 433c5b2abe0SLewanczyk, Dawid // Verify Host State 43494732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 4351abe55efSEd Tanous { 43655c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 4376617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 4381abe55efSEd Tanous } 4391abe55efSEd Tanous else 4401abe55efSEd Tanous { 44155c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 4426617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 443c5b2abe0SLewanczyk, Dawid } 444c5b2abe0SLewanczyk, Dawid } 445c5b2abe0SLewanczyk, Dawid }, 4466c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 4476617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 4486617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 449c5b2abe0SLewanczyk, Dawid } 450c5b2abe0SLewanczyk, Dawid 451c5b2abe0SLewanczyk, Dawid /** 452491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 453491d8ee7SSantosh Puranik * 454491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 455491d8ee7SSantosh Puranik * 456491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 457491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 458491d8ee7SSantosh Puranik */ 459491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 460491d8ee7SSantosh Puranik { 461491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 462491d8ee7SSantosh Puranik { 463491d8ee7SSantosh Puranik return "None"; 464491d8ee7SSantosh Puranik } 465491d8ee7SSantosh Puranik else if (dbusSource == 466491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 467491d8ee7SSantosh Puranik { 468491d8ee7SSantosh Puranik return "Hdd"; 469491d8ee7SSantosh Puranik } 470491d8ee7SSantosh Puranik else if (dbusSource == 471*a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 472491d8ee7SSantosh Puranik { 473491d8ee7SSantosh Puranik return "Cd"; 474491d8ee7SSantosh Puranik } 475491d8ee7SSantosh Puranik else if (dbusSource == 476491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 477491d8ee7SSantosh Puranik { 478491d8ee7SSantosh Puranik return "Pxe"; 479491d8ee7SSantosh Puranik } 4809f16b2c1SJennifer Lee else if (dbusSource == 4819f16b2c1SJennifer Lee "xyz.openbmc_project.Control.Boot.Source.Sources.Removable") 4829f16b2c1SJennifer Lee { 4839f16b2c1SJennifer Lee return "Usb"; 4849f16b2c1SJennifer Lee } 485491d8ee7SSantosh Puranik else 486491d8ee7SSantosh Puranik { 487491d8ee7SSantosh Puranik return ""; 488491d8ee7SSantosh Puranik } 489491d8ee7SSantosh Puranik } 490491d8ee7SSantosh Puranik 491491d8ee7SSantosh Puranik /** 492491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 493491d8ee7SSantosh Puranik * 494491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 495491d8ee7SSantosh Puranik * 496491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 497491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 498491d8ee7SSantosh Puranik */ 499491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 500491d8ee7SSantosh Puranik { 501491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 502491d8ee7SSantosh Puranik { 503491d8ee7SSantosh Puranik return "None"; 504491d8ee7SSantosh Puranik } 505491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 506491d8ee7SSantosh Puranik { 507491d8ee7SSantosh Puranik return "Diags"; 508491d8ee7SSantosh Puranik } 509491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 510491d8ee7SSantosh Puranik { 511491d8ee7SSantosh Puranik return "BiosSetup"; 512491d8ee7SSantosh Puranik } 513491d8ee7SSantosh Puranik else 514491d8ee7SSantosh Puranik { 515491d8ee7SSantosh Puranik return ""; 516491d8ee7SSantosh Puranik } 517491d8ee7SSantosh Puranik } 518491d8ee7SSantosh Puranik 519491d8ee7SSantosh Puranik /** 520491d8ee7SSantosh Puranik * @brief Traslates boot source from Redfish to DBUS property value. 521491d8ee7SSantosh Puranik * 522491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 523491d8ee7SSantosh Puranik * 524491d8ee7SSantosh Puranik * @return Returns as a string, the boot source as expected by DBUS. 525491d8ee7SSantosh Puranik * If translation cannot be done, returns an empty string. 526491d8ee7SSantosh Puranik */ 527491d8ee7SSantosh Puranik static std::string rfToDbusBootSource(const std::string &rfSource) 528491d8ee7SSantosh Puranik { 529491d8ee7SSantosh Puranik if (rfSource == "None") 530491d8ee7SSantosh Puranik { 531491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 532491d8ee7SSantosh Puranik } 533491d8ee7SSantosh Puranik else if (rfSource == "Hdd") 534491d8ee7SSantosh Puranik { 535491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 536491d8ee7SSantosh Puranik } 537491d8ee7SSantosh Puranik else if (rfSource == "Cd") 538491d8ee7SSantosh Puranik { 539*a71dc0b7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 540491d8ee7SSantosh Puranik } 541491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 542491d8ee7SSantosh Puranik { 543491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 544491d8ee7SSantosh Puranik } 5459f16b2c1SJennifer Lee else if (rfSource == "Usb") 5469f16b2c1SJennifer Lee { 5479f16b2c1SJennifer Lee return "xyz.openbmc_project.Control.Boot.Source.Sources.Removable"; 5489f16b2c1SJennifer Lee } 549491d8ee7SSantosh Puranik else 550491d8ee7SSantosh Puranik { 551491d8ee7SSantosh Puranik return ""; 552491d8ee7SSantosh Puranik } 553491d8ee7SSantosh Puranik } 554491d8ee7SSantosh Puranik 555491d8ee7SSantosh Puranik /** 556491d8ee7SSantosh Puranik * @brief Traslates boot mode from Redfish to DBUS property value. 557491d8ee7SSantosh Puranik * 558491d8ee7SSantosh Puranik * @param[in] rfMode The boot mode in Redfish. 559491d8ee7SSantosh Puranik * 560491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode as expected by DBUS. 561491d8ee7SSantosh Puranik * If translation cannot be done, returns an empty string. 562491d8ee7SSantosh Puranik */ 563491d8ee7SSantosh Puranik static std::string rfToDbusBootMode(const std::string &rfMode) 564491d8ee7SSantosh Puranik { 565491d8ee7SSantosh Puranik if (rfMode == "None") 566491d8ee7SSantosh Puranik { 567491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 568491d8ee7SSantosh Puranik } 569491d8ee7SSantosh Puranik else if (rfMode == "Diags") 570491d8ee7SSantosh Puranik { 571491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 572491d8ee7SSantosh Puranik } 573491d8ee7SSantosh Puranik else if (rfMode == "BiosSetup") 574491d8ee7SSantosh Puranik { 575491d8ee7SSantosh Puranik return "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 576491d8ee7SSantosh Puranik } 577491d8ee7SSantosh Puranik else 578491d8ee7SSantosh Puranik { 579491d8ee7SSantosh Puranik return ""; 580491d8ee7SSantosh Puranik } 581491d8ee7SSantosh Puranik } 582491d8ee7SSantosh Puranik 583491d8ee7SSantosh Puranik /** 584491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 585491d8ee7SSantosh Puranik * 586491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 587491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 588491d8ee7SSantosh Puranik * 589491d8ee7SSantosh Puranik * @return None. 590491d8ee7SSantosh Puranik */ 591491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 592491d8ee7SSantosh Puranik std::string bootDbusObj) 593491d8ee7SSantosh Puranik { 594491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 595491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 596491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 597491d8ee7SSantosh Puranik if (ec) 598491d8ee7SSantosh Puranik { 599491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 600491d8ee7SSantosh Puranik messages::internalError(aResp->res); 601491d8ee7SSantosh Puranik return; 602491d8ee7SSantosh Puranik } 603491d8ee7SSantosh Puranik 604491d8ee7SSantosh Puranik const std::string *bootModeStr = 605491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 606491d8ee7SSantosh Puranik 607491d8ee7SSantosh Puranik if (!bootModeStr) 608491d8ee7SSantosh Puranik { 609491d8ee7SSantosh Puranik messages::internalError(aResp->res); 610491d8ee7SSantosh Puranik return; 611491d8ee7SSantosh Puranik } 612491d8ee7SSantosh Puranik 613491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 614491d8ee7SSantosh Puranik 615491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 616491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 617491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 618491d8ee7SSantosh Puranik "AllowableValues"] = { 619491d8ee7SSantosh Puranik "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup"}; 620491d8ee7SSantosh Puranik 621491d8ee7SSantosh Puranik if (*bootModeStr != 622491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 623491d8ee7SSantosh Puranik { 624491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 625491d8ee7SSantosh Puranik if (!rfMode.empty()) 626491d8ee7SSantosh Puranik { 627491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 628491d8ee7SSantosh Puranik rfMode; 629491d8ee7SSantosh Puranik } 630491d8ee7SSantosh Puranik } 631491d8ee7SSantosh Puranik 632491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 633491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 634491d8ee7SSantosh Puranik // overrides are disabled 635491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 636491d8ee7SSantosh Puranik "None") 637491d8ee7SSantosh Puranik { 638491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 639491d8ee7SSantosh Puranik "Disabled"; 640491d8ee7SSantosh Puranik } 641491d8ee7SSantosh Puranik }, 642491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 643491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 644491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 645491d8ee7SSantosh Puranik } 646491d8ee7SSantosh Puranik 647491d8ee7SSantosh Puranik /** 648491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 649491d8ee7SSantosh Puranik * 650491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 651491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 652491d8ee7SSantosh Puranik * 653491d8ee7SSantosh Puranik * @return None. 654491d8ee7SSantosh Puranik */ 655491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 656491d8ee7SSantosh Puranik { 657491d8ee7SSantosh Puranik std::string bootDbusObj = 658491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 659491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 660491d8ee7SSantosh Puranik 661491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 662491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 663491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 664491d8ee7SSantosh Puranik 665491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 666491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 667491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 668491d8ee7SSantosh Puranik if (ec) 669491d8ee7SSantosh Puranik { 670491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 671491d8ee7SSantosh Puranik messages::internalError(aResp->res); 672491d8ee7SSantosh Puranik return; 673491d8ee7SSantosh Puranik } 674491d8ee7SSantosh Puranik 675491d8ee7SSantosh Puranik const std::string *bootSourceStr = 676491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 677491d8ee7SSantosh Puranik 678491d8ee7SSantosh Puranik if (!bootSourceStr) 679491d8ee7SSantosh Puranik { 680491d8ee7SSantosh Puranik messages::internalError(aResp->res); 681491d8ee7SSantosh Puranik return; 682491d8ee7SSantosh Puranik } 683491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 684491d8ee7SSantosh Puranik 685491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 686491d8ee7SSantosh Puranik if (!rfSource.empty()) 687491d8ee7SSantosh Puranik { 688491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 689491d8ee7SSantosh Puranik rfSource; 690491d8ee7SSantosh Puranik } 691491d8ee7SSantosh Puranik }, 692491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 693491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 694491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 695491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 696491d8ee7SSantosh Puranik } 697491d8ee7SSantosh Puranik 698491d8ee7SSantosh Puranik /** 699491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 700491d8ee7SSantosh Puranik * get boot source and boot mode. 701491d8ee7SSantosh Puranik * 702491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 703491d8ee7SSantosh Puranik * 704491d8ee7SSantosh Puranik * @return None. 705491d8ee7SSantosh Puranik */ 706491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 707491d8ee7SSantosh Puranik { 708491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 709491d8ee7SSantosh Puranik 710491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 711491d8ee7SSantosh Puranik [aResp{std::move(aResp)}]( 712491d8ee7SSantosh Puranik const boost::system::error_code ec, 713491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 714491d8ee7SSantosh Puranik if (ec) 715491d8ee7SSantosh Puranik { 716491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 717491d8ee7SSantosh Puranik messages::internalError(aResp->res); 718491d8ee7SSantosh Puranik return; 719491d8ee7SSantosh Puranik } 720491d8ee7SSantosh Puranik 721491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 722491d8ee7SSantosh Puranik 723491d8ee7SSantosh Puranik if (!oneTimePtr) 724491d8ee7SSantosh Puranik { 725491d8ee7SSantosh Puranik messages::internalError(aResp->res); 726491d8ee7SSantosh Puranik return; 727491d8ee7SSantosh Puranik } 728491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 729491d8ee7SSantosh Puranik }, 730491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 731491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 732491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 733491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 734491d8ee7SSantosh Puranik } 735491d8ee7SSantosh Puranik 736491d8ee7SSantosh Puranik /** 737491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 738491d8ee7SSantosh Puranik * 739491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 740491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 741491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 742491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 743491d8ee7SSantosh Puranik * 744491d8ee7SSantosh Puranik * @return None. 745491d8ee7SSantosh Puranik */ 746491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 747491d8ee7SSantosh Puranik bool oneTimeEnabled, 748491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 749491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 750491d8ee7SSantosh Puranik { 751491d8ee7SSantosh Puranik if (bootEnable && (bootEnable != "Once") && (bootEnable != "Continuous") && 752491d8ee7SSantosh Puranik (bootEnable != "Disabled")) 753491d8ee7SSantosh Puranik { 754491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for BootSourceOverrideEnabled: " 755491d8ee7SSantosh Puranik << *bootEnable; 756491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 757491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 758491d8ee7SSantosh Puranik return; 759491d8ee7SSantosh Puranik } 760491d8ee7SSantosh Puranik 761491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 762491d8ee7SSantosh Puranik // Validate incoming parameters 763491d8ee7SSantosh Puranik if (bootEnable) 764491d8ee7SSantosh Puranik { 765491d8ee7SSantosh Puranik if (*bootEnable == "Once") 766491d8ee7SSantosh Puranik { 767491d8ee7SSantosh Puranik oneTimeSetting = true; 768491d8ee7SSantosh Puranik } 769491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 770491d8ee7SSantosh Puranik { 771491d8ee7SSantosh Puranik oneTimeSetting = false; 772491d8ee7SSantosh Puranik } 773491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 774491d8ee7SSantosh Puranik { 775491d8ee7SSantosh Puranik oneTimeSetting = false; 776491d8ee7SSantosh Puranik } 777491d8ee7SSantosh Puranik else 778491d8ee7SSantosh Puranik { 779491d8ee7SSantosh Puranik 780491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 781491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 782491d8ee7SSantosh Puranik << *bootEnable; 783491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 784491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 785491d8ee7SSantosh Puranik return; 786491d8ee7SSantosh Puranik } 787491d8ee7SSantosh Puranik } 788491d8ee7SSantosh Puranik std::string bootSourceStr; 789491d8ee7SSantosh Puranik std::string bootModeStr; 790491d8ee7SSantosh Puranik if (bootSource) 791491d8ee7SSantosh Puranik { 792491d8ee7SSantosh Puranik bootSourceStr = rfToDbusBootSource(*bootSource); 793491d8ee7SSantosh Puranik bootModeStr = rfToDbusBootMode(*bootSource); 794491d8ee7SSantosh Puranik 795491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 796491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 797491d8ee7SSantosh Puranik 798491d8ee7SSantosh Puranik if (bootSourceStr.empty() && bootModeStr.empty()) 799491d8ee7SSantosh Puranik { 800491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Invalid property value for " 801491d8ee7SSantosh Puranik "BootSourceOverrideTarget: " 802491d8ee7SSantosh Puranik << *bootSource; 803491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 804491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 805491d8ee7SSantosh Puranik return; 806491d8ee7SSantosh Puranik } 807491d8ee7SSantosh Puranik } 808491d8ee7SSantosh Puranik const char *bootObj = 809491d8ee7SSantosh Puranik oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 810491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 811491d8ee7SSantosh Puranik // Figure out what properties to set 812491d8ee7SSantosh Puranik if (bootEnable && (*bootEnable == "Disabled")) 813491d8ee7SSantosh Puranik { 814491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 815491d8ee7SSantosh Puranik // Request to only turn OFF/ON enabled, if turning enabled OFF, need 816491d8ee7SSantosh Puranik // to reset the source and mode too. If turning it ON, we only need 817491d8ee7SSantosh Puranik // to set the enabled property 818491d8ee7SSantosh Puranik bootSourceStr = 819491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 820491d8ee7SSantosh Puranik bootModeStr = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 821491d8ee7SSantosh Puranik } 822491d8ee7SSantosh Puranik else if (bootSource) 823491d8ee7SSantosh Puranik { 824491d8ee7SSantosh Puranik // Source target specified 825491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 826491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 827491d8ee7SSantosh Puranik bootSourceStr = rfToDbusBootSource(*bootSource); 828491d8ee7SSantosh Puranik bootModeStr = rfToDbusBootMode(*bootSource); 829491d8ee7SSantosh Puranik 830491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 831491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 832491d8ee7SSantosh Puranik 833491d8ee7SSantosh Puranik if (bootSourceStr.empty() && bootModeStr.empty()) 834491d8ee7SSantosh Puranik { 835491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Invalid property value for " 836491d8ee7SSantosh Puranik "BootSourceOverrideTarget: " 837491d8ee7SSantosh Puranik << *bootSource; 838491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 839491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 840491d8ee7SSantosh Puranik return; 841491d8ee7SSantosh Puranik } 842491d8ee7SSantosh Puranik 843491d8ee7SSantosh Puranik if (!bootSourceStr.empty()) 844491d8ee7SSantosh Puranik { 845491d8ee7SSantosh Puranik // If setting to anything other than default, also reset boot 846491d8ee7SSantosh Puranik // mode property 847491d8ee7SSantosh Puranik if (bootSourceStr != 848491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 849491d8ee7SSantosh Puranik { 850491d8ee7SSantosh Puranik bootModeStr = 851491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 852491d8ee7SSantosh Puranik } 853491d8ee7SSantosh Puranik } 854491d8ee7SSantosh Puranik else // if (!bootModeStr.empty()) 855491d8ee7SSantosh Puranik { 856491d8ee7SSantosh Puranik // If setting to anything other than default, also reset boot 857491d8ee7SSantosh Puranik // source property 858491d8ee7SSantosh Puranik if (bootModeStr != 859491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 860491d8ee7SSantosh Puranik { 861491d8ee7SSantosh Puranik bootSourceStr = 862491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 863491d8ee7SSantosh Puranik } 864491d8ee7SSantosh Puranik } 865491d8ee7SSantosh Puranik } 866491d8ee7SSantosh Puranik if (!bootSourceStr.empty()) 867491d8ee7SSantosh Puranik { 868491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 869491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 870491d8ee7SSantosh Puranik if (ec) 871491d8ee7SSantosh Puranik { 872491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 873491d8ee7SSantosh Puranik messages::internalError(aResp->res); 874491d8ee7SSantosh Puranik return; 875491d8ee7SSantosh Puranik } 876491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 877491d8ee7SSantosh Puranik }, 878491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 879491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 880491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 881491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 882491d8ee7SSantosh Puranik } 883491d8ee7SSantosh Puranik if (!bootModeStr.empty()) 884491d8ee7SSantosh Puranik { 885491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 886491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 887491d8ee7SSantosh Puranik if (ec) 888491d8ee7SSantosh Puranik { 889491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 890491d8ee7SSantosh Puranik messages::internalError(aResp->res); 891491d8ee7SSantosh Puranik return; 892491d8ee7SSantosh Puranik } 893491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 894491d8ee7SSantosh Puranik }, 895491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 896491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 897491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 898491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 899491d8ee7SSantosh Puranik } 900491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 901491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 902491d8ee7SSantosh Puranik if (ec) 903491d8ee7SSantosh Puranik { 904491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 905491d8ee7SSantosh Puranik messages::internalError(aResp->res); 906491d8ee7SSantosh Puranik return; 907491d8ee7SSantosh Puranik } 908491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 909491d8ee7SSantosh Puranik }, 910491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 911491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 912491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 913491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 914491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 915491d8ee7SSantosh Puranik } 916491d8ee7SSantosh Puranik 917491d8ee7SSantosh Puranik /** 918491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 919491d8ee7SSantosh Puranik * set boot source/boot mode properties. 920491d8ee7SSantosh Puranik * 921491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 922491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 923491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 924491d8ee7SSantosh Puranik * 925491d8ee7SSantosh Puranik * @return None. 926491d8ee7SSantosh Puranik */ 927491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 928491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 929491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 930491d8ee7SSantosh Puranik { 931491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 932491d8ee7SSantosh Puranik 933491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 934491d8ee7SSantosh Puranik [aResp{std::move(aResp)}, bootSource{std::move(bootSource)}, 935491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 936491d8ee7SSantosh Puranik const boost::system::error_code ec, 937491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 938491d8ee7SSantosh Puranik if (ec) 939491d8ee7SSantosh Puranik { 940491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 941491d8ee7SSantosh Puranik messages::internalError(aResp->res); 942491d8ee7SSantosh Puranik return; 943491d8ee7SSantosh Puranik } 944491d8ee7SSantosh Puranik 945491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 946491d8ee7SSantosh Puranik 947491d8ee7SSantosh Puranik if (!oneTimePtr) 948491d8ee7SSantosh Puranik { 949491d8ee7SSantosh Puranik messages::internalError(aResp->res); 950491d8ee7SSantosh Puranik return; 951491d8ee7SSantosh Puranik } 952491d8ee7SSantosh Puranik 953491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 954491d8ee7SSantosh Puranik 955491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 956491d8ee7SSantosh Puranik std::move(bootEnable)); 957491d8ee7SSantosh Puranik }, 958491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 959491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 960491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 961491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 962491d8ee7SSantosh Puranik } 963491d8ee7SSantosh Puranik 964491d8ee7SSantosh Puranik /** 965c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 966c5b2abe0SLewanczyk, Dawid * Schema 967c5b2abe0SLewanczyk, Dawid */ 9681abe55efSEd Tanous class SystemsCollection : public Node 9691abe55efSEd Tanous { 970c5b2abe0SLewanczyk, Dawid public: 9711abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 9721abe55efSEd Tanous { 973c5b2abe0SLewanczyk, Dawid entityPrivileges = { 974c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 975c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 976c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 977c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 978c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 979c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 980c5b2abe0SLewanczyk, Dawid } 981c5b2abe0SLewanczyk, Dawid 982c5b2abe0SLewanczyk, Dawid private: 98355c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 9841abe55efSEd Tanous const std::vector<std::string> ¶ms) override 9851abe55efSEd Tanous { 9860f74e643SEd Tanous res.jsonValue["@odata.type"] = 9870f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 9880f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 9890f74e643SEd Tanous res.jsonValue["@odata.context"] = 9900f74e643SEd Tanous "/redfish/v1/" 9910f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 9920f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 993029573d4SEd Tanous res.jsonValue["Members"] = { 994029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 995029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 996029573d4SEd Tanous res.end(); 997c5b2abe0SLewanczyk, Dawid } 998c5b2abe0SLewanczyk, Dawid }; 999c5b2abe0SLewanczyk, Dawid 1000c5b2abe0SLewanczyk, Dawid /** 1001cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1002cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1003cc340dd9SEd Tanous */ 1004cc340dd9SEd Tanous class SystemActionsReset : public Node 1005cc340dd9SEd Tanous { 1006cc340dd9SEd Tanous public: 1007cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1008029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1009cc340dd9SEd Tanous { 1010cc340dd9SEd Tanous entityPrivileges = { 1011cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1012cc340dd9SEd Tanous } 1013cc340dd9SEd Tanous 1014cc340dd9SEd Tanous private: 1015cc340dd9SEd Tanous /** 1016cc340dd9SEd Tanous * Function handles POST method request. 1017cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1018cc340dd9SEd Tanous */ 1019cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1020cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1021cc340dd9SEd Tanous { 1022cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1023cc340dd9SEd Tanous 10249712f8acSEd Tanous std::string resetType; 10259712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1026cc340dd9SEd Tanous { 1027cc340dd9SEd Tanous return; 1028cc340dd9SEd Tanous } 1029cc340dd9SEd Tanous 10309712f8acSEd Tanous if (resetType == "ForceOff") 1031cc340dd9SEd Tanous { 1032cc340dd9SEd Tanous // Force off acts on the chassis 1033cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1034cc340dd9SEd Tanous [asyncResp](const boost::system::error_code ec) { 1035cc340dd9SEd Tanous if (ec) 1036cc340dd9SEd Tanous { 10379712f8acSEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1038f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1039cc340dd9SEd Tanous return; 1040cc340dd9SEd Tanous } 1041cc340dd9SEd Tanous // TODO Consider support polling mechanism to verify 1042cc340dd9SEd Tanous // status of host and chassis after execute the 1043cc340dd9SEd Tanous // requested action. 1044f12894f8SJason M. Bills messages::success(asyncResp->res); 1045cc340dd9SEd Tanous }, 1046cc340dd9SEd Tanous "xyz.openbmc_project.State.Chassis", 1047cc340dd9SEd Tanous "/xyz/openbmc_project/state/chassis0", 1048cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 10499712f8acSEd Tanous "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1050abf2add6SEd Tanous std::variant<std::string>{ 10519712f8acSEd Tanous "xyz.openbmc_project.State.Chassis.Transition.Off"}); 1052cc340dd9SEd Tanous return; 1053cc340dd9SEd Tanous } 1054cc340dd9SEd Tanous // all other actions operate on the host 1055cc340dd9SEd Tanous std::string command; 1056cc340dd9SEd Tanous // Execute Reset Action regarding to each reset type. 10579712f8acSEd Tanous if (resetType == "On") 1058cc340dd9SEd Tanous { 1059cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1060cc340dd9SEd Tanous } 10619712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1062cc340dd9SEd Tanous { 1063cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1064cc340dd9SEd Tanous } 10659712f8acSEd Tanous else if (resetType == "GracefulRestart") 1066cc340dd9SEd Tanous { 10679712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1068cc340dd9SEd Tanous } 1069cc340dd9SEd Tanous else 1070cc340dd9SEd Tanous { 1071f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1072cc340dd9SEd Tanous return; 1073cc340dd9SEd Tanous } 1074cc340dd9SEd Tanous 1075cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1076cc340dd9SEd Tanous [asyncResp](const boost::system::error_code ec) { 1077cc340dd9SEd Tanous if (ec) 1078cc340dd9SEd Tanous { 1079cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1080f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1081cc340dd9SEd Tanous return; 1082cc340dd9SEd Tanous } 1083cc340dd9SEd Tanous // TODO Consider support polling mechanism to verify 1084cc340dd9SEd Tanous // status of host and chassis after execute the 1085cc340dd9SEd Tanous // requested action. 1086f12894f8SJason M. Bills messages::success(asyncResp->res); 1087cc340dd9SEd Tanous }, 1088cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1089cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1090cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 10919712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1092abf2add6SEd Tanous std::variant<std::string>{command}); 1093cc340dd9SEd Tanous } 1094cc340dd9SEd Tanous }; 1095cc340dd9SEd Tanous 1096cc340dd9SEd Tanous /** 10976617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1098c5b2abe0SLewanczyk, Dawid */ 10991abe55efSEd Tanous class Systems : public Node 11001abe55efSEd Tanous { 1101c5b2abe0SLewanczyk, Dawid public: 1102c5b2abe0SLewanczyk, Dawid /* 1103c5b2abe0SLewanczyk, Dawid * Default Constructor 1104c5b2abe0SLewanczyk, Dawid */ 1105029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 11061abe55efSEd Tanous { 1107c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1108c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1109c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1110c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1111c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1112c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1113c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1114c5b2abe0SLewanczyk, Dawid } 1115c5b2abe0SLewanczyk, Dawid 1116c5b2abe0SLewanczyk, Dawid private: 1117c5b2abe0SLewanczyk, Dawid /** 1118c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1119c5b2abe0SLewanczyk, Dawid */ 112055c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 11211abe55efSEd Tanous const std::vector<std::string> ¶ms) override 11221abe55efSEd Tanous { 1123491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 11240f74e643SEd Tanous res.jsonValue["@odata.context"] = 11250f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1126029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1127029573d4SEd Tanous res.jsonValue["Id"] = "system"; 11280f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 11290f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 11300f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 11310f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 11320f74e643SEd Tanous res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0); 11330f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1134029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 113504a258f4SEd Tanous 1136443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1137029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1138443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1139029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1140029573d4SEd Tanous 1141cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1142cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1143cc340dd9SEd Tanous {"target", 1144029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1145cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1146cc340dd9SEd Tanous {"On", "ForceOff", "GracefulRestart", "GracefulShutdown"}}}; 1147c5b2abe0SLewanczyk, Dawid 1148c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1149029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1150c4bf6374SJason M. Bills 1151a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1152c5b2abe0SLewanczyk, Dawid 11536c34de48SEd Tanous getLedGroupIdentify( 1154a0803efaSEd Tanous asyncResp, 1155a0803efaSEd Tanous [&](const bool &asserted, const std::shared_ptr<AsyncResp> &aResp) { 11561abe55efSEd Tanous if (asserted) 11571abe55efSEd Tanous { 1158c5b2abe0SLewanczyk, Dawid // If led group is asserted, then another call is needed to 1159c5b2abe0SLewanczyk, Dawid // get led status 11606c34de48SEd Tanous getLedIdentify( 1161a0803efaSEd Tanous aResp, [](const std::string &ledStatus, 1162a0803efaSEd Tanous const std::shared_ptr<AsyncResp> &aResp) { 11631abe55efSEd Tanous if (!ledStatus.empty()) 11641abe55efSEd Tanous { 11651abe55efSEd Tanous aResp->res.jsonValue["IndicatorLED"] = 11661abe55efSEd Tanous ledStatus; 1167c5b2abe0SLewanczyk, Dawid } 1168c5b2abe0SLewanczyk, Dawid }); 11691abe55efSEd Tanous } 11701abe55efSEd Tanous else 11711abe55efSEd Tanous { 117255c7b7a2SEd Tanous aResp->res.jsonValue["IndicatorLED"] = "Off"; 1173c5b2abe0SLewanczyk, Dawid } 1174c5b2abe0SLewanczyk, Dawid }); 1175029573d4SEd Tanous getComputerSystem(asyncResp); 11766c34de48SEd Tanous getHostState(asyncResp); 1177491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1178c5b2abe0SLewanczyk, Dawid } 1179c5b2abe0SLewanczyk, Dawid 118055c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 11811abe55efSEd Tanous const std::vector<std::string> ¶ms) override 11821abe55efSEd Tanous { 1183cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1184491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1185491d8ee7SSantosh Puranik if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1186491d8ee7SSantosh Puranik bootProps)) 11876617338dSEd Tanous { 11886617338dSEd Tanous return; 11896617338dSEd Tanous } 1190491d8ee7SSantosh Puranik 1191029573d4SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1192d573bb2aSJennifer Lee asyncResp->res.result(boost::beast::http::status::no_content); 1193491d8ee7SSantosh Puranik 1194491d8ee7SSantosh Puranik if (bootProps) 1195491d8ee7SSantosh Puranik { 1196491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1197491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1198491d8ee7SSantosh Puranik 1199491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1200491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1201491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1202491d8ee7SSantosh Puranik { 1203491d8ee7SSantosh Puranik return; 1204491d8ee7SSantosh Puranik } 1205491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1206491d8ee7SSantosh Puranik std::move(bootEnable)); 1207491d8ee7SSantosh Puranik } 12089712f8acSEd Tanous if (indicatorLed) 12096617338dSEd Tanous { 12109712f8acSEd Tanous std::string dbusLedState; 1211d573bb2aSJennifer Lee if (*indicatorLed == "Lit") 12129712f8acSEd Tanous { 1213d573bb2aSJennifer Lee dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On"; 12146617338dSEd Tanous } 12155c6221acSGunnar Mills else if (*indicatorLed == "Blinking") 12166617338dSEd Tanous { 12175c6221acSGunnar Mills dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink"; 12186617338dSEd Tanous } 12199712f8acSEd Tanous else if (*indicatorLed == "Off") 12206617338dSEd Tanous { 12219712f8acSEd Tanous dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off"; 12226617338dSEd Tanous } 12236617338dSEd Tanous else 12246617338dSEd Tanous { 1225a08b46ccSJason M. Bills messages::propertyValueNotInList(res, *indicatorLed, 1226a08b46ccSJason M. Bills "IndicatorLED"); 12276617338dSEd Tanous return; 12286617338dSEd Tanous } 12296617338dSEd Tanous 1230c5b2abe0SLewanczyk, Dawid // Update led group 123155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led group."; 123255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1233cde19e5fSSantosh Puranik [asyncResp](const boost::system::error_code ec) { 12341abe55efSEd Tanous if (ec) 12351abe55efSEd Tanous { 123655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1237f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1238c5b2abe0SLewanczyk, Dawid return; 1239c5b2abe0SLewanczyk, Dawid } 124055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led group update done."; 1241c5b2abe0SLewanczyk, Dawid }, 1242c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 1243c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/groups/enclosure_identify", 1244c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1245c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Group", "Asserted", 1246abf2add6SEd Tanous std::variant<bool>( 12476617338dSEd Tanous (dbusLedState == 12486617338dSEd Tanous "xyz.openbmc_project.Led.Physical.Action.Off" 12496617338dSEd Tanous ? false 12506617338dSEd Tanous : true))); 1251c5b2abe0SLewanczyk, Dawid // Update identify led status 125255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection."; 125355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 12546617338dSEd Tanous [asyncResp{std::move(asyncResp)}, 12559712f8acSEd Tanous indicatorLed{std::move(*indicatorLed)}]( 1256c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec) { 12571abe55efSEd Tanous if (ec) 12581abe55efSEd Tanous { 125955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1260f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1261c5b2abe0SLewanczyk, Dawid return; 1262c5b2abe0SLewanczyk, Dawid } 126355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led state update done."; 1264c5b2abe0SLewanczyk, Dawid }, 1265c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 1266c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 1267c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1268c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical", "State", 1269abf2add6SEd Tanous std::variant<std::string>(dbusLedState)); 12706617338dSEd Tanous } 1271c5b2abe0SLewanczyk, Dawid } 1272c5b2abe0SLewanczyk, Dawid }; 1273c5b2abe0SLewanczyk, Dawid } // namespace redfish 1274