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" 19f5c9f8bdSJason 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 319d3ae10eSAlpana Kumari /** 329d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 339d3ae10eSAlpana Kumari * 349d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 359d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 369d3ae10eSAlpana Kumari * 379d3ae10eSAlpana Kumari * @return None. 389d3ae10eSAlpana Kumari */ 399d3ae10eSAlpana Kumari void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, 409d3ae10eSAlpana Kumari const std::variant<bool> &dimmState) 419d3ae10eSAlpana Kumari { 429d3ae10eSAlpana Kumari const bool *isDimmFunctional = std::get_if<bool>(&dimmState); 439d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 449d3ae10eSAlpana Kumari { 459d3ae10eSAlpana Kumari messages::internalError(aResp->res); 469d3ae10eSAlpana Kumari return; 479d3ae10eSAlpana Kumari } 489d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 499d3ae10eSAlpana Kumari 509d3ae10eSAlpana Kumari // Set it as Enabled if atleast one DIMM is functional 519d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 529d3ae10eSAlpana Kumari // ENABLED. 539d3ae10eSAlpana Kumari nlohmann::json &prevMemSummary = 549d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 559d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 569d3ae10eSAlpana Kumari { 579d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 589d3ae10eSAlpana Kumari { 599d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 609d3ae10eSAlpana Kumari "Enabled"; 619d3ae10eSAlpana Kumari } 629d3ae10eSAlpana Kumari } 639d3ae10eSAlpana Kumari } 649d3ae10eSAlpana Kumari 6557e8c9beSAlpana Kumari /* 6657e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 6757e8c9beSAlpana Kumari * 6857e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 6957e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7057e8c9beSAlpana Kumari * 7157e8c9beSAlpana Kumari * @return None. 7257e8c9beSAlpana Kumari */ 7357e8c9beSAlpana Kumari void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, 7457e8c9beSAlpana Kumari const std::variant<bool> &cpuPresenceState) 7557e8c9beSAlpana Kumari { 7657e8c9beSAlpana Kumari const bool *isCpuPresent = std::get_if<bool>(&cpuPresenceState); 7757e8c9beSAlpana Kumari 7857e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 7957e8c9beSAlpana Kumari { 8057e8c9beSAlpana Kumari messages::internalError(aResp->res); 8157e8c9beSAlpana Kumari return; 8257e8c9beSAlpana Kumari } 8357e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8457e8c9beSAlpana Kumari 8557e8c9beSAlpana Kumari nlohmann::json &procCount = 8657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Count"]; 8757e8c9beSAlpana Kumari if (*isCpuPresent == true) 8857e8c9beSAlpana Kumari { 8957e8c9beSAlpana Kumari procCount = procCount.get<int>() + 1; 9057e8c9beSAlpana Kumari } 9157e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Count"] = procCount; 9257e8c9beSAlpana Kumari } 9357e8c9beSAlpana Kumari 9457e8c9beSAlpana Kumari /* 9557e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 9657e8c9beSAlpana Kumari * CPU Functional State 9757e8c9beSAlpana Kumari * 9857e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 9957e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10057e8c9beSAlpana Kumari * 10157e8c9beSAlpana Kumari * @return None. 10257e8c9beSAlpana Kumari */ 10357e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, 10457e8c9beSAlpana Kumari const std::variant<bool> &cpuFunctionalState) 10557e8c9beSAlpana Kumari { 10657e8c9beSAlpana Kumari const bool *isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 10757e8c9beSAlpana Kumari 10857e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 10957e8c9beSAlpana Kumari { 11057e8c9beSAlpana Kumari messages::internalError(aResp->res); 11157e8c9beSAlpana Kumari return; 11257e8c9beSAlpana Kumari } 11357e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 11457e8c9beSAlpana Kumari 11557e8c9beSAlpana Kumari nlohmann::json &prevProcState = 11657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 11757e8c9beSAlpana Kumari 11857e8c9beSAlpana Kumari // Set it as Enabled if atleast one CPU is functional 11957e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12057e8c9beSAlpana Kumari // Functional. 12157e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12257e8c9beSAlpana Kumari { 12357e8c9beSAlpana Kumari if (*isCpuFunctional == true) 12457e8c9beSAlpana Kumari { 12557e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 12657e8c9beSAlpana Kumari "Enabled"; 12757e8c9beSAlpana Kumari } 12857e8c9beSAlpana Kumari } 12957e8c9beSAlpana Kumari } 13057e8c9beSAlpana Kumari 13157e8c9beSAlpana Kumari /* 132c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 133c5b2abe0SLewanczyk, Dawid * 134c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 135c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 136c5b2abe0SLewanczyk, Dawid * 137c5b2abe0SLewanczyk, Dawid * @return None. 138c5b2abe0SLewanczyk, Dawid */ 139029573d4SEd Tanous void getComputerSystem(std::shared_ptr<AsyncResp> aResp) 1401abe55efSEd Tanous { 14155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1429d3ae10eSAlpana Kumari 14355c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 144c5d03ff4SJennifer Lee [aResp]( 145c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 146c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1476c34de48SEd Tanous std::string, 1486c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 149c5b2abe0SLewanczyk, Dawid &subtree) { 1501abe55efSEd Tanous if (ec) 1511abe55efSEd Tanous { 15255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 153f12894f8SJason M. Bills messages::internalError(aResp->res); 154c5b2abe0SLewanczyk, Dawid return; 155c5b2abe0SLewanczyk, Dawid } 156c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1576c34de48SEd Tanous for (const std::pair<std::string, 1586c34de48SEd Tanous std::vector<std::pair< 1596c34de48SEd Tanous std::string, std::vector<std::string>>>> 1601abe55efSEd Tanous &object : subtree) 1611abe55efSEd Tanous { 162c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 16355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1641abe55efSEd Tanous const std::vector< 1651abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 166c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 1671abe55efSEd Tanous if (connectionNames.size() < 1) 1681abe55efSEd Tanous { 169c5b2abe0SLewanczyk, Dawid continue; 170c5b2abe0SLewanczyk, Dawid } 171029573d4SEd Tanous 1726c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1736c34de48SEd Tanous // BiosVer 17404a258f4SEd Tanous for (const auto &connection : connectionNames) 1751abe55efSEd Tanous { 17604a258f4SEd Tanous for (const auto &interfaceName : connection.second) 1771abe55efSEd Tanous { 17804a258f4SEd Tanous if (interfaceName == 17904a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1801abe55efSEd Tanous { 1811abe55efSEd Tanous BMCWEB_LOG_DEBUG 18204a258f4SEd Tanous << "Found Dimm, now get its properties."; 1839d3ae10eSAlpana Kumari 18455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1859d3ae10eSAlpana Kumari [aResp, service{connection.first}, 1869d3ae10eSAlpana Kumari path(std::move(path))]( 1879d3ae10eSAlpana Kumari const boost::system::error_code ec, 1886c34de48SEd Tanous const std::vector< 1896c34de48SEd Tanous std::pair<std::string, VariantType>> 1901abe55efSEd Tanous &properties) { 1911abe55efSEd Tanous if (ec) 1921abe55efSEd Tanous { 1931abe55efSEd Tanous BMCWEB_LOG_ERROR 1946c34de48SEd Tanous << "DBUS response error " << ec; 195f12894f8SJason M. Bills messages::internalError(aResp->res); 196c5b2abe0SLewanczyk, Dawid return; 197c5b2abe0SLewanczyk, Dawid } 1986c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 1996c34de48SEd Tanous << properties.size() 200c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2019d3ae10eSAlpana Kumari 2029d3ae10eSAlpana Kumari if (properties.size() > 0) 2039d3ae10eSAlpana Kumari { 20404a258f4SEd Tanous for (const std::pair<std::string, 20504a258f4SEd Tanous VariantType> 20604a258f4SEd Tanous &property : properties) 2071abe55efSEd Tanous { 2089d3ae10eSAlpana Kumari if (property.first == 2099d3ae10eSAlpana Kumari "MemorySizeInKb") 2101abe55efSEd Tanous { 21104a258f4SEd Tanous const uint64_t *value = 2129d3ae10eSAlpana Kumari sdbusplus::message:: 2139d3ae10eSAlpana Kumari variant_ns::get_if< 2149d3ae10eSAlpana Kumari uint64_t>( 2151b6b96c5SEd Tanous &property.second); 21604a258f4SEd Tanous if (value != nullptr) 2171abe55efSEd Tanous { 2181abe55efSEd Tanous aResp->res.jsonValue 2196c34de48SEd Tanous ["TotalSystemMemoryGi" 2206c34de48SEd Tanous "B"] += 22104a258f4SEd Tanous *value / (1024 * 1024); 2229d3ae10eSAlpana Kumari aResp->res.jsonValue 2239d3ae10eSAlpana Kumari ["MemorySummary"] 2249d3ae10eSAlpana Kumari ["Status"]["State"] = 2251abe55efSEd Tanous "Enabled"; 226c5b2abe0SLewanczyk, Dawid } 227c5b2abe0SLewanczyk, Dawid } 228c5b2abe0SLewanczyk, Dawid } 2299d3ae10eSAlpana Kumari } 2309d3ae10eSAlpana Kumari else 2319d3ae10eSAlpana Kumari { 2329d3ae10eSAlpana Kumari auto getDimmProperties = 2339d3ae10eSAlpana Kumari [aResp]( 2349d3ae10eSAlpana Kumari const boost::system::error_code 2359d3ae10eSAlpana Kumari ec, 2369d3ae10eSAlpana Kumari const std::variant<bool> 2379d3ae10eSAlpana Kumari &dimmState) { 2389d3ae10eSAlpana Kumari if (ec) 2399d3ae10eSAlpana Kumari { 2409d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2419d3ae10eSAlpana Kumari << "DBUS response " 2429d3ae10eSAlpana Kumari "error " 2439d3ae10eSAlpana Kumari << ec; 2449d3ae10eSAlpana Kumari return; 2459d3ae10eSAlpana Kumari } 2469d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2479d3ae10eSAlpana Kumari dimmState); 2489d3ae10eSAlpana Kumari }; 2499d3ae10eSAlpana Kumari crow::connections::systemBus 2509d3ae10eSAlpana Kumari ->async_method_call( 2519d3ae10eSAlpana Kumari std::move(getDimmProperties), 2529d3ae10eSAlpana Kumari service, path, 2539d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2549d3ae10eSAlpana Kumari "Properties", 2559d3ae10eSAlpana Kumari "Get", 2569d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2579d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2589d3ae10eSAlpana Kumari "Functional"); 2599d3ae10eSAlpana Kumari } 260c5b2abe0SLewanczyk, Dawid }, 26104a258f4SEd Tanous connection.first, path, 2626c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2636c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2641abe55efSEd Tanous } 26504a258f4SEd Tanous else if (interfaceName == 26604a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 2671abe55efSEd Tanous { 2681abe55efSEd Tanous BMCWEB_LOG_DEBUG 26904a258f4SEd Tanous << "Found Cpu, now get its properties."; 27057e8c9beSAlpana Kumari 271a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 27257e8c9beSAlpana Kumari [aResp, service{connection.first}, 27357e8c9beSAlpana Kumari path(std::move(path))]( 27457e8c9beSAlpana Kumari const boost::system::error_code ec, 2756c34de48SEd Tanous const std::vector< 2766c34de48SEd Tanous std::pair<std::string, VariantType>> 2771abe55efSEd Tanous &properties) { 2781abe55efSEd Tanous if (ec) 2791abe55efSEd Tanous { 2801abe55efSEd Tanous BMCWEB_LOG_ERROR 2816c34de48SEd Tanous << "DBUS response error " << ec; 282f12894f8SJason M. Bills messages::internalError(aResp->res); 283c5b2abe0SLewanczyk, Dawid return; 284c5b2abe0SLewanczyk, Dawid } 2856c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2866c34de48SEd Tanous << properties.size() 287c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 28857e8c9beSAlpana Kumari 28957e8c9beSAlpana Kumari if (properties.size() > 0) 29057e8c9beSAlpana Kumari { 29104a258f4SEd Tanous for (const auto &property : properties) 2921abe55efSEd Tanous { 29357e8c9beSAlpana Kumari if (property.first == 29457e8c9beSAlpana Kumari "ProcessorFamily") 2951abe55efSEd Tanous { 296a0803efaSEd Tanous const std::string *value = 29757e8c9beSAlpana Kumari sdbusplus::message:: 29857e8c9beSAlpana Kumari variant_ns::get_if< 29957e8c9beSAlpana Kumari std::string>( 3001b6b96c5SEd Tanous &property.second); 3011abe55efSEd Tanous if (value != nullptr) 3021abe55efSEd Tanous { 30357e8c9beSAlpana Kumari nlohmann::json 30457e8c9beSAlpana Kumari &procSummary = 3051abe55efSEd Tanous aResp->res.jsonValue 3066c34de48SEd Tanous ["ProcessorSumm" 30704a258f4SEd Tanous "ary"]; 30804a258f4SEd Tanous nlohmann::json &procCount = 30904a258f4SEd Tanous procSummary["Count"]; 31004a258f4SEd Tanous procCount = 31157e8c9beSAlpana Kumari procCount.get<int>() + 31257e8c9beSAlpana Kumari 1; 31357e8c9beSAlpana Kumari procSummary["Status"] 31457e8c9beSAlpana Kumari ["State"] = 315c5b2abe0SLewanczyk, Dawid "Enabled"; 31657e8c9beSAlpana Kumari procSummary["Model"] = 31757e8c9beSAlpana Kumari *value; 318c5b2abe0SLewanczyk, Dawid } 319c5b2abe0SLewanczyk, Dawid } 320c5b2abe0SLewanczyk, Dawid } 32157e8c9beSAlpana Kumari } 32257e8c9beSAlpana Kumari else 32357e8c9beSAlpana Kumari { 32457e8c9beSAlpana Kumari auto getCpuPresenceState = 32557e8c9beSAlpana Kumari [aResp]( 32657e8c9beSAlpana Kumari const boost::system::error_code 32757e8c9beSAlpana Kumari ec, 32857e8c9beSAlpana Kumari const std::variant<bool> 32957e8c9beSAlpana Kumari &cpuPresenceCheck) { 33057e8c9beSAlpana Kumari if (ec) 33157e8c9beSAlpana Kumari { 33257e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 33357e8c9beSAlpana Kumari << "DBUS response " 33457e8c9beSAlpana Kumari "error " 33557e8c9beSAlpana Kumari << ec; 33657e8c9beSAlpana Kumari return; 33757e8c9beSAlpana Kumari } 33857e8c9beSAlpana Kumari modifyCpuPresenceState( 33957e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 34057e8c9beSAlpana Kumari }; 34157e8c9beSAlpana Kumari 34257e8c9beSAlpana Kumari auto getCpuFunctionalState = 34357e8c9beSAlpana Kumari [aResp]( 34457e8c9beSAlpana Kumari const boost::system::error_code 34557e8c9beSAlpana Kumari ec, 34657e8c9beSAlpana Kumari const std::variant<bool> 34757e8c9beSAlpana Kumari &cpuFunctionalCheck) { 34857e8c9beSAlpana Kumari if (ec) 34957e8c9beSAlpana Kumari { 35057e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 35157e8c9beSAlpana Kumari << "DBUS response " 35257e8c9beSAlpana Kumari "error " 35357e8c9beSAlpana Kumari << ec; 35457e8c9beSAlpana Kumari return; 35557e8c9beSAlpana Kumari } 35657e8c9beSAlpana Kumari modifyCpuFunctionalState( 35757e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 35857e8c9beSAlpana Kumari }; 35957e8c9beSAlpana Kumari // Get the Presence of CPU 36057e8c9beSAlpana Kumari crow::connections::systemBus 36157e8c9beSAlpana Kumari ->async_method_call( 36257e8c9beSAlpana Kumari std::move(getCpuPresenceState), 36357e8c9beSAlpana Kumari service, path, 36457e8c9beSAlpana Kumari "org.freedesktop.DBus." 36557e8c9beSAlpana Kumari "Properties", 36657e8c9beSAlpana Kumari "Get", 36757e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 36857e8c9beSAlpana Kumari "Item", 36957e8c9beSAlpana Kumari "Present"); 37057e8c9beSAlpana Kumari 37157e8c9beSAlpana Kumari // Get the Functional State 37257e8c9beSAlpana Kumari crow::connections::systemBus 37357e8c9beSAlpana Kumari ->async_method_call( 37457e8c9beSAlpana Kumari std::move( 37557e8c9beSAlpana Kumari getCpuFunctionalState), 37657e8c9beSAlpana Kumari service, path, 37757e8c9beSAlpana Kumari "org.freedesktop.DBus." 37857e8c9beSAlpana Kumari "Properties", 37957e8c9beSAlpana Kumari "Get", 38057e8c9beSAlpana Kumari "xyz.openbmc_project.State." 38157e8c9beSAlpana Kumari "Decorator." 38257e8c9beSAlpana Kumari "OperationalStatus", 38357e8c9beSAlpana Kumari "Functional"); 38457e8c9beSAlpana Kumari 38557e8c9beSAlpana Kumari // Get the MODEL from 38657e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 38757e8c9beSAlpana Kumari // support it later as Model is Empty 38857e8c9beSAlpana Kumari // currently. 38957e8c9beSAlpana Kumari } 390c5b2abe0SLewanczyk, Dawid }, 39104a258f4SEd Tanous connection.first, path, 3926c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 3936c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 3941abe55efSEd Tanous } 39504a258f4SEd Tanous else if (interfaceName == 39604a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 3971abe55efSEd Tanous { 3981abe55efSEd Tanous BMCWEB_LOG_DEBUG 39904a258f4SEd Tanous << "Found UUID, now get its properties."; 40055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 401029573d4SEd Tanous [aResp](const boost::system::error_code ec, 4026c34de48SEd Tanous const std::vector< 4036c34de48SEd Tanous std::pair<std::string, VariantType>> 4041abe55efSEd Tanous &properties) { 4051abe55efSEd Tanous if (ec) 4061abe55efSEd Tanous { 4071abe55efSEd Tanous BMCWEB_LOG_DEBUG 4086c34de48SEd Tanous << "DBUS response error " << ec; 409f12894f8SJason M. Bills messages::internalError(aResp->res); 410c5b2abe0SLewanczyk, Dawid return; 411c5b2abe0SLewanczyk, Dawid } 4126c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4136c34de48SEd Tanous << properties.size() 414c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4151abe55efSEd Tanous for (const std::pair<std::string, 41604a258f4SEd Tanous VariantType> 41704a258f4SEd Tanous &property : properties) 4181abe55efSEd Tanous { 41904a258f4SEd Tanous if (property.first == "UUID") 4201abe55efSEd Tanous { 421c5b2abe0SLewanczyk, Dawid const std::string *value = 422029573d4SEd Tanous sdbusplus::message::variant_ns:: 423029573d4SEd Tanous get_if<std::string>( 4241b6b96c5SEd Tanous &property.second); 42504a258f4SEd Tanous 4261abe55efSEd Tanous if (value != nullptr) 4271abe55efSEd Tanous { 428029573d4SEd Tanous std::string valueStr = *value; 42904a258f4SEd Tanous if (valueStr.size() == 32) 4301abe55efSEd Tanous { 431029573d4SEd Tanous valueStr.insert(8, 1, '-'); 432029573d4SEd Tanous valueStr.insert(13, 1, '-'); 433029573d4SEd Tanous valueStr.insert(18, 1, '-'); 434029573d4SEd Tanous valueStr.insert(23, 1, '-'); 43504a258f4SEd Tanous } 436029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 43704a258f4SEd Tanous << valueStr; 438029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 43904a258f4SEd Tanous valueStr; 440c5b2abe0SLewanczyk, Dawid } 441c5b2abe0SLewanczyk, Dawid } 442c5b2abe0SLewanczyk, Dawid } 443c5b2abe0SLewanczyk, Dawid }, 44404a258f4SEd Tanous connection.first, path, 4456c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4461abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 447c5b2abe0SLewanczyk, Dawid } 448029573d4SEd Tanous else if (interfaceName == 449029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4501abe55efSEd Tanous { 451029573d4SEd Tanous crow::connections::systemBus->async_method_call( 452029573d4SEd Tanous [aResp](const boost::system::error_code ec, 453029573d4SEd Tanous const std::vector< 454029573d4SEd Tanous std::pair<std::string, VariantType>> 455029573d4SEd Tanous &propertiesList) { 456029573d4SEd Tanous if (ec) 457029573d4SEd Tanous { 458e4a4b9a9SJames Feist // doesn't have to include this 459e4a4b9a9SJames Feist // interface 460029573d4SEd Tanous return; 461029573d4SEd Tanous } 462*698654b6SGunnar Mills BMCWEB_LOG_DEBUG 463*698654b6SGunnar Mills << "Got " << propertiesList.size() 464029573d4SEd Tanous << " properties for system"; 465029573d4SEd Tanous for (const std::pair<std::string, 466029573d4SEd Tanous VariantType> 467029573d4SEd Tanous &property : propertiesList) 468029573d4SEd Tanous { 469fc5afcf9Sbeccabroek const std::string &propertyName = 470fc5afcf9Sbeccabroek property.first; 471fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 472fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 473fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 474fc5afcf9Sbeccabroek (propertyName == "Model")) 475fc5afcf9Sbeccabroek { 476029573d4SEd Tanous const std::string *value = 477fc5afcf9Sbeccabroek std::get_if<std::string>( 478029573d4SEd Tanous &property.second); 479029573d4SEd Tanous if (value != nullptr) 480029573d4SEd Tanous { 481029573d4SEd Tanous aResp->res 482fc5afcf9Sbeccabroek .jsonValue[propertyName] = 483029573d4SEd Tanous *value; 484029573d4SEd Tanous } 485029573d4SEd Tanous } 486fc5afcf9Sbeccabroek } 487029573d4SEd Tanous aResp->res.jsonValue["Name"] = "system"; 488029573d4SEd Tanous aResp->res.jsonValue["Id"] = 489029573d4SEd Tanous aResp->res.jsonValue["SerialNumber"]; 490cb7e1e7bSAndrew Geissler // Grab the bios version 491cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 492cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 493cb7e1e7bSAndrew Geissler "BiosVersion"); 494029573d4SEd Tanous }, 495029573d4SEd Tanous connection.first, path, 496029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 497029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 498029573d4SEd Tanous "Asset"); 499e4a4b9a9SJames Feist 500e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 501e4a4b9a9SJames Feist [aResp]( 502e4a4b9a9SJames Feist const boost::system::error_code ec, 503e4a4b9a9SJames Feist const std::variant<std::string> &property) { 504e4a4b9a9SJames Feist if (ec) 505e4a4b9a9SJames Feist { 506e4a4b9a9SJames Feist // doesn't have to include this 507e4a4b9a9SJames Feist // interface 508e4a4b9a9SJames Feist return; 509e4a4b9a9SJames Feist } 510e4a4b9a9SJames Feist 511e4a4b9a9SJames Feist const std::string *value = 512e4a4b9a9SJames Feist std::get_if<std::string>(&property); 513e4a4b9a9SJames Feist if (value != nullptr) 514e4a4b9a9SJames Feist { 515e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 516e4a4b9a9SJames Feist *value; 517e4a4b9a9SJames Feist } 518e4a4b9a9SJames Feist }, 519e4a4b9a9SJames Feist connection.first, path, 520e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 521e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 522e4a4b9a9SJames Feist "AssetTag", 523e4a4b9a9SJames Feist "AssetTag"); 524029573d4SEd Tanous } 525029573d4SEd Tanous } 526029573d4SEd Tanous } 527c5b2abe0SLewanczyk, Dawid } 528c5b2abe0SLewanczyk, Dawid }, 529c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 530c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 531c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5326617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5336617338dSEd Tanous std::array<const char *, 5>{ 5346617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5356617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5366617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5376617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5386617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5396617338dSEd Tanous }); 540c5b2abe0SLewanczyk, Dawid } 541c5b2abe0SLewanczyk, Dawid 542c5b2abe0SLewanczyk, Dawid /** 543c5b2abe0SLewanczyk, Dawid * @brief Retrieves identify led group properties over dbus 544c5b2abe0SLewanczyk, Dawid * 545491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 546c5b2abe0SLewanczyk, Dawid * @param[in] callback Callback for process retrieved data. 547c5b2abe0SLewanczyk, Dawid * 548c5b2abe0SLewanczyk, Dawid * @return None. 549c5b2abe0SLewanczyk, Dawid */ 550c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 551a0803efaSEd Tanous void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp, 5521abe55efSEd Tanous CallbackFunc &&callback) 5531abe55efSEd Tanous { 55455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get led groups"; 55555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 556c5d03ff4SJennifer Lee [aResp, 5576617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code &ec, 5581abe55efSEd Tanous const ManagedObjectsType &resp) { 5591abe55efSEd Tanous if (ec) 5601abe55efSEd Tanous { 56155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 562f12894f8SJason M. Bills messages::internalError(aResp->res); 563c5b2abe0SLewanczyk, Dawid return; 564c5b2abe0SLewanczyk, Dawid } 5656c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " << resp.size() << " led group objects."; 5661abe55efSEd Tanous for (const auto &objPath : resp) 5671abe55efSEd Tanous { 568c5b2abe0SLewanczyk, Dawid const std::string &path = objPath.first; 5691abe55efSEd Tanous if (path.rfind("enclosure_identify") != std::string::npos) 5701abe55efSEd Tanous { 5711abe55efSEd Tanous for (const auto &interface : objPath.second) 5721abe55efSEd Tanous { 5736c34de48SEd Tanous if (interface.first == "xyz.openbmc_project.Led.Group") 5741abe55efSEd Tanous { 5751abe55efSEd Tanous for (const auto &property : interface.second) 5761abe55efSEd Tanous { 5771abe55efSEd Tanous if (property.first == "Asserted") 5781abe55efSEd Tanous { 579c5b2abe0SLewanczyk, Dawid const bool *asserted = 580abf2add6SEd Tanous std::get_if<bool>(&property.second); 5811abe55efSEd Tanous if (nullptr != asserted) 5821abe55efSEd Tanous { 583c5b2abe0SLewanczyk, Dawid callback(*asserted, aResp); 5841abe55efSEd Tanous } 5851abe55efSEd Tanous else 5861abe55efSEd Tanous { 587c5b2abe0SLewanczyk, Dawid callback(false, aResp); 588c5b2abe0SLewanczyk, Dawid } 589c5b2abe0SLewanczyk, Dawid } 590c5b2abe0SLewanczyk, Dawid } 591c5b2abe0SLewanczyk, Dawid } 592c5b2abe0SLewanczyk, Dawid } 593c5b2abe0SLewanczyk, Dawid } 594c5b2abe0SLewanczyk, Dawid } 595c5b2abe0SLewanczyk, Dawid }, 596c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 5976c34de48SEd Tanous "/xyz/openbmc_project/led/groups", "org.freedesktop.DBus.ObjectManager", 5986c34de48SEd Tanous "GetManagedObjects"); 599c5b2abe0SLewanczyk, Dawid } 600c5b2abe0SLewanczyk, Dawid 601c5b2abe0SLewanczyk, Dawid template <typename CallbackFunc> 6026c34de48SEd Tanous void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback) 6031abe55efSEd Tanous { 60455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get identify led properties"; 60555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 6066617338dSEd Tanous [aResp, 6076617338dSEd Tanous callback{std::move(callback)}](const boost::system::error_code ec, 608c5b2abe0SLewanczyk, Dawid const PropertiesType &properties) { 6091abe55efSEd Tanous if (ec) 6101abe55efSEd Tanous { 61155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 612f12894f8SJason M. Bills messages::internalError(aResp->res); 613c5b2abe0SLewanczyk, Dawid return; 614c5b2abe0SLewanczyk, Dawid } 6151abe55efSEd Tanous BMCWEB_LOG_DEBUG << "Got " << properties.size() 6161abe55efSEd Tanous << " led properties."; 617c5b2abe0SLewanczyk, Dawid std::string output; 6181abe55efSEd Tanous for (const auto &property : properties) 6191abe55efSEd Tanous { 6201abe55efSEd Tanous if (property.first == "State") 6211abe55efSEd Tanous { 622c5b2abe0SLewanczyk, Dawid const std::string *s = 623abf2add6SEd Tanous std::get_if<std::string>(&property.second); 6241abe55efSEd Tanous if (nullptr != s) 6251abe55efSEd Tanous { 62655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Identify Led State: " << *s; 627c5b2abe0SLewanczyk, Dawid const auto pos = s->rfind('.'); 6281abe55efSEd Tanous if (pos != std::string::npos) 6291abe55efSEd Tanous { 630c5b2abe0SLewanczyk, Dawid auto led = s->substr(pos + 1); 6311abe55efSEd Tanous for (const std::pair<const char *, const char *> 6321abe55efSEd Tanous &p : 6331abe55efSEd Tanous std::array< 6346c34de48SEd Tanous std::pair<const char *, const char *>, 3>{ 6356c34de48SEd Tanous {{"On", "Lit"}, 636c5b2abe0SLewanczyk, Dawid {"Blink", "Blinking"}, 6371abe55efSEd Tanous {"Off", "Off"}}}) 6381abe55efSEd Tanous { 6391abe55efSEd Tanous if (led == p.first) 6401abe55efSEd Tanous { 641c5b2abe0SLewanczyk, Dawid output = p.second; 642c5b2abe0SLewanczyk, Dawid } 643c5b2abe0SLewanczyk, Dawid } 644c5b2abe0SLewanczyk, Dawid } 645c5b2abe0SLewanczyk, Dawid } 646c5b2abe0SLewanczyk, Dawid } 647c5b2abe0SLewanczyk, Dawid } 648c5b2abe0SLewanczyk, Dawid callback(output, aResp); 649c5b2abe0SLewanczyk, Dawid }, 650c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 651c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 652c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "GetAll", 653c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical"); 654c5b2abe0SLewanczyk, Dawid } 655c5b2abe0SLewanczyk, Dawid /** 656c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 657c5b2abe0SLewanczyk, Dawid * 658c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 659c5b2abe0SLewanczyk, Dawid * 660c5b2abe0SLewanczyk, Dawid * @return None. 661c5b2abe0SLewanczyk, Dawid */ 662a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 6631abe55efSEd Tanous { 66455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 66555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 666c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 667abf2add6SEd Tanous const std::variant<std::string> &hostState) { 6681abe55efSEd Tanous if (ec) 6691abe55efSEd Tanous { 67055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 671f12894f8SJason M. Bills messages::internalError(aResp->res); 672c5b2abe0SLewanczyk, Dawid return; 673c5b2abe0SLewanczyk, Dawid } 6746617338dSEd Tanous 675abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 67655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6776617338dSEd Tanous if (s != nullptr) 6781abe55efSEd Tanous { 679c5b2abe0SLewanczyk, Dawid // Verify Host State 68094732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6811abe55efSEd Tanous { 68255c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6836617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6841abe55efSEd Tanous } 6851abe55efSEd Tanous else 6861abe55efSEd Tanous { 68755c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6886617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 689c5b2abe0SLewanczyk, Dawid } 690c5b2abe0SLewanczyk, Dawid } 691c5b2abe0SLewanczyk, Dawid }, 6926c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6936617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6946617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 695c5b2abe0SLewanczyk, Dawid } 696c5b2abe0SLewanczyk, Dawid 697c5b2abe0SLewanczyk, Dawid /** 698491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 699491d8ee7SSantosh Puranik * 700491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 701491d8ee7SSantosh Puranik * 702491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 703491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 704491d8ee7SSantosh Puranik */ 705491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 706491d8ee7SSantosh Puranik { 707491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 708491d8ee7SSantosh Puranik { 709491d8ee7SSantosh Puranik return "None"; 710491d8ee7SSantosh Puranik } 711491d8ee7SSantosh Puranik else if (dbusSource == 712491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 713491d8ee7SSantosh Puranik { 714491d8ee7SSantosh Puranik return "Hdd"; 715491d8ee7SSantosh Puranik } 716491d8ee7SSantosh Puranik else if (dbusSource == 717a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 718491d8ee7SSantosh Puranik { 719491d8ee7SSantosh Puranik return "Cd"; 720491d8ee7SSantosh Puranik } 721491d8ee7SSantosh Puranik else if (dbusSource == 722491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 723491d8ee7SSantosh Puranik { 724491d8ee7SSantosh Puranik return "Pxe"; 725491d8ee7SSantosh Puranik } 7269f16b2c1SJennifer Lee else if (dbusSource == 727944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7289f16b2c1SJennifer Lee { 7299f16b2c1SJennifer Lee return "Usb"; 7309f16b2c1SJennifer Lee } 731491d8ee7SSantosh Puranik else 732491d8ee7SSantosh Puranik { 733491d8ee7SSantosh Puranik return ""; 734491d8ee7SSantosh Puranik } 735491d8ee7SSantosh Puranik } 736491d8ee7SSantosh Puranik 737491d8ee7SSantosh Puranik /** 738491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 739491d8ee7SSantosh Puranik * 740491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 741491d8ee7SSantosh Puranik * 742491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 743491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 744491d8ee7SSantosh Puranik */ 745491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 746491d8ee7SSantosh Puranik { 747491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 748491d8ee7SSantosh Puranik { 749491d8ee7SSantosh Puranik return "None"; 750491d8ee7SSantosh Puranik } 751491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 752491d8ee7SSantosh Puranik { 753491d8ee7SSantosh Puranik return "Diags"; 754491d8ee7SSantosh Puranik } 755491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 756491d8ee7SSantosh Puranik { 757491d8ee7SSantosh Puranik return "BiosSetup"; 758491d8ee7SSantosh Puranik } 759491d8ee7SSantosh Puranik else 760491d8ee7SSantosh Puranik { 761491d8ee7SSantosh Puranik return ""; 762491d8ee7SSantosh Puranik } 763491d8ee7SSantosh Puranik } 764491d8ee7SSantosh Puranik 765491d8ee7SSantosh Puranik /** 766944ffaf9SJohnathan Mantey * @brief Traslates boot source from Redfish to the DBus boot paths. 767491d8ee7SSantosh Puranik * 768491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 769944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 770944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 771491d8ee7SSantosh Puranik * 772944ffaf9SJohnathan Mantey * @return Integer error code. 773491d8ee7SSantosh Puranik */ 774944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 775944ffaf9SJohnathan Mantey const std::string &rfSource, 776944ffaf9SJohnathan Mantey std::string &bootSource, std::string &bootMode) 777491d8ee7SSantosh Puranik { 778944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 779944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 780944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 781944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 782944ffaf9SJohnathan Mantey // desired boot action. 783944ffaf9SJohnathan Mantey 784491d8ee7SSantosh Puranik if (rfSource == "None") 785491d8ee7SSantosh Puranik { 786944ffaf9SJohnathan Mantey return 0; 787491d8ee7SSantosh Puranik } 788491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 789491d8ee7SSantosh Puranik { 790944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 791944ffaf9SJohnathan Mantey } 792944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 793944ffaf9SJohnathan Mantey { 794944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 795944ffaf9SJohnathan Mantey } 796944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 797944ffaf9SJohnathan Mantey { 798944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 799944ffaf9SJohnathan Mantey } 800944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 801944ffaf9SJohnathan Mantey { 802944ffaf9SJohnathan Mantey bootSource = 803944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 804944ffaf9SJohnathan Mantey } 805944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 806944ffaf9SJohnathan Mantey { 807944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 808491d8ee7SSantosh Puranik } 8099f16b2c1SJennifer Lee else if (rfSource == "Usb") 8109f16b2c1SJennifer Lee { 811944ffaf9SJohnathan Mantey bootSource = 812944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 8139f16b2c1SJennifer Lee } 814491d8ee7SSantosh Puranik else 815491d8ee7SSantosh Puranik { 816944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 817944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 818944ffaf9SJohnathan Mantey << bootSource; 819944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 820944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 821944ffaf9SJohnathan Mantey return -1; 822491d8ee7SSantosh Puranik } 823944ffaf9SJohnathan Mantey return 0; 824491d8ee7SSantosh Puranik } 825491d8ee7SSantosh Puranik 826491d8ee7SSantosh Puranik /** 827491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 828491d8ee7SSantosh Puranik * 829491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 830491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 831491d8ee7SSantosh Puranik * 832491d8ee7SSantosh Puranik * @return None. 833491d8ee7SSantosh Puranik */ 834491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 835491d8ee7SSantosh Puranik std::string bootDbusObj) 836491d8ee7SSantosh Puranik { 837491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 838491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 839491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 840491d8ee7SSantosh Puranik if (ec) 841491d8ee7SSantosh Puranik { 842491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 843491d8ee7SSantosh Puranik messages::internalError(aResp->res); 844491d8ee7SSantosh Puranik return; 845491d8ee7SSantosh Puranik } 846491d8ee7SSantosh Puranik 847491d8ee7SSantosh Puranik const std::string *bootModeStr = 848491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 849491d8ee7SSantosh Puranik 850491d8ee7SSantosh Puranik if (!bootModeStr) 851491d8ee7SSantosh Puranik { 852491d8ee7SSantosh Puranik messages::internalError(aResp->res); 853491d8ee7SSantosh Puranik return; 854491d8ee7SSantosh Puranik } 855491d8ee7SSantosh Puranik 856491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 857491d8ee7SSantosh Puranik 858491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 859491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 860491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 861491d8ee7SSantosh Puranik "AllowableValues"] = { 862944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 863491d8ee7SSantosh Puranik 864491d8ee7SSantosh Puranik if (*bootModeStr != 865491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 866491d8ee7SSantosh Puranik { 867491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 868491d8ee7SSantosh Puranik if (!rfMode.empty()) 869491d8ee7SSantosh Puranik { 870491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 871491d8ee7SSantosh Puranik rfMode; 872491d8ee7SSantosh Puranik } 873491d8ee7SSantosh Puranik } 874491d8ee7SSantosh Puranik 875491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 876491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 877491d8ee7SSantosh Puranik // overrides are disabled 878491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 879491d8ee7SSantosh Puranik "None") 880491d8ee7SSantosh Puranik { 881491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 882491d8ee7SSantosh Puranik "Disabled"; 883491d8ee7SSantosh Puranik } 884491d8ee7SSantosh Puranik }, 885491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 886491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 887491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 888491d8ee7SSantosh Puranik } 889491d8ee7SSantosh Puranik 890491d8ee7SSantosh Puranik /** 891491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 892491d8ee7SSantosh Puranik * 893491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 894491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 895491d8ee7SSantosh Puranik * 896491d8ee7SSantosh Puranik * @return None. 897491d8ee7SSantosh Puranik */ 898491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 899491d8ee7SSantosh Puranik { 900491d8ee7SSantosh Puranik std::string bootDbusObj = 901491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 902491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 903491d8ee7SSantosh Puranik 904491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 905491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 906491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 907491d8ee7SSantosh Puranik 908491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 909491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 910491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 911491d8ee7SSantosh Puranik if (ec) 912491d8ee7SSantosh Puranik { 913491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 914491d8ee7SSantosh Puranik messages::internalError(aResp->res); 915491d8ee7SSantosh Puranik return; 916491d8ee7SSantosh Puranik } 917491d8ee7SSantosh Puranik 918491d8ee7SSantosh Puranik const std::string *bootSourceStr = 919491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik if (!bootSourceStr) 922491d8ee7SSantosh Puranik { 923491d8ee7SSantosh Puranik messages::internalError(aResp->res); 924491d8ee7SSantosh Puranik return; 925491d8ee7SSantosh Puranik } 926491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 927491d8ee7SSantosh Puranik 928491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 929491d8ee7SSantosh Puranik if (!rfSource.empty()) 930491d8ee7SSantosh Puranik { 931491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 932491d8ee7SSantosh Puranik rfSource; 933491d8ee7SSantosh Puranik } 934491d8ee7SSantosh Puranik }, 935491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 936491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 937491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 938491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 939491d8ee7SSantosh Puranik } 940491d8ee7SSantosh Puranik 941491d8ee7SSantosh Puranik /** 942491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 943491d8ee7SSantosh Puranik * get boot source and boot mode. 944491d8ee7SSantosh Puranik * 945491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 946491d8ee7SSantosh Puranik * 947491d8ee7SSantosh Puranik * @return None. 948491d8ee7SSantosh Puranik */ 949491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 950491d8ee7SSantosh Puranik { 951491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 952491d8ee7SSantosh Puranik 953491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 954c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 955491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 956491d8ee7SSantosh Puranik if (ec) 957491d8ee7SSantosh Puranik { 958491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9592a833c77SJames Feist // not an error, don't have to have the interface 960491d8ee7SSantosh Puranik return; 961491d8ee7SSantosh Puranik } 962491d8ee7SSantosh Puranik 963491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 964491d8ee7SSantosh Puranik 965491d8ee7SSantosh Puranik if (!oneTimePtr) 966491d8ee7SSantosh Puranik { 967491d8ee7SSantosh Puranik messages::internalError(aResp->res); 968491d8ee7SSantosh Puranik return; 969491d8ee7SSantosh Puranik } 970491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 971491d8ee7SSantosh Puranik }, 972491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 973491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 974491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 975491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 976491d8ee7SSantosh Puranik } 977491d8ee7SSantosh Puranik 978491d8ee7SSantosh Puranik /** 979491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 980491d8ee7SSantosh Puranik * 981491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 982491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 983491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 984491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 985491d8ee7SSantosh Puranik * 986265c1602SJohnathan Mantey * @return Integer error code. 987491d8ee7SSantosh Puranik */ 988491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 989491d8ee7SSantosh Puranik bool oneTimeEnabled, 990491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 991491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 992491d8ee7SSantosh Puranik { 993944ffaf9SJohnathan Mantey std::string bootSourceStr = 994944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 995944ffaf9SJohnathan Mantey std::string bootModeStr = 996944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 997491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 998944ffaf9SJohnathan Mantey bool useBootSource = true; 999944ffaf9SJohnathan Mantey 1000491d8ee7SSantosh Puranik // Validate incoming parameters 1001491d8ee7SSantosh Puranik if (bootEnable) 1002491d8ee7SSantosh Puranik { 1003491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1004491d8ee7SSantosh Puranik { 1005491d8ee7SSantosh Puranik oneTimeSetting = true; 1006491d8ee7SSantosh Puranik } 1007491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1008491d8ee7SSantosh Puranik { 1009491d8ee7SSantosh Puranik oneTimeSetting = false; 1010491d8ee7SSantosh Puranik } 1011491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1012491d8ee7SSantosh Puranik { 1013944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1014491d8ee7SSantosh Puranik oneTimeSetting = false; 1015944ffaf9SJohnathan Mantey useBootSource = false; 1016491d8ee7SSantosh Puranik } 1017491d8ee7SSantosh Puranik else 1018491d8ee7SSantosh Puranik { 1019491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1020491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1021491d8ee7SSantosh Puranik << *bootEnable; 1022491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1023491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1024491d8ee7SSantosh Puranik return; 1025491d8ee7SSantosh Puranik } 1026491d8ee7SSantosh Puranik } 1027491d8ee7SSantosh Puranik 1028944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1029491d8ee7SSantosh Puranik { 1030491d8ee7SSantosh Puranik // Source target specified 1031491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1032491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1033944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1034944ffaf9SJohnathan Mantey bootModeStr)) 1035491d8ee7SSantosh Puranik { 1036944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1037944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1038491d8ee7SSantosh Puranik << *bootSource; 1039491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1040491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1041491d8ee7SSantosh Puranik return; 1042491d8ee7SSantosh Puranik } 1043944ffaf9SJohnathan Mantey } 1044491d8ee7SSantosh Puranik 1045944ffaf9SJohnathan Mantey // Act on validated parameters 1046944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1047944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1048944ffaf9SJohnathan Mantey const char *bootObj = 1049944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1050944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1051944ffaf9SJohnathan Mantey 1052491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1053491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1054491d8ee7SSantosh Puranik if (ec) 1055491d8ee7SSantosh Puranik { 1056491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1057491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1058491d8ee7SSantosh Puranik return; 1059491d8ee7SSantosh Puranik } 1060491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1061491d8ee7SSantosh Puranik }, 1062491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1063491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1064491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1065491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1066944ffaf9SJohnathan Mantey 1067491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1068491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1069491d8ee7SSantosh Puranik if (ec) 1070491d8ee7SSantosh Puranik { 1071491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1072491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1073491d8ee7SSantosh Puranik return; 1074491d8ee7SSantosh Puranik } 1075491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1076491d8ee7SSantosh Puranik }, 1077491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1078491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1079491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1080491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1081944ffaf9SJohnathan Mantey 1082491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1083491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1084491d8ee7SSantosh Puranik if (ec) 1085491d8ee7SSantosh Puranik { 1086491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1087491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1088491d8ee7SSantosh Puranik return; 1089491d8ee7SSantosh Puranik } 1090491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1091491d8ee7SSantosh Puranik }, 1092491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1093491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1094491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1095491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1096491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1097491d8ee7SSantosh Puranik } 1098491d8ee7SSantosh Puranik 1099491d8ee7SSantosh Puranik /** 1100491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1101491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1102491d8ee7SSantosh Puranik * 1103491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1104491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1105491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1106491d8ee7SSantosh Puranik * 1107265c1602SJohnathan Mantey * @return Integer error code. 1108491d8ee7SSantosh Puranik */ 1109491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1110491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1111491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1112491d8ee7SSantosh Puranik { 1113491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1114491d8ee7SSantosh Puranik 1115491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1116265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1117491d8ee7SSantosh Puranik bootEnable{std::move(bootEnable)}]( 1118491d8ee7SSantosh Puranik const boost::system::error_code ec, 1119491d8ee7SSantosh Puranik const sdbusplus::message::variant<bool> &oneTime) { 1120491d8ee7SSantosh Puranik if (ec) 1121491d8ee7SSantosh Puranik { 1122491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1123491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1124491d8ee7SSantosh Puranik return; 1125491d8ee7SSantosh Puranik } 1126491d8ee7SSantosh Puranik 1127491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1128491d8ee7SSantosh Puranik 1129491d8ee7SSantosh Puranik if (!oneTimePtr) 1130491d8ee7SSantosh Puranik { 1131491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1132491d8ee7SSantosh Puranik return; 1133491d8ee7SSantosh Puranik } 1134491d8ee7SSantosh Puranik 1135491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1136491d8ee7SSantosh Puranik 1137491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1138491d8ee7SSantosh Puranik std::move(bootEnable)); 1139491d8ee7SSantosh Puranik }, 1140491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1141491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1142491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1143491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1144491d8ee7SSantosh Puranik } 1145491d8ee7SSantosh Puranik 1146491d8ee7SSantosh Puranik /** 1147c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1148c5b2abe0SLewanczyk, Dawid * Schema 1149c5b2abe0SLewanczyk, Dawid */ 11501abe55efSEd Tanous class SystemsCollection : public Node 11511abe55efSEd Tanous { 1152c5b2abe0SLewanczyk, Dawid public: 11531abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 11541abe55efSEd Tanous { 1155c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1156c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1157c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1158c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1159c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1160c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1161c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1162c5b2abe0SLewanczyk, Dawid } 1163c5b2abe0SLewanczyk, Dawid 1164c5b2abe0SLewanczyk, Dawid private: 116555c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 11661abe55efSEd Tanous const std::vector<std::string> ¶ms) override 11671abe55efSEd Tanous { 11680f74e643SEd Tanous res.jsonValue["@odata.type"] = 11690f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 11700f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 11710f74e643SEd Tanous res.jsonValue["@odata.context"] = 11720f74e643SEd Tanous "/redfish/v1/" 11730f74e643SEd Tanous "$metadata#ComputerSystemCollection.ComputerSystemCollection"; 11740f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1175029573d4SEd Tanous res.jsonValue["Members"] = { 1176029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}}; 1177029573d4SEd Tanous res.jsonValue["Members@odata.count"] = 1; 1178029573d4SEd Tanous res.end(); 1179c5b2abe0SLewanczyk, Dawid } 1180c5b2abe0SLewanczyk, Dawid }; 1181c5b2abe0SLewanczyk, Dawid 1182c5b2abe0SLewanczyk, Dawid /** 1183cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1184cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1185cc340dd9SEd Tanous */ 1186cc340dd9SEd Tanous class SystemActionsReset : public Node 1187cc340dd9SEd Tanous { 1188cc340dd9SEd Tanous public: 1189cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1190029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1191cc340dd9SEd Tanous { 1192cc340dd9SEd Tanous entityPrivileges = { 1193cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1194cc340dd9SEd Tanous } 1195cc340dd9SEd Tanous 1196cc340dd9SEd Tanous private: 1197cc340dd9SEd Tanous /** 1198cc340dd9SEd Tanous * Function handles POST method request. 1199cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1200cc340dd9SEd Tanous */ 1201cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1202cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1203cc340dd9SEd Tanous { 1204cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1205cc340dd9SEd Tanous 12069712f8acSEd Tanous std::string resetType; 12079712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1208cc340dd9SEd Tanous { 1209cc340dd9SEd Tanous return; 1210cc340dd9SEd Tanous } 1211cc340dd9SEd Tanous 1212d22c8396SJason M. Bills // Get the command and host vs. chassis 1213cc340dd9SEd Tanous std::string command; 1214d22c8396SJason M. Bills bool hostCommand; 12159712f8acSEd Tanous if (resetType == "On") 1216cc340dd9SEd Tanous { 1217cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1218d22c8396SJason M. Bills hostCommand = true; 1219d22c8396SJason M. Bills } 1220d22c8396SJason M. Bills else if (resetType == "ForceOff") 1221d22c8396SJason M. Bills { 1222d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1223d22c8396SJason M. Bills hostCommand = false; 1224d22c8396SJason M. Bills } 1225d22c8396SJason M. Bills else if (resetType == "ForceOn") 1226d22c8396SJason M. Bills { 1227d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1228d22c8396SJason M. Bills hostCommand = true; 1229d22c8396SJason M. Bills } 1230d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1231d22c8396SJason M. Bills { 1232d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Reset"; 1233d22c8396SJason M. Bills hostCommand = false; 1234cc340dd9SEd Tanous } 12359712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1236cc340dd9SEd Tanous { 1237cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1238d22c8396SJason M. Bills hostCommand = true; 1239cc340dd9SEd Tanous } 12409712f8acSEd Tanous else if (resetType == "GracefulRestart") 1241cc340dd9SEd Tanous { 12429712f8acSEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 1243d22c8396SJason M. Bills hostCommand = true; 1244d22c8396SJason M. Bills } 1245d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1246d22c8396SJason M. Bills { 1247d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; 1248d22c8396SJason M. Bills hostCommand = false; 1249cc340dd9SEd Tanous } 1250bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1251bfd5b826SLakshminarayana R. Kammath { 1252bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1253bfd5b826SLakshminarayana R. Kammath return; 1254bfd5b826SLakshminarayana R. Kammath } 1255cc340dd9SEd Tanous else 1256cc340dd9SEd Tanous { 1257f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1258cc340dd9SEd Tanous return; 1259cc340dd9SEd Tanous } 1260cc340dd9SEd Tanous 1261d22c8396SJason M. Bills if (hostCommand) 1262d22c8396SJason M. Bills { 1263cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1264d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1265cc340dd9SEd Tanous if (ec) 1266cc340dd9SEd Tanous { 1267cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1268d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1269d22c8396SJason M. Bills { 1270d22c8396SJason M. Bills messages::actionParameterNotSupported( 1271d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1272d22c8396SJason M. Bills } 1273d22c8396SJason M. Bills else 1274d22c8396SJason M. Bills { 1275f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1276d22c8396SJason M. Bills } 1277cc340dd9SEd Tanous return; 1278cc340dd9SEd Tanous } 1279f12894f8SJason M. Bills messages::success(asyncResp->res); 1280cc340dd9SEd Tanous }, 1281cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1282cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1283cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 12849712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1285abf2add6SEd Tanous std::variant<std::string>{command}); 1286cc340dd9SEd Tanous } 1287d22c8396SJason M. Bills else 1288d22c8396SJason M. Bills { 1289d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1290d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1291d22c8396SJason M. Bills if (ec) 1292d22c8396SJason M. Bills { 1293d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1294d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1295d22c8396SJason M. Bills { 1296d22c8396SJason M. Bills messages::actionParameterNotSupported( 1297d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1298d22c8396SJason M. Bills } 1299d22c8396SJason M. Bills else 1300d22c8396SJason M. Bills { 1301d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1302d22c8396SJason M. Bills } 1303d22c8396SJason M. Bills return; 1304d22c8396SJason M. Bills } 1305d22c8396SJason M. Bills messages::success(asyncResp->res); 1306d22c8396SJason M. Bills }, 1307d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1308d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1309d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1310d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1311d22c8396SJason M. Bills std::variant<std::string>{command}); 1312d22c8396SJason M. Bills } 1313d22c8396SJason M. Bills } 1314bfd5b826SLakshminarayana R. Kammath /** 1315bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1316bfd5b826SLakshminarayana R. Kammath */ 1317bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1318bfd5b826SLakshminarayana R. Kammath { 1319bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1320bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1321bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1322bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1323bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1324bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1325bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1326bfd5b826SLakshminarayana R. Kammath 1327bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1328bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1329bfd5b826SLakshminarayana R. Kammath if (ec) 1330bfd5b826SLakshminarayana R. Kammath { 1331bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1332bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1333bfd5b826SLakshminarayana R. Kammath return; 1334bfd5b826SLakshminarayana R. Kammath } 1335bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1336bfd5b826SLakshminarayana R. Kammath }, 1337bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1338bfd5b826SLakshminarayana R. Kammath } 1339cc340dd9SEd Tanous }; 1340cc340dd9SEd Tanous 1341cc340dd9SEd Tanous /** 13426617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1343c5b2abe0SLewanczyk, Dawid */ 13441abe55efSEd Tanous class Systems : public Node 13451abe55efSEd Tanous { 1346c5b2abe0SLewanczyk, Dawid public: 1347c5b2abe0SLewanczyk, Dawid /* 1348c5b2abe0SLewanczyk, Dawid * Default Constructor 1349c5b2abe0SLewanczyk, Dawid */ 1350029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 13511abe55efSEd Tanous { 1352c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1353c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1354c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1355c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1356c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1357c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1358c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1359c5b2abe0SLewanczyk, Dawid } 1360c5b2abe0SLewanczyk, Dawid 1361c5b2abe0SLewanczyk, Dawid private: 1362c5b2abe0SLewanczyk, Dawid /** 1363c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1364c5b2abe0SLewanczyk, Dawid */ 136555c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 13661abe55efSEd Tanous const std::vector<std::string> ¶ms) override 13671abe55efSEd Tanous { 1368491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 13690f74e643SEd Tanous res.jsonValue["@odata.context"] = 13700f74e643SEd Tanous "/redfish/v1/$metadata#ComputerSystem.ComputerSystem"; 1371029573d4SEd Tanous res.jsonValue["Name"] = "Computer System"; 1372029573d4SEd Tanous res.jsonValue["Id"] = "system"; 13730f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 13740f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 13750f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 13760f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 13770f74e643SEd Tanous res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0); 13780f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1379029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 138004a258f4SEd Tanous 1381443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1382029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1383443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1384029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1385029573d4SEd Tanous 1386cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1387cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1388cc340dd9SEd Tanous {"target", 1389029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1390cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1391d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1392bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1393c5b2abe0SLewanczyk, Dawid 1394c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1395029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1396c4bf6374SJason M. Bills 1397c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1398c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1399c5d03ff4SJennifer Lee 1400c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1401c5d03ff4SJennifer Lee {"Health", "OK"}, 1402c5d03ff4SJennifer Lee {"State", "Enabled"}, 1403c5d03ff4SJennifer Lee }; 1404a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1405c5b2abe0SLewanczyk, Dawid 1406b49ac873SJames Feist constexpr const std::array<const char *, 2> inventoryForSystems = { 1407b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 1408b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu"}; 1409b49ac873SJames Feist 1410b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1411b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1412b49ac873SJames Feist [health](const boost::system::error_code ec, 1413b49ac873SJames Feist std::vector<std::string> &resp) { 1414b49ac873SJames Feist if (ec) 1415b49ac873SJames Feist { 1416b49ac873SJames Feist // no inventory 1417b49ac873SJames Feist return; 1418b49ac873SJames Feist } 1419b49ac873SJames Feist 1420b49ac873SJames Feist health->inventory = std::move(resp); 1421b49ac873SJames Feist }, 1422b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1423b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1424b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1425b49ac873SJames Feist int32_t(0), inventoryForSystems); 1426b49ac873SJames Feist 1427b49ac873SJames Feist health->populate(); 1428b49ac873SJames Feist 1429c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1430c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1431c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1432c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1433c5d03ff4SJennifer Lee }); 14346c34de48SEd Tanous getLedGroupIdentify( 1435a0803efaSEd Tanous asyncResp, 1436c5d03ff4SJennifer Lee [](const bool &asserted, const std::shared_ptr<AsyncResp> aRsp) { 14371abe55efSEd Tanous if (asserted) 14381abe55efSEd Tanous { 1439c5b2abe0SLewanczyk, Dawid // If led group is asserted, then another call is needed to 1440c5b2abe0SLewanczyk, Dawid // get led status 14416c34de48SEd Tanous getLedIdentify( 1442c5d03ff4SJennifer Lee aRsp, [](const std::string &ledStatus, 1443c5d03ff4SJennifer Lee const std::shared_ptr<AsyncResp> aRsp) { 14441abe55efSEd Tanous if (!ledStatus.empty()) 14451abe55efSEd Tanous { 1446c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = ledStatus; 1447c5b2abe0SLewanczyk, Dawid } 1448c5b2abe0SLewanczyk, Dawid }); 14491abe55efSEd Tanous } 14501abe55efSEd Tanous else 14511abe55efSEd Tanous { 1452c5d03ff4SJennifer Lee aRsp->res.jsonValue["IndicatorLED"] = "Off"; 1453c5b2abe0SLewanczyk, Dawid } 1454c5b2abe0SLewanczyk, Dawid }); 1455029573d4SEd Tanous getComputerSystem(asyncResp); 14566c34de48SEd Tanous getHostState(asyncResp); 1457491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1458f5c9f8bdSJason M. Bills getPCIeDeviceList(asyncResp); 1459c5b2abe0SLewanczyk, Dawid } 1460c5b2abe0SLewanczyk, Dawid 146155c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 14621abe55efSEd Tanous const std::vector<std::string> ¶ms) override 14631abe55efSEd Tanous { 1464cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1465491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 146641352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 146741352c24SSantosh Puranik 1468944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1469944ffaf9SJohnathan Mantey bootProps)) 14706617338dSEd Tanous { 14716617338dSEd Tanous return; 14726617338dSEd Tanous } 1473491d8ee7SSantosh Puranik 1474944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1475491d8ee7SSantosh Puranik if (bootProps) 1476491d8ee7SSantosh Puranik { 1477491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1478491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1479491d8ee7SSantosh Puranik 1480491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1481491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1482491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1483491d8ee7SSantosh Puranik { 1484491d8ee7SSantosh Puranik return; 1485491d8ee7SSantosh Puranik } 1486491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1487491d8ee7SSantosh Puranik std::move(bootEnable)); 1488491d8ee7SSantosh Puranik } 1489265c1602SJohnathan Mantey 14909712f8acSEd Tanous if (indicatorLed) 14916617338dSEd Tanous { 14929712f8acSEd Tanous std::string dbusLedState; 1493d573bb2aSJennifer Lee if (*indicatorLed == "Lit") 14949712f8acSEd Tanous { 1495d573bb2aSJennifer Lee dbusLedState = "xyz.openbmc_project.Led.Physical.Action.On"; 14966617338dSEd Tanous } 14975c6221acSGunnar Mills else if (*indicatorLed == "Blinking") 14986617338dSEd Tanous { 14995c6221acSGunnar Mills dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Blink"; 15006617338dSEd Tanous } 15019712f8acSEd Tanous else if (*indicatorLed == "Off") 15026617338dSEd Tanous { 15039712f8acSEd Tanous dbusLedState = "xyz.openbmc_project.Led.Physical.Action.Off"; 15046617338dSEd Tanous } 15056617338dSEd Tanous else 15066617338dSEd Tanous { 1507a08b46ccSJason M. Bills messages::propertyValueNotInList(res, *indicatorLed, 1508a08b46ccSJason M. Bills "IndicatorLED"); 15096617338dSEd Tanous return; 15106617338dSEd Tanous } 15116617338dSEd Tanous 1512c5b2abe0SLewanczyk, Dawid // Update led group 151355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led group."; 151455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1515cde19e5fSSantosh Puranik [asyncResp](const boost::system::error_code ec) { 15161abe55efSEd Tanous if (ec) 15171abe55efSEd Tanous { 151855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1519f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1520c5b2abe0SLewanczyk, Dawid return; 1521c5b2abe0SLewanczyk, Dawid } 152255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led group update done."; 1523c5b2abe0SLewanczyk, Dawid }, 1524c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.GroupManager", 1525c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/groups/enclosure_identify", 1526c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1527c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Group", "Asserted", 1528abf2add6SEd Tanous std::variant<bool>( 1529265c1602SJohnathan Mantey (dbusLedState != 1530265c1602SJohnathan Mantey "xyz.openbmc_project.Led.Physical.Action.Off"))); 1531265c1602SJohnathan Mantey 1532c5b2abe0SLewanczyk, Dawid // Update identify led status 153355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Update led SoftwareInventoryCollection."; 153455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1535265c1602SJohnathan Mantey [asyncResp](const boost::system::error_code ec) { 15361abe55efSEd Tanous if (ec) 15371abe55efSEd Tanous { 153855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1539f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1540c5b2abe0SLewanczyk, Dawid return; 1541c5b2abe0SLewanczyk, Dawid } 154255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Led state update done."; 1543c5b2abe0SLewanczyk, Dawid }, 1544c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.LED.Controller.identify", 1545c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/led/physical/identify", 1546c5b2abe0SLewanczyk, Dawid "org.freedesktop.DBus.Properties", "Set", 1547c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.Led.Physical", "State", 1548abf2add6SEd Tanous std::variant<std::string>(dbusLedState)); 15496617338dSEd Tanous } 1550c5b2abe0SLewanczyk, Dawid } 1551c5b2abe0SLewanczyk, Dawid }; 1552c5b2abe0SLewanczyk, Dawid } // namespace redfish 1553