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, 896*19bd78d9SPatrick 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 /** 920c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 921c6a620f2SGeorge Liu * 922c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 923c6a620f2SGeorge Liu * 924c6a620f2SGeorge Liu * @return None. 925c6a620f2SGeorge Liu */ 926c6a620f2SGeorge Liu void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) 927c6a620f2SGeorge Liu { 928c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 929c6a620f2SGeorge Liu 930c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 931c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 932*19bd78d9SPatrick Williams std::variant<std::string> &policy) { 933c6a620f2SGeorge Liu if (ec) 934c6a620f2SGeorge Liu { 935c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 936c6a620f2SGeorge Liu return; 937c6a620f2SGeorge Liu } 938c6a620f2SGeorge Liu 939c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 940c6a620f2SGeorge Liu policyMaps = { 941c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 942c6a620f2SGeorge Liu "AlwaysOn", 943c6a620f2SGeorge Liu "AlwaysOn"}, 944c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 945c6a620f2SGeorge Liu "AlwaysOff", 946c6a620f2SGeorge Liu "AlwaysOff"}, 947c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 948c6a620f2SGeorge Liu "LastState", 949c6a620f2SGeorge Liu "LastState"}}; 950c6a620f2SGeorge Liu 951c6a620f2SGeorge Liu const std::string *policyPtr = std::get_if<std::string>(&policy); 952c6a620f2SGeorge Liu 953c6a620f2SGeorge Liu if (!policyPtr) 954c6a620f2SGeorge Liu { 955c6a620f2SGeorge Liu messages::internalError(aResp->res); 956c6a620f2SGeorge Liu return; 957c6a620f2SGeorge Liu } 958c6a620f2SGeorge Liu 959c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 960c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 961c6a620f2SGeorge Liu { 962c6a620f2SGeorge Liu messages::internalError(aResp->res); 963c6a620f2SGeorge Liu return; 964c6a620f2SGeorge Liu } 965c6a620f2SGeorge Liu 966c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 967c6a620f2SGeorge Liu }, 968c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 969c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 970c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 971c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 972c6a620f2SGeorge Liu "PowerRestorePolicy"); 973c6a620f2SGeorge Liu } 974c6a620f2SGeorge Liu 975c6a620f2SGeorge Liu /** 976491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 977491d8ee7SSantosh Puranik * 978491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 979491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 980491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 981491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 982491d8ee7SSantosh Puranik * 983265c1602SJohnathan Mantey * @return Integer error code. 984491d8ee7SSantosh Puranik */ 985491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 986491d8ee7SSantosh Puranik bool oneTimeEnabled, 987491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 988491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 989491d8ee7SSantosh Puranik { 990944ffaf9SJohnathan Mantey std::string bootSourceStr = 991944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 992944ffaf9SJohnathan Mantey std::string bootModeStr = 993944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 994491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 995944ffaf9SJohnathan Mantey bool useBootSource = true; 996944ffaf9SJohnathan Mantey 997491d8ee7SSantosh Puranik // Validate incoming parameters 998491d8ee7SSantosh Puranik if (bootEnable) 999491d8ee7SSantosh Puranik { 1000491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1001491d8ee7SSantosh Puranik { 1002491d8ee7SSantosh Puranik oneTimeSetting = true; 1003491d8ee7SSantosh Puranik } 1004491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1005491d8ee7SSantosh Puranik { 1006491d8ee7SSantosh Puranik oneTimeSetting = false; 1007491d8ee7SSantosh Puranik } 1008491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1009491d8ee7SSantosh Puranik { 1010944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1011491d8ee7SSantosh Puranik oneTimeSetting = false; 1012944ffaf9SJohnathan Mantey useBootSource = false; 1013491d8ee7SSantosh Puranik } 1014491d8ee7SSantosh Puranik else 1015491d8ee7SSantosh Puranik { 1016491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1017491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1018491d8ee7SSantosh Puranik << *bootEnable; 1019491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1020491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1021491d8ee7SSantosh Puranik return; 1022491d8ee7SSantosh Puranik } 1023491d8ee7SSantosh Puranik } 1024491d8ee7SSantosh Puranik 1025944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1026491d8ee7SSantosh Puranik { 1027491d8ee7SSantosh Puranik // Source target specified 1028491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1029491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1030944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1031944ffaf9SJohnathan Mantey bootModeStr)) 1032491d8ee7SSantosh Puranik { 1033944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1034944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1035491d8ee7SSantosh Puranik << *bootSource; 1036491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1037491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1038491d8ee7SSantosh Puranik return; 1039491d8ee7SSantosh Puranik } 1040944ffaf9SJohnathan Mantey } 1041491d8ee7SSantosh Puranik 1042944ffaf9SJohnathan Mantey // Act on validated parameters 1043944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1044944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1045944ffaf9SJohnathan Mantey const char *bootObj = 1046944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1047944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1048944ffaf9SJohnathan Mantey 1049491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1050491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1051491d8ee7SSantosh Puranik if (ec) 1052491d8ee7SSantosh Puranik { 1053491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1054491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1055491d8ee7SSantosh Puranik return; 1056491d8ee7SSantosh Puranik } 1057491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1058491d8ee7SSantosh Puranik }, 1059491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1060491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1061491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1062491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1063944ffaf9SJohnathan Mantey 1064491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1065491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1066491d8ee7SSantosh Puranik if (ec) 1067491d8ee7SSantosh Puranik { 1068491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1069491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1070491d8ee7SSantosh Puranik return; 1071491d8ee7SSantosh Puranik } 1072491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1073491d8ee7SSantosh Puranik }, 1074491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1075491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1076491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1077491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1078944ffaf9SJohnathan Mantey 1079491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1080491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1081491d8ee7SSantosh Puranik if (ec) 1082491d8ee7SSantosh Puranik { 1083491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1084491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1085491d8ee7SSantosh Puranik return; 1086491d8ee7SSantosh Puranik } 1087491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1088491d8ee7SSantosh Puranik }, 1089491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1090491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1091491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1092491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1093491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1094491d8ee7SSantosh Puranik } 1095491d8ee7SSantosh Puranik 1096491d8ee7SSantosh Puranik /** 1097491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1098491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1099491d8ee7SSantosh Puranik * 1100491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1101491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1102491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1103491d8ee7SSantosh Puranik * 1104265c1602SJohnathan Mantey * @return Integer error code. 1105491d8ee7SSantosh Puranik */ 1106491d8ee7SSantosh Puranik static void setBootProperties(std::shared_ptr<AsyncResp> aResp, 1107491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1108491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1109491d8ee7SSantosh Puranik { 1110491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1111491d8ee7SSantosh Puranik 1112491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1113265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 1114*19bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 1115*19bd78d9SPatrick Williams const std::variant<bool> &oneTime) { 1116491d8ee7SSantosh Puranik if (ec) 1117491d8ee7SSantosh Puranik { 1118491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1119491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1120491d8ee7SSantosh Puranik return; 1121491d8ee7SSantosh Puranik } 1122491d8ee7SSantosh Puranik 1123491d8ee7SSantosh Puranik const bool *oneTimePtr = std::get_if<bool>(&oneTime); 1124491d8ee7SSantosh Puranik 1125491d8ee7SSantosh Puranik if (!oneTimePtr) 1126491d8ee7SSantosh Puranik { 1127491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1128491d8ee7SSantosh Puranik return; 1129491d8ee7SSantosh Puranik } 1130491d8ee7SSantosh Puranik 1131491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1132491d8ee7SSantosh Puranik 1133491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1134491d8ee7SSantosh Puranik std::move(bootEnable)); 1135491d8ee7SSantosh Puranik }, 1136491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1137491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1138491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1139491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1140491d8ee7SSantosh Puranik } 1141491d8ee7SSantosh Puranik 1142c6a620f2SGeorge Liu /** 1143c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1144c6a620f2SGeorge Liu * 1145c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1146c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1147c6a620f2SGeorge Liu * 1148c6a620f2SGeorge Liu * @return None. 1149c6a620f2SGeorge Liu */ 1150c6a620f2SGeorge Liu static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, 1151c6a620f2SGeorge Liu std::optional<std::string> policy) 1152c6a620f2SGeorge Liu { 1153c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1154c6a620f2SGeorge Liu 1155c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1156c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1157c6a620f2SGeorge Liu "AlwaysOn"}, 1158c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1159c6a620f2SGeorge Liu "AlwaysOff"}, 1160c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1161c6a620f2SGeorge Liu "LastState"}}; 1162c6a620f2SGeorge Liu 1163c6a620f2SGeorge Liu std::string powerRestorPolicy; 1164c6a620f2SGeorge Liu 1165c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policy); 1166c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1167c6a620f2SGeorge Liu { 1168c6a620f2SGeorge Liu messages::internalError(aResp->res); 1169c6a620f2SGeorge Liu return; 1170c6a620f2SGeorge Liu } 1171c6a620f2SGeorge Liu 1172c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1173c6a620f2SGeorge Liu 1174c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1175c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1176c6a620f2SGeorge Liu if (ec) 1177c6a620f2SGeorge Liu { 1178c6a620f2SGeorge Liu messages::internalError(aResp->res); 1179c6a620f2SGeorge Liu return; 1180c6a620f2SGeorge Liu } 1181c6a620f2SGeorge Liu }, 1182c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1183c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1184c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1185c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1186c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1187c6a620f2SGeorge Liu } 1188c6a620f2SGeorge Liu 1189a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1190a6349918SAppaRao Puli /** 1191a6349918SAppaRao Puli * @brief Retrieves provisioning status 1192a6349918SAppaRao Puli * 1193a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1194a6349918SAppaRao Puli * 1195a6349918SAppaRao Puli * @return None. 1196a6349918SAppaRao Puli */ 1197a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1198a6349918SAppaRao Puli { 1199a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1200a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1201a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 1202a6349918SAppaRao Puli const std::vector<std::pair<std::string, VariantType>> 1203a6349918SAppaRao Puli &propertiesList) { 1204a6349918SAppaRao Puli if (ec) 1205a6349918SAppaRao Puli { 1206a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1207a6349918SAppaRao Puli messages::internalError(aResp->res); 1208a6349918SAppaRao Puli return; 1209a6349918SAppaRao Puli } 1210a6349918SAppaRao Puli 1211a6349918SAppaRao Puli const bool *provState = nullptr; 1212a6349918SAppaRao Puli const bool *lockState = nullptr; 1213a6349918SAppaRao Puli for (const std::pair<std::string, VariantType> &property : 1214a6349918SAppaRao Puli propertiesList) 1215a6349918SAppaRao Puli { 1216a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1217a6349918SAppaRao Puli { 1218a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1219a6349918SAppaRao Puli } 1220a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1221a6349918SAppaRao Puli { 1222a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1223a6349918SAppaRao Puli } 1224a6349918SAppaRao Puli } 1225a6349918SAppaRao Puli 1226a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1227a6349918SAppaRao Puli { 1228a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1229a6349918SAppaRao Puli messages::internalError(aResp->res); 1230a6349918SAppaRao Puli return; 1231a6349918SAppaRao Puli } 1232a6349918SAppaRao Puli 1233a6349918SAppaRao Puli nlohmann::json &oemPFR = 1234a6349918SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1235a6349918SAppaRao Puli if (*provState == true) 1236a6349918SAppaRao Puli { 1237a6349918SAppaRao Puli if (*lockState == true) 1238a6349918SAppaRao Puli { 1239a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1240a6349918SAppaRao Puli } 1241a6349918SAppaRao Puli else 1242a6349918SAppaRao Puli { 1243a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1244a6349918SAppaRao Puli } 1245a6349918SAppaRao Puli } 1246a6349918SAppaRao Puli else 1247a6349918SAppaRao Puli { 1248a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1249a6349918SAppaRao Puli } 1250a6349918SAppaRao Puli }, 1251a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1252a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1253a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1254a6349918SAppaRao Puli } 1255a6349918SAppaRao Puli #endif 1256a6349918SAppaRao Puli 1257491d8ee7SSantosh Puranik /** 125851709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 125951709ffdSYong Li * 126051709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 126151709ffdSYong Li * 126251709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 126351709ffdSYong Li * translation cannot be done, returns an empty string. 126451709ffdSYong Li */ 126551709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string &dbusAction) 126651709ffdSYong Li { 126751709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 126851709ffdSYong Li { 126951709ffdSYong Li return "None"; 127051709ffdSYong Li } 127151709ffdSYong Li else if (dbusAction == 127251709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 127351709ffdSYong Li { 127451709ffdSYong Li return "ResetSystem"; 127551709ffdSYong Li } 127651709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 127751709ffdSYong Li { 127851709ffdSYong Li return "PowerDown"; 127951709ffdSYong Li } 128051709ffdSYong Li else if (dbusAction == 128151709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 128251709ffdSYong Li { 128351709ffdSYong Li return "PowerCycle"; 128451709ffdSYong Li } 128551709ffdSYong Li 128651709ffdSYong Li return ""; 128751709ffdSYong Li } 128851709ffdSYong Li 128951709ffdSYong Li /** 1290c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1291c45f0082SYong Li * 1292c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1293c45f0082SYong Li * 1294c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1295c45f0082SYong Li *If translation cannot be done, returns an empty string. 1296c45f0082SYong Li */ 1297c45f0082SYong Li 1298c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string &rfAction) 1299c45f0082SYong Li { 1300c45f0082SYong Li if (rfAction == "None") 1301c45f0082SYong Li { 1302c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1303c45f0082SYong Li } 1304c45f0082SYong Li else if (rfAction == "PowerCycle") 1305c45f0082SYong Li { 1306c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1307c45f0082SYong Li } 1308c45f0082SYong Li else if (rfAction == "PowerDown") 1309c45f0082SYong Li { 1310c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1311c45f0082SYong Li } 1312c45f0082SYong Li else if (rfAction == "ResetSystem") 1313c45f0082SYong Li { 1314c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1315c45f0082SYong Li } 1316c45f0082SYong Li 1317c45f0082SYong Li return ""; 1318c45f0082SYong Li } 1319c45f0082SYong Li 1320c45f0082SYong Li /** 132151709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 132251709ffdSYong Li * 132351709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 132451709ffdSYong Li * 132551709ffdSYong Li * @return None. 132651709ffdSYong Li */ 132751709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 132851709ffdSYong Li { 132951709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 133051709ffdSYong Li crow::connections::systemBus->async_method_call( 133151709ffdSYong Li [aResp](const boost::system::error_code ec, 133251709ffdSYong Li PropertiesType &properties) { 133351709ffdSYong Li if (ec) 133451709ffdSYong Li { 133551709ffdSYong Li // watchdog service is stopped 133651709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 133751709ffdSYong Li return; 133851709ffdSYong Li } 133951709ffdSYong Li 134051709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 134151709ffdSYong Li 134251709ffdSYong Li nlohmann::json &hostWatchdogTimer = 134351709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 134451709ffdSYong Li 134551709ffdSYong Li // watchdog service is running/enabled 134651709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 134751709ffdSYong Li 134851709ffdSYong Li for (const auto &property : properties) 134951709ffdSYong Li { 135051709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 135151709ffdSYong Li if (property.first == "Enabled") 135251709ffdSYong Li { 135351709ffdSYong Li const bool *state = std::get_if<bool>(&property.second); 135451709ffdSYong Li 135551709ffdSYong Li if (!state) 135651709ffdSYong Li { 135751709ffdSYong Li messages::internalError(aResp->res); 135851709ffdSYong Li continue; 135951709ffdSYong Li } 136051709ffdSYong Li 136151709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 136251709ffdSYong Li } 136351709ffdSYong Li else if (property.first == "ExpireAction") 136451709ffdSYong Li { 136551709ffdSYong Li const std::string *s = 136651709ffdSYong Li std::get_if<std::string>(&property.second); 136751709ffdSYong Li if (!s) 136851709ffdSYong Li { 136951709ffdSYong Li messages::internalError(aResp->res); 137051709ffdSYong Li continue; 137151709ffdSYong Li } 137251709ffdSYong Li 137351709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 137451709ffdSYong Li if (action.empty()) 137551709ffdSYong Li { 137651709ffdSYong Li messages::internalError(aResp->res); 137751709ffdSYong Li continue; 137851709ffdSYong Li } 137951709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 138051709ffdSYong Li } 138151709ffdSYong Li } 138251709ffdSYong Li }, 138351709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 138451709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 138551709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 138651709ffdSYong Li } 138751709ffdSYong Li 138851709ffdSYong Li /** 1389c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1390c45f0082SYong Li * 1391c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1392c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1393c45f0082SYong Li * RF request. 1394c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1395c45f0082SYong Li * 1396c45f0082SYong Li * @return None. 1397c45f0082SYong Li */ 1398c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1399c45f0082SYong Li const std::optional<bool> wdtEnable, 1400c45f0082SYong Li const std::optional<std::string> &wdtTimeOutAction) 1401c45f0082SYong Li { 1402c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1403c45f0082SYong Li 1404c45f0082SYong Li if (wdtTimeOutAction) 1405c45f0082SYong Li { 1406c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1407c45f0082SYong Li // check if TimeOut Action is Valid 1408c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1409c45f0082SYong Li { 1410c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1411c45f0082SYong Li << *wdtTimeOutAction; 1412c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1413c45f0082SYong Li "TimeoutAction"); 1414c45f0082SYong Li return; 1415c45f0082SYong Li } 1416c45f0082SYong Li 1417c45f0082SYong Li crow::connections::systemBus->async_method_call( 1418c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1419c45f0082SYong Li if (ec) 1420c45f0082SYong Li { 1421c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1422c45f0082SYong Li messages::internalError(aResp->res); 1423c45f0082SYong Li return; 1424c45f0082SYong Li } 1425c45f0082SYong Li }, 1426c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1427c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1428c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1429c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1430c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1431c45f0082SYong Li } 1432c45f0082SYong Li 1433c45f0082SYong Li if (wdtEnable) 1434c45f0082SYong Li { 1435c45f0082SYong Li crow::connections::systemBus->async_method_call( 1436c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1437c45f0082SYong Li if (ec) 1438c45f0082SYong Li { 1439c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1440c45f0082SYong Li messages::internalError(aResp->res); 1441c45f0082SYong Li return; 1442c45f0082SYong Li } 1443c45f0082SYong Li }, 1444c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1445c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1446c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1447c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1448c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1449c45f0082SYong Li } 1450c45f0082SYong Li } 1451c45f0082SYong Li 1452c45f0082SYong Li /** 1453c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1454c5b2abe0SLewanczyk, Dawid * Schema 1455c5b2abe0SLewanczyk, Dawid */ 14561abe55efSEd Tanous class SystemsCollection : public Node 14571abe55efSEd Tanous { 1458c5b2abe0SLewanczyk, Dawid public: 14591abe55efSEd Tanous SystemsCollection(CrowApp &app) : Node(app, "/redfish/v1/Systems/") 14601abe55efSEd Tanous { 1461c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1462c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1463c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1464c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1465c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1466c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1467c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1468c5b2abe0SLewanczyk, Dawid } 1469c5b2abe0SLewanczyk, Dawid 1470c5b2abe0SLewanczyk, Dawid private: 147155c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 14721abe55efSEd Tanous const std::vector<std::string> ¶ms) override 14731abe55efSEd Tanous { 1474462023adSSunitha Harish std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 14750f74e643SEd Tanous res.jsonValue["@odata.type"] = 14760f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 14770f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 14780f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1479462023adSSunitha Harish 1480462023adSSunitha Harish crow::connections::systemBus->async_method_call( 1481462023adSSunitha Harish [asyncResp](const boost::system::error_code ec, 1482462023adSSunitha Harish const std::variant<std::string> &hostName) { 1483462023adSSunitha Harish nlohmann::json &iface_array = 1484462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 1485462023adSSunitha Harish iface_array = nlohmann::json::array(); 1486462023adSSunitha Harish auto &count = asyncResp->res.jsonValue["Members@odata.count"]; 1487462023adSSunitha Harish count = 0; 1488462023adSSunitha Harish if (ec) 1489462023adSSunitha Harish { 1490462023adSSunitha Harish iface_array.push_back( 1491462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1492462023adSSunitha Harish count = iface_array.size(); 1493462023adSSunitha Harish return; 1494462023adSSunitha Harish } 1495462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 1496462023adSSunitha Harish iface_array.push_back( 1497462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1498462023adSSunitha Harish iface_array.push_back( 1499462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); 1500462023adSSunitha Harish count = iface_array.size(); 1501462023adSSunitha Harish }, 1502462023adSSunitha Harish "xyz.openbmc_project.Settings", "/xyz/openbmc_project/network/vmi", 1503462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 1504462023adSSunitha Harish "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); 1505c5b2abe0SLewanczyk, Dawid } 1506c5b2abe0SLewanczyk, Dawid }; 1507c5b2abe0SLewanczyk, Dawid 1508c5b2abe0SLewanczyk, Dawid /** 1509cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1510cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1511cc340dd9SEd Tanous */ 1512cc340dd9SEd Tanous class SystemActionsReset : public Node 1513cc340dd9SEd Tanous { 1514cc340dd9SEd Tanous public: 1515cc340dd9SEd Tanous SystemActionsReset(CrowApp &app) : 1516029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1517cc340dd9SEd Tanous { 1518cc340dd9SEd Tanous entityPrivileges = { 1519cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1520cc340dd9SEd Tanous } 1521cc340dd9SEd Tanous 1522cc340dd9SEd Tanous private: 1523cc340dd9SEd Tanous /** 1524cc340dd9SEd Tanous * Function handles POST method request. 1525cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1526cc340dd9SEd Tanous */ 1527cc340dd9SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 1528cc340dd9SEd Tanous const std::vector<std::string> ¶ms) override 1529cc340dd9SEd Tanous { 1530cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1531cc340dd9SEd Tanous 15329712f8acSEd Tanous std::string resetType; 15339712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1534cc340dd9SEd Tanous { 1535cc340dd9SEd Tanous return; 1536cc340dd9SEd Tanous } 1537cc340dd9SEd Tanous 1538d22c8396SJason M. Bills // Get the command and host vs. chassis 1539cc340dd9SEd Tanous std::string command; 1540d22c8396SJason M. Bills bool hostCommand; 15419712f8acSEd Tanous if (resetType == "On") 1542cc340dd9SEd Tanous { 1543cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1544d22c8396SJason M. Bills hostCommand = true; 1545d22c8396SJason M. Bills } 1546d22c8396SJason M. Bills else if (resetType == "ForceOff") 1547d22c8396SJason M. Bills { 1548d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1549d22c8396SJason M. Bills hostCommand = false; 1550d22c8396SJason M. Bills } 1551d22c8396SJason M. Bills else if (resetType == "ForceOn") 1552d22c8396SJason M. Bills { 1553d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1554d22c8396SJason M. Bills hostCommand = true; 1555d22c8396SJason M. Bills } 1556d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1557d22c8396SJason M. Bills { 155886a0851aSJason M. Bills command = 155986a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 156086a0851aSJason M. Bills hostCommand = true; 1561cc340dd9SEd Tanous } 15629712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1563cc340dd9SEd Tanous { 1564cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1565d22c8396SJason M. Bills hostCommand = true; 1566cc340dd9SEd Tanous } 15679712f8acSEd Tanous else if (resetType == "GracefulRestart") 1568cc340dd9SEd Tanous { 156986a0851aSJason M. Bills command = 157086a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 1571d22c8396SJason M. Bills hostCommand = true; 1572d22c8396SJason M. Bills } 1573d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1574d22c8396SJason M. Bills { 157586a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 157686a0851aSJason M. Bills hostCommand = true; 1577cc340dd9SEd Tanous } 1578bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1579bfd5b826SLakshminarayana R. Kammath { 1580bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1581bfd5b826SLakshminarayana R. Kammath return; 1582bfd5b826SLakshminarayana R. Kammath } 1583cc340dd9SEd Tanous else 1584cc340dd9SEd Tanous { 1585f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1586cc340dd9SEd Tanous return; 1587cc340dd9SEd Tanous } 1588cc340dd9SEd Tanous 1589d22c8396SJason M. Bills if (hostCommand) 1590d22c8396SJason M. Bills { 1591cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1592d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1593cc340dd9SEd Tanous if (ec) 1594cc340dd9SEd Tanous { 1595cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1596d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1597d22c8396SJason M. Bills { 1598d22c8396SJason M. Bills messages::actionParameterNotSupported( 1599d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1600d22c8396SJason M. Bills } 1601d22c8396SJason M. Bills else 1602d22c8396SJason M. Bills { 1603f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1604d22c8396SJason M. Bills } 1605cc340dd9SEd Tanous return; 1606cc340dd9SEd Tanous } 1607f12894f8SJason M. Bills messages::success(asyncResp->res); 1608cc340dd9SEd Tanous }, 1609cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1610cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1611cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 16129712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1613abf2add6SEd Tanous std::variant<std::string>{command}); 1614cc340dd9SEd Tanous } 1615d22c8396SJason M. Bills else 1616d22c8396SJason M. Bills { 1617d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1618d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1619d22c8396SJason M. Bills if (ec) 1620d22c8396SJason M. Bills { 1621d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1622d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1623d22c8396SJason M. Bills { 1624d22c8396SJason M. Bills messages::actionParameterNotSupported( 1625d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1626d22c8396SJason M. Bills } 1627d22c8396SJason M. Bills else 1628d22c8396SJason M. Bills { 1629d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1630d22c8396SJason M. Bills } 1631d22c8396SJason M. Bills return; 1632d22c8396SJason M. Bills } 1633d22c8396SJason M. Bills messages::success(asyncResp->res); 1634d22c8396SJason M. Bills }, 1635d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1636d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1637d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1638d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1639d22c8396SJason M. Bills std::variant<std::string>{command}); 1640d22c8396SJason M. Bills } 1641d22c8396SJason M. Bills } 1642bfd5b826SLakshminarayana R. Kammath /** 1643bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1644bfd5b826SLakshminarayana R. Kammath */ 1645bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp> &asyncResp) 1646bfd5b826SLakshminarayana R. Kammath { 1647bfd5b826SLakshminarayana R. Kammath constexpr char const *serviceName = 1648bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1649bfd5b826SLakshminarayana R. Kammath constexpr char const *objectPath = 1650bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1651bfd5b826SLakshminarayana R. Kammath constexpr char const *interfaceName = 1652bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1653bfd5b826SLakshminarayana R. Kammath constexpr char const *method = "NMI"; 1654bfd5b826SLakshminarayana R. Kammath 1655bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1656bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1657bfd5b826SLakshminarayana R. Kammath if (ec) 1658bfd5b826SLakshminarayana R. Kammath { 1659bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1660bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1661bfd5b826SLakshminarayana R. Kammath return; 1662bfd5b826SLakshminarayana R. Kammath } 1663bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1664bfd5b826SLakshminarayana R. Kammath }, 1665bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1666bfd5b826SLakshminarayana R. Kammath } 1667cc340dd9SEd Tanous }; 1668cc340dd9SEd Tanous 1669cc340dd9SEd Tanous /** 16706617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1671c5b2abe0SLewanczyk, Dawid */ 16721abe55efSEd Tanous class Systems : public Node 16731abe55efSEd Tanous { 1674c5b2abe0SLewanczyk, Dawid public: 1675c5b2abe0SLewanczyk, Dawid /* 1676c5b2abe0SLewanczyk, Dawid * Default Constructor 1677c5b2abe0SLewanczyk, Dawid */ 1678029573d4SEd Tanous Systems(CrowApp &app) : Node(app, "/redfish/v1/Systems/system/") 16791abe55efSEd Tanous { 1680c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1681c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1682c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1683c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1684c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1685c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1686c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1687c5b2abe0SLewanczyk, Dawid } 1688c5b2abe0SLewanczyk, Dawid 1689c5b2abe0SLewanczyk, Dawid private: 1690c5b2abe0SLewanczyk, Dawid /** 1691c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1692c5b2abe0SLewanczyk, Dawid */ 169355c7b7a2SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 16941abe55efSEd Tanous const std::vector<std::string> ¶ms) override 16951abe55efSEd Tanous { 1696491d8ee7SSantosh Puranik res.jsonValue["@odata.type"] = "#ComputerSystem.v1_6_0.ComputerSystem"; 1697450a25cbSGunnar Mills res.jsonValue["Name"] = "system"; 1698029573d4SEd Tanous res.jsonValue["Id"] = "system"; 16990f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 17000f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 17010f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 17020f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 17035fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 17040f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1705029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 170604a258f4SEd Tanous 1707443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1708029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1709443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1710029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1711a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1712a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1713029573d4SEd Tanous 1714cc340dd9SEd Tanous // TODO Need to support ForceRestart. 1715cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1716cc340dd9SEd Tanous {"target", 1717029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1718cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1719d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1720bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1721c5b2abe0SLewanczyk, Dawid 1722c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1723029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1724c4bf6374SJason M. Bills 1725d82a3acdSCarol Wang res.jsonValue["Bios"] = { 1726d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 1727d82a3acdSCarol Wang 1728c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1729c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1730c5d03ff4SJennifer Lee 1731c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1732c5d03ff4SJennifer Lee {"Health", "OK"}, 1733c5d03ff4SJennifer Lee {"State", "Enabled"}, 1734c5d03ff4SJennifer Lee }; 1735a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1736c5b2abe0SLewanczyk, Dawid 1737e284a7c1SJames Feist constexpr const std::array<const char *, 4> inventoryForSystems = { 1738b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 17392ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1740e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1741e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1742b49ac873SJames Feist 1743b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1744b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1745b49ac873SJames Feist [health](const boost::system::error_code ec, 1746b49ac873SJames Feist std::vector<std::string> &resp) { 1747b49ac873SJames Feist if (ec) 1748b49ac873SJames Feist { 1749b49ac873SJames Feist // no inventory 1750b49ac873SJames Feist return; 1751b49ac873SJames Feist } 1752b49ac873SJames Feist 1753b49ac873SJames Feist health->inventory = std::move(resp); 1754b49ac873SJames Feist }, 1755b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1756b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1757b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1758b49ac873SJames Feist int32_t(0), inventoryForSystems); 1759b49ac873SJames Feist 1760b49ac873SJames Feist health->populate(); 1761b49ac873SJames Feist 1762c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string &chassisId, 1763c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1764c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1765c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1766c5d03ff4SJennifer Lee }); 1767a3002228SAppaRao Puli 1768a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 17695bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 17706c34de48SEd Tanous getHostState(asyncResp); 1771491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1772adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 177351709ffdSYong Li getHostWatchdogTimer(asyncResp); 1774c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 1775a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1776a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1777a6349918SAppaRao Puli #endif 1778c5b2abe0SLewanczyk, Dawid } 1779c5b2abe0SLewanczyk, Dawid 178055c7b7a2SEd Tanous void doPatch(crow::Response &res, const crow::Request &req, 17811abe55efSEd Tanous const std::vector<std::string> ¶ms) override 17821abe55efSEd Tanous { 1783cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1784491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1785c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 1786c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 178741352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 178841352c24SSantosh Puranik 1789944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1790c6a620f2SGeorge Liu bootProps, "WatchdogTimer", wdtTimerProps, 1791c6a620f2SGeorge Liu "PowerRestorePolicy", powerRestorePolicy)) 17926617338dSEd Tanous { 17936617338dSEd Tanous return; 17946617338dSEd Tanous } 1795491d8ee7SSantosh Puranik 1796944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1797c45f0082SYong Li 1798c45f0082SYong Li if (wdtTimerProps) 1799c45f0082SYong Li { 1800c45f0082SYong Li std::optional<bool> wdtEnable; 1801c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1802c45f0082SYong Li 1803c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1804c45f0082SYong Li "FunctionEnabled", wdtEnable, 1805c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1806c45f0082SYong Li { 1807c45f0082SYong Li return; 1808c45f0082SYong Li } 1809c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 1810c45f0082SYong Li std::move(wdtTimeOutAction)); 1811c45f0082SYong Li } 1812c45f0082SYong Li 1813491d8ee7SSantosh Puranik if (bootProps) 1814491d8ee7SSantosh Puranik { 1815491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 1816491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 1817491d8ee7SSantosh Puranik 1818491d8ee7SSantosh Puranik if (!json_util::readJson(*bootProps, asyncResp->res, 1819491d8ee7SSantosh Puranik "BootSourceOverrideTarget", bootSource, 1820491d8ee7SSantosh Puranik "BootSourceOverrideEnabled", bootEnable)) 1821491d8ee7SSantosh Puranik { 1822491d8ee7SSantosh Puranik return; 1823491d8ee7SSantosh Puranik } 1824491d8ee7SSantosh Puranik setBootProperties(asyncResp, std::move(bootSource), 1825491d8ee7SSantosh Puranik std::move(bootEnable)); 1826491d8ee7SSantosh Puranik } 1827265c1602SJohnathan Mantey 18289712f8acSEd Tanous if (indicatorLed) 18296617338dSEd Tanous { 1830a3002228SAppaRao Puli setIndicatorLedState(asyncResp, std::move(*indicatorLed)); 18316617338dSEd Tanous } 1832c6a620f2SGeorge Liu 1833c6a620f2SGeorge Liu if (powerRestorePolicy) 1834c6a620f2SGeorge Liu { 1835c6a620f2SGeorge Liu setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); 1836c6a620f2SGeorge Liu } 1837c5b2abe0SLewanczyk, Dawid } 1838c5b2abe0SLewanczyk, Dawid }; 1839c5b2abe0SLewanczyk, Dawid } // namespace redfish 1840