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 237e860f15SJohn Edward Broadbent #include <app.hpp> 249712f8acSEd Tanous #include <boost/container/flat_map.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 */ 418d1b46d7Szhanghch05 inline void 428d1b46d7Szhanghch05 updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 439d3ae10eSAlpana Kumari const std::variant<bool>& dimmState) 449d3ae10eSAlpana Kumari { 459d3ae10eSAlpana Kumari const bool* isDimmFunctional = std::get_if<bool>(&dimmState); 469d3ae10eSAlpana Kumari if (isDimmFunctional == nullptr) 479d3ae10eSAlpana Kumari { 489d3ae10eSAlpana Kumari messages::internalError(aResp->res); 499d3ae10eSAlpana Kumari return; 509d3ae10eSAlpana Kumari } 519d3ae10eSAlpana Kumari BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; 529d3ae10eSAlpana Kumari 539d3ae10eSAlpana Kumari // Set it as Enabled if at least one DIMM is functional 549d3ae10eSAlpana Kumari // Update STATE only if previous State was DISABLED and current Dimm is 559d3ae10eSAlpana Kumari // ENABLED. 569d3ae10eSAlpana Kumari nlohmann::json& prevMemSummary = 579d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; 589d3ae10eSAlpana Kumari if (prevMemSummary == "Disabled") 599d3ae10eSAlpana Kumari { 609d3ae10eSAlpana Kumari if (*isDimmFunctional == true) 619d3ae10eSAlpana Kumari { 629d3ae10eSAlpana Kumari aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 639d3ae10eSAlpana Kumari "Enabled"; 649d3ae10eSAlpana Kumari } 659d3ae10eSAlpana Kumari } 669d3ae10eSAlpana Kumari } 679d3ae10eSAlpana Kumari 6857e8c9beSAlpana Kumari /* 6957e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState 7057e8c9beSAlpana Kumari * 7157e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 7257e8c9beSAlpana Kumari * @param[in] cpuPresenceState CPU present or not 7357e8c9beSAlpana Kumari * 7457e8c9beSAlpana Kumari * @return None. 7557e8c9beSAlpana Kumari */ 768d1b46d7Szhanghch05 inline void 778d1b46d7Szhanghch05 modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 7857e8c9beSAlpana Kumari const std::variant<bool>& cpuPresenceState) 7957e8c9beSAlpana Kumari { 8057e8c9beSAlpana Kumari const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); 8157e8c9beSAlpana Kumari 8257e8c9beSAlpana Kumari if (isCpuPresent == nullptr) 8357e8c9beSAlpana Kumari { 8457e8c9beSAlpana Kumari messages::internalError(aResp->res); 8557e8c9beSAlpana Kumari return; 8657e8c9beSAlpana Kumari } 8757e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; 8857e8c9beSAlpana Kumari 8957e8c9beSAlpana Kumari if (*isCpuPresent == true) 9057e8c9beSAlpana Kumari { 91b4b9595aSJames Feist nlohmann::json& procCount = 92b4b9595aSJames Feist aResp->res.jsonValue["ProcessorSummary"]["Count"]; 93b4b9595aSJames Feist auto procCountPtr = 94b4b9595aSJames Feist procCount.get_ptr<nlohmann::json::number_integer_t*>(); 95b4b9595aSJames Feist if (procCountPtr != nullptr) 96b4b9595aSJames Feist { 97b4b9595aSJames Feist // shouldn't be possible to be nullptr 98b4b9595aSJames Feist *procCountPtr += 1; 9957e8c9beSAlpana Kumari } 100b4b9595aSJames Feist } 10157e8c9beSAlpana Kumari } 10257e8c9beSAlpana Kumari 10357e8c9beSAlpana Kumari /* 10457e8c9beSAlpana Kumari * @brief Update "ProcessorSummary" "Status" "State" based on 10557e8c9beSAlpana Kumari * CPU Functional State 10657e8c9beSAlpana Kumari * 10757e8c9beSAlpana Kumari * @param[in] aResp Shared pointer for completing asynchronous calls 10857e8c9beSAlpana Kumari * @param[in] cpuFunctionalState is CPU functional true/false 10957e8c9beSAlpana Kumari * 11057e8c9beSAlpana Kumari * @return None. 11157e8c9beSAlpana Kumari */ 11223a21a1cSEd Tanous inline void 1138d1b46d7Szhanghch05 modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 11457e8c9beSAlpana Kumari const std::variant<bool>& cpuFunctionalState) 11557e8c9beSAlpana Kumari { 11657e8c9beSAlpana Kumari const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); 11757e8c9beSAlpana Kumari 11857e8c9beSAlpana Kumari if (isCpuFunctional == nullptr) 11957e8c9beSAlpana Kumari { 12057e8c9beSAlpana Kumari messages::internalError(aResp->res); 12157e8c9beSAlpana Kumari return; 12257e8c9beSAlpana Kumari } 12357e8c9beSAlpana Kumari BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; 12457e8c9beSAlpana Kumari 12557e8c9beSAlpana Kumari nlohmann::json& prevProcState = 12657e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; 12757e8c9beSAlpana Kumari 12857e8c9beSAlpana Kumari // Set it as Enabled if at least one CPU is functional 12957e8c9beSAlpana Kumari // Update STATE only if previous State was Non_Functional and current CPU is 13057e8c9beSAlpana Kumari // Functional. 13157e8c9beSAlpana Kumari if (prevProcState == "Disabled") 13257e8c9beSAlpana Kumari { 13357e8c9beSAlpana Kumari if (*isCpuFunctional == true) 13457e8c9beSAlpana Kumari { 13557e8c9beSAlpana Kumari aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 13657e8c9beSAlpana Kumari "Enabled"; 13757e8c9beSAlpana Kumari } 13857e8c9beSAlpana Kumari } 13957e8c9beSAlpana Kumari } 14057e8c9beSAlpana Kumari 14157e8c9beSAlpana Kumari /* 142c5b2abe0SLewanczyk, Dawid * @brief Retrieves computer system properties over dbus 143c5b2abe0SLewanczyk, Dawid * 144c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls 1458f9ee3cdSGunnar Mills * @param[in] systemHealth Shared HealthPopulate pointer 146c5b2abe0SLewanczyk, Dawid * 147c5b2abe0SLewanczyk, Dawid * @return None. 148c5b2abe0SLewanczyk, Dawid */ 149b5a76932SEd Tanous inline void 1508d1b46d7Szhanghch05 getComputerSystem(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 151b5a76932SEd Tanous const std::shared_ptr<HealthPopulate>& systemHealth) 1521abe55efSEd Tanous { 15355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get available system components."; 1549d3ae10eSAlpana Kumari 15555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 1565bc2dc8eSJames Feist [aResp, systemHealth]( 157c5b2abe0SLewanczyk, Dawid const boost::system::error_code ec, 158c5b2abe0SLewanczyk, Dawid const std::vector<std::pair< 1596c34de48SEd Tanous std::string, 1601214b7e7SGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1611214b7e7SGunnar Mills subtree) { 1621abe55efSEd Tanous if (ec) 1631abe55efSEd Tanous { 16455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error"; 165f12894f8SJason M. Bills messages::internalError(aResp->res); 166c5b2abe0SLewanczyk, Dawid return; 167c5b2abe0SLewanczyk, Dawid } 168c5b2abe0SLewanczyk, Dawid // Iterate over all retrieved ObjectPaths. 1696c34de48SEd Tanous for (const std::pair<std::string, 1706c34de48SEd Tanous std::vector<std::pair< 1711214b7e7SGunnar Mills std::string, std::vector<std::string>>>>& 1721214b7e7SGunnar Mills object : subtree) 1731abe55efSEd Tanous { 174c5b2abe0SLewanczyk, Dawid const std::string& path = object.first; 17555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Got path: " << path; 1761abe55efSEd Tanous const std::vector< 1771214b7e7SGunnar Mills std::pair<std::string, std::vector<std::string>>>& 1781214b7e7SGunnar Mills connectionNames = object.second; 1791abe55efSEd Tanous if (connectionNames.size() < 1) 1801abe55efSEd Tanous { 181c5b2abe0SLewanczyk, Dawid continue; 182c5b2abe0SLewanczyk, Dawid } 183029573d4SEd Tanous 1845bc2dc8eSJames Feist auto memoryHealth = std::make_shared<HealthPopulate>( 1855bc2dc8eSJames Feist aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); 1865bc2dc8eSJames Feist 1875bc2dc8eSJames Feist auto cpuHealth = std::make_shared<HealthPopulate>( 1885bc2dc8eSJames Feist aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); 1895bc2dc8eSJames Feist 1905bc2dc8eSJames Feist systemHealth->children.emplace_back(memoryHealth); 1915bc2dc8eSJames Feist systemHealth->children.emplace_back(cpuHealth); 1925bc2dc8eSJames Feist 1936c34de48SEd Tanous // This is not system, so check if it's cpu, dimm, UUID or 1946c34de48SEd Tanous // BiosVer 19504a258f4SEd Tanous for (const auto& connection : connectionNames) 1961abe55efSEd Tanous { 19704a258f4SEd Tanous for (const auto& interfaceName : connection.second) 1981abe55efSEd Tanous { 19904a258f4SEd Tanous if (interfaceName == 20004a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm") 2011abe55efSEd Tanous { 2021abe55efSEd Tanous BMCWEB_LOG_DEBUG 20304a258f4SEd Tanous << "Found Dimm, now get its properties."; 2049d3ae10eSAlpana Kumari 20555c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 2069d3ae10eSAlpana Kumari [aResp, service{connection.first}, 207f23b7296SEd Tanous path](const boost::system::error_code ec2, 2086c34de48SEd Tanous const std::vector< 2091214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 2101214b7e7SGunnar Mills properties) { 211cb13a392SEd Tanous if (ec2) 2121abe55efSEd Tanous { 2131abe55efSEd Tanous BMCWEB_LOG_ERROR 214cb13a392SEd Tanous << "DBUS response error " << ec2; 215f12894f8SJason M. Bills messages::internalError(aResp->res); 216c5b2abe0SLewanczyk, Dawid return; 217c5b2abe0SLewanczyk, Dawid } 2186c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 2196c34de48SEd Tanous << properties.size() 220c5b2abe0SLewanczyk, Dawid << " Dimm properties."; 2219d3ae10eSAlpana Kumari 2229d3ae10eSAlpana Kumari if (properties.size() > 0) 2239d3ae10eSAlpana Kumari { 22404a258f4SEd Tanous for (const std::pair<std::string, 2251214b7e7SGunnar Mills VariantType>& 2261214b7e7SGunnar Mills property : properties) 2271abe55efSEd Tanous { 2285fd7ba65SCheng C Yang if (property.first != 2295fd7ba65SCheng C Yang "MemorySizeInKB") 2301abe55efSEd Tanous { 2315fd7ba65SCheng C Yang continue; 2325fd7ba65SCheng C Yang } 2335fd7ba65SCheng C Yang const uint32_t* value = 2348d78b7a9SPatrick Williams std::get_if<uint32_t>( 2351b6b96c5SEd Tanous &property.second); 2365fd7ba65SCheng C Yang if (value == nullptr) 2371abe55efSEd Tanous { 2385fd7ba65SCheng C Yang BMCWEB_LOG_DEBUG 2395fd7ba65SCheng C Yang << "Find incorrect type of " 2405fd7ba65SCheng C Yang "MemorySize"; 2415fd7ba65SCheng C Yang continue; 2425fd7ba65SCheng C Yang } 2435fd7ba65SCheng C Yang nlohmann::json& totalMemory = 2445fd7ba65SCheng C Yang aResp->res 2455fd7ba65SCheng C Yang .jsonValue["MemorySummar" 2465fd7ba65SCheng C Yang "y"] 2475fd7ba65SCheng C Yang ["TotalSystemMe" 2485fd7ba65SCheng C Yang "moryGiB"]; 2495fd7ba65SCheng C Yang uint64_t* preValue = 2505fd7ba65SCheng C Yang totalMemory 2515fd7ba65SCheng C Yang .get_ptr<uint64_t*>(); 2525fd7ba65SCheng C Yang if (preValue == nullptr) 2535fd7ba65SCheng C Yang { 2545fd7ba65SCheng C Yang continue; 2555fd7ba65SCheng C Yang } 2565fd7ba65SCheng C Yang aResp->res 2575fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2586c34de48SEd Tanous ["TotalSystemMemoryGi" 2595fd7ba65SCheng C Yang "B"] = 2605fd7ba65SCheng C Yang *value / (1024 * 1024) + 2615fd7ba65SCheng C Yang *preValue; 2625fd7ba65SCheng C Yang aResp->res 2635fd7ba65SCheng C Yang .jsonValue["MemorySummary"] 2649d3ae10eSAlpana Kumari ["Status"]["State"] = 2651abe55efSEd Tanous "Enabled"; 266c5b2abe0SLewanczyk, Dawid } 267c5b2abe0SLewanczyk, Dawid } 2689d3ae10eSAlpana Kumari else 2699d3ae10eSAlpana Kumari { 2709d3ae10eSAlpana Kumari auto getDimmProperties = 2719d3ae10eSAlpana Kumari [aResp]( 2729d3ae10eSAlpana Kumari const boost::system::error_code 273cb13a392SEd Tanous ec3, 2741214b7e7SGunnar Mills const std::variant<bool>& 2751214b7e7SGunnar Mills dimmState) { 276cb13a392SEd Tanous if (ec3) 2779d3ae10eSAlpana Kumari { 2789d3ae10eSAlpana Kumari BMCWEB_LOG_ERROR 2799d3ae10eSAlpana Kumari << "DBUS response " 2809d3ae10eSAlpana Kumari "error " 281cb13a392SEd Tanous << ec3; 2829d3ae10eSAlpana Kumari return; 2839d3ae10eSAlpana Kumari } 2849d3ae10eSAlpana Kumari updateDimmProperties(aResp, 2859d3ae10eSAlpana Kumari dimmState); 2869d3ae10eSAlpana Kumari }; 2879d3ae10eSAlpana Kumari crow::connections::systemBus 2889d3ae10eSAlpana Kumari ->async_method_call( 2899d3ae10eSAlpana Kumari std::move(getDimmProperties), 2909d3ae10eSAlpana Kumari service, path, 2919d3ae10eSAlpana Kumari "org.freedesktop.DBus." 2929d3ae10eSAlpana Kumari "Properties", 2939d3ae10eSAlpana Kumari "Get", 2949d3ae10eSAlpana Kumari "xyz.openbmc_project.State." 2959d3ae10eSAlpana Kumari "Decorator.OperationalStatus", 2969d3ae10eSAlpana Kumari "Functional"); 2979d3ae10eSAlpana Kumari } 298c5b2abe0SLewanczyk, Dawid }, 29904a258f4SEd Tanous connection.first, path, 3006c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 3016c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm"); 3025bc2dc8eSJames Feist 3035bc2dc8eSJames Feist memoryHealth->inventory.emplace_back(path); 3041abe55efSEd Tanous } 30504a258f4SEd Tanous else if (interfaceName == 30604a258f4SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu") 3071abe55efSEd Tanous { 3081abe55efSEd Tanous BMCWEB_LOG_DEBUG 30904a258f4SEd Tanous << "Found Cpu, now get its properties."; 31057e8c9beSAlpana Kumari 311a0803efaSEd Tanous crow::connections::systemBus->async_method_call( 31257e8c9beSAlpana Kumari [aResp, service{connection.first}, 313f23b7296SEd Tanous path](const boost::system::error_code ec2, 3146c34de48SEd Tanous const std::vector< 3151214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 3161214b7e7SGunnar Mills properties) { 317cb13a392SEd Tanous if (ec2) 3181abe55efSEd Tanous { 3191abe55efSEd Tanous BMCWEB_LOG_ERROR 320cb13a392SEd Tanous << "DBUS response error " << ec2; 321f12894f8SJason M. Bills messages::internalError(aResp->res); 322c5b2abe0SLewanczyk, Dawid return; 323c5b2abe0SLewanczyk, Dawid } 3246c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 3256c34de48SEd Tanous << properties.size() 326c5b2abe0SLewanczyk, Dawid << " Cpu properties."; 32757e8c9beSAlpana Kumari 32857e8c9beSAlpana Kumari if (properties.size() > 0) 32957e8c9beSAlpana Kumari { 3309cf21522SZhikui Ren const uint64_t* processorId = nullptr; 331029cc1f4SZhikui Ren const std::string* procFamily = nullptr; 332029cc1f4SZhikui Ren nlohmann::json& procSummary = 333029cc1f4SZhikui Ren aResp->res.jsonValue["ProcessorSumm" 33404a258f4SEd Tanous "ary"]; 33504a258f4SEd Tanous nlohmann::json& procCount = 33604a258f4SEd Tanous procSummary["Count"]; 337b4b9595aSJames Feist 338029cc1f4SZhikui Ren auto procCountPtr = procCount.get_ptr< 339b4b9595aSJames Feist nlohmann::json:: 3401214b7e7SGunnar Mills number_integer_t*>(); 341029cc1f4SZhikui Ren if (procCountPtr == nullptr) 342b4b9595aSJames Feist { 343029cc1f4SZhikui Ren messages::internalError(aResp->res); 344029cc1f4SZhikui Ren return; 345029cc1f4SZhikui Ren } 346029cc1f4SZhikui Ren for (const auto& property : properties) 347029cc1f4SZhikui Ren { 348029cc1f4SZhikui Ren 3499cf21522SZhikui Ren if (property.first == "Id") 350029cc1f4SZhikui Ren { 351029cc1f4SZhikui Ren processorId = 3529cf21522SZhikui Ren std::get_if<uint64_t>( 353029cc1f4SZhikui Ren &property.second); 354029cc1f4SZhikui Ren if (nullptr != procFamily) 3553174e4dfSEd Tanous { 356029cc1f4SZhikui Ren break; 3573174e4dfSEd Tanous } 358029cc1f4SZhikui Ren continue; 359029cc1f4SZhikui Ren } 360029cc1f4SZhikui Ren 3619cf21522SZhikui Ren if (property.first == "Family") 362029cc1f4SZhikui Ren { 363029cc1f4SZhikui Ren procFamily = 364029cc1f4SZhikui Ren std::get_if<std::string>( 365029cc1f4SZhikui Ren &property.second); 366029cc1f4SZhikui Ren if (nullptr != processorId) 3673174e4dfSEd Tanous { 368029cc1f4SZhikui Ren break; 3693174e4dfSEd Tanous } 370029cc1f4SZhikui Ren continue; 371029cc1f4SZhikui Ren } 372029cc1f4SZhikui Ren } 373029cc1f4SZhikui Ren 374029cc1f4SZhikui Ren if (procFamily != nullptr && 375029cc1f4SZhikui Ren processorId != nullptr) 376029cc1f4SZhikui Ren { 377029cc1f4SZhikui Ren if (procCountPtr != nullptr && 378029cc1f4SZhikui Ren *processorId != 0) 379029cc1f4SZhikui Ren { 380b4b9595aSJames Feist *procCountPtr += 1; 381029cc1f4SZhikui Ren procSummary["Status"]["State"] = 382c5b2abe0SLewanczyk, Dawid "Enabled"; 383029cc1f4SZhikui Ren 38457e8c9beSAlpana Kumari procSummary["Model"] = 385029cc1f4SZhikui Ren *procFamily; 386c5b2abe0SLewanczyk, Dawid } 387c5b2abe0SLewanczyk, Dawid } 38857e8c9beSAlpana Kumari } 38957e8c9beSAlpana Kumari else 39057e8c9beSAlpana Kumari { 39157e8c9beSAlpana Kumari auto getCpuPresenceState = 39257e8c9beSAlpana Kumari [aResp]( 39357e8c9beSAlpana Kumari const boost::system::error_code 394cb13a392SEd Tanous ec3, 3951214b7e7SGunnar Mills const std::variant<bool>& 3961214b7e7SGunnar Mills cpuPresenceCheck) { 397cb13a392SEd Tanous if (ec3) 39857e8c9beSAlpana Kumari { 39957e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 40057e8c9beSAlpana Kumari << "DBUS response " 40157e8c9beSAlpana Kumari "error " 402cb13a392SEd Tanous << ec3; 40357e8c9beSAlpana Kumari return; 40457e8c9beSAlpana Kumari } 40557e8c9beSAlpana Kumari modifyCpuPresenceState( 40657e8c9beSAlpana Kumari aResp, cpuPresenceCheck); 40757e8c9beSAlpana Kumari }; 40857e8c9beSAlpana Kumari 40957e8c9beSAlpana Kumari auto getCpuFunctionalState = 41057e8c9beSAlpana Kumari [aResp]( 41157e8c9beSAlpana Kumari const boost::system::error_code 412cb13a392SEd Tanous ec3, 4131214b7e7SGunnar Mills const std::variant<bool>& 4141214b7e7SGunnar Mills cpuFunctionalCheck) { 415cb13a392SEd Tanous if (ec3) 41657e8c9beSAlpana Kumari { 41757e8c9beSAlpana Kumari BMCWEB_LOG_ERROR 41857e8c9beSAlpana Kumari << "DBUS response " 41957e8c9beSAlpana Kumari "error " 420cb13a392SEd Tanous << ec3; 42157e8c9beSAlpana Kumari return; 42257e8c9beSAlpana Kumari } 42357e8c9beSAlpana Kumari modifyCpuFunctionalState( 42457e8c9beSAlpana Kumari aResp, cpuFunctionalCheck); 42557e8c9beSAlpana Kumari }; 42657e8c9beSAlpana Kumari // Get the Presence of CPU 42757e8c9beSAlpana Kumari crow::connections::systemBus 42857e8c9beSAlpana Kumari ->async_method_call( 42957e8c9beSAlpana Kumari std::move(getCpuPresenceState), 43057e8c9beSAlpana Kumari service, path, 43157e8c9beSAlpana Kumari "org.freedesktop.DBus." 43257e8c9beSAlpana Kumari "Properties", 43357e8c9beSAlpana Kumari "Get", 43457e8c9beSAlpana Kumari "xyz.openbmc_project.Inventory." 43557e8c9beSAlpana Kumari "Item", 43657e8c9beSAlpana Kumari "Present"); 43757e8c9beSAlpana Kumari 43857e8c9beSAlpana Kumari // Get the Functional State 43957e8c9beSAlpana Kumari crow::connections::systemBus 44057e8c9beSAlpana Kumari ->async_method_call( 44157e8c9beSAlpana Kumari std::move( 44257e8c9beSAlpana Kumari getCpuFunctionalState), 44357e8c9beSAlpana Kumari service, path, 44457e8c9beSAlpana Kumari "org.freedesktop.DBus." 44557e8c9beSAlpana Kumari "Properties", 44657e8c9beSAlpana Kumari "Get", 44757e8c9beSAlpana Kumari "xyz.openbmc_project.State." 44857e8c9beSAlpana Kumari "Decorator." 44957e8c9beSAlpana Kumari "OperationalStatus", 45057e8c9beSAlpana Kumari "Functional"); 45157e8c9beSAlpana Kumari 45257e8c9beSAlpana Kumari // Get the MODEL from 45357e8c9beSAlpana Kumari // xyz.openbmc_project.Inventory.Decorator.Asset 45457e8c9beSAlpana Kumari // support it later as Model is Empty 45557e8c9beSAlpana Kumari // currently. 45657e8c9beSAlpana Kumari } 457c5b2abe0SLewanczyk, Dawid }, 45804a258f4SEd Tanous connection.first, path, 4596c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 4606c34de48SEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu"); 4615bc2dc8eSJames Feist 4625bc2dc8eSJames Feist cpuHealth->inventory.emplace_back(path); 4631abe55efSEd Tanous } 46404a258f4SEd Tanous else if (interfaceName == 46504a258f4SEd Tanous "xyz.openbmc_project.Common.UUID") 4661abe55efSEd Tanous { 4671abe55efSEd Tanous BMCWEB_LOG_DEBUG 46804a258f4SEd Tanous << "Found UUID, now get its properties."; 46955c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 4701214b7e7SGunnar Mills [aResp]( 471cb13a392SEd Tanous const boost::system::error_code ec3, 4726c34de48SEd Tanous const std::vector< 4731214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 4741214b7e7SGunnar Mills properties) { 475cb13a392SEd Tanous if (ec3) 4761abe55efSEd Tanous { 4771abe55efSEd Tanous BMCWEB_LOG_DEBUG 478cb13a392SEd Tanous << "DBUS response error " << ec3; 479f12894f8SJason M. Bills messages::internalError(aResp->res); 480c5b2abe0SLewanczyk, Dawid return; 481c5b2abe0SLewanczyk, Dawid } 4826c34de48SEd Tanous BMCWEB_LOG_DEBUG << "Got " 4836c34de48SEd Tanous << properties.size() 484c5b2abe0SLewanczyk, Dawid << " UUID properties."; 4851abe55efSEd Tanous for (const std::pair<std::string, 4861214b7e7SGunnar Mills VariantType>& 4871214b7e7SGunnar Mills property : properties) 4881abe55efSEd Tanous { 48904a258f4SEd Tanous if (property.first == "UUID") 4901abe55efSEd Tanous { 491c5b2abe0SLewanczyk, Dawid const std::string* value = 4928d78b7a9SPatrick Williams std::get_if<std::string>( 4931b6b96c5SEd Tanous &property.second); 49404a258f4SEd Tanous 4951abe55efSEd Tanous if (value != nullptr) 4961abe55efSEd Tanous { 497029573d4SEd Tanous std::string valueStr = *value; 49804a258f4SEd Tanous if (valueStr.size() == 32) 4991abe55efSEd Tanous { 500029573d4SEd Tanous valueStr.insert(8, 1, '-'); 501029573d4SEd Tanous valueStr.insert(13, 1, '-'); 502029573d4SEd Tanous valueStr.insert(18, 1, '-'); 503029573d4SEd Tanous valueStr.insert(23, 1, '-'); 50404a258f4SEd Tanous } 505029573d4SEd Tanous BMCWEB_LOG_DEBUG << "UUID = " 50604a258f4SEd Tanous << valueStr; 507029573d4SEd Tanous aResp->res.jsonValue["UUID"] = 50804a258f4SEd Tanous valueStr; 509c5b2abe0SLewanczyk, Dawid } 510c5b2abe0SLewanczyk, Dawid } 511c5b2abe0SLewanczyk, Dawid } 512c5b2abe0SLewanczyk, Dawid }, 51304a258f4SEd Tanous connection.first, path, 5146c34de48SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 5151abe55efSEd Tanous "xyz.openbmc_project.Common.UUID"); 516c5b2abe0SLewanczyk, Dawid } 517029573d4SEd Tanous else if (interfaceName == 518029573d4SEd Tanous "xyz.openbmc_project.Inventory.Item.System") 5191abe55efSEd Tanous { 520029573d4SEd Tanous crow::connections::systemBus->async_method_call( 5211214b7e7SGunnar Mills [aResp]( 522cb13a392SEd Tanous const boost::system::error_code ec2, 523029573d4SEd Tanous const std::vector< 5241214b7e7SGunnar Mills std::pair<std::string, VariantType>>& 5251214b7e7SGunnar Mills propertiesList) { 526cb13a392SEd Tanous if (ec2) 527029573d4SEd Tanous { 528e4a4b9a9SJames Feist // doesn't have to include this 529e4a4b9a9SJames Feist // interface 530029573d4SEd Tanous return; 531029573d4SEd Tanous } 532698654b6SGunnar Mills BMCWEB_LOG_DEBUG 533698654b6SGunnar Mills << "Got " << propertiesList.size() 534029573d4SEd Tanous << " properties for system"; 535029573d4SEd Tanous for (const std::pair<std::string, 5361214b7e7SGunnar Mills VariantType>& 5371214b7e7SGunnar Mills property : propertiesList) 538029573d4SEd Tanous { 539fc5afcf9Sbeccabroek const std::string& propertyName = 540fc5afcf9Sbeccabroek property.first; 541fc5afcf9Sbeccabroek if ((propertyName == "PartNumber") || 542fc5afcf9Sbeccabroek (propertyName == "SerialNumber") || 543fc5afcf9Sbeccabroek (propertyName == "Manufacturer") || 5445235d964SSunnySrivastava1984 (propertyName == "Model") || 5455235d964SSunnySrivastava1984 (propertyName == "SubModel")) 546fc5afcf9Sbeccabroek { 547029573d4SEd Tanous const std::string* value = 548fc5afcf9Sbeccabroek std::get_if<std::string>( 549029573d4SEd Tanous &property.second); 550029573d4SEd Tanous if (value != nullptr) 551029573d4SEd Tanous { 552029573d4SEd Tanous aResp->res 553fc5afcf9Sbeccabroek .jsonValue[propertyName] = 554029573d4SEd Tanous *value; 555029573d4SEd Tanous } 556029573d4SEd Tanous } 557fc5afcf9Sbeccabroek } 558c1e236a6SGunnar Mills 559cb7e1e7bSAndrew Geissler // Grab the bios version 560f97ddba7SGunnar Mills fw_util::populateFirmwareInformation( 561cb7e1e7bSAndrew Geissler aResp, fw_util::biosPurpose, 56272d566d9SGunnar Mills "BiosVersion", false); 563029573d4SEd Tanous }, 564029573d4SEd Tanous connection.first, path, 565029573d4SEd Tanous "org.freedesktop.DBus.Properties", "GetAll", 566029573d4SEd Tanous "xyz.openbmc_project.Inventory.Decorator." 567029573d4SEd Tanous "Asset"); 568e4a4b9a9SJames Feist 569e4a4b9a9SJames Feist crow::connections::systemBus->async_method_call( 570e4a4b9a9SJames Feist [aResp]( 571cb13a392SEd Tanous const boost::system::error_code ec2, 572e4a4b9a9SJames Feist const std::variant<std::string>& property) { 573cb13a392SEd Tanous if (ec2) 574e4a4b9a9SJames Feist { 575e4a4b9a9SJames Feist // doesn't have to include this 576e4a4b9a9SJames Feist // interface 577e4a4b9a9SJames Feist return; 578e4a4b9a9SJames Feist } 579e4a4b9a9SJames Feist 580e4a4b9a9SJames Feist const std::string* value = 581e4a4b9a9SJames Feist std::get_if<std::string>(&property); 582e4a4b9a9SJames Feist if (value != nullptr) 583e4a4b9a9SJames Feist { 584e4a4b9a9SJames Feist aResp->res.jsonValue["AssetTag"] = 585e4a4b9a9SJames Feist *value; 586e4a4b9a9SJames Feist } 587e4a4b9a9SJames Feist }, 588e4a4b9a9SJames Feist connection.first, path, 589e4a4b9a9SJames Feist "org.freedesktop.DBus.Properties", "Get", 590e4a4b9a9SJames Feist "xyz.openbmc_project.Inventory.Decorator." 591e4a4b9a9SJames Feist "AssetTag", 592e4a4b9a9SJames Feist "AssetTag"); 593029573d4SEd Tanous } 594029573d4SEd Tanous } 595029573d4SEd Tanous } 596c5b2abe0SLewanczyk, Dawid } 597c5b2abe0SLewanczyk, Dawid }, 598c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", 599c5b2abe0SLewanczyk, Dawid "/xyz/openbmc_project/object_mapper", 600c5b2abe0SLewanczyk, Dawid "xyz.openbmc_project.ObjectMapper", "GetSubTree", 6016617338dSEd Tanous "/xyz/openbmc_project/inventory", int32_t(0), 6026617338dSEd Tanous std::array<const char*, 5>{ 6036617338dSEd Tanous "xyz.openbmc_project.Inventory.Decorator.Asset", 6046617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Cpu", 6056617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.Dimm", 6066617338dSEd Tanous "xyz.openbmc_project.Inventory.Item.System", 6076617338dSEd Tanous "xyz.openbmc_project.Common.UUID", 6086617338dSEd Tanous }); 609c5b2abe0SLewanczyk, Dawid } 610c5b2abe0SLewanczyk, Dawid 611c5b2abe0SLewanczyk, Dawid /** 612c5b2abe0SLewanczyk, Dawid * @brief Retrieves host state properties over dbus 613c5b2abe0SLewanczyk, Dawid * 614c5b2abe0SLewanczyk, Dawid * @param[in] aResp Shared pointer for completing asynchronous calls. 615c5b2abe0SLewanczyk, Dawid * 616c5b2abe0SLewanczyk, Dawid * @return None. 617c5b2abe0SLewanczyk, Dawid */ 6188d1b46d7Szhanghch05 inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 6191abe55efSEd Tanous { 62055c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Get host information."; 62155c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 622c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 623abf2add6SEd Tanous const std::variant<std::string>& hostState) { 6241abe55efSEd Tanous if (ec) 6251abe55efSEd Tanous { 62655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 627f12894f8SJason M. Bills messages::internalError(aResp->res); 628c5b2abe0SLewanczyk, Dawid return; 629c5b2abe0SLewanczyk, Dawid } 6306617338dSEd Tanous 631abf2add6SEd Tanous const std::string* s = std::get_if<std::string>(&hostState); 63255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Host state: " << *s; 6336617338dSEd Tanous if (s != nullptr) 6341abe55efSEd Tanous { 635c5b2abe0SLewanczyk, Dawid // Verify Host State 63694732661SAndrew Geissler if (*s == "xyz.openbmc_project.State.Host.HostState.Running") 6371abe55efSEd Tanous { 63855c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "On"; 6396617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Enabled"; 6401abe55efSEd Tanous } 64183935af9SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6428c888608SGunnar Mills "Quiesced") 6438c888608SGunnar Mills { 6448c888608SGunnar Mills aResp->res.jsonValue["PowerState"] = "On"; 6458c888608SGunnar Mills aResp->res.jsonValue["Status"]["State"] = "Quiesced"; 6468c888608SGunnar Mills } 6478c888608SGunnar Mills else if (*s == "xyz.openbmc_project.State.Host.HostState." 64883935af9SAndrew Geissler "DiagnosticMode") 64983935af9SAndrew Geissler { 65083935af9SAndrew Geissler aResp->res.jsonValue["PowerState"] = "On"; 65183935af9SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "InTest"; 65283935af9SAndrew Geissler } 6531a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6541a2a1437SAndrew Geissler "TransitioningToRunning") 6551a2a1437SAndrew Geissler { 6561a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOn"; 65715c27bf8SNoah Brewer aResp->res.jsonValue["Status"]["State"] = "Starting"; 6581a2a1437SAndrew Geissler } 6591a2a1437SAndrew Geissler else if (*s == "xyz.openbmc_project.State.Host.HostState." 6601a2a1437SAndrew Geissler "TransitioningToOff") 6611a2a1437SAndrew Geissler { 6621a2a1437SAndrew Geissler aResp->res.jsonValue["PowerState"] = "PoweringOff"; 6631a2a1437SAndrew Geissler aResp->res.jsonValue["Status"]["State"] = "Disabled"; 6641a2a1437SAndrew Geissler } 6651abe55efSEd Tanous else 6661abe55efSEd Tanous { 66755c7b7a2SEd Tanous aResp->res.jsonValue["PowerState"] = "Off"; 6686617338dSEd Tanous aResp->res.jsonValue["Status"]["State"] = "Disabled"; 669c5b2abe0SLewanczyk, Dawid } 670c5b2abe0SLewanczyk, Dawid } 671c5b2abe0SLewanczyk, Dawid }, 6726c34de48SEd Tanous "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 6736617338dSEd Tanous "org.freedesktop.DBus.Properties", "Get", 6746617338dSEd Tanous "xyz.openbmc_project.State.Host", "CurrentHostState"); 675c5b2abe0SLewanczyk, Dawid } 676c5b2abe0SLewanczyk, Dawid 677c5b2abe0SLewanczyk, Dawid /** 678786d0f60SGunnar Mills * @brief Translates boot source DBUS property value to redfish. 679491d8ee7SSantosh Puranik * 680491d8ee7SSantosh Puranik * @param[in] dbusSource The boot source in DBUS speak. 681491d8ee7SSantosh Puranik * 682491d8ee7SSantosh Puranik * @return Returns as a string, the boot source in Redfish terms. If translation 683491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 684491d8ee7SSantosh Puranik */ 68523a21a1cSEd Tanous inline std::string dbusToRfBootSource(const std::string& dbusSource) 686491d8ee7SSantosh Puranik { 687491d8ee7SSantosh Puranik if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") 688491d8ee7SSantosh Puranik { 689491d8ee7SSantosh Puranik return "None"; 690491d8ee7SSantosh Puranik } 6913174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") 692491d8ee7SSantosh Puranik { 693491d8ee7SSantosh Puranik return "Hdd"; 694491d8ee7SSantosh Puranik } 6953174e4dfSEd Tanous if (dbusSource == 696a71dc0b7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") 697491d8ee7SSantosh Puranik { 698491d8ee7SSantosh Puranik return "Cd"; 699491d8ee7SSantosh Puranik } 7003174e4dfSEd Tanous if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") 701491d8ee7SSantosh Puranik { 702491d8ee7SSantosh Puranik return "Pxe"; 703491d8ee7SSantosh Puranik } 7043174e4dfSEd Tanous if (dbusSource == 705944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") 7069f16b2c1SJennifer Lee { 7079f16b2c1SJennifer Lee return "Usb"; 7089f16b2c1SJennifer Lee } 709491d8ee7SSantosh Puranik return ""; 710491d8ee7SSantosh Puranik } 711491d8ee7SSantosh Puranik 712491d8ee7SSantosh Puranik /** 713786d0f60SGunnar Mills * @brief Translates boot mode DBUS property value to redfish. 714491d8ee7SSantosh Puranik * 715491d8ee7SSantosh Puranik * @param[in] dbusMode The boot mode in DBUS speak. 716491d8ee7SSantosh Puranik * 717491d8ee7SSantosh Puranik * @return Returns as a string, the boot mode in Redfish terms. If translation 718491d8ee7SSantosh Puranik * cannot be done, returns an empty string. 719491d8ee7SSantosh Puranik */ 72023a21a1cSEd Tanous inline std::string dbusToRfBootMode(const std::string& dbusMode) 721491d8ee7SSantosh Puranik { 722491d8ee7SSantosh Puranik if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 723491d8ee7SSantosh Puranik { 724491d8ee7SSantosh Puranik return "None"; 725491d8ee7SSantosh Puranik } 7263174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") 727491d8ee7SSantosh Puranik { 728491d8ee7SSantosh Puranik return "Diags"; 729491d8ee7SSantosh Puranik } 7303174e4dfSEd Tanous if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") 731491d8ee7SSantosh Puranik { 732491d8ee7SSantosh Puranik return "BiosSetup"; 733491d8ee7SSantosh Puranik } 734491d8ee7SSantosh Puranik return ""; 735491d8ee7SSantosh Puranik } 736491d8ee7SSantosh Puranik 737491d8ee7SSantosh Puranik /** 738786d0f60SGunnar Mills * @brief Translates boot source from Redfish to the DBus boot paths. 739491d8ee7SSantosh Puranik * 740491d8ee7SSantosh Puranik * @param[in] rfSource The boot source in Redfish. 741944ffaf9SJohnathan Mantey * @param[out] bootSource The DBus source 742944ffaf9SJohnathan Mantey * @param[out] bootMode the DBus boot mode 743491d8ee7SSantosh Puranik * 744944ffaf9SJohnathan Mantey * @return Integer error code. 745491d8ee7SSantosh Puranik */ 7468d1b46d7Szhanghch05 inline int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 747944ffaf9SJohnathan Mantey const std::string& rfSource, 748944ffaf9SJohnathan Mantey std::string& bootSource, std::string& bootMode) 749491d8ee7SSantosh Puranik { 750944ffaf9SJohnathan Mantey // The caller has initialized the bootSource and bootMode to: 751944ffaf9SJohnathan Mantey // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 752944ffaf9SJohnathan Mantey // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 753944ffaf9SJohnathan Mantey // Only modify the bootSource/bootMode variable needed to achieve the 754944ffaf9SJohnathan Mantey // desired boot action. 755944ffaf9SJohnathan Mantey 756491d8ee7SSantosh Puranik if (rfSource == "None") 757491d8ee7SSantosh Puranik { 758944ffaf9SJohnathan Mantey return 0; 759491d8ee7SSantosh Puranik } 7603174e4dfSEd Tanous if (rfSource == "Pxe") 761491d8ee7SSantosh Puranik { 762944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; 763944ffaf9SJohnathan Mantey } 764944ffaf9SJohnathan Mantey else if (rfSource == "Hdd") 765944ffaf9SJohnathan Mantey { 766944ffaf9SJohnathan Mantey bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; 767944ffaf9SJohnathan Mantey } 768944ffaf9SJohnathan Mantey else if (rfSource == "Diags") 769944ffaf9SJohnathan Mantey { 770944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; 771944ffaf9SJohnathan Mantey } 772944ffaf9SJohnathan Mantey else if (rfSource == "Cd") 773944ffaf9SJohnathan Mantey { 774944ffaf9SJohnathan Mantey bootSource = 775944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; 776944ffaf9SJohnathan Mantey } 777944ffaf9SJohnathan Mantey else if (rfSource == "BiosSetup") 778944ffaf9SJohnathan Mantey { 779944ffaf9SJohnathan Mantey bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; 780491d8ee7SSantosh Puranik } 7819f16b2c1SJennifer Lee else if (rfSource == "Usb") 7829f16b2c1SJennifer Lee { 783944ffaf9SJohnathan Mantey bootSource = 784944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; 7859f16b2c1SJennifer Lee } 786491d8ee7SSantosh Puranik else 787491d8ee7SSantosh Puranik { 788944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Invalid property value for " 789944ffaf9SJohnathan Mantey "BootSourceOverrideTarget: " 790944ffaf9SJohnathan Mantey << bootSource; 791944ffaf9SJohnathan Mantey messages::propertyValueNotInList(aResp->res, rfSource, 792944ffaf9SJohnathan Mantey "BootSourceTargetOverride"); 793944ffaf9SJohnathan Mantey return -1; 794491d8ee7SSantosh Puranik } 795944ffaf9SJohnathan Mantey return 0; 796491d8ee7SSantosh Puranik } 7971981771bSAli Ahmed 798978b8803SAndrew Geissler /** 799978b8803SAndrew Geissler * @brief Retrieves boot progress of the system 800978b8803SAndrew Geissler * 801978b8803SAndrew Geissler * @param[in] aResp Shared pointer for generating response message. 802978b8803SAndrew Geissler * 803978b8803SAndrew Geissler * @return None. 804978b8803SAndrew Geissler */ 8058d1b46d7Szhanghch05 inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 806978b8803SAndrew Geissler { 807978b8803SAndrew Geissler crow::connections::systemBus->async_method_call( 808978b8803SAndrew Geissler [aResp](const boost::system::error_code ec, 809978b8803SAndrew Geissler const std::variant<std::string>& bootProgress) { 810978b8803SAndrew Geissler if (ec) 811978b8803SAndrew Geissler { 812978b8803SAndrew Geissler // BootProgress is an optional object so just do nothing if 813978b8803SAndrew Geissler // not found 814978b8803SAndrew Geissler return; 815978b8803SAndrew Geissler } 816978b8803SAndrew Geissler 817978b8803SAndrew Geissler const std::string* bootProgressStr = 818978b8803SAndrew Geissler std::get_if<std::string>(&bootProgress); 819978b8803SAndrew Geissler 820978b8803SAndrew Geissler if (!bootProgressStr) 821978b8803SAndrew Geissler { 822978b8803SAndrew Geissler // Interface implemented but property not found, return error 823978b8803SAndrew Geissler // for that 824978b8803SAndrew Geissler messages::internalError(aResp->res); 825978b8803SAndrew Geissler return; 826978b8803SAndrew Geissler } 827978b8803SAndrew Geissler 828978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr; 829978b8803SAndrew Geissler 830978b8803SAndrew Geissler // Now convert the D-Bus BootProgress to the appropriate Redfish 831978b8803SAndrew Geissler // enum 832978b8803SAndrew Geissler std::string rfBpLastState = "None"; 833978b8803SAndrew Geissler if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress." 834978b8803SAndrew Geissler "ProgressStages.Unspecified") 835978b8803SAndrew Geissler { 836978b8803SAndrew Geissler rfBpLastState = "None"; 837978b8803SAndrew Geissler } 838978b8803SAndrew Geissler else if (*bootProgressStr == 839978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 840978b8803SAndrew Geissler "PrimaryProcInit") 841978b8803SAndrew Geissler { 842978b8803SAndrew Geissler rfBpLastState = "PrimaryProcessorInitializationStarted"; 843978b8803SAndrew Geissler } 844978b8803SAndrew Geissler else if (*bootProgressStr == 845978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 846978b8803SAndrew Geissler "BusInit") 847978b8803SAndrew Geissler { 848978b8803SAndrew Geissler rfBpLastState = "BusInitializationStarted"; 849978b8803SAndrew Geissler } 850978b8803SAndrew Geissler else if (*bootProgressStr == 851978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 852978b8803SAndrew Geissler "MemoryInit") 853978b8803SAndrew Geissler { 854978b8803SAndrew Geissler rfBpLastState = "MemoryInitializationStarted"; 855978b8803SAndrew Geissler } 856978b8803SAndrew Geissler else if (*bootProgressStr == 857978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 858978b8803SAndrew Geissler "SecondaryProcInit") 859978b8803SAndrew Geissler { 860978b8803SAndrew Geissler rfBpLastState = "SecondaryProcessorInitializationStarted"; 861978b8803SAndrew Geissler } 862978b8803SAndrew Geissler else if (*bootProgressStr == 863978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 864978b8803SAndrew Geissler "PCIInit") 865978b8803SAndrew Geissler { 866978b8803SAndrew Geissler rfBpLastState = "PCIResourceConfigStarted"; 867978b8803SAndrew Geissler } 868978b8803SAndrew Geissler else if (*bootProgressStr == 869978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 870978b8803SAndrew Geissler "SystemInitComplete") 871978b8803SAndrew Geissler { 872978b8803SAndrew Geissler rfBpLastState = "SystemHardwareInitializationComplete"; 873978b8803SAndrew Geissler } 874978b8803SAndrew Geissler else if (*bootProgressStr == 875978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 876978b8803SAndrew Geissler "OSStart") 877978b8803SAndrew Geissler { 878978b8803SAndrew Geissler rfBpLastState = "OSBootStarted"; 879978b8803SAndrew Geissler } 880978b8803SAndrew Geissler else if (*bootProgressStr == 881978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress.ProgressStages." 882978b8803SAndrew Geissler "OSRunning") 883978b8803SAndrew Geissler { 884978b8803SAndrew Geissler rfBpLastState = "OSRunning"; 885978b8803SAndrew Geissler } 886978b8803SAndrew Geissler else 887978b8803SAndrew Geissler { 888978b8803SAndrew Geissler BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " 889978b8803SAndrew Geissler << *bootProgressStr; 890978b8803SAndrew Geissler // Just return the default 891978b8803SAndrew Geissler } 892978b8803SAndrew Geissler 893978b8803SAndrew Geissler aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState; 894978b8803SAndrew Geissler }, 895978b8803SAndrew Geissler "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", 896978b8803SAndrew Geissler "org.freedesktop.DBus.Properties", "Get", 897978b8803SAndrew Geissler "xyz.openbmc_project.State.Boot.Progress", "BootProgress"); 898978b8803SAndrew Geissler } 899491d8ee7SSantosh Puranik 900491d8ee7SSantosh Puranik /** 901491d8ee7SSantosh Puranik * @brief Retrieves boot mode over DBUS and fills out the response 902491d8ee7SSantosh Puranik * 903491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 904491d8ee7SSantosh Puranik * @param[in] bootDbusObj The dbus object to query for boot properties. 905491d8ee7SSantosh Puranik * 906491d8ee7SSantosh Puranik * @return None. 907491d8ee7SSantosh Puranik */ 9088d1b46d7Szhanghch05 inline void getBootMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 909b5a76932SEd Tanous const std::string& bootDbusObj) 910491d8ee7SSantosh Puranik { 911491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 912491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec, 913491d8ee7SSantosh Puranik const std::variant<std::string>& bootMode) { 914491d8ee7SSantosh Puranik if (ec) 915491d8ee7SSantosh Puranik { 916491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 917491d8ee7SSantosh Puranik messages::internalError(aResp->res); 918491d8ee7SSantosh Puranik return; 919491d8ee7SSantosh Puranik } 920491d8ee7SSantosh Puranik 921491d8ee7SSantosh Puranik const std::string* bootModeStr = 922491d8ee7SSantosh Puranik std::get_if<std::string>(&bootMode); 923491d8ee7SSantosh Puranik 924491d8ee7SSantosh Puranik if (!bootModeStr) 925491d8ee7SSantosh Puranik { 926491d8ee7SSantosh Puranik messages::internalError(aResp->res); 927491d8ee7SSantosh Puranik return; 928491d8ee7SSantosh Puranik } 929491d8ee7SSantosh Puranik 930491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; 931491d8ee7SSantosh Puranik 932491d8ee7SSantosh Puranik // TODO (Santosh): Do we need to support override mode? 933491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; 934491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." 935491d8ee7SSantosh Puranik "AllowableValues"] = { 936944ffaf9SJohnathan Mantey "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; 937491d8ee7SSantosh Puranik 938491d8ee7SSantosh Puranik if (*bootModeStr != 939491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") 940491d8ee7SSantosh Puranik { 941491d8ee7SSantosh Puranik auto rfMode = dbusToRfBootMode(*bootModeStr); 942491d8ee7SSantosh Puranik if (!rfMode.empty()) 943491d8ee7SSantosh Puranik { 944491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 945491d8ee7SSantosh Puranik rfMode; 946491d8ee7SSantosh Puranik } 947491d8ee7SSantosh Puranik } 948491d8ee7SSantosh Puranik 949491d8ee7SSantosh Puranik // If the BootSourceOverrideTarget is still "None" at the end, 950491d8ee7SSantosh Puranik // reset the BootSourceOverrideEnabled to indicate that 951491d8ee7SSantosh Puranik // overrides are disabled 952491d8ee7SSantosh Puranik if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == 953491d8ee7SSantosh Puranik "None") 954491d8ee7SSantosh Puranik { 955491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 956491d8ee7SSantosh Puranik "Disabled"; 957491d8ee7SSantosh Puranik } 958491d8ee7SSantosh Puranik }, 959491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 960491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 961491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); 962491d8ee7SSantosh Puranik } 963491d8ee7SSantosh Puranik 964491d8ee7SSantosh Puranik /** 965491d8ee7SSantosh Puranik * @brief Retrieves boot source over DBUS 966491d8ee7SSantosh Puranik * 967491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 968491d8ee7SSantosh Puranik * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. 969491d8ee7SSantosh Puranik * 970491d8ee7SSantosh Puranik * @return None. 971491d8ee7SSantosh Puranik */ 9728d1b46d7Szhanghch05 inline void getBootSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 973f23b7296SEd Tanous bool oneTimeEnabled) 974491d8ee7SSantosh Puranik { 975491d8ee7SSantosh Puranik std::string bootDbusObj = 976491d8ee7SSantosh Puranik oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" 977491d8ee7SSantosh Puranik : "/xyz/openbmc_project/control/host0/boot"; 978491d8ee7SSantosh Puranik 979491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; 980491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = 981491d8ee7SSantosh Puranik (oneTimeEnabled) ? "Once" : "Continuous"; 982491d8ee7SSantosh Puranik 983491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 984491d8ee7SSantosh Puranik [aResp, bootDbusObj](const boost::system::error_code ec, 985491d8ee7SSantosh Puranik const std::variant<std::string>& bootSource) { 986491d8ee7SSantosh Puranik if (ec) 987491d8ee7SSantosh Puranik { 988491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 989491d8ee7SSantosh Puranik messages::internalError(aResp->res); 990491d8ee7SSantosh Puranik return; 991491d8ee7SSantosh Puranik } 992491d8ee7SSantosh Puranik 993491d8ee7SSantosh Puranik const std::string* bootSourceStr = 994491d8ee7SSantosh Puranik std::get_if<std::string>(&bootSource); 995491d8ee7SSantosh Puranik 996491d8ee7SSantosh Puranik if (!bootSourceStr) 997491d8ee7SSantosh Puranik { 998491d8ee7SSantosh Puranik messages::internalError(aResp->res); 999491d8ee7SSantosh Puranik return; 1000491d8ee7SSantosh Puranik } 1001491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; 1002491d8ee7SSantosh Puranik 1003491d8ee7SSantosh Puranik auto rfSource = dbusToRfBootSource(*bootSourceStr); 1004491d8ee7SSantosh Puranik if (!rfSource.empty()) 1005491d8ee7SSantosh Puranik { 1006491d8ee7SSantosh Puranik aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = 1007491d8ee7SSantosh Puranik rfSource; 1008491d8ee7SSantosh Puranik } 1009491d8ee7SSantosh Puranik }, 1010491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootDbusObj, 1011491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1012491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource"); 1013f23b7296SEd Tanous getBootMode(aResp, bootDbusObj); 1014491d8ee7SSantosh Puranik } 1015491d8ee7SSantosh Puranik 1016491d8ee7SSantosh Puranik /** 1017491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1018491d8ee7SSantosh Puranik * get boot source and boot mode. 1019491d8ee7SSantosh Puranik * 1020491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1021491d8ee7SSantosh Puranik * 1022491d8ee7SSantosh Puranik * @return None. 1023491d8ee7SSantosh Puranik */ 10248d1b46d7Szhanghch05 inline void getBootProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1025491d8ee7SSantosh Puranik { 1026491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Get boot information."; 1027491d8ee7SSantosh Puranik 1028491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1029c5d03ff4SJennifer Lee [aResp](const boost::system::error_code ec, 103019bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1031491d8ee7SSantosh Puranik if (ec) 1032491d8ee7SSantosh Puranik { 1033491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 10342a833c77SJames Feist // not an error, don't have to have the interface 1035491d8ee7SSantosh Puranik return; 1036491d8ee7SSantosh Puranik } 1037491d8ee7SSantosh Puranik 1038491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1039491d8ee7SSantosh Puranik 1040491d8ee7SSantosh Puranik if (!oneTimePtr) 1041491d8ee7SSantosh Puranik { 1042491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1043491d8ee7SSantosh Puranik return; 1044491d8ee7SSantosh Puranik } 1045491d8ee7SSantosh Puranik getBootSource(aResp, *oneTimePtr); 1046491d8ee7SSantosh Puranik }, 1047491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1048491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1049491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1050491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1051491d8ee7SSantosh Puranik } 1052491d8ee7SSantosh Puranik 1053491d8ee7SSantosh Puranik /** 1054c0557e1aSGunnar Mills * @brief Retrieves the Last Reset Time 1055c0557e1aSGunnar Mills * 1056c0557e1aSGunnar Mills * "Reset" is an overloaded term in Redfish, "Reset" includes power on 1057c0557e1aSGunnar Mills * and power off. Even though this is the "system" Redfish object look at the 1058c0557e1aSGunnar Mills * chassis D-Bus interface for the LastStateChangeTime since this has the 1059c0557e1aSGunnar Mills * last power operation time. 1060c0557e1aSGunnar Mills * 1061c0557e1aSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1062c0557e1aSGunnar Mills * 1063c0557e1aSGunnar Mills * @return None. 1064c0557e1aSGunnar Mills */ 10658d1b46d7Szhanghch05 inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1066c0557e1aSGunnar Mills { 1067c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; 1068c0557e1aSGunnar Mills 1069c0557e1aSGunnar Mills crow::connections::systemBus->async_method_call( 1070c0557e1aSGunnar Mills [aResp](const boost::system::error_code ec, 1071c0557e1aSGunnar Mills std::variant<uint64_t>& lastResetTime) { 1072c0557e1aSGunnar Mills if (ec) 1073c0557e1aSGunnar Mills { 1074c0557e1aSGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 1075c0557e1aSGunnar Mills return; 1076c0557e1aSGunnar Mills } 1077c0557e1aSGunnar Mills 1078c0557e1aSGunnar Mills const uint64_t* lastResetTimePtr = 1079c0557e1aSGunnar Mills std::get_if<uint64_t>(&lastResetTime); 1080c0557e1aSGunnar Mills 1081c0557e1aSGunnar Mills if (!lastResetTimePtr) 1082c0557e1aSGunnar Mills { 1083c0557e1aSGunnar Mills messages::internalError(aResp->res); 1084c0557e1aSGunnar Mills return; 1085c0557e1aSGunnar Mills } 1086c0557e1aSGunnar Mills // LastStateChangeTime is epoch time, in milliseconds 1087c0557e1aSGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 1088c0557e1aSGunnar Mills time_t lastResetTimeStamp = 1089c0557e1aSGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 1090c0557e1aSGunnar Mills 1091c0557e1aSGunnar Mills // Convert to ISO 8601 standard 1092c0557e1aSGunnar Mills aResp->res.jsonValue["LastResetTime"] = 1093c0557e1aSGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 1094c0557e1aSGunnar Mills }, 1095c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", 1096c0557e1aSGunnar Mills "/xyz/openbmc_project/state/chassis0", 1097c0557e1aSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 1098c0557e1aSGunnar Mills "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); 1099c0557e1aSGunnar Mills } 1100c0557e1aSGunnar Mills 1101c0557e1aSGunnar Mills /** 11026bd5a8d2SGunnar Mills * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. 11036bd5a8d2SGunnar Mills * 11046bd5a8d2SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 11056bd5a8d2SGunnar Mills * 11066bd5a8d2SGunnar Mills * @return None. 11076bd5a8d2SGunnar Mills */ 11088d1b46d7Szhanghch05 inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 11096bd5a8d2SGunnar Mills { 11106bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; 11116bd5a8d2SGunnar Mills 11126bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 11136bd5a8d2SGunnar Mills [aResp](const boost::system::error_code ec, 11146bd5a8d2SGunnar Mills std::variant<bool>& autoRebootEnabled) { 11156bd5a8d2SGunnar Mills if (ec) 11166bd5a8d2SGunnar Mills { 11176bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 11186bd5a8d2SGunnar Mills return; 11196bd5a8d2SGunnar Mills } 11206bd5a8d2SGunnar Mills 11216bd5a8d2SGunnar Mills const bool* autoRebootEnabledPtr = 11226bd5a8d2SGunnar Mills std::get_if<bool>(&autoRebootEnabled); 11236bd5a8d2SGunnar Mills 11246bd5a8d2SGunnar Mills if (!autoRebootEnabledPtr) 11256bd5a8d2SGunnar Mills { 11266bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11276bd5a8d2SGunnar Mills return; 11286bd5a8d2SGunnar Mills } 11296bd5a8d2SGunnar Mills 11306bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; 11316bd5a8d2SGunnar Mills if (*autoRebootEnabledPtr == true) 11326bd5a8d2SGunnar Mills { 11336bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11346bd5a8d2SGunnar Mills "RetryAttempts"; 11356bd5a8d2SGunnar Mills // If AutomaticRetry (AutoReboot) is enabled see how many 11366bd5a8d2SGunnar Mills // attempts are left 11376bd5a8d2SGunnar Mills crow::connections::systemBus->async_method_call( 1138cb13a392SEd Tanous [aResp](const boost::system::error_code ec2, 11396bd5a8d2SGunnar Mills std::variant<uint32_t>& autoRebootAttemptsLeft) { 1140cb13a392SEd Tanous if (ec2) 11416bd5a8d2SGunnar Mills { 1142cb13a392SEd Tanous BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; 11436bd5a8d2SGunnar Mills return; 11446bd5a8d2SGunnar Mills } 11456bd5a8d2SGunnar Mills 11466bd5a8d2SGunnar Mills const uint32_t* autoRebootAttemptsLeftPtr = 11476bd5a8d2SGunnar Mills std::get_if<uint32_t>(&autoRebootAttemptsLeft); 11486bd5a8d2SGunnar Mills 11496bd5a8d2SGunnar Mills if (!autoRebootAttemptsLeftPtr) 11506bd5a8d2SGunnar Mills { 11516bd5a8d2SGunnar Mills messages::internalError(aResp->res); 11526bd5a8d2SGunnar Mills return; 11536bd5a8d2SGunnar Mills } 11546bd5a8d2SGunnar Mills 11556bd5a8d2SGunnar Mills BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " 11566bd5a8d2SGunnar Mills << *autoRebootAttemptsLeftPtr; 11576bd5a8d2SGunnar Mills 11586bd5a8d2SGunnar Mills aResp->res 11596bd5a8d2SGunnar Mills .jsonValue["Boot"] 11606bd5a8d2SGunnar Mills ["RemainingAutomaticRetryAttempts"] = 11616bd5a8d2SGunnar Mills *autoRebootAttemptsLeftPtr; 11626bd5a8d2SGunnar Mills }, 11636bd5a8d2SGunnar Mills "xyz.openbmc_project.State.Host", 11646bd5a8d2SGunnar Mills "/xyz/openbmc_project/state/host0", 11656bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11666bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootAttempts", 11676bd5a8d2SGunnar Mills "AttemptsLeft"); 11686bd5a8d2SGunnar Mills } 11696bd5a8d2SGunnar Mills else 11706bd5a8d2SGunnar Mills { 11716bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = 11726bd5a8d2SGunnar Mills "Disabled"; 11736bd5a8d2SGunnar Mills } 11746bd5a8d2SGunnar Mills 11756bd5a8d2SGunnar Mills // Not on D-Bus. Hardcoded here: 11766bd5a8d2SGunnar Mills // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 11776bd5a8d2SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; 117869f35306SGunnar Mills 117969f35306SGunnar Mills // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, 118069f35306SGunnar Mills // and RetryAttempts. OpenBMC only supports Disabled and 118169f35306SGunnar Mills // RetryAttempts. 118269f35306SGunnar Mills aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." 118369f35306SGunnar Mills "AllowableValues"] = {"Disabled", 118469f35306SGunnar Mills "RetryAttempts"}; 11856bd5a8d2SGunnar Mills }, 11866bd5a8d2SGunnar Mills "xyz.openbmc_project.Settings", 11876bd5a8d2SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 11886bd5a8d2SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 11896bd5a8d2SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); 11906bd5a8d2SGunnar Mills } 11916bd5a8d2SGunnar Mills 11926bd5a8d2SGunnar Mills /** 1193c6a620f2SGeorge Liu * @brief Retrieves power restore policy over DBUS. 1194c6a620f2SGeorge Liu * 1195c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1196c6a620f2SGeorge Liu * 1197c6a620f2SGeorge Liu * @return None. 1198c6a620f2SGeorge Liu */ 11998d1b46d7Szhanghch05 inline void 12008d1b46d7Szhanghch05 getPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1201c6a620f2SGeorge Liu { 1202c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Get power restore policy"; 1203c6a620f2SGeorge Liu 1204c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1205c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec, 120619bd78d9SPatrick Williams std::variant<std::string>& policy) { 1207c6a620f2SGeorge Liu if (ec) 1208c6a620f2SGeorge Liu { 1209c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1210c6a620f2SGeorge Liu return; 1211c6a620f2SGeorge Liu } 1212c6a620f2SGeorge Liu 1213c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> 1214c6a620f2SGeorge Liu policyMaps = { 1215c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1216c6a620f2SGeorge Liu "AlwaysOn", 1217c6a620f2SGeorge Liu "AlwaysOn"}, 1218c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1219c6a620f2SGeorge Liu "AlwaysOff", 1220c6a620f2SGeorge Liu "AlwaysOff"}, 1221c6a620f2SGeorge Liu {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 122237ec9072SGunnar Mills "Restore", 1223c6a620f2SGeorge Liu "LastState"}}; 1224c6a620f2SGeorge Liu 1225c6a620f2SGeorge Liu const std::string* policyPtr = std::get_if<std::string>(&policy); 1226c6a620f2SGeorge Liu 1227c6a620f2SGeorge Liu if (!policyPtr) 1228c6a620f2SGeorge Liu { 1229c6a620f2SGeorge Liu messages::internalError(aResp->res); 1230c6a620f2SGeorge Liu return; 1231c6a620f2SGeorge Liu } 1232c6a620f2SGeorge Liu 1233c6a620f2SGeorge Liu auto policyMapsIt = policyMaps.find(*policyPtr); 1234c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1235c6a620f2SGeorge Liu { 1236c6a620f2SGeorge Liu messages::internalError(aResp->res); 1237c6a620f2SGeorge Liu return; 1238c6a620f2SGeorge Liu } 1239c6a620f2SGeorge Liu 1240c6a620f2SGeorge Liu aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; 1241c6a620f2SGeorge Liu }, 1242c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1243c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1244c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Get", 1245c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", 1246c6a620f2SGeorge Liu "PowerRestorePolicy"); 1247c6a620f2SGeorge Liu } 1248c6a620f2SGeorge Liu 1249c6a620f2SGeorge Liu /** 12501981771bSAli Ahmed * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not 12511981771bSAli Ahmed * TPM is required for booting the host. 12521981771bSAli Ahmed * 12531981771bSAli Ahmed * @param[in] aResp Shared pointer for generating response message. 12541981771bSAli Ahmed * 12551981771bSAli Ahmed * @return None. 12561981771bSAli Ahmed */ 12571981771bSAli Ahmed inline void getTrustedModuleRequiredToBoot( 12581981771bSAli Ahmed const std::shared_ptr<bmcweb::AsyncResp>& aResp) 12591981771bSAli Ahmed { 12601981771bSAli Ahmed BMCWEB_LOG_DEBUG << "Get TPM required to boot."; 12611981771bSAli Ahmed 12621981771bSAli Ahmed crow::connections::systemBus->async_method_call( 12631981771bSAli Ahmed [aResp]( 12641981771bSAli Ahmed const boost::system::error_code ec, 12651981771bSAli Ahmed std::vector<std::pair< 12661981771bSAli Ahmed std::string, 12671981771bSAli Ahmed std::vector<std::pair<std::string, std::vector<std::string>>>>>& 12681981771bSAli Ahmed subtree) { 12691981771bSAli Ahmed if (ec) 12701981771bSAli Ahmed { 12711981771bSAli Ahmed BMCWEB_LOG_DEBUG 12721981771bSAli Ahmed << "DBUS response error on TPM.Policy GetSubTree" << ec; 12731981771bSAli Ahmed // This is an optional D-Bus object so just return if 12741981771bSAli Ahmed // error occurs 12751981771bSAli Ahmed return; 12761981771bSAli Ahmed } 12771981771bSAli Ahmed if (subtree.size() == 0) 12781981771bSAli Ahmed { 12791981771bSAli Ahmed // As noted above, this is an optional interface so just return 12801981771bSAli Ahmed // if there is no instance found 12811981771bSAli Ahmed return; 12821981771bSAli Ahmed } 12831981771bSAli Ahmed 12841981771bSAli Ahmed /* When there is more than one TPMEnable object... */ 12851981771bSAli Ahmed if (subtree.size() > 1) 12861981771bSAli Ahmed { 12871981771bSAli Ahmed BMCWEB_LOG_DEBUG 12881981771bSAli Ahmed << "DBUS response has more than 1 TPM Enable object:" 12891981771bSAli Ahmed << subtree.size(); 12901981771bSAli Ahmed // Throw an internal Error and return 12911981771bSAli Ahmed messages::internalError(aResp->res); 12921981771bSAli Ahmed return; 12931981771bSAli Ahmed } 12941981771bSAli Ahmed 12951981771bSAli Ahmed // Make sure the Dbus response map has a service and objectPath 12961981771bSAli Ahmed // field 12971981771bSAli Ahmed if (subtree[0].first.empty() || subtree[0].second.size() != 1) 12981981771bSAli Ahmed { 12991981771bSAli Ahmed BMCWEB_LOG_DEBUG << "TPM.Policy mapper error!"; 13001981771bSAli Ahmed messages::internalError(aResp->res); 13011981771bSAli Ahmed return; 13021981771bSAli Ahmed } 13031981771bSAli Ahmed 13041981771bSAli Ahmed const std::string& path = subtree[0].first; 13051981771bSAli Ahmed const std::string& serv = subtree[0].second.begin()->first; 13061981771bSAli Ahmed 13071981771bSAli Ahmed // Valid TPM Enable object found, now reading the current value 13081981771bSAli Ahmed crow::connections::systemBus->async_method_call( 13091981771bSAli Ahmed [aResp](const boost::system::error_code ec, 13101981771bSAli Ahmed std::variant<bool>& tpmRequired) { 13111981771bSAli Ahmed if (ec) 13121981771bSAli Ahmed { 13131981771bSAli Ahmed BMCWEB_LOG_DEBUG 13141981771bSAli Ahmed << "D-BUS response error on TPM.Policy Get" << ec; 13151981771bSAli Ahmed messages::internalError(aResp->res); 13161981771bSAli Ahmed return; 13171981771bSAli Ahmed } 13181981771bSAli Ahmed 13191981771bSAli Ahmed const bool* tpmRequiredVal = 13201981771bSAli Ahmed std::get_if<bool>(&tpmRequired); 13211981771bSAli Ahmed 13221981771bSAli Ahmed if (!tpmRequiredVal) 13231981771bSAli Ahmed { 13241981771bSAli Ahmed messages::internalError(aResp->res); 13251981771bSAli Ahmed return; 13261981771bSAli Ahmed } 13271981771bSAli Ahmed 13281981771bSAli Ahmed if (*tpmRequiredVal == true) 13291981771bSAli Ahmed { 13301981771bSAli Ahmed aResp->res 13311981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13321981771bSAli Ahmed "Required"; 13331981771bSAli Ahmed } 13341981771bSAli Ahmed else 13351981771bSAli Ahmed { 13361981771bSAli Ahmed aResp->res 13371981771bSAli Ahmed .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = 13381981771bSAli Ahmed "Disabled"; 13391981771bSAli Ahmed } 13401981771bSAli Ahmed }, 13411981771bSAli Ahmed serv, path, "org.freedesktop.DBus.Properties", "Get", 13421981771bSAli Ahmed "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable"); 13431981771bSAli Ahmed }, 13441981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", 13451981771bSAli Ahmed "/xyz/openbmc_project/object_mapper", 13461981771bSAli Ahmed "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 13471981771bSAli Ahmed std::array<const char*, 1>{"xyz.openbmc_project.Control.TPM.Policy"}); 13481981771bSAli Ahmed } 13491981771bSAli Ahmed 13501981771bSAli Ahmed /** 1351491d8ee7SSantosh Puranik * @brief Sets boot properties into DBUS object(s). 1352491d8ee7SSantosh Puranik * 1353491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1354491d8ee7SSantosh Puranik * @param[in] oneTimeEnabled Is "one-time" setting already enabled. 1355491d8ee7SSantosh Puranik * @param[in] bootSource The boot source to set. 1356491d8ee7SSantosh Puranik * @param[in] bootEnable The source override "enable" to set. 1357491d8ee7SSantosh Puranik * 1358265c1602SJohnathan Mantey * @return Integer error code. 1359491d8ee7SSantosh Puranik */ 13608d1b46d7Szhanghch05 inline void setBootModeOrSource(std::shared_ptr<bmcweb::AsyncResp> aResp, 1361491d8ee7SSantosh Puranik bool oneTimeEnabled, 1362f23b7296SEd Tanous const std::optional<std::string>& bootSource, 1363f23b7296SEd Tanous const std::optional<std::string>& bootEnable) 1364491d8ee7SSantosh Puranik { 1365944ffaf9SJohnathan Mantey std::string bootSourceStr = 1366944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; 1367944ffaf9SJohnathan Mantey std::string bootModeStr = 1368944ffaf9SJohnathan Mantey "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; 1369491d8ee7SSantosh Puranik bool oneTimeSetting = oneTimeEnabled; 1370944ffaf9SJohnathan Mantey bool useBootSource = true; 1371944ffaf9SJohnathan Mantey 1372491d8ee7SSantosh Puranik // Validate incoming parameters 1373491d8ee7SSantosh Puranik if (bootEnable) 1374491d8ee7SSantosh Puranik { 1375491d8ee7SSantosh Puranik if (*bootEnable == "Once") 1376491d8ee7SSantosh Puranik { 1377491d8ee7SSantosh Puranik oneTimeSetting = true; 1378491d8ee7SSantosh Puranik } 1379491d8ee7SSantosh Puranik else if (*bootEnable == "Continuous") 1380491d8ee7SSantosh Puranik { 1381491d8ee7SSantosh Puranik oneTimeSetting = false; 1382491d8ee7SSantosh Puranik } 1383491d8ee7SSantosh Puranik else if (*bootEnable == "Disabled") 1384491d8ee7SSantosh Puranik { 1385944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; 1386491d8ee7SSantosh Puranik oneTimeSetting = false; 1387944ffaf9SJohnathan Mantey useBootSource = false; 1388491d8ee7SSantosh Puranik } 1389491d8ee7SSantosh Puranik else 1390491d8ee7SSantosh Puranik { 1391491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Unsupported value for " 1392491d8ee7SSantosh Puranik "BootSourceOverrideEnabled: " 1393491d8ee7SSantosh Puranik << *bootEnable; 1394491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootEnable, 1395491d8ee7SSantosh Puranik "BootSourceOverrideEnabled"); 1396491d8ee7SSantosh Puranik return; 1397491d8ee7SSantosh Puranik } 1398491d8ee7SSantosh Puranik } 1399491d8ee7SSantosh Puranik 1400944ffaf9SJohnathan Mantey if (bootSource && useBootSource) 1401491d8ee7SSantosh Puranik { 1402491d8ee7SSantosh Puranik // Source target specified 1403491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; 1404491d8ee7SSantosh Puranik // Figure out which DBUS interface and property to use 1405944ffaf9SJohnathan Mantey if (assignBootParameters(aResp, *bootSource, bootSourceStr, 1406944ffaf9SJohnathan Mantey bootModeStr)) 1407491d8ee7SSantosh Puranik { 1408944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG 1409944ffaf9SJohnathan Mantey << "Invalid property value for BootSourceOverrideTarget: " 1410491d8ee7SSantosh Puranik << *bootSource; 1411491d8ee7SSantosh Puranik messages::propertyValueNotInList(aResp->res, *bootSource, 1412491d8ee7SSantosh Puranik "BootSourceTargetOverride"); 1413491d8ee7SSantosh Puranik return; 1414491d8ee7SSantosh Puranik } 1415944ffaf9SJohnathan Mantey } 1416491d8ee7SSantosh Puranik 1417944ffaf9SJohnathan Mantey // Act on validated parameters 1418944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; 1419944ffaf9SJohnathan Mantey BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; 1420944ffaf9SJohnathan Mantey const char* bootObj = 1421944ffaf9SJohnathan Mantey oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" 1422944ffaf9SJohnathan Mantey : "/xyz/openbmc_project/control/host0/boot"; 1423944ffaf9SJohnathan Mantey 1424491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1425491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1426491d8ee7SSantosh Puranik if (ec) 1427491d8ee7SSantosh Puranik { 1428491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1429491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1430491d8ee7SSantosh Puranik return; 1431491d8ee7SSantosh Puranik } 1432491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot source update done."; 1433491d8ee7SSantosh Puranik }, 1434491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1435491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1436491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Source", "BootSource", 1437491d8ee7SSantosh Puranik std::variant<std::string>(bootSourceStr)); 1438944ffaf9SJohnathan Mantey 1439491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1440491d8ee7SSantosh Puranik [aResp](const boost::system::error_code ec) { 1441491d8ee7SSantosh Puranik if (ec) 1442491d8ee7SSantosh Puranik { 1443491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1444491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1445491d8ee7SSantosh Puranik return; 1446491d8ee7SSantosh Puranik } 1447491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot mode update done."; 1448491d8ee7SSantosh Puranik }, 1449491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", bootObj, 1450491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1451491d8ee7SSantosh Puranik "xyz.openbmc_project.Control.Boot.Mode", "BootMode", 1452491d8ee7SSantosh Puranik std::variant<std::string>(bootModeStr)); 1453944ffaf9SJohnathan Mantey 1454491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1455491d8ee7SSantosh Puranik [aResp{std::move(aResp)}](const boost::system::error_code ec) { 1456491d8ee7SSantosh Puranik if (ec) 1457491d8ee7SSantosh Puranik { 1458491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1459491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1460491d8ee7SSantosh Puranik return; 1461491d8ee7SSantosh Puranik } 1462491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Boot enable update done."; 1463491d8ee7SSantosh Puranik }, 1464491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1465491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1466491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1467491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled", 1468491d8ee7SSantosh Puranik std::variant<bool>(oneTimeSetting)); 1469491d8ee7SSantosh Puranik } 1470491d8ee7SSantosh Puranik 1471491d8ee7SSantosh Puranik /** 1472491d8ee7SSantosh Puranik * @brief Retrieves "One time" enabled setting over DBUS and calls function to 1473491d8ee7SSantosh Puranik * set boot source/boot mode properties. 1474491d8ee7SSantosh Puranik * 1475491d8ee7SSantosh Puranik * @param[in] aResp Shared pointer for generating response message. 1476491d8ee7SSantosh Puranik * @param[in] bootSource The boot source from incoming RF request. 1477491d8ee7SSantosh Puranik * @param[in] bootEnable The boot override enable from incoming RF request. 1478491d8ee7SSantosh Puranik * 1479265c1602SJohnathan Mantey * @return Integer error code. 1480491d8ee7SSantosh Puranik */ 14818d1b46d7Szhanghch05 inline void 14828d1b46d7Szhanghch05 setBootSourceProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1483491d8ee7SSantosh Puranik std::optional<std::string> bootSource, 1484491d8ee7SSantosh Puranik std::optional<std::string> bootEnable) 1485491d8ee7SSantosh Puranik { 1486491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Set boot information."; 1487491d8ee7SSantosh Puranik 1488491d8ee7SSantosh Puranik crow::connections::systemBus->async_method_call( 1489265c1602SJohnathan Mantey [aResp, bootSource{std::move(bootSource)}, 149019bd78d9SPatrick Williams bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, 149119bd78d9SPatrick Williams const std::variant<bool>& oneTime) { 1492491d8ee7SSantosh Puranik if (ec) 1493491d8ee7SSantosh Puranik { 1494491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1495491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1496491d8ee7SSantosh Puranik return; 1497491d8ee7SSantosh Puranik } 1498491d8ee7SSantosh Puranik 1499491d8ee7SSantosh Puranik const bool* oneTimePtr = std::get_if<bool>(&oneTime); 1500491d8ee7SSantosh Puranik 1501491d8ee7SSantosh Puranik if (!oneTimePtr) 1502491d8ee7SSantosh Puranik { 1503491d8ee7SSantosh Puranik messages::internalError(aResp->res); 1504491d8ee7SSantosh Puranik return; 1505491d8ee7SSantosh Puranik } 1506491d8ee7SSantosh Puranik 1507491d8ee7SSantosh Puranik BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; 1508491d8ee7SSantosh Puranik 1509f23b7296SEd Tanous setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable); 1510491d8ee7SSantosh Puranik }, 1511491d8ee7SSantosh Puranik "xyz.openbmc_project.Settings", 1512491d8ee7SSantosh Puranik "/xyz/openbmc_project/control/host0/boot/one_time", 1513491d8ee7SSantosh Puranik "org.freedesktop.DBus.Properties", "Get", 1514491d8ee7SSantosh Puranik "xyz.openbmc_project.Object.Enable", "Enabled"); 1515491d8ee7SSantosh Puranik } 1516491d8ee7SSantosh Puranik 1517c6a620f2SGeorge Liu /** 151898e386ecSGunnar Mills * @brief Sets AssetTag 151998e386ecSGunnar Mills * 152098e386ecSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 152198e386ecSGunnar Mills * @param[in] assetTag "AssetTag" from request. 152298e386ecSGunnar Mills * 152398e386ecSGunnar Mills * @return None. 152498e386ecSGunnar Mills */ 15258d1b46d7Szhanghch05 inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 152698e386ecSGunnar Mills const std::string& assetTag) 152798e386ecSGunnar Mills { 152898e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 152998e386ecSGunnar Mills [aResp, assetTag]( 153098e386ecSGunnar Mills const boost::system::error_code ec, 153198e386ecSGunnar Mills const std::vector<std::pair< 153298e386ecSGunnar Mills std::string, 153398e386ecSGunnar Mills std::vector<std::pair<std::string, std::vector<std::string>>>>>& 153498e386ecSGunnar Mills subtree) { 153598e386ecSGunnar Mills if (ec) 153698e386ecSGunnar Mills { 153798e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 153898e386ecSGunnar Mills messages::internalError(aResp->res); 153998e386ecSGunnar Mills return; 154098e386ecSGunnar Mills } 154198e386ecSGunnar Mills if (subtree.size() == 0) 154298e386ecSGunnar Mills { 154398e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; 154498e386ecSGunnar Mills messages::internalError(aResp->res); 154598e386ecSGunnar Mills return; 154698e386ecSGunnar Mills } 154798e386ecSGunnar Mills // Assume only 1 system D-Bus object 154898e386ecSGunnar Mills // Throw an error if there is more than 1 154998e386ecSGunnar Mills if (subtree.size() > 1) 155098e386ecSGunnar Mills { 155198e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; 155298e386ecSGunnar Mills messages::internalError(aResp->res); 155398e386ecSGunnar Mills return; 155498e386ecSGunnar Mills } 155598e386ecSGunnar Mills if (subtree[0].first.empty() || subtree[0].second.size() != 1) 155698e386ecSGunnar Mills { 155798e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; 155898e386ecSGunnar Mills messages::internalError(aResp->res); 155998e386ecSGunnar Mills return; 156098e386ecSGunnar Mills } 156198e386ecSGunnar Mills 156298e386ecSGunnar Mills const std::string& path = subtree[0].first; 156398e386ecSGunnar Mills const std::string& service = subtree[0].second.begin()->first; 156498e386ecSGunnar Mills 156598e386ecSGunnar Mills if (service.empty()) 156698e386ecSGunnar Mills { 156798e386ecSGunnar Mills BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; 156898e386ecSGunnar Mills messages::internalError(aResp->res); 156998e386ecSGunnar Mills return; 157098e386ecSGunnar Mills } 157198e386ecSGunnar Mills 157298e386ecSGunnar Mills crow::connections::systemBus->async_method_call( 157398e386ecSGunnar Mills [aResp](const boost::system::error_code ec2) { 157498e386ecSGunnar Mills if (ec2) 157598e386ecSGunnar Mills { 157698e386ecSGunnar Mills BMCWEB_LOG_DEBUG 157798e386ecSGunnar Mills << "D-Bus response error on AssetTag Set " << ec2; 157898e386ecSGunnar Mills messages::internalError(aResp->res); 157998e386ecSGunnar Mills return; 158098e386ecSGunnar Mills } 158198e386ecSGunnar Mills }, 158298e386ecSGunnar Mills service, path, "org.freedesktop.DBus.Properties", "Set", 158398e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", 158498e386ecSGunnar Mills std::variant<std::string>(assetTag)); 158598e386ecSGunnar Mills }, 158698e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", 158798e386ecSGunnar Mills "/xyz/openbmc_project/object_mapper", 158898e386ecSGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 158998e386ecSGunnar Mills "/xyz/openbmc_project/inventory", int32_t(0), 159098e386ecSGunnar Mills std::array<const char*, 1>{ 159198e386ecSGunnar Mills "xyz.openbmc_project.Inventory.Item.System"}); 159298e386ecSGunnar Mills } 159398e386ecSGunnar Mills 159498e386ecSGunnar Mills /** 159569f35306SGunnar Mills * @brief Sets automaticRetry (Auto Reboot) 159669f35306SGunnar Mills * 159769f35306SGunnar Mills * @param[in] aResp Shared pointer for generating response message. 159869f35306SGunnar Mills * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. 159969f35306SGunnar Mills * 160069f35306SGunnar Mills * @return None. 160169f35306SGunnar Mills */ 16028d1b46d7Szhanghch05 inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1603f23b7296SEd Tanous const std::string& automaticRetryConfig) 160469f35306SGunnar Mills { 160569f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Set Automatic Retry."; 160669f35306SGunnar Mills 160769f35306SGunnar Mills // OpenBMC only supports "Disabled" and "RetryAttempts". 160869f35306SGunnar Mills bool autoRebootEnabled; 160969f35306SGunnar Mills 161069f35306SGunnar Mills if (automaticRetryConfig == "Disabled") 161169f35306SGunnar Mills { 161269f35306SGunnar Mills autoRebootEnabled = false; 161369f35306SGunnar Mills } 161469f35306SGunnar Mills else if (automaticRetryConfig == "RetryAttempts") 161569f35306SGunnar Mills { 161669f35306SGunnar Mills autoRebootEnabled = true; 161769f35306SGunnar Mills } 161869f35306SGunnar Mills else 161969f35306SGunnar Mills { 162069f35306SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 162169f35306SGunnar Mills "AutomaticRetryConfig: " 162269f35306SGunnar Mills << automaticRetryConfig; 162369f35306SGunnar Mills messages::propertyValueNotInList(aResp->res, automaticRetryConfig, 162469f35306SGunnar Mills "AutomaticRetryConfig"); 162569f35306SGunnar Mills return; 162669f35306SGunnar Mills } 162769f35306SGunnar Mills 162869f35306SGunnar Mills crow::connections::systemBus->async_method_call( 162969f35306SGunnar Mills [aResp](const boost::system::error_code ec) { 163069f35306SGunnar Mills if (ec) 163169f35306SGunnar Mills { 163269f35306SGunnar Mills messages::internalError(aResp->res); 163369f35306SGunnar Mills return; 163469f35306SGunnar Mills } 163569f35306SGunnar Mills }, 163669f35306SGunnar Mills "xyz.openbmc_project.Settings", 163769f35306SGunnar Mills "/xyz/openbmc_project/control/host0/auto_reboot", 163869f35306SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 163969f35306SGunnar Mills "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", 164069f35306SGunnar Mills std::variant<bool>(autoRebootEnabled)); 164169f35306SGunnar Mills } 164269f35306SGunnar Mills 164369f35306SGunnar Mills /** 1644c6a620f2SGeorge Liu * @brief Sets power restore policy properties. 1645c6a620f2SGeorge Liu * 1646c6a620f2SGeorge Liu * @param[in] aResp Shared pointer for generating response message. 1647c6a620f2SGeorge Liu * @param[in] policy power restore policy properties from request. 1648c6a620f2SGeorge Liu * 1649c6a620f2SGeorge Liu * @return None. 1650c6a620f2SGeorge Liu */ 16518d1b46d7Szhanghch05 inline void 16528d1b46d7Szhanghch05 setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 16534e69c904SGunnar Mills const std::string& policy) 1654c6a620f2SGeorge Liu { 1655c6a620f2SGeorge Liu BMCWEB_LOG_DEBUG << "Set power restore policy."; 1656c6a620f2SGeorge Liu 1657c6a620f2SGeorge Liu const boost::container::flat_map<std::string, std::string> policyMaps = { 1658c6a620f2SGeorge Liu {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1659c6a620f2SGeorge Liu "AlwaysOn"}, 1660c6a620f2SGeorge Liu {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 1661c6a620f2SGeorge Liu "AlwaysOff"}, 1662c6a620f2SGeorge Liu {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." 166337ec9072SGunnar Mills "Restore"}}; 1664c6a620f2SGeorge Liu 1665c6a620f2SGeorge Liu std::string powerRestorPolicy; 1666c6a620f2SGeorge Liu 16674e69c904SGunnar Mills auto policyMapsIt = policyMaps.find(policy); 1668c6a620f2SGeorge Liu if (policyMapsIt == policyMaps.end()) 1669c6a620f2SGeorge Liu { 16704e69c904SGunnar Mills messages::propertyValueNotInList(aResp->res, policy, 16714e69c904SGunnar Mills "PowerRestorePolicy"); 1672c6a620f2SGeorge Liu return; 1673c6a620f2SGeorge Liu } 1674c6a620f2SGeorge Liu 1675c6a620f2SGeorge Liu powerRestorPolicy = policyMapsIt->second; 1676c6a620f2SGeorge Liu 1677c6a620f2SGeorge Liu crow::connections::systemBus->async_method_call( 1678c6a620f2SGeorge Liu [aResp](const boost::system::error_code ec) { 1679c6a620f2SGeorge Liu if (ec) 1680c6a620f2SGeorge Liu { 1681c6a620f2SGeorge Liu messages::internalError(aResp->res); 1682c6a620f2SGeorge Liu return; 1683c6a620f2SGeorge Liu } 1684c6a620f2SGeorge Liu }, 1685c6a620f2SGeorge Liu "xyz.openbmc_project.Settings", 1686c6a620f2SGeorge Liu "/xyz/openbmc_project/control/host0/power_restore_policy", 1687c6a620f2SGeorge Liu "org.freedesktop.DBus.Properties", "Set", 1688c6a620f2SGeorge Liu "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", 1689c6a620f2SGeorge Liu std::variant<std::string>(powerRestorPolicy)); 1690c6a620f2SGeorge Liu } 1691c6a620f2SGeorge Liu 1692a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 1693a6349918SAppaRao Puli /** 1694a6349918SAppaRao Puli * @brief Retrieves provisioning status 1695a6349918SAppaRao Puli * 1696a6349918SAppaRao Puli * @param[in] aResp Shared pointer for completing asynchronous calls. 1697a6349918SAppaRao Puli * 1698a6349918SAppaRao Puli * @return None. 1699a6349918SAppaRao Puli */ 17008d1b46d7Szhanghch05 inline void getProvisioningStatus(std::shared_ptr<bmcweb::AsyncResp> aResp) 1701a6349918SAppaRao Puli { 1702a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Get OEM information."; 1703a6349918SAppaRao Puli crow::connections::systemBus->async_method_call( 1704a6349918SAppaRao Puli [aResp](const boost::system::error_code ec, 17051214b7e7SGunnar Mills const std::vector<std::pair<std::string, VariantType>>& 17061214b7e7SGunnar Mills propertiesList) { 1707b99fb1a9SAppaRao Puli nlohmann::json& oemPFR = 1708b99fb1a9SAppaRao Puli aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; 170950626f4fSJames Feist aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 171050626f4fSJames Feist "#OemComputerSystem.OpenBmc"; 171150626f4fSJames Feist oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; 171250626f4fSJames Feist 1713a6349918SAppaRao Puli if (ec) 1714a6349918SAppaRao Puli { 1715a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 1716b99fb1a9SAppaRao Puli // not an error, don't have to have the interface 1717b99fb1a9SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1718a6349918SAppaRao Puli return; 1719a6349918SAppaRao Puli } 1720a6349918SAppaRao Puli 1721a6349918SAppaRao Puli const bool* provState = nullptr; 1722a6349918SAppaRao Puli const bool* lockState = nullptr; 1723a6349918SAppaRao Puli for (const std::pair<std::string, VariantType>& property : 1724a6349918SAppaRao Puli propertiesList) 1725a6349918SAppaRao Puli { 1726a6349918SAppaRao Puli if (property.first == "UfmProvisioned") 1727a6349918SAppaRao Puli { 1728a6349918SAppaRao Puli provState = std::get_if<bool>(&property.second); 1729a6349918SAppaRao Puli } 1730a6349918SAppaRao Puli else if (property.first == "UfmLocked") 1731a6349918SAppaRao Puli { 1732a6349918SAppaRao Puli lockState = std::get_if<bool>(&property.second); 1733a6349918SAppaRao Puli } 1734a6349918SAppaRao Puli } 1735a6349918SAppaRao Puli 1736a6349918SAppaRao Puli if ((provState == nullptr) || (lockState == nullptr)) 1737a6349918SAppaRao Puli { 1738a6349918SAppaRao Puli BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; 1739a6349918SAppaRao Puli messages::internalError(aResp->res); 1740a6349918SAppaRao Puli return; 1741a6349918SAppaRao Puli } 1742a6349918SAppaRao Puli 1743a6349918SAppaRao Puli if (*provState == true) 1744a6349918SAppaRao Puli { 1745a6349918SAppaRao Puli if (*lockState == true) 1746a6349918SAppaRao Puli { 1747a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; 1748a6349918SAppaRao Puli } 1749a6349918SAppaRao Puli else 1750a6349918SAppaRao Puli { 1751a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; 1752a6349918SAppaRao Puli } 1753a6349918SAppaRao Puli } 1754a6349918SAppaRao Puli else 1755a6349918SAppaRao Puli { 1756a6349918SAppaRao Puli oemPFR["ProvisioningStatus"] = "NotProvisioned"; 1757a6349918SAppaRao Puli } 1758a6349918SAppaRao Puli }, 1759a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", 1760a6349918SAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 1761a6349918SAppaRao Puli "xyz.openbmc_project.PFR.Attributes"); 1762a6349918SAppaRao Puli } 1763a6349918SAppaRao Puli #endif 1764a6349918SAppaRao Puli 1765491d8ee7SSantosh Puranik /** 1766*3a2d0424SChris Cain * @brief Translate the PowerMode to a response message. 1767*3a2d0424SChris Cain * 1768*3a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 1769*3a2d0424SChris Cain * @param[in] modeValue PowerMode value to be translated 1770*3a2d0424SChris Cain * 1771*3a2d0424SChris Cain * @return None. 1772*3a2d0424SChris Cain */ 1773*3a2d0424SChris Cain inline void translatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1774*3a2d0424SChris Cain const std::string& modeValue) 1775*3a2d0424SChris Cain { 1776*3a2d0424SChris Cain std::string modeString; 1777*3a2d0424SChris Cain 1778*3a2d0424SChris Cain if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 1779*3a2d0424SChris Cain "PowerMode.Static") 1780*3a2d0424SChris Cain { 1781*3a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "Static"; 1782*3a2d0424SChris Cain } 1783*3a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 1784*3a2d0424SChris Cain "PowerMode.MaximumPerformance") 1785*3a2d0424SChris Cain { 1786*3a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "MaximumPerformance"; 1787*3a2d0424SChris Cain } 1788*3a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 1789*3a2d0424SChris Cain "PowerMode.PowerSaving") 1790*3a2d0424SChris Cain { 1791*3a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "PowerSaving"; 1792*3a2d0424SChris Cain } 1793*3a2d0424SChris Cain else if (modeValue == "xyz.openbmc_project.Control.Power.Mode." 1794*3a2d0424SChris Cain "PowerMode.OEM") 1795*3a2d0424SChris Cain { 1796*3a2d0424SChris Cain aResp->res.jsonValue["PowerMode"] = "OEM"; 1797*3a2d0424SChris Cain } 1798*3a2d0424SChris Cain else 1799*3a2d0424SChris Cain { 1800*3a2d0424SChris Cain // Any other values would be invalid 1801*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "PowerMode value was not valid: " << modeValue; 1802*3a2d0424SChris Cain messages::internalError(aResp->res); 1803*3a2d0424SChris Cain } 1804*3a2d0424SChris Cain } 1805*3a2d0424SChris Cain 1806*3a2d0424SChris Cain /** 1807*3a2d0424SChris Cain * @brief Retrieves system power mode 1808*3a2d0424SChris Cain * 1809*3a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 1810*3a2d0424SChris Cain * 1811*3a2d0424SChris Cain * @return None. 1812*3a2d0424SChris Cain */ 1813*3a2d0424SChris Cain inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1814*3a2d0424SChris Cain { 1815*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Get power mode."; 1816*3a2d0424SChris Cain 1817*3a2d0424SChris Cain // Get Power Mode object path: 1818*3a2d0424SChris Cain crow::connections::systemBus->async_method_call( 1819*3a2d0424SChris Cain [aResp]( 1820*3a2d0424SChris Cain const boost::system::error_code ec, 1821*3a2d0424SChris Cain const std::vector<std::pair< 1822*3a2d0424SChris Cain std::string, 1823*3a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1824*3a2d0424SChris Cain subtree) { 1825*3a2d0424SChris Cain if (ec) 1826*3a2d0424SChris Cain { 1827*3a2d0424SChris Cain BMCWEB_LOG_DEBUG 1828*3a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 1829*3a2d0424SChris Cain // This is an optional D-Bus object so just return if 1830*3a2d0424SChris Cain // error occurs 1831*3a2d0424SChris Cain return; 1832*3a2d0424SChris Cain } 1833*3a2d0424SChris Cain if (subtree.empty()) 1834*3a2d0424SChris Cain { 1835*3a2d0424SChris Cain // As noted above, this is an optional interface so just return 1836*3a2d0424SChris Cain // if there is no instance found 1837*3a2d0424SChris Cain return; 1838*3a2d0424SChris Cain } 1839*3a2d0424SChris Cain if (subtree.size() > 1) 1840*3a2d0424SChris Cain { 1841*3a2d0424SChris Cain // More then one PowerMode object is not supported and is an 1842*3a2d0424SChris Cain // error 1843*3a2d0424SChris Cain BMCWEB_LOG_DEBUG 1844*3a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 1845*3a2d0424SChris Cain << subtree.size(); 1846*3a2d0424SChris Cain messages::internalError(aResp->res); 1847*3a2d0424SChris Cain return; 1848*3a2d0424SChris Cain } 1849*3a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 1850*3a2d0424SChris Cain { 1851*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 1852*3a2d0424SChris Cain messages::internalError(aResp->res); 1853*3a2d0424SChris Cain return; 1854*3a2d0424SChris Cain } 1855*3a2d0424SChris Cain const std::string& path = subtree[0].first; 1856*3a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 1857*3a2d0424SChris Cain if (service.empty()) 1858*3a2d0424SChris Cain { 1859*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 1860*3a2d0424SChris Cain messages::internalError(aResp->res); 1861*3a2d0424SChris Cain return; 1862*3a2d0424SChris Cain } 1863*3a2d0424SChris Cain // Valid Power Mode object found, now read the current value 1864*3a2d0424SChris Cain crow::connections::systemBus->async_method_call( 1865*3a2d0424SChris Cain [aResp](const boost::system::error_code ec, 1866*3a2d0424SChris Cain const std::variant<std::string>& pmode) { 1867*3a2d0424SChris Cain if (ec) 1868*3a2d0424SChris Cain { 1869*3a2d0424SChris Cain BMCWEB_LOG_DEBUG 1870*3a2d0424SChris Cain << "DBUS response error on PowerMode Get: " << ec; 1871*3a2d0424SChris Cain messages::internalError(aResp->res); 1872*3a2d0424SChris Cain return; 1873*3a2d0424SChris Cain } 1874*3a2d0424SChris Cain 1875*3a2d0424SChris Cain const std::string* s = std::get_if<std::string>(&pmode); 1876*3a2d0424SChris Cain if (s == nullptr) 1877*3a2d0424SChris Cain { 1878*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Unable to get PowerMode value"; 1879*3a2d0424SChris Cain messages::internalError(aResp->res); 1880*3a2d0424SChris Cain return; 1881*3a2d0424SChris Cain } 1882*3a2d0424SChris Cain 1883*3a2d0424SChris Cain aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = 1884*3a2d0424SChris Cain {"Static", "MaximumPerformance", "PowerSaving"}; 1885*3a2d0424SChris Cain 1886*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Current power mode: " << *s; 1887*3a2d0424SChris Cain translatePowerMode(aResp, *s); 1888*3a2d0424SChris Cain }, 1889*3a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Get", 1890*3a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode"); 1891*3a2d0424SChris Cain }, 1892*3a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 1893*3a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 1894*3a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 1895*3a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 1896*3a2d0424SChris Cain } 1897*3a2d0424SChris Cain 1898*3a2d0424SChris Cain /** 1899*3a2d0424SChris Cain * @brief Validate the specified mode is valid and return the PowerMode 1900*3a2d0424SChris Cain * name associated with that string 1901*3a2d0424SChris Cain * 1902*3a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 1903*3a2d0424SChris Cain * @param[in] modeString String representing the desired PowerMode 1904*3a2d0424SChris Cain * 1905*3a2d0424SChris Cain * @return PowerMode value or empty string if mode is not valid 1906*3a2d0424SChris Cain */ 1907*3a2d0424SChris Cain inline std::string 1908*3a2d0424SChris Cain validatePowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1909*3a2d0424SChris Cain const std::string& modeString) 1910*3a2d0424SChris Cain { 1911*3a2d0424SChris Cain std::string mode; 1912*3a2d0424SChris Cain 1913*3a2d0424SChris Cain if (modeString == "Static") 1914*3a2d0424SChris Cain { 1915*3a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; 1916*3a2d0424SChris Cain } 1917*3a2d0424SChris Cain else if (modeString == "MaximumPerformance") 1918*3a2d0424SChris Cain { 1919*3a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode." 1920*3a2d0424SChris Cain "MaximumPerformance"; 1921*3a2d0424SChris Cain } 1922*3a2d0424SChris Cain else if (modeString == "PowerSaving") 1923*3a2d0424SChris Cain { 1924*3a2d0424SChris Cain mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; 1925*3a2d0424SChris Cain } 1926*3a2d0424SChris Cain else 1927*3a2d0424SChris Cain { 1928*3a2d0424SChris Cain messages::propertyValueNotInList(aResp->res, modeString, "PowerMode"); 1929*3a2d0424SChris Cain } 1930*3a2d0424SChris Cain return mode; 1931*3a2d0424SChris Cain } 1932*3a2d0424SChris Cain 1933*3a2d0424SChris Cain /** 1934*3a2d0424SChris Cain * @brief Sets system power mode. 1935*3a2d0424SChris Cain * 1936*3a2d0424SChris Cain * @param[in] aResp Shared pointer for generating response message. 1937*3a2d0424SChris Cain * @param[in] pmode System power mode from request. 1938*3a2d0424SChris Cain * 1939*3a2d0424SChris Cain * @return None. 1940*3a2d0424SChris Cain */ 1941*3a2d0424SChris Cain inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1942*3a2d0424SChris Cain const std::string& pmode) 1943*3a2d0424SChris Cain { 1944*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Set power mode."; 1945*3a2d0424SChris Cain 1946*3a2d0424SChris Cain std::string powerMode = validatePowerMode(aResp, pmode); 1947*3a2d0424SChris Cain if (powerMode.empty()) 1948*3a2d0424SChris Cain { 1949*3a2d0424SChris Cain return; 1950*3a2d0424SChris Cain } 1951*3a2d0424SChris Cain 1952*3a2d0424SChris Cain // Get Power Mode object path: 1953*3a2d0424SChris Cain crow::connections::systemBus->async_method_call( 1954*3a2d0424SChris Cain [aResp, powerMode]( 1955*3a2d0424SChris Cain const boost::system::error_code ec, 1956*3a2d0424SChris Cain const std::vector<std::pair< 1957*3a2d0424SChris Cain std::string, 1958*3a2d0424SChris Cain std::vector<std::pair<std::string, std::vector<std::string>>>>>& 1959*3a2d0424SChris Cain subtree) { 1960*3a2d0424SChris Cain if (ec) 1961*3a2d0424SChris Cain { 1962*3a2d0424SChris Cain BMCWEB_LOG_DEBUG 1963*3a2d0424SChris Cain << "DBUS response error on Power.Mode GetSubTree " << ec; 1964*3a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 1965*3a2d0424SChris Cain messages::internalError(aResp->res); 1966*3a2d0424SChris Cain return; 1967*3a2d0424SChris Cain } 1968*3a2d0424SChris Cain if (subtree.empty()) 1969*3a2d0424SChris Cain { 1970*3a2d0424SChris Cain // This is an optional D-Bus object, but user attempted to patch 1971*3a2d0424SChris Cain messages::resourceNotFound(aResp->res, "ComputerSystem", 1972*3a2d0424SChris Cain "PowerMode"); 1973*3a2d0424SChris Cain return; 1974*3a2d0424SChris Cain } 1975*3a2d0424SChris Cain if (subtree.size() > 1) 1976*3a2d0424SChris Cain { 1977*3a2d0424SChris Cain // More then one PowerMode object is not supported and is an 1978*3a2d0424SChris Cain // error 1979*3a2d0424SChris Cain BMCWEB_LOG_DEBUG 1980*3a2d0424SChris Cain << "Found more than 1 system D-Bus Power.Mode objects: " 1981*3a2d0424SChris Cain << subtree.size(); 1982*3a2d0424SChris Cain messages::internalError(aResp->res); 1983*3a2d0424SChris Cain return; 1984*3a2d0424SChris Cain } 1985*3a2d0424SChris Cain if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) 1986*3a2d0424SChris Cain { 1987*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode mapper error!"; 1988*3a2d0424SChris Cain messages::internalError(aResp->res); 1989*3a2d0424SChris Cain return; 1990*3a2d0424SChris Cain } 1991*3a2d0424SChris Cain const std::string& path = subtree[0].first; 1992*3a2d0424SChris Cain const std::string& service = subtree[0].second.begin()->first; 1993*3a2d0424SChris Cain if (service.empty()) 1994*3a2d0424SChris Cain { 1995*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Power.Mode service mapper error!"; 1996*3a2d0424SChris Cain messages::internalError(aResp->res); 1997*3a2d0424SChris Cain return; 1998*3a2d0424SChris Cain } 1999*3a2d0424SChris Cain 2000*3a2d0424SChris Cain BMCWEB_LOG_DEBUG << "Setting power mode(" << powerMode << ") -> " 2001*3a2d0424SChris Cain << path; 2002*3a2d0424SChris Cain 2003*3a2d0424SChris Cain // Set the Power Mode property 2004*3a2d0424SChris Cain crow::connections::systemBus->async_method_call( 2005*3a2d0424SChris Cain [aResp](const boost::system::error_code ec) { 2006*3a2d0424SChris Cain if (ec) 2007*3a2d0424SChris Cain { 2008*3a2d0424SChris Cain messages::internalError(aResp->res); 2009*3a2d0424SChris Cain return; 2010*3a2d0424SChris Cain } 2011*3a2d0424SChris Cain }, 2012*3a2d0424SChris Cain service, path, "org.freedesktop.DBus.Properties", "Set", 2013*3a2d0424SChris Cain "xyz.openbmc_project.Control.Power.Mode", "PowerMode", 2014*3a2d0424SChris Cain std::variant<std::string>(powerMode)); 2015*3a2d0424SChris Cain }, 2016*3a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", 2017*3a2d0424SChris Cain "/xyz/openbmc_project/object_mapper", 2018*3a2d0424SChris Cain "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", int32_t(0), 2019*3a2d0424SChris Cain std::array<const char*, 1>{"xyz.openbmc_project.Control.Power.Mode"}); 2020*3a2d0424SChris Cain } 2021*3a2d0424SChris Cain 2022*3a2d0424SChris Cain /** 202351709ffdSYong Li * @brief Translates watchdog timeout action DBUS property value to redfish. 202451709ffdSYong Li * 202551709ffdSYong Li * @param[in] dbusAction The watchdog timeout action in D-BUS. 202651709ffdSYong Li * 202751709ffdSYong Li * @return Returns as a string, the timeout action in Redfish terms. If 202851709ffdSYong Li * translation cannot be done, returns an empty string. 202951709ffdSYong Li */ 203023a21a1cSEd Tanous inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) 203151709ffdSYong Li { 203251709ffdSYong Li if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") 203351709ffdSYong Li { 203451709ffdSYong Li return "None"; 203551709ffdSYong Li } 20363174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") 203751709ffdSYong Li { 203851709ffdSYong Li return "ResetSystem"; 203951709ffdSYong Li } 20403174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") 204151709ffdSYong Li { 204251709ffdSYong Li return "PowerDown"; 204351709ffdSYong Li } 20443174e4dfSEd Tanous if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") 204551709ffdSYong Li { 204651709ffdSYong Li return "PowerCycle"; 204751709ffdSYong Li } 204851709ffdSYong Li 204951709ffdSYong Li return ""; 205051709ffdSYong Li } 205151709ffdSYong Li 205251709ffdSYong Li /** 2053c45f0082SYong Li *@brief Translates timeout action from Redfish to DBUS property value. 2054c45f0082SYong Li * 2055c45f0082SYong Li *@param[in] rfAction The timeout action in Redfish. 2056c45f0082SYong Li * 2057c45f0082SYong Li *@return Returns as a string, the time_out action as expected by DBUS. 2058c45f0082SYong Li *If translation cannot be done, returns an empty string. 2059c45f0082SYong Li */ 2060c45f0082SYong Li 206123a21a1cSEd Tanous inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) 2062c45f0082SYong Li { 2063c45f0082SYong Li if (rfAction == "None") 2064c45f0082SYong Li { 2065c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.None"; 2066c45f0082SYong Li } 20673174e4dfSEd Tanous if (rfAction == "PowerCycle") 2068c45f0082SYong Li { 2069c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; 2070c45f0082SYong Li } 20713174e4dfSEd Tanous if (rfAction == "PowerDown") 2072c45f0082SYong Li { 2073c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; 2074c45f0082SYong Li } 20753174e4dfSEd Tanous if (rfAction == "ResetSystem") 2076c45f0082SYong Li { 2077c45f0082SYong Li return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; 2078c45f0082SYong Li } 2079c45f0082SYong Li 2080c45f0082SYong Li return ""; 2081c45f0082SYong Li } 2082c45f0082SYong Li 2083c45f0082SYong Li /** 208451709ffdSYong Li * @brief Retrieves host watchdog timer properties over DBUS 208551709ffdSYong Li * 208651709ffdSYong Li * @param[in] aResp Shared pointer for completing asynchronous calls. 208751709ffdSYong Li * 208851709ffdSYong Li * @return None. 208951709ffdSYong Li */ 20908d1b46d7Szhanghch05 inline void 20918d1b46d7Szhanghch05 getHostWatchdogTimer(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 209251709ffdSYong Li { 209351709ffdSYong Li BMCWEB_LOG_DEBUG << "Get host watchodg"; 209451709ffdSYong Li crow::connections::systemBus->async_method_call( 209551709ffdSYong Li [aResp](const boost::system::error_code ec, 209651709ffdSYong Li PropertiesType& properties) { 209751709ffdSYong Li if (ec) 209851709ffdSYong Li { 209951709ffdSYong Li // watchdog service is stopped 210051709ffdSYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 210151709ffdSYong Li return; 210251709ffdSYong Li } 210351709ffdSYong Li 210451709ffdSYong Li BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; 210551709ffdSYong Li 210651709ffdSYong Li nlohmann::json& hostWatchdogTimer = 210751709ffdSYong Li aResp->res.jsonValue["HostWatchdogTimer"]; 210851709ffdSYong Li 210951709ffdSYong Li // watchdog service is running/enabled 211051709ffdSYong Li hostWatchdogTimer["Status"]["State"] = "Enabled"; 211151709ffdSYong Li 211251709ffdSYong Li for (const auto& property : properties) 211351709ffdSYong Li { 211451709ffdSYong Li BMCWEB_LOG_DEBUG << "prop=" << property.first; 211551709ffdSYong Li if (property.first == "Enabled") 211651709ffdSYong Li { 211751709ffdSYong Li const bool* state = std::get_if<bool>(&property.second); 211851709ffdSYong Li 211951709ffdSYong Li if (!state) 212051709ffdSYong Li { 212151709ffdSYong Li messages::internalError(aResp->res); 2122601af5edSChicago Duan return; 212351709ffdSYong Li } 212451709ffdSYong Li 212551709ffdSYong Li hostWatchdogTimer["FunctionEnabled"] = *state; 212651709ffdSYong Li } 212751709ffdSYong Li else if (property.first == "ExpireAction") 212851709ffdSYong Li { 212951709ffdSYong Li const std::string* s = 213051709ffdSYong Li std::get_if<std::string>(&property.second); 213151709ffdSYong Li if (!s) 213251709ffdSYong Li { 213351709ffdSYong Li messages::internalError(aResp->res); 2134601af5edSChicago Duan return; 213551709ffdSYong Li } 213651709ffdSYong Li 213751709ffdSYong Li std::string action = dbusToRfWatchdogAction(*s); 213851709ffdSYong Li if (action.empty()) 213951709ffdSYong Li { 214051709ffdSYong Li messages::internalError(aResp->res); 2141601af5edSChicago Duan return; 214251709ffdSYong Li } 214351709ffdSYong Li hostWatchdogTimer["TimeoutAction"] = action; 214451709ffdSYong Li } 214551709ffdSYong Li } 214651709ffdSYong Li }, 214751709ffdSYong Li "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", 214851709ffdSYong Li "org.freedesktop.DBus.Properties", "GetAll", 214951709ffdSYong Li "xyz.openbmc_project.State.Watchdog"); 215051709ffdSYong Li } 215151709ffdSYong Li 215251709ffdSYong Li /** 2153c45f0082SYong Li * @brief Sets Host WatchDog Timer properties. 2154c45f0082SYong Li * 2155c45f0082SYong Li * @param[in] aResp Shared pointer for generating response message. 2156c45f0082SYong Li * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming 2157c45f0082SYong Li * RF request. 2158c45f0082SYong Li * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. 2159c45f0082SYong Li * 2160c45f0082SYong Li * @return None. 2161c45f0082SYong Li */ 21628d1b46d7Szhanghch05 inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2163c45f0082SYong Li const std::optional<bool> wdtEnable, 2164c45f0082SYong Li const std::optional<std::string>& wdtTimeOutAction) 2165c45f0082SYong Li { 2166c45f0082SYong Li BMCWEB_LOG_DEBUG << "Set host watchdog"; 2167c45f0082SYong Li 2168c45f0082SYong Li if (wdtTimeOutAction) 2169c45f0082SYong Li { 2170c45f0082SYong Li std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); 2171c45f0082SYong Li // check if TimeOut Action is Valid 2172c45f0082SYong Li if (wdtTimeOutActStr.empty()) 2173c45f0082SYong Li { 2174c45f0082SYong Li BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " 2175c45f0082SYong Li << *wdtTimeOutAction; 2176c45f0082SYong Li messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, 2177c45f0082SYong Li "TimeoutAction"); 2178c45f0082SYong Li return; 2179c45f0082SYong Li } 2180c45f0082SYong Li 2181c45f0082SYong Li crow::connections::systemBus->async_method_call( 2182c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2183c45f0082SYong Li if (ec) 2184c45f0082SYong Li { 2185c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2186c45f0082SYong Li messages::internalError(aResp->res); 2187c45f0082SYong Li return; 2188c45f0082SYong Li } 2189c45f0082SYong Li }, 2190c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2191c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2192c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2193c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "ExpireAction", 2194c45f0082SYong Li std::variant<std::string>(wdtTimeOutActStr)); 2195c45f0082SYong Li } 2196c45f0082SYong Li 2197c45f0082SYong Li if (wdtEnable) 2198c45f0082SYong Li { 2199c45f0082SYong Li crow::connections::systemBus->async_method_call( 2200c45f0082SYong Li [aResp](const boost::system::error_code ec) { 2201c45f0082SYong Li if (ec) 2202c45f0082SYong Li { 2203c45f0082SYong Li BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2204c45f0082SYong Li messages::internalError(aResp->res); 2205c45f0082SYong Li return; 2206c45f0082SYong Li } 2207c45f0082SYong Li }, 2208c45f0082SYong Li "xyz.openbmc_project.Watchdog", 2209c45f0082SYong Li "/xyz/openbmc_project/watchdog/host0", 2210c45f0082SYong Li "org.freedesktop.DBus.Properties", "Set", 2211c45f0082SYong Li "xyz.openbmc_project.State.Watchdog", "Enabled", 2212c45f0082SYong Li std::variant<bool>(*wdtEnable)); 2213c45f0082SYong Li } 2214c45f0082SYong Li } 2215c45f0082SYong Li 2216c45f0082SYong Li /** 2217c5b2abe0SLewanczyk, Dawid * SystemsCollection derived class for delivering ComputerSystems Collection 2218c5b2abe0SLewanczyk, Dawid * Schema 2219c5b2abe0SLewanczyk, Dawid */ 22207e860f15SJohn Edward Broadbent inline void requestRoutesSystemsCollection(App& app) 22211abe55efSEd Tanous { 22227e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/") 2223432a890cSEd Tanous .privileges({{"Login"}}) 22247e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22257e860f15SJohn Edward Broadbent [](const crow::Request& req, 22267e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22278d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22280f74e643SEd Tanous "#ComputerSystemCollection.ComputerSystemCollection"; 22298d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; 22308d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Computer System Collection"; 2231462023adSSunitha Harish 2232462023adSSunitha Harish crow::connections::systemBus->async_method_call( 22337e860f15SJohn Edward Broadbent [asyncResp, 22347e860f15SJohn Edward Broadbent &req](const boost::system::error_code ec, 2235cb13a392SEd Tanous const std::variant<std::string>& /*hostName*/) { 22362c70f800SEd Tanous nlohmann::json& ifaceArray = 2237462023adSSunitha Harish asyncResp->res.jsonValue["Members"]; 22382c70f800SEd Tanous ifaceArray = nlohmann::json::array(); 22397e860f15SJohn Edward Broadbent auto& count = 22407e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Members@odata.count"]; 22412c70f800SEd Tanous ifaceArray.push_back( 2242cb13a392SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system"}}); 224394bda602STim Lee count = ifaceArray.size(); 2244cb13a392SEd Tanous if (!ec) 2245462023adSSunitha Harish { 2246462023adSSunitha Harish BMCWEB_LOG_DEBUG << "Hypervisor is available"; 22472c70f800SEd Tanous ifaceArray.push_back( 22487e860f15SJohn Edward Broadbent {{"@odata.id", 22497e860f15SJohn Edward Broadbent "/redfish/v1/Systems/hypervisor"}}); 22502c70f800SEd Tanous count = ifaceArray.size(); 2251cb13a392SEd Tanous } 2252462023adSSunitha Harish }, 22538e651fbfSSunitha Harish "xyz.openbmc_project.Settings", 22548e651fbfSSunitha Harish "/xyz/openbmc_project/network/hypervisor", 2255462023adSSunitha Harish "org.freedesktop.DBus.Properties", "Get", 22567e860f15SJohn Edward Broadbent "xyz.openbmc_project.Network.SystemConfiguration", 22577e860f15SJohn Edward Broadbent "HostName"); 22587e860f15SJohn Edward Broadbent }); 2259c5b2abe0SLewanczyk, Dawid } 22607e860f15SJohn Edward Broadbent 22617e860f15SJohn Edward Broadbent /** 22627e860f15SJohn Edward Broadbent * Function transceives data with dbus directly. 22637e860f15SJohn Edward Broadbent */ 22647e860f15SJohn Edward Broadbent void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 22657e860f15SJohn Edward Broadbent { 22667e860f15SJohn Edward Broadbent constexpr char const* serviceName = "xyz.openbmc_project.Control.Host.NMI"; 22677e860f15SJohn Edward Broadbent constexpr char const* objectPath = "/xyz/openbmc_project/control/host0/nmi"; 22687e860f15SJohn Edward Broadbent constexpr char const* interfaceName = 22697e860f15SJohn Edward Broadbent "xyz.openbmc_project.Control.Host.NMI"; 22707e860f15SJohn Edward Broadbent constexpr char const* method = "NMI"; 22717e860f15SJohn Edward Broadbent 22727e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 22737e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec) { 22747e860f15SJohn Edward Broadbent if (ec) 22757e860f15SJohn Edward Broadbent { 22767e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; 22777e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 22787e860f15SJohn Edward Broadbent return; 22797e860f15SJohn Edward Broadbent } 22807e860f15SJohn Edward Broadbent messages::success(asyncResp->res); 22817e860f15SJohn Edward Broadbent }, 22827e860f15SJohn Edward Broadbent serviceName, objectPath, interfaceName, method); 22837e860f15SJohn Edward Broadbent } 2284c5b2abe0SLewanczyk, Dawid 2285c5b2abe0SLewanczyk, Dawid /** 2286cc340dd9SEd Tanous * SystemActionsReset class supports handle POST method for Reset action. 2287cc340dd9SEd Tanous * The class retrieves and sends data directly to D-Bus. 2288cc340dd9SEd Tanous */ 22897e860f15SJohn Edward Broadbent inline void requestRoutesSystemActionsReset(App& app) 2290cc340dd9SEd Tanous { 2291cc340dd9SEd Tanous /** 2292cc340dd9SEd Tanous * Function handles POST method request. 2293cc340dd9SEd Tanous * Analyzes POST body message before sends Reset request data to D-Bus. 2294cc340dd9SEd Tanous */ 22957e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 22967e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") 2297432a890cSEd Tanous .privileges({{"ConfigureComponent"}}) 22987e860f15SJohn Edward Broadbent .methods( 22997e860f15SJohn Edward Broadbent boost::beast::http::verb:: 23007e860f15SJohn Edward Broadbent post)([](const crow::Request& req, 23017e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 23029712f8acSEd Tanous std::string resetType; 23037e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 23047e860f15SJohn Edward Broadbent resetType)) 2305cc340dd9SEd Tanous { 2306cc340dd9SEd Tanous return; 2307cc340dd9SEd Tanous } 2308cc340dd9SEd Tanous 2309d22c8396SJason M. Bills // Get the command and host vs. chassis 2310cc340dd9SEd Tanous std::string command; 2311d22c8396SJason M. Bills bool hostCommand; 2312d4d25793SEd Tanous if ((resetType == "On") || (resetType == "ForceOn")) 2313cc340dd9SEd Tanous { 2314cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.On"; 2315d22c8396SJason M. Bills hostCommand = true; 2316d22c8396SJason M. Bills } 2317d22c8396SJason M. Bills else if (resetType == "ForceOff") 2318d22c8396SJason M. Bills { 2319d22c8396SJason M. Bills command = "xyz.openbmc_project.State.Chassis.Transition.Off"; 2320d22c8396SJason M. Bills hostCommand = false; 2321d22c8396SJason M. Bills } 2322d22c8396SJason M. Bills else if (resetType == "ForceRestart") 2323d22c8396SJason M. Bills { 232486a0851aSJason M. Bills command = 232586a0851aSJason M. Bills "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; 232686a0851aSJason M. Bills hostCommand = true; 2327cc340dd9SEd Tanous } 23289712f8acSEd Tanous else if (resetType == "GracefulShutdown") 2329cc340dd9SEd Tanous { 2330cc340dd9SEd Tanous command = "xyz.openbmc_project.State.Host.Transition.Off"; 2331d22c8396SJason M. Bills hostCommand = true; 2332cc340dd9SEd Tanous } 23339712f8acSEd Tanous else if (resetType == "GracefulRestart") 2334cc340dd9SEd Tanous { 23357e860f15SJohn Edward Broadbent command = "xyz.openbmc_project.State.Host.Transition." 23367e860f15SJohn Edward Broadbent "GracefulWarmReboot"; 2337d22c8396SJason M. Bills hostCommand = true; 2338d22c8396SJason M. Bills } 2339d22c8396SJason M. Bills else if (resetType == "PowerCycle") 2340d22c8396SJason M. Bills { 234186a0851aSJason M. Bills command = "xyz.openbmc_project.State.Host.Transition.Reboot"; 234286a0851aSJason M. Bills hostCommand = true; 2343cc340dd9SEd Tanous } 2344bfd5b826SLakshminarayana R. Kammath else if (resetType == "Nmi") 2345bfd5b826SLakshminarayana R. Kammath { 2346bfd5b826SLakshminarayana R. Kammath doNMI(asyncResp); 2347bfd5b826SLakshminarayana R. Kammath return; 2348bfd5b826SLakshminarayana R. Kammath } 2349cc340dd9SEd Tanous else 2350cc340dd9SEd Tanous { 23518d1b46d7Szhanghch05 messages::actionParameterUnknown(asyncResp->res, "Reset", 23528d1b46d7Szhanghch05 resetType); 2353cc340dd9SEd Tanous return; 2354cc340dd9SEd Tanous } 2355cc340dd9SEd Tanous 2356d22c8396SJason M. Bills if (hostCommand) 2357d22c8396SJason M. Bills { 2358cc340dd9SEd Tanous crow::connections::systemBus->async_method_call( 2359d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2360cc340dd9SEd Tanous if (ec) 2361cc340dd9SEd Tanous { 2362cc340dd9SEd Tanous BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 23637e860f15SJohn Edward Broadbent if (ec.value() == 23647e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2365d22c8396SJason M. Bills { 2366d22c8396SJason M. Bills messages::actionParameterNotSupported( 2367d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2368d22c8396SJason M. Bills } 2369d22c8396SJason M. Bills else 2370d22c8396SJason M. Bills { 2371f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2372d22c8396SJason M. Bills } 2373cc340dd9SEd Tanous return; 2374cc340dd9SEd Tanous } 2375f12894f8SJason M. Bills messages::success(asyncResp->res); 2376cc340dd9SEd Tanous }, 2377cc340dd9SEd Tanous "xyz.openbmc_project.State.Host", 2378cc340dd9SEd Tanous "/xyz/openbmc_project/state/host0", 2379cc340dd9SEd Tanous "org.freedesktop.DBus.Properties", "Set", 23809712f8acSEd Tanous "xyz.openbmc_project.State.Host", "RequestedHostTransition", 2381abf2add6SEd Tanous std::variant<std::string>{command}); 2382cc340dd9SEd Tanous } 2383d22c8396SJason M. Bills else 2384d22c8396SJason M. Bills { 2385d22c8396SJason M. Bills crow::connections::systemBus->async_method_call( 2386d22c8396SJason M. Bills [asyncResp, resetType](const boost::system::error_code ec) { 2387d22c8396SJason M. Bills if (ec) 2388d22c8396SJason M. Bills { 2389d22c8396SJason M. Bills BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; 23907e860f15SJohn Edward Broadbent if (ec.value() == 23917e860f15SJohn Edward Broadbent boost::asio::error::invalid_argument) 2392d22c8396SJason M. Bills { 2393d22c8396SJason M. Bills messages::actionParameterNotSupported( 2394d22c8396SJason M. Bills asyncResp->res, resetType, "Reset"); 2395d22c8396SJason M. Bills } 2396d22c8396SJason M. Bills else 2397d22c8396SJason M. Bills { 2398d22c8396SJason M. Bills messages::internalError(asyncResp->res); 2399d22c8396SJason M. Bills } 2400d22c8396SJason M. Bills return; 2401d22c8396SJason M. Bills } 2402d22c8396SJason M. Bills messages::success(asyncResp->res); 2403d22c8396SJason M. Bills }, 2404d22c8396SJason M. Bills "xyz.openbmc_project.State.Chassis", 2405d22c8396SJason M. Bills "/xyz/openbmc_project/state/chassis0", 2406d22c8396SJason M. Bills "org.freedesktop.DBus.Properties", "Set", 24077e860f15SJohn Edward Broadbent "xyz.openbmc_project.State.Chassis", 24087e860f15SJohn Edward Broadbent "RequestedPowerTransition", 2409d22c8396SJason M. Bills std::variant<std::string>{command}); 2410d22c8396SJason M. Bills } 24117e860f15SJohn Edward Broadbent }); 2412d22c8396SJason M. Bills } 2413cc340dd9SEd Tanous 2414cc340dd9SEd Tanous /** 24156617338dSEd Tanous * Systems derived class for delivering Computer Systems Schema. 2416c5b2abe0SLewanczyk, Dawid */ 24177e860f15SJohn Edward Broadbent inline void requestRoutesSystems(App& app) 24181abe55efSEd Tanous { 2419c5b2abe0SLewanczyk, Dawid 2420c5b2abe0SLewanczyk, Dawid /** 2421c5b2abe0SLewanczyk, Dawid * Functions triggers appropriate requests on DBus 2422c5b2abe0SLewanczyk, Dawid */ 24237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2424432a890cSEd Tanous .privileges({{"Login"}}) 24257e860f15SJohn Edward Broadbent .methods( 24267e860f15SJohn Edward Broadbent boost::beast::http::verb:: 24277e860f15SJohn Edward Broadbent get)([](const crow::Request&, 24287e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24298d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 2430*3a2d0424SChris Cain "#ComputerSystem.v1_15_0.ComputerSystem"; 24318d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "system"; 24328d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "system"; 24338d1b46d7Szhanghch05 asyncResp->res.jsonValue["SystemType"] = "Physical"; 24348d1b46d7Szhanghch05 asyncResp->res.jsonValue["Description"] = "Computer System"; 24358d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; 24368d1b46d7Szhanghch05 asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = 24378d1b46d7Szhanghch05 "Disabled"; 24388d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = 24398d1b46d7Szhanghch05 uint64_t(0); 24408d1b46d7Szhanghch05 asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = 24418d1b46d7Szhanghch05 "Disabled"; 24427e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = 24437e860f15SJohn Edward Broadbent "/redfish/v1/Systems/system"; 244404a258f4SEd Tanous 24458d1b46d7Szhanghch05 asyncResp->res.jsonValue["Processors"] = { 2446029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; 24478d1b46d7Szhanghch05 asyncResp->res.jsonValue["Memory"] = { 2448029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; 24498d1b46d7Szhanghch05 asyncResp->res.jsonValue["Storage"] = { 2450a25aeccfSNikhil Potade {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; 2451029573d4SEd Tanous 24528d1b46d7Szhanghch05 asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { 2453cc340dd9SEd Tanous {"target", 2454029573d4SEd Tanous "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, 24551cb1a9e6SAppaRao Puli {"@Redfish.ActionInfo", 24561cb1a9e6SAppaRao Puli "/redfish/v1/Systems/system/ResetActionInfo"}}; 2457c5b2abe0SLewanczyk, Dawid 24588d1b46d7Szhanghch05 asyncResp->res.jsonValue["LogServices"] = { 2459029573d4SEd Tanous {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; 2460c4bf6374SJason M. Bills 24618d1b46d7Szhanghch05 asyncResp->res.jsonValue["Bios"] = { 2462d82a3acdSCarol Wang {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; 2463d82a3acdSCarol Wang 24648d1b46d7Szhanghch05 asyncResp->res.jsonValue["Links"]["ManagedBy"] = { 2465c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 2466c5d03ff4SJennifer Lee 24678d1b46d7Szhanghch05 asyncResp->res.jsonValue["Status"] = { 2468c5d03ff4SJennifer Lee {"Health", "OK"}, 2469c5d03ff4SJennifer Lee {"State", "Enabled"}, 2470c5d03ff4SJennifer Lee }; 24710e8ac5e7SGunnar Mills 24720e8ac5e7SGunnar Mills // Fill in SerialConsole info 24730e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 24740e8ac5e7SGunnar Mills 15; 24750e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["IPMI"] = { 24760e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24770e8ac5e7SGunnar Mills }; 24780e8ac5e7SGunnar Mills // TODO (Gunnar): Should look for obmc-console-ssh@2200.service 24790e8ac5e7SGunnar Mills asyncResp->res.jsonValue["SerialConsole"]["SSH"] = { 24800e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24810e8ac5e7SGunnar Mills {"Port", 2200}, 24820e8ac5e7SGunnar Mills // https://github.com/openbmc/docs/blob/master/console.md 24830e8ac5e7SGunnar Mills {"HotKeySequenceDisplay", "Press ~. to exit console"}, 24840e8ac5e7SGunnar Mills }; 24850e8ac5e7SGunnar Mills 24860e8ac5e7SGunnar Mills #ifdef BMCWEB_ENABLE_KVM 24870e8ac5e7SGunnar Mills // Fill in GraphicalConsole info 24880e8ac5e7SGunnar Mills asyncResp->res.jsonValue["GraphicalConsole"] = { 24890e8ac5e7SGunnar Mills {"ServiceEnabled", true}, 24900e8ac5e7SGunnar Mills {"MaxConcurrentSessions", 4}, 24910e8ac5e7SGunnar Mills {"ConnectTypesSupported", {"KVMIP"}}, 24920e8ac5e7SGunnar Mills }; 24930e8ac5e7SGunnar Mills #endif // BMCWEB_ENABLE_KVM 2494e284a7c1SJames Feist constexpr const std::array<const char*, 4> inventoryForSystems = { 2495b49ac873SJames Feist "xyz.openbmc_project.Inventory.Item.Dimm", 24962ad9c2f6SJames Feist "xyz.openbmc_project.Inventory.Item.Cpu", 2497e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.Drive", 2498e284a7c1SJames Feist "xyz.openbmc_project.Inventory.Item.StorageController"}; 2499b49ac873SJames Feist 2500b49ac873SJames Feist auto health = std::make_shared<HealthPopulate>(asyncResp); 2501b49ac873SJames Feist crow::connections::systemBus->async_method_call( 2502b49ac873SJames Feist [health](const boost::system::error_code ec, 2503b49ac873SJames Feist std::vector<std::string>& resp) { 2504b49ac873SJames Feist if (ec) 2505b49ac873SJames Feist { 2506b49ac873SJames Feist // no inventory 2507b49ac873SJames Feist return; 2508b49ac873SJames Feist } 2509b49ac873SJames Feist 2510b49ac873SJames Feist health->inventory = std::move(resp); 2511b49ac873SJames Feist }, 2512b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", 2513b49ac873SJames Feist "/xyz/openbmc_project/object_mapper", 2514b49ac873SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 2515b49ac873SJames Feist int32_t(0), inventoryForSystems); 2516b49ac873SJames Feist 2517b49ac873SJames Feist health->populate(); 2518b49ac873SJames Feist 25198d1b46d7Szhanghch05 getMainChassisId( 25208d1b46d7Szhanghch05 asyncResp, [](const std::string& chassisId, 25218d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2522c5d03ff4SJennifer Lee aRsp->res.jsonValue["Links"]["Chassis"] = { 2523c5d03ff4SJennifer Lee {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 2524c5d03ff4SJennifer Lee }); 2525a3002228SAppaRao Puli 25269f8bfa7cSGunnar Mills getLocationIndicatorActive(asyncResp); 25279f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 2528a3002228SAppaRao Puli getIndicatorLedState(asyncResp); 25295bc2dc8eSJames Feist getComputerSystem(asyncResp, health); 25306c34de48SEd Tanous getHostState(asyncResp); 2531491d8ee7SSantosh Puranik getBootProperties(asyncResp); 2532978b8803SAndrew Geissler getBootProgress(asyncResp); 2533adbe192aSJason M. Bills getPCIeDeviceList(asyncResp, "PCIeDevices"); 253451709ffdSYong Li getHostWatchdogTimer(asyncResp); 2535c6a620f2SGeorge Liu getPowerRestorePolicy(asyncResp); 25366bd5a8d2SGunnar Mills getAutomaticRetry(asyncResp); 2537c0557e1aSGunnar Mills getLastResetTime(asyncResp); 2538a6349918SAppaRao Puli #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE 2539a6349918SAppaRao Puli getProvisioningStatus(asyncResp); 2540a6349918SAppaRao Puli #endif 25411981771bSAli Ahmed getTrustedModuleRequiredToBoot(asyncResp); 2542*3a2d0424SChris Cain getPowerMode(asyncResp); 25437e860f15SJohn Edward Broadbent }); 25447e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/") 2545432a890cSEd Tanous .privileges({{"ConfigureComponent"}}) 25467e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 25477e860f15SJohn Edward Broadbent [](const crow::Request& req, 25487e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 25499f8bfa7cSGunnar Mills std::optional<bool> locationIndicatorActive; 2550cde19e5fSSantosh Puranik std::optional<std::string> indicatorLed; 2551491d8ee7SSantosh Puranik std::optional<nlohmann::json> bootProps; 2552c45f0082SYong Li std::optional<nlohmann::json> wdtTimerProps; 255398e386ecSGunnar Mills std::optional<std::string> assetTag; 2554c6a620f2SGeorge Liu std::optional<std::string> powerRestorePolicy; 2555*3a2d0424SChris Cain std::optional<std::string> powerMode; 255641352c24SSantosh Puranik 25579f8bfa7cSGunnar Mills if (!json_util::readJson( 25588d1b46d7Szhanghch05 req, asyncResp->res, "IndicatorLED", indicatorLed, 25597e860f15SJohn Edward Broadbent "LocationIndicatorActive", locationIndicatorActive, 25607e860f15SJohn Edward Broadbent "Boot", bootProps, "WatchdogTimer", wdtTimerProps, 25617e860f15SJohn Edward Broadbent "PowerRestorePolicy", powerRestorePolicy, "AssetTag", 2562*3a2d0424SChris Cain assetTag, "PowerMode", powerMode)) 25636617338dSEd Tanous { 25646617338dSEd Tanous return; 25656617338dSEd Tanous } 2566491d8ee7SSantosh Puranik 25678d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 2568c45f0082SYong Li 256998e386ecSGunnar Mills if (assetTag) 257098e386ecSGunnar Mills { 257198e386ecSGunnar Mills setAssetTag(asyncResp, *assetTag); 257298e386ecSGunnar Mills } 257398e386ecSGunnar Mills 2574c45f0082SYong Li if (wdtTimerProps) 2575c45f0082SYong Li { 2576c45f0082SYong Li std::optional<bool> wdtEnable; 2577c45f0082SYong Li std::optional<std::string> wdtTimeOutAction; 2578c45f0082SYong Li 2579c45f0082SYong Li if (!json_util::readJson(*wdtTimerProps, asyncResp->res, 2580c45f0082SYong Li "FunctionEnabled", wdtEnable, 2581c45f0082SYong Li "TimeoutAction", wdtTimeOutAction)) 2582c45f0082SYong Li { 2583c45f0082SYong Li return; 2584c45f0082SYong Li } 2585f23b7296SEd Tanous setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); 2586c45f0082SYong Li } 2587c45f0082SYong Li 2588491d8ee7SSantosh Puranik if (bootProps) 2589491d8ee7SSantosh Puranik { 2590491d8ee7SSantosh Puranik std::optional<std::string> bootSource; 2591491d8ee7SSantosh Puranik std::optional<std::string> bootEnable; 259269f35306SGunnar Mills std::optional<std::string> automaticRetryConfig; 2593491d8ee7SSantosh Puranik 259469f35306SGunnar Mills if (!json_util::readJson( 25957e860f15SJohn Edward Broadbent *bootProps, asyncResp->res, 25967e860f15SJohn Edward Broadbent "BootSourceOverrideTarget", bootSource, 25977e860f15SJohn Edward Broadbent "BootSourceOverrideEnabled", bootEnable, 259869f35306SGunnar Mills "AutomaticRetryConfig", automaticRetryConfig)) 2599491d8ee7SSantosh Puranik { 2600491d8ee7SSantosh Puranik return; 2601491d8ee7SSantosh Puranik } 260269f35306SGunnar Mills if (bootSource || bootEnable) 260369f35306SGunnar Mills { 26047e860f15SJohn Edward Broadbent setBootSourceProperties(asyncResp, 26057e860f15SJohn Edward Broadbent std::move(bootSource), 2606491d8ee7SSantosh Puranik std::move(bootEnable)); 2607491d8ee7SSantosh Puranik } 260869f35306SGunnar Mills if (automaticRetryConfig) 260969f35306SGunnar Mills { 2610f23b7296SEd Tanous setAutomaticRetry(asyncResp, *automaticRetryConfig); 261169f35306SGunnar Mills } 261269f35306SGunnar Mills } 2613265c1602SJohnathan Mantey 26149f8bfa7cSGunnar Mills if (locationIndicatorActive) 26159f8bfa7cSGunnar Mills { 26167e860f15SJohn Edward Broadbent setLocationIndicatorActive(asyncResp, 26177e860f15SJohn Edward Broadbent *locationIndicatorActive); 26189f8bfa7cSGunnar Mills } 26199f8bfa7cSGunnar Mills 26207e860f15SJohn Edward Broadbent // TODO (Gunnar): Remove IndicatorLED after enough time has 26217e860f15SJohn Edward Broadbent // passed 26229712f8acSEd Tanous if (indicatorLed) 26236617338dSEd Tanous { 2624f23b7296SEd Tanous setIndicatorLedState(asyncResp, *indicatorLed); 26257e860f15SJohn Edward Broadbent asyncResp->res.addHeader( 26267e860f15SJohn Edward Broadbent boost::beast::http::field::warning, 2627d6aa0093SGunnar Mills "299 - \"IndicatorLED is deprecated. Use " 2628d6aa0093SGunnar Mills "LocationIndicatorActive instead.\""); 26296617338dSEd Tanous } 2630c6a620f2SGeorge Liu 2631c6a620f2SGeorge Liu if (powerRestorePolicy) 2632c6a620f2SGeorge Liu { 26334e69c904SGunnar Mills setPowerRestorePolicy(asyncResp, *powerRestorePolicy); 2634c6a620f2SGeorge Liu } 2635*3a2d0424SChris Cain 2636*3a2d0424SChris Cain if (powerMode) 2637*3a2d0424SChris Cain { 2638*3a2d0424SChris Cain setPowerMode(asyncResp, *powerMode); 2639*3a2d0424SChris Cain } 26407e860f15SJohn Edward Broadbent }); 2641c5b2abe0SLewanczyk, Dawid } 26421cb1a9e6SAppaRao Puli 26431cb1a9e6SAppaRao Puli /** 26441cb1a9e6SAppaRao Puli * SystemResetActionInfo derived class for delivering Computer Systems 26451cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 26461cb1a9e6SAppaRao Puli */ 26477e860f15SJohn Edward Broadbent inline void requestRoutesSystemResetActionInfo(App& app) 26481cb1a9e6SAppaRao Puli { 26491cb1a9e6SAppaRao Puli 26501cb1a9e6SAppaRao Puli /** 26511cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 26521cb1a9e6SAppaRao Puli */ 26537e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/") 2654432a890cSEd Tanous .privileges({{"Login"}}) 26557e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 26567e860f15SJohn Edward Broadbent [](const crow::Request&, 26577e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 26588d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 26591cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 26601cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, 26611cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 26621cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 26631cb1a9e6SAppaRao Puli {"Parameters", 26641cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 26651cb1a9e6SAppaRao Puli {"Required", true}, 26661cb1a9e6SAppaRao Puli {"DataType", "String"}, 26671cb1a9e6SAppaRao Puli {"AllowableValues", 26687e860f15SJohn Edward Broadbent {"On", "ForceOff", "ForceOn", "ForceRestart", 26697e860f15SJohn Edward Broadbent "GracefulRestart", "GracefulShutdown", "PowerCycle", 26707e860f15SJohn Edward Broadbent "Nmi"}}}}}}; 26717e860f15SJohn Edward Broadbent }); 26721cb1a9e6SAppaRao Puli } 2673c5b2abe0SLewanczyk, Dawid } // namespace redfish 2674