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" 191c8fba97SJames Feist #include "led.hpp" 20f5c9f8bdSJason M. Bills #include "pcie.hpp" 21c5d03ff4SJennifer Lee #include "redfish_util.hpp" 22c5d03ff4SJennifer Lee 239712f8acSEd Tanous #include <boost/container/flat_map.hpp> 249712f8acSEd Tanous #include <node.hpp> 25cb7e1e7bSAndrew Geissler #include <utils/fw_utils.hpp> 26c5b2abe0SLewanczyk, Dawid #include <utils/json_utils.hpp> 27abf2add6SEd Tanous #include <variant> 28c5b2abe0SLewanczyk, Dawid 291abe55efSEd Tanous namespace redfish 301abe55efSEd Tanous { 31c5b2abe0SLewanczyk, Dawid 329d3ae10eSAlpana Kumari /** 339d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 349d3ae10eSAlpana Kumari * 359d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 369d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 379d3ae10eSAlpana Kumari * 389d3ae10eSAlpana Kumari * @return None. 399d3ae10eSAlpana Kumari */ 409d3ae10eSAlpana Kumari void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, 419d3ae10eSAlpana Kumari const std::variant<bool> &dimmState) 429d3ae10eSAlpana Kumari { 439d3ae10eSAlpana Kumari const bool *isDimmFunctional = std::get_if<bool>(&dimmState); 449d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 459d3ae10eSAlpana Kumari { 469d3ae10eSAlpana Kumari messages::internalError(aResp->res); 479d3ae10eSAlpana Kumari return; 489d3ae10eSAlpana Kumari } 499d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 509d3ae10eSAlpana Kumari 519d3ae10eSAlpana Kumari // Set it as Enabled if atleast one DIMM is functional 529d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 539d3ae10eSAlpana Kumari // ENABLED. 549d3ae10eSAlpana Kumari nlohmann::json &prevMemSummary = 559d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 569d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 579d3ae10eSAlpana Kumari { 589d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 599d3ae10eSAlpana Kumari { 609d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 619d3ae10eSAlpana Kumari "Enabled"; 629d3ae10eSAlpana Kumari } 639d3ae10eSAlpana Kumari } 649d3ae10eSAlpana Kumari } 659d3ae10eSAlpana Kumari 6657e8c9beSAlpana Kumari /* 6757e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 6857e8c9beSAlpana Kumari * 6957e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7057e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7157e8c9beSAlpana Kumari * 7257e8c9beSAlpana Kumari * @return None. 7357e8c9beSAlpana Kumari */ 7457e8c9beSAlpana Kumari void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, 7557e8c9beSAlpana Kumari const std::variant<bool> &cpuPresenceState) 7657e8c9beSAlpana Kumari { 7757e8c9beSAlpana Kumari const bool *isCpuPresent = std::get_if<bool>(&cpuPresenceState); 7857e8c9beSAlpana Kumari 7957e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 8057e8c9beSAlpana Kumari { 8157e8c9beSAlpana Kumari messages::internalError(aResp->res); 8257e8c9beSAlpana Kumari return; 8357e8c9beSAlpana Kumari } 8457e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8557e8c9beSAlpana Kumari 8657e8c9beSAlpana Kumari if (*isCpuPresent == true) 8757e8c9beSAlpana Kumari { 88b4b9595aSJames Feist nlohmann::json &procCount = 89b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 90b4b9595aSJames Feist auto procCountPtr = 91b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t *>(); 92b4b9595aSJames Feist if (procCountPtr != nullptr) 93b4b9595aSJames Feist { 94b4b9595aSJames Feist // shouldn't be possible to be nullptr 95b4b9595aSJames Feist *procCountPtr += 1; 9657e8c9beSAlpana Kumari } 97b4b9595aSJames Feist } 9857e8c9beSAlpana Kumari } 9957e8c9beSAlpana Kumari 10057e8c9beSAlpana Kumari /* 10157e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10257e8c9beSAlpana Kumari * CPU Functional State 10357e8c9beSAlpana Kumari * 10457e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10557e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10657e8c9beSAlpana Kumari * 10757e8c9beSAlpana Kumari * @return None. 10857e8c9beSAlpana Kumari */ 10957e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, 11057e8c9beSAlpana Kumari const std::variant<bool> &cpuFunctionalState) 11157e8c9beSAlpana Kumari { 11257e8c9beSAlpana Kumari const bool *isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11357e8c9beSAlpana Kumari 11457e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 11557e8c9beSAlpana Kumari { 11657e8c9beSAlpana Kumari messages::internalError(aResp->res); 11757e8c9beSAlpana Kumari return; 11857e8c9beSAlpana Kumari } 11957e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 12057e8c9beSAlpana Kumari 12157e8c9beSAlpana Kumari nlohmann::json &prevProcState = 12257e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12357e8c9beSAlpana Kumari 12457e8c9beSAlpana Kumari // Set it as Enabled if atleast one CPU is functional 12557e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12657e8c9beSAlpana Kumari // Functional. 12757e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12857e8c9beSAlpana Kumari { 12957e8c9beSAlpana Kumari if (*isCpuFunctional == true) 13057e8c9beSAlpana Kumari { 13157e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13257e8c9beSAlpana Kumari "Enabled"; 13357e8c9beSAlpana Kumari } 13457e8c9beSAlpana Kumari } 13557e8c9beSAlpana Kumari } 13657e8c9beSAlpana Kumari 13757e8c9beSAlpana Kumari /* 138c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 139c5b2abe0SLewanczyk, Dawid * 140c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 141c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 142c5b2abe0SLewanczyk, Dawid * 143c5b2abe0SLewanczyk, Dawid * @return None. 144c5b2abe0SLewanczyk, Dawid */ 1455bc2dc8eSJames Feist void getComputerSystem(std::shared_ptr<AsyncResp> aResp, 1465bc2dc8eSJames Feist std::shared_ptr<HealthPopulate> systemHealth) 1471abe55efSEd Tanous { 14855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1499d3ae10eSAlpana Kumari 15055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1515bc2dc8eSJames Feist [aResp, systemHealth]( 152c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 153c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1546c34de48SEd Tanous std::string, 1556c34de48SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>>> 156c5b2abe0SLewanczyk, Dawid &subtree) { 1571abe55efSEd Tanous if (ec) 1581abe55efSEd Tanous { 15955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 160f12894f8SJason M. Bills messages::internalError(aResp->res); 161c5b2abe0SLewanczyk, Dawid return; 162c5b2abe0SLewanczyk, Dawid } 163c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1646c34de48SEd Tanous for (const std::pair<std::string, 1656c34de48SEd Tanous std::vector<std::pair< 1666c34de48SEd Tanous std::string, std::vector<std::string>>>> 1671abe55efSEd Tanous &object : subtree) 1681abe55efSEd Tanous { 169c5b2abe0SLewanczyk, Dawid const std::string &path = object.first; 17055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1711abe55efSEd Tanous const std::vector< 1721abe55efSEd Tanous std::pair<std::string, std::vector<std::string>>> 173c5b2abe0SLewanczyk, Dawid &connectionNames = object.second; 1741abe55efSEd Tanous if (connectionNames.size() < 1) 1751abe55efSEd Tanous { 176c5b2abe0SLewanczyk, Dawid continue; 177c5b2abe0SLewanczyk, Dawid } 178029573d4SEd Tanous 1795bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1805bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1815bc2dc8eSJames Feist 1825bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1835bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1845bc2dc8eSJames Feist 1855bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1865bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1875bc2dc8eSJames Feist 1886c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1896c34de48SEd Tanous // BiosVer 19004a258f4SEd Tanous for (const auto &connection : connectionNames) 1911abe55efSEd Tanous { 19204a258f4SEd Tanous for (const auto &interfaceName : connection.second) 1931abe55efSEd Tanous { 19404a258f4SEd Tanous if (interfaceName == 19504a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1961abe55efSEd Tanous { 1971abe55efSEd Tanous BMCWEB_LOG_DEBUG 19804a258f4SEd Tanous << "Found Dimm, now get its properties."; 1999d3ae10eSAlpana Kumari 20055c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2019d3ae10eSAlpana Kumari [aResp, service{connection.first}, 2029d3ae10eSAlpana Kumari path(std::move(path))]( 2039d3ae10eSAlpana Kumari const boost::system::error_code ec, 2046c34de48SEd Tanous const std::vector< 2056c34de48SEd Tanous std::pair<std::string, VariantType>> 2061abe55efSEd Tanous &properties) { 2071abe55efSEd Tanous if (ec) 2081abe55efSEd Tanous { 2091abe55efSEd Tanous BMCWEB_LOG_ERROR 2106c34de48SEd Tanous << "DBUS response error " << ec; 211f12894f8SJason M. Bills messages::internalError(aResp->res); 212c5b2abe0SLewanczyk, Dawid return; 213c5b2abe0SLewanczyk, Dawid } 2146c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2156c34de48SEd Tanous << properties.size() 216c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2179d3ae10eSAlpana Kumari 2189d3ae10eSAlpana Kumari if (properties.size() > 0) 2199d3ae10eSAlpana Kumari { 22004a258f4SEd Tanous for (const std::pair<std::string, 22104a258f4SEd Tanous VariantType> 22204a258f4SEd Tanous &property : properties) 2231abe55efSEd Tanous { 2245fd7ba65SCheng C Yang if (property.first != 2255fd7ba65SCheng C Yang "MemorySizeInKB") 2261abe55efSEd Tanous { 2275fd7ba65SCheng C Yang continue; 2285fd7ba65SCheng C Yang } 2295fd7ba65SCheng C Yang const uint32_t *value = 2308d78b7a9SPatrick Williams std::get_if<uint32_t>( 2311b6b96c5SEd Tanous &property.second); 2325fd7ba65SCheng C Yang if (value == nullptr) 2331abe55efSEd Tanous { 2345fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2355fd7ba65SCheng C Yang << "Find incorrect type of " 2365fd7ba65SCheng C Yang "MemorySize"; 2375fd7ba65SCheng C Yang continue; 2385fd7ba65SCheng C Yang } 2395fd7ba65SCheng C Yang nlohmann::json &totalMemory = 2405fd7ba65SCheng C Yang aResp->res 2415fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2425fd7ba65SCheng C Yang "y"] 2435fd7ba65SCheng C Yang ["TotalSystemMe" 2445fd7ba65SCheng C Yang "moryGiB"]; 2455fd7ba65SCheng C Yang uint64_t *preValue = 2465fd7ba65SCheng C Yang totalMemory 2475fd7ba65SCheng C Yang .get_ptr<uint64_t *>(); 2485fd7ba65SCheng C Yang if (preValue == nullptr) 2495fd7ba65SCheng C Yang { 2505fd7ba65SCheng C Yang continue; 2515fd7ba65SCheng C Yang } 2525fd7ba65SCheng C Yang aResp->res 2535fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2546c34de48SEd Tanous ["TotalSystemMemoryGi" 2555fd7ba65SCheng C Yang "B"] = 2565fd7ba65SCheng C Yang *value / (1024 * 1024) + 2575fd7ba65SCheng C Yang *preValue; 2585fd7ba65SCheng C Yang aResp->res 2595fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2609d3ae10eSAlpana Kumari ["Status"]["State"] = 2611abe55efSEd Tanous "Enabled"; 262c5b2abe0SLewanczyk, Dawid } 263c5b2abe0SLewanczyk, Dawid } 2649d3ae10eSAlpana Kumari else 2659d3ae10eSAlpana Kumari { 2669d3ae10eSAlpana Kumari auto getDimmProperties = 2679d3ae10eSAlpana Kumari [aResp]( 2689d3ae10eSAlpana Kumari const boost::system::error_code 2699d3ae10eSAlpana Kumari ec, 2709d3ae10eSAlpana Kumari const std::variant<bool> 2719d3ae10eSAlpana Kumari &dimmState) { 2729d3ae10eSAlpana Kumari if (ec) 2739d3ae10eSAlpana Kumari { 2749d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2759d3ae10eSAlpana Kumari << "DBUS response " 2769d3ae10eSAlpana Kumari "error " 2779d3ae10eSAlpana Kumari << ec; 2789d3ae10eSAlpana Kumari return; 2799d3ae10eSAlpana Kumari } 2809d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2819d3ae10eSAlpana Kumari dimmState); 2829d3ae10eSAlpana Kumari }; 2839d3ae10eSAlpana Kumari crow::connections::systemBus 2849d3ae10eSAlpana Kumari ->async_method_call( 2859d3ae10eSAlpana Kumari std::move(getDimmProperties), 2869d3ae10eSAlpana Kumari service, path, 2879d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2889d3ae10eSAlpana Kumari "Properties", 2899d3ae10eSAlpana Kumari "Get", 2909d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2919d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2929d3ae10eSAlpana Kumari "Functional"); 2939d3ae10eSAlpana Kumari } 294c5b2abe0SLewanczyk, Dawid }, 29504a258f4SEd Tanous connection.first, path, 2966c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2976c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2985bc2dc8eSJames Feist 2995bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3001abe55efSEd Tanous } 30104a258f4SEd Tanous else if (interfaceName == 30204a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3031abe55efSEd Tanous { 3041abe55efSEd Tanous BMCWEB_LOG_DEBUG 30504a258f4SEd Tanous << "Found Cpu, now get its properties."; 30657e8c9beSAlpana Kumari 307a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 30857e8c9beSAlpana Kumari [aResp, service{connection.first}, 30957e8c9beSAlpana Kumari path(std::move(path))]( 31057e8c9beSAlpana Kumari const boost::system::error_code ec, 3116c34de48SEd Tanous const std::vector< 3126c34de48SEd Tanous std::pair<std::string, VariantType>> 3131abe55efSEd Tanous &properties) { 3141abe55efSEd Tanous if (ec) 3151abe55efSEd Tanous { 3161abe55efSEd Tanous BMCWEB_LOG_ERROR 3176c34de48SEd Tanous << "DBUS response error " << ec; 318f12894f8SJason M. Bills messages::internalError(aResp->res); 319c5b2abe0SLewanczyk, Dawid return; 320c5b2abe0SLewanczyk, Dawid } 3216c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3226c34de48SEd Tanous << properties.size() 323c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32457e8c9beSAlpana Kumari 32557e8c9beSAlpana Kumari if (properties.size() > 0) 32657e8c9beSAlpana Kumari { 32704a258f4SEd Tanous for (const auto &property : properties) 3281abe55efSEd Tanous { 32957e8c9beSAlpana Kumari if (property.first == 33057e8c9beSAlpana Kumari "ProcessorFamily") 3311abe55efSEd Tanous { 332a0803efaSEd Tanous const std::string *value = 3338d78b7a9SPatrick Williams std::get_if<std::string>( 3341b6b96c5SEd Tanous &property.second); 3351abe55efSEd Tanous if (value != nullptr) 3361abe55efSEd Tanous { 33757e8c9beSAlpana Kumari nlohmann::json 33857e8c9beSAlpana Kumari &procSummary = 3391abe55efSEd Tanous aResp->res.jsonValue 3406c34de48SEd Tanous ["ProcessorSumm" 34104a258f4SEd Tanous "ary"]; 34204a258f4SEd Tanous nlohmann::json &procCount = 34304a258f4SEd Tanous procSummary["Count"]; 344b4b9595aSJames Feist 345b4b9595aSJames Feist auto procCountPtr = 346b4b9595aSJames Feist procCount.get_ptr< 347b4b9595aSJames Feist nlohmann::json:: 348b4b9595aSJames Feist number_integer_t 349b4b9595aSJames Feist *>(); 350b4b9595aSJames Feist if (procCountPtr != nullptr) 351b4b9595aSJames Feist { 352b4b9595aSJames Feist // shouldn't be possible 353b4b9595aSJames Feist // to be nullptr 354b4b9595aSJames Feist *procCountPtr += 1; 355b4b9595aSJames Feist } 35657e8c9beSAlpana Kumari procSummary["Status"] 35757e8c9beSAlpana Kumari ["State"] = 358c5b2abe0SLewanczyk, Dawid "Enabled"; 35957e8c9beSAlpana Kumari procSummary["Model"] = 36057e8c9beSAlpana Kumari *value; 361c5b2abe0SLewanczyk, Dawid } 362c5b2abe0SLewanczyk, Dawid } 363c5b2abe0SLewanczyk, Dawid } 36457e8c9beSAlpana Kumari } 36557e8c9beSAlpana Kumari else 36657e8c9beSAlpana Kumari { 36757e8c9beSAlpana Kumari auto getCpuPresenceState = 36857e8c9beSAlpana Kumari [aResp]( 36957e8c9beSAlpana Kumari const boost::system::error_code 37057e8c9beSAlpana Kumari ec, 37157e8c9beSAlpana Kumari const std::variant<bool> 37257e8c9beSAlpana Kumari &cpuPresenceCheck) { 37357e8c9beSAlpana Kumari if (ec) 37457e8c9beSAlpana Kumari { 37557e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 37657e8c9beSAlpana Kumari << "DBUS response " 37757e8c9beSAlpana Kumari "error " 37857e8c9beSAlpana Kumari << ec; 37957e8c9beSAlpana Kumari return; 38057e8c9beSAlpana Kumari } 38157e8c9beSAlpana Kumari modifyCpuPresenceState( 38257e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 38357e8c9beSAlpana Kumari }; 38457e8c9beSAlpana Kumari 38557e8c9beSAlpana Kumari auto getCpuFunctionalState = 38657e8c9beSAlpana Kumari [aResp]( 38757e8c9beSAlpana Kumari const boost::system::error_code 38857e8c9beSAlpana Kumari ec, 38957e8c9beSAlpana Kumari const std::variant<bool> 39057e8c9beSAlpana Kumari &cpuFunctionalCheck) { 39157e8c9beSAlpana Kumari if (ec) 39257e8c9beSAlpana Kumari { 39357e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 39457e8c9beSAlpana Kumari << "DBUS response " 39557e8c9beSAlpana Kumari "error " 39657e8c9beSAlpana Kumari << ec; 39757e8c9beSAlpana Kumari return; 39857e8c9beSAlpana Kumari } 39957e8c9beSAlpana Kumari modifyCpuFunctionalState( 40057e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 40157e8c9beSAlpana Kumari }; 40257e8c9beSAlpana Kumari // Get the Presence of CPU 40357e8c9beSAlpana Kumari crow::connections::systemBus 40457e8c9beSAlpana Kumari ->async_method_call( 40557e8c9beSAlpana Kumari std::move(getCpuPresenceState), 40657e8c9beSAlpana Kumari service, path, 40757e8c9beSAlpana Kumari "org.freedesktop.DBus." 40857e8c9beSAlpana Kumari "Properties", 40957e8c9beSAlpana Kumari "Get", 41057e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 41157e8c9beSAlpana Kumari "Item", 41257e8c9beSAlpana Kumari "Present"); 41357e8c9beSAlpana Kumari 41457e8c9beSAlpana Kumari // Get the Functional State 41557e8c9beSAlpana Kumari crow::connections::systemBus 41657e8c9beSAlpana Kumari ->async_method_call( 41757e8c9beSAlpana Kumari std::move( 41857e8c9beSAlpana Kumari getCpuFunctionalState), 41957e8c9beSAlpana Kumari service, path, 42057e8c9beSAlpana Kumari "org.freedesktop.DBus." 42157e8c9beSAlpana Kumari "Properties", 42257e8c9beSAlpana Kumari "Get", 42357e8c9beSAlpana Kumari "xyz.openbmc_project.State." 42457e8c9beSAlpana Kumari "Decorator." 42557e8c9beSAlpana Kumari "OperationalStatus", 42657e8c9beSAlpana Kumari "Functional"); 42757e8c9beSAlpana Kumari 42857e8c9beSAlpana Kumari // Get the MODEL from 42957e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 43057e8c9beSAlpana Kumari // support it later as Model is Empty 43157e8c9beSAlpana Kumari // currently. 43257e8c9beSAlpana Kumari } 433c5b2abe0SLewanczyk, Dawid }, 43404a258f4SEd Tanous connection.first, path, 4356c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4366c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4375bc2dc8eSJames Feist 4385bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4391abe55efSEd Tanous } 44004a258f4SEd Tanous else if (interfaceName == 44104a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4421abe55efSEd Tanous { 4431abe55efSEd Tanous BMCWEB_LOG_DEBUG 44404a258f4SEd Tanous << "Found UUID, now get its properties."; 44555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 446029573d4SEd Tanous [aResp](const boost::system::error_code ec, 4476c34de48SEd Tanous const std::vector< 4486c34de48SEd Tanous std::pair<std::string, VariantType>> 4491abe55efSEd Tanous &properties) { 4501abe55efSEd Tanous if (ec) 4511abe55efSEd Tanous { 4521abe55efSEd Tanous BMCWEB_LOG_DEBUG 4536c34de48SEd Tanous << "DBUS response error " << ec; 454f12894f8SJason M. Bills messages::internalError(aResp->res); 455c5b2abe0SLewanczyk, Dawid return; 456c5b2abe0SLewanczyk, Dawid } 4576c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4586c34de48SEd Tanous << properties.size() 459c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4601abe55efSEd Tanous for (const std::pair<std::string, 46104a258f4SEd Tanous VariantType> 46204a258f4SEd Tanous &property : properties) 4631abe55efSEd Tanous { 46404a258f4SEd Tanous if (property.first == "UUID") 4651abe55efSEd Tanous { 466c5b2abe0SLewanczyk, Dawid const std::string *value = 4678d78b7a9SPatrick Williams std::get_if<std::string>( 4681b6b96c5SEd Tanous &property.second); 46904a258f4SEd Tanous 4701abe55efSEd Tanous if (value != nullptr) 4711abe55efSEd Tanous { 472029573d4SEd Tanous std::string valueStr = *value; 47304a258f4SEd Tanous if (valueStr.size() == 32) 4741abe55efSEd Tanous { 475029573d4SEd Tanous valueStr.insert(8, 1, '-'); 476029573d4SEd Tanous valueStr.insert(13, 1, '-'); 477029573d4SEd Tanous valueStr.insert(18, 1, '-'); 478029573d4SEd Tanous valueStr.insert(23, 1, '-'); 47904a258f4SEd Tanous } 480029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 48104a258f4SEd Tanous << valueStr; 482029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 48304a258f4SEd Tanous valueStr; 484c5b2abe0SLewanczyk, Dawid } 485c5b2abe0SLewanczyk, Dawid } 486c5b2abe0SLewanczyk, Dawid } 487c5b2abe0SLewanczyk, Dawid }, 48804a258f4SEd Tanous connection.first, path, 4896c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4901abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 491c5b2abe0SLewanczyk, Dawid } 492029573d4SEd Tanous else if (interfaceName == 493029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4941abe55efSEd Tanous { 495029573d4SEd Tanous crow::connections::systemBus->async_method_call( 496029573d4SEd Tanous [aResp](const boost::system::error_code ec, 497029573d4SEd Tanous const std::vector< 498029573d4SEd Tanous std::pair<std::string, VariantType>> 499029573d4SEd Tanous &propertiesList) { 500029573d4SEd Tanous if (ec) 501029573d4SEd Tanous { 502e4a4b9a9SJames Feist // doesn't have to include this 503e4a4b9a9SJames Feist // interface 504029573d4SEd Tanous return; 505029573d4SEd Tanous } 506698654b6SGunnar Mills BMCWEB_LOG_DEBUG 507698654b6SGunnar Mills << "Got " << propertiesList.size() 508029573d4SEd Tanous << " properties for system"; 509029573d4SEd Tanous for (const std::pair<std::string, 510029573d4SEd Tanous VariantType> 511029573d4SEd Tanous &property : propertiesList) 512029573d4SEd Tanous { 513fc5afcf9Sbeccabroek const std::string &propertyName = 514fc5afcf9Sbeccabroek property.first; 515fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 516fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 517fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 518fc5afcf9Sbeccabroek (propertyName == "Model")) 519fc5afcf9Sbeccabroek { 520029573d4SEd Tanous const std::string *value = 521fc5afcf9Sbeccabroek std::get_if<std::string>( 522029573d4SEd Tanous &property.second); 523029573d4SEd Tanous if (value != nullptr) 524029573d4SEd Tanous { 525029573d4SEd Tanous aResp->res 526fc5afcf9Sbeccabroek .jsonValue[propertyName] = 527029573d4SEd Tanous *value; 528029573d4SEd Tanous } 529029573d4SEd Tanous } 530fc5afcf9Sbeccabroek } 531c1e236a6SGunnar Mills 532cb7e1e7bSAndrew Geissler // Grab the bios version 533cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 534cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 535cb7e1e7bSAndrew Geissler "BiosVersion"); 536029573d4SEd Tanous }, 537029573d4SEd Tanous connection.first, path, 538029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 539029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 540029573d4SEd Tanous "Asset"); 541e4a4b9a9SJames Feist 542e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 543e4a4b9a9SJames Feist [aResp]( 544e4a4b9a9SJames Feist const boost::system::error_code ec, 545e4a4b9a9SJames Feist const std::variant<std::string> &property) { 546e4a4b9a9SJames Feist if (ec) 547e4a4b9a9SJames Feist { 548e4a4b9a9SJames Feist // doesn't have to include this 549e4a4b9a9SJames Feist // interface 550e4a4b9a9SJames Feist return; 551e4a4b9a9SJames Feist } 552e4a4b9a9SJames Feist 553e4a4b9a9SJames Feist const std::string *value = 554e4a4b9a9SJames Feist std::get_if<std::string>(&property); 555e4a4b9a9SJames Feist if (value != nullptr) 556e4a4b9a9SJames Feist { 557e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 558e4a4b9a9SJames Feist *value; 559e4a4b9a9SJames Feist } 560e4a4b9a9SJames Feist }, 561e4a4b9a9SJames Feist connection.first, path, 562e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 563e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 564e4a4b9a9SJames Feist "AssetTag", 565e4a4b9a9SJames Feist "AssetTag"); 566029573d4SEd Tanous } 567029573d4SEd Tanous } 568029573d4SEd Tanous } 569c5b2abe0SLewanczyk, Dawid } 570c5b2abe0SLewanczyk, Dawid }, 571c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 572c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 573c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5746617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5756617338dSEd Tanous std::array<const char *, 5>{ 5766617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5776617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5786617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5796617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5806617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5816617338dSEd Tanous }); 582c5b2abe0SLewanczyk, Dawid } 583c5b2abe0SLewanczyk, Dawid 584c5b2abe0SLewanczyk, Dawid /** 585c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 586c5b2abe0SLewanczyk, Dawid * 587c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 588c5b2abe0SLewanczyk, Dawid * 589c5b2abe0SLewanczyk, Dawid * @return None. 590c5b2abe0SLewanczyk, Dawid */ 591a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 5921abe55efSEd Tanous { 59355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 59455c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 595c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 596abf2add6SEd Tanous const std::variant<std::string> &hostState) { 5971abe55efSEd Tanous if (ec) 5981abe55efSEd Tanous { 59955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 600f12894f8SJason M. Bills messages::internalError(aResp->res); 601c5b2abe0SLewanczyk, Dawid return; 602c5b2abe0SLewanczyk, Dawid } 6036617338dSEd Tanous 604abf2add6SEd Tanous const std::string *s = std::get_if<std::string>(&hostState); 60555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6066617338dSEd Tanous if (s != nullptr) 6071abe55efSEd Tanous { 608c5b2abe0SLewanczyk, Dawid // Verify Host State 60994732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6101abe55efSEd Tanous { 61155c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6126617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6131abe55efSEd Tanous } 61483935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6158c888608SGunnar Mills "Quiesced") 6168c888608SGunnar Mills { 6178c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6188c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6198c888608SGunnar Mills } 6208c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 62183935af9SAndrew Geissler "DiagnosticMode") 62283935af9SAndrew Geissler { 62383935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 62483935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 62583935af9SAndrew Geissler } 6261abe55efSEd Tanous else 6271abe55efSEd Tanous { 62855c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6296617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 630c5b2abe0SLewanczyk, Dawid } 631c5b2abe0SLewanczyk, Dawid } 632c5b2abe0SLewanczyk, Dawid }, 6336c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6346617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6356617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 636c5b2abe0SLewanczyk, Dawid } 637c5b2abe0SLewanczyk, Dawid 638c5b2abe0SLewanczyk, Dawid /** 639491d8ee7SSantosh Puranik * @brief Traslates boot source DBUS property value to redfish. 640491d8ee7SSantosh Puranik * 641491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 642491d8ee7SSantosh Puranik * 643491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 644491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 645491d8ee7SSantosh Puranik */ 646491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string &dbusSource) 647491d8ee7SSantosh Puranik { 648491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 649491d8ee7SSantosh Puranik { 650491d8ee7SSantosh Puranik return "None"; 651491d8ee7SSantosh Puranik } 652491d8ee7SSantosh Puranik else if (dbusSource == 653491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 654491d8ee7SSantosh Puranik { 655491d8ee7SSantosh Puranik return "Hdd"; 656491d8ee7SSantosh Puranik } 657491d8ee7SSantosh Puranik else if (dbusSource == 658a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 659491d8ee7SSantosh Puranik { 660491d8ee7SSantosh Puranik return "Cd"; 661491d8ee7SSantosh Puranik } 662491d8ee7SSantosh Puranik else if (dbusSource == 663491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 664491d8ee7SSantosh Puranik { 665491d8ee7SSantosh Puranik return "Pxe"; 666491d8ee7SSantosh Puranik } 6679f16b2c1SJennifer Lee else if (dbusSource == 668944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6699f16b2c1SJennifer Lee { 6709f16b2c1SJennifer Lee return "Usb"; 6719f16b2c1SJennifer Lee } 672491d8ee7SSantosh Puranik else 673491d8ee7SSantosh Puranik { 674491d8ee7SSantosh Puranik return ""; 675491d8ee7SSantosh Puranik } 676491d8ee7SSantosh Puranik } 677491d8ee7SSantosh Puranik 678491d8ee7SSantosh Puranik /** 679491d8ee7SSantosh Puranik * @brief Traslates boot mode DBUS property value to redfish. 680491d8ee7SSantosh Puranik * 681491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 682491d8ee7SSantosh Puranik * 683491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 684491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 685491d8ee7SSantosh Puranik */ 686491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string &dbusMode) 687491d8ee7SSantosh Puranik { 688491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 689491d8ee7SSantosh Puranik { 690491d8ee7SSantosh Puranik return "None"; 691491d8ee7SSantosh Puranik } 692491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 693491d8ee7SSantosh Puranik { 694491d8ee7SSantosh Puranik return "Diags"; 695491d8ee7SSantosh Puranik } 696491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 697491d8ee7SSantosh Puranik { 698491d8ee7SSantosh Puranik return "BiosSetup"; 699491d8ee7SSantosh Puranik } 700491d8ee7SSantosh Puranik else 701491d8ee7SSantosh Puranik { 702491d8ee7SSantosh Puranik return ""; 703491d8ee7SSantosh Puranik } 704491d8ee7SSantosh Puranik } 705491d8ee7SSantosh Puranik 706491d8ee7SSantosh Puranik /** 707944ffaf9SJohnathan Mantey * @brief Traslates boot source from Redfish to the DBus boot paths. 708491d8ee7SSantosh Puranik * 709491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 710944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 711944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 712491d8ee7SSantosh Puranik * 713944ffaf9SJohnathan Mantey * @return Integer error code. 714491d8ee7SSantosh Puranik */ 715944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 716944ffaf9SJohnathan Mantey const std::string &rfSource, 717944ffaf9SJohnathan Mantey std::string &bootSource, std::string &bootMode) 718491d8ee7SSantosh Puranik { 719944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 720944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 721944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 722944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 723944ffaf9SJohnathan Mantey // desired boot action. 724944ffaf9SJohnathan Mantey 725491d8ee7SSantosh Puranik if (rfSource == "None") 726491d8ee7SSantosh Puranik { 727944ffaf9SJohnathan Mantey return 0; 728491d8ee7SSantosh Puranik } 729491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 730491d8ee7SSantosh Puranik { 731944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 732944ffaf9SJohnathan Mantey } 733944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 734944ffaf9SJohnathan Mantey { 735944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 736944ffaf9SJohnathan Mantey } 737944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 738944ffaf9SJohnathan Mantey { 739944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 740944ffaf9SJohnathan Mantey } 741944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 742944ffaf9SJohnathan Mantey { 743944ffaf9SJohnathan Mantey bootSource = 744944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 745944ffaf9SJohnathan Mantey } 746944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 747944ffaf9SJohnathan Mantey { 748944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 749491d8ee7SSantosh Puranik } 7509f16b2c1SJennifer Lee else if (rfSource == "Usb") 7519f16b2c1SJennifer Lee { 752944ffaf9SJohnathan Mantey bootSource = 753944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7549f16b2c1SJennifer Lee } 755491d8ee7SSantosh Puranik else 756491d8ee7SSantosh Puranik { 757944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 758944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 759944ffaf9SJohnathan Mantey << bootSource; 760944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 761944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 762944ffaf9SJohnathan Mantey return -1; 763491d8ee7SSantosh Puranik } 764944ffaf9SJohnathan Mantey return 0; 765491d8ee7SSantosh Puranik } 766491d8ee7SSantosh Puranik 767491d8ee7SSantosh Puranik /** 768491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 769491d8ee7SSantosh Puranik * 770491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 771491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 772491d8ee7SSantosh Puranik * 773491d8ee7SSantosh Puranik * @return None. 774491d8ee7SSantosh Puranik */ 775491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 776491d8ee7SSantosh Puranik std::string bootDbusObj) 777491d8ee7SSantosh Puranik { 778491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 779491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 780491d8ee7SSantosh Puranik const std::variant<std::string> &bootMode) { 781491d8ee7SSantosh Puranik if (ec) 782491d8ee7SSantosh Puranik { 783491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 784491d8ee7SSantosh Puranik messages::internalError(aResp->res); 785491d8ee7SSantosh Puranik return; 786491d8ee7SSantosh Puranik } 787491d8ee7SSantosh Puranik 788491d8ee7SSantosh Puranik const std::string *bootModeStr = 789491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 790491d8ee7SSantosh Puranik 791491d8ee7SSantosh Puranik if (!bootModeStr) 792491d8ee7SSantosh Puranik { 793491d8ee7SSantosh Puranik messages::internalError(aResp->res); 794491d8ee7SSantosh Puranik return; 795491d8ee7SSantosh Puranik } 796491d8ee7SSantosh Puranik 797491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 798491d8ee7SSantosh Puranik 799491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 800491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 801491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 802491d8ee7SSantosh Puranik "AllowableValues"] = { 803944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 804491d8ee7SSantosh Puranik 805491d8ee7SSantosh Puranik if (*bootModeStr != 806491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 807491d8ee7SSantosh Puranik { 808491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 809491d8ee7SSantosh Puranik if (!rfMode.empty()) 810491d8ee7SSantosh Puranik { 811491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 812491d8ee7SSantosh Puranik rfMode; 813491d8ee7SSantosh Puranik } 814491d8ee7SSantosh Puranik } 815491d8ee7SSantosh Puranik 816491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 817491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 818491d8ee7SSantosh Puranik // overrides are disabled 819491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 820491d8ee7SSantosh Puranik "None") 821491d8ee7SSantosh Puranik { 822491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 823491d8ee7SSantosh Puranik "Disabled"; 824491d8ee7SSantosh Puranik } 825491d8ee7SSantosh Puranik }, 826491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 827491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 828491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 829491d8ee7SSantosh Puranik } 830491d8ee7SSantosh Puranik 831491d8ee7SSantosh Puranik /** 832491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 833491d8ee7SSantosh Puranik * 834491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 835491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 836491d8ee7SSantosh Puranik * 837491d8ee7SSantosh Puranik * @return None. 838491d8ee7SSantosh Puranik */ 839491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 840491d8ee7SSantosh Puranik { 841491d8ee7SSantosh Puranik std::string bootDbusObj = 842491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 843491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 844491d8ee7SSantosh Puranik 845491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 846491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 847491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 848491d8ee7SSantosh Puranik 849491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 850491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 851491d8ee7SSantosh Puranik const std::variant<std::string> &bootSource) { 852491d8ee7SSantosh Puranik if (ec) 853491d8ee7SSantosh Puranik { 854491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 855491d8ee7SSantosh Puranik messages::internalError(aResp->res); 856491d8ee7SSantosh Puranik return; 857491d8ee7SSantosh Puranik } 858491d8ee7SSantosh Puranik 859491d8ee7SSantosh Puranik const std::string *bootSourceStr = 860491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 861491d8ee7SSantosh Puranik 862491d8ee7SSantosh Puranik if (!bootSourceStr) 863491d8ee7SSantosh Puranik { 864491d8ee7SSantosh Puranik messages::internalError(aResp->res); 865491d8ee7SSantosh Puranik return; 866491d8ee7SSantosh Puranik } 867491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 868491d8ee7SSantosh Puranik 869491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 870491d8ee7SSantosh Puranik if (!rfSource.empty()) 871491d8ee7SSantosh Puranik { 872491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 873491d8ee7SSantosh Puranik rfSource; 874491d8ee7SSantosh Puranik } 875491d8ee7SSantosh Puranik }, 876491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 877491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 878491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 879491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 880491d8ee7SSantosh Puranik } 881491d8ee7SSantosh Puranik 882491d8ee7SSantosh Puranik /** 883491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 884491d8ee7SSantosh Puranik * get boot source and boot mode. 885491d8ee7SSantosh Puranik * 886491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 887491d8ee7SSantosh Puranik * 888491d8ee7SSantosh Puranik * @return None. 889491d8ee7SSantosh Puranik */ 890491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 891491d8ee7SSantosh Puranik { 892491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 893491d8ee7SSantosh Puranik 894491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 895c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 89619bd78d9SPatrick Williams const std::variant<bool> &oneTime) { 897491d8ee7SSantosh Puranik if (ec) 898491d8ee7SSantosh Puranik { 899491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9002a833c77SJames Feist // not an error, don't have to have the interface 901491d8ee7SSantosh Puranik return; 902491d8ee7SSantosh Puranik } 903491d8ee7SSantosh Puranik 904491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 905491d8ee7SSantosh Puranik 906491d8ee7SSantosh Puranik if (!oneTimePtr) 907491d8ee7SSantosh Puranik { 908491d8ee7SSantosh Puranik messages::internalError(aResp->res); 909491d8ee7SSantosh Puranik return; 910491d8ee7SSantosh Puranik } 911491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 912491d8ee7SSantosh Puranik }, 913491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 914491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 915491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 916491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 917491d8ee7SSantosh Puranik } 918491d8ee7SSantosh Puranik 919491d8ee7SSantosh Puranik /** 920*6bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 921*6bd5a8d2SGunnar Mills * 922*6bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 923*6bd5a8d2SGunnar Mills * 924*6bd5a8d2SGunnar Mills * @return None. 925*6bd5a8d2SGunnar Mills */ 926*6bd5a8d2SGunnar Mills void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) 927*6bd5a8d2SGunnar Mills { 928*6bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 929*6bd5a8d2SGunnar Mills 930*6bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 931*6bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 932*6bd5a8d2SGunnar Mills std::variant<bool> &autoRebootEnabled) { 933*6bd5a8d2SGunnar Mills if (ec) 934*6bd5a8d2SGunnar Mills { 935*6bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 936*6bd5a8d2SGunnar Mills return; 937*6bd5a8d2SGunnar Mills } 938*6bd5a8d2SGunnar Mills 939*6bd5a8d2SGunnar Mills const bool *autoRebootEnabledPtr = 940*6bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 941*6bd5a8d2SGunnar Mills 942*6bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 943*6bd5a8d2SGunnar Mills { 944*6bd5a8d2SGunnar Mills messages::internalError(aResp->res); 945*6bd5a8d2SGunnar Mills return; 946*6bd5a8d2SGunnar Mills } 947*6bd5a8d2SGunnar Mills 948*6bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 949*6bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 950*6bd5a8d2SGunnar Mills { 951*6bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 952*6bd5a8d2SGunnar Mills "RetryAttempts"; 953*6bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 954*6bd5a8d2SGunnar Mills // attempts are left 955*6bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 956*6bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 957*6bd5a8d2SGunnar Mills std::variant<uint32_t> &autoRebootAttemptsLeft) { 958*6bd5a8d2SGunnar Mills if (ec) 959*6bd5a8d2SGunnar Mills { 960*6bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 961*6bd5a8d2SGunnar Mills return; 962*6bd5a8d2SGunnar Mills } 963*6bd5a8d2SGunnar Mills 964*6bd5a8d2SGunnar Mills const uint32_t *autoRebootAttemptsLeftPtr = 965*6bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 966*6bd5a8d2SGunnar Mills 967*6bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 968*6bd5a8d2SGunnar Mills { 969*6bd5a8d2SGunnar Mills messages::internalError(aResp->res); 970*6bd5a8d2SGunnar Mills return; 971*6bd5a8d2SGunnar Mills } 972*6bd5a8d2SGunnar Mills 973*6bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 974*6bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 975*6bd5a8d2SGunnar Mills 976*6bd5a8d2SGunnar Mills aResp->res 977*6bd5a8d2SGunnar Mills .jsonValue["Boot"] 978*6bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 979*6bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 980*6bd5a8d2SGunnar Mills }, 981*6bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 982*6bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 983*6bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 984*6bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 985*6bd5a8d2SGunnar Mills "AttemptsLeft"); 986*6bd5a8d2SGunnar Mills } 987*6bd5a8d2SGunnar Mills else 988*6bd5a8d2SGunnar Mills { 989*6bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 990*6bd5a8d2SGunnar Mills "Disabled"; 991*6bd5a8d2SGunnar Mills } 992*6bd5a8d2SGunnar Mills 993*6bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 994*6bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 995*6bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 996*6bd5a8d2SGunnar Mills }, 997*6bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 998*6bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 999*6bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 1000*6bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 1001*6bd5a8d2SGunnar Mills } 1002*6bd5a8d2SGunnar Mills 1003*6bd5a8d2SGunnar Mills /** 1004c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1005c6a620f2SGeorge Liu * 1006c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1007c6a620f2SGeorge Liu * 1008c6a620f2SGeorge Liu * @return None. 1009c6a620f2SGeorge Liu */ 1010c6a620f2SGeorge Liu void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) 1011c6a620f2SGeorge Liu { 1012c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1013c6a620f2SGeorge Liu 1014c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1015c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 101619bd78d9SPatrick Williams std::variant<std::string> &policy) { 1017c6a620f2SGeorge Liu if (ec) 1018c6a620f2SGeorge Liu { 1019c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1020c6a620f2SGeorge Liu return; 1021c6a620f2SGeorge Liu } 1022c6a620f2SGeorge Liu 1023c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1024c6a620f2SGeorge Liu policyMaps = { 1025c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1026c6a620f2SGeorge Liu "AlwaysOn", 1027c6a620f2SGeorge Liu "AlwaysOn"}, 1028c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1029c6a620f2SGeorge Liu "AlwaysOff", 1030c6a620f2SGeorge Liu "AlwaysOff"}, 1031c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1032c6a620f2SGeorge Liu "LastState", 1033c6a620f2SGeorge Liu "LastState"}}; 1034c6a620f2SGeorge Liu 1035c6a620f2SGeorge Liu const std::string *policyPtr = std::get_if<std::string>(&policy); 1036c6a620f2SGeorge Liu 1037c6a620f2SGeorge Liu if (!policyPtr) 1038c6a620f2SGeorge Liu { 1039c6a620f2SGeorge Liu messages::internalError(aResp->res); 1040c6a620f2SGeorge Liu return; 1041c6a620f2SGeorge Liu } 1042c6a620f2SGeorge Liu 1043c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1044c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1045c6a620f2SGeorge Liu { 1046c6a620f2SGeorge Liu messages::internalError(aResp->res); 1047c6a620f2SGeorge Liu return; 1048c6a620f2SGeorge Liu } 1049c6a620f2SGeorge Liu 1050c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1051c6a620f2SGeorge Liu }, 1052c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1053c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1054c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1055c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1056c6a620f2SGeorge Liu "PowerRestorePolicy"); 1057c6a620f2SGeorge Liu } 1058c6a620f2SGeorge Liu 1059c6a620f2SGeorge Liu /** 1060491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1061491d8ee7SSantosh Puranik * 1062491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1063491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1064491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1065491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1066491d8ee7SSantosh Puranik * 1067265c1602SJohnathan Mantey * @return Integer error code. 1068491d8ee7SSantosh Puranik */ 1069491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1070491d8ee7SSantosh Puranik bool oneTimeEnabled, 1071491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1072491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1073491d8ee7SSantosh Puranik { 1074944ffaf9SJohnathan Mantey std::string bootSourceStr = 1075944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1076944ffaf9SJohnathan Mantey std::string bootModeStr = 1077944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1078491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1079944ffaf9SJohnathan Mantey bool useBootSource = true; 1080944ffaf9SJohnathan Mantey 1081491d8ee7SSantosh Puranik // Validate incoming parameters 1082491d8ee7SSantosh Puranik if (bootEnable) 1083491d8ee7SSantosh Puranik { 1084491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1085491d8ee7SSantosh Puranik { 1086491d8ee7SSantosh Puranik oneTimeSetting = true; 1087491d8ee7SSantosh Puranik } 1088491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1089491d8ee7SSantosh Puranik { 1090491d8ee7SSantosh Puranik oneTimeSetting = false; 1091491d8ee7SSantosh Puranik } 1092491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1093491d8ee7SSantosh Puranik { 1094944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1095491d8ee7SSantosh Puranik oneTimeSetting = false; 1096944ffaf9SJohnathan Mantey useBootSource = false; 1097491d8ee7SSantosh Puranik } 1098491d8ee7SSantosh Puranik else 1099491d8ee7SSantosh Puranik { 1100491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1101491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1102491d8ee7SSantosh Puranik << *bootEnable; 1103491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1104491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1105491d8ee7SSantosh Puranik return; 1106491d8ee7SSantosh Puranik } 1107491d8ee7SSantosh Puranik } 1108491d8ee7SSantosh Puranik 1109944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1110491d8ee7SSantosh Puranik { 1111491d8ee7SSantosh Puranik // Source target specified 1112491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1113491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1114944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1115944ffaf9SJohnathan Mantey bootModeStr)) 1116491d8ee7SSantosh Puranik { 1117944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1118944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1119491d8ee7SSantosh Puranik << *bootSource; 1120491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1121491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1122491d8ee7SSantosh Puranik return; 1123491d8ee7SSantosh Puranik } 1124944ffaf9SJohnathan Mantey } 1125491d8ee7SSantosh Puranik 1126944ffaf9SJohnathan Mantey // Act on validated parameters 1127944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1128944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1129944ffaf9SJohnathan Mantey const char *bootObj = 1130944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1131944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1132944ffaf9SJohnathan Mantey 1133491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1134491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1135491d8ee7SSantosh Puranik if (ec) 1136491d8ee7SSantosh Puranik { 1137491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1138491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1139491d8ee7SSantosh Puranik return; 1140491d8ee7SSantosh Puranik } 1141491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1142491d8ee7SSantosh Puranik }, 1143491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1144491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1145491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1146491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1147944ffaf9SJohnathan Mantey 1148491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1149491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1150491d8ee7SSantosh Puranik if (ec) 1151491d8ee7SSantosh Puranik { 1152491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1153491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1154491d8ee7SSantosh Puranik return; 1155491d8ee7SSantosh Puranik } 1156491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1157491d8ee7SSantosh Puranik }, 1158491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1159491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1160491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1161491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1162944ffaf9SJohnathan Mantey 1163491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1164491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1165491d8ee7SSantosh Puranik if (ec) 1166491d8ee7SSantosh Puranik { 1167491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1168491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1169491d8ee7SSantosh Puranik return; 1170491d8ee7SSantosh Puranik } 1171491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1172491d8ee7SSantosh Puranik }, 1173491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1174491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1175491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1176491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1177491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1178491d8ee7SSantosh Puranik } 1179491d8ee7SSantosh Puranik 1180491d8ee7SSantosh Puranik /** 1181491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1182491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1183491d8ee7SSantosh Puranik * 1184491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1185491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1186491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1187491d8ee7SSantosh Puranik * 1188265c1602SJohnathan Mantey * @return Integer error code. 1189491d8ee7SSantosh Puranik */ 1190491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1191491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1192491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1193491d8ee7SSantosh Puranik { 1194491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1195491d8ee7SSantosh Puranik 1196491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1197265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 119819bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 119919bd78d9SPatrick Williams const std::variant<bool> &oneTime) { 1200491d8ee7SSantosh Puranik if (ec) 1201491d8ee7SSantosh Puranik { 1202491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1203491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1204491d8ee7SSantosh Puranik return; 1205491d8ee7SSantosh Puranik } 1206491d8ee7SSantosh Puranik 1207491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1208491d8ee7SSantosh Puranik 1209491d8ee7SSantosh Puranik if (!oneTimePtr) 1210491d8ee7SSantosh Puranik { 1211491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1212491d8ee7SSantosh Puranik return; 1213491d8ee7SSantosh Puranik } 1214491d8ee7SSantosh Puranik 1215491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1216491d8ee7SSantosh Puranik 1217491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1218491d8ee7SSantosh Puranik std::move(bootEnable)); 1219491d8ee7SSantosh Puranik }, 1220491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1221491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1222491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1223491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1224491d8ee7SSantosh Puranik } 1225491d8ee7SSantosh Puranik 1226c6a620f2SGeorge Liu /** 1227c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1228c6a620f2SGeorge Liu * 1229c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1230c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1231c6a620f2SGeorge Liu * 1232c6a620f2SGeorge Liu * @return None. 1233c6a620f2SGeorge Liu */ 1234c6a620f2SGeorge Liu static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, 1235c6a620f2SGeorge Liu std::optional<std::string> policy) 1236c6a620f2SGeorge Liu { 1237c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1238c6a620f2SGeorge Liu 1239c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1240c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1241c6a620f2SGeorge Liu "AlwaysOn"}, 1242c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1243c6a620f2SGeorge Liu "AlwaysOff"}, 1244c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1245c6a620f2SGeorge Liu "LastState"}}; 1246c6a620f2SGeorge Liu 1247c6a620f2SGeorge Liu std::string powerRestorPolicy; 1248c6a620f2SGeorge Liu 1249c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policy); 1250c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1251c6a620f2SGeorge Liu { 1252c6a620f2SGeorge Liu messages::internalError(aResp->res); 1253c6a620f2SGeorge Liu return; 1254c6a620f2SGeorge Liu } 1255c6a620f2SGeorge Liu 1256c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1257c6a620f2SGeorge Liu 1258c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1259c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1260c6a620f2SGeorge Liu if (ec) 1261c6a620f2SGeorge Liu { 1262c6a620f2SGeorge Liu messages::internalError(aResp->res); 1263c6a620f2SGeorge Liu return; 1264c6a620f2SGeorge Liu } 1265c6a620f2SGeorge Liu }, 1266c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1267c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1268c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1269c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1270c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1271c6a620f2SGeorge Liu } 1272c6a620f2SGeorge Liu 1273a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1274a6349918SAppaRao Puli /** 1275a6349918SAppaRao Puli * @brief Retrieves provisioning status 1276a6349918SAppaRao Puli * 1277a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1278a6349918SAppaRao Puli * 1279a6349918SAppaRao Puli * @return None. 1280a6349918SAppaRao Puli */ 1281a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1282a6349918SAppaRao Puli { 1283a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1284a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1285a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 1286a6349918SAppaRao Puli const std::vector<std::pair<std::string, VariantType>> 1287a6349918SAppaRao Puli &propertiesList) { 1288a6349918SAppaRao Puli if (ec) 1289a6349918SAppaRao Puli { 1290a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1291a6349918SAppaRao Puli messages::internalError(aResp->res); 1292a6349918SAppaRao Puli return; 1293a6349918SAppaRao Puli } 1294a6349918SAppaRao Puli 1295a6349918SAppaRao Puli const bool *provState = nullptr; 1296a6349918SAppaRao Puli const bool *lockState = nullptr; 1297a6349918SAppaRao Puli for (const std::pair<std::string, VariantType> &property : 1298a6349918SAppaRao Puli propertiesList) 1299a6349918SAppaRao Puli { 1300a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1301a6349918SAppaRao Puli { 1302a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1303a6349918SAppaRao Puli } 1304a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1305a6349918SAppaRao Puli { 1306a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1307a6349918SAppaRao Puli } 1308a6349918SAppaRao Puli } 1309a6349918SAppaRao Puli 1310a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1311a6349918SAppaRao Puli { 1312a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1313a6349918SAppaRao Puli messages::internalError(aResp->res); 1314a6349918SAppaRao Puli return; 1315a6349918SAppaRao Puli } 1316a6349918SAppaRao Puli 1317a6349918SAppaRao Puli nlohmann::json &oemPFR = 1318a6349918SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1319a6349918SAppaRao Puli if (*provState == true) 1320a6349918SAppaRao Puli { 1321a6349918SAppaRao Puli if (*lockState == true) 1322a6349918SAppaRao Puli { 1323a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1324a6349918SAppaRao Puli } 1325a6349918SAppaRao Puli else 1326a6349918SAppaRao Puli { 1327a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1328a6349918SAppaRao Puli } 1329a6349918SAppaRao Puli } 1330a6349918SAppaRao Puli else 1331a6349918SAppaRao Puli { 1332a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1333a6349918SAppaRao Puli } 1334a6349918SAppaRao Puli }, 1335a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1336a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1337a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1338a6349918SAppaRao Puli } 1339a6349918SAppaRao Puli #endif 1340a6349918SAppaRao Puli 1341491d8ee7SSantosh Puranik /** 134251709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 134351709ffdSYong Li * 134451709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 134551709ffdSYong Li * 134651709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 134751709ffdSYong Li * translation cannot be done, returns an empty string. 134851709ffdSYong Li */ 134951709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction) 135051709ffdSYong Li { 135151709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 135251709ffdSYong Li { 135351709ffdSYong Li return "None"; 135451709ffdSYong Li } 135551709ffdSYong Li else if (dbusAction == 135651709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 135751709ffdSYong Li { 135851709ffdSYong Li return "ResetSystem"; 135951709ffdSYong Li } 136051709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 136151709ffdSYong Li { 136251709ffdSYong Li return "PowerDown"; 136351709ffdSYong Li } 136451709ffdSYong Li else if (dbusAction == 136551709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 136651709ffdSYong Li { 136751709ffdSYong Li return "PowerCycle"; 136851709ffdSYong Li } 136951709ffdSYong Li 137051709ffdSYong Li return ""; 137151709ffdSYong Li } 137251709ffdSYong Li 137351709ffdSYong Li /** 1374c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1375c45f0082SYong Li * 1376c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1377c45f0082SYong Li * 1378c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1379c45f0082SYong Li *If translation cannot be done, returns an empty string. 1380c45f0082SYong Li */ 1381c45f0082SYong Li 1382c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction) 1383c45f0082SYong Li { 1384c45f0082SYong Li if (rfAction == "None") 1385c45f0082SYong Li { 1386c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1387c45f0082SYong Li } 1388c45f0082SYong Li else if (rfAction == "PowerCycle") 1389c45f0082SYong Li { 1390c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1391c45f0082SYong Li } 1392c45f0082SYong Li else if (rfAction == "PowerDown") 1393c45f0082SYong Li { 1394c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1395c45f0082SYong Li } 1396c45f0082SYong Li else if (rfAction == "ResetSystem") 1397c45f0082SYong Li { 1398c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1399c45f0082SYong Li } 1400c45f0082SYong Li 1401c45f0082SYong Li return ""; 1402c45f0082SYong Li } 1403c45f0082SYong Li 1404c45f0082SYong Li /** 140551709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 140651709ffdSYong Li * 140751709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 140851709ffdSYong Li * 140951709ffdSYong Li * @return None. 141051709ffdSYong Li */ 141151709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 141251709ffdSYong Li { 141351709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 141451709ffdSYong Li crow::connections::systemBus->async_method_call( 141551709ffdSYong Li [aResp](const boost::system::error_code ec, 141651709ffdSYong Li PropertiesType &properties) { 141751709ffdSYong Li if (ec) 141851709ffdSYong Li { 141951709ffdSYong Li // watchdog service is stopped 142051709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 142151709ffdSYong Li return; 142251709ffdSYong Li } 142351709ffdSYong Li 142451709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 142551709ffdSYong Li 142651709ffdSYong Li nlohmann::json &hostWatchdogTimer = 142751709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 142851709ffdSYong Li 142951709ffdSYong Li // watchdog service is running/enabled 143051709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 143151709ffdSYong Li 143251709ffdSYong Li for (const auto &property : properties) 143351709ffdSYong Li { 143451709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 143551709ffdSYong Li if (property.first == "Enabled") 143651709ffdSYong Li { 143751709ffdSYong Li const bool *state = std::get_if<bool>(&property.second); 143851709ffdSYong Li 143951709ffdSYong Li if (!state) 144051709ffdSYong Li { 144151709ffdSYong Li messages::internalError(aResp->res); 144251709ffdSYong Li continue; 144351709ffdSYong Li } 144451709ffdSYong Li 144551709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 144651709ffdSYong Li } 144751709ffdSYong Li else if (property.first == "ExpireAction") 144851709ffdSYong Li { 144951709ffdSYong Li const std::string *s = 145051709ffdSYong Li std::get_if<std::string>(&property.second); 145151709ffdSYong Li if (!s) 145251709ffdSYong Li { 145351709ffdSYong Li messages::internalError(aResp->res); 145451709ffdSYong Li continue; 145551709ffdSYong Li } 145651709ffdSYong Li 145751709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 145851709ffdSYong Li if (action.empty()) 145951709ffdSYong Li { 146051709ffdSYong Li messages::internalError(aResp->res); 146151709ffdSYong Li continue; 146251709ffdSYong Li } 146351709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 146451709ffdSYong Li } 146551709ffdSYong Li } 146651709ffdSYong Li }, 146751709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 146851709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 146951709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 147051709ffdSYong Li } 147151709ffdSYong Li 147251709ffdSYong Li /** 1473c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1474c45f0082SYong Li * 1475c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1476c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1477c45f0082SYong Li * RF request. 1478c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1479c45f0082SYong Li * 1480c45f0082SYong Li * @return None. 1481c45f0082SYong Li */ 1482c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1483c45f0082SYong Li const std::optional<bool> wdtEnable, 1484c45f0082SYong Li const std::optional<std::string> &wdtTimeOutAction) 1485c45f0082SYong Li { 1486c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1487c45f0082SYong Li 1488c45f0082SYong Li if (wdtTimeOutAction) 1489c45f0082SYong Li { 1490c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1491c45f0082SYong Li // check if TimeOut Action is Valid 1492c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1493c45f0082SYong Li { 1494c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1495c45f0082SYong Li << *wdtTimeOutAction; 1496c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1497c45f0082SYong Li "TimeoutAction"); 1498c45f0082SYong Li return; 1499c45f0082SYong Li } 1500c45f0082SYong Li 1501c45f0082SYong Li crow::connections::systemBus->async_method_call( 1502c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1503c45f0082SYong Li if (ec) 1504c45f0082SYong Li { 1505c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1506c45f0082SYong Li messages::internalError(aResp->res); 1507c45f0082SYong Li return; 1508c45f0082SYong Li } 1509c45f0082SYong Li }, 1510c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1511c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1512c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1513c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1514c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1515c45f0082SYong Li } 1516c45f0082SYong Li 1517c45f0082SYong Li if (wdtEnable) 1518c45f0082SYong Li { 1519c45f0082SYong Li crow::connections::systemBus->async_method_call( 1520c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1521c45f0082SYong Li if (ec) 1522c45f0082SYong Li { 1523c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1524c45f0082SYong Li messages::internalError(aResp->res); 1525c45f0082SYong Li return; 1526c45f0082SYong Li } 1527c45f0082SYong Li }, 1528c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1529c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1530c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1531c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1532c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1533c45f0082SYong Li } 1534c45f0082SYong Li } 1535c45f0082SYong Li 1536c45f0082SYong Li /** 1537c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1538c5b2abe0SLewanczyk, Dawid * Schema 1539c5b2abe0SLewanczyk, Dawid */ 15401abe55efSEd Tanous class SystemsCollection : public Node 15411abe55efSEd Tanous { 1542c5b2abe0SLewanczyk, Dawid public: 15431abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 15441abe55efSEd Tanous { 1545c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1546c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1547c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1548c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1549c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1550c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1551c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1552c5b2abe0SLewanczyk, Dawid } 1553c5b2abe0SLewanczyk, Dawid 1554c5b2abe0SLewanczyk, Dawid private: 155555c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 15561abe55efSEd Tanous const std::vector<std::string> ¶ms) override 15571abe55efSEd Tanous { 1558462023adSSunitha Harish std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 15590f74e643SEd Tanous res.jsonValue["@odata.type"] = 15600f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 15610f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 15620f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1563462023adSSunitha Harish 1564462023adSSunitha Harish crow::connections::systemBus->async_method_call( 1565462023adSSunitha Harish [asyncResp](const boost::system::error_code ec, 1566462023adSSunitha Harish const std::variant<std::string> &hostName) { 1567462023adSSunitha Harish nlohmann::json &iface_array = 1568462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 1569462023adSSunitha Harish iface_array = nlohmann::json::array(); 1570462023adSSunitha Harish auto &count = asyncResp->res.jsonValue["Members@odata.count"]; 1571462023adSSunitha Harish count = 0; 1572462023adSSunitha Harish if (ec) 1573462023adSSunitha Harish { 1574462023adSSunitha Harish iface_array.push_back( 1575462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1576462023adSSunitha Harish count = iface_array.size(); 1577462023adSSunitha Harish return; 1578462023adSSunitha Harish } 1579462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 1580462023adSSunitha Harish iface_array.push_back( 1581462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1582462023adSSunitha Harish iface_array.push_back( 1583462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); 1584462023adSSunitha Harish count = iface_array.size(); 1585462023adSSunitha Harish }, 1586462023adSSunitha Harish "xyz.openbmc_project.Settings", "/xyz/openbmc_project/network/vmi", 1587462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 1588462023adSSunitha Harish "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); 1589c5b2abe0SLewanczyk, Dawid } 1590c5b2abe0SLewanczyk, Dawid }; 1591c5b2abe0SLewanczyk, Dawid 1592c5b2abe0SLewanczyk, Dawid /** 1593cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1594cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1595cc340dd9SEd Tanous */ 1596cc340dd9SEd Tanous class SystemActionsReset : public Node 1597cc340dd9SEd Tanous { 1598cc340dd9SEd Tanous public: 1599cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1600029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1601cc340dd9SEd Tanous { 1602cc340dd9SEd Tanous entityPrivileges = { 1603cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1604cc340dd9SEd Tanous } 1605cc340dd9SEd Tanous 1606cc340dd9SEd Tanous private: 1607cc340dd9SEd Tanous /** 1608cc340dd9SEd Tanous * Function handles POST method request. 1609cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1610cc340dd9SEd Tanous */ 1611cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1612cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1613cc340dd9SEd Tanous { 1614cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1615cc340dd9SEd Tanous 16169712f8acSEd Tanous std::string resetType; 16179712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1618cc340dd9SEd Tanous { 1619cc340dd9SEd Tanous return; 1620cc340dd9SEd Tanous } 1621cc340dd9SEd Tanous 1622d22c8396SJason M. Bills // Get the command and host vs. chassis 1623cc340dd9SEd Tanous std::string command; 1624d22c8396SJason M. Bills bool hostCommand; 16259712f8acSEd Tanous if (resetType == "On") 1626cc340dd9SEd Tanous { 1627cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1628d22c8396SJason M. Bills hostCommand = true; 1629d22c8396SJason M. Bills } 1630d22c8396SJason M. Bills else if (resetType == "ForceOff") 1631d22c8396SJason M. Bills { 1632d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1633d22c8396SJason M. Bills hostCommand = false; 1634d22c8396SJason M. Bills } 1635d22c8396SJason M. Bills else if (resetType == "ForceOn") 1636d22c8396SJason M. Bills { 1637d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1638d22c8396SJason M. Bills hostCommand = true; 1639d22c8396SJason M. Bills } 1640d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1641d22c8396SJason M. Bills { 164286a0851aSJason M. Bills command = 164386a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 164486a0851aSJason M. Bills hostCommand = true; 1645cc340dd9SEd Tanous } 16469712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1647cc340dd9SEd Tanous { 1648cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1649d22c8396SJason M. Bills hostCommand = true; 1650cc340dd9SEd Tanous } 16519712f8acSEd Tanous else if (resetType == "GracefulRestart") 1652cc340dd9SEd Tanous { 165386a0851aSJason M. Bills command = 165486a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 1655d22c8396SJason M. Bills hostCommand = true; 1656d22c8396SJason M. Bills } 1657d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1658d22c8396SJason M. Bills { 165986a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 166086a0851aSJason M. Bills hostCommand = true; 1661cc340dd9SEd Tanous } 1662bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1663bfd5b826SLakshminarayana R. Kammath { 1664bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1665bfd5b826SLakshminarayana R. Kammath return; 1666bfd5b826SLakshminarayana R. Kammath } 1667cc340dd9SEd Tanous else 1668cc340dd9SEd Tanous { 1669f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1670cc340dd9SEd Tanous return; 1671cc340dd9SEd Tanous } 1672cc340dd9SEd Tanous 1673d22c8396SJason M. Bills if (hostCommand) 1674d22c8396SJason M. Bills { 1675cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1676d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1677cc340dd9SEd Tanous if (ec) 1678cc340dd9SEd Tanous { 1679cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1680d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1681d22c8396SJason M. Bills { 1682d22c8396SJason M. Bills messages::actionParameterNotSupported( 1683d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1684d22c8396SJason M. Bills } 1685d22c8396SJason M. Bills else 1686d22c8396SJason M. Bills { 1687f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1688d22c8396SJason M. Bills } 1689cc340dd9SEd Tanous return; 1690cc340dd9SEd Tanous } 1691f12894f8SJason M. Bills messages::success(asyncResp->res); 1692cc340dd9SEd Tanous }, 1693cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1694cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1695cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 16969712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1697abf2add6SEd Tanous std::variant<std::string>{command}); 1698cc340dd9SEd Tanous } 1699d22c8396SJason M. Bills else 1700d22c8396SJason M. Bills { 1701d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1702d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1703d22c8396SJason M. Bills if (ec) 1704d22c8396SJason M. Bills { 1705d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1706d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1707d22c8396SJason M. Bills { 1708d22c8396SJason M. Bills messages::actionParameterNotSupported( 1709d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1710d22c8396SJason M. Bills } 1711d22c8396SJason M. Bills else 1712d22c8396SJason M. Bills { 1713d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1714d22c8396SJason M. Bills } 1715d22c8396SJason M. Bills return; 1716d22c8396SJason M. Bills } 1717d22c8396SJason M. Bills messages::success(asyncResp->res); 1718d22c8396SJason M. Bills }, 1719d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1720d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1721d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1722d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1723d22c8396SJason M. Bills std::variant<std::string>{command}); 1724d22c8396SJason M. Bills } 1725d22c8396SJason M. Bills } 1726bfd5b826SLakshminarayana R. Kammath /** 1727bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1728bfd5b826SLakshminarayana R. Kammath */ 1729bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1730bfd5b826SLakshminarayana R. Kammath { 1731bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1732bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1733bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1734bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1735bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1736bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1737bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1738bfd5b826SLakshminarayana R. Kammath 1739bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1740bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1741bfd5b826SLakshminarayana R. Kammath if (ec) 1742bfd5b826SLakshminarayana R. Kammath { 1743bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1744bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1745bfd5b826SLakshminarayana R. Kammath return; 1746bfd5b826SLakshminarayana R. Kammath } 1747bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1748bfd5b826SLakshminarayana R. Kammath }, 1749bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1750bfd5b826SLakshminarayana R. Kammath } 1751cc340dd9SEd Tanous }; 1752cc340dd9SEd Tanous 1753cc340dd9SEd Tanous /** 17546617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1755c5b2abe0SLewanczyk, Dawid */ 17561abe55efSEd Tanous class Systems : public Node 17571abe55efSEd Tanous { 1758c5b2abe0SLewanczyk, Dawid public: 1759c5b2abe0SLewanczyk, Dawid /* 1760c5b2abe0SLewanczyk, Dawid * Default Constructor 1761c5b2abe0SLewanczyk, Dawid */ 1762029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 17631abe55efSEd Tanous { 1764c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1765c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1766c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1767c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1768c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1769c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1770c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1771c5b2abe0SLewanczyk, Dawid } 1772c5b2abe0SLewanczyk, Dawid 1773c5b2abe0SLewanczyk, Dawid private: 1774c5b2abe0SLewanczyk, Dawid /** 1775c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1776c5b2abe0SLewanczyk, Dawid */ 177755c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 17781abe55efSEd Tanous const std::vector<std::string> ¶ms) override 17791abe55efSEd Tanous { 1780*6bd5a8d2SGunnar Mills res.jsonValue["@odata.type"] = "#ComputerSystem.v1_11_0.ComputerSystem"; 1781450a25cbSGunnar Mills res.jsonValue["Name"] = "system"; 1782029573d4SEd Tanous res.jsonValue["Id"] = "system"; 17830f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 17840f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 17850f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 17860f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 17875fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 17880f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1789029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 179004a258f4SEd Tanous 1791443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1792029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1793443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1794029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1795a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1796a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1797029573d4SEd Tanous 1798cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1799cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1800cc340dd9SEd Tanous {"target", 1801029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1802cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1803d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1804bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1805c5b2abe0SLewanczyk, Dawid 1806c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1807029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1808c4bf6374SJason M. Bills 1809d82a3acdSCarol Wang res.jsonValue["Bios"] = { 1810d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 1811d82a3acdSCarol Wang 1812c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1813c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1814c5d03ff4SJennifer Lee 1815c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1816c5d03ff4SJennifer Lee {"Health", "OK"}, 1817c5d03ff4SJennifer Lee {"State", "Enabled"}, 1818c5d03ff4SJennifer Lee }; 1819a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1820c5b2abe0SLewanczyk, Dawid 1821e284a7c1SJames Feist constexpr const std::array<const char *, 4> inventoryForSystems = { 1822b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 18232ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1824e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1825e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1826b49ac873SJames Feist 1827b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1828b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1829b49ac873SJames Feist [health](const boost::system::error_code ec, 1830b49ac873SJames Feist std::vector<std::string> &resp) { 1831b49ac873SJames Feist if (ec) 1832b49ac873SJames Feist { 1833b49ac873SJames Feist // no inventory 1834b49ac873SJames Feist return; 1835b49ac873SJames Feist } 1836b49ac873SJames Feist 1837b49ac873SJames Feist health->inventory = std::move(resp); 1838b49ac873SJames Feist }, 1839b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1840b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1841b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1842b49ac873SJames Feist int32_t(0), inventoryForSystems); 1843b49ac873SJames Feist 1844b49ac873SJames Feist health->populate(); 1845b49ac873SJames Feist 1846c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1847c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1848c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1849c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1850c5d03ff4SJennifer Lee }); 1851a3002228SAppaRao Puli 1852a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 18535bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 18546c34de48SEd Tanous getHostState(asyncResp); 1855491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1856adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 185751709ffdSYong Li getHostWatchdogTimer(asyncResp); 1858c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 1859*6bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 1860a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1861a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1862a6349918SAppaRao Puli #endif 1863c5b2abe0SLewanczyk, Dawid } 1864c5b2abe0SLewanczyk, Dawid 186555c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 18661abe55efSEd Tanous const std::vector<std::string> ¶ms) override 18671abe55efSEd Tanous { 1868cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1869491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1870c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 1871c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 187241352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 187341352c24SSantosh Puranik 1874944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1875c6a620f2SGeorge Liu bootProps, "WatchdogTimer", wdtTimerProps, 1876c6a620f2SGeorge Liu "PowerRestorePolicy", powerRestorePolicy)) 18776617338dSEd Tanous { 18786617338dSEd Tanous return; 18796617338dSEd Tanous } 1880491d8ee7SSantosh Puranik 1881944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1882c45f0082SYong Li 1883c45f0082SYong Li if (wdtTimerProps) 1884c45f0082SYong Li { 1885c45f0082SYong Li std::optional<bool> wdtEnable; 1886c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1887c45f0082SYong Li 1888c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1889c45f0082SYong Li "FunctionEnabled", wdtEnable, 1890c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1891c45f0082SYong Li { 1892c45f0082SYong Li return; 1893c45f0082SYong Li } 1894c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 1895c45f0082SYong Li std::move(wdtTimeOutAction)); 1896c45f0082SYong Li } 1897c45f0082SYong Li 1898491d8ee7SSantosh Puranik if (bootProps) 1899491d8ee7SSantosh Puranik { 1900491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1901491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1902491d8ee7SSantosh Puranik 1903491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1904491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1905491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1906491d8ee7SSantosh Puranik { 1907491d8ee7SSantosh Puranik return; 1908491d8ee7SSantosh Puranik } 1909491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1910491d8ee7SSantosh Puranik std::move(bootEnable)); 1911491d8ee7SSantosh Puranik } 1912265c1602SJohnathan Mantey 19139712f8acSEd Tanous if (indicatorLed) 19146617338dSEd Tanous { 1915a3002228SAppaRao Puli setIndicatorLedState(asyncResp, std::move(*indicatorLed)); 19166617338dSEd Tanous } 1917c6a620f2SGeorge Liu 1918c6a620f2SGeorge Liu if (powerRestorePolicy) 1919c6a620f2SGeorge Liu { 1920c6a620f2SGeorge Liu setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); 1921c6a620f2SGeorge Liu } 1922c5b2abe0SLewanczyk, Dawid } 1923c5b2abe0SLewanczyk, Dawid }; 1924c5b2abe0SLewanczyk, Dawid } // namespace redfish 1925