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> 271214b7e7SGunnar Mills 28abf2add6SEd Tanous #include <variant> 29c5b2abe0SLewanczyk, Dawid 301abe55efSEd Tanous namespace redfish 311abe55efSEd Tanous { 32c5b2abe0SLewanczyk, Dawid 339d3ae10eSAlpana Kumari /** 349d3ae10eSAlpana Kumari * @brief Updates the Functional State of DIMMs 359d3ae10eSAlpana Kumari * 369d3ae10eSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 379d3ae10eSAlpana Kumari * @param[in] dimmState Dimm's Functional state, true/false 389d3ae10eSAlpana Kumari * 399d3ae10eSAlpana Kumari * @return None. 409d3ae10eSAlpana Kumari */ 419d3ae10eSAlpana Kumari void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, 429d3ae10eSAlpana Kumari const std::variant<bool>& dimmState) 439d3ae10eSAlpana Kumari { 449d3ae10eSAlpana Kumari const bool* isDimmFunctional = std::get_if<bool>(&dimmState); 459d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 469d3ae10eSAlpana Kumari { 479d3ae10eSAlpana Kumari messages::internalError(aResp->res); 489d3ae10eSAlpana Kumari return; 499d3ae10eSAlpana Kumari } 509d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 519d3ae10eSAlpana Kumari 529d3ae10eSAlpana Kumari // Set it as Enabled if atleast one DIMM is functional 539d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 549d3ae10eSAlpana Kumari // ENABLED. 559d3ae10eSAlpana Kumari nlohmann::json& prevMemSummary = 569d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 579d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 589d3ae10eSAlpana Kumari { 599d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 609d3ae10eSAlpana Kumari { 619d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 629d3ae10eSAlpana Kumari "Enabled"; 639d3ae10eSAlpana Kumari } 649d3ae10eSAlpana Kumari } 659d3ae10eSAlpana Kumari } 669d3ae10eSAlpana Kumari 6757e8c9beSAlpana Kumari /* 6857e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 6957e8c9beSAlpana Kumari * 7057e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7157e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7257e8c9beSAlpana Kumari * 7357e8c9beSAlpana Kumari * @return None. 7457e8c9beSAlpana Kumari */ 7557e8c9beSAlpana Kumari void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, 7657e8c9beSAlpana Kumari const std::variant<bool>& cpuPresenceState) 7757e8c9beSAlpana Kumari { 7857e8c9beSAlpana Kumari const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); 7957e8c9beSAlpana Kumari 8057e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 8157e8c9beSAlpana Kumari { 8257e8c9beSAlpana Kumari messages::internalError(aResp->res); 8357e8c9beSAlpana Kumari return; 8457e8c9beSAlpana Kumari } 8557e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8657e8c9beSAlpana Kumari 8757e8c9beSAlpana Kumari if (*isCpuPresent == true) 8857e8c9beSAlpana Kumari { 89b4b9595aSJames Feist nlohmann::json& procCount = 90b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 91b4b9595aSJames Feist auto procCountPtr = 92b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t*>(); 93b4b9595aSJames Feist if (procCountPtr != nullptr) 94b4b9595aSJames Feist { 95b4b9595aSJames Feist // shouldn't be possible to be nullptr 96b4b9595aSJames Feist *procCountPtr += 1; 9757e8c9beSAlpana Kumari } 98b4b9595aSJames Feist } 9957e8c9beSAlpana Kumari } 10057e8c9beSAlpana Kumari 10157e8c9beSAlpana Kumari /* 10257e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10357e8c9beSAlpana Kumari * CPU Functional State 10457e8c9beSAlpana Kumari * 10557e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10657e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10757e8c9beSAlpana Kumari * 10857e8c9beSAlpana Kumari * @return None. 10957e8c9beSAlpana Kumari */ 11057e8c9beSAlpana Kumari void modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, 11157e8c9beSAlpana Kumari const std::variant<bool>& cpuFunctionalState) 11257e8c9beSAlpana Kumari { 11357e8c9beSAlpana Kumari const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11457e8c9beSAlpana Kumari 11557e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 11657e8c9beSAlpana Kumari { 11757e8c9beSAlpana Kumari messages::internalError(aResp->res); 11857e8c9beSAlpana Kumari return; 11957e8c9beSAlpana Kumari } 12057e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 12157e8c9beSAlpana Kumari 12257e8c9beSAlpana Kumari nlohmann::json& prevProcState = 12357e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12457e8c9beSAlpana Kumari 12557e8c9beSAlpana Kumari // Set it as Enabled if atleast one CPU is functional 12657e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 12757e8c9beSAlpana Kumari // Functional. 12857e8c9beSAlpana Kumari if (prevProcState == "Disabled") 12957e8c9beSAlpana Kumari { 13057e8c9beSAlpana Kumari if (*isCpuFunctional == true) 13157e8c9beSAlpana Kumari { 13257e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13357e8c9beSAlpana Kumari "Enabled"; 13457e8c9beSAlpana Kumari } 13557e8c9beSAlpana Kumari } 13657e8c9beSAlpana Kumari } 13757e8c9beSAlpana Kumari 13857e8c9beSAlpana Kumari /* 139c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 140c5b2abe0SLewanczyk, Dawid * 141c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 142c5b2abe0SLewanczyk, Dawid * @param[in] name Computer system name from request 143c5b2abe0SLewanczyk, Dawid * 144c5b2abe0SLewanczyk, Dawid * @return None. 145c5b2abe0SLewanczyk, Dawid */ 1465bc2dc8eSJames Feist void getComputerSystem(std::shared_ptr<AsyncResp> aResp, 1475bc2dc8eSJames Feist std::shared_ptr<HealthPopulate> systemHealth) 1481abe55efSEd Tanous { 14955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1509d3ae10eSAlpana Kumari 15155c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1525bc2dc8eSJames Feist [aResp, systemHealth]( 153c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 154c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1556c34de48SEd Tanous std::string, 1561214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1571214b7e7SGunnar Mills subtree) { 1581abe55efSEd Tanous if (ec) 1591abe55efSEd Tanous { 16055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 161f12894f8SJason M. Bills messages::internalError(aResp->res); 162c5b2abe0SLewanczyk, Dawid return; 163c5b2abe0SLewanczyk, Dawid } 164c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1656c34de48SEd Tanous for (const std::pair<std::string, 1666c34de48SEd Tanous std::vector<std::pair< 1671214b7e7SGunnar Mills std::string, std::vector<std::string>>>>& 1681214b7e7SGunnar Mills object : subtree) 1691abe55efSEd Tanous { 170c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 17155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1721abe55efSEd Tanous const std::vector< 1731214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 1741214b7e7SGunnar Mills connectionNames = object.second; 1751abe55efSEd Tanous if (connectionNames.size() < 1) 1761abe55efSEd Tanous { 177c5b2abe0SLewanczyk, Dawid continue; 178c5b2abe0SLewanczyk, Dawid } 179029573d4SEd Tanous 1805bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1815bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1825bc2dc8eSJames Feist 1835bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1845bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1855bc2dc8eSJames Feist 1865bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1875bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1885bc2dc8eSJames Feist 1896c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1906c34de48SEd Tanous // BiosVer 19104a258f4SEd Tanous for (const auto& connection : connectionNames) 1921abe55efSEd Tanous { 19304a258f4SEd Tanous for (const auto& interfaceName : connection.second) 1941abe55efSEd Tanous { 19504a258f4SEd Tanous if (interfaceName == 19604a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 1971abe55efSEd Tanous { 1981abe55efSEd Tanous BMCWEB_LOG_DEBUG 19904a258f4SEd Tanous << "Found Dimm, now get its properties."; 2009d3ae10eSAlpana Kumari 20155c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2029d3ae10eSAlpana Kumari [aResp, service{connection.first}, 2039d3ae10eSAlpana Kumari path(std::move(path))]( 2049d3ae10eSAlpana Kumari const boost::system::error_code ec, 2056c34de48SEd Tanous const std::vector< 2061214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 2071214b7e7SGunnar Mills properties) { 2081abe55efSEd Tanous if (ec) 2091abe55efSEd Tanous { 2101abe55efSEd Tanous BMCWEB_LOG_ERROR 2116c34de48SEd Tanous << "DBUS response error " << ec; 212f12894f8SJason M. Bills messages::internalError(aResp->res); 213c5b2abe0SLewanczyk, Dawid return; 214c5b2abe0SLewanczyk, Dawid } 2156c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2166c34de48SEd Tanous << properties.size() 217c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2189d3ae10eSAlpana Kumari 2199d3ae10eSAlpana Kumari if (properties.size() > 0) 2209d3ae10eSAlpana Kumari { 22104a258f4SEd Tanous for (const std::pair<std::string, 2221214b7e7SGunnar Mills VariantType>& 2231214b7e7SGunnar Mills property : properties) 2241abe55efSEd Tanous { 2255fd7ba65SCheng C Yang if (property.first != 2265fd7ba65SCheng C Yang "MemorySizeInKB") 2271abe55efSEd Tanous { 2285fd7ba65SCheng C Yang continue; 2295fd7ba65SCheng C Yang } 2305fd7ba65SCheng C Yang const uint32_t* value = 2318d78b7a9SPatrick Williams std::get_if<uint32_t>( 2321b6b96c5SEd Tanous &property.second); 2335fd7ba65SCheng C Yang if (value == nullptr) 2341abe55efSEd Tanous { 2355fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2365fd7ba65SCheng C Yang << "Find incorrect type of " 2375fd7ba65SCheng C Yang "MemorySize"; 2385fd7ba65SCheng C Yang continue; 2395fd7ba65SCheng C Yang } 2405fd7ba65SCheng C Yang nlohmann::json& totalMemory = 2415fd7ba65SCheng C Yang aResp->res 2425fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2435fd7ba65SCheng C Yang "y"] 2445fd7ba65SCheng C Yang ["TotalSystemMe" 2455fd7ba65SCheng C Yang "moryGiB"]; 2465fd7ba65SCheng C Yang uint64_t* preValue = 2475fd7ba65SCheng C Yang totalMemory 2485fd7ba65SCheng C Yang .get_ptr<uint64_t*>(); 2495fd7ba65SCheng C Yang if (preValue == nullptr) 2505fd7ba65SCheng C Yang { 2515fd7ba65SCheng C Yang continue; 2525fd7ba65SCheng C Yang } 2535fd7ba65SCheng C Yang aResp->res 2545fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2556c34de48SEd Tanous ["TotalSystemMemoryGi" 2565fd7ba65SCheng C Yang "B"] = 2575fd7ba65SCheng C Yang *value / (1024 * 1024) + 2585fd7ba65SCheng C Yang *preValue; 2595fd7ba65SCheng C Yang aResp->res 2605fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2619d3ae10eSAlpana Kumari ["Status"]["State"] = 2621abe55efSEd Tanous "Enabled"; 263c5b2abe0SLewanczyk, Dawid } 264c5b2abe0SLewanczyk, Dawid } 2659d3ae10eSAlpana Kumari else 2669d3ae10eSAlpana Kumari { 2679d3ae10eSAlpana Kumari auto getDimmProperties = 2689d3ae10eSAlpana Kumari [aResp]( 2699d3ae10eSAlpana Kumari const boost::system::error_code 2709d3ae10eSAlpana Kumari ec, 2711214b7e7SGunnar Mills const std::variant<bool>& 2721214b7e7SGunnar Mills dimmState) { 2739d3ae10eSAlpana Kumari if (ec) 2749d3ae10eSAlpana Kumari { 2759d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2769d3ae10eSAlpana Kumari << "DBUS response " 2779d3ae10eSAlpana Kumari "error " 2789d3ae10eSAlpana Kumari << ec; 2799d3ae10eSAlpana Kumari return; 2809d3ae10eSAlpana Kumari } 2819d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2829d3ae10eSAlpana Kumari dimmState); 2839d3ae10eSAlpana Kumari }; 2849d3ae10eSAlpana Kumari crow::connections::systemBus 2859d3ae10eSAlpana Kumari ->async_method_call( 2869d3ae10eSAlpana Kumari std::move(getDimmProperties), 2879d3ae10eSAlpana Kumari service, path, 2889d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2899d3ae10eSAlpana Kumari "Properties", 2909d3ae10eSAlpana Kumari "Get", 2919d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2929d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2939d3ae10eSAlpana Kumari "Functional"); 2949d3ae10eSAlpana Kumari } 295c5b2abe0SLewanczyk, Dawid }, 29604a258f4SEd Tanous connection.first, path, 2976c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 2986c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 2995bc2dc8eSJames Feist 3005bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3011abe55efSEd Tanous } 30204a258f4SEd Tanous else if (interfaceName == 30304a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3041abe55efSEd Tanous { 3051abe55efSEd Tanous BMCWEB_LOG_DEBUG 30604a258f4SEd Tanous << "Found Cpu, now get its properties."; 30757e8c9beSAlpana Kumari 308a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 30957e8c9beSAlpana Kumari [aResp, service{connection.first}, 31057e8c9beSAlpana Kumari path(std::move(path))]( 31157e8c9beSAlpana Kumari const boost::system::error_code ec, 3126c34de48SEd Tanous const std::vector< 3131214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 3141214b7e7SGunnar Mills properties) { 3151abe55efSEd Tanous if (ec) 3161abe55efSEd Tanous { 3171abe55efSEd Tanous BMCWEB_LOG_ERROR 3186c34de48SEd Tanous << "DBUS response error " << ec; 319f12894f8SJason M. Bills messages::internalError(aResp->res); 320c5b2abe0SLewanczyk, Dawid return; 321c5b2abe0SLewanczyk, Dawid } 3226c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3236c34de48SEd Tanous << properties.size() 324c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32557e8c9beSAlpana Kumari 32657e8c9beSAlpana Kumari if (properties.size() > 0) 32757e8c9beSAlpana Kumari { 32804a258f4SEd Tanous for (const auto& property : properties) 3291abe55efSEd Tanous { 33057e8c9beSAlpana Kumari if (property.first == 33157e8c9beSAlpana Kumari "ProcessorFamily") 3321abe55efSEd Tanous { 333a0803efaSEd Tanous const std::string* value = 3348d78b7a9SPatrick Williams std::get_if<std::string>( 3351b6b96c5SEd Tanous &property.second); 3361abe55efSEd Tanous if (value != nullptr) 3371abe55efSEd Tanous { 3381214b7e7SGunnar Mills nlohmann::json& 3391214b7e7SGunnar Mills procSummary = 3401abe55efSEd Tanous aResp->res.jsonValue 3416c34de48SEd Tanous ["ProcessorSumm" 34204a258f4SEd Tanous "ary"]; 34304a258f4SEd Tanous nlohmann::json& procCount = 34404a258f4SEd Tanous procSummary["Count"]; 345b4b9595aSJames Feist 346b4b9595aSJames Feist auto procCountPtr = 347b4b9595aSJames Feist procCount.get_ptr< 348b4b9595aSJames Feist nlohmann::json:: 3491214b7e7SGunnar Mills number_integer_t*>(); 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, 3711214b7e7SGunnar Mills const std::variant<bool>& 3721214b7e7SGunnar Mills 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, 3891214b7e7SGunnar Mills const std::variant<bool>& 3901214b7e7SGunnar Mills 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( 4461214b7e7SGunnar Mills [aResp]( 4471214b7e7SGunnar Mills const boost::system::error_code ec, 4486c34de48SEd Tanous const std::vector< 4491214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 4501214b7e7SGunnar Mills properties) { 4511abe55efSEd Tanous if (ec) 4521abe55efSEd Tanous { 4531abe55efSEd Tanous BMCWEB_LOG_DEBUG 4546c34de48SEd Tanous << "DBUS response error " << ec; 455f12894f8SJason M. Bills messages::internalError(aResp->res); 456c5b2abe0SLewanczyk, Dawid return; 457c5b2abe0SLewanczyk, Dawid } 4586c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4596c34de48SEd Tanous << properties.size() 460c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4611abe55efSEd Tanous for (const std::pair<std::string, 4621214b7e7SGunnar Mills VariantType>& 4631214b7e7SGunnar Mills property : properties) 4641abe55efSEd Tanous { 46504a258f4SEd Tanous if (property.first == "UUID") 4661abe55efSEd Tanous { 467c5b2abe0SLewanczyk, Dawid const std::string* value = 4688d78b7a9SPatrick Williams std::get_if<std::string>( 4691b6b96c5SEd Tanous &property.second); 47004a258f4SEd Tanous 4711abe55efSEd Tanous if (value != nullptr) 4721abe55efSEd Tanous { 473029573d4SEd Tanous std::string valueStr = *value; 47404a258f4SEd Tanous if (valueStr.size() == 32) 4751abe55efSEd Tanous { 476029573d4SEd Tanous valueStr.insert(8, 1, '-'); 477029573d4SEd Tanous valueStr.insert(13, 1, '-'); 478029573d4SEd Tanous valueStr.insert(18, 1, '-'); 479029573d4SEd Tanous valueStr.insert(23, 1, '-'); 48004a258f4SEd Tanous } 481029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 48204a258f4SEd Tanous << valueStr; 483029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 48404a258f4SEd Tanous valueStr; 485c5b2abe0SLewanczyk, Dawid } 486c5b2abe0SLewanczyk, Dawid } 487c5b2abe0SLewanczyk, Dawid } 488c5b2abe0SLewanczyk, Dawid }, 48904a258f4SEd Tanous connection.first, path, 4906c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4911abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 492c5b2abe0SLewanczyk, Dawid } 493029573d4SEd Tanous else if (interfaceName == 494029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 4951abe55efSEd Tanous { 496029573d4SEd Tanous crow::connections::systemBus->async_method_call( 4971214b7e7SGunnar Mills [aResp]( 4981214b7e7SGunnar Mills const boost::system::error_code ec, 499029573d4SEd Tanous const std::vector< 5001214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 5011214b7e7SGunnar Mills propertiesList) { 502029573d4SEd Tanous if (ec) 503029573d4SEd Tanous { 504e4a4b9a9SJames Feist // doesn't have to include this 505e4a4b9a9SJames Feist // interface 506029573d4SEd Tanous return; 507029573d4SEd Tanous } 508698654b6SGunnar Mills BMCWEB_LOG_DEBUG 509698654b6SGunnar Mills << "Got " << propertiesList.size() 510029573d4SEd Tanous << " properties for system"; 511029573d4SEd Tanous for (const std::pair<std::string, 5121214b7e7SGunnar Mills VariantType>& 5131214b7e7SGunnar Mills property : propertiesList) 514029573d4SEd Tanous { 515fc5afcf9Sbeccabroek const std::string& propertyName = 516fc5afcf9Sbeccabroek property.first; 517fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 518fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 519fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 520fc5afcf9Sbeccabroek (propertyName == "Model")) 521fc5afcf9Sbeccabroek { 522029573d4SEd Tanous const std::string* value = 523fc5afcf9Sbeccabroek std::get_if<std::string>( 524029573d4SEd Tanous &property.second); 525029573d4SEd Tanous if (value != nullptr) 526029573d4SEd Tanous { 527029573d4SEd Tanous aResp->res 528fc5afcf9Sbeccabroek .jsonValue[propertyName] = 529029573d4SEd Tanous *value; 530029573d4SEd Tanous } 531029573d4SEd Tanous } 532fc5afcf9Sbeccabroek } 533c1e236a6SGunnar Mills 534cb7e1e7bSAndrew Geissler // Grab the bios version 535cb7e1e7bSAndrew Geissler fw_util::getActiveFwVersion( 536cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 537cb7e1e7bSAndrew Geissler "BiosVersion"); 538029573d4SEd Tanous }, 539029573d4SEd Tanous connection.first, path, 540029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 541029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 542029573d4SEd Tanous "Asset"); 543e4a4b9a9SJames Feist 544e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 545e4a4b9a9SJames Feist [aResp]( 546e4a4b9a9SJames Feist const boost::system::error_code ec, 547e4a4b9a9SJames Feist const std::variant<std::string>& property) { 548e4a4b9a9SJames Feist if (ec) 549e4a4b9a9SJames Feist { 550e4a4b9a9SJames Feist // doesn't have to include this 551e4a4b9a9SJames Feist // interface 552e4a4b9a9SJames Feist return; 553e4a4b9a9SJames Feist } 554e4a4b9a9SJames Feist 555e4a4b9a9SJames Feist const std::string* value = 556e4a4b9a9SJames Feist std::get_if<std::string>(&property); 557e4a4b9a9SJames Feist if (value != nullptr) 558e4a4b9a9SJames Feist { 559e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 560e4a4b9a9SJames Feist *value; 561e4a4b9a9SJames Feist } 562e4a4b9a9SJames Feist }, 563e4a4b9a9SJames Feist connection.first, path, 564e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 565e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 566e4a4b9a9SJames Feist "AssetTag", 567e4a4b9a9SJames Feist "AssetTag"); 568029573d4SEd Tanous } 569029573d4SEd Tanous } 570029573d4SEd Tanous } 571c5b2abe0SLewanczyk, Dawid } 572c5b2abe0SLewanczyk, Dawid }, 573c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 574c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 575c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 5766617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 5776617338dSEd Tanous std::array<const char*, 5>{ 5786617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 5796617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 5806617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 5816617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 5826617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 5836617338dSEd Tanous }); 584c5b2abe0SLewanczyk, Dawid } 585c5b2abe0SLewanczyk, Dawid 586c5b2abe0SLewanczyk, Dawid /** 587c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 588c5b2abe0SLewanczyk, Dawid * 589c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 590c5b2abe0SLewanczyk, Dawid * 591c5b2abe0SLewanczyk, Dawid * @return None. 592c5b2abe0SLewanczyk, Dawid */ 593a0803efaSEd Tanous void getHostState(std::shared_ptr<AsyncResp> aResp) 5941abe55efSEd Tanous { 59555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 59655c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 597c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 598abf2add6SEd Tanous const std::variant<std::string>& hostState) { 5991abe55efSEd Tanous if (ec) 6001abe55efSEd Tanous { 60155c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 602f12894f8SJason M. Bills messages::internalError(aResp->res); 603c5b2abe0SLewanczyk, Dawid return; 604c5b2abe0SLewanczyk, Dawid } 6056617338dSEd Tanous 606abf2add6SEd Tanous const std::string* s = std::get_if<std::string>(&hostState); 60755c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6086617338dSEd Tanous if (s != nullptr) 6091abe55efSEd Tanous { 610c5b2abe0SLewanczyk, Dawid // Verify Host State 61194732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6121abe55efSEd Tanous { 61355c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6146617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6151abe55efSEd Tanous } 61683935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6178c888608SGunnar Mills "Quiesced") 6188c888608SGunnar Mills { 6198c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6208c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6218c888608SGunnar Mills } 6228c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 62383935af9SAndrew Geissler "DiagnosticMode") 62483935af9SAndrew Geissler { 62583935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 62683935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 62783935af9SAndrew Geissler } 6281abe55efSEd Tanous else 6291abe55efSEd Tanous { 63055c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6316617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 632c5b2abe0SLewanczyk, Dawid } 633c5b2abe0SLewanczyk, Dawid } 634c5b2abe0SLewanczyk, Dawid }, 6356c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6366617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6376617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 638c5b2abe0SLewanczyk, Dawid } 639c5b2abe0SLewanczyk, Dawid 640c5b2abe0SLewanczyk, Dawid /** 641*786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 642491d8ee7SSantosh Puranik * 643491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 644491d8ee7SSantosh Puranik * 645491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 646491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 647491d8ee7SSantosh Puranik */ 648491d8ee7SSantosh Puranik static std::string dbusToRfBootSource(const std::string& dbusSource) 649491d8ee7SSantosh Puranik { 650491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 651491d8ee7SSantosh Puranik { 652491d8ee7SSantosh Puranik return "None"; 653491d8ee7SSantosh Puranik } 654491d8ee7SSantosh Puranik else if (dbusSource == 655491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 656491d8ee7SSantosh Puranik { 657491d8ee7SSantosh Puranik return "Hdd"; 658491d8ee7SSantosh Puranik } 659491d8ee7SSantosh Puranik else if (dbusSource == 660a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 661491d8ee7SSantosh Puranik { 662491d8ee7SSantosh Puranik return "Cd"; 663491d8ee7SSantosh Puranik } 664491d8ee7SSantosh Puranik else if (dbusSource == 665491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 666491d8ee7SSantosh Puranik { 667491d8ee7SSantosh Puranik return "Pxe"; 668491d8ee7SSantosh Puranik } 6699f16b2c1SJennifer Lee else if (dbusSource == 670944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 6719f16b2c1SJennifer Lee { 6729f16b2c1SJennifer Lee return "Usb"; 6739f16b2c1SJennifer Lee } 674491d8ee7SSantosh Puranik else 675491d8ee7SSantosh Puranik { 676491d8ee7SSantosh Puranik return ""; 677491d8ee7SSantosh Puranik } 678491d8ee7SSantosh Puranik } 679491d8ee7SSantosh Puranik 680491d8ee7SSantosh Puranik /** 681*786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 682491d8ee7SSantosh Puranik * 683491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 684491d8ee7SSantosh Puranik * 685491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 686491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 687491d8ee7SSantosh Puranik */ 688491d8ee7SSantosh Puranik static std::string dbusToRfBootMode(const std::string& dbusMode) 689491d8ee7SSantosh Puranik { 690491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 691491d8ee7SSantosh Puranik { 692491d8ee7SSantosh Puranik return "None"; 693491d8ee7SSantosh Puranik } 694491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 695491d8ee7SSantosh Puranik { 696491d8ee7SSantosh Puranik return "Diags"; 697491d8ee7SSantosh Puranik } 698491d8ee7SSantosh Puranik else if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 699491d8ee7SSantosh Puranik { 700491d8ee7SSantosh Puranik return "BiosSetup"; 701491d8ee7SSantosh Puranik } 702491d8ee7SSantosh Puranik else 703491d8ee7SSantosh Puranik { 704491d8ee7SSantosh Puranik return ""; 705491d8ee7SSantosh Puranik } 706491d8ee7SSantosh Puranik } 707491d8ee7SSantosh Puranik 708491d8ee7SSantosh Puranik /** 709*786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 710491d8ee7SSantosh Puranik * 711491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 712944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 713944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 714491d8ee7SSantosh Puranik * 715944ffaf9SJohnathan Mantey * @return Integer error code. 716491d8ee7SSantosh Puranik */ 717944ffaf9SJohnathan Mantey static int assignBootParameters(std::shared_ptr<AsyncResp> aResp, 718944ffaf9SJohnathan Mantey const std::string& rfSource, 719944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 720491d8ee7SSantosh Puranik { 721944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 722944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 723944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 724944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 725944ffaf9SJohnathan Mantey // desired boot action. 726944ffaf9SJohnathan Mantey 727491d8ee7SSantosh Puranik if (rfSource == "None") 728491d8ee7SSantosh Puranik { 729944ffaf9SJohnathan Mantey return 0; 730491d8ee7SSantosh Puranik } 731491d8ee7SSantosh Puranik else if (rfSource == "Pxe") 732491d8ee7SSantosh Puranik { 733944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 734944ffaf9SJohnathan Mantey } 735944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 736944ffaf9SJohnathan Mantey { 737944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 738944ffaf9SJohnathan Mantey } 739944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 740944ffaf9SJohnathan Mantey { 741944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 742944ffaf9SJohnathan Mantey } 743944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 744944ffaf9SJohnathan Mantey { 745944ffaf9SJohnathan Mantey bootSource = 746944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 747944ffaf9SJohnathan Mantey } 748944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 749944ffaf9SJohnathan Mantey { 750944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 751491d8ee7SSantosh Puranik } 7529f16b2c1SJennifer Lee else if (rfSource == "Usb") 7539f16b2c1SJennifer Lee { 754944ffaf9SJohnathan Mantey bootSource = 755944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7569f16b2c1SJennifer Lee } 757491d8ee7SSantosh Puranik else 758491d8ee7SSantosh Puranik { 759944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 760944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 761944ffaf9SJohnathan Mantey << bootSource; 762944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 763944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 764944ffaf9SJohnathan Mantey return -1; 765491d8ee7SSantosh Puranik } 766944ffaf9SJohnathan Mantey return 0; 767491d8ee7SSantosh Puranik } 768491d8ee7SSantosh Puranik 769491d8ee7SSantosh Puranik /** 770491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 771491d8ee7SSantosh Puranik * 772491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 773491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 774491d8ee7SSantosh Puranik * 775491d8ee7SSantosh Puranik * @return None. 776491d8ee7SSantosh Puranik */ 777491d8ee7SSantosh Puranik static void getBootMode(std::shared_ptr<AsyncResp> aResp, 778491d8ee7SSantosh Puranik std::string bootDbusObj) 779491d8ee7SSantosh Puranik { 780491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 781491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 782491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 783491d8ee7SSantosh Puranik if (ec) 784491d8ee7SSantosh Puranik { 785491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 786491d8ee7SSantosh Puranik messages::internalError(aResp->res); 787491d8ee7SSantosh Puranik return; 788491d8ee7SSantosh Puranik } 789491d8ee7SSantosh Puranik 790491d8ee7SSantosh Puranik const std::string* bootModeStr = 791491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 792491d8ee7SSantosh Puranik 793491d8ee7SSantosh Puranik if (!bootModeStr) 794491d8ee7SSantosh Puranik { 795491d8ee7SSantosh Puranik messages::internalError(aResp->res); 796491d8ee7SSantosh Puranik return; 797491d8ee7SSantosh Puranik } 798491d8ee7SSantosh Puranik 799491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 800491d8ee7SSantosh Puranik 801491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 802491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 803491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 804491d8ee7SSantosh Puranik "AllowableValues"] = { 805944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 806491d8ee7SSantosh Puranik 807491d8ee7SSantosh Puranik if (*bootModeStr != 808491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 809491d8ee7SSantosh Puranik { 810491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 811491d8ee7SSantosh Puranik if (!rfMode.empty()) 812491d8ee7SSantosh Puranik { 813491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 814491d8ee7SSantosh Puranik rfMode; 815491d8ee7SSantosh Puranik } 816491d8ee7SSantosh Puranik } 817491d8ee7SSantosh Puranik 818491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 819491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 820491d8ee7SSantosh Puranik // overrides are disabled 821491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 822491d8ee7SSantosh Puranik "None") 823491d8ee7SSantosh Puranik { 824491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 825491d8ee7SSantosh Puranik "Disabled"; 826491d8ee7SSantosh Puranik } 827491d8ee7SSantosh Puranik }, 828491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 829491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 830491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 831491d8ee7SSantosh Puranik } 832491d8ee7SSantosh Puranik 833491d8ee7SSantosh Puranik /** 834491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 835491d8ee7SSantosh Puranik * 836491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 837491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 838491d8ee7SSantosh Puranik * 839491d8ee7SSantosh Puranik * @return None. 840491d8ee7SSantosh Puranik */ 841491d8ee7SSantosh Puranik static void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) 842491d8ee7SSantosh Puranik { 843491d8ee7SSantosh Puranik std::string bootDbusObj = 844491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 845491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 846491d8ee7SSantosh Puranik 847491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 848491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 849491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 850491d8ee7SSantosh Puranik 851491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 852491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 853491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 854491d8ee7SSantosh Puranik if (ec) 855491d8ee7SSantosh Puranik { 856491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 857491d8ee7SSantosh Puranik messages::internalError(aResp->res); 858491d8ee7SSantosh Puranik return; 859491d8ee7SSantosh Puranik } 860491d8ee7SSantosh Puranik 861491d8ee7SSantosh Puranik const std::string* bootSourceStr = 862491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 863491d8ee7SSantosh Puranik 864491d8ee7SSantosh Puranik if (!bootSourceStr) 865491d8ee7SSantosh Puranik { 866491d8ee7SSantosh Puranik messages::internalError(aResp->res); 867491d8ee7SSantosh Puranik return; 868491d8ee7SSantosh Puranik } 869491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 870491d8ee7SSantosh Puranik 871491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 872491d8ee7SSantosh Puranik if (!rfSource.empty()) 873491d8ee7SSantosh Puranik { 874491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 875491d8ee7SSantosh Puranik rfSource; 876491d8ee7SSantosh Puranik } 877491d8ee7SSantosh Puranik }, 878491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 879491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 880491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 881491d8ee7SSantosh Puranik getBootMode(std::move(aResp), std::move(bootDbusObj)); 882491d8ee7SSantosh Puranik } 883491d8ee7SSantosh Puranik 884491d8ee7SSantosh Puranik /** 885491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 886491d8ee7SSantosh Puranik * get boot source and boot mode. 887491d8ee7SSantosh Puranik * 888491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 889491d8ee7SSantosh Puranik * 890491d8ee7SSantosh Puranik * @return None. 891491d8ee7SSantosh Puranik */ 892491d8ee7SSantosh Puranik static void getBootProperties(std::shared_ptr<AsyncResp> aResp) 893491d8ee7SSantosh Puranik { 894491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 895491d8ee7SSantosh Puranik 896491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 897c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 89819bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 899491d8ee7SSantosh Puranik if (ec) 900491d8ee7SSantosh Puranik { 901491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 9022a833c77SJames Feist // not an error, don't have to have the interface 903491d8ee7SSantosh Puranik return; 904491d8ee7SSantosh Puranik } 905491d8ee7SSantosh Puranik 906491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 907491d8ee7SSantosh Puranik 908491d8ee7SSantosh Puranik if (!oneTimePtr) 909491d8ee7SSantosh Puranik { 910491d8ee7SSantosh Puranik messages::internalError(aResp->res); 911491d8ee7SSantosh Puranik return; 912491d8ee7SSantosh Puranik } 913491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 914491d8ee7SSantosh Puranik }, 915491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 916491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 917491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 918491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 919491d8ee7SSantosh Puranik } 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik /** 922c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 923c0557e1aSGunnar Mills * 924c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 925c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 926c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 927c0557e1aSGunnar Mills * last power operation time. 928c0557e1aSGunnar Mills * 929c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 930c0557e1aSGunnar Mills * 931c0557e1aSGunnar Mills * @return None. 932c0557e1aSGunnar Mills */ 933c0557e1aSGunnar Mills void getLastResetTime(std::shared_ptr<AsyncResp> aResp) 934c0557e1aSGunnar Mills { 935c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 936c0557e1aSGunnar Mills 937c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 938c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 939c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 940c0557e1aSGunnar Mills if (ec) 941c0557e1aSGunnar Mills { 942c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 943c0557e1aSGunnar Mills return; 944c0557e1aSGunnar Mills } 945c0557e1aSGunnar Mills 946c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 947c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 948c0557e1aSGunnar Mills 949c0557e1aSGunnar Mills if (!lastResetTimePtr) 950c0557e1aSGunnar Mills { 951c0557e1aSGunnar Mills messages::internalError(aResp->res); 952c0557e1aSGunnar Mills return; 953c0557e1aSGunnar Mills } 954c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 955c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 956c0557e1aSGunnar Mills time_t lastResetTimeStamp = 957c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 958c0557e1aSGunnar Mills 959c0557e1aSGunnar Mills // Convert to ISO 8601 standard 960c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 961c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 962c0557e1aSGunnar Mills }, 963c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 964c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 965c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 966c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 967c0557e1aSGunnar Mills } 968c0557e1aSGunnar Mills 969c0557e1aSGunnar Mills /** 9706bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 9716bd5a8d2SGunnar Mills * 9726bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 9736bd5a8d2SGunnar Mills * 9746bd5a8d2SGunnar Mills * @return None. 9756bd5a8d2SGunnar Mills */ 9766bd5a8d2SGunnar Mills void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) 9776bd5a8d2SGunnar Mills { 9786bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 9796bd5a8d2SGunnar Mills 9806bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 9816bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 9826bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 9836bd5a8d2SGunnar Mills if (ec) 9846bd5a8d2SGunnar Mills { 9856bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 9866bd5a8d2SGunnar Mills return; 9876bd5a8d2SGunnar Mills } 9886bd5a8d2SGunnar Mills 9896bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 9906bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 9916bd5a8d2SGunnar Mills 9926bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 9936bd5a8d2SGunnar Mills { 9946bd5a8d2SGunnar Mills messages::internalError(aResp->res); 9956bd5a8d2SGunnar Mills return; 9966bd5a8d2SGunnar Mills } 9976bd5a8d2SGunnar Mills 9986bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 9996bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 10006bd5a8d2SGunnar Mills { 10016bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 10026bd5a8d2SGunnar Mills "RetryAttempts"; 10036bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 10046bd5a8d2SGunnar Mills // attempts are left 10056bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 10066bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 10076bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 10086bd5a8d2SGunnar Mills if (ec) 10096bd5a8d2SGunnar Mills { 10106bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 10116bd5a8d2SGunnar Mills return; 10126bd5a8d2SGunnar Mills } 10136bd5a8d2SGunnar Mills 10146bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 10156bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 10166bd5a8d2SGunnar Mills 10176bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 10186bd5a8d2SGunnar Mills { 10196bd5a8d2SGunnar Mills messages::internalError(aResp->res); 10206bd5a8d2SGunnar Mills return; 10216bd5a8d2SGunnar Mills } 10226bd5a8d2SGunnar Mills 10236bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 10246bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 10256bd5a8d2SGunnar Mills 10266bd5a8d2SGunnar Mills aResp->res 10276bd5a8d2SGunnar Mills .jsonValue["Boot"] 10286bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 10296bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 10306bd5a8d2SGunnar Mills }, 10316bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 10326bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 10336bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 10346bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 10356bd5a8d2SGunnar Mills "AttemptsLeft"); 10366bd5a8d2SGunnar Mills } 10376bd5a8d2SGunnar Mills else 10386bd5a8d2SGunnar Mills { 10396bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 10406bd5a8d2SGunnar Mills "Disabled"; 10416bd5a8d2SGunnar Mills } 10426bd5a8d2SGunnar Mills 10436bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 10446bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 10456bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 104669f35306SGunnar Mills 104769f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 104869f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 104969f35306SGunnar Mills // RetryAttempts. 105069f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 105169f35306SGunnar Mills "AllowableValues"] = {"Disabled", 105269f35306SGunnar Mills "RetryAttempts"}; 10536bd5a8d2SGunnar Mills }, 10546bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 10556bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 10566bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 10576bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 10586bd5a8d2SGunnar Mills } 10596bd5a8d2SGunnar Mills 10606bd5a8d2SGunnar Mills /** 1061c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1062c6a620f2SGeorge Liu * 1063c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1064c6a620f2SGeorge Liu * 1065c6a620f2SGeorge Liu * @return None. 1066c6a620f2SGeorge Liu */ 1067c6a620f2SGeorge Liu void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) 1068c6a620f2SGeorge Liu { 1069c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1070c6a620f2SGeorge Liu 1071c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1072c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 107319bd78d9SPatrick Williams std::variant<std::string>& policy) { 1074c6a620f2SGeorge Liu if (ec) 1075c6a620f2SGeorge Liu { 1076c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1077c6a620f2SGeorge Liu return; 1078c6a620f2SGeorge Liu } 1079c6a620f2SGeorge Liu 1080c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1081c6a620f2SGeorge Liu policyMaps = { 1082c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1083c6a620f2SGeorge Liu "AlwaysOn", 1084c6a620f2SGeorge Liu "AlwaysOn"}, 1085c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1086c6a620f2SGeorge Liu "AlwaysOff", 1087c6a620f2SGeorge Liu "AlwaysOff"}, 1088c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1089c6a620f2SGeorge Liu "LastState", 1090c6a620f2SGeorge Liu "LastState"}}; 1091c6a620f2SGeorge Liu 1092c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1093c6a620f2SGeorge Liu 1094c6a620f2SGeorge Liu if (!policyPtr) 1095c6a620f2SGeorge Liu { 1096c6a620f2SGeorge Liu messages::internalError(aResp->res); 1097c6a620f2SGeorge Liu return; 1098c6a620f2SGeorge Liu } 1099c6a620f2SGeorge Liu 1100c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1101c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1102c6a620f2SGeorge Liu { 1103c6a620f2SGeorge Liu messages::internalError(aResp->res); 1104c6a620f2SGeorge Liu return; 1105c6a620f2SGeorge Liu } 1106c6a620f2SGeorge Liu 1107c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1108c6a620f2SGeorge Liu }, 1109c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1110c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1111c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1112c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1113c6a620f2SGeorge Liu "PowerRestorePolicy"); 1114c6a620f2SGeorge Liu } 1115c6a620f2SGeorge Liu 1116c6a620f2SGeorge Liu /** 1117491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1118491d8ee7SSantosh Puranik * 1119491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1120491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1121491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1122491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1123491d8ee7SSantosh Puranik * 1124265c1602SJohnathan Mantey * @return Integer error code. 1125491d8ee7SSantosh Puranik */ 1126491d8ee7SSantosh Puranik static void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, 1127491d8ee7SSantosh Puranik bool oneTimeEnabled, 1128491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1129491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1130491d8ee7SSantosh Puranik { 1131944ffaf9SJohnathan Mantey std::string bootSourceStr = 1132944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1133944ffaf9SJohnathan Mantey std::string bootModeStr = 1134944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1135491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1136944ffaf9SJohnathan Mantey bool useBootSource = true; 1137944ffaf9SJohnathan Mantey 1138491d8ee7SSantosh Puranik // Validate incoming parameters 1139491d8ee7SSantosh Puranik if (bootEnable) 1140491d8ee7SSantosh Puranik { 1141491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1142491d8ee7SSantosh Puranik { 1143491d8ee7SSantosh Puranik oneTimeSetting = true; 1144491d8ee7SSantosh Puranik } 1145491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1146491d8ee7SSantosh Puranik { 1147491d8ee7SSantosh Puranik oneTimeSetting = false; 1148491d8ee7SSantosh Puranik } 1149491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1150491d8ee7SSantosh Puranik { 1151944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1152491d8ee7SSantosh Puranik oneTimeSetting = false; 1153944ffaf9SJohnathan Mantey useBootSource = false; 1154491d8ee7SSantosh Puranik } 1155491d8ee7SSantosh Puranik else 1156491d8ee7SSantosh Puranik { 1157491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1158491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1159491d8ee7SSantosh Puranik << *bootEnable; 1160491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1161491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1162491d8ee7SSantosh Puranik return; 1163491d8ee7SSantosh Puranik } 1164491d8ee7SSantosh Puranik } 1165491d8ee7SSantosh Puranik 1166944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1167491d8ee7SSantosh Puranik { 1168491d8ee7SSantosh Puranik // Source target specified 1169491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1170491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1171944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1172944ffaf9SJohnathan Mantey bootModeStr)) 1173491d8ee7SSantosh Puranik { 1174944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1175944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1176491d8ee7SSantosh Puranik << *bootSource; 1177491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1178491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1179491d8ee7SSantosh Puranik return; 1180491d8ee7SSantosh Puranik } 1181944ffaf9SJohnathan Mantey } 1182491d8ee7SSantosh Puranik 1183944ffaf9SJohnathan Mantey // Act on validated parameters 1184944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1185944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1186944ffaf9SJohnathan Mantey const char* bootObj = 1187944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1188944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1189944ffaf9SJohnathan Mantey 1190491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1191491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1192491d8ee7SSantosh Puranik if (ec) 1193491d8ee7SSantosh Puranik { 1194491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1195491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1196491d8ee7SSantosh Puranik return; 1197491d8ee7SSantosh Puranik } 1198491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1199491d8ee7SSantosh Puranik }, 1200491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1201491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1202491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1203491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1204944ffaf9SJohnathan Mantey 1205491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1206491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1207491d8ee7SSantosh Puranik if (ec) 1208491d8ee7SSantosh Puranik { 1209491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1210491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1211491d8ee7SSantosh Puranik return; 1212491d8ee7SSantosh Puranik } 1213491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1214491d8ee7SSantosh Puranik }, 1215491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1216491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1217491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1218491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1219944ffaf9SJohnathan Mantey 1220491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1221491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1222491d8ee7SSantosh Puranik if (ec) 1223491d8ee7SSantosh Puranik { 1224491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1225491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1226491d8ee7SSantosh Puranik return; 1227491d8ee7SSantosh Puranik } 1228491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1229491d8ee7SSantosh Puranik }, 1230491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1231491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1232491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1233491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1234491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1235491d8ee7SSantosh Puranik } 1236491d8ee7SSantosh Puranik 1237491d8ee7SSantosh Puranik /** 1238491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1239491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1240491d8ee7SSantosh Puranik * 1241491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1242491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1243491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1244491d8ee7SSantosh Puranik * 1245265c1602SJohnathan Mantey * @return Integer error code. 1246491d8ee7SSantosh Puranik */ 124769f35306SGunnar Mills static void setBootSourceProperties(std::shared_ptr<AsyncResp> aResp, 1248491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1249491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1250491d8ee7SSantosh Puranik { 1251491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1252491d8ee7SSantosh Puranik 1253491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1254265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 125519bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 125619bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1257491d8ee7SSantosh Puranik if (ec) 1258491d8ee7SSantosh Puranik { 1259491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1260491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1261491d8ee7SSantosh Puranik return; 1262491d8ee7SSantosh Puranik } 1263491d8ee7SSantosh Puranik 1264491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1265491d8ee7SSantosh Puranik 1266491d8ee7SSantosh Puranik if (!oneTimePtr) 1267491d8ee7SSantosh Puranik { 1268491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1269491d8ee7SSantosh Puranik return; 1270491d8ee7SSantosh Puranik } 1271491d8ee7SSantosh Puranik 1272491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1273491d8ee7SSantosh Puranik 1274491d8ee7SSantosh Puranik setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), 1275491d8ee7SSantosh Puranik std::move(bootEnable)); 1276491d8ee7SSantosh Puranik }, 1277491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1278491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1279491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1280491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1281491d8ee7SSantosh Puranik } 1282491d8ee7SSantosh Puranik 1283c6a620f2SGeorge Liu /** 128469f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 128569f35306SGunnar Mills * 128669f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 128769f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 128869f35306SGunnar Mills * 128969f35306SGunnar Mills * @return None. 129069f35306SGunnar Mills */ 129169f35306SGunnar Mills static void setAutomaticRetry(std::shared_ptr<AsyncResp> aResp, 129269f35306SGunnar Mills const std::string&& automaticRetryConfig) 129369f35306SGunnar Mills { 129469f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 129569f35306SGunnar Mills 129669f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 129769f35306SGunnar Mills bool autoRebootEnabled; 129869f35306SGunnar Mills 129969f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 130069f35306SGunnar Mills { 130169f35306SGunnar Mills autoRebootEnabled = false; 130269f35306SGunnar Mills } 130369f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 130469f35306SGunnar Mills { 130569f35306SGunnar Mills autoRebootEnabled = true; 130669f35306SGunnar Mills } 130769f35306SGunnar Mills else 130869f35306SGunnar Mills { 130969f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 131069f35306SGunnar Mills "AutomaticRetryConfig: " 131169f35306SGunnar Mills << automaticRetryConfig; 131269f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 131369f35306SGunnar Mills "AutomaticRetryConfig"); 131469f35306SGunnar Mills return; 131569f35306SGunnar Mills } 131669f35306SGunnar Mills 131769f35306SGunnar Mills crow::connections::systemBus->async_method_call( 131869f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 131969f35306SGunnar Mills if (ec) 132069f35306SGunnar Mills { 132169f35306SGunnar Mills messages::internalError(aResp->res); 132269f35306SGunnar Mills return; 132369f35306SGunnar Mills } 132469f35306SGunnar Mills }, 132569f35306SGunnar Mills "xyz.openbmc_project.Settings", 132669f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 132769f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 132869f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 132969f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 133069f35306SGunnar Mills } 133169f35306SGunnar Mills 133269f35306SGunnar Mills /** 1333c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1334c6a620f2SGeorge Liu * 1335c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1336c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1337c6a620f2SGeorge Liu * 1338c6a620f2SGeorge Liu * @return None. 1339c6a620f2SGeorge Liu */ 1340c6a620f2SGeorge Liu static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, 1341c6a620f2SGeorge Liu std::optional<std::string> policy) 1342c6a620f2SGeorge Liu { 1343c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1344c6a620f2SGeorge Liu 1345c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1346c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1347c6a620f2SGeorge Liu "AlwaysOn"}, 1348c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1349c6a620f2SGeorge Liu "AlwaysOff"}, 1350c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1351c6a620f2SGeorge Liu "LastState"}}; 1352c6a620f2SGeorge Liu 1353c6a620f2SGeorge Liu std::string powerRestorPolicy; 1354c6a620f2SGeorge Liu 1355c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policy); 1356c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1357c6a620f2SGeorge Liu { 1358c6a620f2SGeorge Liu messages::internalError(aResp->res); 1359c6a620f2SGeorge Liu return; 1360c6a620f2SGeorge Liu } 1361c6a620f2SGeorge Liu 1362c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1363c6a620f2SGeorge Liu 1364c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1365c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1366c6a620f2SGeorge Liu if (ec) 1367c6a620f2SGeorge Liu { 1368c6a620f2SGeorge Liu messages::internalError(aResp->res); 1369c6a620f2SGeorge Liu return; 1370c6a620f2SGeorge Liu } 1371c6a620f2SGeorge Liu }, 1372c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1373c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1374c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1375c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1376c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1377c6a620f2SGeorge Liu } 1378c6a620f2SGeorge Liu 1379a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1380a6349918SAppaRao Puli /** 1381a6349918SAppaRao Puli * @brief Retrieves provisioning status 1382a6349918SAppaRao Puli * 1383a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1384a6349918SAppaRao Puli * 1385a6349918SAppaRao Puli * @return None. 1386a6349918SAppaRao Puli */ 1387a6349918SAppaRao Puli void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) 1388a6349918SAppaRao Puli { 1389a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1390a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1391a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 13921214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 13931214b7e7SGunnar Mills propertiesList) { 1394b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1395b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 1396a6349918SAppaRao Puli if (ec) 1397a6349918SAppaRao Puli { 1398a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1399b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1400b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1401a6349918SAppaRao Puli return; 1402a6349918SAppaRao Puli } 1403a6349918SAppaRao Puli 1404a6349918SAppaRao Puli const bool* provState = nullptr; 1405a6349918SAppaRao Puli const bool* lockState = nullptr; 1406a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1407a6349918SAppaRao Puli propertiesList) 1408a6349918SAppaRao Puli { 1409a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1410a6349918SAppaRao Puli { 1411a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1412a6349918SAppaRao Puli } 1413a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1414a6349918SAppaRao Puli { 1415a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1416a6349918SAppaRao Puli } 1417a6349918SAppaRao Puli } 1418a6349918SAppaRao Puli 1419a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1420a6349918SAppaRao Puli { 1421a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1422a6349918SAppaRao Puli messages::internalError(aResp->res); 1423a6349918SAppaRao Puli return; 1424a6349918SAppaRao Puli } 1425a6349918SAppaRao Puli 1426a6349918SAppaRao Puli if (*provState == true) 1427a6349918SAppaRao Puli { 1428a6349918SAppaRao Puli if (*lockState == true) 1429a6349918SAppaRao Puli { 1430a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1431a6349918SAppaRao Puli } 1432a6349918SAppaRao Puli else 1433a6349918SAppaRao Puli { 1434a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1435a6349918SAppaRao Puli } 1436a6349918SAppaRao Puli } 1437a6349918SAppaRao Puli else 1438a6349918SAppaRao Puli { 1439a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1440a6349918SAppaRao Puli } 1441a6349918SAppaRao Puli }, 1442a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1443a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1444a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1445a6349918SAppaRao Puli } 1446a6349918SAppaRao Puli #endif 1447a6349918SAppaRao Puli 1448491d8ee7SSantosh Puranik /** 144951709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 145051709ffdSYong Li * 145151709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 145251709ffdSYong Li * 145351709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 145451709ffdSYong Li * translation cannot be done, returns an empty string. 145551709ffdSYong Li */ 145651709ffdSYong Li static std::string dbusToRfWatchdogAction(const std::string& dbusAction) 145751709ffdSYong Li { 145851709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 145951709ffdSYong Li { 146051709ffdSYong Li return "None"; 146151709ffdSYong Li } 146251709ffdSYong Li else if (dbusAction == 146351709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.HardReset") 146451709ffdSYong Li { 146551709ffdSYong Li return "ResetSystem"; 146651709ffdSYong Li } 146751709ffdSYong Li else if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 146851709ffdSYong Li { 146951709ffdSYong Li return "PowerDown"; 147051709ffdSYong Li } 147151709ffdSYong Li else if (dbusAction == 147251709ffdSYong Li "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 147351709ffdSYong Li { 147451709ffdSYong Li return "PowerCycle"; 147551709ffdSYong Li } 147651709ffdSYong Li 147751709ffdSYong Li return ""; 147851709ffdSYong Li } 147951709ffdSYong Li 148051709ffdSYong Li /** 1481c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 1482c45f0082SYong Li * 1483c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 1484c45f0082SYong Li * 1485c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 1486c45f0082SYong Li *If translation cannot be done, returns an empty string. 1487c45f0082SYong Li */ 1488c45f0082SYong Li 1489c45f0082SYong Li static std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 1490c45f0082SYong Li { 1491c45f0082SYong Li if (rfAction == "None") 1492c45f0082SYong Li { 1493c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 1494c45f0082SYong Li } 1495c45f0082SYong Li else if (rfAction == "PowerCycle") 1496c45f0082SYong Li { 1497c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 1498c45f0082SYong Li } 1499c45f0082SYong Li else if (rfAction == "PowerDown") 1500c45f0082SYong Li { 1501c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 1502c45f0082SYong Li } 1503c45f0082SYong Li else if (rfAction == "ResetSystem") 1504c45f0082SYong Li { 1505c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 1506c45f0082SYong Li } 1507c45f0082SYong Li 1508c45f0082SYong Li return ""; 1509c45f0082SYong Li } 1510c45f0082SYong Li 1511c45f0082SYong Li /** 151251709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 151351709ffdSYong Li * 151451709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 151551709ffdSYong Li * 151651709ffdSYong Li * @return None. 151751709ffdSYong Li */ 151851709ffdSYong Li void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) 151951709ffdSYong Li { 152051709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 152151709ffdSYong Li crow::connections::systemBus->async_method_call( 152251709ffdSYong Li [aResp](const boost::system::error_code ec, 152351709ffdSYong Li PropertiesType& properties) { 152451709ffdSYong Li if (ec) 152551709ffdSYong Li { 152651709ffdSYong Li // watchdog service is stopped 152751709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 152851709ffdSYong Li return; 152951709ffdSYong Li } 153051709ffdSYong Li 153151709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 153251709ffdSYong Li 153351709ffdSYong Li nlohmann::json& hostWatchdogTimer = 153451709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 153551709ffdSYong Li 153651709ffdSYong Li // watchdog service is running/enabled 153751709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 153851709ffdSYong Li 153951709ffdSYong Li for (const auto& property : properties) 154051709ffdSYong Li { 154151709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 154251709ffdSYong Li if (property.first == "Enabled") 154351709ffdSYong Li { 154451709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 154551709ffdSYong Li 154651709ffdSYong Li if (!state) 154751709ffdSYong Li { 154851709ffdSYong Li messages::internalError(aResp->res); 154951709ffdSYong Li continue; 155051709ffdSYong Li } 155151709ffdSYong Li 155251709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 155351709ffdSYong Li } 155451709ffdSYong Li else if (property.first == "ExpireAction") 155551709ffdSYong Li { 155651709ffdSYong Li const std::string* s = 155751709ffdSYong Li std::get_if<std::string>(&property.second); 155851709ffdSYong Li if (!s) 155951709ffdSYong Li { 156051709ffdSYong Li messages::internalError(aResp->res); 156151709ffdSYong Li continue; 156251709ffdSYong Li } 156351709ffdSYong Li 156451709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 156551709ffdSYong Li if (action.empty()) 156651709ffdSYong Li { 156751709ffdSYong Li messages::internalError(aResp->res); 156851709ffdSYong Li continue; 156951709ffdSYong Li } 157051709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 157151709ffdSYong Li } 157251709ffdSYong Li } 157351709ffdSYong Li }, 157451709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 157551709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 157651709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 157751709ffdSYong Li } 157851709ffdSYong Li 157951709ffdSYong Li /** 1580c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 1581c45f0082SYong Li * 1582c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 1583c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 1584c45f0082SYong Li * RF request. 1585c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 1586c45f0082SYong Li * 1587c45f0082SYong Li * @return None. 1588c45f0082SYong Li */ 1589c45f0082SYong Li static void setWDTProperties(std::shared_ptr<AsyncResp> aResp, 1590c45f0082SYong Li const std::optional<bool> wdtEnable, 1591c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 1592c45f0082SYong Li { 1593c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 1594c45f0082SYong Li 1595c45f0082SYong Li if (wdtTimeOutAction) 1596c45f0082SYong Li { 1597c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 1598c45f0082SYong Li // check if TimeOut Action is Valid 1599c45f0082SYong Li if (wdtTimeOutActStr.empty()) 1600c45f0082SYong Li { 1601c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 1602c45f0082SYong Li << *wdtTimeOutAction; 1603c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 1604c45f0082SYong Li "TimeoutAction"); 1605c45f0082SYong Li return; 1606c45f0082SYong Li } 1607c45f0082SYong Li 1608c45f0082SYong Li crow::connections::systemBus->async_method_call( 1609c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1610c45f0082SYong Li if (ec) 1611c45f0082SYong Li { 1612c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1613c45f0082SYong Li messages::internalError(aResp->res); 1614c45f0082SYong Li return; 1615c45f0082SYong Li } 1616c45f0082SYong Li }, 1617c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1618c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1619c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1620c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 1621c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 1622c45f0082SYong Li } 1623c45f0082SYong Li 1624c45f0082SYong Li if (wdtEnable) 1625c45f0082SYong Li { 1626c45f0082SYong Li crow::connections::systemBus->async_method_call( 1627c45f0082SYong Li [aResp](const boost::system::error_code ec) { 1628c45f0082SYong Li if (ec) 1629c45f0082SYong Li { 1630c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1631c45f0082SYong Li messages::internalError(aResp->res); 1632c45f0082SYong Li return; 1633c45f0082SYong Li } 1634c45f0082SYong Li }, 1635c45f0082SYong Li "xyz.openbmc_project.Watchdog", 1636c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 1637c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 1638c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 1639c45f0082SYong Li std::variant<bool>(*wdtEnable)); 1640c45f0082SYong Li } 1641c45f0082SYong Li } 1642c45f0082SYong Li 1643c45f0082SYong Li /** 1644c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 1645c5b2abe0SLewanczyk, Dawid * Schema 1646c5b2abe0SLewanczyk, Dawid */ 16471abe55efSEd Tanous class SystemsCollection : public Node 16481abe55efSEd Tanous { 1649c5b2abe0SLewanczyk, Dawid public: 16501abe55efSEd Tanous SystemsCollection(CrowApp& app) : Node(app, "/redfish/v1/Systems/") 16511abe55efSEd Tanous { 1652c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1653c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1654c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1655c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1656c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1657c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1658c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1659c5b2abe0SLewanczyk, Dawid } 1660c5b2abe0SLewanczyk, Dawid 1661c5b2abe0SLewanczyk, Dawid private: 166255c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 16631abe55efSEd Tanous const std::vector<std::string>& params) override 16641abe55efSEd Tanous { 1665462023adSSunitha Harish std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 16660f74e643SEd Tanous res.jsonValue["@odata.type"] = 16670f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 16680f74e643SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 16690f74e643SEd Tanous res.jsonValue["Name"] = "Computer System Collection"; 1670462023adSSunitha Harish 1671462023adSSunitha Harish crow::connections::systemBus->async_method_call( 1672462023adSSunitha Harish [asyncResp](const boost::system::error_code ec, 1673462023adSSunitha Harish const std::variant<std::string>& hostName) { 1674462023adSSunitha Harish nlohmann::json& iface_array = 1675462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 1676462023adSSunitha Harish iface_array = nlohmann::json::array(); 1677462023adSSunitha Harish auto& count = asyncResp->res.jsonValue["Members@odata.count"]; 1678462023adSSunitha Harish count = 0; 1679462023adSSunitha Harish if (ec) 1680462023adSSunitha Harish { 1681462023adSSunitha Harish iface_array.push_back( 1682462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1683462023adSSunitha Harish count = iface_array.size(); 1684462023adSSunitha Harish return; 1685462023adSSunitha Harish } 1686462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 1687462023adSSunitha Harish iface_array.push_back( 1688462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/system"}}); 1689462023adSSunitha Harish iface_array.push_back( 1690462023adSSunitha Harish {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); 1691462023adSSunitha Harish count = iface_array.size(); 1692462023adSSunitha Harish }, 16938e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 16948e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 1695462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 1696462023adSSunitha Harish "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); 1697c5b2abe0SLewanczyk, Dawid } 1698c5b2abe0SLewanczyk, Dawid }; 1699c5b2abe0SLewanczyk, Dawid 1700c5b2abe0SLewanczyk, Dawid /** 1701cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 1702cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 1703cc340dd9SEd Tanous */ 1704cc340dd9SEd Tanous class SystemActionsReset : public Node 1705cc340dd9SEd Tanous { 1706cc340dd9SEd Tanous public: 1707cc340dd9SEd Tanous SystemActionsReset(CrowApp& app) : 1708029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 1709cc340dd9SEd Tanous { 1710cc340dd9SEd Tanous entityPrivileges = { 1711cc340dd9SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1712cc340dd9SEd Tanous } 1713cc340dd9SEd Tanous 1714cc340dd9SEd Tanous private: 1715cc340dd9SEd Tanous /** 1716cc340dd9SEd Tanous * Function handles POST method request. 1717cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 1718cc340dd9SEd Tanous */ 1719cc340dd9SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 1720cc340dd9SEd Tanous const std::vector<std::string>& params) override 1721cc340dd9SEd Tanous { 1722cc340dd9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1723cc340dd9SEd Tanous 17249712f8acSEd Tanous std::string resetType; 17259712f8acSEd Tanous if (!json_util::readJson(req, res, "ResetType", resetType)) 1726cc340dd9SEd Tanous { 1727cc340dd9SEd Tanous return; 1728cc340dd9SEd Tanous } 1729cc340dd9SEd Tanous 1730d22c8396SJason M. Bills // Get the command and host vs. chassis 1731cc340dd9SEd Tanous std::string command; 1732d22c8396SJason M. Bills bool hostCommand; 17339712f8acSEd Tanous if (resetType == "On") 1734cc340dd9SEd Tanous { 1735cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 1736d22c8396SJason M. Bills hostCommand = true; 1737d22c8396SJason M. Bills } 1738d22c8396SJason M. Bills else if (resetType == "ForceOff") 1739d22c8396SJason M. Bills { 1740d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 1741d22c8396SJason M. Bills hostCommand = false; 1742d22c8396SJason M. Bills } 1743d22c8396SJason M. Bills else if (resetType == "ForceOn") 1744d22c8396SJason M. Bills { 1745d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.On"; 1746d22c8396SJason M. Bills hostCommand = true; 1747d22c8396SJason M. Bills } 1748d22c8396SJason M. Bills else if (resetType == "ForceRestart") 1749d22c8396SJason M. Bills { 175086a0851aSJason M. Bills command = 175186a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 175286a0851aSJason M. Bills hostCommand = true; 1753cc340dd9SEd Tanous } 17549712f8acSEd Tanous else if (resetType == "GracefulShutdown") 1755cc340dd9SEd Tanous { 1756cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 1757d22c8396SJason M. Bills hostCommand = true; 1758cc340dd9SEd Tanous } 17599712f8acSEd Tanous else if (resetType == "GracefulRestart") 1760cc340dd9SEd Tanous { 176186a0851aSJason M. Bills command = 176286a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; 1763d22c8396SJason M. Bills hostCommand = true; 1764d22c8396SJason M. Bills } 1765d22c8396SJason M. Bills else if (resetType == "PowerCycle") 1766d22c8396SJason M. Bills { 176786a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 176886a0851aSJason M. Bills hostCommand = true; 1769cc340dd9SEd Tanous } 1770bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 1771bfd5b826SLakshminarayana R. Kammath { 1772bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 1773bfd5b826SLakshminarayana R. Kammath return; 1774bfd5b826SLakshminarayana R. Kammath } 1775cc340dd9SEd Tanous else 1776cc340dd9SEd Tanous { 1777f12894f8SJason M. Bills messages::actionParameterUnknown(res, "Reset", resetType); 1778cc340dd9SEd Tanous return; 1779cc340dd9SEd Tanous } 1780cc340dd9SEd Tanous 1781d22c8396SJason M. Bills if (hostCommand) 1782d22c8396SJason M. Bills { 1783cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 1784d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1785cc340dd9SEd Tanous if (ec) 1786cc340dd9SEd Tanous { 1787cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1788d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1789d22c8396SJason M. Bills { 1790d22c8396SJason M. Bills messages::actionParameterNotSupported( 1791d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1792d22c8396SJason M. Bills } 1793d22c8396SJason M. Bills else 1794d22c8396SJason M. Bills { 1795f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1796d22c8396SJason M. Bills } 1797cc340dd9SEd Tanous return; 1798cc340dd9SEd Tanous } 1799f12894f8SJason M. Bills messages::success(asyncResp->res); 1800cc340dd9SEd Tanous }, 1801cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 1802cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 1803cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 18049712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 1805abf2add6SEd Tanous std::variant<std::string>{command}); 1806cc340dd9SEd Tanous } 1807d22c8396SJason M. Bills else 1808d22c8396SJason M. Bills { 1809d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 1810d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 1811d22c8396SJason M. Bills if (ec) 1812d22c8396SJason M. Bills { 1813d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 1814d22c8396SJason M. Bills if (ec.value() == boost::asio::error::invalid_argument) 1815d22c8396SJason M. Bills { 1816d22c8396SJason M. Bills messages::actionParameterNotSupported( 1817d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 1818d22c8396SJason M. Bills } 1819d22c8396SJason M. Bills else 1820d22c8396SJason M. Bills { 1821d22c8396SJason M. Bills messages::internalError(asyncResp->res); 1822d22c8396SJason M. Bills } 1823d22c8396SJason M. Bills return; 1824d22c8396SJason M. Bills } 1825d22c8396SJason M. Bills messages::success(asyncResp->res); 1826d22c8396SJason M. Bills }, 1827d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 1828d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 1829d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 1830d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", 1831d22c8396SJason M. Bills std::variant<std::string>{command}); 1832d22c8396SJason M. Bills } 1833d22c8396SJason M. Bills } 1834bfd5b826SLakshminarayana R. Kammath /** 1835bfd5b826SLakshminarayana R. Kammath * Function transceives data with dbus directly. 1836bfd5b826SLakshminarayana R. Kammath */ 1837bfd5b826SLakshminarayana R. Kammath void doNMI(const std::shared_ptr<AsyncResp>& asyncResp) 1838bfd5b826SLakshminarayana R. Kammath { 1839bfd5b826SLakshminarayana R. Kammath constexpr char const* serviceName = 1840bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1841bfd5b826SLakshminarayana R. Kammath constexpr char const* objectPath = 1842bfd5b826SLakshminarayana R. Kammath "/xyz/openbmc_project/control/host0/nmi"; 1843bfd5b826SLakshminarayana R. Kammath constexpr char const* interfaceName = 1844bfd5b826SLakshminarayana R. Kammath "xyz.openbmc_project.Control.Host.NMI"; 1845bfd5b826SLakshminarayana R. Kammath constexpr char const* method = "NMI"; 1846bfd5b826SLakshminarayana R. Kammath 1847bfd5b826SLakshminarayana R. Kammath crow::connections::systemBus->async_method_call( 1848bfd5b826SLakshminarayana R. Kammath [asyncResp](const boost::system::error_code ec) { 1849bfd5b826SLakshminarayana R. Kammath if (ec) 1850bfd5b826SLakshminarayana R. Kammath { 1851bfd5b826SLakshminarayana R. Kammath BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 1852bfd5b826SLakshminarayana R. Kammath messages::internalError(asyncResp->res); 1853bfd5b826SLakshminarayana R. Kammath return; 1854bfd5b826SLakshminarayana R. Kammath } 1855bfd5b826SLakshminarayana R. Kammath messages::success(asyncResp->res); 1856bfd5b826SLakshminarayana R. Kammath }, 1857bfd5b826SLakshminarayana R. Kammath serviceName, objectPath, interfaceName, method); 1858bfd5b826SLakshminarayana R. Kammath } 1859cc340dd9SEd Tanous }; 1860cc340dd9SEd Tanous 1861cc340dd9SEd Tanous /** 18626617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 1863c5b2abe0SLewanczyk, Dawid */ 18641abe55efSEd Tanous class Systems : public Node 18651abe55efSEd Tanous { 1866c5b2abe0SLewanczyk, Dawid public: 1867c5b2abe0SLewanczyk, Dawid /* 1868c5b2abe0SLewanczyk, Dawid * Default Constructor 1869c5b2abe0SLewanczyk, Dawid */ 1870029573d4SEd Tanous Systems(CrowApp& app) : Node(app, "/redfish/v1/Systems/system/") 18711abe55efSEd Tanous { 1872c5b2abe0SLewanczyk, Dawid entityPrivileges = { 1873c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::get, {{"Login"}}}, 1874c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::head, {{"Login"}}}, 1875c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1876c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1877c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1878c5b2abe0SLewanczyk, Dawid {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 1879c5b2abe0SLewanczyk, Dawid } 1880c5b2abe0SLewanczyk, Dawid 1881c5b2abe0SLewanczyk, Dawid private: 1882c5b2abe0SLewanczyk, Dawid /** 1883c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 1884c5b2abe0SLewanczyk, Dawid */ 188555c7b7a2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 18861abe55efSEd Tanous const std::vector<std::string>& params) override 18871abe55efSEd Tanous { 1888c0557e1aSGunnar Mills res.jsonValue["@odata.type"] = "#ComputerSystem.v1_12_0.ComputerSystem"; 1889450a25cbSGunnar Mills res.jsonValue["Name"] = "system"; 1890029573d4SEd Tanous res.jsonValue["Id"] = "system"; 18910f74e643SEd Tanous res.jsonValue["SystemType"] = "Physical"; 18920f74e643SEd Tanous res.jsonValue["Description"] = "Computer System"; 18930f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Count"] = 0; 18940f74e643SEd Tanous res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; 18955fd7ba65SCheng C Yang res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); 18960f74e643SEd Tanous res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; 1897029573d4SEd Tanous res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; 189804a258f4SEd Tanous 1899443c2934SRapkiewicz, Pawel res.jsonValue["Processors"] = { 1900029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 1901443c2934SRapkiewicz, Pawel res.jsonValue["Memory"] = { 1902029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 1903a25aeccfSNikhil Potade res.jsonValue["Storage"] = { 1904a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 1905029573d4SEd Tanous 1906cc340dd9SEd Tanous res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 1907cc340dd9SEd Tanous {"target", 1908029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 1909cc340dd9SEd Tanous {"ResetType@Redfish.AllowableValues", 1910d22c8396SJason M. Bills {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", 1911bfd5b826SLakshminarayana R. Kammath "GracefulShutdown", "PowerCycle", "Nmi"}}}; 1912c5b2abe0SLewanczyk, Dawid 1913c4bf6374SJason M. Bills res.jsonValue["LogServices"] = { 1914029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 1915c4bf6374SJason M. Bills 1916d82a3acdSCarol Wang res.jsonValue["Bios"] = { 1917d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 1918d82a3acdSCarol Wang 1919c5d03ff4SJennifer Lee res.jsonValue["Links"]["ManagedBy"] = { 1920c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 1921c5d03ff4SJennifer Lee 1922c5d03ff4SJennifer Lee res.jsonValue["Status"] = { 1923c5d03ff4SJennifer Lee {"Health", "OK"}, 1924c5d03ff4SJennifer Lee {"State", "Enabled"}, 1925c5d03ff4SJennifer Lee }; 1926a0803efaSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1927c5b2abe0SLewanczyk, Dawid 1928e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 1929b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 19302ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 1931e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 1932e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 1933b49ac873SJames Feist 1934b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 1935b49ac873SJames Feist crow::connections::systemBus->async_method_call( 1936b49ac873SJames Feist [health](const boost::system::error_code ec, 1937b49ac873SJames Feist std::vector<std::string>& resp) { 1938b49ac873SJames Feist if (ec) 1939b49ac873SJames Feist { 1940b49ac873SJames Feist // no inventory 1941b49ac873SJames Feist return; 1942b49ac873SJames Feist } 1943b49ac873SJames Feist 1944b49ac873SJames Feist health->inventory = std::move(resp); 1945b49ac873SJames Feist }, 1946b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 1947b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 1948b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 1949b49ac873SJames Feist int32_t(0), inventoryForSystems); 1950b49ac873SJames Feist 1951b49ac873SJames Feist health->populate(); 1952b49ac873SJames Feist 1953c5d03ff4SJennifer Lee getMainChassisId(asyncResp, [](const std::string& chassisId, 1954c5d03ff4SJennifer Lee std::shared_ptr<AsyncResp> aRsp) { 1955c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 1956c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 1957c5d03ff4SJennifer Lee }); 1958a3002228SAppaRao Puli 1959a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 19605bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 19616c34de48SEd Tanous getHostState(asyncResp); 1962491d8ee7SSantosh Puranik getBootProperties(asyncResp); 1963adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 196451709ffdSYong Li getHostWatchdogTimer(asyncResp); 1965c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 19666bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 1967c0557e1aSGunnar Mills getLastResetTime(asyncResp); 1968a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1969a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 1970a6349918SAppaRao Puli #endif 1971c5b2abe0SLewanczyk, Dawid } 1972c5b2abe0SLewanczyk, Dawid 197355c7b7a2SEd Tanous void doPatch(crow::Response& res, const crow::Request& req, 19741abe55efSEd Tanous const std::vector<std::string>& params) override 19751abe55efSEd Tanous { 1976cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 1977491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 1978c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 1979c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 198041352c24SSantosh Puranik auto asyncResp = std::make_shared<AsyncResp>(res); 198141352c24SSantosh Puranik 1982944ffaf9SJohnathan Mantey if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", 1983c6a620f2SGeorge Liu bootProps, "WatchdogTimer", wdtTimerProps, 1984c6a620f2SGeorge Liu "PowerRestorePolicy", powerRestorePolicy)) 19856617338dSEd Tanous { 19866617338dSEd Tanous return; 19876617338dSEd Tanous } 1988491d8ee7SSantosh Puranik 1989944ffaf9SJohnathan Mantey res.result(boost::beast::http::status::no_content); 1990c45f0082SYong Li 1991c45f0082SYong Li if (wdtTimerProps) 1992c45f0082SYong Li { 1993c45f0082SYong Li std::optional<bool> wdtEnable; 1994c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 1995c45f0082SYong Li 1996c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 1997c45f0082SYong Li "FunctionEnabled", wdtEnable, 1998c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 1999c45f0082SYong Li { 2000c45f0082SYong Li return; 2001c45f0082SYong Li } 2002c45f0082SYong Li setWDTProperties(asyncResp, std::move(wdtEnable), 2003c45f0082SYong Li std::move(wdtTimeOutAction)); 2004c45f0082SYong Li } 2005c45f0082SYong Li 2006491d8ee7SSantosh Puranik if (bootProps) 2007491d8ee7SSantosh Puranik { 2008491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2009491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 201069f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2011491d8ee7SSantosh Puranik 201269f35306SGunnar Mills if (!json_util::readJson( 201369f35306SGunnar Mills *bootProps, asyncResp->res, "BootSourceOverrideTarget", 201469f35306SGunnar Mills bootSource, "BootSourceOverrideEnabled", bootEnable, 201569f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2016491d8ee7SSantosh Puranik { 2017491d8ee7SSantosh Puranik return; 2018491d8ee7SSantosh Puranik } 201969f35306SGunnar Mills if (bootSource || bootEnable) 202069f35306SGunnar Mills { 202169f35306SGunnar Mills setBootSourceProperties(asyncResp, std::move(bootSource), 2022491d8ee7SSantosh Puranik std::move(bootEnable)); 2023491d8ee7SSantosh Puranik } 202469f35306SGunnar Mills if (automaticRetryConfig) 202569f35306SGunnar Mills { 202669f35306SGunnar Mills setAutomaticRetry(asyncResp, std::move(*automaticRetryConfig)); 202769f35306SGunnar Mills } 202869f35306SGunnar Mills } 2029265c1602SJohnathan Mantey 20309712f8acSEd Tanous if (indicatorLed) 20316617338dSEd Tanous { 2032a3002228SAppaRao Puli setIndicatorLedState(asyncResp, std::move(*indicatorLed)); 20336617338dSEd Tanous } 2034c6a620f2SGeorge Liu 2035c6a620f2SGeorge Liu if (powerRestorePolicy) 2036c6a620f2SGeorge Liu { 2037c6a620f2SGeorge Liu setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); 2038c6a620f2SGeorge Liu } 2039c5b2abe0SLewanczyk, Dawid } 2040c5b2abe0SLewanczyk, Dawid }; 2041c5b2abe0SLewanczyk, Dawid } // namespace redfish 2042